date
int64
1,220B
1,719B
question_description
stringlengths
28
29.9k
accepted_answer
stringlengths
12
26.4k
question_title
stringlengths
14
159
1,552,997,393,000
I am currently aware of two recent methods to bind a LUKS encrypted root partition to a TPM2: systemd-cryptenroll and clevis. Both of them seem to release the encryption key after successfully checking the PCRs the key was sealed against. But I don't like the idea of the volume being decrypted without user interaction. I'd rather have a solution like it is offered by BitLocker for Windows: Either TPM and an additional PIN or a recovery key. Even though I searched the web quite exhaustively I was not able to find any hints in this direction. Is anybody aware of a solution? EDIT: There is a --recovery-key option for systemd-cryptenroll. I'm only concerned with the question how to get an additional PIN requirement when using the TPM.
2022-05-21 - systemd v251 Support for TPM2 + PIN has been merged in systemd-cryptenroll and is available as part of release v251. Changes in disk encryption: systemd-cryptenroll can now control whether to require the user to enter a PIN when using TPM-based unlocking of a volume via the new --tpm2-with-pin= option. Option tpm2-pin= can be used in /etc/crypttab. Source
LUKS + TPM2 + PIN
1,552,997,393,000
first of all I already read this topic : How to change the hash-spec and iter-time of an existing dm-crypt LUKS device? where the proposal is the following command : cryptsetup-reencrypt --keep-key However, the answer is 7 years ago and was considered as experimental. On my side, I have installed Debian from a live USB ticking on encrypt Disk during install. So when I boot my device, I have to decrypt directly from grub. It takes too long to decrypt because it seems that default --iter-time is around 30 seconds even if my password is correct, therefore some people propose to reduce --iter-time to 300. This is why I have additional questions : Is cryptsetup-reencrypt --keep-key -iter-time DEVICE the exact correct code today ? The partition which has Luks over it is /dev/nvme0n1p2 and the luks partition is /dev/mapper/luks-xxxx, there is also the same for the swap partition. Which device to chose : cryptsetup-reencrypt --keep-key -iter-time /dev/nvme0n1p2 or cryptsetup-reencrypt --keep-key -iter-time /dev/mapper/luks-xxxx ? Shall I use it from command in grub menu or from a live USB ? Is it formatting my data ? (better asking twice) Thank you very much. FYI : OS : Debian Way of installing Luks : by live USB (just ticking "encrypt disk") LUKS version : LUKS 1 SLOTS : Key Slots 0 & 1 enabled, key slots 2 to 7 disabled
You don't need to reencrypt the device if you want to change only --iter-time. Reencryption is used when you want to change the way the data on the disk is encrypted (so different key, algorithm or, in case of the linked question, hash function). Iteration time is a "property" of the key slot -- it tells how long should PBKDF2 take when derivating the key from your passphrase. To change it you need to change only the key slot property with cryptsetup luksChangeKey /dev/nvme0n1p2 --iter-time <time in ms> It will ask for passphrase and change properties of key slot with that passphrase, it is possible to select key slot for the operation with --key-slot (if you have same passphrase for multiple key slots). You'll need to repeat this if you want to change the iteration time for both key slots. (This will also ask you to change your password, you can just reuse your old one, luksConvertKey which only changes the parameters doesn't work with LUKS 1.) You can check the result with cryptsetup luksDump /dev/nvme0n1p2 you should see the number PBKDF iterations decreased.
How to modify -iter-time on a existing luks partition
1,552,997,393,000
I'm installing a system on SSD with LUKS and Btrfs, where should I enable discard option for TRIM support? Only /etc/crypttab, only /etc/fstab, everywhere, or nowhere since Btrfs detects SSDs and enables TRIM support? I also use LVM, shoud I somehow change configs to activate TRIM support for LVM too? P.S. I know about security implications on LUKS with TRIM and I'm fine with it.
For TRIM to work, it has to be enabled on all layers. The first step therefore is to enable it in LUKS as LUKS normally disables TRIM due to the security implications. For some distributions you do this in the crypttab, for others you need to edit the cmdline. Since LVM is the next layer on top of LUKS it needs to pass TRIM, which it does per default if the underlying device supports it. Additionally you can set issue_discards = 1 in your lvm.conf, which will bulk-TRIM on lvremove and vgremove. With this in place you can either use fstrim or enable btrfs' native discard (set discard in fstab, see here). If everything works successfully, btrfs will print BTRFS info (device <something>): turning on discard to syslog.
Where should I enable discard option?
1,552,997,393,000
I have been using ecryptfs encryption for a long time. I prefer per user encryption. That means even a root user can not read a user files when the user is not logged in. When an user is not logged in, any users (including root) should not be able to read his files. But ecryptfs is not an encryption for the entire system. So today, I am thinking to use LUKS to encrypt the entire partition and then use ecryptfs to encrypt per user's home. Is this recommended (standard) way to achieve what I want? should I use both LUKS and ecryptfs at the same time? Thanks a lot.
This is exactly what I do with my desktop. I have my entire partition encrypted with LUKS. And then I have my home directory encrypted using ecryptfs. The reason I encrypt my home directory using ecryptfs is because the desktop is used by my partner as well. If you are the sole user of your system, ecryptfs may not be necessary. Make sure you use different passwords for LUKS and ecryptfs so that compromise of the LUKS password will still protect the files in your home directory.
Is it good to have both LUKS and ecryptfs encryptions at the same time?
1,552,997,393,000
My Raspberry Pi (which is 10,000 km away from me right now) works as follows: It is running Raspbian (July 2016's version) The SD card contains /boot An encrypted hard disk drive (using LUKS cryptsetup) contains / When the Pi boots, I can unlock the HDD remotely using dropbear over SSH. It asks for the HDD's password and then the boot sequence continues normally. For more info about how I did all of this, read http://blog.romainpellerin.eu/raspberry-pi-the-ultimate-guide.html. TL;DR here is a shortened version: apt-get install busybox cryptsetup rsync echo "initramfs initramfs.gz 0x00f00000" >> /boot/config.txt sed -e "s|root=/dev/mmcblk0p2|root=/dev/mapper/hddcrypt cryptdevice=/dev/sda1:hddcrypt|" -i /boot/cmdline.txt sed -e "s|/dev/mmcblk0p2|/dev/mapper/hddcrypt|" -i /etc/fstab echo -e "hddcrypt\t/dev/sda1\tnone\tluks" >> /etc/crypttab cryptsetup --verify-passphrase -c aes-xts-plain64 -s 512 -h sha256 luksFormat /dev/sda1 mkinitramfs -o /boot/initramfs.gz $(uname -r) aptitude install dropbear // Configuring the SSH access here... mkinitramfs -o /boot/initramfs.gz $(uname -r) update-initramfs -u Problem Up until yesterday, everything was working fine. I could reboot it and unlock the HDD over SSH. However, yesterday I did aptitude update && aptitude upgrade. As far as I know, this does not upgrade the kernel. Anyway, I rebooted it. Now, I'm stuck at the unlocking step. Even though I type the right password, it immediately says Can't change directory to <something/a kernel version> and Cannot initialize device-mapper. Is dm_mod kernel module loaded? and keeps asking again for the password. I cannot tell you what kernel it is running as I set up a while ago and do not use it that much. Sorry for the lack of details, I do not have a physical access to my Raspberry and I turned it off yesterday, thus I am telling from what I remember. Supposition I am pretty sure I could fix it by tweaking /boot/initramfs.gz but I do not know how. Can you help me please? Thank you very much.
I do not know what gave you the impression that aptitude upgrade would leave your kernel untouched, it simply doesn't. I had the same trouble after a kernel update on my encrypted pi. The problem is that your initramfs needs to be rebuilt. Here is how you do that on an external machine. First, plug in your SD card with the crypted raspbian on it into your external computer and mount everything like so: cryptsetup -v luksOpen /dev/mmcblk0p2 thunderdome mount /dev/mapper/thunderdome /mnt mount /dev/mmcblk0p1 /mnt/boot mount -o bind /dev /mnt/dev mount -t sysfs none /mnt/sys mount -t proc none /mnt/proc Install qemu to emulate raspberry pi binaries: apt-get install qemu qemu-user-static binfmt-support Accoding to this gist, it is better to remove all lines from /mnt/etc/ld.so.preload before proceeding, this is what the sed commands do in the following: # comment out ld.so.preload sed -i 's/^/#/g' /mnt/etc/ld.so.preload # copy qemu binary cp /usr/bin/qemu-arm-static /mnt/usr/bin/ # chroot to raspbian and rebuild initramfs chroot /mnt /bin/bash mkinitramfs -o /boot/initramfs.gz [NEW RASPBIAN KERNEL VERSION] exit # undo damage sed -i 's/^#//g' /mnt/etc/ld.so.preload umount /mnt/{dev,sys,proc,boot} You can find the new raspbian kernel version by checking out /lib/modules, inside the chroot. After doing that, my raspberry pi booted just fine again.
initramfs, LUKS and dm_mod can't boot after upgrade
1,552,997,393,000
I am trying to do what I think is a pretty standard setup of encrypted / partition and unencrypted /boot using the Debian installer (for Stretch-rc1). I created /boot by selecting the option EFI System Partition, as this is a UEFI system. I then created an encrypted LUKS volume and put the root file system there. Although all this was done with the installer, the GPT and the unformatted partitions were first created with fdisk. When I try to finish writing the changes to disk, I get an error: Encryption configuration failure You have selected the root file system to be stored on an encrypted partition. This feature requires a separate /boot partition on which the kernel and initrd can be stored. You should go back and setup a /boot partition. I am confused because I did this earlier without the encryption and everything worked fine. Looking at the ESP /boot partition shows the bootable flag is on. Perhaps I have a fundamental misunderstanding of what Debian wants to do with the ESP? I welcome any suggestions to get this working.
I ended up getting this fixed. Basically, I needed three partitions rather than two: ESP (FAT, unencrypted) /boot (ext, unencrypted) / (any valid Linux file system, encrypted) The unencrypted EFI system partition (ESP) only contains the bootloader (e.g. GRUB), not the kernel or its initrd/initramfs (initial ramdisk image containing the kernel). The bootloader by itself cannot decrypt and access the root file system to get to initrd. So initrd needs to live on its own unencrypted /boot partition, formatted as an ext file system (e.g. ext4), which can be unpacked by the bootloader. Once the kernel has been unpacked, it will be able to take over the remaining boot process to decrypt and mount the root file system. I found this answer helpful.
Installing Debian with encrypted root: installer does not see EFI /boot partition
1,552,997,393,000
I have an encrypted hard drive on my Lan Server. It was encrypted using luks/dm-crypt. The server has a NFS v4 running to share files in the Lan. It works, except for the encrypted USB hard drive. If the client mounts the shares into his file system, he finds an empty folder where the decrypted files should be. This is the setup: How the server mounts the luks partition: sudo cryptsetup luksOpen /dev/sdb1 data1 sudo mount /dev/mapper/data1 /exports/user1/data1 Decrypting and mounting the drive on the server works fine. If I go to /exports/user1/data1 I get the decrypted files. The NFS exports: /exports 192.168.178.20(rw,sync,fsid=0,no_subtree_check,root_squash) 192.168.178.21(rw,sync,fsid=0,no_subtree_check,root_squash) /exports/user1 192.168.178.20(rw,sync,no_subtree_check,root_squash) 192.168.178.21(rw,sync,no_subtree_check,root_squash) So the decrypted USB drive is mounted right into the NFS exports at /exports/user1/data1 And this is how the client mounts the shared folder: sudo mount.nfs4 192.168.178.10:/ /fs_data -o soft,intr,rsize=32768,wsize=32768 Now, if the client mounts the server exports into his file system, he finds the 'data1' folder empty. Is there anything I'm missing? Update: Thanks to Gilles great answer I got it working. I tried to avoid crossmnt and nohide to not run into eventual inode problems. This is what I use now: /etc/exports /exports/user1 192.168.178.20(rw,sync,fsid=0,crossmnt,no_subtree_check) /exports/user1/data1 192.168.178.20(rw,sync,no_subtree_check) client command to mount data1: sudo mount.nfs4 192.168.178.10:/data1 /fs_data -o soft,intr,rsize=32768,wsize=32768
With the Linux kernel NFS server, if you export a directory tree, this does not include any filesystems mounted on that tree. See the description of the nohide option in the exports(5) man page. You need to export the mounted filesystem explicitly, i.e. you need a separate line in exports for /exports/user1/data1. Furthermore you'll need to (re)start the NFS server after mounting /exports/user1/data1. On the client side, you need to mount /fs_data/data1 separately. As discussed in the exports man page, you can avoid this by including the nohide option on /exports/users1/data1, or the crossmnt option on /exports/users1, but this can cause trouble because the client will see files with the same inode number on what appears to be the same filesystem. This can, for example, lead a file copy or archiving program to omit files because it thinks it's already backed them up (if the program has seen /fs_data/foo with inode 42, it'll think that the unrelated file /fs_data/data1/bar with inode 42 on what appears to be the same filesystem — but actually isn't — is the same file).
NFS v4 export encrypted partition. Client mounts empty dir
1,552,997,393,000
I have some encrypted volumes that I use with my Xubuntu machine. One volume is a container file that is mapped to /dev/loop0 and encrypted using plain dm-crypt; another volume is a USB hard drive encrypted using dm-crypt/LUKS. What I'd like to know is what would happen if I accidentally shut down the computer without unmounting and unmapping these volumes? Is it any more risky than if the volumes weren't encrypted? Similarly, what would happen if I had to hard-reboot the machine without unmapping the volumes, because the system froze for example?
The short answer is that encrypted volumes are not really more at risk. The encrypted volumes have a single point of failure in the information at the beginning of the volumes that maps the password (or possibly several passwords for systems like LUKS) to the encryption key for the data. (That is why it is a good idea to encrypt a partition and not a whole disc, so that accidental partitioning doesn't overwrite this data). This data does, AFAIK, not have to be updated unless one of the passwords changes, so the chances of it getting corrupted because a shutdown while it is half-written are low. The rest of the disc is normally accessible with the encryption key retrieved from the above information block. Normal filesystem recovery is possible given that key. You can make a backup of the LUKS header. But you have to realise that when you do and change one of the passwords later on (e.g. because it was compromised), that the backup "uses" the old passwords.
Are encrypted volumes more vulnerable to power loss?
1,552,997,393,000
I was battling with setting up a Mint install on an encrypted hard-drive, and I think I partially succeeded. But I cannot boot the system because some configuration is not correct. I have no idea how to fix it now. The rough guidelines I followed was along the lines of http://blog.andreas-haerter.com/2011/06/18/ubuntu-full-disk-encryption-lvm-luks.sh The differences are that I partitioned with GParted. I'm also dual-booting with Windows, and I'm not using extra partition for /home. vg is on extended partition /dev/sda4, within logical partition /dev/sda5 /boot in on primary partition /dev/sda3 bootloader is on /dev/sda The install went good, I can mount the file-system as in script, from live DVD, but the script in chroot part failed, and the system doesn't boot... Can anyone tell me what do I have to do to allow boot to mount the encrypted partition? Is it enough to edit fstab and crypttab only? They seem to reside on the encrypted partition, so not readable by boot... If it's enough, what they should look like? Everything seems very confusing, and I cannot find a good source I could read about the problem... UPDATES: fdisk -l /dev/sda Device Boot Start End Blocks Id System /dev/sda1 * 2048 206847 102400 7 HPFS/NTFS/exFAT /dev/sda2 206848 209715199 104754176 7 HPFS/NTFS/exFAT /dev/sda3 209715200 210763775 524288 83 Linux /dev/sda4 210763776 625141759 207188992 5 Extended /dev/sda5 210765824 567281663 178257920 83 Linux /dev/sda6 567283712 625141759 28929024 7 HPFS/NTFS/exFAT pvs PV VG Fmt Attr PSize PFree /dev/dm-0 mint lvm2 a- 170.00g 0 pvscan PV /dev/dm-0 VG mint lvm2 [170.00 GiB / 0 free] Total: 1 [170.00 GiB] / in use: 1 [170.00 GiB] / in no VG: 0 [0 ] vgscan Reading all physical volumes. This may take a while... Found volume group "mint" using metadata type lvm2 vgs VG #PV #LV #SN Attr VSize VFree mint 1 2 0 wz--n- 170.00g 0 mount /dev/mapper/mint-root /mnt + cat /mnt/etc/fstab # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc nodev,noexec,nosuid 0 0 /dev/mapper/mint-root / ext4 errors=remount-ro 0 1 # /boot was on /dev/sda3 during installation UUID={uuidhre} /boot ext4 defaults 0 2 /dev/mapper/mint-swap none swap sw 0 0 cat /mnt/etc/crypttab - manually edited # <target name> <source device> <key file> <options> lvm_crypt /dev/sda5 none luks The tutorial for the reference in readable format: http://blog.andreas-haerter.com/2011/06/18/ubuntu-full-disk-encryption-lvm-luks SOLUTION: The post install update doesn't work in tutorial. You have to create the crypttab file manually, or fix it up before calling initramfs. I called everything except intitramfs, opened the /mnt/etc/crypttab with nano, patched the file, and then called chroot with initramfs only. Everything worked smoothly this way.
There's a evident wrong configuration: lvm_crypt /dev/sda5 none luks You decrypted the volume and named it lvm_crypt while mounting /dev/mapper/mint-root Were you asked to input the password during boot ? Also, did you updated initramfs afterwards ? Because this crypttab need to be embedded since it's for root partition. EDIT mint_root /dev/sda5 none luks And chroot inside, do update-initramfs -u will fix it.
How to salvage a lvm/luks install from custom install
1,552,997,393,000
My root and home partitions are LUKS-encrypted. I wish to have discard/TRIM enabled on them (I'm aware of security implications). If my understanding is correct, this should result in discarded areas being zeros on a raw disk device and gibberish on cryptsetup-mapped device. I've made some configuration changes, ran fstrim and now I want to verify if discard is working. To do that, I want to count how many bytes on my partition are zeros. On a trimmed disk I'd expect that: count of 0 bytes ÷ total partition size ≈ percentage of free space On a non-trimmed, encrypted partition: (assuming all bytes were written at least once) count of 0 bytes ≈ total partition size ÷ 256 Inspired by How to gather byte occurrence statistics in binary file?, I've tried this approach: sudo pv /dev/disk/by-label/ESP | od -vtu1 -An -w1 | grep -Fx ' 0' | wc -l but results were disappointing: processing a 500 MB partition took almost 3 minutes. That's 3 MB/s, while my SSD can reach sequential reads of 360 MB/s. I've also noticed that one of my CPU cores was running at 100%, while others were idle, so I guess this could benefit from parallelization. (Impact of pv is negligible, almost no difference compared to cat) What's the fastest way to count 0 bytes on a partition?
If you are able to access the raw disk (without encryption) you could do: dd if=/dev/sda bs=1M count=100 2>/dev/null | tr -d '\0' | wc -c That will read 100Mega byte from the disk, remove all the zeros and count the number of bytes remaining. I do not know if that is the fastest method but it should be quite fast assuming that there are more zeros than data. The command above will read 100 times 1Mega byte or 100*2^20 (104857600) bytes (if they are available). Try with a small number (10 or 100) to test speed and how well the command works. To read the whole disk just remove the count option, let the side of the disk limit the command. Extracting the two values that matter (full disk byte count and number of non-zero bytes) the command become more complex: $ time { { { sudo dd if=/dev/sdX bs=100M 2> >(grep -oP '[0-9]+(?=\s*bytes)' 1>&2 ) | tr -d '\0' | wc -c; } 2>&1; } | { read -d '' a b; echo "$b/$a"; }; } Which will print the two values as: non-zero/disk, like: 766568020/999292928 calculate 1-766568020/999292928 to find the percentage of zero bytes: $ bc <<<'(1-766568020/999292928)*100' 23.28895776994831289400
Fastest way to count zero bytes on a partition
1,552,997,393,000
I was trying to encrypt all the HDD during the installation process of Debian 8 Jessie using full disk encryption + LVM, and I did it, but, there are a little "problem". Before the system asks me the password to unlock the disk, it display a message: Loading, please wait... [5.004102] sd 2:0:0:0: [sda] Assuming drive cache: write through Volume group "lvm_group" not found Skipping volume group lvm_group Unable to find LVM volume lvm_group/root Volume group "lvm_group" not found Skipping volume group lvm_group Unable to find LVM volume lvm_group/swap Please unlock disk sda5_crypt: But when I introduce the password and press Enter, the system boots successfully without any problem. I can't understand why. I found some people with the similar issues in other forums and articles/manuals, but the ones I found just can't boot after the message "Unable to find LVM volume", but I can boot the system after introducing the password. My fstab: # /etc/fstab: static file system information. # # Use 'blkid' to print the universally unique identifier for a # device; this may be used with UUID= as a more robust way to name devices # that works even if disks are added and removed. See fstab(5). # # <file system> <mount point> <type> <options> <dump> <pass> /dev/mapper/lvm_group-root / ext4 errors=remount-ro 0 1 # /boot was on /dev/sda1 during installation UUID=4f7e12ab-84d3-4715-bab4-62cf5033ca8a /boot ext4 defaults 0 2 /dev/mapper/lvm_group-home /home ext4 defaults 0 2 /dev/mapper/lvm_group-swap none swap sw 0 0 /dev/sr0 /media/cdrom0 udf,iso9660 user,noauto 0 0 My crypttab: sda5_crypt UUID=21feadfc-72e7-4a2c-b5f2-0c9ca3137b03 none luks My /proc/cmdline: BOOT_IMAGE=/vmlinuz-3.16.0-4-amd64 root=/dev/mapper/lvm_group-root ro quiet So how can I fix it and avoid these messages? I feel like I've tried everything.
It's not an error, so you shouldn't try to make it go away. The scripts in your initramfs are opportunistically checking to see if they can activate the LVM VG that contains your root device before they bother asking for a passphrase to decrypt any encrypted devices. In the case that your root device is not encrypted, this will work, and the system will proceed to boot without delay. Otherwise, you get an opportunity to enter a passphrase to decrypt any possible encrypted devices, and then it tries again to access the VG. See: /usr/share/initramfs-tools/scripts/local-top/lvm2 /usr/share/initramfs-tools/scripts/local-top/cryptroot especially the function activate_vg() in each of those scripts.
Debian error message: "Unable to find LVM volume", but then boots successfully
1,552,997,393,000
I've decided to move my Debian bootloader and /boot from the hard drive to a USB stick. I'm using LUKS to en/decrypt my hard drive and the bootloader is the only unencrypted partition. How can I easily do this? I want to remove it from the hard drive, resize any of the partitions (/, /var, /tmp) to get the free space after I deleted /boot and put a new bootloader on the USB stick. The Bootloader in use is GRUB it is on /dev/sda1.
Screw grub. It's probably some complexity it introduces that leads you to believe this is a difficult problem to solve. If your computer is less than 5 years old or so, then you're probably booting from a UEFI firmware, in which case your Debian-built linux kernel is already a bootloader. Partition the disk: printf %c\\n o y n 1 '' '' ef00 w y | gdisk /dev/usb-stick/or-whatever-path That's a scripted shortcut for the options you'd want to feed the program interactively. It will create a GUID partition table and a partition of type EFI-system that spans the whole disk. The gdisk program is easy to use though - and so you might do better to go at it interactively instead. The target disk should not be mounted when it is run, and you'll probably need root rights to write the changes. As a general rule you can do pretty much whatever you want in that program without any effect until you write - so be sure when you do. Format the stick fat32: mkfs.vfat -nLABEL /dev/usb-stick/or-whatever-path LABEL is whatever you want it to be. You should LABEL all disks, in my opinion. Install a boot-menu-manager if wanted. I like rEFInd: dpkg -i refind_0.8.7-1_amd64.deb That probably won't install to the USB automatically, so afterward you may want to do... /path/to/refinds/install/dir/install.sh --usedefault /dev/usbstick If you use rEFInd, you'll want to do something like this after: mount /dev/usbstick /mnt mkdir -p /mnt/EFI/debian /esp cp -ar /boot/* /mnt/EFI/debian cat <<\TWONEWLINES >>/etc/fstab LABEL=LABEL /esp vfat defaults 0 2 /esp/EFI/debian /boot none bind,defaults 0 0 TWONEWLINES cat <<\ONESIMPLECONFIG >/mnt/EFI/debian/refind_linux.conf "Debian Menu Entry" root=LABEL=rootlabel other_kernel_params ONESIMPLECONFIG But you might skip rEFInd and just use the firmware's boot menu: efibootmgr -c -d /dev/rootdevice \ -p 1 -L "Debian" \ -l '\EFI\debian\kernelfile' \ -u root=/dev/sda3 kparams \ initrd=EFI/debian/initramfs_image_file And that's pretty much it. Pretty much forever - no more fuss. The firmware loads the kernel from the EFI-system partition you format on your USB stick. The kernel loads its initial root in the initramfs file. If you're already successfully booting LUKS then you must have already arranged for it to access its key somehow - your key is probably already in the initramfs image. If not, well, you'll want to put it in there - or on the USB. The boot partition is a mount on a UEFI-system - there is absolutely no need for all of the old-timey nastiness surrounding embedding boot-loaders and MBRs and the rest. You just mount the boot from firmware, load a kernel executable, and go on your merry way. The fstab stuff just --bind mounts a directory on your USB-stick over /boot - so all kernel updates will happen just as always. If you like yourself, you'll uninstall grub entirely, though. Its arcane update process - a bunch of scripts that read and/or generate other scripts in a wicked chain - is more than a little ridiculous and the kind of nightmare you can easily do without. If you'll take my advice you'll use rEFInd, though. It has pretty menus, and you never have to worry about it - the effects of the install.sh script above can easily be reproduced (and is above, in large part) with a single cp command. It's just a static directory called /EFI/BOOT on the EFI-system partition containing a little EFI-executable file that tells the firmware where to find the kernel. The kernel is the actual bootloader - as it should be. With the setup above you can boot as many EFI-executables as you'd like - just put their /boot (or whatever their boot partition is) contents on the USB-stick in /EFI somewhere and rEFInd will probably find them automatically and present them as an option to you from the firmware menu - to include Microsoft systems. Forevermore.
How to move the bootloader from a hard drive to a usb stick
1,552,997,393,000
Background: I'm investigating methods for encrypted storage on untrusted machines. My current setup uses sshfs to access a LUKS-encrypted image on the remote machine, which is decrypted locally and mounted as ext3. (If I were to use sshfs only, someone gaining access to the remote machine could see my data.) Here's my example setup: # On the local machine: sshfs remote:/home/crypt /home/crypt cryptsetup luksOpen /home/crypt/container.img container mount /dev/mapper/container /home/crypt-open # Place cleartext files in /home/crypt-open, # then reverse the above steps to unmount. I want to make this resilient against network failures. To do this, I'd like to understand what caching / buffering happens with this setup. Consider these two commands: dd if=/dev/random of=/home/crypt-open/test.dat bs=1000000 count=100 dd if=/dev/random of=/home/crypt-open/test.dat bs=1000000 count=100 conv=fsync The first command returns very quickly, and I can see from the network traffic that the data is still being transmitted after the command has returned. The second command seems to wait until the data is finished transferring. Concrete questions: What guarantees does fsync() make under this setup? When fsync() returns, how far along these layers is the data guaranteed to be synced? And what can I do to guarantee that it gets synced all the way down to the remote machine's hard drive? --- /home/crypt-open on the local machine | | (ext3 fs) | --- /dev/mapper/container on the local machine | | (LUKS) | --- /home/crypt/container.img on the local machine | | (sshfs) | --- /home/crypt/container.img on the remote machine | | (ext3 fs) | --- hard drive on the remote machine
I'd assume the weakest link here is the SSHFS code -- the rest of the stuff is in kernel and pretty heavily used, so it's probably fine. I've never actually looked at any FUSE code before, so there could be something else going on that I've missed, but according to the SSHFS source code, SSHFS's implementation of fsync() doesn't do a whole bunch, it just calls flush() on the IO stream. static int sshfs_fsync(const char *path, int isdatasync, struct fuse_file_info *fi) { (void) isdatasync; return sshfs_flush(path, fi); } At sshfs.c:2551, we can see that sshfs_flush() function doesn't send any sort of sync command to the remote machine that enforces an fsync. I believe the sshfs.sync_write flag means "wait for commands to go to the server before returning from write", not "fsync on the server on every write" because that second meaning would be very odd. Thus your fsync measurement is slower because it's bottlenecked by network speed, not remote disk speed. static int sshfs_flush(const char *path, struct fuse_file_info *fi) { int err; struct sshfs_file *sf = get_sshfs_file(fi); struct list_head write_reqs; struct list_head *curr_list; if (!sshfs_file_is_conn(sf)) return -EIO; if (sshfs.sync_write) return 0; (void) path; pthread_mutex_lock(&sshfs.lock); if (!list_empty(&sf->write_reqs)) { curr_list = sf->write_reqs.prev; list_del(&sf->write_reqs); list_init(&sf->write_reqs); list_add(&write_reqs, curr_list); while (!list_empty(&write_reqs)) pthread_cond_wait(&sf->write_finished, &sshfs.lock); } err = sf->write_error; sf->write_error = 0; pthread_mutex_unlock(&sshfs.lock); return err; } Note that it's possible that the remote SFTP implementation does actually fsync on writes, but I think that's actually not what's happening. According to an old draft of the SFTP standard (which is the best I can find) there is a way to specify this behavior: 7.9. attrib-bits and attrib-bits-valid ... SSH_FILEXFER_ATTR_FLAGS_SYNC When the file is modified, the changes are written synchronously to the disk. which would imply that this isn't the default (as it's faster to not fsync). According to that standards document there doesn't appear to be a way to request a fsync on the remote file, but it looks like OpenSSH supports this as an extension to SFTP /* SSH2_FXP_EXTENDED submessages */ struct sftp_handler extended_handlers[] = { ... { "fsync", "[email protected]", 0, process_extended_fsync, 1 }, ... }; static void process_extended_fsync(u_int32_t id) { int handle, fd, ret, status = SSH2_FX_OP_UNSUPPORTED; handle = get_handle(); debug3("request %u: fsync (handle %u)", id, handle); verbose("fsync \"%s\"", handle_to_name(handle)); if ((fd = handle_to_fd(handle)) < 0) status = SSH2_FX_NO_SUCH_FILE; else if (handle_is_ok(handle, HANDLE_FILE)) { ret = fsync(fd); status = (ret == -1) ? errno_to_portable(errno) : SSH2_FX_OK; } send_status(id, status); } I doubt it'd be hard to query for that extension and properly support fsync in SSHFS, that seems a pretty reasonable thing to do. That said, I think it'd probably be easier to just use Linux's network block device support which I assume supports all this stuff properly (though I've never used it myself, so it could be horrible).
Meaning of fsync() in sshfs+LUKS setup
1,552,997,393,000
Let's suppose I create a file, map it to /dev/loop0, and create a LUKS partition inside dd if=/dev/zero of=myfile bs=1M count=1000 losetup /dev/loop0 myfile cryptsetup -c aes-cbc-essiv:sha256 -s 256 -v -y luksFormat /dev/loop0 I then open the encrypted partition cryptsetup luksOpen /dev/loop0 myfile Now, I have my encrypted file appear as a disk /dev/mapper/myfile. I need to create a filesystem before I can use it. Here is my question: Given that this my new filesystem-inside-file resides on another ext4 filesystem (which already is using journal), what options would be best for this new filesystem ? Specifically, if I format my new filesystem-inside-file ext4, should I use journal?. Somehow, the idea of journal filesystem inside another journal filesystem seems not right to me, intuitively.
From my experience running an encrypted reiserfs with private information you should not put that on an journalling filesystem like ext3. I switched back from ext3 to having the file on an ext2 partition after I had to restore from a backup. Over the years ( I have had this file for 5 years ), I had to run recovery several times, and when hosted on ext3 this was the only time reiserfsck could not recover. I think that was because ext3 did a recover which confused the internals of the encrypted disk. I never tried a non-journal filesystem on a journal filesystem (e.g. encrypted ext2 file on reiserfs) for me the important (i.e. encrypted data should be journalled). I am still running reiserfs, never used ext4 for this (but I am considering btrfs, just need to check some time if that is stable enough) If you put your homedirectory on there, be prepared that this feels a bit sluggish, I don't think any finetuning with parameters could have helped that, and I don't think the ext4 ones will influence things much, given that encryption is a performance penalty hit in all directions.
File containing ext filesystem
1,552,997,393,000
I recently bought a new laptop with a 16Gb mSATA SSD cache drive. I haven't used that one yet. I have, however, opted for Ubuntu 13.04 with "Full Disk Encryption" for the main partition (is that what's called LUKS?). With bcache making it's way into 3.10, I'd like to take advantage of the aforementioned cache drive. According to this, one has to format one's backing and cache drives in order to take advantage of bcache. My questions are: Which order do I proceed in? Set up bcache, then (re)setup LUKS or the other way around? Except for the few files pertaining to the encrypted setup (incl. /etc/fstab), can I tar/rsync/whatever the rest of the existing fs to another disk, set up bcache and LUKS and then tar/rsync/whatever back and expect things to work? Are there other things I should know about?
To answer 1., the most sensible thing to do is to put bcache on top of two LUKS virtual devices. LUKS-encrypting a bcache device might work, but there's no guarantee LUKS will consistently put the same virtual sector in the same physical sector every time. You can encrypt both LUKS devices with the same keyfile and unlock both at the same time.
BCache and disk encryption
1,714,761,042,000
I am trying to install Kubuntu 24.04 with manual partitioning. I have created primary partitions for EFI and boot, and an encrypted partition with logical volumes for swap, root, and home. Previously, after this step I just run the Kubuntu installer, manually assigned /dev/mapper/vg0-* partitions for root, home, and swap, as well as the primary partitions for /boot/efi and /boot, and it all worked ok. But in Kubuntu 24.10 the installer changed, and now I'm not sure what I should do. There are separate dropdown items for the whole disk and for the mounted logical volume, and the installer suggests that I should format the logical volumes to use them, and then tries to delete them for some reason. It all ends with this error: Is there any way to solve this? Maybe I do not need to manually partition the disk prior to running the installer? Could I achieve what I want just using the dialogs within the installer itself?
I actually found a solution and was able to perform an installation. I created and mounted my luks volumes (with luksOpen), and after that formatted all of them with mkfs / mkswap. The key to success was to name the luks device (when opening it) to live-WHATEVER, so that it appears under /dev/mapper/live-WHATEVER. Also, before starting the installation, I run the command while true; do vgchange -ay; done (it should stay running in terminal while the installation is performed). Not sure if any one of those would be enough, but as a result, my luks partitions were not unmounted during the installation, and I was able to successfully install the system on them. I found this solution on Calamares github issues, not sure if I'm allowed to post links here, but I hope this attribution is enough.
How do I use LUKS encrypted partitions with Kubuntu 24.04 installation?
1,714,761,042,000
I have an Ubuntu 20.04 machine setup that I am trying to configure for disk encryption. I am trying to setup auto unlock, but my configuration has not worked so far, and I am always prompted for a password. To do this I followed the following steps: sudo apt-get update and sudo apt-get install cryptsetup Check /dev/nvme0n1p3 -> sudo cryptsetup luksDump /dev/nvme0n1p3 -> No Tokens or Keyslots Install clevis, clevis-luks, clevis-dracut, clevis-udisks2, clevis-systemd, clevis-tpm2 sudo clevis luks list -d /dev/nvme0n1p3 -> Empty echo <my password> | sudo clevis luks bind -d /dev/nvme0n1p3 tpm2 '{ "pcr_bank":"sha256", "pcr_ids": "7,11" }' sudo dracut -fv --regenerate-all Check sudo clevis luks list -d /dev/nvme0n1p3 -> 1: tpm2 '{"hash":"sha256","key":"ecc","pcr_bank":"sha256","pcr_ids":"7,11"}' lsblk -o NAME,UUID,MOUNTPOINT -> ├─nvme0n1p1 <uuid1> /boot/efi ├─nvme0n1p2 <uuid2> /boot └─nvme0n1p3 <uuid3> └─dm_crypt-0 <uuid4> └─ubuntu--vg-ubuntu--lv <uuidd5> / cat /etc/crypttab -> dm_crypt-0 UUID=<uuid3> none luks When booting I do not notice any errors for cryptsetup, luks, tpm2. Googling around and checking others questions, I have also verified tried: sudo systemctl enable clevis-luks-askpass.path update-initramfs -c -k all -> Runs successfully My fstab file doesn't actually list the encrypted partition: cat /etc/fstab -> # /etc/fstab: static file system information. # # Use 'blkid' to print the universally unique identifier for a # device; this may be used with UUID= as a more robust way to name devices # that works even if disks are added and removed. See fstab(5). # # <file system> <mount point> <type> <options> <dump> <pass> # / was on /dev/ubuntu-vg/ubuntu-lv during curtin installation /dev/disk/by-id/<Some id which I don't know the origin of> / ext4 defaults 0 1 # /boot was on /dev/nvme0n1p2 during curtin installation /dev/disk/by-uuid/<uuid2> /boot ext4 defaults 0 1 # /boot/efi was on /dev/nvme0n1p1 during curtin installation /dev/disk/by-uuid/<uuid1> /boot/efi vfat defaults 0 1 /swap.img none swap sw 0 0 I've also tried manually adding in the partition to fstab but did not work. No matter what I try, it always asks for password on boot. What could I do to fix this?
I was missing: clevis-initramfs that needed to be installed. Once added the auto unlocker worked.
Ubuntu 20.04 clevis-luks setup auto unlocking not working
1,714,761,042,000
I'd like to setup Arch Linux with encryption. I found the tutorial on the Arch wiki, and think that the second option (LVM on LUKS) is the best option for me. Here's the partitioning I'd like to use (Thinkpad X1 Carbon, ~ 500 GB SSD, 16 GB RAM): [alignment gap] 1 MB /boot 256 MB (FAT 32) swap 16 GB (size of memory) / (root) 64 GB (ext4) /var 8 GB (ext4) /tmp 4 GB (ext4) /home ~400 GB (ext4, remainder) The disk has the name nvme0n1. After booting the installer (September 2020 release) and connecting to the WiFi, I overwrite the disk with random data: # shred --random-source=/dev/urandom --iterations=3 /dev/nvme0n1 Then I setup a new GPT partition schema: # parted -s /dev/nvme0n1 mklabel gpt Next, I create and format a boot partition with a 1 MB alignment gap in front of it. # parted -s /dev/nvme0n1 mkpart boot fat32 1MiB 257MiB # parted -s /dev/nvme0n1 set 1 esp on # mkfs.fat -F 32 /dev/nvme0n1p1 Now comes the part, where the wiki is unclear. (It only mentions that it's possible to have /boot on a different device, which I don't.) I decided to make another partition, on top of which my encrypted volume will be located: # parted -s /dev/nvme0n1 mkpart cryptlvm 257MiB '100%' This creates a second partition /dev/nvme0n1p2 with the remainder disk size. (Maybe this step causes the problem.) I continue to setup the encryption: # cryptsetup luksFormat /dev/nvme0n1p2 # YES, entering passphrase twice # cryptsetup open /dev/nvme0n1p2 cryptlvm # entering passphrase # pvcreate /dev/mapper/cryptlvm # vgcreate VolumeGroup /dev/mapper/cryptlvm Then I create the partitions as described above: # lvcreate -L 16G VolumeGroup -n swap # lvcreate -L 64G VolumeGroup -n root # lvcreate -L 8G VolumeGroup -n var # lvcreate -L 4G VolumeGroup -n tmp # lvcreate -l '100%FREE' VolumeGroup -n home The partitions are now being formatted: # mkswap /dev/VolumeGroup/swap # mkfs.ext4 -F /dev/VolumeGroup/root # mkfs.ext4 -F /dev/VolumeGroup/var # mkfs.ext4 -F /dev/VolumeGroup/tmp # mkfs.ext4 -F /dev/VolumeGroup/home And mounted: # mount /dev/VolumeGroup/root /mnt # mkdir /mnt/boot # mount /dev/nvme0n1p1 /mnt/boot # mkdir /mnt/var mount /dev/VolumeGroup/var /mnt/var # mkdir /mnt/tmp mount /dev/VolumeGroup/tmp /mnt/tmp # mkdir /mnt/home mount /dev/VolumeGroup/home /mnt/home The system can now be bootstrapped together with lvm2: # pacstrap /mnt base liux linux-firmware lvm2 I also create and store the fstab: # genfstab -U /mnt >> /mnt/etc/fstab I chroot into the bootstrapped system: # arch-chroot /mnt As mentioned in the wiki, I add the hooks encrypt and lvm2 in /etc/mkinitcpio.conf: HOOKS=(base udev autodetect keyboard keymap consolefont modconf block filesystems fsck encrypt lvm2) I continue with the usual setup tasks (setup root password, install base packages, set timezone, locale, language, hostname): # passwd # pacman -S iw wpa_supplicant dialog intel-ucode netctl dhcpcd # ln -sf /usr/share/zoneinfo/Europe/Zurich /etc/localtime # timedatectl set-ntp true # hwclock --systohc # echo 'en_US.UTF-8 UTF-8' >> /etc/locale.gen # locale-gen # echo 'LANG=en_US.UTF-8' > /etc/locale.conf # echo -n 'x1' > /etc/hostname Now comes the bootloader. Here I traditionally use the systemd bootloader instead of grub. Here's how I set it up: # systemd-machine-id-setup # bootctl --path=/boot install I figure out the UUID (not PARTUUID) of the root partition as follows: # blkid | grep /dev/VolumeGroup/root | egrep -o 'UUID="[^"]!"' UUID="6d5b4777-2621-4bec-8bbc-ebd4b5ba9faf" Then I create the boot entry in /boot/loader/entries/arch.conf: title Arch Linux linux /vmlinuz-linux initrd /initramfs-linux.img options cryptdevice=UUID=6d5b4777-2621-4bec-8bbc-ebd4b5ba9faf:cryptlvm root/dev/VolumeGroup/root And an accordng /boot/loader/loader.conf: default arch timeout 0 editor 0 Last but not least, I run mkinitcpio, before leaving for a fresh boot: # mkinitcpio -P # exit # umount -R /mnt # shutdown -h now So that was my setup procedure. I remove the USB dongle and boot the system. The bootloader shows up, but then I get the following screen: :: running early hook [udev] Starting version 246.6-1-arch :: running early hook [lvm2] :: running hook [udev] :: Triggering uevents... :: running hook [encrypt] Waiting 10 seconds for device /dev/disk/by-uuid/6d5b4777-2621-4bec-8bbc-ebd4b5ba9faf ... Waiting 10 seconds for device /dev/VolumeGroup/root ... ERROR: device '/dev/VolumeGroup/root' not found. Skippng fsck. :: mounting '/dev/VolumeGroup/root' on real root mount: /new_root: no filesystem type specified. You are now being dropped into an emergency shell. Now I'm pretty clueless what I've done wrong. One suspicion is the second partition (/dev/nvme0n1p2) that I needed to create. Another suspicion is that I did something wrong with the bootloader. On regular setups, I always use the PARTUUID instead of the UUID. (However, there's no PARTUUID in the output of blikd, so this probably isn't the issue.)
Since @frostschutz hasn't written his correct solution to the problem as an answer yet, I'll summarize the issue here quickly: I picked the UUID of the wrong partition. The root partition under /dev/VolumeGroup/root is not the one to be chosen, but the actual partition /dev/nvme0n1p2. Here's how to extract that UUID: # uuid=$(blkid --match-tag UUID -o value /dev/nvme0n1p2) Which then can be used in the boot loader entry config: # cat <<EOF >/boot/loader/entries/arch.conf title Arch Linux linux /vmlinuz-linux initrd /initramfs-linux.img options cryptdevice=UUID=${uuid}:cryptlvm root=/dev/volgrp/root EOF I summarized the whole procedure on my private website. Thanks also to @Cbhihe for the advice on partition sizes.
Arch Linux Setup with Encryption (LVM on LUKS)
1,714,761,042,000
I am following the Debian dev's guide to full disk encryption. I am currently on Section 4, step 3- editing /etc/crypttab. In the guide, in section 3 they set up keyslot 0 for something else and now in section 4 are setting up keyslot 1. However, during my setup, section 3 defaulted to keyslot 1, and therefore for section 4 I will need to use keyslot 0, by adding this to my /etc/crypttab: root_crypt UUID=... /etc/keys/root.key luks,discard,key-slot=0 (the guide has key-slot=1 here instead) I think. I worry that I may be wrong, put key-slot=0 when I should have put key-slot=1, so LUKS looks at the wrong slot for decryption, fails to decrypt due to wrong password, and cannot continue. And since everything's encrypted, I can't fix it with a live OS. So my question is: Does the key-slot= option makes LUKS only try that keyslot, or try that keyslot first and if it fails try the other ones? Assuming I am wrong and put key-slot=0 when I should have put key-slot=1, will LUKS try slot 0, fail, then try slot 1, and succeed? I've read through /etc/crypttab's manpage and found nothing but a reference to cryptsetup -S, but cannot find the manpage that describes this option. I can only find one page on cryptsetup, which doesn't include the -S option. Thank you very much!
The cryptsetup manual is divided into several pages. The crypttab man page should reference the cryptsetup-open man page. --key-slot, -S <0-N> This option selects a specific key-slot to compare the passphrase against. If the given passphrase would only match a different key-slot, the operation fails. So you'll have to correct or remove the key-slot option in /etc/crypttab. Note that by default, all slots are tried, so the only advantage of specifying a key slot explicitly is a speed improvement. You can recover from a live USB (I think the Debian netinst image has the necessary tooling, but I haven't tried this recently). The file you need isn't encrypted, since it's needed to decrypt the rest of the system. You should be able to fix your system from the initramfs as well (don't you get a shell prompt?), by running cryptsetup, mount and any other necessary step manually until you gain access to the root filesystem.
Does crypttab's "key-slot" option mean LUKS will try that keyslot "only", or "first"?
1,714,761,042,000
Several years ago I installed Debian on my 500 GiB hard disk. During installation I chose to have encrypted filesystem. So installer created one small unencrypted boot partition (I guess that grub configuration is kept there) and one large LUKS encrypted partition. This large encrypted partition is a physical volume, which is the only member of a volume group, on which two logical volumes are created - one for swap and one for everything else. And everything was working fine in this configuration for several years without me thinking too much about it. Few days ago I bought new 2 TiB hard drive and decided to move my system to it. I copied my old hard drive to my new hard drive - bit by bit, simple by "cat /dev/sda > /dev/sdb". After that my computer was booting fine from my new hard disk, but it was only 500 GiB large, because it had partition table copied from the old hard disk. So I tried to enlarge it. First I created new (the third) partition on it. I created physical volume on it. I LUKS encrypted this physical volume (using "cryptsetup" command), with the same password as the old partition had. I added this physical volume to already existing volume group. I enlarged already existing logical volume, enlarging filesystem sitting on it as well. I did it all using Knoppix booted from CD. I did not alter grub configuration. Then (I was still at Knoppix) I tried to mount the filesystem from these two encrypted partitions - it worked well, it was one filesystem, 2 TiB large and all files were there. Then I tried booting from this hard disk. Grub asked me for a password to a LUKS encrypted partition and then failed with these messages: In these messages we can see uuid "EFc551-(...)" - I don't know what this uuid is. Commands that grub executes while booting are those (the photo is blurry, but I hope you can read the text): String "9e5881c3(...)" which you can see in this command is uuid of the old encrypted partition. Now I want to achieve two things: understand what goes on, be able to boot from my 2 TiB hard disk. Could you help me to achieve those two goals? Final solution Marmarek's idea was the right one. Contrary to what I thought at the beginning, in my setup (which is, I guess, default Debian setup) grub has nothing to do with LVM. Grub boots small unencrypted boot partition and it's job of that partition's init to decrypt and mount encrypted LVM volumes. So I didn't have to tinker with grub but with initrd. Marmarek suggested to recreate it under Knoppix using update-initramfs, but it did not work. Initrd created by update-initramfs lacked /conf/conf.d/cryptroot file (my original initrd had it) and because of that it didn't try to decrypt any partitions at all. I guessed that maybe it lacked that file because when I run update-initramfs command those partitions were not unencrypted and LVM volumes were not activated? So I just unpacked my original initrd image and put into its init file such line: cryptsetup luksOpen UUID=some-uuid udisks-luks-uuid-this-uuid I don't know if the last argument to cryptsetup must be exactly as I gave it - I just mimicked what I saw in some examples. The line had to be put in such place inside init where /dev is already mounted - I found such place by trial and error. This was the place right after the line: run_scripts /scripts/init-top When I packed back this modified initrd and booted my computer, it asked me for two passwords and worked well.
This uuid "EFc551-(...)" probably is your 2TB disk (namely encrypted PV on it). You need to tell somehow your initramfs about this second PV. Probably update-initramfs will do it, something like (from knoppix): (assuming you've mounted your disk in /mnt/disk) cp -a /dev/* /mnt/disk/dev/ chroot /mnt/disk mount /proc mount /sys update-initramfs -u -k all
after adding one more physical volume and enlarging logical volume, grub fails
1,714,761,042,000
Here's my setup $ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS nvme0n1 259:0 0 238.5G 0 disk ├─nvme0n1p1 259:1 0 100M 0 part /boot/efi ├─nvme0n1p2 259:2 0 250M 0 part /boot └─nvme0n1p3 259:3 0 238.1G 0 part └─Be-Water-My-Friend 254:0 0 238.1G 0 crypt ├─Arch-swap 254:1 0 2G 0 lvm [SWAP] └─Arch-root 254:2 0 236.1G 0 lvm / I have one main LUKS2-encrypted partition (nvme0n1p3), with one LVM volume group (Be-Water-My-Friend) containing two logical volumes Arch-swap and Arch-root. The Arch-root is a btrfs. When I set that up, I only chose 2GB of swap which turns out to be insufficient for my needs. I would like to increase that to 24GB of swap. For that, I think I need to boot on a USB live key decrypt the LUKS2 partition mount the Arch-root volume shrink the Arch-root file system with btrfs filesystem resize -22g remove the Arch-swap logical volume recreate the Arch-swap logical volume taking all available space in the Be-Water-My-Friend volume group. Is there anything I'm missing? I really don't want to screw that up!
You need one extra step between 4 and 5 -- shrink the Arch-root logical volume using lvresize -L-22G Arch/root (lvresize has option --resizefs to resize both the LV and the filesystem, but it currently doesn't support btrfs so you can't use it here). This answer nicely explains difference between resizing filesystem (btrfs in your case) and the block device (LVM logical volume). You also might want to use --uuid with mkswap to set your old swap UUID for the new swap. Swaps are usually not referred with UUID in /etc/fstab and GRUB, but using the old UUID might save you some problems. Also if you just want a bigger swap, you can create a swap file on btrfs and use it as second swap.
Shrink root LVM on LUKS2 btrfs root partition to enlarge swap partition
1,714,761,042,000
luks1 has limit of 8. But I just accidentally add 9 slots to luks2 (from 0 to 8). I wonder what is the limit for luks2? Keyslots: 0: luks2 Key: 512 bits Priority: normal Cipher: aes-xts-plain64 Cipher key: 512 bits PBKDF: argon2i Time cost: 5 Memory: 1048576 Threads: 4 Salt: 32 ff 35 1e a2 b5 64 a7 fe f9 6e 7d 12 75 75 d5 a4 e7 47 39 80 96 1d 76 b1 35 b3 77 0a 85 46 ac AF stripes: 4000 AF hash: sha256 Area offset:32768 [bytes] Area length:258048 [bytes] Digest ID: 0 1: luks2 Key: 512 bits Priority: normal Cipher: aes-xts-plain64 Cipher key: 512 bits PBKDF: argon2i Time cost: 5 Memory: 1048576 Threads: 4 Salt: 55 7b 9a 4c d8 53 2b bb 90 af 57 44 67 b5 0c 03 85 a1 5d 70 e4 1e b0 5f 97 1a f3 0e f2 8c dc b2 AF stripes: 4000 AF hash: sha256 Area offset:290816 [bytes] Area length:258048 [bytes] Digest ID: 0 2: luks2 Key: 512 bits Priority: normal Cipher: aes-xts-plain64 Cipher key: 512 bits PBKDF: argon2i Time cost: 5 Memory: 1048576 Threads: 4 Salt: ac 24 09 ca f9 24 52 3d 49 d3 c9 89 63 d0 1d 61 83 4a aa ed 75 a2 39 ec 3f f8 ab 95 5d 0c 49 aa AF stripes: 4000 AF hash: sha256 Area offset:1064960 [bytes] Area length:258048 [bytes] Digest ID: 0 3: luks2 Key: 512 bits Priority: normal Cipher: aes-xts-plain64 Cipher key: 512 bits PBKDF: argon2i Time cost: 5 Memory: 1048576 Threads: 4 Salt: 3d 37 41 20 93 44 55 62 c6 19 fe e0 7d ae 14 0d 67 86 6a 44 5e c8 8a f0 97 01 1d c7 c6 83 02 22 AF stripes: 4000 AF hash: sha256 Area offset:1323008 [bytes] Area length:258048 [bytes] Digest ID: 0 4: luks2 Key: 512 bits Priority: normal Cipher: aes-xts-plain64 Cipher key: 512 bits PBKDF: argon2i Time cost: 5 Memory: 1048576 Threads: 4 Salt: bf 6d a0 15 c9 8e 9b 49 12 84 86 6b 13 93 95 7d cf cf 8f 3a e2 b7 42 42 4c 59 a1 5c 23 cd e6 1a AF stripes: 4000 AF hash: sha256 Area offset:1581056 [bytes] Area length:258048 [bytes] Digest ID: 0 5: luks2 Key: 512 bits Priority: normal Cipher: aes-xts-plain64 Cipher key: 512 bits PBKDF: argon2i Time cost: 5 Memory: 1048576 Threads: 4 Salt: bd 76 ae e1 33 d3 7a 83 5b 59 d4 bc 46 17 36 ec e6 94 a5 b1 85 2d 00 9f a4 ff f4 02 cc b6 ca bc AF stripes: 4000 AF hash: sha256 Area offset:1839104 [bytes] Area length:258048 [bytes] Digest ID: 0 6: luks2 Key: 512 bits Priority: normal Cipher: aes-xts-plain64 Cipher key: 512 bits PBKDF: argon2i Time cost: 5 Memory: 1048576 Threads: 4 Salt: ab 7f dd e5 2c eb 32 51 97 9a 10 5e 70 75 1e 15 91 35 10 63 f5 8b b6 8c 7a 97 16 40 50 e6 89 fb AF stripes: 4000 AF hash: sha256 Area offset:2097152 [bytes] Area length:258048 [bytes] Digest ID: 0 7: luks2 Key: 512 bits Priority: normal Cipher: aes-xts-plain64 Cipher key: 512 bits PBKDF: argon2i Time cost: 5 Memory: 1048576 Threads: 4 Salt: aa 02 fd a2 fd 4a ee 84 1a 41 93 58 7a 25 c2 d4 0d 65 bc b4 5b 18 1a 05 4b 0a 81 f7 68 8c 9a 26 AF stripes: 4000 AF hash: sha256 Area offset:548864 [bytes] Area length:258048 [bytes] Digest ID: 0 8: luks2 Key: 512 bits Priority: normal Cipher: aes-xts-plain64 Cipher key: 512 bits PBKDF: argon2i Time cost: 5 Memory: 1048576 Threads: 4 Salt: 2b 04 62 29 e2 dc 42 b4 3a 28 8d 46 28 17 05 26 a1 05 86 62 95 8e 50 98 91 67 18 15 71 1c 8a f9 AF stripes: 4000 AF hash: sha256 Area offset:806912 [bytes] Area length:258048 [bytes] Digest ID: 0
For LUKS1, it's 8 key-slots, fixed. For LUKS2, currently it's at most 32 key-slots: #define LUKS2_KEYSLOTS_MAX 32 Trying to add more simply results in the error message "All key slots full.". However, the answer might not be so simple after all. The limit of 32 exists in code but is not mentioned at all in the LUKS2 On-Disk Format Specification. The LUKS2 header is actually capable of storing more than just 32 key-slots. Or it might not even be able to store 8 of them. It depends on the data offset, the size of the keyslots area, as well as the size required by each individual key. For a newly formatted header, it defaults to a large data offset so you might easily get 32 key-slots. If you converted from LUKS1 (with only 2MiB data offset), it's unchanged at 8 key-slots. If the data offset is smaller, it might be less than 8 key-slots. With a data offset of 1MiB, you only get 3 key-slots (cryptsetup emits a warning about it): # truncate -s 100M foobar.img # cryptsetup luksFormat --offset=2048 foobar.img WARNING: keyslots area (1015808 bytes) is very small, available LUKS2 keyslot count is very limited. # cryptsetup luksAddKey foobar.img # cryptsetup luksAddKey foobar.img # cryptsetup luksAddKey foobar.img No space for new keyslot. In this particular example, only 3 key-slots could be used before the header ran out of space to store more: # cryptsetup luksDump foobar.img LUKS header information Version: 2 Epoch: 5 Metadata area: 16384 [bytes] Keyslots area: 1015808 [bytes] [...] Keyslots: 0: luks2 [...] Area offset:32768 [bytes] Area length:258048 [bytes] Digest ID: 0 1: luks2 [...] Area offset:290816 [bytes] Area length:258048 [bytes] Digest ID: 0 2: luks2 [...] Area offset:548864 [bytes] Area length:258048 [bytes] Digest ID: 0 Here the total available keyslots area is only 1015808 bytes. Each key has a size of 257048 bytes. To store an additional key, 1032192 bytes would be required at minimum so, it just doesn't fit more keys in this particular case. If you don't care about MiB alignment, it's possible to make the offset even smaller, leaving you with only a single key-slot.
how many key slots does the luks2 support?
1,714,761,042,000
How do I format LUKS encrypted disk if I don't know the passphrase? I recently switched my HDD for a new SSD disk in my laptop and now when I connect the old HDD externally I can't mount disk event with the right passphrase (I assume I am doing something wrong at this point). However I want to format that disk and use it as regular external HDD, so is there a way how to do that? All tutorials I've found requires the knowledge of passphrase. This is what I get during unlocking Error unlocking /dev/dm-6: Command-line `cryptsetup luksOpen "/dev/dm-6" "luks-5a73e3e1-6b40-415f-8c40-ca14faecc7cb" ' exited with non-zero exit status 1: .
If you want to overwrite the data of the encrypted disk with non-encrypted data anyway (i.e. you don't care about the current contents), you don't have to unlock the drive/partition first. If the partition has a particular uncommon partition type, you might want to change that, but it is not necessary. You can just use mkfs.ext4 (or any filesystem type you prefer) on the partition which contains the LUKS encrypte partition.
Formatting LUKS encrypted disk
1,714,761,042,000
From: https://code.google.com/p/cryptsetup/wiki/FrequentlyAskedQuestions 6.15 Can I clone a LUKS container? You can, but it breaks security, because the cloned container has the same header and hence the same master key. You cannot change the master key on a LUKS container, even if you change the passphrase(s), the master key stays the same. That means whoever has access to one of the clones can decrypt them all, completely bypassing the passphrases. The right way to do this is to first luksFormat the target container, then to clone the contents of the source container, with both containers mapped, i.e. decrypted. You can clone the decrypted contents of a LUKS container in binary mode, although you may run into secondary issues with GUIDs in filesystems, partition tables, RAID-components and the like. These are just the normal problems binary cloning causes. Note that if you need to ship (e.g.) cloned LUKS containers with a default passphrase, that is fine as long as each container was individually created (and hence has its own master key). In this case, changing the default passphrase will make it secure again. I have two notebooks with root access installed with LUKS. I don't know if originally they where CLONED or not. My question: How can I create a HASH (ex.: sha512) from the LUKS master keys, so that I can compare the two, that if they are the same or not?
Thanks for the answers, I created a sed command for it: [root@notebook ~] test `whoami`=root && k=`cryptsetup luksDump -q --dump-master-key $(blkid | awk '/crypto_LUKS/ {print $1}' | cut -d: -f1 | head -1)` && echo "$k" | sed 's/^MK dump:/Fgkmtusjs\nMK dump:/g' | sed '1,/^Fgkmtusjs/d' | sed 's/.*\t//g' | sha512sum | sed "s/\-/`hostname`/g" Enter LUKS passphrase: d78abb0542736865f94704521609c230dac03a2f369d043ac212d6933b91410e06399e37f9c5cc88436a31737330c1c8eccb2c2f9f374d62f716432a32d50fac notebook.localdomain [root@notebook ~] tested on: Scientific Linux 6.4; Ubuntu 12.04
How can I get a HASH of the LUKS master key?
1,714,761,042,000
I've followed this question https://unix.stackexchange.com/questions/5017/ssh-to-decrypt-encrypted-lvm-during-headless-server-boot and successfully remotely decrypted my root drive. However, I have a second drive that I also have encrpted, and unfortunately dropbear is killed by the boot process before second passphrase prompt for the second drive is shown and the main open-ssh server has not yet started so once again the headless system sits waiting for input indefinitely. Is there any way round this? The second drive will be used for private cloud data storage so needs to be encrypted to protect the data, and needs to be decrypted before the cloud service starts (which I haven't chosen or installed yet). Ubuntu 13.10 x64 server running headless, though I'm not totally tied to Ubuntu it is kinda convenient.
The easiest way to solve this is to add a derived key from the first partition to to the second disk by running: /lib/cryptsetup/scripts/decrypt_derived sda1_crypt > new_key_file cryptsetup luksAddKey /dev/sdb1 new_key_file # prompts for an existing key shred -u new_key_file # remove the key file Then replace the sdb1_crypt line in /etc/crypttab with: sdb1_crypt /dev/sdb1 sda1_crypt \ luks,keyscript=/lib/cryptsetup/scripts/decrypt_derived With this, the second disk can be automatically mounted as soon as the first disk is available. Of course, you need to replace sda1 and sdb1 with the correct partitions/labels you use and do not forget to run update-initramfs -u after the change and to add a corresponding entry to /etc/fstab.
Decrypt second encrypted LVM during headless server boot?
1,714,761,042,000
I set up two LUKS encrypted drives to automount on system startup (using crypttab and a LUKS file key). It works fine, but unfortunately, if I disconnect one of the drives, the "auto decrypting" process doesn't run when I connect them to my PC again (running Fedora), and I have to do the mounting manually after unmounting. What command can I use to trigger the same process that systemd triggers on system startup to auto-mount and decrypt the drives on cue without further involvement from me? Or, failing that, how can I get systemd to auto-decrypt and mount them in those circumstances? For reference, this is the tutorial I used to set up the drives: https://www.golinuxcloud.com/mount-luks-encrypted-disk-partition-linux/
Each entry in /etc/crypttab is automatically converted by systemd's systemd-cryptsetup-generator into a Unit at boot or when you run sudo systemctl daemon-reload. For example, assuming the LUKS filesystem has a UUID of 1111... (I won't show it in full) the entry mytest /dev/disk/by-uuid/1111... /etc/luks/mykeyfile luks will generate the file /run/systemd/generator/[email protected], with a dependency BindsTo=dev-disk-by\x2duuid-1111....device and so on. This Unit runs cryptsetup when the UUID appears on a new disk. Similarly, each entry in /etc/fstab is automatically converted by systemd's systemd-fstab-generator into a Unit. For example, the entry /dev/mapper/mytest /mnt/mytest ext4 defaults will generate the file /run/systemd/generator/mnt-mytest.mount, which (perhaps via udev) will do a mount whenever the file /dev/mapper/mytest appears (it will be created by cryptsetup). You can check the status of these two Units with systemctl status systemd-cryptsetup@mytest mnt-mytest.mount Normally, when the decryption and mount has been done successfully they will show respectively as Active: active (exited) Active: active (mounted) To remove the disk cleanly, first give the commands sudo systemctl stop mnt-mytest.mount sudo systemctl stop systemd-cryptsetup@mytest When this disk is plugged in again, it will be mounted automatically. If the mounted disk is removed without doing this, the Units can be left in a failed state. Tail the systemd logs with journalctl -f to see the messages. Sometimes, on unplugging without unmounting, the kernel emits messages about i/o errors on the filesystem, but it manages to successfully unmount the filesystem, and the crypt detach successfully closes the device. In this case, when the device is plugged back in it should be successfully mounted automatically with no intervention. However, sometimes, after the i/o errors, the kernel decides to remount the filesystem read-only. This causes a problem for the crypt detach command, which fails because the device is busy (mounted, when it should have been unmounted by systemd). There seems to be a race problem as the filesystem usually ends up unmounted. When the device is plugged back in, the decryption says the volume is already active, so does not seem to trigger the mount. In this case, what seems to work is to clear the failed state of the stop job, and to run the detach command manually. When the device is plugged in again, the decryption mechanism starts off cleanly, and the mount gets done. The commands are sudo systemctl reset-failed systemd-cryptsetup@mytest sudo /usr/lib/systemd/systemd-cryptsetup detach mytest There is also a dev-mapper-mytest.device unit that can be checked for status. It remains in the active state if the detach failed, but will become inactive after the above manual detach command.
How do I manually trigger systemd's "auto mounting" of encrypted partitions/drives?
1,714,761,042,000
Currently, I do this to mount my encrypted thumbdrive: # Works! pass thumbdrive-password | # get device password entry from password manager head -n 1 | # get the device password itself sudo cryptsetup luksOpen /dev/sdb thumbdrive # unlock device udisksctl mount -b /dev/mapper/thumbdrive # mount device I'd like to do something like this instead: # Does not work! pass thumbdrive-password | head -n 1 | udisksctl unlock -b /dev/sdb # unlock device udisksctl mount -b /dev/mapper/luks-foobar # mount device with uuid "foobar" This would allow semi-privileged users (with permission to org.freedesktop.udisks2.filesystem-mount in polkit) to mount encrypted filesystems without using sudo. Udisks will not accept this piping method, because it uses an interactive password prompt. How can I provide my device password to udisksctl unlock without typing it in manually?
For udisks version 2.6.4 and later Note: I haven't tested this. I will once I get udisks 2.6.4 (whenever https://github.com/NixOS/nixpkgs/pull/41723 is backported to NixOS stable). Update: I have udisks 2.8.0 now, so I can test my solution. The only thing I missed was removing the trailing newline from the output of pass (...) | head (...). To trim that, either use the -n flag with echo, or append | tr -d '\n' to the head output . I've reflected this in my two solutions below. Generic (unsecure) solution Use the --key-file flag and substitute the password string in place of a keyfile. To unlock /dev/sdb with the password hunter2: udisksctl unlock --block-device /dev/sdb --key-file <(echo -n "hunter2") Passing sensitive data directly through the command line is unsafe, so this method should be avoided. pass implementation Instead, retrieve the password string with pass thumbdrive-password | head -n 1, trim the trailing newline, and substitute it in place of a keyfile: udisksctl unlock \ --block-device /dev/sdb \ --key-file <(pass thumbdrive-password | head -n 1 | tr -d '\n')
Provide password to udisks to unlock LUKS-encrypted device
1,714,761,042,000
I have a LUKS (Linux Unified Key Setup) partition that contains the rootfs. I wish to replace it with an unencrypted ext4 partition containing the same rootfs. Having searched far and wide I've seen no tools to aid in this process. Did I miss something? If not what is the solution? Use parted to delete the LUKS partition, create an ext4 partition and copy the rootfs into it?
This is a highly dangerous operation and should be executed with an abundance of caution. At the most simplified level, there is a utility called cryptsetup-reencrypt which allows for this operation. It explicitly calls out in it's man page: WARNING: The cryptsetup-reencrypt program is not resistant to hardware or kernel failures during reencryption (you can lose your data in this case). ALWAYS BE SURE YOU HAVE RELIABLE BACKUP BEFORE USING THIS TOOL. The reencryption can be temporarily suspended (by TERM signal or by using ctrl+c) but you need to retain temporary files named LUKS-<uuid>.[log|org|new]. LUKS device is unavailable until reencryption is finished though. As per the "Examples" section of the man page: Remove LUKS encryption completely cryptsetup-reencrypt /dev/sdb1 --decrypt This will likely need to be done from a "Live" environment (meaning a fully running ephemeral Linux enviornment like the one provided by Fedora Live or Ubuntu Live. As an alternative to this workflow, you can also take the more explicit route of backing up the data, removing the partition, and recreating it. Arch Linux has excellent documentation on this workflow as well as additional troubleshooting steps: https://wiki.archlinux.org/index.php/Removing_System_Encryption Again, it should be stressed that this is not a trivial operation and backups of all data are paramount in the event of catastrophic failure.
Replace LUKS partition with ext4 partition with same contents
1,714,761,042,000
This is a way I enter a new passphrase for my encrypted volume: sudo cryptsetup luksAddKey --key-slot 4 /dev/sda5 Unfortunately, cryptsetup does not ask to confirm the new passphrase. How to make sure that the passphrase I have entered is the one that I actually meant? I see two workarounds. Reboot and try the new passphrase. Add a temporary passphrase to another slot with the help of the new passphrase. Kill the temporary passphrase. Is there a more elegant way?
Just run cryptsetup with argument -y. From the manpage of cryptsetup: --verify-passphrase, -y query for passwords twice. Useful when creating a (regular) mapping for the first time, or when running luksFormat. The system would ask twice for an existing passphrase and for a new one: $ sudo cryptsetup luksAddKey -y --key-slot 4 /dev/sda5 Enter any existing passphrase: Verify passphrase: Enter new passphrase for key slot: Verify passphrase: Passphrases do not match.
How to double-check a LUKS passphrase
1,714,761,042,000
I'm trying to accomplish encrypting my OS w/ LVM on RHEL 7.2 and have it boot without entering a password by using a key on an unencrypted partition. LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert home rhel -wi-ao---- 22.35g root rhel -wi-ao---- 27.94g swap rhel -wi-ao---- 1.86g I created an unencrypted mount point /media where I generated a key using the following commands: dd bs=512 count=4 if=/dev/urandom of=/media/fdekey iflag=fullblock I added the key with my passphrase as follows: cryptsetup luksAddKey /dev/mapper/rhel-root /media/fdekey cryptsetup luksAddKey /dev/mapper/rhel-home /media/fdekey cryptsetup luksAddKey /dev/mapper/rhel-swap /media/fdekey I then edited /etc/crypttab to add the key: luks-b7ac522a-52fd-4540-917d-3454dafdf7dc UUID=b7ac522a-52fd-4540-917d-3454dafdf7dc /media/fdekey luks luks-ad431e02-a49d-4ba3-bf9c-06e7a9f9a7f9 UUID=ad431e02-a49d-4ba3-bf9c-06e7a9f9a7f9 /media/fdekey luks luks-a3819933-91d5-434b-bb6c-42d273bb34c2 UUID=a3819933-91d5-434b-bb6c-42d273bb34c2 /media/fdekey luks Modified /etc/dracut.conf # dracut modules to omit omit_dracutmodules+="systemd" # dracut modules to add to the default add_dracutmodules+="crypt lvm" Modified /etc/default/grub: rd.luks.key=/media/fdekey:LABEL=media Generated grub: grub2-mkconfig -o /boot/grub2/grub.cfg Generated initramfs: dracut -fv output of df -h: Filesystem Size Used Avail Use% Mounted on /dev/dm-3 28G 876M 28G 4% / devtmpfs 9.6G 0 9.6G 0% /dev tmpfs 9.6G 0 9.6G 0% /dev/shm tmpfs 9.6G 8.4M 9.6G 1% /run tmpfs 9.6G 0 9.6G 0% /sys/fs/cgroup /dev/sda2 4.5G 19M 4.2G 1% /media /dev/sda1 950M 133M 818M 14% /boot /dev/dm-5 23G 33M 23G 1% /home tmpfs 2.0G 0 2.0G 0% /run/user/0 output of fdisk -l: Disk /dev/sda: 64.4 GB, 64424509440 bytes, 125829120 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x000a0a6e Device Boot Start End Blocks Id System /dev/sda1 * 2048 1953791 975872 83 Linux /dev/sda2 1953792 11718655 4882432 83 Linux /dev/sda3 11718656 121114623 54697984 8e Linux LVM Disk /dev/mapper/rhel-root: 30.0 GB, 30001856512 bytes, 58597376 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/mapper/rhel-swap: 2000 MB, 2000683008 bytes, 3907584 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/mapper/luks-b7ac522a-52fd-4540-917d-3454dafdf7dc: 1998 MB, 1998585856 bytes, 3903488 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/mapper/luks-a3819933-91d5-434b-bb6c-42d273bb34c2: 30.0 GB, 29999759360 bytes, 58593280 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/mapper/rhel-home: 24.0 GB, 23999807488 bytes, 46874624 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/mapper/luks-ad431e02-a49d-4ba3-bf9c-06e7a9f9a7f9: 24.0 GB, 23997710336 bytes, 46870528 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes I feel like I'm missing some step(s). Upon boot up I am still asked for the passphrase.
I needed to add the path to my keyfile to dracut.confand rebuild initramfs. echo 'install_items+="/media/key"' >> /etc/dracut.conf dracut -fv
RHEL: FDE w/o password - boot from key on partition
1,714,761,042,000
I have a 1.5 TB partition of data, of which I accidentally overwrote some bytes at the beginning, due to a typo like: ssh somewhere command | dd of=/dev/sda3 // should have used quotes here, dd was executed locally by mistake! /dev/sda3 holds a LUKS container for the 1.5 TB ext4 partition with important data. When I noticed the problem I suspended and killed the dd; it should have overwritten less than 4K. Is there a way to recover the data? The computer has not been rebooted since, so whatever data was lost may still be in RAM? What do the first (say) 4k of a LUKS container contain? The partition is still mounted, but shows errors like [1157706.786897] EXT4-fs error (device dm-4): htree_dirblock_to_tree:896: inode #2: block 9249: comm ls: bad entry in directory: rec_len % 4 != 0 - offset=0(0), inode=2791782547, rec_len=44529, name_len=90 when trying to access it. Please help! Thanks! PS: I made some more tests and it seems more data was overwritten than just 4K :-( But still a very very small percentage of the 1.5 TB data! Can I still dump data from the uncontaminated region - maybe search with an ext4 recovery tool (if a good one exists) in a dump of the /dev/mapper/cr_sda3 - would that still work?
First: run dmsetup table --showkeys. Save the output of that somewhere safe—that big long hex string it shows is the actual encryption key (master key) used to secure your data. LUKS works by (simplification here) encrypting that key with your passphrase(s), so keep in mind that compromise of that key means game over—a passphrase change won't help. You have to wipe and recreate the LUKS partition. However, that same property means that even with a completely destroyed LUKS header, you can use that "table" (including the key) to read your data. The line you're looking for (and there may be many lines, LVM also uses Device Mapper) looks like this. Except instead of a bunch of 0's, you'll have random hex digits (the 0s is what you get without --showkey): Zia-swap_crypt: 0 11714560 crypt aes-xts-plain64 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0 253:1 0 (You do the above first because it's quick. If the power goes out, the machine crashes, etc. you can use it to recover your data. Without it, your data would be unrecoverable.) You want to keep the entire line. Better yet, the entire output. You can feed that line back to dmsetup to restore the table, and thus your access to the data, even without the LUKS header). Next, copy an image of the decrypted device somewhere. The decrypted device is the name you see in the dmsetup output above; in my case /dev/mapper/Zia-swap_crypt. It's the same one you'd put in /etc/fstab or pass to mount. Now, you can copy your data off the running system (e.g., with tar) or, if that fails, attempt an fsck to repair the filesystem. (Then copy data off). You can use that key to create a new LUKS header, and that should work—or just reinitialize it and start over. In the future, please make use of cryptsetup luksHeaderBackup.
Recover LUKS partition after overwriting first few bytes of LUKS container? System still up!
1,714,761,042,000
I'm actually trying to setup LUKS on a Red Hat 9.2 Server. Here is the problem : I can't do yum install cryptsetup-luks or dnf install cryptsetup-luks. When I try to use one of these command I have the following output : no match for parameter: cryptsetup-luks error: unable to find a match: cryptsetup-luks I don't really understand why, because I'm following procedures from IBM and Official Red Hat documentation. The links of these procedures are below : https://www.ibm.com/docs/en/order-management-sw/10.0?topic=considerations-encrypting-data-partitions-using-luks https://access.redhat.com/documentation/eng-eng/red_hat_enterprise_linux/9/html/security_hardening/encrypting-block-devices-using-luks_security-hardening#options-for-data-protection-during-luks2-re-encryption_encrypting-block-devices-using-luks I think the problem can comes from my repos because my repolist is as follow : Local-AppStream Local-BaseOS Tuleap epel epel-cisco-openh264 remi-modular remi-safe Anyone can explain me what am I doing wrong ? Or if I didn't see an important thing ? I tried to check if any other encryption solution was present on my system regarding which packages are installed that could be apparented to this. But even if I'm new on this activity, I didn't see any package that could be blocking me. Thanks
The package is called just cryptsetup. It used to be called cryptsetup-luks way back in RHEL 6 but since RHEL 7 it's just cryptsetup and it's in the BaseOS repository so you don't need any other extra repository.
How to install cryptsetup-luks
1,714,761,042,000
I already have a /boot partition on a USB stick and a LUKS partition on my computer, which correspond to a fulldisk encryption scheme with Ubuntu 21 I want to put the header of my LUKS partition onto the USB (either on the /boot partition or on another new partition on my USB) I have put the header (with cryptsetup luksHeaderBackup) in boot_header.luks on my boot partition (let say on device /dev/sda3) then in the crypttab file with the option header= I tried the following : /boot/boot_header.luks /dev/sda3/boot_header.luks /dev/sda3:/boot_header.luks and also /boot_header.luks:/dev/sda3 (to be sure) and the same with the uuid of /dev/sda3 and also with /dev/disk/by-uuid/[uuid] So I though the device sda3 wasn't mounted as it should be according to the doc of crypttab (if I understand it correctly) Optionally, the path [of the file containing the header] may be followed by ":" and an /etc/fstab device specification (e.g. starting with "UUID=" or similar); in which case, the path is relative to the device file system root. The device gets mounted automatically for LUKS device activation duration only. So I looked for mounting the boot partition before the execution of the cryptroot script with a custom script in local-bottom and init-bottom. And also as suggested here I tried to incorporate the header in the initramfs following this answer But the result at boot time is always the same : wrong value for 'header' option I found that it was quite feasible with arch but is there a way to do the same with Ubuntu (without modifying an existing script like cryptroot) ?
As pointed out in the comments by @A.B the solution is a raw partition that contains the header instead of the header file inside a partition (which is a hassle due to the need to mount the filesystem first) To copy the header (around 16MB for LUKS2) to a partition (/dev/sdb larger than the header size) two options. The first one is to copy the raw header with dd. First, you need to find the offset of the data (since the header always starts at 0). For a LUKS device /dev/sda4, use cryptsetup luksDump /dev/sda4 and look for the ligne offset in the section Data segments. Then find the filesystem block size with stat -fc %s /dev/sda4. And Finally, dd if=/dev/sda4 of=/dev/sdb bs=<fs_block_size> count=<data_offset> The second one is to pack all the header data into a backup file that will be copied to the partition /dev/sdb. Because having a backup file can lead to some security issues even if it is saved on your encrypted disk, it's better to create a ramdisk just for that file. mkdir /tmp/header_backup mount -t tmpfs -o size=512m tmpfs /tmp/header_backup cryptsetup luksHeaderBackup /dev/sda4 --header-backup-file /tmp/header_backup/header.luks dd if=/tmp/header_backup/header.luks of=/dev/sdb umount /tmp/header_backup Then in /etc/crypttab add the option header=/dev/sdb to the corresponding line (e.g sda4_crypt [UUID] none luks,discard,header=/dev/sdb) To erase the old LUKS header : cryptsetup luksErase /dev/sda4. That only wipes the keyslots but keep all the metadata. If you want (it's not necessary) to completely wipe the header you will need to have another filesystem header on it in order to keep a UUID onto that partition. But be aware that completely wiping the LUKS header may not results in a secure erase depending on your storage device (SSD or HDD). For SSD it's possible that the deleted block will stay in a queue until the device need to allocate more space. Otherwise to wipe the header : get the filesystem block size (<fs_block_size>) with stat -fc %s /dev/sda4, the LUKS data offset (<luks_data_offset>) with cryptsetup luksDump /dev/sdb, the UUID of the partition /dev/sda4 (<uuid_sda4>) and then : dd if=/dev/urandom of=/dev/sda4 bs=<fs_block_size> count=<luks_data_offset> mkfs.ext4 fs.img tune2fs -U <uuid_sda4> fs.img dd if=fs.img of=/dev/sda4 The partition /dev/sdb will have the same UUID that the LUKS one which may be a problem. You can change it without messing up the LUKS process with cryptsetup luksUUID /dev/sdb --uuid $(uuidgen) And finally update the initramfs with update-initramfs -u -k all
Detached LUKS header (on USB) for an existing full-disk encryption device with Ubuntu
1,714,761,042,000
we're trying to implement an initramfs with the intent of: Open a LUKS partition (using a key saved on TPM) Mounting the partition RO Mounting an OverlayFS switch_root to the new system The first part of the script seems to work fine. Our problem is in the "switch_root" part which ends in a kernel panic. Please note that we have the same problem also without the encryption/overlay part. The problem seems strictly related to the switch_root. We are using Yocto Sumo and the initramfs image is bundled with the kernel. Please find attached the kernel panic log. bash-4.4# exec switch_root /newroot /sbin/init BusyBox v1.27.2 (2020-05-20 09:00:12 UTC) multi-call binary. Us[ 593.127118] Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000100 [ 593.127118] age: switch_root [-c [/ d e59v3/.137247] CPU: 1 PID: 1 Comm: init Tainted: G W 4.14.98+g80655a2d3532 #1 [ 593.147478] Hardware name: Engicam i.Core MX8MM module (DT) onsole] N[E W _5R9O3O.T1 5N3E0W8_] Call trace: [ 593.157367] [<ffff000008089c30>] dump_backtrace+0x0/0x3c8 [ 593.162798] [<ffff00000808a00c>] show_stack+0x14/0x20 INIT [ARGS] [ 593.167891] [<ffff000008d50040>] dump_stack+0x9c/0xbc [ 593.174075] [<ffff0000080ce5b0>] panic+0x11c/0x28c [ 593.178902] [<ffff0000080d27d8>] complete_and_exit+0x0/0x20 [ 593.184495] [<ffff0000080d2840>] do_group_exit+0x38/0xa0 [ 593.189828] [<ffff0000080d28b8>] __wake_up_parent+0x0/0x28 [ 593.195338] Exception stack(0xffff00000805bec0 to 0xffff00000805c000) [ 593.201800] bec0: 0000000000000001 0000000000000001 0000000000000001 0000ffffa819b700 [ 593.209644] bee0: 0000000000000020 0000ffffcb90abc8 0000000000010000 0000ffffa81a4a18 [ 593.217490] bf00: 000000000000005e fffffffffffffff0 0101010101010101 0000000000000000 [ 593.225336] bf20: 0101010101010101 00000000004f2f10 0000ffffa7fe92c8 0000ffffa7fdbde0 [ 593.233184] bf40: 0000ffffa7fd7028 0000ffffa800cb68 00000000000005c2 0000000000000008 [ 593.241030] bf60: 0000000000000008 0000ffffa8122bb8 0000000000000001 0000ffffa8125000 [ 593.248874] bf80: 0000ffffa81265a0 0000ffffa81a3738 0000000000000001 0000000000000000 [ 593.256719] bfa0: 0000ffffa812a000 0000ffffcb90ac70 0000ffffa800c7f0 0000ffffcb90ac70 [ 593.264564] bfc0: 0000ffffa807946c 0000000060000000 0000000000000001 000000000000005e [ 593.272408] bfe0: 0000000000000000 0000000000000000 0000000000000000 0000000000000000 [ 593.280259] [<ffff000008083ac0>] el0_svc_naked+0x34/0x38 [ 593.285620] SMP: stopping secondary CPUs [ 593.290003] Kernel Offset: disabled [ 593.293520] CPU features: 0x080200c [ 593.297028] Memory Limit: none [ 593.300135] ---[ end Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000100 [ 593.300135] Thanks!
We found the solution. Basically, for testing purpose, we were executing our exec switch_root from a /bin/bash opened at the end of the init script. The problem is that switch_root requires to run with PID 1 but, in our setup, that PID was not available since it was occupied by init. PID 1: /init PID x: /bin/bash => exec switch_root from /bin/bash would assign the PID x to switch_root. That's not an option. So, for testing environment the solution was to call exec /bin/bash at the end of init and then, as usual, exec swtich_root. For production, we moved exec switch_root at the end of init (of course removing the call to /bin/bash).
switch_root from initramfs is failing
1,714,761,042,000
I recently installed Antergos (which is basically Arch) and set it to use full disk encryption. Now, I want to migrate from encrypt to sd-encrypt because I want to be able to hibernate and I couldn't put swap partition in the same LUKS volume.. Background During the setup: I used LUKS for / partition and swap partition, because my main SSD is small, I wanted to be able to hibernate and I have 32GB of RAM I created the encrypted swap partition on the second drive, I mounted swap partition (as well as another encrypted EXT4 partition from the second drive) using /etc/crypttab. I tested that installation works, grub let me boot into both linux and dual booted Windows, on Linux boot it decrypts and mounts both encrypted drives. However, I was getting error about not finding disk with the UUID of a swap drive, and Arch manual confirmed that encrypt which I got from installer can handle only one encrypted partition during boot. If I want to handle more of them I should move to sd-encrypt. However, even after reading the documentation I am not certain what I have to do in order to migrate to sd-encrypt. Details HOOKS="base udev autodetect modconf block keyboard keymap encrypt resume filesystems fsck" GRUB_CMDLINE_LINUX_DEFAULT="quiet resume=UUID=[encrypted swap UUID]" GRUB_CMDLINE_LINUX=cryptdevice=/dev/disk/by-uuid/[/ UUID]:Arch_crypt GRUB_ENABLE_CRYPTODISK=y /etc/crypttab swap_crypt /dev/disk/by-uuid/[/ UUID] password_file luks data_crypt /dev/disk/by-uuid/[/ UUID] password_file luks What else should I do after I change encrypt to sd-encrypt in HOOKS? Do I have to create a /etc/crypttab.initramfs and move swap_crypt there? Do I have to change luks to rd.luks? Both swap partition and / partition uses the same password, so according to the documentation both should be mounted on boot after I entered the password once, is that right? Documentation mentions luks.* and rd.luks.* params and similar - do I have to use them and if so, where should I put them?
I don't use Grub myself (but Arch and sd-encrypt) but from my kernel options I guess you would have to transform your configuration to look like (don't forget to backup your old configuration before switching). HOOKS="base systemd autodetect modconf block keyboard sd-vconsole sd-encrypt resume filesystems fsck" GRUB_CMDLINE_LINUX_DEFAULT="quiet resume=UUID=[decrypted swap UUID]" # I use resume=/dev/mapper/name-of-decrypted-device GRUB_CMDLINE_LINUX=luks.uuid=[/ encrypted UUID] luks.uuid=[swap encrypted UUID] GRUB_ENABLE_CRYPTODISK=y /etc/crypttab swap_crypt /dev/disk/by-uuid/[/ UUID] password_file luks data_crypt /dev/disk/by-uuid/[/ UUID] password_file luks Don't forget to run mkinitcpio -p linux or the equivalent to regenerate your initramfs, once the modification of the HOOKS have been done. And the grub.cfg file with grub-mkconfig -o /boot/grub/grub.cfg or something similar.
Migrate Arch from encrypt to sd-encrypt
1,714,761,042,000
I'm currently trying to teach myself some non-Windowsland operating systems, and I figured Ubuntu Server 16.04 would be the best place to start. Having "mastered" LVM, I'm trying to familiarize myself with cryptsetup and LUKS. I'm beginning to get it, but the one thing I'm perplexed by is... ...to what end are the random numbers generated by the --use-urandom or --use-random options used for? In the context of a cryptsetup command, for example: $ sudo cryptsetup luksFormat --cipher=aes-xts-plain64 --key-size=512 --hash=sha256 --use-random /dev/sdb1 --key-file=/crypto/keyfile I have done some reading here that using /dev/random (which is what I assume --use-random pulls its random number entropy from) can sometimes take a long time as the system generates more entropy, and so in certain instances it's recommended to use --use-urandom (which correspondingly pulls from /dev/urandom, which as I understand it is wholly pseudorandom) since the system won't get stuck waiting for the entropy pool to "refill." I don't FULLY understand cryptography, but I'm guessing that this option is used just the once, setting the initial state of the whole encryption scheme, and then we're good. If that's the case, I have no problem waiting for a good and chaotic bed of encryption to protect my data - but if I have to deal with that with every read and write to the disk... that could get old fast. Am I right? Is this just a one-time thing? Or, by setting --use-random in my command there, am I dooming myself to long LUKS opens and closes, reads and writes, etc?
using /dev/random (…) can sometimes take a long time as the system generates more entropy Correct. in certain instances it's recommended to use --use-urandom (which correspondingly pulls from /dev/urandom In virtually all circumstances, it's recommended not to use /dev/random. See Is a rand from /dev/urandom secure for a login key? or Myths about urandom. /dev/urandom, which as I understand it is wholly pseudorandom No, urandom is not pseudorandom. “Pseudorandom” means “deterministic”. urandom is not deterministic, it uses a (cryptographic-quality) deterministic random generator that is seeded by entropy, and thus produces an effectively endless stream of random bytes from a small amount of non-deterministic data. The options --use-random and --use-urandom only affect what happens when generating the key, not what happens when using the volume. So --use-random won't make using the volume any slower, it only makes the creation slower. Nonetheless, --use-urandom is generally fine, whereas --use-random is fine for interactive use but not recommended in scripts because it could block forever if there's nothing on the system to increase the entropy count. The only case in which /dev/urandom must not be used is on a freshly-installed, freshly-booted system that hasn't had time to gather entropy yet — unfortunately urandom will return predictable data in this case. As soon as the system has been used for a few minutes (and even across reboots once you've installed the system), /dev/urandom is safe.
What are the --use-urandom or --use-random options in LUKS used for?
1,714,761,042,000
If someone steals our master key to the FDE/LUKS, then we have to re-create the LUKS device, or is it enough to only change the LUKS password?
The master key is what encrypts the disk. All other keys and passwords provide access only to the master key. The reasoning behind this is that if you want to change the LUKS password (or have several of them) only a tiny amount of data needs to be encrypted or re-encrypted. The disadvantage is that once your master key is compromised your entire data set is compromised. Since your master key is no longer secure, it no longer matters what your LUKS passwords are. Rather, at this point you should replace and rebuild the entire LUKS volume, ensuring it has a fresh master key. You should also examine your security procedures to determine how your previous master key was compromised in the first place. Fortunately, the cryptsetup-reencrypt tool will allow you to do this in place provided you can take the volume offline for the duration of the process. As ever, taking a backup beforehand is strongly recommended. Synopsis from the man page: cryptsetup-reencrypt can be used to change reencryption parameters which otherwise require full on-disk data change (re-encryption). You can regenerate volume key (the real key used in on-disk encryption unclocked by passphrase), cipher, cipher mode.
If the LUKS master key has been copied once, does it matter that we change the LUKS pw?
1,714,761,042,000
I have 3 encrypted partitions, one for /, one for /home, and one for swap. It seemed silly to me to type in my password 3 times, so I replaced the swap partition with a swap file on the encrypted drive. However, even though I removed the entry from fstab, I am still being prompted for my password for the old swap partition on boot. When I boot, the OS asks me for the password for sda7_crypt which I would expect. However, after that, it asks me for the password for sda5_crypt. How do I disable sda5_crypt? /etc/fstab: /dev/mapper/sda7_crypt / ext4 errors=remount-ro 0 1 UUID=xxxxxxxxxxxxxxxxxxxxxxx /boot ext4 defaults 0 2 /dev/mapper/sdb5_crypt /home ext4 defaults 0 2 /myswapfile swap swap defaults 0 0 /etc/cryptsetup: sda7_crypt UUID=xxxxxxxxxxxxxxxxxxxxx none luks,discard sdb5_crypt UUID=xxxxxxxxxxxxxxxxxxxxx /keyfile luks,discard Update: more information to answer questions in the comments: System: Ubuntu 14.04 64-bit Desktop /boot/grub/grub.cfg: # # DO NOT EDIT THIS FILE # # It is automatically generated by grub-mkconfig using templates # from /etc/grub.d and settings from /etc/default/grub # ### BEGIN /etc/grub.d/00_header ### if [ -s $prefix/grubenv ]; then set have_grubenv=true load_env fi if [ "${next_entry}" ] ; then set default="${next_entry}" set next_entry= save_env next_entry set boot_once=true else set default="0" fi if [ x"${feature_menuentry_id}" = xy ]; then menuentry_id_option="--id" else menuentry_id_option="" fi export menuentry_id_option if [ "${prev_saved_entry}" ]; then set saved_entry="${prev_saved_entry}" save_env saved_entry set prev_saved_entry= save_env prev_saved_entry set boot_once=true fi function savedefault { if [ -z "${boot_once}" ]; then saved_entry="${chosen}" save_env saved_entry fi } function recordfail { set recordfail=1 if [ -n "${have_grubenv}" ]; then if [ -z "${boot_once}" ]; then save_env recordfail; fi; fi } function load_video { if [ x$feature_all_video_module = xy ]; then insmod all_video else insmod efi_gop insmod efi_uga insmod ieee1275_fb insmod vbe insmod vga insmod video_bochs insmod video_cirrus fi } if loadfont unicode ; then set gfxmode=auto load_video insmod gfxterm set locale_dir=$prefix/locale set lang=en_US insmod gettext fi terminal_output gfxterm if [ "${recordfail}" = 1 ] ; then set timeout=-1 else if [ x$feature_timeout_style = xy ] ; then set timeout_style=hidden set timeout=0 # Fallback hidden-timeout code in case the timeout_style feature is # unavailable. elif sleep --interruptible 0 ; then set timeout=0 fi fi ### END /etc/grub.d/00_header ### ### BEGIN /etc/grub.d/05_debian_theme ### set menu_color_normal=white/black set menu_color_highlight=black/light-gray if background_color 44,0,30; then clear fi ### END /etc/grub.d/05_debian_theme ### ### BEGIN /etc/grub.d/10_linux ### function gfxmode { set gfxpayload="${1}" if [ "${1}" = "keep" ]; then set vt_handoff=vt.handoff=7 else set vt_handoff= fi } if [ "${recordfail}" != 1 ]; then if [ -e ${prefix}/gfxblacklist.txt ]; then if hwmatch ${prefix}/gfxblacklist.txt 3; then if [ ${match} = 0 ]; then set linux_gfx_mode=keep else set linux_gfx_mode=text fi else set linux_gfx_mode=text fi else set linux_gfx_mode=keep fi else set linux_gfx_mode=text fi export linux_gfx_mode menuentry 'Ubuntu' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-c3444e01-a00a-4e4b-a73e-d213dc913a1e' { recordfail load_video gfxmode $linux_gfx_mode insmod gzio insmod part_msdos insmod ext2 set root='hd0,msdos6' if [ x$feature_platform_search_hint = xy ]; then search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos6 --hint-efi=hd0,msdos6 --hint-baremetal=ahci0,msdos6 52381e81-2730-434f-93be-e8223c4aa95c else search --no-floppy --fs-uuid --set=root 52381e81-2730-434f-93be-e8223c4aa95c fi linux /vmlinuz-3.13.0-35-generic root=UUID=xxxxxxxxxxxxxxxxxxxxxxx ro quiet splash $vt_handoff initrd /initrd.img-3.13.0-35-generic } submenu 'Advanced options for Ubuntu' $menuentry_id_option 'gnulinux-advanced-c3444e01-a00a-4e4b-a73e-d213dc913a1e' { menuentry 'Ubuntu, with Linux 3.13.0-35-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.13.0-35-generic-advanced-c3444e01-a00a-4e4b-a73e-d213dc913a1e' { recordfail load_video gfxmode $linux_gfx_mode insmod gzio insmod part_msdos insmod ext2 set root='hd0,msdos6' if [ x$feature_platform_search_hint = xy ]; then search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos6 --hint-efi=hd0,msdos6 --hint-baremetal=ahci0,msdos6 52381e81-2730-434f-93be-e8223c4aa95c else search --no-floppy --fs-uuid --set=root 52381e81-2730-434f-93be-e8223c4aa95c fi echo 'Loading Linux 3.13.0-35-generic ...' linux /vmlinuz-3.13.0-35-generic root=UUID=xxxxxxxxxxxxxxxx ro quiet splash $vt_handoff echo 'Loading initial ramdisk ...' initrd /initrd.img-3.13.0-35-generic } menuentry 'Ubuntu, with Linux 3.13.0-35-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.13.0-35-generic-recovery-c3444e01-a00a-4e4b-a73e-d213dc913a1e' { recordfail load_video insmod gzio insmod part_msdos insmod ext2 set root='hd0,msdos6' if [ x$feature_platform_search_hint = xy ]; then search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos6 --hint-efi=hd0,msdos6 --hint-baremetal=ahci0,msdos6 52381e81-2730-434f-93be-e8223c4aa95c else search --no-floppy --fs-uuid --set=root 52381e81-2730-434f-93be-e8223c4aa95c fi echo 'Loading Linux 3.13.0-35-generic ...' linux /vmlinuz-3.13.0-35-generic root=UUID=c3444e01-a00a-4e4b-a73e-d213dc913a1e ro recovery nomodeset echo 'Loading initial ramdisk ...' initrd /initrd.img-3.13.0-35-generic } menuentry 'Ubuntu, with Linux 3.13.0-34-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.13.0-34-generic-advanced-c3444e01-a00a-4e4b-a73e-d213dc913a1e' { recordfail load_video gfxmode $linux_gfx_mode insmod gzio insmod part_msdos insmod ext2 set root='hd0,msdos6' if [ x$feature_platform_search_hint = xy ]; then search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos6 --hint-efi=hd0,msdos6 --hint-baremetal=ahci0,msdos6 52381e81-2730-434f-93be-e8223c4aa95c else search --no-floppy --fs-uuid --set=root 52381e81-2730-434f-93be-e8223c4aa95c fi echo 'Loading Linux 3.13.0-34-generic ...' linux /vmlinuz-3.13.0-34-generic root=UUID=xxxxxxxxxxxxxxxxx ro quiet splash $vt_handoff echo 'Loading initial ramdisk ...' initrd /initrd.img-3.13.0-34-generic } menuentry 'Ubuntu, with Linux 3.13.0-34-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.13.0-34-generic-recovery-c3444e01-a00a-4e4b-a73e-d213dc913a1e' { recordfail load_video insmod gzio insmod part_msdos insmod ext2 set root='hd0,msdos6' if [ x$feature_platform_search_hint = xy ]; then search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos6 --hint-efi=hd0,msdos6 --hint-baremetal=ahci0,msdos6 52381e81-2730-434f-93be-e8223c4aa95c else search --no-floppy --fs-uuid --set=root 52381e81-2730-434f-93be-e8223c4aa95c fi echo 'Loading Linux 3.13.0-34-generic ...' linux /vmlinuz-3.13.0-34-generic root=UUID=xxxxxxxxxxxxxxxxxxxxxxxxx ro recovery nomodeset echo 'Loading initial ramdisk ...' initrd /initrd.img-3.13.0-34-generic } menuentry 'Ubuntu, with Linux 3.13.0-33-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.13.0-33-generic-advanced-c3444e01-a00a-4e4b-a73e-d213dc913a1e' { recordfail load_video gfxmode $linux_gfx_mode insmod gzio insmod part_msdos insmod ext2 set root='hd0,msdos6' if [ x$feature_platform_search_hint = xy ]; then search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos6 --hint-efi=hd0,msdos6 --hint-baremetal=ahci0,msdos6 52381e81-2730-434f-93be-e8223c4aa95c else search --no-floppy --fs-uuid --set=root 52381e81-2730-434f-93be-e8223c4aa95c fi echo 'Loading Linux 3.13.0-33-generic ...' linux /vmlinuz-3.13.0-33-generic root=UUID=xxxxxxxxxxxxxxxxx ro quiet splash $vt_handoff echo 'Loading initial ramdisk ...' initrd /initrd.img-3.13.0-33-generic } menuentry 'Ubuntu, with Linux 3.13.0-33-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.13.0-33-generic-recovery-c3444e01-a00a-4e4b-a73e-d213dc913a1e' { recordfail load_video insmod gzio insmod part_msdos insmod ext2 set root='hd0,msdos6' if [ x$feature_platform_search_hint = xy ]; then search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos6 --hint-efi=hd0,msdos6 --hint-baremetal=ahci0,msdos6 52381e81-2730-434f-93be-e8223c4aa95c else search --no-floppy --fs-uuid --set=root 52381e81-2730-434f-93be-e8223c4aa95c fi echo 'Loading Linux 3.13.0-33-generic ...' linux /vmlinuz-3.13.0-33-generic root=UUID=xxxxxxxxxxxxxxxxxxx ro recovery nomodeset echo 'Loading initial ramdisk ...' initrd /initrd.img-3.13.0-33-generic } menuentry 'Ubuntu, with Linux 3.13.0-32-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.13.0-32-generic-advanced-c3444e01-a00a-4e4b-a73e-d213dc913a1e' { recordfail load_video gfxmode $linux_gfx_mode insmod gzio insmod part_msdos insmod ext2 set root='hd0,msdos6' if [ x$feature_platform_search_hint = xy ]; then search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos6 --hint-efi=hd0,msdos6 --hint-baremetal=ahci0,msdos6 52381e81-2730-434f-93be-e8223c4aa95c else search --no-floppy --fs-uuid --set=root 52381e81-2730-434f-93be-e8223c4aa95c fi echo 'Loading Linux 3.13.0-32-generic ...' linux /vmlinuz-3.13.0-32-generic root=UUID=xxxxxxxxxxxxxxxxxxxx ro quiet splash $vt_handoff echo 'Loading initial ramdisk ...' initrd /initrd.img-3.13.0-32-generic } menuentry 'Ubuntu, with Linux 3.13.0-32-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.13.0-32-generic-recovery-c3444e01-a00a-4e4b-a73e-d213dc913a1e' { recordfail load_video insmod gzio insmod part_msdos insmod ext2 set root='hd0,msdos6' if [ x$feature_platform_search_hint = xy ]; then search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos6 --hint-efi=hd0,msdos6 --hint-baremetal=ahci0,msdos6 52381e81-2730-434f-93be-e8223c4aa95c else search --no-floppy --fs-uuid --set=root 52381e81-2730-434f-93be-e8223c4aa95c fi echo 'Loading Linux 3.13.0-32-generic ...' linux /vmlinuz-3.13.0-32-generic root=UUID=xxxxxxxxxxxxxxxxxxxxx ro recovery nomodeset echo 'Loading initial ramdisk ...' initrd /initrd.img-3.13.0-32-generic } } ### END /etc/grub.d/10_linux ### ### BEGIN /etc/grub.d/20_linux_xen ### ### END /etc/grub.d/20_linux_xen ### ### BEGIN /etc/grub.d/20_memtest86+ ### menuentry 'Memory test (memtest86+)' { insmod part_msdos insmod ext2 set root='hd0,msdos6' if [ x$feature_platform_search_hint = xy ]; then search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos6 --hint-efi=hd0,msdos6 --hint-baremetal=ahci0,msdos6 52381e81-2730-434f-93be-e8223c4aa95c else search --no-floppy --fs-uuid --set=root 52381e81-2730-434f-93be-e8223c4aa95c fi knetbsd /memtest86+.elf } menuentry 'Memory test (memtest86+, serial console 115200)' { insmod part_msdos insmod ext2 set root='hd0,msdos6' if [ x$feature_platform_search_hint = xy ]; then search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos6 --hint-efi=hd0,msdos6 --hint-baremetal=ahci0,msdos6 52381e81-2730-434f-93be-e8223c4aa95c else search --no-floppy --fs-uuid --set=root 52381e81-2730-434f-93be-e8223c4aa95c fi linux16 /memtest86+.bin console=ttyS0,115200n8 } ### END /etc/grub.d/20_memtest86+ ### ### BEGIN /etc/grub.d/30_os-prober ### ### END /etc/grub.d/30_os-prober ### ### BEGIN /etc/grub.d/30_uefi-firmware ### ### END /etc/grub.d/30_uefi-firmware ### ### BEGIN /etc/grub.d/40_custom ### # This file provides an easy way to add custom menu entries. Simply type the # menu entries you want to add after this comment. Be careful not to change # the 'exec tail' line above. ### END /etc/grub.d/40_custom ### ### BEGIN /etc/grub.d/41_custom ### if [ -f ${config_directory}/custom.cfg ]; then source ${config_directory}/custom.cfg elif [ -z "${config_directory}" -a -f $prefix/custom.cfg ]; then source $prefix/custom.cfg; fi ### END /etc/grub.d/41_custom ### /etc/default/grub # If you change this file, run 'update-grub' afterwards to update # /boot/grub/grub.cfg. # For full documentation of the options in this file, see: # info -f grub -n 'Simple configuration' GRUB_DEFAULT=0 GRUB_HIDDEN_TIMEOUT=0 GRUB_HIDDEN_TIMEOUT_QUIET=true GRUB_TIMEOUT=10 GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian` GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" GRUB_CMDLINE_LINUX="" # Uncomment to enable BadRAM filtering, modify to suit your needs # This works with Linux (no patch required) and with any kernel that obtains # the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...) #GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef" # Uncomment to disable graphical terminal (grub-pc only) #GRUB_TERMINAL=console # The resolution used on graphical terminal # note that you can use only modes which your graphic card supports via VBE # you can see them in real GRUB with the command `vbeinfo' #GRUB_GFXMODE=640x480 # Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux #GRUB_DISABLE_LINUX_UUID=true # Uncomment to disable generation of recovery mode menu entries #GRUB_DISABLE_RECOVERY="true" # Uncomment to get a beep at grub start #GRUB_INIT_TUNE="480 440 1"
Encrypted volumes are listed in /etc/crypttab. You need to update that file, to remove the volume that you no longer want mounted. After doing this, you need to rebuild the initramfs, by running sudo update-initramfs -u If you want to have three encrypted partitions on the same disk, then you should have a single encrypted volume instead of three, and create partitions inside it (with LVM: make the encrypted volume a physical volume, create a volume group containing that physical volume, and create a logical volume for /, one for /home and one for swap). Ubuntu's startup scripts don't handle sharing the passphrase between volumes, though you can tweak them to do that; see bug #1022815. By the way, you can use a random key (generated at each boot) for the swap volume, if you don't use hibernation.
Luks Partition Mounting After Removing From fstab
1,714,761,042,000
For the tl;dr, skip to the bottom. I have a dual-boot setup with Mac OS X at the beginning of my drive and three GNU/Linux partitions at the end of the drive. I don't have the relevant machine on hand to give an fdisk dump, but here's a rough overview of the original disk layout: /dev/sda1: EFI System Partition /dev/sda2: Macintosh HD (main OS X partition) /dev/sda3: Recovery HD (part of OS X's recovery system) /dev/sda4: / /dev/sda5: /home inside a LUKS container /dev/sda6: swapspace inside a LUKS container I'm reinstalling GNU/Linux on this system and as a part of that, I want to make / encrypted. However, that requires a separate /boot. In order to create that partition, I resized Macintosh HD and moved Recovery HD back to the end of Macintosh HD. I also took the opportunity to make my / larger. So the end result is a disk that looks like this: /dev/sda1: EFI System Partition /dev/sda2: Macintosh HD (main OS X partition) (smaller than before) /dev/sda3: Recovery HD (part of OS X's recovery system) /dev/sda4: /boot /dev/sda5: / (larger than before, and now inside a LUKS container) /dev/sda6: /home inside a LUKS container /dev/sda7: swapspace inside a LUKS container tl;dr: Here's the problem: due to the order in which I configured things, I now have a cryptsetup-created LUKS container in the middle of /dev/sda5. Because it's in the middle, nothing can find it to unlock/mount/recover it. How can I move my cryptcontainer to the beginning of the partition? Probably this involves two distinct steps (actually finding the thing on disk, then using that information to move it), but I'm not sure. Googling's turned up nothing.
LUKS has a distinct header, you could find possible offsets with grep: # grep -a -b --only-matching 'LUKS' /dev/sda5 1832480940:LUKS 1959072314:LUKS 2019974297:LUKS For each possible offset you find, you could create a loop device and see if it's a valid LUKS device or not: # losetup --find --show --offset 1832480940 --read-only /dev/sda5 /dev/loop3 # cryptsetup luksOpen /dev/loop3 luksloop3 ...mount -o ro, ls, backup, umount... # cryptsetup luksClose luksloop3 # losetup -d /dev/loop3 Once you have found the correct offset, you can move it to the beginning of the partition using dd. This is dangerous, if you get the offset wrong or cancel the operation, the data is lost. So you should make a backup first in any case. # dd if=/dev/sda5 of=/dev/sda5 bs=1M iflag=skip_bytes skip=1832480940 See if it worked: # cryptsetup luksOpen /dev/sda5 luks Restore from backup otherwise.
How can move a LUKS container from the middle of a partition to the beginning?
1,714,761,042,000
I've gotten myself in a bit of a bind, here. A while ago I set up an encrypted Unbuntu 13.04 under Xen. It's virtual disk is an LVM LV. This LV was presented to the DomU as a (whole) physical disk during installation, and I let Ubuntu's installer set up encrypted root and swap (using LVM). However, I forgot to write down the root pw. Or I wrote it down wrong. After a power failure the other day I cannot get back into the machine as root. I have the passphrase for the DomU:s LVM partition though, so the DomU goes up. I just can't log in. Booting with init=/bin/bash does not work, since init needs to unlock the encrypted partition. I can't figure out how to open the LVM-containg partition the LVM LV from Dom0, either, since ´cryptsetup luksOpen´ won't accept an offset in the LVM LV. Does anyone know how to get into the LV - Partition - (LVM) - LV and reset the root password?
I'm not familiar with Xen. With KVM, I'd just make the VM boot up in a rescue or live CD, and chroot from there. As you would do if you had this problem on your real desktop. If all you need is an offset, in general you can use losetup for that. Or more specifically offsets for partition tables, you can use partx or kpartx. If you have a partitioned LV, you could get the offsets using parted: parted /dev/mapper/lvm-vmfoobar unit b print and it would print partition offsets (in bytes) like so Number Start End Size Type File system Flags 1 1048576B 2148532223B 2147483648B primary fat32 lba 2 2149580800B 3223322623B 1073741824B primary ext2 boot 3 3224371200B 13961789439B 10737418240B primary ext2 So suppose you wanted to access the partition 3 more direct like, using the offset 3224371200, you could do it with losetup like this: # losetup -f --show -o 3224371200 --sizelimit 10737418240 /dev/mapper/lvm-foobar /dev/loop0 (sizelimit is optional, for safety so you can not write past the end of the partition) and verify that it's the correct thing file -s /dev/loop0 /dev/loop0: Linux rev 1.0 ext2 filesystem data, UUID... Alternatively if you have partx or kpartx, a simple partx -a /dev/mapper/lvm-foobar should work and you'd find the mapped partitions like /dev/mapper/lvm-foobarp1 or similar (kpartx may use different names from partx). And then you can work with that mapped device (cryptsetup luksOpen, vgchange, ...) so you should eventually be able to mount the root filesystem of the VM, chroot, and passwd a new root password.
Open luks-encrypted partition from virtual DomU LVM disk containing another LVM
1,714,761,042,000
I just read this discussion between Linus Torvalds and (among others) Milan Broz, one of dm-crypt's maintainers. I am intrigued by the the following part of the discussion : Linus Torvalds: I thought the people who used hidden ("deniable") things didn't actually ever use the outer filesystem at all, exactly so that they can just put the real encrypted thing in there and nor worry about it. Milan Broz: Well, they actually should "use" outer from time to time so the data looks "recent" and for the whole "hidden OS" they should be even able to boot to outer decoy OS on request, just to show that something working is there. In theory, I agree with Milan's statement, using the decoy data is a good thing to do to increase credibility. But how do you achieve that in practice? E.g., how can you write to the outer volume without risking to overwrite the inner volume? I have been using hidden LUKS volumes for years now, combining detachable headers and data offset. Usually I start by creating a small LUKS-encrypted outer volume (let's say 20 GB), I format it with EXT4, I fill it with decoy data, then I increase this outer volume's size (to for example 500 GB), and I create the inner volume with an offset of 25GB for example. And after that I do what Linus said, I religiously avoid to touch the outer volume's decoy data, out of fear of damaging the inner volume's data. Is there a way to refresh the outer volume's data, without risking to damage the inner volume's data? E.g., is there a tool to write specifically on the 20 first Gigs of the outer volume, making sure to not mess with the 480 following gigs? I am using both HDDs and SSDs, so the question applies to both.
There are probably a few ways to do this with reasonable safety, with potentially different approaches if starting with a new outer volume or an existing one. Probably the best way to do this would be with the debugfs setb command on the unmounted outer filesystem device to mark range(s) of blocks that belong to the inner volume before mounting the outer filesystem and updating files there.: debugfs -c -R "setb <inner_start_blk> <inner_count>" /dev/<outer> setb block [count] Mark the block number block as allocated. If the optional argument "count" is present, then "count" blocks starting at block number "block" will be marked as allocated. If there are disjoint ranges to the file, then multiple setb commands could be scripted writing by piping a file with block ranges like: setb <range1> <count1> setb <range2> <count2> : to debugfs reading the file debugfs -c -f <file> /dev/<outer>. If you wanted to be a bit more clever than just packing the inner volume at the end of the outer filesystem, the inner volume could initially be created with fallocate -s 32M mydir/inner in the the outer filesystem, then the block range could be generated from debugfs: # debugfs -c -R "stat mydir/inner" /dev/vg_root/lvhome Inode: 263236 Type: regular Mode: 0664 Flags: 0x80000 Generation: 2399864846 Version: 0x00000000:00000001 User: 1000 Group: 1000 Project: 0 Size: 32499577 File ACL: 0 Links: 1 Blockcount: 63480 Fragment: Address: 0 Number: 0 Size: 0 ctime: 0x63c98fc0:62bb0a38 -- Thu Jan 19 11:45:20 2023 atime: 0x63cee835:5e019630 -- Mon Jan 23 13:04:05 2023 mtime: 0x63c98fc0:559e2928 -- Thu Jan 19 11:45:20 2023 crtime: 0x63c98fc0:41974a6c -- Thu Jan 19 11:45:20 2023 Size of extra inode fields: 32 Extended attributes: security.selinux (37) = "unconfined_u:object_r:user_home_t:s0\000" EXTENTS: (0-7934):966656-974590 In this case, the ~32MB (7935x4KiB block) file is in blocks 966656-974590, so this would use setb 966656 7935 to mark those blocks used. The inode should be erased with clri <inum> to prevent the allocated block range from being visible afterward. The blocks allocated in the outer filesystem by debugfs setb would remain allocated until the next time that e2fsck was run on the outer filesystem. That could potentially "expose" those blocks are in use if someone was really paying attention, so they could optionally be cleared again after the outer filesystem was unmounted, using `debugfs -c -R "clrb <inner_start> <inner_count>" /dev/", or kept allocated to avoid the inner filesystem from potentially being corrupted.
How to refresh decoy data on a plausible deniability dm-crypt scheme?
1,714,761,042,000
I have built a kali live usb 32GB with encrypted persistence. Now I have copied the 32GB content to a 64GB usb device using the dd command, and everything is working fine on the new 64 GB device. Since the 64 GB stick has free available space, I want to expand the encrypted (LUKS) partition. Unfortunately, so far I have no reliable information on how to implement this partition extension. Does anyone have any suggestions? Thank you very much!
I finally managed to resize the new 64GB device, taking in consideration the information found here. For the sake of completeness, I have included the output of the single commands. Start kali-live system using the original usb device (32GB). Inserted the usb stick (64GB) containing the LUKS partition to be modified (expanded). Using GParted, create a new partition (8 GB), saving the remaining free space for other use. Delete LUKS partition, delete partition to be added (8GB), and create new one (size old_LUKS_partition + 8GB) sudo fdisk /dev/sdb Welcome to fdisk (util-linux 2.37.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): p Disk /dev/sdb: 59.63 GiB, 64023257088 bytes, 125045424 sectors Disk model: Extreme Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x59536a28 Device Boot Start End Sectors Size Id Type /dev/sdb1 * 64 7866239 7866176 3.8G 17 Hidden HPFS/NTFS /dev/sdb2 7866240 7867711 1472 736K 1 FAT12 /dev/sdb3 7868416 60088319 52219904 24.9G 83 Linux /dev/sdb4 60088320 76865535 16777216 8G 83 Linux Command (m for help): d Partition number (1-4, default 4): Partition 4 has been deleted. Command (m for help): d Partition number (1-3, default 3): Partition 3 has been deleted. Command (m for help): n Partition type p primary (2 primary, 0 extended, 2 free) e extended (container for logical partitions) Select (default p): p Partition number (3,4, default 3): First sector (7867712-125045423, default 7868416): Last sector, +/-sectors or +/-size{K,M,G,T,P} (7868416-125045423, default 125045423): -22.9G Created a new partition 3 of type 'Linux' and of size 32.9 GiB. Partition #3 contains a crypto_LUKS signature. Do you want to remove the signature? [Y]es/[N]o: N Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks. Unlock the partition: sudo cryptsetup luksOpen /dev/sdb3 persistence Enter passphrase for /dev/sdb3: Filesystem Check: sudo e2fsck -f /dev/mapper/persistence e2fsck 1.46.4 (18-Aug-2021) persistence: recovering journal Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information Free blocks count wrong (2400085, counted=2397778). Fix<y>? yes Free inodes count wrong (1243709, counted=1243712). Fix<y>? yes persistence: ***** FILE SYSTEM WAS MODIFIED ***** persistence: 388288/1632000 files (6.2% non-contiguous), 4125614/6523392 blocks Resize the Partition: sudo resize2fs /dev/mapper/persistence resize2fs 1.46.4 (18-Aug-2021) Resizing the filesystem on /dev/mapper/persistence to 8613632 (4k) blocks. The filesystem on /dev/mapper/persistence is now 8613632 (4k) blocks long. Final result of the running kali-live file system itself on the 64GB stick: I hope this can help people with similar problems.
Extend LUKS partition
1,624,309,449,000
I am trying to unlock my root encrypted Debian Buster on an acepc T11. I installed dropbear, added DEVICE=enp1s0 IP=:::::enp1s0:dhcp to /etc/initramfs-tools/initramfs.conf and executed update-initramfs -k all -u. When the initramfs is loaded, I get multple times the error ipconfig: enp1s0: SIOCGIFINDEX: No such device ipconfig: no devices to configure and a single time the error /scripts/init-premount/dropbear: .: line 275: can't open '/run/net-enp1s0.conf': No such file or directory I can then only proceed by entering the LUKS password at the machine. A few things I tried: The interface enp1s0 is the one that is shown by ip a once the system is fully booted, but seems to be incorrect in the initram?! I tried to omit the interface name so the initram would figure the correct one out by itself, but then I still receive the ipconfig: no devices to configure errors and the last error changes to /scripts/init-premount/dropbear: .: line 275: can't open '/run/net-*.conf': No such file or directory. I also tried the "standard" interface names eth0 and eth1 but got the same errors. I edited /boot/cmdline.txt according to this answer, but that didn't help. I added virtio, virtio_pci and virtio_net to /etc/initramfs/modules as that seemed to help someone with a similar issue (can not find the webpage anymore), but with no success. I added ip=dhcp to GRUB_CMDLINE_LINUX_DEFAULT in /etc/default/grub as described in this article. No change at all. I created the file /etc/initramfs-tools/conf.d/cryptroot with content target=mmcblk0p3_crypt,source=UUID=49429a5f-f094-485c-8c2e-45f53f81919f as suggested on this Q/A site. (The content of /etc/crypttab ist mmcblk0p3_crypt UUID=49429a5f-f094-485c-8c2e-45f53f81919f none luks,discard,initramfs, by the way.) My guess is, that either the network is not up or a driver is missing in that initramfs phase or I have the wrong interface name, but I do not know how to fix the first or how to find out the correct name. Any help is appreciated.
Turned out, that indeed the network driver was missing in the initramfs. The module argument MODULES=most in /etc/initramfs-tools/initramfs.conf was not sufficient. Thanks to this answer, I found my network driver using lspci -v and added the appropriate module to /etc/initramfs-tools/modules. After rebuilding the initramfs, I still receive an error about some module that can not be loaded but the network is running nonetheless and I can unlock the LUKS device remotely.
Unlock LUKS device remotely - ipconfig: no devices to configure
1,624,309,449,000
I have installed system on ext4 filesystem on lvm (vg name encrypted, root is called encrypted-root) on luks. When I'm trying to run fstrim /, I get fstrim: /: the discard operation is not supported. My /etc/crypttab contains cryptroot UUID=5ddb7e3a-dcbe-442d-85e8-359e944d0717 none luks,discard,lvm=encrypted /etc/lvm/lvm.conf contains issue_discards = 1 /etc/initramfs-tools/conf.d/cryptroot contains only CRYPTROOT=target=encrypted-root,source=/dev/disk/by-uuid/5ddb7e3a-dcbe-442d-85e8-359e944d0717 (I used update-initramfs -k all -c to create initramfs). /etc/default/grub contains GRUB_CMDLINE_LINUX="cryptops=target=encrypted-root,source=/dev/disk/by-uuid/5ddb7e3a-dcbe-442d-85e8-359e944d0717,lvm=encrypted" I have tried to manually put rd.luks.options=discard as parameter for linux in grub. I have tried refresh option of cryptsetup utility (cryptsetup --allow-discards refreshdevice), but it does not seem to have one (cryptsetup: Unknown action). Physical device apparently has TRIM support, when I run fstrim /boot it works (it's same device, just not encrypted). dmsetup table command does not show allow_discards for cryptroot. When I boot from USB and manually decrypt (with --allow-discards argument to cryptsetup) and mount root partition, it works. I have tried to use --persistent option, but it said that it couldn't make it persistent. I'm lost. What should I do to make fstrim / work? Something tells me I should somehow modify boot options in grub, but I'm not sure how. I'm also not sure if line in /etc/crypttab is used at all (I changed it to cryptroot after install, it seems to do nothing even if I change it). I'm running Linux Mint 19.3. Links: I have followed this guide to encrypt system: link Arch-wiki section about SSDs and dm-crypt possibly relevant: 1, 2
I figured out problem was on encryption level. (You can run dmsetup table as root to see if your device shows allow_discards.) This fixed the problem for me: Edit /etc/initramfs-tools/conf.d/cryptroot, add discard option for particular device. In my case line looked like this: CRYPTROOT=target=encrypted-root,source=/dev/disk/by-uuid/5ddb7e3a-dcbe-442d-85e8-359e944d0717,discard. Run update-initramfs -k all -c. (Maybe make backup first in case there is something wrong with your config and you don't know about it.)
How to enable discards on encrypted root
1,624,309,449,000
I have a dual boot setup on a Windows machine with multiple partitions, the two Linux ones being encrypted using LUKS. For some reason, I can no longer restore a backup to my second Linux LUKS partition and properly boot into the LUKS splash screen so I can enter my decryption password. Instead, it tries to boot the root partition and throws a dracut error. The key partitions in my setup for this question are: /dev/sda1 EFI /dev/sda5 Boot for Fedora I /dev/sda6 Root for Fedora I -- ENCRYPTED LUKS /dev/sda7 Boot for Fedora II /dev/sda8 Root for Fedora II -- ENCRYPTED LUKS I use one combo (Fedora I Root and Boot) for my main driver. Then, if I want to try something new, I backup everything using tar and install it to to the second combo (Fedora II Root and Boot). So I happily go back and forth between my installs without risking borking my setup. Until recently, I was able to untar a system backup to the decrypted LUKS logical partition, chroot into it, and update the initramfs (using sudo dracut -vf). Doing this is what (I thought) told it to look for the LUKS partition when booting. And on reboot, that newly installed system would display the LUKS decryption splash, then after I entered the password, boot from the root partition. Now, however, I cannot seem to get a restored system using the second partition combo (Fedora II Root and Boot) to start at the LUKS splash screen. I have triple checked, and the setup is identical to the Fedora I combo. Specifically: On the Fedora I and Fedora II /bootpartitions (note: each is a separate partition), there is a file named refind_linux.conf the first stanza of which reads something like "Boot with standard options" "root=UUID=3a404a5a-3d2e-46cd-bf73-8f40e89efed3 ro rhgb quiet LANG=en_US.UTF-8 acpi_osi=Linux acpi_backlight=native", where 3a404a5a-3d2e-46cd-bf73-8f40e89efed3 is the UUID for the partition inside the encrypted partition (aka /dev/mapper/luks-f3303886-beb1-4733-8e6f-5794d430e87e). Of course, the UUID differs depending on whether it is the Fedora I partition or the Fedora II partition. On both the Fedora I and Fedora II root partitions (aka /), there is a file called /etc/fstab, which provides the /, /boot, and /boot/efi UUIDs for the respective partition. For example, one is: UUID=3a404a5a-3d2e-46cd-bf73-8f40e89efed3 / ext4 defaults 1 1 UUID=D0BD-BA39 /boot/efi vfat umask=0077,shortname=winnt 0 2 UUID=e40053cc-4402-478e-9af8-67a218401b33 /boot ext4 defaults 1 1 The UUID for the / partition is the same one listed in refind_linux.conf. On both the Fedora I and Fedora II root partitions (aka /), there is a file called /etc/crypttab, which I thought tells Fedora where to look for the LUKS partition. Here, it is: luks-f3303886-beb1-4733-8e6f-5794d430e87e UUID=f3303886-beb1-4733-8e6f-5794d430e87e none luks, where f3303886-beb1-4733-8e6f-5794d430e87e is the UUID of the LUKS wrapper (aka /dev/sda7). Although the setups are identical, the first combo boots and the second does not. What am I missing? Is there some new method to get a newly installed system to recognize that there is an encrypted partition that it needs to read first? What do I need to do to get the second partition combo to recognize that it should be looking at the LUKS partition first, not the root partition?
The problem was a failing hard drive, with bad (repairable) sectors where this partition was.
Dual boot setup with LUKS and rEFInd: Can't Restore Backup to Second Partition
1,624,309,449,000
After each hibernation process I get a corrupted root filesystem. My setup is a LUKS encrypted root and swap partition on LVM. I use a GPG encrypted key for the root filesystem and a unencrypted key file on the root partition for swap decryption. The initramfs is generated by genkernel with genkernel --lvm --luks --gpg initramfs For the hibernation setup I followed the Gentoo Wiki. I tried using pm-hibernate s2disk -r /dev/mapper/swap echo disk > /sys/power/state but all result in a corrupted root partition. I am not using tuxonice as (afaik) I would need to switch to other kernel sources or apply patches. System: Gentoo Kernel 4.9.6-gentoo-r1 genkernel 3.4.52.4-r2 pm-utils 1.4.1-r7 Disk layout: NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 477G 0 disk ├─sda2 8:2 0 128M 0 part /boot ├─sda3 8:3 0 410G 0 part │ ├─vg1-swap 253:1 0 30G 0 lvm │ │ └─swap 253:3 0 30G 0 crypt [SWAP] │ └─vg1-root 253:0 0 380G 0 lvm │ └─root 253:2 0 380G 0 crypt / └─sda1 8:1 0 2M 0 part
I use a GPG encrypted key for the root filesystem and a unencrypted key file on the root partition for swap decryption. Does that mean you have to mount the root filesystem in order to be able to decrypt swap? If so, this could likely be the cause of your problems. You're not allowed to access (write) filesystems while in hibernation (because they are "still mounted" by the hibernated system). https://www.kernel.org/doc/Documentation/power/swsusp.txt * BIG FAT WARNING ********************************************************* * * If you touch anything on disk between suspend and resume... * ...kiss your data goodbye. * * If you do resume from initrd after your filesystems are mounted... * ...bye bye root partition. * [this is actually same case as above] * Hibernation is very chancy business, basically you have to hope for whatever your Initramfs flavour to handle all cases properly. It's best to use a plain swap partition that can be reached without any shenanigans.
Corrupt Filesystem after Hibernation
1,624,309,449,000
I have two external hard discs on an OpenSUSE 13.1 system. On one I have created a partition structure: An encrypted LVM partition (LUKS) Several volumes (10) on this LVM partition, some formatted with xfs, some with ext4. sdf 8:80 0 5,5T 0 disk └─sdf1 8:81 0 5,5T 0 part └─extern-2-crypt 253:5 0 5,5T 0 crypt ├─extern--2-nelson--home 253:10 0 8G 0 lvm /extern/nelson/home ├─extern--2-lucien--boot 253:11 0 300M 0 lvm /extern/lucien/boot ├─extern--2-nelson--root 253:12 0 11,5G 0 lvm /extern/nelson/root ├─extern--2-nelson--space 253:13 0 90,1G 0 lvm /extern/nelson/space ├─extern--2-lucien--backup 253:14 0 400G 0 lvm /extern/lucien/backup ├─extern--2-lucien--home 253:15 0 20G 0 lvm /extern/lucien/home ├─extern--2-lucien--raid 253:16 0 3,5T 0 lvm /extern/lucien/raid ├─extern--2-lucien--root 253:17 0 8,5G 0 lvm /extern/lucien/root └─extern--2-lucien--space 253:18 0 30G 0 lvm /extern/lucien/space How can I replicate this structure easily including the LVM config from one disc to the other (with only one disc running at the same time)? I know of sgdisk (8) and parted (mentioned in How to copy the partition layout of a whole disk using standard tools), but that covers only the partition, not the LUKS information and certainly not the LVM config.
ReaR (Relax-and-Recover) is a collection of shell scripts that can recreate the lvm structures. It does using either vgcfgbackup/vgcfgrestore backup restore native tools or lvm create. It does not yet support recreating lvm configurations on thin pools. For luks, it prompts for the passphrase and recreates the container. It proclaims itself as "the leading Open Source disaster recovery and system migration solution" and appears to be backed by RedHat
Replicate a complex partition structure with LUKS and LVM volumes
1,624,309,449,000
I've installed gentoo on my new laptop. I've got an LUKS-encrypted root partition (/dev/sda3). Cryptsetup (USE="gcrypt") is installed. Essential cryptographic API is compiled in kernel. Kernel and initrd image are built using genkernel-next (--luks --gpg). I use GRUB2 and these kernel options: root=/dev/ram0 crypt_root=/dev/sda3 real_root=/dev/mapper/root rootfstype=ext4 I also tried to omit rootfstype, and root=/dev/mapper/root (no real_root), but nothing has changed. When I boot my system it asks me for my password: Enter passphrase for /dev/sda3: ... and after I type (in)correct password nothing happens: I can type any symbol infinitely. Any ideas? I can boot with live-cd and successfully mount this encrypted volume with cryptsetup.
The problem was solved by rebuilding initrd image using genkernel-next with --lvm option.
LUKS: Enter passphrase and nothing happens
1,624,309,449,000
I have get informed on how prepare a LUKS system & partitions, giving a key/passphrase, etc. But for a new fresh install of linux. How to encrypt an already installed/configured linux system ? EDIT I have made my linux system as a server. I need it crypted, and I would like to test encryption without to reinstall anything.
Make another partition (or image file) with an encrypted fs for your data. Moving root on the fly to an encrypted fs on the same disk does not work.
Encrypt existing disk with LUKS?
1,624,309,449,000
I have a dd image of disk, which is a LUKS container containing a filesystme, and which I can loop mount and unlock to access the files. The filesystem in the container is only about 1/4 full. What is the proper way to take advantage of compression, while allowing me to be able to mounted and unlock the disk?
You can't compress LUKS encrypted data. However, if all involved filesystems support it, you can discard free space using fstrim, resulting in a sparse file where free space is zero and does not occupy space. # du -h foobar.img 1.0G foobar.img # cryptsetup open --allow-discards foobar.img foobar Enter passphrase for foobar.img: foobar # mount /dev/mapper/foobar loop/ # df -h loop/ Filesystem Size Used Avail Use% Mounted on /dev/mapper/foobar 974M 129M 780M 15% /foobar/loop # fstrim -v loop/ loop/: 845.7 MiB (886763520 bytes) trimmed # du -h foobar.img 179M foobar.img Yet another option may be to shrink the filesystem itself and truncate the size of the image file accordingly (remember to account for the LUKS header offset, usually 2 MiB for LUKS 1 and 16 MiB for LUKS 2). The alternative would be to compress the unencrypted data instead.
Compression, and a disk image of a LUKS container
1,624,309,449,000
I've followed this guideline to the point where I encrypt the target partition: cryptsetup -h sha256 -c aes-xts-plain64 -s 512 luksFormat /dev/nvme0n1p3 Then, the error appears, even though I'd unmounted the home partition previously like so: umount -l /home The reason for the -l-flag was that it didn't work without it. Moreover, in order to get so far, I had to boot my system till reaching the user-login screen, then press CTRL+ALT+F2 to get into tty2, there log into my user via "login" and "password", then unmount the "/home" - partition forcefully. Even though I'd checked previously via gparted which is the mount-point on the hard-drive related to /home, it states "Device /dev/nvme0n1p3 is in use. Can not proceed with format operation." albeit having unmounted "/home" previously. How can I finish encrypting my "/home" - partition with LUKS (cryptsetup)? Could I use this in the same way to encrypt my swap, /temp, and /var/temp as well, since I couldn't encrypt the entire ubuntu 20.04 installation due to being installed in parallel to Windows 10?
umount -l is so called lazy unmount -- for busy filesystems this waits until the filesystem is no longer in use before really unmounting it. From mount manpage: -l, --lazy Lazy unmount. Detach the filesystem from the file hierarchy now, and clean up all references to this filesystem as soon as it is not busy anymore. So the cryptsetup call failed because your /home is still in use and it is used because you are logged in. You need to logout first and then unmount your /home. For that you'll need to either login as root (which doesn't use /home) or use LiveCD. Yes you can use the same steps to encrypt your swap (this can be done from running system after swapoff -a to disable swap) and other partitions. Btw. if you want to encrypt your entire system, I'd recommend using LVM which allows you to setup the encryption on a single point on the physical volume layer (but that would require reinstalling your system).
cryptsetup luksFormat error "Device /dev/nvme0n1p3 is in use. Can not proceed with format operation."
1,624,309,449,000
This is more of a educational and curiosity question, rather than tying to fix a problem. I have an Ubuntu system using LUKS. lsblk shows this: Noteably, / is encrypted but /boot and /boot/efi are not. This is important because LUKS needs /boot to be unencrypted in order to boot GRUB. But... / contains /boot. So it seems that if / is encrypted, that would force /boot to be too. After all, how would you know where on disk /boot starts, since /'s pointer to /boot is encrypted? (i assume) Thank you!
The devices (partitions) that / and /boot reside on are different, and one can be encrypted while the other is not.  GRUB knows how to find /boot by using something like set root=(hd0,1) or search --hint=... as defined in grub.cfg. Since GRUB can handle booting into multiple OS's installed simultaneously, the / file system (or C:) cannot be used to locate /boot unambiguously.
LUKS - How can / be encrypted but /boot and /boot/efi are not?
1,624,309,449,000
Let's assume I lost a LUKS encrypted USB pen drive. I think the file system type (ext4/fat32/...) doesn't play a role. A foreign person finds it. Of course he cannot access my data because he doesn't have the password. But he can change a single byte in the middle of the "raw" data so the data is damaged. After the pen drive is returned to me, is it possible to verify my data was damaged or not? I thought reading the whole mapper device will cause an I/O error but unfortunately it does not. I also checked dmesg. # create an all zero 100MiB file dd if=/dev/zero of=moh bs=100M count=1 # format it as LUKS device /usr/sbin/cryptsetup luksFormat moh # map it to /dev/mapper/moh sudo cryptsetup luksOpen moh moh # initialize mapper file to zero sudo dd if=/dev/zero of=/dev/mapper/moh # close LUKS device sudo cryptsetup luksClose moh # overwrite 1MiB with zeroes at offset 10MiB. After this the LUKS device is damaged. sudo dd if=/dev/zero of=moh conv=notrunc bs=1M seek=10 count=1 # open LUKS device and see if it complains sudo cryptsetup luksOpen moh moh # read all data to see if it complains sudo dd if=/dev/mapper/moh of=/dev/null The above commands proofs that opening and reading a damaged LUKS device does not produce any error. Please note that I don't want to perform any file system checks. Instead I want to verify whether the LUKS device is untouched on the encryption level. Because I am looking for a single command to verify a luks device I hope you understand this is not a programming question more suitable for SO.
It is possible but not with "plain" LUKS, you need to set up authenticated encryption. This is possible with LUKS v2, you need to create the LUKS device using the --integrity option with luksFormat. This will basically add checksums for the encrypted data to ensure integrity, without it LUKS/dm-crypt simply doesn't care (or know) what is on the disk and if you overwrite it with zeroes it will "decrypt" those zeroes. See the Authenticated disk encryption section in cryptsetup man page for more details.
Is it possible to check if a LUKS device has been damaged by a foreign person?
1,624,309,449,000
I installed Linux Mint 18.2, as LVM with LUKS encryption, onto a 128GB SSDD. I would like to remove the swap drive b/c I have 16GB of RAM on my machine and I want to try to preserve the drive as long as I can. When I started the disk and started Gparted to remove the swap partition I noticed that Gparted lists the drive as only two partitions /dev/sdb1 ~.5GB boot-sector (I think) and /dev/sdb2 the crypt-luks container. When I checked /ect/fstab I noticed that this was the last line; /dev/mapper/cryptswap1 none swap sw 0 0 Does anyone know a safe way to remove this kind of swap partition?
There shouldn't be any problem disabling a swap partition of any sort. Once booted, you can disable the swap partition with: sudo swapoff -a And then place a swap partition on some other disk and enable that with: sudo swapon -U uuid-of-new-swap-partition. Once you verify that the new swap is working, you can remove the LVM swap partition on your LUKS drive... and reuse the space. LVM is awesome! To make the changes permanent, replace the swap partition listed in /etc/fstab with the new one using the same options as the prior swap... none swap sw 0 0 LUKS specific instructions Apparently... There is a specific option with cryptmount for enabling and disabling swap. cryptmount --swapoff and cryptmount --swapon It seems that cryptmount will perform the close operation in addition to disabling the swap partition. If you've disabled the swap with the regular system swapoff, you may need to disable the current swap partition (safe to do) to close the LUKS swap partition before you can remove it... cryptsetup -v luksClose /dev/mapper/cryptswap1
Removing the swap partition from a LUKS encrypted SSDD
1,624,309,449,000
Why is it considered good practice to zero free space before formatting a luks drive? Do I need to do this even with a brand new usb flash drive that has never been used before?
You don't need or want to zero the partition. You want to fill it with random data, so that a hypothetical attacker cannot tell which sectors are used and which are not used. Usually this is done by opening it as a plain cryptsetup volume with a random key and dd-ing /dev/zero onto the volume. (This is very much faster than dd-ing /dev/urandom onto the partition.) You then close the plain cryptsetup volume and run cryptsetup luksFormat. Let's say that the partition or file on which you want to create a LUKS container is $ENCRYPTED_CONTAINER and the name of the container is $CONTAINER; first, you fill $ENCRYPTED_CONTAINER with random data (the example code works on Ubuntu or other Linux variants where administrative commands are to be run with sudo): sudo cryptsetup plainOpen --key-file /dev/urandom $ENCRYPTED_CONTAINER $CONTAINER sudo dd if=/dev/zero of=/dev/mapper/$CONTAINER bs=1M sudo cryptsetup plainClose $CONTAINER Then you create a LUKS container and open it: sudo cryptsetup luksFormat $ENCRYPTED_CONTAINER sudo cryptsetup luskOpen $ENCRYPTED_CONTAINER $CONTAINER
Why do you need to clean free space before creating a LUKS partition?
1,624,309,449,000
Is it possible to set up a bootloader that automatically begins shredding the header.img file and then the encrypted partition itself upon X failed attempts at decrypting the partition? If this does not already exist - is it possible to create any such software without extensive work? Cheers,
Yes (for your own bootloader / initramfs) and No (for a thief who tries to decrypt it from a Live CD and thus circumvents your trap). So the question is, which situation are you trying to cover here... From a security standpoint it's not a good idea since it doesn't work and the password should be impossible to bruteforce anyhow. Also there is a high risk of triggering that trap yourself. It's entirely possible to make mistakes when entering a passphrase. My favourite is the caps lock key, hit it accidentally and not notice (since the password is not echoed) and... in your case it goes boom. In order to implement it you'd have to see if your distro's flavour of initramfs has a hook system or similar. A normal cryptsetup call may look like this: cryptsetup -T 5 luksOpen /dev/sda1 luksroot To boobytrap it you could simply do something like: cryptsetup -T 5 luksOpen /dev/sda1 luksroot || boobytrap And boobytrap would be a function that deletes your stuff while keeping the thief occupied. In addition to that you must absolutely check the error code of cryptsetup; so you don't delete because of wrong parameters or anything like that. Check the RETURN CODES section in the manpage. Pseudocode: (untested and not recommended) boobytrap() { if [ $? -eq 2 ] then # kill the disk silently in the background... dd bs=1M if=/dev/zero of=/dev/sda1 seek=2 2> /dev/null & # ...while keeping the thief busy entering more passwords cryptsetup -T 9999 luksOpen /dev/sda1 luksroot \ && echo Congrats, but I already deleted your data... fi } I hope you have a good backup.
Automatically shred LUKS partition upon X failed decryption attempts?
1,624,309,449,000
I have my hard disk encrypted with LUKS, but I make regular backups to an unencrypted external harddrive. Is there any reason I shouldn't setup LUKS on my backup drive as well? Obviously, the big thing will be keeping track of the key/passphrase, but I believe I have that in hand. I'm more concerned about obsolescence of LUKS, I guess. I want to make sure that if my backup sits around for five or ten years, I'll still be able to mount and access it on whatever linux system I have setup at the time.
I'm more concerned about obsolescence of LUKS What about USB mass storage support? The underlying PATA or SATA disk access? (It's already pretty hard to find motherboards with PATA ports.) How about Linux itself, or USB for that matter? As frostschutz said, it depends very much on why you are encrypting the main drive. If your main concern is LUKS obsolescence, there's a pretty simple solution. Make a small unencrypted partition with some basic file system support for which is unlikely to go away (ext2, ext3 or maybe even FAT32) and put ISOs (live and install) for your favorite Linux distribution there, and devote the majority of the disk to an encrypted partition holding the actual backup. Store hashes of the ISOs to be able to detect corruption, and check them on a regular schedule to make sure the drive does not suffer from bit rot. If you need to, just boot from the ISO and mount the encrypted partition. This is trivially accomplished in a virtual machine. Be sure to try it out before you need it; backups are easy, restores are hard. And major Linux distribution ISOs don't go away easily. Here is year 2000 vintage Red Hat Linux 6.2, which came with a 2.2.14 kernel. I'm sure you can find older if you look around a little.
Any reason not to use LUKS on a backup drive?
1,624,309,449,000
I have an external eSATA-hdd on an OpenSUSE 12.2 system. The external hdd has an LVM on a dm-crypt partition. I mount it by powering it up and then doing rescan-scsi-bus.sh cryptsetup -v luksOpen vgchange -ay mount Now when I want to power the hdd down, I do umount vgchange -an extern-1 cryptsetup -v remove /dev/mapper/extern-1-crypt echo 1 >/sys/block/sdf/device/delete Here the device (sdf) is currently hardcoded in the script. Can I somehow deduce it in the script from the VG or the crypto device?
Yes, you can find the information in /sys/block/$DEVICE/slaves. If you only have the canonical name you can use readlink to get the details, e.g: devdm="$(readlink -f /dev/mapper/extern-1-crypt)" dm="${devdm#/dev/}" ls /sys/block/$dm/slaves/ If you want to remove all you can just utilize directly the sys filesystem: echo 1 > /sys/block/$dm/slaves/*/../device/delete
Detecting the device of a crypto mount
1,624,309,449,000
In GRUB's project status update, at FOSDEM 2022, they talked about adding detached headers support in GRUB 2.12 (for decryption) : Add cryptodisk detached headers and key files support, Denis 'GNUtoo' Carikli, Glenn Washburn,Patrick Steinhardt GRUB 2.12 was released in December 2023, but I couldn't find any mention of that feature in its NEWS file. Does anybody know if 2.12 now supports detached headers, as initially planned ?
Technically, yes. See GRUB Manual on cryptomount. cryptomount [-H file] The -H options can be used to supply cryptomount backends with an alternative header file (aka detached header). Not all backends have headers nor support alternative header files (currently only LUKS1 and LUKS2 support them). In the Grub console, help cryptomount also lists it: -H, --header Read header from file However, the other side is getting this feature integrated in Grub's userspace utilities. In /etc/default/grub GRUB_ENABLE_CRYPTODISK, there seems to be no way to specify an external header yet. So you'd have to jump some hoops to make this work for early cryptomount. It does not work out of the box for an encrypted /boot partition and encrypted grub config.
Does GRUB 2.12 now support detached headers?
1,624,309,449,000
I had an old, small SSD, so I bought a new, bigger one. Ubuntu 20.04 LTS, LUKS. With CloneZilla, I cloned it to an IMG file from the old SSD, then restored the IMG file to the new SSD. Question: Everything is ok, only strange that the "lvextend -l 100%FREE" isn't working, while the "lvextend -L +4.59G" works for the same LV! What? 100%FREE should extend it to max, why do I have to manually set the +GBytes to make lvextend work? And why is there a "<" sign at the size of the VSize?
strange that the "lvextend -l 100%FREE" isn't working Without the + the 100%FREE is interpreted as absolute size. Which works if you have more free space than the current size of the volume, but it's probably not what you intended to do. In your case, it seems you have 1176 extents free while the current size of the volume is 236731 extents so naturally, it fails. If you had 236773 extents free, the command would have worked, but the volume size would only have grown by 42 extents... So, the + sign is very important here. And why is there a "<" sign at the size of the VSize? It indicates that the value has been rounded, see also manpage on --units.
lvextend -l 100%FREE isn't working
1,624,309,449,000
I recently installed Debian 10 on my laptop and for the first time I decided to give file encryption a go. But I've found something interesting in the /etc/fstab file, and it's that it doesn't use UUID and instead it uses absolute paths. This is my /etc/fstab: # <file system> <mount point> <type> <options> <dump> <pass> /dev/mapper/sda1_crypt / ext4 errors=remount-ro 0 1 # /boot was on /dev/sda3 during installation UUID=fb4bd462-2ad8-4e56-b84e-602a94bf8b31 /boot ext4 defaults 0 2 /dev/mapper/sda5_crypt none swap sw 0 0 And this is the output from lsblk -o PATH,UUID,NAME,MOUNTPOINT NAME PATH UUID MOUNTPOINT sda /dev/sda ├─sda1 /dev/sda1 f0ece3a3-69c2-4ad8-b819-311a18c37b21 │ └─sda1_crypt │ /dev/mapper/sda1_crypt b73f7cef-ba4e-4587-9dba-da8385d93824 / ├─sda2 /dev/sda2 ├─sda3 /dev/sda3 fb4bd462-2ad8-4e56-b84e-602a94bf8b31 /boot └─sda5 /dev/sda5 ca96319f-82b3-4cbf-a1e1-7d30f7be4576 └─sda5_crypt /dev/mapper/sda5_crypt 40b9e71c-46b5-4d29-91a4-aaa12ca0e109 [SWAP] I have an encrypted root partition on sda1 and an encrypted swap partition on sda5. I had to create an unencrypted /boot partition too (sda3). sda2 is free space I'll use for other purposes. As you can see in the /etc/fstab, Debian identifies my /boot partition with its UUID, as it did on other occasions that I installed an unencrypted system, but it uses absolute paths for the encrypted partitions. Can anyone help me identify why this happens and if it would be a good idea or even a good practice to change the /etc/fstab file so it uses UUID instead of paths? Thanks.
These absolute device paths are perfectly fine, since their names are stable and prescribed by the first fields in the lines of /etc/crypttab. Actually, they are symlinks to the numbered (thus unstable) device mapper device node names. If /etc/crypttab refers to their source devices (in the second fields) by stable names or UUIDs, your are safe from unpredictable device ordering.
Mount points in /etc/fstab on Debian system for an encrypted partition
1,624,309,449,000
I installed debian stretch using encrypted lvm from the installer on a usb drive. during installation, with all disks connected, sdo5 is assigned to my boot disk. when running the full system, my boot disk is now assigned sdn5 this is problematic, because I have an encrypted data disk that shows up as sdo1, as per blkid. I need to change the crypt configuration and initramfs to look for sdn, so that sdo is free. how can I do that? simply changing the crypttab and running update-initramfs -u -k all gives an error about invalid line in crypttab and then the system will not boot. cryptsetup: WARNING: invalid line in /etc/crypttab for sdo5_crypt there must be another step. where is sdo5_crypt referenced other than crypttab? my crypttab is as follows: sdo5_crypt UUID=long_string_here none luks and my fstab is: /dev/mapper/coldstorage--vg-root / ext4 errors=remount-ro 0 1 # /boot was on /dev/sdo1 during installation UUID=long_string_here /boot ext2 defaults 0 2 /dev/mapper/coldstorage--vg-swap_1 none swap sw 0 0 EDIT: I can see there is a lingering /dev/mapper/sdo5_crypt even when I reboot after changing crypttab but not updating initramfs (which causes the system to request the password for sdn5) If I can rename that, it might be enough? lvrename does not seem to work. # ls /dev/mapper/ control sdo5_crypt coldstorage--vg-root coldstorage--vg-swap_1 result of pvdisplay --- Physical volume --- PV Name /dev/mapper/sdo5_crypt VG Name coldstorage-vg and attempt to fix... # pvmove /dev/mapper/sdo5_crypt /dev/mapper/sdn5_crypt Physical Volume "/dev/mapper/sdn5_crypt" not found in Volume Group "coldstorage-vg".
Got it. dmsetup rename sdo5_crypt sdn5_crypt sed -i -e 's/sdo5_crypt/sdn5_crypt/g' /etc/crypttab update-initramfs -u -k all
change designated name of encrypted lvm root? from sdo to sdn in crypttab?
1,624,309,449,000
Say I have a LUKS encrypted USB (full disk). I am looking for a way to hide the fact that it is a LUKS device. Which strategy would you use to hide the fact that my USB is a LUKS device? My approach would be to alter the LUKS header to make the LUKS header unrecognizable (and be able to go back easily). What about exchanging a define portion of the bits of the header for instance? PS: Say I don't want to use Truecrypt
So, without opening the whole topic of deniable encryption (and the cryptsetup FAQ has a section dedicated to that topic too) and since you're asking to simply hide the LUKS device (if that's sufficient), I'd use the luksHeaderBackup and luksHeaderRestore options from cryptsetup(8). Example for an already created LUKS device with an ext4 file system on it: # file -Ls /dev/vg0/lv1 /dev/mapper/test /dev/vg0/lv1: LUKS encrypted file, ver 1 [aes, cbc-plain, sha1] UUID: 0b52a420-742d-4f0f-87f1-29c51d8b2232 /dev/mapper/test: Linux rev 1.0 ext4 filesystem data, UUID=840fc046-df2f-428d-8069-faa239c2f9f3 (extents) (large files) (huge files) Backup the LUKS header: # cryptsetup luksHeaderBackup /dev/vg0/lv1 --header-backup-file test.bkp # ls -go test.bkp -r-------- 1 1052672 Dec 17 18:41 test.bkp Now we can overwrite this many bytes of the beginning of the LUKS partition. Our root partition is formatted with ext4 as well, let's just use that: # dd if=/dev/sda1 of=/dev/vg0/lv1 bs=1 count=1052672 # file -Ls /dev/sda1 /dev/vg0/lv1 /dev/sda1: Linux rev 1.0 ext4 filesystem data, UUID=f0cf7fa2-9977-4e1f-938d-1e8f71934cce (needs journal recovery) (extents) (large files) (huge files) /dev/vg0/lv1: Linux rev 1.0 ext4 filesystem data, UUID=f0cf7fa2-9977-4e1f-938d-1e8f71934cce (needs journal recovery) (extents) (large files) (huge files) Now our LUKS partition looks like our root partition. Hm, they both have now the same header, even the UUID matches, maybe a bit too similar. Of course we could have filled the LUKS partition with something else, you get the point. The important part is to backup the LUKS headerfile (test.bkp), because without that we won't be able to unlock the partition again. Once you feel safe to unlock the LUKS partition again, get the backup file (maybe from your own USB drive) and simply restore the header: # cryptsetup luksHeaderRestore /dev/vg0/lv1 --header-backup-file test.bkp ...and unlock the partition again.
Can I hide the fact that my USB is LUKS encryted?
1,624,309,449,000
When I try to LUKS encrypt a partition on a CentOS 7 server using the command cryptsetup -y luksFormat /dev/sda4, the attempt fails with the error Cannot format device /dev/sda4 which is still in use. How can I resolve this error and successfully LUKS encrypt the partition? Here is the terminal record: [root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/dm-1 50G 1.1G 46G 3% / devtmpfs 3.8G 0 3.8G 0% /dev tmpfs 3.8G 0 3.8G 0% /dev/shm tmpfs 3.8G 8.7M 3.8G 1% /run tmpfs 3.8G 0 3.8G 0% /sys/fs/cgroup /dev/sda6 296G 65M 281G 1% /vpn /dev/sda2 477M 110M 338M 25% /boot /dev/sda1 200M 9.8M 191M 5% /boot/efi /dev/sda3 596G 73M 565G 1% /home /dev/sda7 296G 65M 281G 1% /test /dev/sda5 296G 65M 281G 1% /public /dev/sda4 296G 65M 281G 1% /data [root@localhost ~]# cryptsetup -y luksFormat /dev/sda4 WARNING! ======== This will overwrite data on /dev/sda4 irrevocably. Are you sure? (Type uppercase yes): YES Enter passphrase: Verify passphrase: Cannot format device /dev/sda4 which is still in use.
Is the goal to completely destroy everything on your current /data disk and create a new, entirely empty encrypted volume? Because that's what you're doing with this command. That's what the whole "WARNING: This will overwrite data on /dev/sda4 irrevocably" thing is about. You will lose all the current data, and start over with an empty block device. More likely, what you want to do is take a data backup of /data, create the new volume, then restore the backup into the new, encrypted filesystem. You can use tar for this nicely: cd /data tar czvf /root/data_backup.tar.gz . Then, and only then, do you write over the filesystem using cryptsetup. The way to get around your error is by unmounting first: umount /data cryptsetup -y luksFormat /dev/sda4 Then you can luksOpen the new /dev/sda4, then mkfs onto the encrypted mapping, mount the result, and finally cd into it and restore the existing data with tar. If you are actually, 100% sure that you want to irrevocably destroy everything in the current /data, then skip the first step, and just jump down to umount /data. Edit: If you're doing this at all it's possible that the current data is sensitive. If so, consider: cryptsetup luksFormat does not overwrite all existing data. It only overwrites the first few KiB. If the data is sensitive you will first want to overwrite all data on the partition, e.g. with wipe, see https://superuser.com/questions/831486/complete-wiping-of-hard-drive-shred-wipe-or-dd. If the partition is large and if there is not much data on the other partitions it will be faster to include all data in a backup on external storage, use the internal disk's "secure erase" feature to blank it in an instant, prepare /data with LUKS and restore your backup. To not contaminate /root with the sensitive data, write to a sufficiently large tmpfs, a smaller volume which you can secure-erase afterward or a new filesystem in an encrypted container, or pipe the tar output through gpg before writing the backup. cryptsetup-reencrypt can encrypt the data in-place. As the tool is not crash resistant, having a backup is still advisable. An existing backup becomes the primary copy during the operation. For important data, a second backup should be made so that more than one copy exists at all times.
Cannot format device /dev/sda4 which is still in use
1,624,309,449,000
I want to re-encrypt a system and swap partitions on EndeavourOS. The issue is that in many files (crypttab, mikinicpio, fstab, etc) the exact UUID of the LUKS partition is built in, meaning I would have to change manually the UUID after re-encryption if it this the case for the system and bootloader to recognize the partitions as parts of the system. Does the UUID change after re-encryption? If not, then I can simply re-encrypt (with a backup of course) and be done with it.
Looks like it does not: # lsblk -f /dev/sde2 NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS sde2 crypto_LUKS 2 d37a4c03-8ca2-4410-97d8-77bb39d4b499 # cryptsetup reencrypt /dev/sde2 Enter passphrase for key slot 0: Finished, time 00m01s, 84 MiB written, speed 72.9 MiB/s # lsblk -f /dev/sde2 NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS sde2 crypto_LUKS 2 d37a4c03-8ca2-4410-97d8-77bb39d4b499 It makes sense that the UUID doesn't change -- it's a unique identifier of the format and it is created when the format is created, reencrypt doesn't recreate the LUKS format, it just changes some parameters.
Does the UUID of a LUKS partition change after re-encryption?
1,624,309,449,000
There are many tips on how to resize (increase) a LUKS2 encrypted device / partition / LVM volume. But how to increase the size of the LUKS container created in the file? I once created: dd if=/dev/random of=/some file bs=1M count=100 cryptsetup luksFormat /some-file cryptsetup luksOpen /some-file some-mount mkfs.ext4 /dev/mapper/some-mount Now this container has run out of space and I need to increase its size. How to do it?
You can just set a new file size with truncate, then cryptsetup resize and resize2fs. For example, setting it to 200M: truncate -s 200M cryptfile.img Alternatively, if you prefer dd or other tools, you can just append another 100M of random data: head -c 100M /dev/urandom >> cryptfile.img Warning: if you truncate to a too small size, or if you typo and use > instead of >>, your data would be lost. dd in particular likes to truncate files to 0 bytes by default, and it's easy to make mistakes, so I don't really recommend using it here. The difference between truncate and appending random data is that truncate makes sparse files (zero, unallocated) while appending properly allocates space and initializes it with random data. Then you can online resize the mapping (this might ask for your passphrase again): cryptsetup resize cryptname This would also happen automatically next time you cryptsetup open the container normally. At this point the encrypted block device (loop device, image file) should be properly resized to 200M (minus 16M or whatever is the size of your LUKS header). That leaves the filesystem: resize2fs /dev/mapper/cryptname
How to increase the size of a LUKS file-container
1,615,361,613,000
Can cryptsetup be used to open a veracrypt file like crypsetup can open luks? What is the correct process ? Want to make sure other software can open veracrypt file , command line or gui is fine, as long as it can open a veracrypt file. Tried: $ sudo cryptsetup tcryptOpen '/media/path/to/veracrypt/file' stuff $ sudo cryptsetup --type --tcryptOpen ''/media/path/to/veracrypt/file' stuff cryptsetup tcryptOpen '/media/path/to/veracrypt/file' stuff Thanks to @Vojtech Trefny below command seemed to work but with an error: ~$ sudo cryptsetup --type tcrypt --veracrypt open '/media/path/to/veracrypt/file' stuff Enter passphrase for /media/...: Device '/media/path/to/veracrypt/file' is too small. password was able to open the veracrypt file using veracrypt, but not using cryptsetup.... Additional Note: This is command allowed me to access veracrypt/truecrypt files using * cryptsetup * $ sudo cryptsetup --type tcrypt open container-to-mount container-name kenfavors.com has a simple example page that may be useful to anyone having similar problem described above
You are probably mistaking LUKS and cryptsetup. LUKS is a disk encryption format/metadata specification and cryptsetup is a tool (and library) for working with encrypted devices. It was first started for LUKS/dm-crypt but it also supports other formats including TrueCrypt/VeraCrypt, BitLocker and loopaes. To unlock a VeraCrypt device using cryptsetup use cryptsetup tcryptOpen <device> <name>, details about TrueCrypt/VeraCrypt support are available in the man page, section TCRYPT (TrueCrypt-compatible and VeraCrypt) EXTENSION.
open veracrypt file with cryptsetup/luks
1,615,361,613,000
I'm benchmarking various cryptsetup volumes and I'm getting unexpected results on Debian. I'm using numbers from this talk as a rough reference. One of the slides shows benchmark results for various configurations: My setup is not identical and I'm running all tests in VMs, so I don't expect results to be exactly identical, but I think they should roughly reflect what's on the slide. In particular I expect to see performance drop of about 35 for authenticated integrity modes (AES-XTS,HMAC-SHA256) compared to non-authenticated counterparts (AES-XTS) and then another 35% for journaled integrity vs. non-journaled integrity. But here are my results, similar for Ubuntu Server 20.04 and Debian 10.4: LUKS2 container: Capacity 1056964608 B Read 26.5MB/s Write 8855kB/s LUKS2 with hmac-sha256, no journal: Capacity 1040322560 B Read 19.0MB/s Write 6352kB/s LUKS2 with hmac-sha256, journaled: Capacity 1040322560 B Read 18.9MB/s Write 6311kB/s About 30% performance drop after enabling integrity, that's expected. But then the difference between journaled and non-journaled integrity is marginal. I mean, that's much better than original benchmark so I should be happy, but how do I know that the journal is actually working and if it is, how do I opt out? Here are my cryptsetup format commands: cryptsetup luksFormat --type luks2 /dev/sdb --sector-size 4096 cryptsetup luksFormat --type luks2 /dev/sdb --sector-size 4096 --integrity hmac-sha256 cryptsetup luksFormat --type luks2 /dev/sdb --sector-size 4096 --integrity hmac-sha256 --integrity-no-journal Benchmark command: fio --randrepeat=1 --ioengine=libaio --direct=1 --gtod_reduce=1 --name=test --filename=/dev/mapper/sdb --bs=4k --iodepth=64 --readwrite=randrw --rwmixread=75 VMs are configured on VirtualBox 6.1 with settings default for Debian or Ubuntu respectively. Disks are 1 GB VDIs, fixed size and pre-filled with zeros, host buffering disabled. Underlying SSD is using 4k sectors, hence --sector-size 4096. Interestingly, both the basic --integrity variant and the --integrity-no-journal one create intermediate sdb_dif mapped device with journal and both sdb devices have identical size: $ sudo integritysetup status /dev/mapper/sdb_dif /dev/mapper/sdb_dif is active and is in use. type: INTEGRITY tag size: 32 integrity: (none) device: /dev/sdb sector size: 4096 bytes interleave sectors: 32768 size: 2031880 sectors mode: read/write failures: 0 journal size: 8380416 bytes journal watermark: 50% journal commit time: 10000 ms $ sudo blockdev --getsize64 /dev/mapper/sdb 1040322560
Summary of answer: cryptsetup format ignores the --integrity-no-journal flag. Instead, your options are: At each open, always provide --integrity-no-journal. At your first open (i.e. when formatting the inner device with a filesystem, or to add the inner device to an MD RAID), provide --persistent --integrity-no-journal to persist the --integrity-no-journal setting. Then future open will not need the flag. This option only works with cryptsetup, not if you are using direct integritysetup. While the device is already opened, issue a refresh --persistent --integrity-no-journal. This option only works with cryptsetup, not if you are using direct integritysetup. Old text: Did you provide the --integrity-no-journal flag to integritysetup open? It looks like dm-integrity does not save the (non-)existence of a journal in the superblock when you format. I formatted a USB 2.0 flash disk partition with integritysetup format /dev/sdb1 --no-wipe. Then I opened it with integritysetup open /dev/sdb1 int-sdb1, and did sync; echo 1 > /proc/sys/vm/drop_caches; dd count=16384 bs=4096 if=/dev/zero of=/dev/mapper/int-sdb1. This consistently gave me results of between 2.1Mb/s to 2.4Mb/s. I closed it and then reopened with integritysetup open /dev/sdb1 int-sdb1 --integrity-no-journal, and issued the same dd command. This time it gave me from between 4.0Mb/s to 7.0Mb/s, a marked improvement. The massive variance might be due to the flash translation layer; it's a lousy throwaway cheap disk. I repeated this again with integritysetup format /dev/sdb1 --no-wipe --integrity-no-journal. Again, what matters is wheter you gave --integrity-no-journal to the open command, not to the format command. So it might be a non-clarity of integritysetup. If you gave --integrity-no=journal to the format command.
Cryptsetup with dm-integrity - weird benchmark results
1,615,361,613,000
I have three copies of the same folder but the sizes of these are different. Why? I have a folder "Documents" that I have copied from an encrypted lvm on the hard drive of my desktop to an encrypted luks partition on an external drive. I have then copied this folder from the external drive to an encrypted lvm on the hard drive of my laptop. So I have three copies of the same folder: Desktop External drive Laptop I have used diff between desktop and external drive --> no differences. I have used diff between laptop and external drive --> no differences. But I have different folder sizes for the three cases. I have used du -bs --apparent-size Documents to measure the sizes. Here are the results: Desktop: 1735750760 External drive: 1735742568 Laptop: 1735746664 So, we notice that there is a slight difference between the sizes. Small difference but still there. I was wondering why that was so. Do you have an explanation?
You might have noticed that the difference between the different folders are as follows: Desktop: 1735750760 - 8192 External drive: 1735742568 + 4096 Laptop: 1735746664 To my experience, such differences of 4K blocks usually result from changes of directory sizes. If you compare the sizes of the directories itself (on ext filesystems usually multiples of 4K) you might find the difference. (e.g. directories sometimes get smaller when they are restructured during a copy operation and deleted entries are thereby purged) To find Directories which differ in size, you would have to compare to Directories against each other. The following script could assist you with that: #!/bin/bash DIR1="${1%/}/" DIR2="${2%/}/" diff \ <(find $DIR1 -type d -printf "%k %p\n" | sed -e "s|$DIR1||" | sort -k2) \ <(find $DIR2 -type d -printf "%k %p\n" | sed -e "s|$DIR2||" | sort -k2) Copy the code to a new file (e.g. dircomp.sh) and make it executable chmod +x dircomp.sh. Then call it like ./dircomp.sh /home/lemenhir/ /media/lemenhir/ExternalDrive/. The output should now list only directories with different sizes and could look like this: < 4 Documents/Appartement/Bail > 8 Documents/Appartement/Bail whereby lines starting with < are listing directories located in the directory given as the first parameter (e.g. /home/lemenhir/) and lines starting with > are listing directories located in the directory given as the second parameter (e.g. /media/lemenhir/ExternalDrive/). If single lines appear, then the directory doesn't exist in the opposite directory. Hope this helps.
Same folder content but different sizes on different drives, why?
1,615,361,613,000
A related question would be: luksOpen doesn't decrypt with keyfile unless --key-file argument is provided On Ubuntu bionic with cryptsetup 2.0.2 however, I do encounter the following problem: when opening a luks encrypted device by using a password contained in a file it works well on the direct call: cat mypass.txt | sudo cryptsetup open --type luks /dev/sda1 enc-store trying to use the documented --key-file=- argument, which should result in the same behavior cat mypass.txt | sudo cryptsetup open --type luks --key-file=- /dev/sda1 enc-store just producing the delayed message No key available with this passphrase. this is especially a problem, when trying to use the script cryptdisks_start enc-store, which relies on the --key-file=- option, which produces the above message thrice which makes life a tad less enjoyable. am I missing something here? -thanks!
There is a difference between the two commands, as described in man cryptsetup: --key-file, -d name Read the passphrase from file. If the name given is "-", then the passphrase will be read from stdin. In this case, reading will not stop at newline characters. That means if you generated your file using echo, vi, or copy/pasting, it most likely includes a newline at the end. if used as pure stdin (no --key-file option), it will have its final newline ignored, but when used as a parameter to --key-file, even if it's the same stdin (--key-file=- ) it will get this newline included in the passphrase: it becomes a new passphrase which is invalid. To verify this: cat mypass.txt | tr -d '\r\n' | sudo cryptsetup open --type luks --key-file=- /dev/sda1 enc-store Should work as intended (just in case I remove any CR too). Should that be the cause, just remove this newline: eg mv -i mypass.txt mypass.old && tr -d '\r\n' < mypass.old > mypass.txt What you should probably do anyway is to generate a new passphrase from pure random numbers, put it in a secure file, and include it in a separate LUKS slot.
cryptsetup open for luks : improper handling of --key-file argument
1,615,361,613,000
My / was originally on an encrypted volume and was transferred to an unencrypted volume by recursively copying every directory, and then grub was reinstalled: sudo -s cp -ax /mnt/encrypted /mnt/decrypted for f in sys dev proc ; do mount --bind /$f /mnt/decrypted/$f ; done chroot /mnt/decrypted grub-install /mnt/decrypted update-grub /etc/fstab was updated accordingly and the original encrypted volume was removed from /etc/crypttab, but after rebooting I'm still asked for a password to decrypt my new /. Why is that and how can it be removed?
Removing cryptsetup and regenerating initramfs fixed the problem: apt-get remove --purge cryptsetup update-initramfs -u -k all
How to remove LUKS encryption after transferring files to an unencrypted disk
1,615,361,613,000
I was looking at this thread to remove the encryption from the usb stick, but it says that the key cannot be removed if its the last. How to remove LUKS encryption? I would simply want the usb stick to be a normal usb stick and not an encrypted one anymore. Can a simple dd with null work? I can create luksFormatted usb sticks, but how do I luksUnformat ?
The only easy way to remove LUKS encryption is to back up the data on the storage device and reformat it to an unencrypted state. dd if=/dev/null of=/dev/sdX bs=8M where X is the location of the USB device should work in your case. If you prefer a GUI, then gnome-disk-uility (cmdline name = gnome-disks) has the tools you need.
how to remove luks encryption from a usb stick
1,615,361,613,000
After reading "man cryptsetup" and many StackExchange questions, I'm confused: Does LUKS use the same master key in each slot? If I execute the commands below, the displayed master key does not change--i.e., additional master keys are not listed. cryptsetup luksDump /dev/xvdd1 cryptsetup luksAddKey /dev/xvdd1 --key-slot 1 cryptsetup luksAddKey /dev/xvdd1 --key-slot 2 cryptsetup luksDump /dev/xvdd1 Is this a terminology problem? Meaning, you have: master key (for encrypting and decrypting the partition) password (for encrypting the master key) key file (for encrypting the master key)
Yes, it's the same master key. After all, you only have one copy of your data on disk, which is encrypted one way only, so as far as the data itself is concerned there is only ever one key. If you used different master keys you'd see different "random" data for each key slot, which is not very useful. It's possible to change the master key but it involves re-encrypting all the data (see cryptsetup-reencrypt).
LUKS: 1 master key but multiple passwords and key files?
1,615,361,613,000
Q: Is it normal if a RHEL 6.5 machine kernel panics if I type the LUKS password a few times wrong?
Yes. The init process, which always had process ID 1, exited. UNIX operating systems panic by design when this happens, because essentally, without init, the system cannot continue to do much of anything useful. (That's not technically quite true, some things can continue, but it's not supposed to happen and it considered bad enough to justify restarting the system.) The initramfs gave up asking you for a password and just quit. Since in that early boot stage init is an initramfs scripts instead of the real init, the same thing happens.
Kernel panic if LUKS password is bad x times
1,615,361,613,000
First, I'm aware that a similar question has already been answered. The answer was YES, but I'd like a second opinion, because : The question didn't specify if it was LUKS1 or LUKS2 Something I've read on Wikipedia casts a doubt in my mind. So, the question is : technically, can a LUKS2 detached header be used for multiple drives ? I know that it's not recommended from a security point of view (see answer to the previously mentioned post), but here I am only interested in the technical side of the question. What casts a doubts in my mind is Wikipedia's statement that a LUKS2 header contains, in its JSON area, segments that describe encrypted areas on the disk. Which would mean that a LUKS2 header is tied to a specific drive, and thus can not be re-used for other drives : Directly after the binary header comes the JSON area, containing the objects config (configuration), keyslots, digests, segments (describes encrypted areas on the disk), and tokens containing extra metadata. So, what do you think ? Can a same LUKS2 detached header be used for several drives ? Is there maybe a difference to be made between several identical drives and several radically different drives (e.g., a HDD and a USB stick) ?
It can be done but it's a bad idea, security wise, to actually use it for independent devices. The answer you linked covers it very well. So I would only recommend it if the data is related, like backup images or snapshots of one and the same LUKS device. Or perhaps in a deployment scenario where a cryptsetup reencrypt will be done on first boot to switch the identical header to an independent one. There may be some side issues that prevent a device from working with a given LUKS2 header: If your sector size is 4096, the device must be multiple of 4096 bytes large. dm-crypt will refuse to work with a device that has an odd number of 512-byte sectors (you have to use a loop device with sizelimit to discard the last partial 4K-sector yourself). This is rarely an issue since most things are 4K-aligned nowadays (and you can just stick to 512 byte sectors for LUKS). If you are using advanced features like dm-integrity with LUKS2, the device you open with this header requires initialization. Otherwise it would have all the wrong integrity checksums and be unusable. So a LUKS2+integrity header can only be used with devices that were initialized with this header. Like you mention, it's also possible for a LUKS2 header to describe specific data segments (offsets, sizes), which would lock it to devices with a specific size. But in practice it's being used for "whole device" encryption only and the size is not even stored in the header. So in luksDump, it looks like this: Data segments: 0: crypt offset: 16777216 [bytes] length: (whole device) cipher: aes-xts-plain64 sector: 4096 [bytes] And you can use any device with it and cryptsetup will encrypt the whole thing for you. With an external header, the offset can technically be set to 0, though that has its own set of issues - your device will lack UUID/LABEL and random data could be misidentified as another meaningful data.
Can a LUKS2 detached header technically be used for multiple drives?
1,615,361,613,000
A few years ago I used this excellent guide https://www.youtube.com/watch?v=co5V2YmFVEE to encrypt my Thinkpad disk with LUKS and use BTRFS as my file system. My SSD at that time only had 256GB, now I have updated to 1TB and have used Clonezilla to clone my drive to the new SSD. The only question remains - how can I safely extend my LUKS encrypted partition and the BTRFS system (with 2 subvolumes - root and home) under it? My /etc/fstab # /dev/nvme0n1p1 UUID=6E39-1234 /boot vfat rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro 0 2 # /dev/mapper/cryptroot UUID=d7cf34c3-8fb4-4cbb-b04b-96e8121e11d9 / btrfs rw,noatime,compress=zstd:3,ssd,discard=async,space_cache=v2,subvolid=256,subvol=/@ 0 0 # /dev/mapper/cryptroot UUID=d7cf34c3-8fb4-4cbb-b04b-96e8121e11d9 /home btrfs rw,noatime,compress=zstd:3,ssd,discard=async,space_cache=v2,subvolid=257,subvol=/@home 0 0
So to answer my own question, this is the easiest way to do this (confirmed working - of course always have a backup ready, I had mine on my NAS via Clonezilla): The name of my device is - cryptroot Boot up a Live CD/USB (I use Arch so I picked that) Open the encrypted partition - cryptsetup open /dev/nvme0n1p2 cryptroot Open the disk with parted, in my case /dev/nvme0n1 - parted /dev/nvme0n1 Print the partitions and then execute resizepart NUMBER 100% (where NUMBER is the ID of the encrypted partition - which should be last on disk, in my case 2) Close the LUKS device once - cryptsetup close cryptroot Opne the LUKS device again - cryptsetup open /dev/nvme0n1p2 cryptroot Resize LUKS - cryptsetup resize cryptroot Mount the partition to any folder (I chose /partition) - mount /dev/mapper/cryptroot /partition Resize BTRFS - btrfs filesystem resize max /partition Unmount the partition Close the LUKS device - cryptsetup close cryptroot Restart into your OS You can also do a test run on any Type 1 Hypervisor you use (that's what I did) - just restore the image via Clonezilla
Extend BTRFS LUKS partition
1,615,361,613,000
TPMs are supposed to solve a chicken and egg problem of where to store unencrypted disk encryption keys such that someone can't simply pop another hard drive in the machine, boot a different OS and read the keys right off the disk / flash / BIOS / ... AFAIK TPMs basically do this by checking what software booted and, if that software doesn't match a preset hash, it will remain locked and refuse to give out the disk encryption keys. I've read numerous articles pointing to the fact that systemd can help embed my LUKS keys in a TPM with systemd-cryptenroll. But these only speak of embedding the key in the TPM, and not preventing attackers reading those keys. Where I'm stuck is figuring out how to ensure there's a solid chain of trust from BIOS firmware to login ensuring that if the OS is tampered with it will either not boot, or the TPM will refuse to hand over the encryption key. For example there's not much use in encrypting my hard drive if someone at the terminal could simply press E at the grub prompt and boot linux with init=/bin/bash to give themselves a root login without needing a password. Encryption would be utterly pointless in that situation. I'm stuck on two fairly specific points: What does a typical systemd based distribution (Debian or Ubuntu) do to lock the TPM in the first place. What files does this protect from tampering? What other things in the boot sequence must I harden from tampering? eg: grub EFI binary, grub.cfg in EFI, grub passwordles editing boot entries, initramfs, ...
Where I'm stuck is figuring out how to ensure there's a solid chain of trust from BIOS firmware to login ensuring that if the OS is tampered with it will either not boot, or the TPM will refuse to hand over the encryption key. That's built into the process; it's the --tpm-pcrs= option that you give to systemd-cryptenroll. The TPM keeps an in-memory "event log" of various events provided to it by system firmware, by the bootloader, and occassionally by the OS. Each event "measures" some part of the system – e.g. the firmware will log a hash of the grubx64.efi executable as it is loaded; GRUB will log every command and (probably?) log a hash of the kernel image being executed; the kernel will log a hash of the initrd and a hash of the command line – and each event "extends" a hash chain that's also stored in the TPM's memory. The destination of all those measurements is a set of PCRs, "platform configuration registers", each of which holds a SHA hash. Each event extends one of the PCRs using the formula: new_value = H(old_value || event_data_hash) so that the final hash in the PCR authenticates the entire event chain for that PCR, exactly like how a single Git commit hash authenticates the entire history of commits leading up to it. (Although there is only one event log, each event only updates a single PCR, so each of the PCRs acts as an independent hash chain.) On their own, the PCRs do absolutely nothing, but the "seal" operation can be used to specify a policy that may require specific PCRs to have specific values; if the policy is not met, the TPM will refuse to unseal the data. So whenever systemd-cryptenroll asks the TPM to seal (encrypt) the LUKS volume key, it includes a policy based on whatever --tpm-pcrs= you have specified. What exactly is being secured depends on which PCRs you select. For example, PCR[4] will contain firmware-generated events that measure every .efi executable that's being run. (This might include the Linux kernel if it's being run as an "EFI stub" with its own embedded bootloader.) This can get annoying as the hashes will change on every upgrade, so Windows with BitLocker often ties the tamper protection to Secure Boot – it binds to PCR[7] which instead contains events for the certificates that were used to sign the executables; anything signed by Microsoft's "official Windows first-party certificate" will pass. Then, if you also wanted to measure the initramfs, with modern (5.17+) Linux kernels you would include PCR[9] in the policy. For the kernel cmdline, systemd-boot would update PCR[8]. (I'm not sure what GRUB uses or when.) Recently systemd developers have put more emphasis on the "Unified Kernel Images" that contain the kernel and the initramfs and the command line bundled together; the entire bundle would be authenticated as a single .efi binary. (I have an old project that's able to dump the event log in text format, in addition to its regular functions.) Specifically for Linux there's a non-authoritative guide to which PCR indexes are used for which purposes here. On Ubuntu, the package tpm2-tools includes the command tpm2_eventlog which can be used to read the TPM's event log via the kernel: tpm2_eventlog /sys/kernel/security/tpm0/binary_bios_measurements This can help determine exactly what content was used to generate the PCR values and therefore which files and settings are effectively protected from tampering.
How must I configure Debian or Ubuntu to ensure there's a chain of trust from TPM to Login?
1,615,361,613,000
If I LUKS encrypted a hard drive using linux machine A, can I read the data on it using machine B? Of course assuming I know the passphrase of the disk. Thanks.
Yes, assuming the passphrase you know is a LUKS passphrase in the first place. LUKS is designed so that the actual master keys that encrypt the blocks are part of the LUKS header and any user key like a passphrase used to unlock the disk simply decrypts a copy of the master keys. However, if the passphrase is used to get the real user key from some other source, like unsealing it from a TPM object in some outside system that interfaces with LUKS then maybe not. Often a system like that cannot be moved between devices.
read encrypted LUKS hard drive from another machine
1,615,361,613,000
A friend of mine has Debian without systemd running on a disk with full disk encryption (including /boot on the same partition as / using LVM). She is prompted twice for the encryption password when booting: Once by grub, and once by the kernel. Our goal is that she is prompted exactly once. I have found a this guide that works for Arch-based GNU/Linux claiming to overcome the problem. But it doesn't work for Debian-based GNU/Linux because at least one of the packages is a little different. Chapter 11 of the guide explains how to make a keyfile that the kernel can use after the drive has been unlocked. That way, the user is prompted exactly once. How would these steps be translated to Debian-based distribution? The following is the guide. Guide Boot up and log in as root or your user. Then generate the key file: # dd bs=512 count=4 if=/dev/urandom of=/etc/mykeyfile iflag=fullblock Insert it into the LUKS volume: # cryptsetup luksAddKey /dev/sdX /etc/mykeyfile ...and enter your LUKS passphrase when prompted. Edit /etc/mkinitcpio.conf to include the key in the FILES array, e.g. FILES="/etc/mykeyfile" Create the initramfs image from scratch: # mkinitcpio -p linux-libre # mkinitcpio -p linux-libre-lts # mkinitcpio -p linux-libre-hardened Add the following to the kernel (linux) line in your grub.cfg -- which you now know to do, see above! --, e.g. after root=/dev/matrix/rootvol if you've followed this guide: # cryptkey=rootfs:/etc/mykeyfile Finally, deny read access to the key file, even by root: # chmod 000 /etc/mykeyfile
On Debian 11 at least, if you have the cryptsetup-initramfs package installed, its /usr/share/initramfs-tools/hooks/cryptroot script will parse your /etc/crypttab and, if I read the script correctly, will automatically detect if your root filesystem is on an encrypted container that is supposed to be unlocked by a keyfile, and will automatically include the keyfile to initramfs. So, after the cryptsetup luksAddKey step, the Debian 11 equivalent would be to make sure the cryptroot-initramfs package is installed, add the keyfile definition to the root filesystem's /etc/crypttab line just like you were setting up a LUKS container for some non-root filesystem. Using the same names as in your example, the crypttab line would be: sdX_crypt /dev/sdX /etc/mykeyfile luks or rather, you really should to use the UUID of the LUKS volume instead for robustness: sdX_crypt UUID=... /etc/mykeyfile luks Then run update-initramfs -u -k all. The sdX_crypt is the name of the mapping device that will be used to access the encrypted content once the encryption is unlocked. Debian installer will default to creating the mapping device name by taking the basename of the encrypted device and adding the _crypt suffix, but I believe it can be customized too. Since your friend uses LVM, you will need to run lsblk and see the NAME column of the LVM devices used for the root and /boot filesystems: those names will be of the form VGname-LVname. You'll need the VGname part, then run pvs as root and find the name of the PV containing the named VG. That should be something like /dev/mapper/sdX_crypt. The hook script will be executed by update-initramfs. It will pick up the information from /etc/crypttab and automatically add the keyfile and the necessary script snippet to use it into the initramfs. You won't need to add the boot option - the autogenerated initramfs script will have all the parameters it needs embedded in it. The link you posted in the comments can certainly be used, but you really should use the crypttab(5) man page of your distribution for the most accurate information. Setting the protection for /etc/mykeyfile to chmod 600 or less is a good idea. I'm not certain whether setting chmod 000 is any use, but you can try it; worst case, you'll just need to type the encryption password twice at next boot, and then readjust the permissions and run update-initramfs -u -k all again.
Preventing boot prompting twice for encryption passphrase on Debian based OS
1,615,361,613,000
I had the following setup: 3 HDDs 10Tb of size, in LVM Raid5 configuration On top a LUKS2 encryption and inside a BTRFS filesystem. Since my storage got low i added another 16TB HDD (was cheaper than 10TB) added it as physcial volume in LVM, added it to the volume group, ran a resync, so that LVM can adjust the size of my RAID. I resized the btrfs partition to max. I noticed, that in dmesg errors began to appear shortly after the btrfs resize when i write to it: [53034.840728] btrfs_dev_stat_print_on_error: 299 callbacks suppressed [53034.840731] BTRFS error (device dm-15): bdev /dev/mapper/data errs: wr 807, rd 0, flush 0, corrupt 0, gen 0 [53034.841289] BTRFS error (device dm-15): bdev /dev/mapper/data errs: wr 808, rd 0, flush 0, corrupt 0, gen 0 [53034.844993] BTRFS error (device dm-15): bdev /dev/mapper/data errs: wr 809, rd 0, flush 0, corrupt 0, gen 0 [53034.845893] BTRFS error (device dm-15): bdev /dev/mapper/data errs: wr 810, rd 0, flush 0, corrupt 0, gen 0 [53034.846154] BTRFS error (device dm-15): bdev /dev/mapper/data errs: wr 811, rd 0, flush 0, corrupt 0, gen 0 I can exclude hardware problems, since i tried that on another computer in a virtual machine. The problems in dmesg do appear when i write bigger files (400Mb) to the filesystem, but not something like a text file - the checksum is also wrong after a copy from one file of the raid to another: gallifrey raid5 # dd if=/dev/urandom of=original.img bs=40M count=100 0+100 records in 0+100 records out 3355443100 bytes (3.4 GB, 3.1 GiB) copied, 54.0163 s, 62.1 MB/s gallifrey raid5 # cp original.img copy.img gallifrey raid5 # md5sum original.img copy.img 29867131c09cc5a6e8958b2eba5db4c9 original.img 59511b99494dd4f7cf1432b19f4548c4 copy.img gallifrey raid5 # btrfs device stats /mnt/raid5 [/dev/mapper/data].write_io_errs 811 [/dev/mapper/data].read_io_errs 0 [/dev/mapper/data].flush_io_errs 0 [/dev/mapper/data].corruption_errs 0 [/dev/mapper/data].generation_errs 0 I already resynced the entire lvm raid, did a smartctl checkup multiple times (shouldn't be a hw problem, but still) and did btrfs scrub start -B /mnt/raid5 and btrfs check -p --force /dev/mapper/data while non of them returned any error whatsoever. Hapened on kernel 5.15.11 and 5.10.27 lvm version: gallifrey raid5 # lvm version LVM version: 2.02.188(2) (2021-05-07) Library version: 1.02.172 (2021-05-07) Driver version: 4.45.0 My goal is that future writes to the drive are non-corrupted, while the already corrupted files can be deleted, but the good files I would like to save or at least not delete. From the man page of btrfs it says, that write_io_errs means that the block device beneath does not succeed in writing. In my case that means, that lvm and or luks2 is the problem here. Any suggestions, or any more information needed? Cheers
I could not find the root cause of this problem, so I decided to ditch LVM in it's entirety and replace it with mdadm - which worked like charm on the first try. Creating mdadm RAID5 (initially with 3 disks) Creating with three disks (henceworth raid-devices = 3): mdadm --create mediaraid --level=raid5 --raid-devices=3 /dev/sda /dev/sdb /dev/sde Optionally checking what encryption you can use at what speed (memory speed, not disk IO): cryptsetup benchmark /dev/md/mediaraid Optionally encrypting the entire RAID (a construct like this does not require to decrypt every disk on its own. One password for the ENTIRE RAID): cryptsetup luksFormat --hash sha512 --cipher aes-xts-plain64 --key-size 512 /dev/md/mediaraid Opening the LUKS device (necessary for formatting it): cryptsetup luksOpen /dev/md/mediaraid Format the RAID with btrfs: mkfs.btrfs /dev/mapper/data -f Growing/Expanding a btrfs filesystem by 1 disk and an underlying mdadm RAID5 Preconditions: Filesystem is not mounted and LUKS device is closed: umount /mnt/raid5 && cryptsetup close /dev/mapper/data Adding /dev/sdc (replace with your drive) to mdadm as a spare disk: mdadm --add /dev/md/mediaraid /dev/sdc Verify it shows up (will be at the bottom, saying it is a spare disk): mdadm --detail /dev/md/mediaraid Note: The following step triggers a RAID reshape, things are getting real, my 10TB hard drives took about 25-30 hours to reshape and sync from 3 to 4 disks. I am not sure if a reboot is safe during the respahe - but I wouldn't recommend it or at least try it in a virtual machine. Grow the RAID to the number of disks (most of the time you want to write the total count of disks here, 3 + 1 = 4, now I have 4 drives available and I want to use ALL 4 of them): mdadm --grow --raid-devices=4 /dev/md/mediaraid Monitor progress of reshape (first one is better): cat /proc/mdstat or mdadm --detail /dev/md/mediaraid After it is done reshaping: Optionally, if you use LUKS Decrypt the RAID - else continue with the next step: cryptsetup luksOpen /dev/md/mediaraid data Mount the btrfs filesystem: mount /dev/mapper/data /mnt/raid5 Grow the btrfs filesystem to max or whatever you want: btrfs filesystem resize max /mnt/raid5 It might be not necessary but I unmounted and remounted the entire thing after the btrfs filesystem resize umount /mnt/raid5 && mount /dev/maper/data /mnt/raid5 Done.
LVM, LUKS2 & BTRFS Problem
1,615,361,613,000
I tried everything I was able to find online. Hours of research since yesterday ;( I found no one struggling with the errors I'm facing, except from GitLab (error code -1 instead of -4 I'm getting), Reddit or this mailing list from 2006. I might give unnecessary details, sorry! I have this 5 TB WD drive where I already have dozens of files. Decided to build a small NAS from a Raspberry Pi 4. Problem was I wanted LUKS encryption, with BTRFS as the file system; the drive was at that time a 5 TB one-partition EXT4. I split the drive in 2 partitions (on my main computer) (only 2.3 TB was occupied), creating a LUKS protected BTRFS partition half the drive size: moved everything to the encrypted BTRFS partition, deleting the EXT4 part, growing LUKS, opening the encryption and then grew the BTRFS partition to fill the entire drive, passphrase still worked for LUKS, for a very long time. I thought nothing could happen when I have the LUKS Header Backup. The 5 TB LUKS-BTRFS partition is only protected with a passphrase, no additional slots etc. configured. I was able to unlock the drive and mount it now maybe for 3 weeks without any hiccups and error codes on all my devices (Artix-Linux x86_64, Linuxmint, Debian Aarch64, Parted Magic). The operating system I chose for the Pi 4 was Debian, not Raspbian OS, since it was lacking the Crypto API/Functionality in the kernel I guess needed for serpent-xts-plain64, my drive encryption cipher. The NAS solution I went with was OpenMediaVault. It does not support unlocking LUKS volumes etc. on its own, so I unlocked it via SSH, mounted the device from the Web UI, created an SMB share, was even able to connect and exchange files for a day. The other day when I wake up I notice when I connect to the SMB share there are no files?! A quick lsblk made clear the drive was not mounted, and the encryption was already closed. Mounting it was now impossible, tried many distros/kernels, architectures (aarch64 & amd64), tried mounting using GParted on many systems, KDE's own disk mounter etc. but no, guess I'm stuck. Funny thing is I was able to change the passphrase using cryptsetup luksChangeKey /dev/sdd1, it happily accepted my password, then successfully changed it to something else (as far as I know when I restore the header the old password is valid). Like I said before I have the LUKS header backup available, it's the right file I know it, since I heard restoring the wrong header makes things more complicated. I hope I don't have to reinvent the wheel to decrypt the drive, but if it's necessary, I'll do it :/ As far as I can remember I did luksFormat using this command, it was inside my .zshrc: cryptsetup -v luksFormat /dev/sdd1 --use-random --verify-passphrase --key-size=512 --hash=whirlpool --cipher=serpent-xts-plain64 --pbkdf=argon2id --type luks2 Here is the output of cryptsetup --debug --verbose luksOpen /dev/sdd1 crypt: ❯ sudo cryptsetup --debug --verbose luksOpen /dev/sdd1 crypt [sudo] password for user: # cryptsetup 2.4.2 processing "cryptsetup --debug --verbose luksOpen /dev/sdd1 crypt" # Running command open. # Locking memory. # Installing SIGINT/SIGTERM handler. # Unblocking interruption on signal. # Allocating context for crypt device /dev/sdd1. # Trying to open and read device /dev/sdd1 with direct-io. # Initialising device-mapper backend library. # Trying to load any crypt type from device /dev/sdd1. # Crypto backend (OpenSSL 1.1.1l 24 Aug 2021) initialized in cryptsetup library version 2.4.2. # Detected kernel Linux 5.15.8-zen1-1-zen x86_64. # Loading LUKS2 header (repair disabled). # Acquiring read lock for device /dev/sdd1. # Opening lock resource file /run/cryptsetup/L_8:49 # Verifying lock handle for /dev/sdd1. # Device /dev/sdd1 READ lock taken. # Trying to read primary LUKS2 header at offset 0x0. # Opening locked device /dev/sdd1 # Verifying locked device handle (bdev) # LUKS2 header version 2 of size 16384 bytes, checksum sha256. # Checksum:cd57d8cf3e5d6bd82e34925c05ac3f84114d564dc1535d443d6003847ede9c03 (on-disk) # Checksum:cd57d8cf3e5d6bd82e34925c05ac3f84114d564dc1535d443d6003847ede9c03 (in-memory) # Trying to read secondary LUKS2 header at offset 0x4000. # Reusing open ro fd on device /dev/sdd1 # LUKS2 header version 2 of size 16384 bytes, checksum sha256. # Checksum:1fa2c8c216bef143a6841c7e6d7b1e737b39a832e3e8067ce580b103673c67b6 (on-disk) # Checksum:1fa2c8c216bef143a6841c7e6d7b1e737b39a832e3e8067ce580b103673c67b6 (in-memory) # Device size 5000946236928, offset 16777216. # Device /dev/sdd1 READ lock released. # PBKDF argon2id, time_ms 2000 (iterations 0), max_memory_kb 1048576, parallel_threads 4. # Activating volume crypt using token (any type) -1. # dm version [ opencount flush ] [16384] (*1) # dm versions [ opencount flush ] [16384] (*1) # Detected dm-ioctl version 4.45.0. # Detected dm-crypt version 1.23.0. # Device-mapper backend running with UDEV support enabled. # dm status crypt [ opencount noflush ] [16384] (*1) No usable token is available. # Interactive passphrase entry requested. Enter passphrase for /dev/sdd1: # Activating volume crypt [keyslot -1] using passphrase. # dm versions [ opencount flush ] [16384] (*1) # dm status crypt [ opencount noflush ] [16384] (*1) # Keyslot 0 priority 1 != 2 (required), skipped. # Trying to open LUKS2 keyslot 0. # Running keyslot key derivation. # Reading keyslot area [0x47000]. # Acquiring read lock for device /dev/sdd1. # Opening lock resource file /run/cryptsetup/L_8:49 # Verifying lock handle for /dev/sdd1. # Device /dev/sdd1 READ lock taken. # Reusing open ro fd on device /dev/sdd1 # Device /dev/sdd1 READ lock released. # Verifying key from keyslot 0, digest 0. # Loading key (64 bytes, type logon) in thread keyring. # dm versions [ opencount flush ] [16384] (*1) # dm status crypt [ opencount noflush ] [16384] (*1) # Calculated device size is 9767440351 sectors (RW), offset 32768. # DM-UUID is CRYPT-LUKS2-355457dcd03343349b2121f41f3e0a5c-crypt # Udev cookie 0xd4de97d (semid 4) created # Udev cookie 0xd4de97d (semid 4) incremented to 1 # Udev cookie 0xd4de97d (semid 4) incremented to 2 # Udev cookie 0xd4de97d (semid 4) assigned to CREATE task(0) with flags DISABLE_LIBRARY_FALLBACK (0x20) # dm create crypt CRYPT-LUKS2-355457dcd03343349b2121f41f3e0a5c-crypt [ opencount flush ] [16384] (*1) # dm reload (254:3) [ opencount flush securedata ] [16384] (*1) device-mapper: reload ioctl on crypt (254:3) failed: Invalid argument # Udev cookie 0xd4de97d (semid 4) decremented to 1 # Udev cookie 0xd4de97d (semid 4) incremented to 2 # Udev cookie 0xd4de97d (semid 4) assigned to REMOVE task(2) with flags DISABLE_LIBRARY_FALLBACK (0x20) # dm remove crypt [ opencount flush securedata ] [16384] (*1) # Uevent not generated! Calling udev_complete internally to avoid process lock-up. # Udev cookie 0xd4de97d (semid 4) decremented to 1 # dm versions [ opencount flush ] [16384] (*1) # dm status crypt [ opencount noflush ] [16384] (*1) # Udev cookie 0xd4de97d (semid 4) decremented to 0 # Udev cookie 0xd4de97d (semid 4) waiting for zero # Udev cookie 0xd4de97d (semid 4) destroyed # Requesting keyring logon key for revoke and unlink. # Releasing crypt device /dev/sdd1 context. # Releasing device-mapper backend. # Closing read only fd for /dev/sdd1. # Unlocking memory. Command failed with code -4 (wrong device or file specified). The output of fdisk -l: Disk /dev/sdd: 4.55 TiB, 5000947302400 bytes, 9767475200 sectors Disk model: My Passport 2627 Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes Disklabel type: gpt Disk identifier: 2505C284-7B8A-4EAE-90CB-950187A84D57 Device Start End Sectors Size Type /dev/sdd1 2048 9767475166 9767473119 4.5T Linux filesystem The luksDump, arrently needed too; output of cryptsetup luksDump /dev/sdd1: ❯ sudo cryptsetup luksDump /dev/sdd1 LUKS header information Version: 2 Epoch: 5 Metadata area: 16384 [bytes] Keyslots area: 16744448 [bytes] UUID: 355457dc-d033-4334-9b21-21f41f3e0a5c Label: (no label) Subsystem: (no subsystem) Flags: (no flags) Data segments: 0: crypt offset: 16777216 [bytes] length: (whole device) cipher: serpent-xts-plain64 sector: 4096 [bytes] Keyslots: 0: luks2 Key: 512 bits Priority: normal Cipher: serpent-xts-plain64 Cipher key: 512 bits PBKDF: argon2id Time cost: 5 Memory: 1048576 Threads: 4 Salt: 67 4b ad d5 89 b5 64 b7 b7 46 61 0f a4 9f cb be 52 90 11 99 8c c0 fb 81 be 6a d6 ac 58 f5 3c 12 AF stripes: 4000 AF hash: sha256 Area offset:290816 [bytes] Area length:258048 [bytes] Digest ID: 0 Tokens: Digests: 0: pbkdf2 Hash: whirlpool Iterations: 68985 Salt: d7 56 5e 8a d3 7c 7a 86 d3 fc b5 f8 d8 1e 6f 8d b3 fd 04 34 e7 08 ab 9a 33 92 2f 08 96 4b ff 74 Digest: ed 9c d5 5f 0e df b3 f3 5b 71 95 09 9d f0 a8 b5 9c a5 02 cb d0 1f f7 7b 52 d2 24 29 ee b2 7b 3f ed bc bd 1d f8 f7 bb 9f f7 c9 68 9b c9 be 86 66 8b 24 5a 3c b7 b2 3e 93 7e d0 42 7c 7e e1 6d ec S.M.A.R.T. values output using smartctl -a /dev/sdd: ❯ sudo smartctl -a /dev/sdd smartctl 7.2 2020-12-30 r5155 [x86_64-linux-5.15.8-zen1-1-zen] (local build) Copyright (C) 2002-20, Bruce Allen, Christian Franke, www.smartmontools.org === START OF INFORMATION SECTION === Model Family: Western Digital Elements / My Passport (USB, AF) Device Model: WDC WD50NDZW-11MR8S1 Serial Number: WD-WXD1E995WRAF LU WWN Device Id: 5 0014ee 211f0443e Firmware Version: 02.01A02 User Capacity: 5,000,947,523,584 bytes [5.00 TB] Sector Sizes: 512 bytes logical, 4096 bytes physical Rotation Rate: 5400 rpm Form Factor: 2.5 inches TRIM Command: Available, deterministic Device is: In smartctl database [for details use: -P show] ATA Version is: ACS-3 (minor revision not indicated) SATA Version is: SATA 3.1, 6.0 Gb/s (current: 6.0 Gb/s) Local Time is: Fri Dec 17 16:02:40 2021 CET SMART support is: Available - device has SMART capability. SMART support is: Enabled === START OF READ SMART DATA SECTION === SMART overall-health self-assessment test result: PASSED General SMART Values: Offline data collection status: (0x82) Offline data collection activity was completed without error. Auto Offline Data Collection: Enabled. Self-test execution status: ( 249) Self-test routine in progress... 90% of test remaining. Total time to complete Offline data collection: ( 2940) seconds. Offline data collection capabilities: (0x1b) SMART execute Offline immediate. Auto Offline data collection on/off support. Suspend Offline collection upon new command. Offline surface scan supported. Self-test supported. No Conveyance Self-test supported. No Selective Self-test supported. SMART capabilities: (0x0003) Saves SMART data before entering power-saving mode. Supports SMART auto save timer. Error logging capability: (0x01) Error logging supported. General Purpose Logging supported. Short self-test routine recommended polling time: ( 2) minutes. Extended self-test routine recommended polling time: ( 776) minutes. SCT capabilities: (0x30b5) SCT Status supported. SCT Feature Control supported. SCT Data Table supported. SMART Attributes Data Structure revision number: 16 Vendor Specific SMART Attributes with Thresholds: ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE 1 Raw_Read_Error_Rate 0x002f 200 200 051 Pre-fail Always - 2 3 Spin_Up_Time 0x0027 253 253 021 Pre-fail Always - 4808 4 Start_Stop_Count 0x0032 100 100 000 Old_age Always - 825 5 Reallocated_Sector_Ct 0x0033 200 200 140 Pre-fail Always - 0 7 Seek_Error_Rate 0x002e 200 200 000 Old_age Always - 0 9 Power_On_Hours 0x0032 098 098 000 Old_age Always - 1577 10 Spin_Retry_Count 0x0032 100 100 000 Old_age Always - 0 11 Calibration_Retry_Count 0x0032 100 100 000 Old_age Always - 0 12 Power_Cycle_Count 0x0032 100 100 000 Old_age Always - 321 192 Power-Off_Retract_Count 0x0032 200 200 000 Old_age Always - 176 193 Load_Cycle_Count 0x0032 198 198 000 Old_age Always - 6431 194 Temperature_Celsius 0x0022 119 098 000 Old_age Always - 33 196 Reallocated_Event_Count 0x0032 200 200 000 Old_age Always - 0 197 Current_Pending_Sector 0x0032 200 200 000 Old_age Always - 0 198 Offline_Uncorrectable 0x0030 200 200 000 Old_age Offline - 0 199 UDMA_CRC_Error_Count 0x0032 200 200 000 Old_age Always - 0 200 Multi_Zone_Error_Rate 0x0008 200 200 000 Old_age Offline - 1 SMART Error Log Version: 1 No Errors Logged SMART Self-test log structure revision number 1 No self-tests have been logged. [To run self-tests, use: smartctl -t] Selective Self-tests/Logging not supported And here's the DMESG output (simply dmesg, due to character limit couldn't post everything): [ 46.940566] wlan0: associated [ 46.989890] wlan0: Limiting TX power to 23 (23 - 0) dBm as advertised by 5c:49:79:56:19:f7 [ 50.007552] usb 2-6: new SuperSpeed USB device number 2 using xhci_hcd [ 50.020426] usb 2-6: New USB device found, idVendor=1058, idProduct=2627, bcdDevice=40.08 [ 50.020439] usb 2-6: New USB device strings: Mfr=2, Product=3, SerialNumber=1 [ 50.020444] usb 2-6: Product: My Passport 2627 [ 50.020448] usb 2-6: Manufacturer: Western Digital [ 50.020452] usb 2-6: SerialNumber: 575844314539393557524146 [ 50.664550] usb-storage 2-6:1.0: USB Mass Storage device detected [ 50.665002] scsi host4: usb-storage 2-6:1.0 [ 50.665220] usbcore: registered new interface driver usb-storage [ 50.676478] usbcore: registered new interface driver uas [ 51.678278] scsi 4:0:0:0: Direct-Access WD My Passport 2627 4008 PQ: 0 ANSI: 6 [ 51.678667] scsi 4:0:0:1: Enclosure WD SES Device 4008 PQ: 0 ANSI: 6 [ 51.682041] sd 4:0:0:0: [sdd] Spinning up disk... [ 51.703600] scsi 4:0:0:1: Wrong diagnostic page; asked for 1 got 8 [ 51.703603] scsi 4:0:0:1: Failed to get diagnostic page 0x1 [ 51.703605] scsi 4:0:0:1: Failed to bind enclosure -19 [ 52.701886] ......ready [ 57.822064] sd 4:0:0:0: [sdd] Very big device. Trying to use READ CAPACITY(16). [ 57.822250] sd 4:0:0:0: [sdd] 9767475200 512-byte logical blocks: (5.00 TB/4.55 TiB) [ 57.822255] sd 4:0:0:0: [sdd] 4096-byte physical blocks [ 57.822540] sd 4:0:0:0: [sdd] Write Protect is off [ 57.822544] sd 4:0:0:0: [sdd] Mode Sense: 47 00 10 08 [ 57.823041] sd 4:0:0:0: [sdd] No Caching mode page found [ 57.823048] sd 4:0:0:0: [sdd] Assuming drive cache: write through [ 57.983930] sdd: sdd1 [ 57.985534] sd 4:0:0:0: [sdd] Attached SCSI disk [ 57.985680] ses 4:0:0:1: Attached Enclosure device [ 137.355239] nvidia-nvlink: Nvlink Core is being initialized, major device number 507 [ 137.355244] NVRM: The NVIDIA probe routine was not called for 1 device(s). [ 137.356116] NVRM: This can occur when a driver such as: NVRM: nouveau, rivafb, nvidiafb or rivatv NVRM: was loaded and obtained ownership of the NVIDIA device(s). [ 137.356117] NVRM: Try unloading the conflicting kernel module (and/or NVRM: reconfigure your kernel without the conflicting NVRM: driver(s)), then try loading the NVIDIA kernel module NVRM: again. [ 137.356118] NVRM: No NVIDIA devices probed. [ 137.356296] nvidia-nvlink: Unregistered the Nvlink Core, major device number 507 [ 317.920451] device-mapper: table: 254:3: crypt: Device size is not multiple of sector_size feature [ 317.920455] device-mapper: ioctl: error adding target to table [ 2685.464145] raid6: skip pq benchmark and using algorithm avx2x4 [ 2685.464148] raid6: using avx2x2 recovery algorithm [ 2685.468011] xor: automatically using best checksumming function avx [ 2685.528254] Btrfs loaded, crc32c=crc32c-intel, zoned=yes, fsverity=yes [ 2685.564424] JFS: nTxBlock = 8192, nTxLock = 65536 [ 2685.582407] NILFS version 2 loaded [ 2685.676402] SGI XFS with ACLs, security attributes, realtime, scrub, repair, quota, no debug enabled [ 2692.757592] sda: sda1 sda2 sda3 sda4 [ 2694.215474] sdd: sdd1 [ 2768.779512] device-mapper: table: 254:3: crypt: Device size is not multiple of sector_size feature [ 2768.779536] device-mapper: ioctl: error adding target to table [ 3123.484363] usb 2-6: USB disconnect, device number 2 [ 4886.654141] usb 2-6: new SuperSpeed USB device number 3 using xhci_hcd [ 4886.667772] usb 2-6: New USB device found, idVendor=1058, idProduct=2627, bcdDevice=40.08 [ 4886.667776] usb 2-6: New USB device strings: Mfr=2, Product=3, SerialNumber=1 [ 4886.667778] usb 2-6: Product: My Passport 2627 [ 4886.667779] usb 2-6: Manufacturer: Western Digital [ 4886.667780] usb 2-6: SerialNumber: 575844314539393557524146 [ 4886.669555] usb-storage 2-6:1.0: USB Mass Storage device detected [ 4886.669800] scsi host4: usb-storage 2-6:1.0 [ 4887.692812] scsi 4:0:0:0: Direct-Access WD My Passport 2627 4008 PQ: 0 ANSI: 6 [ 4887.693055] scsi 4:0:0:1: Enclosure WD SES Device 4008 PQ: 0 ANSI: 6 [ 4887.694634] ses 4:0:0:1: Attached Enclosure device [ 4887.695784] sd 4:0:0:0: [sdd] Spinning up disk... [ 4887.696087] ses 4:0:0:1: Wrong diagnostic page; asked for 1 got 8 [ 4887.696090] ses 4:0:0:1: Failed to get diagnostic page 0x1 [ 4887.696092] ses 4:0:0:1: Failed to bind enclosure -19 [ 4888.716288] ......ready [ 4893.836679] sd 4:0:0:0: [sdd] Very big device. Trying to use READ CAPACITY(16). [ 4893.836793] sd 4:0:0:0: [sdd] 9767475200 512-byte logical blocks: (5.00 TB/4.55 TiB) [ 4893.836795] sd 4:0:0:0: [sdd] 4096-byte physical blocks [ 4893.837071] sd 4:0:0:0: [sdd] Write Protect is off [ 4893.837072] sd 4:0:0:0: [sdd] Mode Sense: 47 00 10 08 [ 4893.837383] sd 4:0:0:0: [sdd] No Caching mode page found [ 4893.837385] sd 4:0:0:0: [sdd] Assuming drive cache: write through [ 4893.996397] sdd: sdd1 [ 4893.997502] sd 4:0:0:0: [sdd] Attached SCSI disk [ 4951.411265] device-mapper: table: 254:3: crypt: Device size is not multiple of sector_size feature [ 4951.411286] device-mapper: ioctl: error adding target to table
This is a problem with the device size of your partition. Your partition is an odd number of 512-byte sectors large (9767473119 sectors as shown by fdisk). Your LUKS header is set to use 4096-byte sectors (sector: 4096 [bytes] shown by cryptsetup luksDump). So that leaves 7 sectors on the partition that can not be used. Unfortunately, instead of just ignoring the surplus sectors, the device mapper crypt target takes offense, resulting in such error messages: [ 8243.293778] device-mapper: table: 253:49: crypt: Device size is not multiple of sector_size feature (-EINVAL) [ 8243.293781] device-mapper: ioctl: error adding target to table In this case you have to make the partition size 4K aligned, i.e. a multiple of 8 512-byte sectors. You can do that with parted resizepart or any other partition tool of your choice. Just make sure the start sector of the partition does not change.
(Probably) Corrupted LUKS Header, Restoring Header does not work
1,615,361,613,000
On linux mint and fedora, when you first boot a LUKS encrypted system, instead of a command line passphrase entering section, it has kind of a GUI that looks better than the default command line on Debian. I noticed that on Debian you can press escape and it will change to a similar type of menu. Is there any way to set this "GUI" type LUKS decryption screen as the default? Also what would be the proper terminology for this screen?
The proper terminology is "flicker-free boot", it was implemented in Fedora about 2-3 years ago (here announcement on the hacker news - https://news.ycombinator.com/item?id=18123984), so it's still relatively new, and many distributions are lacking proper support. When it comes to Debian, I couldn't find much information like how it is supported. There are some forums topics/Reddit threads like this: https://forums.debian.net/viewtopic.php?f=30&t=148804 . This thread has some links that might help. Finally, you might contact developers or fill a bug report about better support or request for documentation update/change.
How to set LUKS loading screen Debian
1,615,361,613,000
I had a LUKS partition for which cryptsetup luksDump /dev/mydisk gave (excerpt) Digests: 0: pbkdf2 Hash: sha256 Iterations: 176646 Salt: xx xx ... ... Running cryptsetup reencrypt /dev/mydisk while the container was offline removed the previous digest after it was done (understandably), leaving the following (Iterations has now changed to a much smaller value) Digests: 1: pbkdf2 Hash: sha256 Iterations: 1000 Salt: xx xx ... ... I doubt I selected the first iteration count manually, so I assume it was chosen by benchmark at luksFormat time. After the reencrypt the iteration count is much smaller, and to my poor knowledge so small that it is not recommended. I would have understood if reencrypt re-chose a default, but clearly it didn't even run a benchmark. Since the digest protects the master key, is this a bug in cryptsetup?
This appears to be a bug in cryptsetup. I've filed a report here: https://gitlab.com/cryptsetup/cryptsetup/-/issues/606.
`cryptsetup reencrypt` seems to cripple digest iteration count
1,615,361,613,000
I have backed up a drive with all its partitions using the command dd if=/dev/sda of=/media/oshirowanen/external-drive/backups-2019/full_drive_backup.img /dev/sda is an ssd which has a Linux OS with full encryption. Before I wipe this drive and re-purpose it, I want to make sure the backup has worked. I have tried the following by searching unix.stackexchange and other stackexchange sites: sudo losetup -P /dev/loop0 /media/oshirowanen/external-drive/backups-2019/full_drive_backup.img [sudo] password for oshirowanen: [password goes here] losetup: /media/oshirowanen/external-drive/backups-2019/full_drive_backup.img: failed to set up loop device: Device or resource busy sudo losetup -P /dev/loop100 /media/oshirowanen/external-drive/backups-2019/full_drive_backup.img sudo cryptsetup luksOpen /dev/loop100p5 img5 Enter passphrase for /dev/loop100p5: [password goes here] cd /mnt mkdir img5 sudo mount /dev/mapper/img5 img5 mount: /mnt/img5: unknown filesystem type 'LVM2_member'. What am I doing wrong? Both cryptsetup and lvm2 are already installed. If this is not the best way to backup the drive, please suggest something else which is better. UPDATE 1: Here is a screenshot of /dev/sda's partitions: UPDATE 2: Output from LiveUSB: liveusb@liveusb:~$ sudo losetup -P /dev/loop100 /media/external-drive/backups-2019/full_drive_backup.img liveusb@liveusb:~$ sudo cryptsetup luksOpen /dev/loop100p5 img5 Enter passphrase for /dev/loop100p5: liveusb@liveusb:~$ cd /mnt liveusb@liveusb:/mnt$ sudo mkdir img5 liveusb@liveusb:/mnt$ sudo mount /dev/mapper/img5 img5 mount: /mnt/img5: unknown filesystem type 'LVM2_member'. liveusb@liveusb:/mnt$ sudo pvscan PV /dev/mapper/img5 VG ubuntu-vg lvm2 [232.16 GiB / 0 free] Total: 1 [232.16 GiB] / in use: 1 [232.16 GiB] / in no VG: 0 [0 ] liveusb@liveusb:/mnt$ sudo vgscan Reading volume groups from cache. Found volume group "ubuntu-vg" using metadata type lvm2 liveusb@liveusb:/mnt$ sudo vgs VG #PV #LV #SN Attr VSize VFree ubuntu-vg 1 2 0 wz--n- 232.16g 0 liveusb@liveusb:/mnt$ sudo lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root ubuntu-vg -wi-a----- <231.21g swap_1 ubuntu-vg -wi-a----- 980.00m liveusb@liveusb:/mnt$ ls /dev/mapper/ control img5 ubuntu--vg-root ubuntu--vg-swap_1 liveusb@liveusb:/mnt$
Judging from the image, the partition seems to be a physical volume. This is verified by pvscan. lvs lists two logical volumes, one of them a swap partition (LV swap_1) it seems, and the other the actual file system (LV root). This is the relevant one, to be mounted by mount -o ro /dev/mapper/ubuntu--vg-root /mnt/img5 When the devices are missing, vgscan --mknodes --mknodes Also checks the LVM special files in /dev that are needed for active LVs and creates any missing ones and removes unused ones. or vgmknodes might be helpful vgmknodes checks the LVM device nodes in /dev that are needed for active LVs and creates any that are missing and removes unused ones.
Mounting a Luks partition
1,615,361,613,000
How do we unlock multiple disks with one password prompt at CentOS-7 bootup? In Debian, I can do it using decrypt_keyctl & initramfs in /etc/crypttab (which I see is described here). Right now, I'm using Nethserver, and crypttab looks like: luks_root UUID=<uuid1> none luks_swap UUID=<uuid2> none How do I add another disk, which I want to decrypt via a (the same) password? Perhaps that will also clear up the mystery of how it is that the present bootup happens with only one password prompt and without a keyfile.
It turns out the answer is actually Method1 in this answer. It applies to both Ubuntu and CentOS. Quoting: Systemd ... will unlock all additional LUKS partitions if all of the partitions you want to unlock use the same password you enter the password for the root partition correctly the first time. If you get it wrong, you'll need to enter it again for every other LUKS partition
Multiple LUKS Disks @Boot with One Password Prompt (CentOS)
1,615,361,613,000
I have several servers each with at least six dm-crypt partitions. I would like to have an automated way to make sure I always have a luks header backup stored in a safe place. I've been making header backups manually until now. My problem with that is that I tend to forget to make a new luks header backup when I have to swap out a hard drive or make other system changes. I'm looking for an existing script that will check to see if a luks header backup exists, and if not, create one. I have to assume somebody has written such a script already. (The need for it seems obvious.) If one does not exist, I'll attempt to make a bash script for the purpose. My manual commands look like this: cryptsetup luksHeaderBackup /dev/sdXN --header-backup-file /path/to/backup/$mountpoint_luksHeader_$devUUID.img I would like to have both the mountpoint and the device UUID in the file name of the header image file. The only clue I have about getting started is that I would need to iterate through all devices and find the partitions of type crypt, then find the corresponding mount point and UUID. I know most of that info exists in lsblk and blkid. I'm not sure how to extract it for use in a script. EDIT: my goal is to name the files intelligently, based on mount points. Each crypto_LUKS device contains one or more BTRFS subvolumes. For example, the crypto_LUKS device sysluks contains four btrfs subvolumes which are: @root @var_log @root_snapshots @var_log_snapshots The command lsblk gives output like this, where only the last of those subvolumes to be mounted is shown as the mountpoint: NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 1.8T 0 disk └─sda2 8:2 0 1.8T 0 part └─sysluks 254:0 0 1.8T 0 crypt /var/log/.snapshots Using /var/log/.snapshots as the name of the file that contains the backup for the root device is not ideal. The command findmnt -t btrfs will show all mountpoints for a given source (such as /dev/mapper/sysluks). Running a few local tests, findmnt seems to always return a list ordered by mount order at system startup. Picking the first mount point from that list would work for my purposes of naming files, but picking the last, as lsblk does, it never ideal.
cd /path/to/backup/ lsblk --fs --output FSTYPE,UUID | grep crypto_LUKS | tr -s ' ' | cut -d ' ' -f2 | \ while read uuid; do mntpoint=$(lsblk /dev/disk/by-uuid/$uuid --output MOUNTPOINT | sed 1,1d | head -n 1) name="${mntpoint}_luksHeader_$uuid.img" if [[ ! -e "$name" ]]; then cryptsetup luksHeaderBackup /dev/disk/by-uuid/$uuid --header-backup-file $name fi done Change your path/to/backup and it should be good to go. Just know that if the mountpoint for a device changes it will produce multiple header backups. Otherwise, it will ignore already backed up devices.
script to automate luksHeaderBackup for multiple partitions
1,615,361,613,000
I already did some research on my question (see below), and it's as good as a 'done deal' but I would still like to put forward my problem to this knowledgeable community. Short version of the issue: in partman (the disk partitioner of the Debian installer) the passphrase of a previously dm-crypt/LUKS encrypted volume was changed (or added) by mistake. The data on this volume was not flagged for removal. I cancelled the installation after that point. Later after manually 'decrypting' this volume it was found that only the ‘new’ password could decrypt the volume, but data could not be read (i.e. filesystem and files were not found)... I was wondering if after changing back to the old passphrase I would be able to properly decrypt the volume's contents. Previous research: the above question was submitted to the debian-boot mailing list, and there I received the following (very clear) answer: I don't think the data will be recoverable unless you have a backup of the LUKS header. The way LUKS works is that data is not encrypted with a passphrase directly but with a key that is encrypted to a set of passphrases. If you worked purely through the installer's UI you will have overwritten your LUKS header and hence will be unable to decrypt the data ever again because the key material is lost. The position of the LUKS header on disk is always in the same place. Data erase is really just about overwriting the existing data with zeros, which I understand is pretty confusing. Technically the data is already erased by the fact that the header is overwritten but some people want to be sure and write random data (or in the case of non-encrypted disks zeros) to the disk before deploying the system into production. Alas, I do not have a backup of the LUKS header of this volume. As I said above, the intention was only to mount the previously encrypted volume, and not to change anything (so, to my regret, I didn't take the proper precautions). The question: Is there any way to (re)generate the original LUKS header using the (known) original password against which this volume was encrypted, or is this data permanently lost? Thank you for your consideration and your time.
There is no way to recover whatsoever. (*) With LUKS, the passphrase you use to open the encryption, and the master key actually used for the encryption, are completely unrelated to one another. Basically your passphrase decrypts a completely random key, and this random key is stored in the LUKS header. Losing the LUKS header entirely (or even changing a single bit of key material) renders you unable to obtain the master key used for the volume. This is also why with LUKS, you can have 8 different passwords, and change each of these passwords any time you like, without re-encrypting all data. No matter how often you change the LUKS passphrase, the master key stays the same. Master key recovery is explicitely NOT part of the LUKS concept, quite the opposite actually; LUKS takes many steps to prevent you (or anyone) to recover the master key from a (partly) overwritten LUKS header. The LUKS documentation even advises you to NOT backup the header, as a backup header out of your control means losing the ability to declare an old passphrase invalid. As the old passphrase would still be stored and usable in the old header. (*) The only exception to this rule is if the container is still open. For an active crypt mapping, one might be able to obtain the master key with dmsetup table --showkeys. So if you killed your LUKS header in a running system and realized immediately, you could create a new LUKS header with the known master key. Without the master key you cannot proceed and it's impossible to brute-force the master key, that's the whole point of the encryption in the first place. Well, you could do it given infinite CPU power and/or time, so if you want to leave your descendants with a puzzle, keep a copy of the encrypted data around and pass it on... ;)
The password of previously encrypted volume got changed by the Debian installer
1,615,361,613,000
I'd like to use dm-crypt with btrfs, because of the bitrot protection of this filesystem. What I am worrying about that the RADI1 is on the filesystem level above the dm-crypt, so if I write a file, it will be encrypted twice. HDD.x ⇄ dm-crypt.x ↰ btrfs-raid1 ⇒ btrfs HDD.y ⇄ dm-crypt.y ↲ Is there a way to encrypt the data only once for example via dm-crypt.x and store the exact same copy on both HDDs? (According to the btrfs FAQ I need encryptfs to do something like this: HDD.x ↰ btrfs-raid1 ⇒ btrfs ⇄ ecryptfs HDD.y ↲ but I'd rather use dm-crypt if it is possible to not get the extra performance penalty by using btrfs RAID1.
With BTRFS there is currently not such an option directly integrated. There has been talk in the past on the BTRFS mailing list about adding support for the VFS Encryption API (the same thing used by ext4 and F2FS for their transparent file encryption), but that appears to never have gone anywhere. At the moment the only way to achieve what you want is to put the replication outside of BTRFS, which eliminates most of the benefits of checksumming in BTRFS. eCryptFS is an option, but it will almost always be slower than using dm-crypt under BTRFS. EncFS might be an option, but I don't know anything about it's performance (it's also FUSE-based though, and as a general rule FUSE layers on top of BTRFS are painfully slow). As an alternative to all of this though, you might consider using a more conventional filesystem on top of regular RAID (through MD or LVM), put that on top of the dm-integrity target (which does cryptographic verification of the stored data, essentially working like a writable version of the dm-verity target that Android and ChromeOS use for integrity checking their system partitions), and then put that on top of dm-crypt. Doing this requires a kernel with dm-integrity support (I don't remember when exactly it was added, but it was within the past year), and a version of cryptsetup that supports it. This will give you the same level of integrity check that AEAD-style encryption does. Unfortunately though, to provide the same error correction ability that BTRFS does, you will have to put dm-crypt and dm-integrity under the RAID layer (otherwise, the I/O error from dm-integrity won't be seen by the RAID layer, and will therefore never be properly corrected by it).
How to dm-crypt the data only once by filesystem level RAID?
1,615,361,613,000
I am running an Ubuntu 16.04 system with the following hard disk configuration: 1 hard drive which I will call /dev/sda. /dev/sda has 3 partitions used for the following purposes: /dev/sda1 is used for the EFI system partition. /dev/sda2 is used for the /boot partition. /dev/sda3 is used to store an encrypted volume, encrypted with LUKS. I will call the decrypted /dev/sda3 device /dev/sda3_crypt. Within /dev/sda3_crypt sits an LVM configuration. The LVM configuration consists of a volume group named "alexmini". The alexmini volume group contains the following logical volumes and filesystems: A /dev/mapper/alexmini-vg--root logical volume containing a btrfs filesystem. A /dev/mapper/alexmini-vg--swap logical volume used for swap space. I have a second hard drive called /dev/sdb. /dev/sdb contains 1 partition called /dev/sdb1. /dev/sdb1 is also encrypted device using LUKS. I will call the decrypted device /dev/sdb1_crypt. /dev/sdb1_crypt contains a btrfs filesystem. /dev/sdb1_crypt is added to the /dev/mapper/alexmini-vg--root btrfs volume pool. The btrfs filesystem is also my root filesystem. When I run update-initramfs from the configuration specified above, I expected that the cryptsetup initramfs boot scripts would decrypt both /dev/sda3 and /dev/sdb1, but the scripts only decrypt /dev/sda3, which only leads to part of the btrfs volume pool to be available. I end up in the initramfs "recovery" mode. How do I configure the update-initramfs so that the cryptsetup boot scripts will prompt me twice to decrypt both my hard disks, once for /dev/sda3 and once for /dev/sdb1?
Okay, I figured it out and I got it working. I spent some time studying the initramfs cryptsetup scripts under /usr/share/initramfs-tools/hooks. This directory contains scripts that are run whenever update-initramfs is executed. In particular, if cryptsetup is installed, there will be a cryptroot script in this directory, which is the one I studied to find clues to how disks are decrypted at boot. When the initramfs is loaded at boot, there is a script that will decrypt hard disk partitions listed in a file called conf/conf.d/cryptroot. This file sits inside the initramfs archive, which you can explore by unpacking the archive with the following commands: $ sudo cp /boot/initrd.img-4.4.0-93-generic ~ $ cd $ # use sudo chown to change the ownership of the initramfs file to the current user $ mv initrd.img-4.4.0-93-generic initrd.img-4.4.0-93-generic.gz $ gunzip initrd.img-4.4.0-93-generic.gz $ mkdir -p tmp && cd tmp $ cpio -i < ../initrd.img-4.4.0-93-generic Normally, conf/conf.d/cryptroot will only list the partition containing your root filesystem for decryption. If your root filesystem spans multiple encrypted partitions, such as a btrfs filesystem or a filesystem sitting in an LVM logical volume, you will not be able to properly mount the filesystem at boot because only one of your encrypted partitions will be decrypted. What we need is for all the backing partitions to be decrypted before mounting. The encrypted partitions that get listed into conf/conf.d/cryptroot are determined when you build the initramfs archive. When you build the initramfs image, the cryptroot script scans which partitions contain your root filesystem. For btrfs filesystems, cryptroot will run btrfs commands to query the partitions backing your filesystem. However, not all partitions returned from the query will be added to conf/conf.d/cryptroot. Only queried partitions that are also listed in /etc/crypttab will be added to conf/conf.d/cryptroot. My solution was to add an entry for the second encrypted partition that was backing my root filesystem to /etc/crypttab. My resulting /etc/crypttab file looked like the following: sda3_crypt UUID=<my UUID for /dev/sda3> none luks,discard sdb1_crypt UUID=<my UUID for /dev/sdb1> none luks Afterwards, you want to run update-initramfs to generate the new initramfs, which will contain an entry for sda3_crypt and sdb1_crypt in conf/conf.d/cryptroot. This will cause the decryption script to prompt for your passphrase twice at boot: once for sda3_crypt, and another for sdb1_crypt. TL;DR: Ensure all your partitions that back your root filesystem contain an entry in /etc/crypttab. Run update-initramfs after updating /etc/crypttab. Side note: Whenever the update-grub runs for btrfs filesystems spanning multiple devices, it does not generate the kernel command line properly. There is a quick workaround given in https://bugs.launchpad.net/ubuntu/+source/grub2/+bug/1238347
I want multiple prompts to decrypt multiple hard disks which contain root filesystem
1,615,361,613,000
I'm not able to boot a freshly installed Arch Linux system with its root file system residing on a LVM thinly provisioned logical volume on a LUKS encrypted partition on a GUID partitioned device. When Systemd's boot loader systemd-boot loads my boot entry Arch Linux it asks me for the passphrase of the LUKS encrypted partition but then, after 10 seconds, fails to activate the LVM volume group on which the root file system of Arch Linux resides. Eventually it drops me into the rescue shell rootfs. Any ideas if what I'm trying to achieve is possible with Arch Linux? N.B. I'm new to Arch Linux and thus carefully read upfront all of the Arch Wiki articles relevant for installing an Arch Linux system on that particular storage configuration. The boot entry Arch Linux (/boot/loader/entries/arch.conf) I specifically configured looks as follows: title Arch Linux linux /vmlinuz-linux initrd /initramfs-linux.img options cryptdevice=PARTUUID=<of /dev/sda3>:system root=UUID=<of /dev/system/arch.root> rootfstype=ext4 add_efi_memmap For completeness what follows is a gist of how I configured my storage devices: $ parted —align optimal (parted) unit MiB (parted) select /dev/sda (parted) mklabel gpt (parted) mkpart primary 1 2 (parted) name 1 bios (parted) set 1 bios_grub on (parted) mkpart primary 2 1026 (parted) name 2 uefi (parted) set 2 boot on (parted) mkpart primary 1026 103426 (parted) name 3 system (parted) quit $ mkfs -t vfat -n UEFI -F 32 /dev/sda2 $ cryptsetup luksFormat —hash sha512 —cipher aes-xts-plain64 —key-size 512 /dev/sda3 $ cryptsetup open /dev/sda3 system $ pvcreate /dev/mapper/system $ vgcreate system /dev/mapper/system $ lvcreate —type thin-pool —name pool —size 75G system $ lvcreate —type thin —name swap —virtualsize 4G —thinpool system/pool $ mkswap -L swap /dev/system/swap $ lvcreate —type thin —name arch.root —virtualsize 20G —thinpool system/pool $ mkfs -t ext4 -L arch.root /dev/system/arch.root
It looks like that the hook lvm2 run after the hook encrypt during Arch Linux's Initial RAM filesystem phase is not able to activate thinly provisioned logical volumes. With the same storage configuration as depicted in my question except for normal logical volumes instead of thinly provisioned ones the volume group containing these can be activated without any problems. With this change Arch Linux successfully boots. So instead of creating thin logical volumes: $ lvcreate —type thin-pool —name pool —size 75G system $ lvcreate —type thin —name swap —virtualsize 4G —thinpool system/pool $ mkswap -L swap /dev/system/swap $ lvcreate —type thin —name arch.root —virtualsize 20G —thinpool system/pool $ mkfs -t ext4 -L arch.root /dev/system/arch.root One must create normal logical volumes: $ lvcreate —name swap —size 4G system $ mkswap -L swap /dev/system/swap $ lvcreate —name arch.root —size 20G system $ mkfs -t ext4 -L arch.root /dev/system/arch.root
How to install Arch Linux root file system on LVM thin LVs on LUKS on GUID partitioned device?
1,615,361,613,000
I would like to convert my raid6 mdadm into encrypted LUKS. Right now raid6 consists of "/dev/sdX1" which are raid partitions. /dev/md0 doesn't have a partition - it is pure ext4 FS. Is it safe to reencrypt (cryptsetup-reencrypt /dev/md0)? Will LUKS add some specific header which could cause data loss/FS corrupt? Or is it safe only when you have partition on top of mdadm (i.e. /dev/md0p1)?
A volume is called a "LUKS volume" because it has a LUKS header. Thus if you convert a non-LUKS volume into a LUKS volume then you do get an additional header and do lose data space. The LUKS header can be on a differenct device (--header) but I do not know whether cryptsetup-reencrypt supports that. But most probably you want to have the LUKS header within the RAID anyway. Thus you have to reduce the file system size by at least 4MiB run cryptsetup-reencrypt with --new and --reduce-device-size I suggest that you decrease the file system size by a bit more than the value for --reduce-device-size (which I guess must be 4MiB or more). You may want to overwrite the gap between the encrypted LUKS data and the end of the device with random data afterwards. But be really careful with that. You should first make a backup (to a different volume, of course) of the blocks you are going to overwrite.
Is it safe to reencrypt unencrypted mdadm array with LUKS?
1,615,361,613,000
What I am trying to do Create an encrypted arch linux setup using LUKS. Bootloader must be on USB. QUESTION Does the speed of USB-device matter? Does the system contiously use the bootloader to decrypt or is this done only at boot? If not - I take it it can be a slow process depending on the size of the harddrive. Will it matter greatly then? Cheers
Does the speed of USB-device matter? It matters for the boot process itself. It has to load the bootloader, kernel and initramfs from USB, which can be several MB altogether, so it can make a difference of a few seconds. Does the system contiously use the bootloader to decrypt No. Usually you can pull the USB device out as soon as the first kernel message appears on the screen. That is, unless you also have keyfiles on the USB device, in which case you can pull it only after it passed the Initramfs / starting of services phase. tl;dr it does not matter for the running system once it's booted That said, I'm very happy I switched to a faster USB3 stick for booting, but I also use entire LiveCDs on that stick, where USB speed matters a lot more as the whole Live system is on USB in that case.
Does the speed of a USB bootloader matter?
1,615,361,613,000
I created a new partition that I would like to encrypt with LUKS. The device is a 1GB partition with ID 83 (Linux). I've changed the owner to root, and chmod to 777. The command I'm using is : cryptsetup luksFormat /dev/sda2p2 When prompted, I reply the capital YES, then receive this error: cannot open device /dev/sda2p2 for read-only access I know this should be simple, but I can't get it to work. Any help would be greatly appreciated. (currently using CentOS 6) In response to comment re: parted print ls -l /dev/sd*:
Whatever you did to create /dev/sda2p2, it didn't do what you intended. You created a regular file in memory. In Linux's disk and partition naming convention, /dev/sda is a disk, /dev/sda2 is a partition on that disk. From the parted output, you currently have three partitions on that disk: a ~300MB partitionwhich is presumably /boot, a partition using most of the disk space which is presumably the system partition, and a swap partition. The sum of their sizes is equal to the disk size (within the tolerance of the reported approximations), so there is no more space to create other partitions. If you want to create a new partition, you'll need to make room by shrinking one of the existing partitions. Note that with msdos partitions, you can only have 4 primary partitions, or 3 primary partitions plus 1 extended partition that can contain any number of logical partitions. If you want to create more partitions, you may want to switch to LVM which is a lot more flexible. Once you've created a partition, run cryptsetup luksFormat to set up an encrypted volume on it. This volume will be refered to by a name like /dev/mapper/sda5_crypt. Then, if you want to create a single encrypted filesystem, create a filesystem on the encrypted volume. If you want to partition the encrypted space between multiple filesystems and maybe swap, then make the encrypted volume an LVM physical volume, create a volume group containing this PV, and create as many logical volumes as you like on the VG.
cryptsetup luksFormat - cannot open device for read-only access
1,615,361,613,000
I've been recently dealing with an LVM + LUKS partition trying to install a new linux (ubuntu in this case). I tried a few different options to make it work, but the pc resisted, the only system I could make work was the 32bit version of ubuntu 12.04. After succeeding with this (discarding all the twists to make the encryption work) I thought give it another try with the 64bit version since the pc is a 64bit after all. But at this time I didn't re-set up the LVM nor re-partitioned it at all. Right now, and just out of curiosity I would like to know, how architecture-dependant or not may an LVM partition be? I mean, was I wrong by assumming I didn't need to repartition/reformat it before installing a 64bit system? Thanks for any information!
LVM/LUKS should not be architecture-dependant whatsoever, same goes for most filesystems. So a multiboot scenario where you have both 32bit and 64bit Linux installed and they share the same VG or access each others partitions, should be entirely possible. You'll find the most dependencies in terms of software versions. For example recently a bug in the gcrypt/Whirlpool implementation was discovered, and the fix for that rendered LUKS containers using that algorithm unmountable. But it's not a default choice so the risk to be affected by this is low. https://code.google.com/p/cryptsetup/wiki/FrequentlyAskedQuestions#8._Issues_with_Specific_Versions_of_cryptsetup
LVM + LUKS partition - Is this architecture dependent or independent?
1,615,361,613,000
Let's say I have a LUKS-formatted partition, and it's secured using the passphrase "test123". Can I migrate this partition to a key-based mechanism, without loss of data?
Yes, you can. LUKS allows you to have multiple keys, so you can add/modify/remove keys as you need. The actual key which is used to access the data is internal and hidden. There is no difference between a plain passphrase, a key in a file or derived keys. You can add a new passphrase for example with cryptsetup luksAddKey DEVICE FILEWITHPASSPHRASE Then you can test it. If everything works, you can remove your old password with cryptsetup luksRemoveKey DEVICE See the man page of cryptsetup for more details.
Can I migrate a LUKS partition from a passphrase to a keyfile?
1,615,361,613,000
At installation I forgot to create a logical volume group in LUKS container. I won't reinstall the system. So how do I create LVG in LUKS container without data loss? My plan is: Install lvm2 package Backup / using rsync to another drive Create logical volumes I need, for example VolumeGroup/root, VolumeGroup/home and VolumeGroup/swap Transfer all data from backup to VolumeGroup/root Change kernel parameters from cryptdevice=PARTUUID=...:root root=/dev/mapper/root to cryptdevice=PARTUUID=...:cryptlvm root=/dev/VolumeGroup/root Add lvm hook to HOOKS in /etc/mkinitcpio.conf Chroot into new root Re-gen fstab Run mkinitcpio -P Possible implementation: ### On the primary OS pacman -S lvm2 # Add lvm2 hook to /etc/mkinitcpio.conf, to it looks like this: # HOOKS=(base udev autodetect keyboard keymap modconf block encrypt filesystems lvm2 fsck) mkinitcpio -P ### Reboot into live-USB now ### My existing layout: ### ### nvme0n1 259:0 0 931.5G 0 disk ### ├─nvme0n1p1 259:1 0 512M 0 part /boot ### └─nvme0n1p2 259:2 0 931G 0 part ### └─root 254:0 0 931G 0 crypt / ### mounting necessary partitions rsync -aAXHv /mnt/ /path/to/backup wipefs -a /dev/nvme0n1p2 cryptsetup luksFormat /dev/nvme0n1p2 cryptsetup open /dev/nvme0n1p2 cryptlvm pvcreate /dev/mapper/cryptlvm vgcreate VolumeGroup /dev/mapper/cryptlvm lvcreate -L 16G VolumeGroup -n swap lvcreate -L 100G VolumeGroup -n root lvcreate -l 100%FREE VolumeGroup -n home lvreduce -l -256M /dev/VolumeGroup/home mkfs.ext4 /dev/VolumeGroup/root mkfs.ext4 /dev/VolumeGroup/home mkswap /dev/VolumeGroup/swap mount /dev/VolumeGroup/root /mnt mount --mkdir /dev/VolumeGroup/home /mnt/home swapon /dev/VolumeGroup/swap rsync -aAXHv /path/to/backup /mnt ### Now editing kernel parameters so (dots are placeholder for real PARTUUID) ### cryptdevice=PARTUUID=...:cryptlvm root=/dev/VolumeGroup/root ### (*I use systemd-boot, so I change /mnt/etc/kernel/cmdline*) arch-chroot /mnt genfstab -U / > /etc/fstab mkinitcpio -P ### Now reboot and hope all will work Will it work?
It should work. The archlinux mkinitcpio hook is lvm2, not lvm. Add this hook first. No harm done if no LVM is present yet. One less thing to worry about later. Backups from a running system can be inconsistent. With --exclude or -x, it can be incomplete. Consider using bind mounts, or do it from a Live/Rescue environment (don't have to exclude /proc /sys /dev if you don't mount it in the first place). Another alternative would be to convert to LVM in-place, there's a German tutorial on that ("LVM nachträglich einrichten" - ubuntuusers.de Wiki). It works by relocating the first extent to make room for LVM metadata. But it's risky enough you have to backup everything anyway, so your method is better.
Moving from plain LUKS to LVM on LUKS
1,615,361,613,000
The problem I cannot cryptsetup close any LUKS volume while any flatpak app is running in the background. Yes, the flatpak app just has to be running in the background, I'm not trying to use cryptsetup from within the sandbox or anything like that. Yes, this is one of those issues. Steps to reproduce mkdir ~/mnt dd if=/dev/zero of=file.img bs=1MiB count=100 sudo losetup /dev/loop4 file.img sudo cryptsetup luksFormat /dev/loop4 sudo cryptsetup open /dev/loop4 my_crypt sudo mkfs.fat /dev/mapper/my_crypt sudo mount /dev/mapper/my_crypt ~/mnt echo ayylmao | sudo tee ~/mnt/foobar.txt sync # <open a flatpak app, such as flatseal, in the background> sudo umount ~/mnt sudo cryptsetup close my_crypt # output: # device-mapper: remove ioctl on my_crypt failed: Device or resource busy # <the above line multiple times> # Device my_crypt is still in use. # <now close the flatpak app> sudo cryptsetup close my_crypt # Now it runs successfully sudo losetup -d /dev/loop4 Note that the same issue happens with "real" LUKS devices as opposed to loop devices, as well as with tombs. Further diagnostics It seems that when launching a flatpak app, it spawns a process called xdg-dbus-proxy in a new mnt namespace, which, for some reason, keeps the filesystem on the LUKS device mounted, even after it is unmounted in the "default" namespace. For example, here is the output of lsns before launching flatseal: NS TYPE NPROCS PID USER COMMAND 4026531834 time 40 1452 renzev -bash 4026531835 cgroup 40 1452 renzev -bash 4026531836 pid 40 1452 renzev -bash 4026531837 user 40 1452 renzev -bash 4026531838 uts 40 1452 renzev -bash 4026531839 ipc 40 1452 renzev -bash 4026531840 net 40 1452 renzev -bash 4026531841 mnt 40 1452 renzev -bash And here is the output after launching flatseal: NS TYPE NPROCS PID USER COMMAND 4026531834 time 44 1452 renzev -bash 4026531835 cgroup 44 1452 renzev -bash 4026531836 pid 42 1452 renzev -bash 4026531837 user 41 1452 renzev -bash 4026531838 uts 44 1452 renzev -bash 4026531839 ipc 44 1452 renzev -bash 4026531840 net 42 1452 renzev -bash 4026531841 mnt 41 1452 renzev -bash 4026532233 user 1 11485 renzev xdg-dbus-proxy --args=42 4026532254 mnt 1 11485 renzev xdg-dbus-proxy --args=42 4026532256 mnt 2 11488 renzev bwrap --args 40 com.github.tchx84. 4026532257 pid 2 11488 renzev bwrap --args 40 com.github.tchx84. 4026532258 net 2 11488 renzev bwrap --args 40 com.github.tchx84. 4026532391 user 2 11488 renzev bwrap --args 40 com.github.tchx84. If we hop into the namespace check the mounted filesystems, we can see that ~/mnt is still mounted, even after we unmount it in the "default" namespace: sudo nsenter -t 11485 -m bash mount | grep mnt /dev/mapper/my_crypt on /home/renzev/mnt type vfat (ro,nosuid,nodev,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro) Trying to manually unmount the device from within the namespace leads to a somewhat entertaining output: mountpoint /home/renzev/mnt /home/renzev/mnt is a mountpoint umount /home/renzev/mnt umount: /home/renzev/mnt: not mounted. System Details Void Linux. cryptsetup 2.6.1 flags: UDEV BLKID KEYRING KERNEL_CAPI. Flatpak 1.15.6. Linux 6.3.13_1. The Question How can I close LUKS devices without needing to close every single flatpak app?
Thank you to @A.B for helping me figure this out! I want this answer to be useful to others in the future, so I'll try to give a really thorough explanation. Here goes! Introduction Namespaces are a Linux feature that allows isolation between processes. There are different types of namespaces for isolating different types of system resources. The one we are interested in for this problem are called mount namespaces, which can give different processes a different view of what block devices (drives, encrypted volumes, disk images, CD's, DVD's and so on) are mounted. Flatpak uses mount namespaces as part of its sandboxing functionality. In Linux, mounts have a property called "propagation", which can be either private or shared. I don't really understand the difference between these two, but the important part is that in most modern linux distros, the root filesystem at / is mounted as shared. The problem On my system, the root filesystem was mounted as private, not shared. For some reason, this means that when I tried unmounting the encrypted volume, the unmount event would not propagate inside the various mount namespaces created by flatpak. So, while the volume was unmounted in the 'default' namespace, it would still be mounted inside of flatpak's namespaces, and would thus keep the LUKS partition busy, preventing cryptsetup for closeing it. The solution The solution is to make sure that / is mounted with shared propagation. This can be done by adding the shared option to the entry for the root filesystem in /etc/fstab and rebooting. For example, before the fix, my /etc/fstab looked like this: PARTLABEL=VOID_ROOT / btrfs lazytime,noatime,autodefrag,compress=zstd:3,discard=async,space_cache=v2,ssd 0 1 PARTLABEL=VOID_SWAP none swap sw 0 0 PARTLABEL=VOID_ESP /mnt/esp vfat defaults,noauto 0 0 tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0 And after the fix, it looked like this: PARTLABEL=VOID_ROOT / btrfs shared,lazytime,noatime,autodefrag,compress=zstd:3,discard=async,space_cache=v2,ssd 0 1 PARTLABEL=VOID_SWAP none swap sw 0 0 PARTLABEL=VOID_ESP /mnt/esp vfat defaults,noauto 0 0 tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0
Cannot close LUKS volume while any flatpak app is running
1,615,361,613,000
If I create an encrypted partition using cryptsetup cryptsetup -q luksFormat /dev/vdb3 /tmp/pwfile cryptsetup -d /tmp/pwfile luksOpen /dev/vdb3 pv00 and setup a nested gpt partition table on /dev/mapper/pv00 parted=/sbin/parted disk=/dev/mapper/pv00 ${parted} -s -- "${disk}" mklabel gpt ${parted} -s -- "${disk}" mkpart root 0% "${endp1}GiB" ${parted} -s -- "${disk}" mkpart swap "${endp1}GiB" "${endp2}GiB" ${parted} -s -- "${disk}" mkpart none "${endp2}GiB" "${endp3}GiB" ${parted} -s -- "${disk}" mkpart export "${endp3}GiB" 100% then the new partitions are listed by lsblk as expected root@clone:~# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS vda 254:0 0 8G 0 disk `-vda1 254:1 0 8G 0 part / vdb 254:16 0 128G 0 disk |-vdb1 254:17 0 126M 0 part |-vdb2 254:18 0 897M 0 part `-vdb3 254:19 0 120.6G 0 part `-pv00 252:0 0 120.6G 0 crypt |-pv00p1 252:1 0 8G 0 part |-pv00p2 252:2 0 8G 0 part |-pv00p3 252:3 0 8G 0 part `-pv00p4 252:4 0 90.6G 0 part but I cannot close the encrypted partition anymore: root@clone:~# cryptsetup luksClose pv00 Device pv00 is still in use. dmsetup info -C shows the nested partitions are not used, but /dev/mapper/pv00 is: # dmsetup info -C Name Maj Min Stat Open Targ Event UUID pv00 252 0 L--w 4 1 0 CRYPT-LUKS2-f2a811407807491b875f414fa61f854d-pv00 pv00p1 252 1 L--w 0 1 0 part1-CRYPT-LUKS2-f2a811407807491b875f414fa61f854d-pv00 pv00p2 252 2 L--w 0 1 0 part2-CRYPT-LUKS2-f2a811407807491b875f414fa61f854d-pv00 pv00p3 252 3 L--w 0 1 0 part3-CRYPT-LUKS2-f2a811407807491b875f414fa61f854d-pv00 pv00p4 252 4 L--w 0 1 0 part4-CRYPT-LUKS2-f2a811407807491b875f414fa61f854d-pv00 AFAIU the nested partitions keep pv00 busy. Using lvm2 instead of a nested gpt partition table there is no such problem. I can deactivate the volume group using vgchange -an vg00, and pv00 can be closed as expected. Is there a similar command to decommission the nested gpt partition table on /dev/mapper/pv00 without removing it?
You can use kpartx. Create the partition mappings with kpartx -a /dev/mapper/pv00 and remove them with kpartx -d /dev/mapper/pv00. Otherwise you could only manually remove them with dmsetup remove pv00p{1,2,3,4}. Why is this a problem anyway? The kernel (device mapper, crypsetup/LUKS, LVM, ...) does not support nested partition tables at all. In theory, LUKS 2 could support multiple data segments / partitions on its own accord, but it was never implemented. So there is no support for any of it, end of story. parted simply "cheats" by creating device mapper linear targets for them (technically the same thing LVM uses for its Logical Volumes). This is done without asking and parted offers no options to control this behavior whatsoever. So it may look like there is support for this, but for the kernel, this isn't a partition table at all. Closing and reopening the LUKS device also does not make those partition devices reappear (unless you got some custom udev magic going). You'd have to re-run parted on it but even then they don't appear, because even parted expects this to be handled by another piece of software. parted NEWS file mentions it: Noteworthy changes in release 3.1 (2012-03-02) [stable] […] Device-mapper devices ( LVM, dmraid ) no longer insert a 'p' between the base device name and the partition number unless the last character of the base device name is a digit. This brings parted into compliance with the partition naming of kpartx and "linux since the dawn of time", but differs from the way that dmraid 1.0.0-rc16-3 operates. A patch to correct dmraid has been submitted to [email protected]. Without this patch, parted and dmraid will both create duplicate partition devices named /dev/mapper/foo1 and /dev/mapper/foop1. It mentions dmraid, which is probably the reason why this functionality exists at all. You kind of want to support partition tables that can be found on fakeraid/dmraid setups. In this case, dmraid itself creates the partition devices, so parted doesn't have to; parted only updates them if you make changes to the partition table. Nested partition tables aren't really a thing, if you use them anyway you'll have to depend on kpartx to manage them since parted only does so as a side effect. Note that compatibility between parted mappings and kpartx is not entirely guaranteed. These are independent implementations.
how to close encrypted partition with nested partition table?
1,615,361,613,000
I've been a Linux user for about 15 years. Since the feature existed, I used LUKS to encrypt the partitions on which I was installing Ubuntu. I have the following issue: when someone else uses my computer, I have to be there to boot it, because only I should know the decryption secret phrase. To solve this problem, I thought of installing several OS on my hard drive, one on a LUKS encrypted partition (for me) and another on a non-encrypted partition (for others). This with a dual boot that would allow booting either on the encrypted partition or on the non-encrypted partition. Unfortunately, I was noble able to implement this idea. After manual partitioning under gparted, the installation always fails. I'm looking for a tutorial that would explain how to install two GNU/Linux systems in dual boot, one of them encrypted and the other one not.
Prepare a partition for /boot/efi and a partition for /boot in gparted |------+-------------+-----------+------+-------+-----------| | Name | Mount point | Flag | Size | FS | Comment | |------+-------------+-----------+------+-------+-----------| | sda1 | /boot/efi | esp, boot | 300M | FAT32 | | | sda2 | /boot | | 2G | EXT4 | | | sda3 | | | | EXT4 | Encrypted | | sda4 | | | | EXT4 | Clear | |------+-------------+-----------+------+-------+-----------| Install clear GNU/Linux on sda4 At manual partitioning step Select sda1 Format FAT32 Flag esp boot Mount /boot/efi Select sda4 Format EXT4 Mount / Install crypted GNU/Linux on sda3 At manual partitioning step, check encrypt Select sda1 Mount /boot/efi Select sda2 Format EXT4 Mount /boot Select sda3 Delete partition Create partition Check crypt and enter passphrase Mount / Edit grub From crypted GNU/Linux do sudo gedit /etc/default/grub Enable os-prober by uncommenting #GRUB_DISABLE_OS_PROBERfalse` Do sudo grub-mkconfig -o /boot/grub/grub.cfg reboot Notes To have the passphrase asked after kernel selection, encrypted GNU/Linux kernels have to be stored on a specific /boot/efi partition (sda2) clear GNU/Linux kernels have to be stored in the same partition as clear GNU/Linux (sda4)
How to install two GNU/Linux in dual boot with one under LUKS and the other not?
1,651,838,414,000
Once the /boot partition is half-full with a single kernel you can't upgrade, Resizing is painful when the other partition is encrypted, Solution: Move /boot to the encrypted partition. Backstory: Linux Mint 17 upgraded to 20 won't allow the latest kernel to be installed; that was my dilemma. There's much written on resizing partitions—terror is induced for encrypted partitions! Fortunately there's an alternative. Having rendered my system "unbootable," I decided to provide some guidance (my answer appears below), others will hopefully chim in.
Credit largely belongs to Guilhem Moulin, I merely simplify. Superuser will be required repeatedly and you may prefer to run command su for a root shell (alternatively, proceed commands with sudo where necessary). Encrypted partition: /dev/sda5 Running fdisk -l lists partitions, e.g., Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 499711 497664 243M 83 Linux /dev/sda2 501758 500117503 499615746 238.2G 5 Extended /dev/sda5 501760 500117503 499615744 238.2G 83 Linux My encrypted partition is /dev/sda5, yours may vary (and you'll need to replace /dev/sda5 accordingly). Prerequisite: LUKS1 Check you're using LUKS1 by checking command cryptsetup luksDump /dev/sda5 outputs Version: 1 For version 2, downgrade before proceeding (see the original article). Prerequisite: GRUB2 Check you're using GRUB2 by checking command grub-install --version outputs version 2 or above. Prerequisite: Keyboard layout Check your passphrase remains the same when you switch to US keyboard layout. Consider changing your passphrase (for one that remains the same), or set your passphrase using a US layout (not recommended), or refer to the original article for a further workaround. Moving /boot Remount /boot as read-only to avoid data modification during the move: mount -oremount,ro /boot Recursively copy to a temporary directory (on the encrypted partition): cp -axT /boot /boot.tmp Unmount /boot and remove the (empty) directory: umount /boot rmdir /boot Relocate the temporary directory: mv -T /boot.tmp /boot Update /etc/fstab Command cat /etc/fstab will output something akin to: UUID=38e... /boot ext2 defaults You need to comment out that line (I favour vim). Enable cryptomount in GRUB2 Add GRUB_ENABLE_CRYPTODISK=y to /etc/default/grub, generate your GRUB configuration file, update-grub and install, grub-install /dev/sda Probably a good time to test Now is probably a good time to test all is going well: Reboot. You should be prompted for your passphrase and (after a disturbing long delay) be dropped into a initramfs prompt. Enter the following command: cryptsetup luksOpen /dev/sda5 sda5_crypt replacing sda5_crypt with the first parameter output by cat /etc/crypttab (if you've gotten this far without having run that command, just use sda5_crypt, we can fix it later). Next issue command: exit Your system should now be booting, if it isn't, recovery should be relatively easy—boot from a Live USB and uncomment the line in /etc/fstab. (It's incredibly useful to have a Live USB available at all times.) Boot performance degraded GRUB isn't optimised for crypto-related CPU instructions—unlocking the encrypted partition will take considerable longer than it did before. Optional: You can tweak for performance by sacrificing resistance against brute-force attacks. It's easier for PBKDF than Argon2—PBKDF slows brute-force attacks by requiring multiple iterations, whereas Argon2 slows attacks with a further variable, hence, tweaking PBKDF is easier. Check how many iterations are currently used with command cryptsetup luksDump /dev/sda5, e.g., Key Slot 0: ENABLED Iterations: 1208036 To improve performance by roughly a factor of two (simultaneously reducing brute-force resistance by half), we can reduce the number of iterations by just over half with command cryptsetup luksChangeKey --pbkdf-force-iterations 500000 /dev/sda5 Enter passphrase to be changed: Enter new passphrase: Verify passphrase: Your existing passphrase can be reused. As far as I can tell, a new key is added: In addition to the above, command cryptsetup luksDump /dev/sda5 now outputs Key Slot 1: ENABLED Iterations: 500000 PBKDF will try all key slots sequentially, to speed things up, run command cryptsetup luksOpen --test-passphrase --verbose /dev/sda5 Enter passphrase for /dev/sda5: Key slot 1 unlocked. Command successful. With command cat /etc/crypttab you'll see something like sda5_crypt UUID=66f... none luks,discard add ,key-slot=1 on the end (changing 1 to match whatever you found above). If you tested all is well and used something other than that first parameter sda5_crypt, reboot and enter cryptsetup luksOpen /dev/sda5 sda5_crypt followed by exit, before the next step. Run command update-initramfs -u -k all to generate and update your initramfs image. (Strictly speaking -k all isn't required, assuming you're following these instructions because you have a single kernel.) Update /etc/fstab Command lsblk -o name,uuid outputs NAME UUID sda ├─sda1 38e... ├─sda2 └─sda5 66f... └─sda5_crypt B6U... ├─mint--vg-root 54f... └─mint--vg-swap_1 fe3... To make your system bootable, add the following line to /etc/fstab UUID=54f... / ext4 defaults 0 1 run command update-grub followed by grub-install /dev/sda, and reboot. Hopefully you'll now have a bootable system. You'll need to enter your passphrase twice, which is unfortunate. Apparently there's a workaround (see the original article). I followed that entire article in one hit, ran into trouble, couldn't boot (prior to discovering cryptsetup luksOpen /dev/sda5 sda5_crypt). With the above instructions, I hope there's less chance of pain. Best of luck.
Boot partition full: Move to encrypted partition