I just installed an encrypted filesystem on my new LFS-7.0 machine, so here is the patch for the hint in diff -Naur form.
Lars
--- crypt-rootfs.txt 2011-11-13 00:05:37.000000000 +0100 +++ crypt-rootfs.txt 2011-11-13 00:04:35.000000000 +0100 @@ -1,6 +1,6 @@ AUTHOR: Lars Bamberger <Lars.Bamberger at gmx dot de> -DATE: 2009-12-30 +DATE: 2011-11-13 LICENSE: GNU Free Documentation License Version 1.2 @@ -48,42 +48,46 @@ 2. Required software and dependencies ===================================== -2.1 Software in the BLFS book +2.1 Software in the BLFS book (BLFS-svn as of date of writing) + +To satisfy dependencies of 'cryptsetup', you need to install +* 'Popt' +* 'Device-mapper' +* 'libgcrypt' (has futher dependencies mentioned in the book) -You need to install 'Popt' as 'cryptsetup' depends on this. Furthermore you need 'uuencode' to create key files. 'uuencode' is included in -'sharutils' and 'GMime' which has further dependencies mentioned in the BLFS -book. To create the initramfs, you need 'Cpio'. +'sharutils' and in 'GMime' which has further dependencies mentioned in the BLFS +book. +To create the initramfs, you need 'Cpio'. 2.2 Software not in the BLFS book -2.2.1 devmapper - -Get it from http://packages.debian.org/stable/source/devmapper -Compile and install it. Required for 'cryptsetup'. - - -2.2.2 cryptsetup with LUKS extension +2.2.1 cryptsetup with LUKS extension Get it from http://code.google.com/p/cryptsetup/ -Compile and install it. Required to handle encrypted partitions. - +Compile and install it. (CMMI-Standard) Required to handle encrypted partitions. -2.2.3 busybox +2.2.2 busybox Get it from http://www.busybox.net/ -The minimum required configuration includes: -* cp -* hush (interactive shell not required) -* mount (with support for lots of -o flags) and -* switch_root. + +The configuration system is quite similar to that of the Linux kernel. +First, we build a minimalistic version of busybox: +Do 'make allnoconfig' followed by 'make menuconfig' (or 'make config' if +that doesn't work). Configure as follows: + +Busybox Settings -> Build Options -> Build as a static binary +Coreutils -> cp +Linux System Utilities -> mount with support for lots of -o flags +Linux System Utilities -> switch_root +Shells -> hush (interactive mode not required) Compile it, but DO NOT install it. Keep the binary and name it 'busybox-minimum'. Next, reconfigure busybox for a full-blown desktop system. You will need all the standard tools and utilities for the purpose of initially -encrypting your root partition and for troubleshooting. (Don't forget 'mkefs'.) +encrypting your root partition and for troubleshooting. (Don't forget 'mkefs'.) Doing a 'make defconfig' should do the trick. Using 'make menuconfig', you can safely disable all Networking, Print, and Mail Utiliies as some of these have dependencies and are not needed for your purpose. If busybox complains about missing dependencies, check if you really need the feature and disable it. Configure busybox to compile as a static binary (Build Options). If some libs will be linked to it anyway, use 'ldd busybox' to find out which ones those are and note the names of those libs. If possible, avoid generating a dynamically linked busybox. This behavoiur may vary with the version of busybox used, as this is a generic description. Name this binary 'busybox-large' or something similar. Again, it is not -required to install it. +required to install it 3. Recompiling the kernel @@ -131,14 +135,15 @@ The process is as follows for every partition: -1) Create as many keys as you like for the partition, for example: +1) Create as many passphrases as you like for the partition, for example: head -c 2880 /dev/urandom | uuencode -m - | head -n-1 | tail -n+2 > keyfile or use an easy to remember passphrase. -2) Make a secure backup of your keys and secure the keyfile by 'chmod 0400' or - so. Your backup keys must be absolutely secure (i.e. not on your computer). - Remember: If you lose your key, you will absolutely, definitely NOT be able - to access you data! +2) Make a secure backup of your passphrases and secure the keyfile by + 'chmod 0400' or so. Your backup passphrases must be absolutely secure (i.e. + not on your computer). + Remember: If you lose your passphrase, you will absolutely, definitely NOT + be able to access your data! 3) Make a backup of the data on the partition. @@ -150,7 +155,7 @@ Replace '$cipher-algorithm', '/dev/sd??' and '$keyfile' with the corresponding values. -6) Optionally, add more keys to the partition. Do a +6) Optionally, add more passphrases to the partition. Do a cryptsetup -y -d $keyfile luksAddKey /dev/sd?? Replace '$keyfile' with the same as above and '/dev/sd??' with the corresponding partition. @@ -166,6 +171,7 @@ mkefs.$WHATEVER /dev/mapper/sd?? Replace '$WHATEVER' with the type of filesystem you would like to use (e.g. ext2) and '/dev/mapper/sd??' with the corresponding partition. + NOTE: Do NOT use the -cc option. The system will hang forever! 9) Adjust /etc/fstab Because the device for the partition has changed, you need to @@ -185,11 +191,11 @@ 4.2 Making the system automatically decrypt and mount the partition(s) Create a bootscript that will decrypt your encrypted partition. It is assumed -that the passphrases are stored in /etc/crypt for example. Note that storing the -passphrases on disk might pose a security problem! Use the template for -bootscripts included with BLFS and make it do: +that the passphrases are stored in /etc/crypt for example. Note that storing +the passphrases on disk might pose a security problem! Use the template for +bootscripts included with LFS and make it do: -/sbin/cryptsetup -d /etc/crypt/$PARTITION.key luksOpen \ +(/usr)/sbin/cryptsetup -d /etc/crypt/$PARTITION.key luksOpen \ /dev/$PARTITION $PARTITION for every encrypted partition other than the root partition and the swap @@ -199,61 +205,77 @@ #!/bin/sh ######################################################################## -# Begin $rc_base/init.d/cryptsetup +# Begin cryptsetup # # Description : Make encrypted filesystems available for mounting # And clean up afterwards # -# Authors : Lars Bamberger +# Authors : You! # -# Version : 00.01 +# Version : LFS 7.0 # # Notes : This should never be automatically called with any # argument other than "start". During shutdown and reboot, -# it is sufficient to umount the filesystems. /dev/mapper/* +# it is sufficient to umount the filesystems. +# /dev/mapper/* # will be gone when the kernel stops or reboots. # ######################################################################## -. /etc/sysconfig/rc -. ${rc_functions} -PROC=/sbin/cryptsetup +### BEGIN INIT INFO +# Provides: cryptsetup +# Required-Start: udev +# Should-Start: +# Required-Stop: +# Should-Stop: +# Default-Start: S +# Default-Stop: +# Short-Description: Make encrypted filesystems available for mounting +# Description: Make encrypted filesystems available for mounting +# X-LFS-Provided-By: +### END INIT INFO + +. /lib/lsb/init-functions +PROC=/usr/sbin/cryptsetup case "${1}" in - start) - boot_mesg "luksOpen Home..." - $PROC -d /etc/crypt/home.key luksOpen /dev/sda4 sda4 - evaluate_retval - stop) - boot_mesg "luksClose Home..." - $PROC luksClose sda4 - evaluate_retval - ;; - reload) - boot_mesg "Reloading home..." - $PROC reload sda4 - evaluate_retval - ;; - restart) - ${0} stop - sleep 1 - ${0} start - ;; - status) - $PROC status sda4 - ;; - *) - echo "Usage: ${0} {start|stop|reload|restart|status}" - exit 1 - ;; + start) + log_info_msg "luksOpen 'sda3'..." + $PROC -d /etc/crypt/sda3.key luksOpen /dev/sda3 sda3 + evaluate_retval + ;; + + stop) + log_info_msg "luksClose 'sda3'..." + $PROC luksClose sda3 + evaluate_retval + ;; + + restart) + ${0} stop + sleep 1 + ${0} start + ;; + + status) + $PROC status sda3 + ;; + + *) + echo "Usage: ${0} {start|stop|restart|status}" + exit 1 + ;; esac -# End $rc_base/init.d/cryptsetup + +exit 0 + +# End cryptsetup Now, before proceeding, make sure everything works as expected up until now. Become familiar with encrypting your partitions this way. Make an appropriate softlink so that this script is called at boottime: -# cd /etc/rc.d/rcsysinit.d +# cd /etc/rc.d/rcS.d # ln -s ../init.d/cryptsetup S19cryptsetup Double-check everything so that booting, rebooting, shutting down etc. works as @@ -275,7 +297,9 @@ However, if you suspend your system (either to RAM or to disk), data in swap space must remain consistent. Therefore you have to treat the swap partition(s) just as if they were a regular partition, meaning you should -encrypt them like explained above. +encrypt them like explained above. Note that I have not experimented with +system hiberantion or supension. If you have anything to contribute toward +encrypting swap partiations, feel free to contact me. 6. Encrypting rootfs @@ -290,8 +314,8 @@ You'll need the standard directories (bin, sbin, usr/{bin,sbin}, proc, sys, dev, lib). In bin we put our busybox-large (rename to busybox) and a softlink to busybox named hush. Copy cryptsetup to sbin. -In dev put some useful devices: console, null, urandom, sd?? and a directory -'mapper' containing 'control'. Then make a copy of dev: +In dev put some useful devices: console, null, random, urandom, sd?? and a +directory 'mapper' containing 'control'. Then make a copy of dev: cp -a dev init-dev In lib (and dev) put everything needed to run busybox and cryptsetup. @@ -312,7 +336,8 @@ boot. *** PITFALL *** -Cryptsetup needs /proc and /sys mounted. It also requires the /dev directory. +Cryptsetup needs /proc and /sys mounted. It also requires the /dev directory and +'random' and 'urandom'. As we want to save /dev when we switch_root later, we mount it as tmpfs. This means that the devices in /dev will be gone, so copy them back into /dev. Be aware that you need at least 'null' and 'console' in /dev before mounting @@ -339,8 +364,8 @@ *** PITFALL *** Since your old rootfs isn't mounted, you might not be able to to run 'mkefs' do to missing libraries. Either copy everything needed to where the linker can -find it, or use the 'mkefs' from busybox. Be sure to configure busybox -accordingly. +find it, reconfigure the linker's search path via 'ldcondif', or use the 'mkefs' +from busybox. Be sure to configure busybox accordingly. Next, modify /etc/fstab (on /new-root) to reflect the new device for the rootfs. Also modify the cryptsetup script as described below (7. PITFALL). @@ -376,7 +401,7 @@ if [[ ! -b /dev/mapper/sd?? ]]; then - boot_mesg "Making device for rootfs..." + log_info_msg "Making device for rootfs..." /bin/mknod -m 0600 /dev/mapper/sd?? b 254 0 evaluate_retval; fi @@ -393,21 +418,21 @@ Create a bootscript (checkbootfs) that makes sure that the unencrypted partition we booted from was not compromised. Use something like: - boot_mesg "Checking integrity of boot FS..." + log_info_mesg "Checking integrity of boot FS..." if [[ $(/bin/md5sum -b /dev/sd??) == \ "$whatevermd5sum */dev/sd??" ]] \ && \ [[ $(/bin/sha1sum -b /dev/sd??) == \ "$whatevensha1sum */dev/sd??" ]]; - then - echo_ok; - else - echo_failure -boot_mesg -n "FAILURE:\n\nThe boot file system seems to have been -altered!\n\n" ${FAILURE} - boot_mesg -n " DO NOT TRUST THIS SYSTEM!\n\n" - boot_mesg_flush + then + log_success_msg; + else + log_failure_msg "The boot file system has been altered!" + log_warning_msg "DO NOT TRUST THIS SYSTEM!" + log_info_msg "Press Enter to continue anyway ..." + wait_for_user + fi *** PITFALL *** Make sure this is the very last thing you implement, as the hashsums will @@ -424,6 +449,12 @@ CHANGELOG: +[2011-11-13] + * Adjust for LFS-7.0 + * Some touchups +[2010-04-17] + * Dev-mapper is now in the BLFS book + * More verbosity for configuring busybox [2009-12-30] * Merged suggestions (typos, format and others) from Emmanuel Trillaud * More verbosity on the boot partition size
-- http://linuxfromscratch.org/mailman/listinfo/hints FAQ: http://www.linuxfromscratch.org/faq/ Unsubscribe: See the above information page
