1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
|
#!/bin/sh
# Apply LVM partitioning on top of a RAID preseed
if ! [ -f /var/lib/partman/initial_auto_raid_crypto_pvs ] ||
! [ -e /usr/lib/partman/lib/auto-lvm.sh ]; then
exit 0
fi
. /usr/lib/partman/lib/auto-lvm.sh
. /usr/lib/partman/lib/crypto-base.sh
# pv_devices is used by auto_lvm_perform()
pv_devices="$(cat /var/lib/partman/initial_auto_raid_crypto_pvs)"
rm -f /var/lib/partman/initial_auto_raid_crypto_pvs
db_get partman-auto/expert_recipe_file
recipe="$RET"
# Clone-and-hack from initial_auto_raid_lvm (adding cryptsetup to the mix),
# which is itself another clone-and-hack described below.
#
# Since we're having LVM on top of LUKS and RAID, and RAID has been handled
# already, let's set up LUKS, before letting the rest of the script handle LVM.
#
# Comparison against partman-auto-crypto's autopartition-crypto:
# - clean_method:
# Skipped for now, doesn't seem needed.
# - auto_lvm_prepare:
# Re-use initial_auto_raid_lvm's re-implementation instead.
# - first loop (find and prepare the first device marked for crypto):
# Copied.
# - crypto_check_setup:
# Copied.
# - crypto_setup:
# Copied.
# - second loop (fix method on PVs):
# Copied, but with pv_devices adjusted to account for the LUKS layer.
# - auto_lvm_perform:
# Copied/already present in initial_auto_raid_lvm's re-implementation.
# - forcing DISK_UNCHANGED:
# Skipped for now, doesn't seem needed.
#
# OPEN QUESTION: Should auto_lvm_create_vg_map be adjusted for the PV-on-LUKS?
# Clone-and-hack from partman-auto-lvm, which can't cope with the idea of
# not needing to create partitions for itself yet.
size=0
devs=
for pv_device in $pv_devices; do
dev="$(dev_to_partman $pv_device)"
devs="${devs:+$devs }$dev"
[ -f $dev/size ] || exit 1
size=$(($size + $(cat $dev/size)))
done
set -- $devs
main_device=$1
shift
extra_devices="$*"
# Be sure the modules are loaded
modprobe dm-mod >/dev/null 2>&1 || true
modprobe lvm-mod >/dev/null 2>&1 || true
if type update-dev >/dev/null 2>&1; then
log-output -t update-dev update-dev --settle
fi
if [ "$extra_devices" ]; then
for dev in $devs; do
physdev="$(cat "$dev/device")"
target="${target:+$target }${physdev#/dev/}"
done
db_metaget partman-auto-lvm/text/multiple_disks description
target=$(printf "$RET" "$target")
else
target="$(humandev $(cat $main_device/device)) - $(cat $main_device/model)"
fi
target="$target: $(longint2human $size)"
free_size=$(convert_to_megabytes $size)
choose_recipe lvm "$target" "$free_size" || return $?
# Copied from partman-auto-crypto's autopartition-crypto:
found=no
for dev in $DEVICES/*; do
[ -d "$dev" ] || continue
cd $dev
partitions=
open_dialog PARTITIONS
while { read_line num id size type fs path name; [ "$id" ]; }; do
if [ "$fs" != free ]; then
partitions="$partitions $id"
fi
done
close_dialog
for id in $partitions; do
[ -f $id/method ] || continue
method=$(cat $id/method)
[ $method = crypto ] || continue
echo dm-crypt > $id/crypto_type
crypto_prepare_method "$dev/$id" dm-crypt || exit 1
if [ "$(debconf-get partman-auto-crypto/erase_disks)" = "false" ]; then
touch $id/skip_erase
fi
found=yes
break
done
[ $found = yes ] && break
done
crypto_check_setup || exit 1
crypto_setup no || exit 1
# Rewrite pv_devices, that auto_lvm_perform would have set properly in the
# partman-auto-crypto case, but since initial_auto_raid_*lvm have their own
# tweaked implementation, build the mapper path like auto-shared.sh does:
for pv in $pv_devices; do
mapped_pv=/dev/mapper/${pv##*/}_crypt
new_pv_devices=${new_pv_devices:+$new_pv_devices }$mapped_pv
done
pv_devices="$new_pv_devices"
# Copied from partman-auto-crypto's autopartition-crypto:
for pv in $pv_devices; do
dev="$(dev_to_partman $pv)"
[ -d "$dev" ] || continue
[ -f "$dev/crypt_realdev" ] || continue
[ -f "$dev/device" ] || continue
# We should have only one partition, but lets be thorough
cd $dev
partitions=
open_dialog PARTITIONS
while { read_line num id size type fs path name; [ "$id" ]; }; do
[ "$fs" != free ] || continue
partitions="$partitions $id"
done
close_dialog
for id in $partitions; do
for file in acting_filesystem filesystem format formatable use_filesystem; do
rm -f $id/$file
done
echo lvm > $id/method
done
done
# Make sure the recipe contains lvmok tags
if ! echo "$scheme" | grep -q lvmok; then
bail_out unusable_recipe
fi
# Make sure a boot partition isn't marked as lvmok, unless the user
# has told us it is ok for /boot to reside on a logical volume
if echo "$scheme" | grep lvmok | grep -q "[[:space:]]/boot[[:space:]]"; then
db_input critical partman-auto-lvm/no_boot || true
db_go || return 255
db_get partman-auto-lvm/no_boot || true
[ "$RET" = true ] || bail_out unusable_recipe
fi
expand_scheme
# Extract the mapping of which VG goes onto which PV
auto_lvm_create_vg_map
auto_lvm_perform
|