See the uuidgen
program which is part of the e2fsprogs package.
According to this, libuuid
is now part of util-linux and the inclusion in e2fsprogs is being phased out. However, on new Ubuntu systems, uuidgen
is now in the uuid-runtime
package.
To create a uuid and save it in a variable:
uuid=$(uuidgen)
On my Ubuntu system, the alpha characters are output as lower case and on my OS X system, they are output as upper case (thanks to David for pointing this out in a comment).
To switch to all upper case (after generating it as above):
uuid=${uuid^^}
To switch to all lower case:
uuid=${uuid,,}
If, for example, you have two UUIDs and you want to compare them in Bash, ignoring their case, you can do a tolower()
style comparison like this:
if [[ ${uuid1,,} == ${uuid2,,} ]]
Every time cryptsetup recreates the encrypted swap partition at boot
time it generates a new UUID for it! Doh!
In /etc/crypttab, use /dev/disk/by-id instead of /dev/disk/by-UUID to refer to your swap partition. For example, your /etc/fstab entry for swap might be
#<file system> <mount point> <type> <options> <dump> <pass>
/dev/mapper/cswap none swap sw 0 0
Then the correct corresponding entry in /etc/crypttab would be something like
# <name> <device> <password> <options>
cswap /dev/disk/by-id/ata-SAMSUNG_SSD_830_Series_S0XYNEAC762041-part5 /dev/urandom swap,cipher=aes-cbc-essiv:sha256,size=256
Notice that the device above is referred to by /dev/disk/by-id which you can find out for your drive by typing the following at the CLI:
ls -lF /dev/disk/by-id
Best Answer
The luks format looks pretty simple and is text based so should be easy to manipulate. I wrote this in about 10 minutes that should do it.
Backup your luks headers first!
Run it with
python /path/to/script.py /path/to/luks/device
Optionally to specify a UUID:python /path/to/script.py /path/to/luks/device abcdef01-abcd-abcd-abcd-abcdef012345