5 # if we should init LVM at boot
8 # LVM volumes that are needed to activate
13 # VG for suspend resume dev
18 # LVM version. Autodetected if not set.
22 lvm=$(find_tool $initrd_dir/lvm /sbin/initrd-lvm)
23 if [ -x /sbin/lvm -a -x $lvm ]; then
29 # LVM devices that should not be included in vgscan on initrd.
33 # return true if node is lvm node
34 # @param string $node device node to be examined
40 if is_no "$USE_LVM"; then
44 if [ ! -e "$node" ]; then
45 die "check_lvm(): node $node doesn't exist!"
49 # block-major-58 is lvm1
50 ls -lL "$node" 2> /dev/null | awk '{if (/^b/) { if ($5 == "58,") { exit 0; } else { exit 1; } } else { exit 1; }}'
58 /sbin/lvm lvdisplay "$node" > /dev/null 2>&1
60 if [ $rc -gt 127 ]; then
61 # lvdisplay terminated by signal! most likely it segfaulted.
62 die "Unexpected exit from 'lvdisplay $node': $rc - are your lvm tools broken?"
68 # find modules for $devpath
69 # @param $devpath device to be examined
74 debug "LVM: $devpath is LVM node"
76 if [ ! -x $lvm -o ! -x /sbin/lvdisplay -o ! -x /sbin/pvdisplay ]; then
77 die "root on LVM but /sbin/lvdisplay or /sbin/pvdisplay not found. Please install lvm(2) and lvm(2)-initrd package and rerun $PROGRAM."
80 if [ -z "$LVMTOOLSVERSION" ]; then
81 LVMTOOLSVERSION=$(LC_ALL=C $lvm vgchange --version 2>/dev/null | awk '/LVM version:/{if ($3 >= 2) print "2"}')
82 if [ -z "$LVMTOOLSVERSION" ]; then
83 die "Can't determine LVM tools version. Please set LVMTOOLSVERSION and rerun $PROGRAM."
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 (via lvdisplay and pvdisplay). 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
129 if ! is_yes "$dev_mounted"; then
131 mknod $DESTDIR/dev/mapper/control c 10 63
132 for device in $PVDEVICES; do
133 # if LVM on RAID then device might be copied already in gen_md
134 [ -e "$DESTDIR/dev/$(basename $device)" ] && continue
140 if [ "$LVMTOOLSVERSION" = "1" ]; then
143 for vg in $VGVOLUMES; do
144 lvm vgchange -T -a y $vg
148 echo "cat /etc/lvm.conf > /tmp/lvm.conf" | add_linuxrc
149 echo "global {" > "$DESTDIR/etc/lvm.conf"
150 echo " locking_type = 0" >> "$DESTDIR/etc/lvm.conf"
151 echo " locking_dir = \"/tmp\"" >> "$DESTDIR/etc/lvm.conf"
152 echo "}" >> "$DESTDIR/etc/lvm.conf"
153 echo "devices {" >> "$DESTDIR/etc/lvm.conf"
154 echo " sysfs_scan=0" >> "$DESTDIR/etc/lvm.conf"
155 if is_yes "$have_md"; then
156 echo " md_component_detection = 1" >> "$DESTDIR/etc/lvm.conf"
158 if is_yes "$have_dmraid" || is_yes "$have_multipath"; then
159 echo ' types = [ "device-mapper", 254 ]' >> "$DESTDIR/etc/lvm.conf"
161 if [ "$lvm_ignore_devices" ]; then
162 # TODO: think of merging with lvm dumpconfig output
163 echo ' filter = [' >> "$DESTDIR/etc/lvm.conf"
165 for dev in $lvm_ignore_devices; do
166 debug "LVM v2: ignore device $dev"
167 printf ' "r|^%s.*|",\n' $dev
168 done >> "$DESTDIR/etc/lvm.conf"
169 echo ']' >> "$DESTDIR/etc/lvm.conf"
171 # XXX filter= must be on one line!
172 lvm dumpconfig | awk '/filter=/' >> "$DESTDIR/etc/lvm.conf"
173 echo "}" >> "$DESTDIR/etc/lvm.conf"
178 export ROOTDEV=$rootdev
179 export ROOTVG="$VGVOLUMES"
180 export SUSPENDVG=$SUSPENDVG
183 # parse rootdev from kernel commandline if it begins with /
186 if [ "$ROOT" != "$ROOTDEV" ]; then
188 echo "LVM: Using 'root=$ROOTDEV' from kernel commandline"
189 local tmp=${ROOTDEV#/dev/}
190 if [ "$tmp" != "$ROOTDEV" ]; then
192 echo "LVM: Using Volume Group '$ROOTVG' for rootfs"
199 if [ "$SUSPENDVG" = "$ROOTVG" ]; then
200 export VGVOLUMES="$ROOTVG"
202 export VGVOLUMES="$SUSPENDVG $ROOTVG"
205 # disable noise from LVM accessing devices that aren't ready.
206 read printk < /proc/sys/kernel/printk
207 if [ ! "$DEBUGINITRD" ]; then
208 echo 0 > /proc/sys/kernel/printk
211 export LVM_SYSTEM_DIR=/tmp
212 : 'Scanning for Volume Groups'
213 lvm.static vgscan --mknodes --ignorelockingfailure 2>/dev/null
215 : 'Activating Volume Groups'
216 for vol in $VGVOLUMES; do
217 lvm.static vgchange --ignorelockingfailure -a y $vol 2>/dev/null
220 echo "$printk" > /proc/sys/kernel/printk
222 # Find out major/minor
223 attrs="$(lvm.static lvdisplay --ignorelockingfailure -c $ROOTDEV 2>/dev/null)"
224 if [ "$attrs" ]; then
225 majmin="${attrs#*$ROOTDEV*:*:*:*:*:*:*:*:*:*:*:*}"
226 if [ "$majmin" != "$attrs" ]; then
232 if [ "$major" -a "$minor" ]; then
234 echo $((256 * $major + $minor)) > /proc/sys/kernel/real-root-dev
236 echo 2>&1 "Error figuring out real root device for $ROOTDEV!"
237 echo 2>&1 "System will not most likely boot up! So dropping you to a shell!"
248 # find PV names from given VG name
249 # @param string $vg Volume Group name
254 local pv=$(/sbin/vgs --noheadings -o pv_name "$vg")
258 # find VG name from given devnode
259 # @param string $devnode device node to be examined
264 local vg=$(/sbin/lvs --noheadings -o vg_name "$devnode")