4 USE_LVM=${USE_LVM:-yes}
6 # if we should init LVM at boot
9 # LVM volumes that are needed to activate
14 # VG for suspend resume dev
19 # LVM version. Autodetected if not set.
23 # LVM devices that should not be included in vgscan on initrd.
27 # setup geninitrd module
30 lvm=$(find_tool $initrd_dir/lvm /sbin/initrd-lvm)
32 if [ ! -x "$lvm" ]; then
36 if is_yes "$USE_LVM" && [ -z "$LVMTOOLSVERSION" ]; then
37 LVMTOOLSVERSION=$(LC_ALL=C $lvm vgchange --version 2>/dev/null | awk '/LVM version:/{if ($3 >= 2) print "2"}')
38 if [ -z "$LVMTOOLSVERSION" ]; then
39 die "Can't determine LVM tools version. Please set LVMTOOLSVERSION and rerun $PROGRAM."
44 # return true if node is lvm node
45 # @param string $node device node to be examined
51 if is_no "$USE_LVM"; then
55 if [ ! -e "$node" ]; then
56 die "check_lvm(): node $node doesn't exist!"
60 # block-major-58 is lvm1
61 ls -lL "$node" 2> /dev/null | awk '{if (/^b/) { if ($5 == "58,") { exit 0; } else { exit 1; } } else { exit 1; }}'
69 $lvm lvdisplay "$node" > /dev/null 2>&1
71 if [ $rc -gt 127 ]; then
72 # lvdisplay terminated by signal! most likely it segfaulted.
73 die "Unexpected exit from 'lvdisplay $node': $rc - are your lvm tools broken?"
79 # find modules for $devpath
80 # @param $devpath device to be examined
85 debug "LVM: $devpath is LVM node"
87 local vg=$(find_lvm_vg "$devpath")
88 debug "LVM VG for $devpath: $vg"
89 VGVOLUMES=$(echo $VGVOLUMES $vg | tr ' ' '\n' | sort -u)
91 local pv=$(find_lvm_pv "$vg")
92 debug "LVM PV for $vg: $pv"
93 PVDEVICES=$(echo $PVDEVICES $pv | tr ' ' '\n' | sort -u)
95 if [ -n "$PVDEVICES" ]; then
96 for device in $PVDEVICES; do
97 find_modules_for_devpath $device
100 die "I wasn't able to find PV. You can try to set PVDEVICES in /etc/sysconfig/geninitrd."
103 if [ "$LVMTOOLSVERSION" = "2" ]; then
104 find_module "-dm-mod"
105 elif [ "$LVMTOOLSVERSION" = "1" ]; then
107 find_module "-lvm-mod"
109 die "LVM version $LVMTOOLSVERSION is not supported."
112 debug "LVM v$LVMTOOLSVERSION enabled"
117 # generate initrd fragment for lvm
120 debug "Adding LVM support to initrd"
122 inst_exec $lvm /bin/lvm.static
124 # always make /dev on tmpfs for LVM2
125 if [ "$LVMTOOLSVERSION" = "2" ]; then
130 mknod $DESTDIR/dev/urandom c 1 9
132 if ! is_yes "$dev_mounted"; then
134 mknod $DESTDIR/dev/mapper/control c 10 63
135 for device in $PVDEVICES; do
136 # if LVM on RAID then device might be copied already in gen_md
137 [ -e "$DESTDIR/dev/$(basename $device)" ] && continue
144 if [ "$LVMTOOLSVERSION" = "1" ]; then
147 for vg in $VGVOLUMES; do
148 lvm vgchange -T -a y $vg
152 echo "cat /etc/lvm.conf > /tmp/lvm.conf" | add_linuxrc
153 echo "global {" > "$DESTDIR/etc/lvm.conf"
154 echo " locking_type = 0" >> "$DESTDIR/etc/lvm.conf"
155 echo " locking_dir = \"/tmp\"" >> "$DESTDIR/etc/lvm.conf"
156 echo "}" >> "$DESTDIR/etc/lvm.conf"
157 echo "devices {" >> "$DESTDIR/etc/lvm.conf"
158 echo " sysfs_scan=0" >> "$DESTDIR/etc/lvm.conf"
159 if is_yes "$have_md"; then
160 echo " md_component_detection = 1" >> "$DESTDIR/etc/lvm.conf"
162 if is_yes "$have_dmraid" || is_yes "$have_multipath"; then
163 echo ' types = [ "device-mapper", 254 ]' >> "$DESTDIR/etc/lvm.conf"
165 if [ "$lvm_ignore_devices" ]; then
166 # TODO: think of merging with lvm dumpconfig output
167 echo ' filter = [' >> "$DESTDIR/etc/lvm.conf"
169 for dev in $lvm_ignore_devices; do
170 debug "LVM v2: ignore device $dev"
171 printf ' "r|^%s.*|",\n' $dev
172 done >> "$DESTDIR/etc/lvm.conf"
173 echo ']' >> "$DESTDIR/etc/lvm.conf"
175 # XXX filter= must be on one line!
176 $lvm dumpconfig | awk '/filter=/' >> "$DESTDIR/etc/lvm.conf"
177 echo "}" >> "$DESTDIR/etc/lvm.conf"
182 export ROOTDEV=$rootdev
183 export ROOTVG="$VGVOLUMES"
184 export SUSPENDVG=$SUSPENDVG
187 # parse rootdev from kernel commandline if it begins with /
190 if [ "$ROOT" != "$ROOTDEV" ]; then
192 echo "LVM: Using 'root=$ROOTDEV' from kernel commandline"
193 local tmp=${ROOTDEV#/dev/}
194 if [ "$tmp" != "$ROOTDEV" ]; then
196 echo "LVM: Using Volume Group '$ROOTVG' for rootfs"
203 if [ "$SUSPENDVG" = "$ROOTVG" ]; then
204 export VGVOLUMES="$ROOTVG"
206 export VGVOLUMES="$SUSPENDVG $ROOTVG"
209 # disable noise from LVM accessing devices that aren't ready.
210 read printk < /proc/sys/kernel/printk
211 if [ ! "$DEBUGINITRD" ]; then
212 echo 0 > /proc/sys/kernel/printk
215 export LVM_SYSTEM_DIR=/tmp
216 : 'Scanning for Volume Groups'
217 lvm.static vgscan --mknodes --ignorelockingfailure 2>/dev/null
219 : 'Activating Volume Groups'
220 for vol in $VGVOLUMES; do
221 lvm.static vgchange --ignorelockingfailure -a y $vol 2>/dev/null
224 echo "$printk" > /proc/sys/kernel/printk
226 # Find out major/minor
227 attrs="$(lvm.static lvdisplay --ignorelockingfailure -c $ROOTDEV 2>/dev/null)"
228 if [ "$attrs" ]; then
229 majmin="${attrs#*$ROOTDEV*:*:*:*:*:*:*:*:*:*:*:*}"
230 if [ "$majmin" != "$attrs" ]; then
236 if [ "$major" -a "$minor" ]; then
238 echo $((256 * $major + $minor)) > /proc/sys/kernel/real-root-dev
240 echo 2>&1 "Error figuring out real root device for $ROOTDEV!"
241 echo 2>&1 "System will not most likely boot up! So dropping you to a shell!"
252 # find PV names from given VG name
253 # @param string $vg Volume Group name
258 local pv=$($lvm vgs --noheadings -o pv_name "$vg")
262 # find VG name from given devnode
263 # @param string $devnode device node to be examined
268 local vg=$($lvm lvs --noheadings -o vg_name "$devnode")