Package: cryptsetup
Version: 2:1.4.3-2
Severity: important
Tags: patch

Booting with / on a multidevice btrfs where the component devices are encrypted 
does not work, as the cryptroot initramfs hook only add support for a single 
encrypted rootdev to the initramfs.

The attached patch makes the hook script support multiple rootdevs and adds 
support for finding all rootdevs for a btrfs filesystem. Someone should 
probably add zfs-fuse support to get_root_devices() as well, but I don't have 
any zfs filesystem to test with...

Best regards
Jon Severinsson

-- Package-specific info:
-- /proc/cmdline
BOOT_IMAGE=/vmlinuz-3.2.0-3-amd64 root=/dev/mapper/gitara-crypt2 ro 
rootflags=subvol=debian bootdegraded=true quiet splash vt.handoff=7

-- /etc/crypttab
# <target name> <source device>         <key file>      <options>
gitara-crypt1 UUID=0c334cb8-d190-4c5f-a218-e240ffbf142d none luks,discard
gitara-crypt2 UUID=948cd1d2-79d3-4515-b494-a7fd7b95c29b none luks,discard

-- /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid -o value -s UUID' 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>
LABEL=gitara-boot       /boot                           ext4    nodev,nosuid    
                                0   2
LABEL=gitara-btrfs      /media/btrfs                    btrfs   ssd,subvolid=0  
                                0   0
LABEL=gitara-btrfs      /                               btrfs   
ssd,subvol=debian                               0   0
LABEL=gitara-btrfs      /opt                            btrfs   ssd,subvol=opt  
                                0   0
LABEL=gitara-btrfs      /home                           btrfs   
ssd,nodev,nosuid,subvol=home                    0   0
LABEL=gitara-btrfs      /export                         btrfs   
ssd,nodev,nosuid,subvol=export                  0   0
LABEL=gitara-backup     /export/backup                  ext4    nodev,nosuid    
                                0   2

-- lsmod
Module                  Size  Used by
parport_pc             22364  0 
ppdev                  12763  0 
lp                     17149  0 
parport                31858  3 lp,ppdev,parport_pc
rfcomm                 33656  0 
bnep                   17567  2 
bluetooth             119406  10 bnep,rfcomm
binfmt_misc            12957  1 
uinput                 17440  1 
isofs                  35171  0 
nls_utf8               12456  1 
nls_cp437              16553  1 
vfat                   17316  1 
fat                    45642  1 vfat
loop                   22641  2 
kvm_amd                47218  0 
kvm                   287662  1 kvm_amd
snd_hda_codec_hdmi     30783  1 
eeepc_wmi              12564  0 
asus_wmi               18726  1 eeepc_wmi
sparse_keymap          12760  1 asus_wmi
rfkill                 19012  3 asus_wmi,bluetooth
snd_hda_codec_realtek   188797  1 
amd64_edac_mod         22334  0 
edac_mce_amd           17103  1 amd64_edac_mod
k10temp                12611  0 
powernow_k8            17573  0 
psmouse                64455  0 
edac_core              35258  3 amd64_edac_mod
joydev                 17266  0 
mperf                  12453  1 powernow_k8
pcspkr                 12579  0 
serio_raw              12931  0 
snd_hda_intel          26345  0 
snd_hda_codec          78031  3 
snd_hda_intel,snd_hda_codec_realtek,snd_hda_codec_hdmi
snd_hwdep              13186  1 snd_hda_codec
snd_pcm                63900  3 snd_hda_codec,snd_hda_intel,snd_hda_codec_hdmi
snd_page_alloc         13003  2 snd_pcm,snd_hda_intel
snd_seq                45093  0 
snd_seq_device         13176  1 snd_seq
evdev                  17562  15 
snd_timer              22917  2 snd_seq,snd_pcm
sp5100_tco             12900  0 
processor              28157  1 powernow_k8
thermal_sys            18040  1 processor
i2c_piix4              12536  0 
snd                    52850  9 
snd_timer,snd_seq_device,snd_seq,snd_pcm,snd_hwdep,snd_hda_codec,snd_hda_intel,snd_hda_codec_realtek,snd_hda_codec_hdmi
soundcore              13065  1 snd
shpchp                 31293  0 
btrfs                 505480  1 
crc32c                 12656  1 
libcrc32c              12426  1 btrfs
zlib_deflate           25638  1 btrfs
sha256_generic         16797  4 
cryptd                 14517  0 
aes_x86_64             16796  32 
aes_generic            33026  1 aes_x86_64
cbc                    12754  16 
ext4                  350411  2 
crc16                  12343  2 ext4,bluetooth
jbd2                   62015  1 ext4
mbcache                13065  1 ext4
dm_crypt               22586  2 
dm_mod                 63545  5 dm_crypt
raid1                  30714  1 
md_mod                 87742  2 raid1
sr_mod                 21899  0 
cdrom                  35401  1 sr_mod
sd_mod                 36136  8 
usb_storage            43870  0 
crc_t10dif             12348  1 sd_mod
uas                    13296  0 
usbhid                 36379  0 
hid                    81288  1 usbhid
sata_sil24             17628  4 
ohci_hcd               22467  0 
mxm_wmi                12473  0 
radeon                639188  2 
firewire_ohci          35772  0 
firewire_core          48407  1 firewire_ohci
crc_itu_t              12347  1 firewire_core
ahci                   24997  1 
libahci                22860  1 ahci
libata                140589  3 libahci,ahci,sata_sil24
ehci_hcd               40215  0 
xhci_hcd               73170  0 
wmi                    13243  2 mxm_wmi,asus_wmi
button                 12937  0 
power_supply           13475  1 radeon
i2c_algo_bit           12841  1 radeon
ttm                    48725  1 radeon
drm_kms_helper         27227  1 radeon
drm                   167670  4 drm_kms_helper,ttm,radeon
usbcore               128498  7 
xhci_hcd,ehci_hcd,ohci_hcd,usbhid,uas,usb_storage
r8169                  46980  0 
mii                    12675  1 r8169
i2c_core               23876  5 drm,drm_kms_helper,i2c_algo_bit,radeon,i2c_piix4
scsi_mod              162372  5 libata,uas,usb_storage,sd_mod,sr_mod
usb_common             12354  1 usbcore


-- System Information:
Debian Release: wheezy/sid
  APT prefers testing
  APT policy: (500, 'testing'), (400, 'unstable'), (1, 'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 3.2.0-3-amd64 (SMP w/2 CPU cores)
Locale: LANG=sv_SE.UTF-8, LC_CTYPE=sv_SE.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages cryptsetup depends on:
ii  cryptsetup-bin         2:1.4.3-2
ii  debconf [debconf-2.0]  1.5.44
ii  dmsetup                2:1.02.74-4
ii  libc6                  2.13-33

cryptsetup recommends no packages.

Versions of packages cryptsetup suggests:
ii  busybox                                 1:1.20.0-5
ii  dosfstools                              3.0.13-1
ii  initramfs-tools [linux-initramfs-tool]  0.107
ii  liblocale-gettext-perl                  1.05-7+b1
ii  udev                                    175-3.1

-- debconf information:
  cryptsetup/prerm_active_mappings: true
--- /usr/share/initramfs-tools/hooks-cryptroot.distrib	2012-06-12 21:29:49.000000000 +0200
+++ /usr/share/initramfs-tools/hooks/cryptroot	2012-07-25 09:00:50.417460434 +0200
@@ -16,7 +16,7 @@
 
 . /usr/share/initramfs-tools/hook-functions
 
-get_root_device() {
+get_root_devices() {
 	local device mount type options dump pass
 
 	if [ ! -r /etc/fstab ]; then
@@ -26,8 +26,15 @@
 	grep -s '^[^#]' /etc/fstab | \
 	while read device mount type options dump pass; do
 		if [ "$mount" = "/" ]; then
-			device=$(canonical_device "$device") || return 0
-			echo "$device"
+			local devices
+			if [ "$type" = "btrfs" ] ; then
+				for dev in $(btrfs filesystem show $(canonical_device "$device" --no-simplify) 2>/dev/null | sed -r -e 's/.*devid .+ path (.+)/\1/;tx;d;:x') ; do
+					devices="$devices $(canonical_device "$dev")"
+				done
+			else
+				devices=$(canonical_device "$device") || return 0
+			fi
+			echo "$devices"
 			return
 		fi
 	done
@@ -90,7 +97,7 @@
 		if [ -n "$derived" ]; then
 			if grep -q "^$derived" /etc/crypttab; then
 				derived=$(canonical_device "/dev/mapper/$derived") || return 0
-				if [ "$derived" != "$rootdev" ]; then
+				if ! echo "$rootdevs" | grep -q -e "$derived"; then
 					devices="$devices $derived"
 				fi
 			else
@@ -305,6 +312,7 @@
 canonical_device() {
 	local dev altdev original
 	dev="$1"
+	opt="$2"
 
 	altdev="${dev#LABEL=}"
 	if [ "$altdev" != "$dev" ]; then
@@ -321,6 +329,11 @@
 		dev=$(readlink -e "$dev")
 	fi
 
+	if [ "$opt" = "--no-simplify" ]; then
+		echo "$dev"
+		return 0
+	fi
+
 	if [ "x${dev%/dev/dm-*}" = "x" ]; then
 		# try to detect corresponding symlink in /dev/mapper/
 		for dmdev in /dev/mapper/*; do
@@ -356,7 +369,7 @@
 	fi
 
 	# Flag root device
-	if [ "$nodes" = "$rootdev" ]; then
+	if echo "$rootdevs" | grep -q -e "$nodes"; then
 		if [ -z "$opts" ]; then
 			opts="rootdev"
 		else
@@ -500,20 +513,20 @@
 #
 
 setup="no"
-rootdev=""
+rootdevs=""
 resumedevs=""
 
 # Find the root and resume device(s)
 if [ -r /etc/crypttab ]; then
-	rootdev=$(get_root_device)
-	if [ -z "$rootdev" ]; then
+	rootdevs=$(get_root_devices)
+	if [ -z "$rootdevs" ]; then
 		echo "cryptsetup: WARNING: could not determine root device from /etc/fstab" >&2
 	fi
 	resumedevs=$(get_resume_devices)
 fi
 
 # Load the config opts and modules for each device
-for dev in $rootdev $resumedevs; do
+for dev in $rootdevs $resumedevs; do
 	if ! modules=$(add_device "$dev"); then
 		echo "cryptsetup: FAILURE: could not determine configuration for $dev" >&2
 		continue

Reply via email to