]> git.ipfire.org Git - thirdparty/dracut.git/blame - modules.d/90dmsquash-live/dmsquash-live-root.sh
dmsquash-live/dmsquash-live-root.sh: add parameter rd.live.squashimg
[thirdparty/dracut.git] / modules.d / 90dmsquash-live / dmsquash-live-root.sh
CommitLineData
2e44f115 1#!/bin/sh
cc02093d
HH
2# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3# ex: ts=8 sw=4 sts=4 et filetype=sh
2e44f115 4
c9f1e3d1 5type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
566dab2a 6
fb59f4c9 7PATH=/usr/sbin:/usr/bin:/sbin:/bin
2e44f115 8
68e7661c 9if getargbool 0 rd.live.debug -n -y rdlivedebug; then
2e44f115
JK
10 exec > /tmp/liveroot.$$.out
11 exec 2>> /tmp/liveroot.$$.out
12 set -x
13fi
14
15[ -z "$1" ] && exit 1
16livedev="$1"
17
cc0e7a36
JK
18# parse various live image specific options that make sense to be
19# specified as their own things
68e7661c 20live_dir=$(getarg rd.live.dir -d live_dir)
cc0e7a36 21[ -z "$live_dir" ] && live_dir="LiveOS"
32214acb
HH
22squash_image=$(getarg rd.live.squashimg)
23[ -z "squash_image" ] && squash_image="squashfs.img"
24
68e7661c
HH
25getargbool 0 rd.live.ram -d -y live_ram && live_ram="yes"
26getargbool 0 rd.live.overlay.reset -d -y reset_overlay && reset_overlay="yes"
27getargbool 0 rd.live.overlay.readonly -d -y readonly_overlay && readonly_overlay="--readonly" || readonly_overlay=""
28overlay=$(getarg rd.live.overlay -d overlay)
cc0e7a36 29
48205bb0
WW
30# CD/DVD media check
31[ -b $livedev ] && fs=$(blkid -s TYPE -o value $livedev)
a607b7d4 32if [ "$fs" = "iso9660" -o "$fs" = "udf" ]; then
c56b63d1
JK
33 check="yes"
34fi
68e7661c 35getarg rd.live.check -d check || check=""
c56b63d1 36if [ -n "$check" ]; then
ca2c6936 37 type plymouth >/dev/null 2>&1 && plymouth --hide-splash
5204d1d3 38 if [ -n "$DRACUT_SYSTEMD" ]; then
040f3883
HH
39 p=$(str_replace "$livedev" "-" '\x2d')
40 systemctl start checkisomd5@${p}.service
41 else
42 checkisomd5 --verbose $livedev
43 fi
c56b63d1 44 if [ $? -ne 0 ]; then
cc02093d
HH
45 die "CD check failed!"
46 exit 1
c56b63d1 47 fi
ca2c6936 48 type plymouth >/dev/null 2>&1 && plymouth --show-splash
c56b63d1 49fi
2e44f115 50
b2de89c5
HH
51ln -s $livedev /run/initramfs/livedev
52
a12db35e
WW
53# determine filesystem type for a filesystem image
54det_img_fs() {
85804a91 55 udevadm settle
380b8b51 56 blkid -s TYPE -u noraid -o value "$1"
a12db35e
WW
57}
58
85804a91
HH
59modprobe squashfs
60
48205bb0 61for arg in $CMDLINE; do case $arg in ro|rw) liverw=$arg ;; esac; done
2e44f115 62# mount the backing of the live image first
d125a470 63mkdir -m 0755 -p /run/initramfs/live
0ddd68f7
WW
64if [ -f $livedev ]; then
65 # no mount needed - we've already got the LiveOS image in initramfs
a12db35e 66 # check filesystem type and handle accordingly
baa5c113
HH
67 fstype=$(det_img_fs $livedev)
68 case $fstype in
69 squashfs) SQUASHED=$livedev;;
a12db35e
WW
70 auto) die "cannot mount live image (unknown filesystem type)" ;;
71 *) FSIMG=$livedev ;;
0ddd68f7 72 esac
baa5c113 73 [ -e /sys/fs/$fstype ] || modprobe $fstype
0ddd68f7 74else
48205bb0
WW
75 mount -n -t $fstype -o ${liverw:-ro} $livedev /run/initramfs/live
76 if [ "$?" != "0" ]; then
0ddd68f7
WW
77 die "Failed to mount block device of live image"
78 exit 1
79 fi
2e44f115
JK
80fi
81
2e44f115
JK
82# overlay setup helper function
83do_live_overlay() {
84 # create a sparse file for the overlay
85 # overlay: if non-ram overlay searching is desired, do it,
86 # otherwise, create traditional overlay in ram
87 OVERLAY_LOOPDEV=$( losetup -f )
88
89 l=$(blkid -s LABEL -o value $livedev) || l=""
90 u=$(blkid -s UUID -o value $livedev) || u=""
91
dfba82b3
JK
92 if [ -z "$overlay" ]; then
93 pathspec="/${live_dir}/overlay-$l-$u"
94 elif ( echo $overlay | grep -q ":" ); then
2e44f115
JK
95 # pathspec specified, extract
96 pathspec=$( echo $overlay | sed -e 's/^.*://' )
2e44f115
JK
97 fi
98
a607b7d4 99 if [ -z "$pathspec" -o "$pathspec" = "auto" ]; then
2e44f115
JK
100 pathspec="/${live_dir}/overlay-$l-$u"
101 fi
102 devspec=$( echo $overlay | sed -e 's/:.*$//' )
103
104 # need to know where to look for the overlay
105 setup=""
dfba82b3 106 if [ -n "$devspec" -a -n "$pathspec" -a -n "$overlay" ]; then
d125a470 107 mkdir -m 0755 /run/initramfs/overlayfs
3da78360
HH
108 mount -n -t auto $devspec /run/initramfs/overlayfs || :
109 if [ -f /run/initramfs/overlayfs$pathspec -a -w /run/initramfs/overlayfs$pathspec ]; then
110 losetup $OVERLAY_LOOPDEV /run/initramfs/overlayfs$pathspec
2e44f115 111 if [ -n "$reset_overlay" ]; then
0db77f5a 112 dd if=/dev/zero of=$OVERLAY_LOOPDEV bs=64k count=1 conv=fsync 2>/dev/null
2e44f115
JK
113 fi
114 setup="yes"
115 fi
d125a470 116 umount -l /run/initramfs/overlayfs || :
2e44f115
JK
117 fi
118
579f3853
FG
119 if [ -z "$setup" -o -n "$readonly_overlay" ]; then
120 if [ -n "$setup" ]; then
121 warn "Using temporary overlay."
122 elif [ -n "$devspec" -a -n "$pathspec" ]; then
cc02093d
HH
123 warn "Unable to find persistent overlay; using temporary"
124 sleep 5
2e44f115
JK
125 fi
126
127 dd if=/dev/null of=/overlay bs=1024 count=1 seek=$((512*1024)) 2> /dev/null
579f3853
FG
128 if [ -n "$setup" -a -n "$readonly_overlay" ]; then
129 RO_OVERLAY_LOOPDEV=$( losetup -f )
130 losetup $RO_OVERLAY_LOOPDEV /overlay
131 else
132 losetup $OVERLAY_LOOPDEV /overlay
133 fi
2e44f115
JK
134 fi
135
136 # set up the snapshot
579f3853
FG
137 sz=$(blockdev --getsz $BASE_LOOPDEV)
138 if [ -n "$readonly_overlay" ]; then
139 echo 0 $sz snapshot $BASE_LOOPDEV $OVERLAY_LOOPDEV p 8 | dmsetup create $readonly_overlay live-ro
140 base="/dev/mapper/live-ro"
141 over=$RO_OVERLAY_LOOPDEV
142 else
143 base=$BASE_LOOPDEV
144 over=$OVERLAY_LOOPDEV
145 fi
146 echo 0 $sz snapshot $base $over p 8 | dmsetup create live-rw
2e44f115
JK
147}
148
149# live cd helper function
150do_live_from_base_loop() {
151 do_live_overlay
152}
153
154# we might have a genMinInstDelta delta file for anaconda to take advantage of
19f3a804
HH
155if [ -e /run/initramfs/live/${live_dir}/osmin.img ]; then
156 OSMINSQFS=/run/initramfs/live/${live_dir}/osmin.img
2e44f115
JK
157fi
158
159if [ -n "$OSMINSQFS" ]; then
160 # decompress the delta data
161 dd if=$OSMINSQFS of=/osmin.img 2> /dev/null
162 OSMIN_SQUASHED_LOOPDEV=$( losetup -f )
163 losetup -r $OSMIN_SQUASHED_LOOPDEV /osmin.img
d125a470
HH
164 mkdir -m 0755 -p /run/initramfs/squashfs.osmin
165 mount -n -t squashfs -o ro $OSMIN_SQUASHED_LOOPDEV /run/initramfs/squashfs.osmin
2e44f115 166 OSMIN_LOOPDEV=$( losetup -f )
d125a470
HH
167 losetup -r $OSMIN_LOOPDEV /run/initramfs/squashfs.osmin/osmin
168 umount -l /run/initramfs/squashfs.osmin
2e44f115
JK
169fi
170
dfec8467 171# we might have an embedded fs image to use as rootfs (uncompressed live)
19f3a804
HH
172if [ -e /run/initramfs/live/${live_dir}/ext3fs.img ]; then
173 FSIMG="/run/initramfs/live/${live_dir}/ext3fs.img"
174elif [ -e /run/initramfs/live/${live_dir}/rootfs.img ]; then
175 FSIMG="/run/initramfs/live/${live_dir}/rootfs.img"
2e44f115
JK
176fi
177
dfec8467 178if [ -n "$FSIMG" ] ; then
2e44f115 179 BASE_LOOPDEV=$( losetup -f )
dfec8467 180 losetup -r $BASE_LOOPDEV $FSIMG
2e44f115
JK
181
182 do_live_from_base_loop
183fi
184
dfec8467 185# we might have an embedded fs image on squashfs (compressed live)
32214acb
HH
186if [ -e /run/initramfs/live/${live_dir}/${squash_image} ]; then
187 SQUASHED="/run/initramfs/live/${live_dir}/${squash_image}"
2e44f115
JK
188fi
189
190if [ -e "$SQUASHED" ] ; then
3ae2f09a 191 if [ -n "$live_ram" ] ; then
2e44f115
JK
192 echo "Copying live image to RAM..."
193 echo "(this may take a few minutes)"
194 dd if=$SQUASHED of=/squashed.img bs=512 2> /dev/null
19f3a804 195 umount -n /run/initramfs/live
2e44f115 196 echo "Done copying live image to RAM."
2e44f115
JK
197 SQUASHED="/squashed.img"
198 fi
199
200 SQUASHED_LOOPDEV=$( losetup -f )
201 losetup -r $SQUASHED_LOOPDEV $SQUASHED
d125a470
HH
202 mkdir -m 0755 -p /run/initramfs/squashfs
203 mount -n -t squashfs -o ro $SQUASHED_LOOPDEV /run/initramfs/squashfs
2e44f115
JK
204
205 BASE_LOOPDEV=$( losetup -f )
f7c05c55
AP
206 if [ -f /run/initramfs/squashfs/LiveOS/ext3fs.img ]; then
207 losetup -r $BASE_LOOPDEV /run/initramfs/squashfs/LiveOS/ext3fs.img
208 elif [ -f /run/initramfs/squashfs/LiveOS/rootfs.img ]; then
209 losetup -r $BASE_LOOPDEV /run/initramfs/squashfs/LiveOS/rootfs.img
53331811 210 fi
2e44f115 211
f7c05c55 212 umount -l /run/initramfs/squashfs
2e44f115
JK
213
214 do_live_from_base_loop
215fi
216
217if [ -b "$OSMIN_LOOPDEV" ]; then
218 # set up the devicemapper snapshot device, which will merge
219 # the normal live fs image, and the delta, into a minimzied fs image
de50046c 220 echo "0 $( blockdev --getsz $BASE_LOOPDEV ) snapshot $BASE_LOOPDEV $OSMIN_LOOPDEV p 8" | dmsetup create --readonly live-osimg-min
2e44f115
JK
221fi
222
fbf1b5b1
JB
223ROOTFLAGS="$(getarg rootflags)"
224if [ -n "$ROOTFLAGS" ]; then
225 ROOTFLAGS="-o $ROOTFLAGS"
226fi
227
ce32e32f 228if [ -b "$BASE_LOOPDEV" ]; then
027dbc9f 229 ln -s $BASE_LOOPDEV /run/initramfs/live-baseloop
ce32e32f 230fi
2e44f115 231ln -s /dev/mapper/live-rw /dev/root
8442dc45 232printf 'mount %s /dev/mapper/live-rw %s\n' "$ROOTFLAGS" "$NEWROOT" > $hookdir/mount/01-$$-live.sh
2e44f115 233
fb67e4aa
HH
234need_shutdown
235
2e44f115 236exit 0