5 # if we should init LVM at boot
8 # LVM volumes that are needed to activate
13 # VG for suspend resume dev
18 if [ -x /sbin/lvm ]; then
24 # LVM devices that should not be included in vgscan on initrd.
28 # return true if node is lvm node
29 # @param string $node device node to be examined
35 if is_no "$USE_LVM"; then
39 if [ ! -e "$node" ]; then
40 die "check_lvm(): node $node doesn't exist!"
44 # block-major-58 is lvm1
45 ls -lL "$node" 2> /dev/null | awk '{if (/^b/) { if ($5 == "58,") { exit 0; } else { exit 1; } } else { exit 1; }}'
53 /sbin/lvm lvdisplay "$node" > /dev/null 2>&1
55 if [ $rc -gt 127 ]; then
56 # lvdisplay terminated by signal! most likely it segfaulted.
57 die "Unexpected exit from 'lvdisplay $node': $rc - are your lvm tools broken?"
63 # find modules for $devpath
64 # @param $devpath device to be examined
69 debug "LVM: $devpath is LVM node"
71 if [ ! -f /sbin/initrd-lvm -o ! -x /sbin/lvdisplay -o ! -x /sbin/pvdisplay ]; then
72 die "root on LVM but /sbin/initrd-lvm, /sbin/lvdisplay and /sbin/pvdisplay not found. Please install lvm(2) and lvm(2)-initrd package and rerun $PROGRAM."
75 if [ -z "$LVMTOOLSVERSION" ]; then
76 LVMTOOLSVERSION=$(/sbin/initrd-lvm vgchange --version 2>/dev/null|head -n 1|awk '{gsub("vgchange: Logical Volume Manager ",NIL); gsub("LVM version: ",NIL); gsub(/\..*/,NIL); print $1}')
77 if [ -z "$LVMTOOLSVERSION" ]; then
78 die "Can't determine LVM tools version. Please set LVMTOOLSVERSION and rerun $PROGRAM."
82 local vg=$(find_lvm_vg "$devpath")
83 debug "LVM VG for $devpath: $vg"
84 VGVOLUMES=$(echo $VGVOLUMES $vg | tr ' ' '\n' | sort -u)
86 local pv=$(find_lvm_pv "$vg")
87 debug "LVM PV for $vg: $pv"
88 PVDEVICES=$(echo $PVDEVICES $pv | tr ' ' '\n' | sort -u)
90 if [ -n "$PVDEVICES" ]; then
91 for device in $PVDEVICES; do
92 find_modules_for_devpath $device
95 die "I wasn't able to find PV (via lvdisplay and pvdisplay). You can try to set PVDEVICES in /etc/sysconfig/geninitrd."
98 if [ "$LVMTOOLSVERSION" = "2" ]; then
100 elif [ "$LVMTOOLSVERSION" = "1" ]; then
102 find_module "-lvm-mod"
104 die "LVM version $LVMTOOLSVERSION is not supported yet."
107 debug "LVM v$LVMTOOLSVERSION enabled"
112 # generate initrd fragment for lvm
115 debug "Adding LVM support to initrd"
117 inst_exec /sbin/initrd-lvm /bin/lvm.static
119 # always make /dev on tmpfs for LVM2
120 if [ "$LVMTOOLSVERSION" = "2" ]; then
124 if ! is_yes "$dev_mounted"; then
126 mknod $DESTDIR/dev/mapper/control c 10 63
127 for device in $PVDEVICES; do
128 # if LVM on RAID then device might be copied already in gen_md
129 [ -e "$DESTDIR/dev/$(basename $device)" ] && continue
135 if [ "$LVMTOOLSVERSION" = "1" ]; then
138 for vg in $VGVOLUMES; do
139 lvm vgchange -T -a y $vg
143 echo "cat /etc/lvm.conf > /tmp/lvm.conf" | add_linuxrc
144 echo "global {" > "$DESTDIR/etc/lvm.conf"
145 echo " locking_type = 0" >> "$DESTDIR/etc/lvm.conf"
146 echo " locking_dir = \"/tmp\"" >> "$DESTDIR/etc/lvm.conf"
147 echo "}" >> "$DESTDIR/etc/lvm.conf"
148 echo "devices {" >> "$DESTDIR/etc/lvm.conf"
149 echo " sysfs_scan=0" >> "$DESTDIR/etc/lvm.conf"
150 if is_yes "$have_md"; then
151 echo " md_component_detection = 1" >> "$DESTDIR/etc/lvm.conf"
153 if is_yes "$have_dmraid" || is_yes "$have_multipath"; then
154 echo ' types = [ "device-mapper", 254 ]' >> "$DESTDIR/etc/lvm.conf"
156 if [ "$lvm_ignore_devices" ]; then
157 # TODO: think of merging with lvm dumpconfig output
158 echo ' filter = [' >> "$DESTDIR/etc/lvm.conf"
160 for dev in $lvm_ignore_devices; do
161 debug "LVM v2: ignore device $dev"
162 printf ' "r|^%s.*|",\n' $dev
163 done >> "$DESTDIR/etc/lvm.conf"
164 echo ']' >> "$DESTDIR/etc/lvm.conf"
166 # XXX filter= must be on one line!
167 lvm dumpconfig | awk '/filter=/' >> "$DESTDIR/etc/lvm.conf"
168 echo "}" >> "$DESTDIR/etc/lvm.conf"
173 export ROOTDEV=$rootdev
174 export ROOTVG="$VGVOLUMES"
175 export SUSPENDVG=$SUSPENDVG
178 # parse rootdev from kernel commandline if it begins with /
181 if [ "$ROOT" != "$ROOTDEV" ]; then
183 echo "LVM: Using 'root=$ROOTDEV' from kernel commandline"
184 local tmp=${ROOTDEV#/dev/}
185 if [ "$tmp" != "$ROOTDEV" ]; then
187 echo "LVM: Using Volume Group '$ROOTVG' for rootfs"
194 if [ "$SUSPENDVG" = "$ROOTVG" ]; then
195 export VGVOLUMES="$ROOTVG"
197 export VGVOLUMES="$SUSPENDVG $ROOTVG"
200 # disable noise from LVM accessing devices that aren't ready.
201 read printk < /proc/sys/kernel/printk
202 if [ ! "$DEBUGINITRD" ]; then
203 echo 0 > /proc/sys/kernel/printk
206 export LVM_SYSTEM_DIR=/tmp
207 : 'Scanning for Volume Groups'
208 lvm.static vgscan --mknodes --ignorelockingfailure 2>/dev/null
210 : 'Activating Volume Groups'
211 for vol in $VGVOLUMES; do
212 lvm.static vgchange --ignorelockingfailure -a y $vol 2>/dev/null
215 echo "$printk" > /proc/sys/kernel/printk
217 # Find out major/minor
218 attrs="$(lvm.static lvdisplay --ignorelockingfailure -c $ROOTDEV 2>/dev/null)"
219 if [ "$attrs" ]; then
220 majmin="${attrs#*$ROOTDEV*:*:*:*:*:*:*:*:*:*:*:*}"
221 if [ "$majmin" != "$attrs" ]; then
227 if [ "$major" -a "$minor" ]; then
229 echo $((256 * $major + $minor)) > /proc/sys/kernel/real-root-dev
231 echo 2>&1 "Error figuring out real root device for $ROOTDEV!"
232 echo 2>&1 "System will not most likely boot up! So dropping you to a shell!"
243 # find PV names from given VG name
244 # @param string $vg Volume Group name
249 local pv=$(/sbin/vgs --noheadings -o pv_name "$vg")
253 # find VG name from given devnode
254 # @param string $devnode device node to be examined
259 local vg=$(/sbin/lvs --noheadings -o vg_name "$devnode")