Encrypted disk filesystem compatibilities

bootencryptionext4filesystemszfs

On my Debian Linux system during the install I decided to use disk encryption (the one offered during a regulard Debian install). When the system boots up I need to enter a password and then the "real" boot begins.

Could someone explain how this encryption is performed? Does it happen before or after the filesystem's laid out? Can I use any filesystem available for Linux with the disk encryption?

The /etc/mtab/ is more complicated than what I was used with Linux and I take it it's related to disk encryption but I'm really not sure. Here's (what I think is) the relevant bits from my /etc/mtab:

/dev/sda1 /boot ext2 rw,relatime,errors=continue 0 
/dev/mapper/archon-root / ext4 rw,noatime,errors=remount-ro,user_xattr,commit=300,barrier=1,data=ordered 0 0
rootfs / rootfs rw 0 0

I don't really understand why /boot is ext2 and why / is ext-4 and using a /dev/mapper.

Could /boot be itself using ext4?

Could / be using, say, ZFS and yet still offer encryption?

Best Answer

/boot is not encrypted (the BIOS would have no way to decrypt it...). It could be ext4, but there really isn't any need for it to be. It usually doesn't get written to. The BIOS reads GRUB from the MBR, then GRUB reads the rest of itself, the kernel, and the initramfs from /boot. The initramfs prompts you for the passphrase. (Assumably, its using cryptsetup and LUKS headers.).

The encryption is performed at a layer below the filesystem. You're using something called dm-crypt (that's the low-level in-kernel backend that cryptsetup uses), where "dm" means "Device Mapper". You appear to also be using LVM, which is also implemented by the kernel Device Mapper layer. Basically, you have a storage stack that looks something like this:

1. /dev/sda2              (guessing it's 2, could be any partition other than 1)
2. /dev/mapper/sda2_crypt (dm-crypt layer; used as a PV for VG archon)
3. LVM (volume group archon)
4. /dev/mapper/archon-root (logical volume in group archon)
5. ext4

You can find all this out with the dmsetup command. E.g., dmsetup ls will tell you the Device Mapper devices in list. dmsetup info will give some details, and dmsetup table will give technical details of the translation the mapping layer is doing.

The way it works is that the dm-crypt layer (#2, above) "maps" the data by performing crypto. So anything written to /dev/mapper/sda2_crypt is encrypted before being passed to /dev/sda2 (the actual hard disk). Anything coming from /dev/sda2 is decrypted before being passed out of /dev/mapper/sda2_crypt.

So any upper layers use that encryption, transparently. The upper layer you have using it first is LVM. You're using LVM to carve up the disk into multiple logical volumes. You've got (at least) one, called root, used for the root filesystem. It's a plain block device, so you can use it just like any other—you can put any filesystem you'd like there, or even raw data. The data gets passed down, so it will be encrypted.

Things to learn about (check manpages, etc.):

  • /etc/crypttab
  • LVM (some important commands: lvs, pvs, lvcreate, lvextend)
  • cryptsetup
Related Question