2 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3 # ex: ts=8 sw=4 sts=4 et filetype=sh
5 type getarg
>/dev
/null
2>&1 || .
/lib
/dracut-lib.sh
6 type det_fs
>/dev
/null
2>&1 || .
/lib
/fs-lib.sh
8 [ -f /tmp
/root.info
] && .
/tmp
/root.info
10 PATH
=/usr
/sbin
:/usr
/bin
:/sbin
:/bin
12 if getargbool
0 rd.live.debug
-y rdlivedebug
; then
13 exec > /tmp
/liveroot.$$.out
14 exec 2>> /tmp
/liveroot.$$.out
21 # parse various live image specific options that make sense to be
22 # specified as their own things
23 live_dir
=$
(getarg rd.live.dir live_dir
)
24 [ -z "$live_dir" ] && live_dir
="LiveOS"
25 getargbool
0 rd.live.ram
-y live_ram
&& live_ram
="yes"
26 getargbool
0 rd.live.overlay.
reset -y reset_overlay
&& reset_overlay
="yes"
27 getargbool
0 rd.live.overlay.
readonly -y readonly_overlay
&& readonly_overlay
="--readonly" || readonly_overlay
=""
28 overlay
=$
(getarg rd.live.overlay overlay
)
31 [ -b $livedev ] && fs
=$
(blkid
-s TYPE
-o value
$livedev)
32 if [ "$fs" = "iso9660" -o "$fs" = "udf" ]; then
35 getarg rd.live.check check || check
=""
36 if [ -n "$check" ]; then
37 [ -x /bin
/plymouth
] && /bin
/plymouth
--hide-splash
38 checkisomd5
--verbose $livedev ||
:
40 die
"CD check failed!"
43 [ -x /bin
/plymouth
] && /bin
/plymouth
--show-splash
46 # determine filesystem type for a filesystem image
48 blkid
-s TYPE
-u noraid
-o value
"$1"
51 for arg
in $CMDLINE; do case $arg in ro|rw
) liverw
=$arg ;; esac; done
52 # mount the backing of the live image first
53 mkdir
-m 0755 -p /run
/initramfs
/live
54 if [ -f $livedev ]; then
55 # no mount needed - we've already got the LiveOS image in initramfs
56 # check filesystem type and handle accordingly
57 fstype
=$
(det_img_fs
$livedev)
59 squashfs
) SQUASHED
=$livedev;;
60 auto
) die
"cannot mount live image (unknown filesystem type)" ;;
63 [ -e /sys
/fs
/$fstype ] || modprobe
$fstype
65 mount
-n -t $fstype -o ${liverw:-ro} $livedev /run
/initramfs
/live
66 if [ "$?" != "0" ]; then
67 die
"Failed to mount block device of live image"
72 # overlay setup helper function
74 # create a sparse file for the overlay
75 # overlay: if non-ram overlay searching is desired, do it,
76 # otherwise, create traditional overlay in ram
77 OVERLAY_LOOPDEV
=$
( losetup
-f )
79 l
=$
(blkid
-s LABEL
-o value
$livedev) || l
=""
80 u
=$
(blkid
-s UUID
-o value
$livedev) || u
=""
82 if [ -z "$overlay" ]; then
83 pathspec
="/${live_dir}/overlay-$l-$u"
84 elif ( echo $overlay |
grep -q ":" ); then
85 # pathspec specified, extract
86 pathspec
=$
( echo $overlay |
sed -e 's/^.*://' )
89 if [ -z "$pathspec" -o "$pathspec" = "auto" ]; then
90 pathspec
="/${live_dir}/overlay-$l-$u"
92 devspec
=$
( echo $overlay |
sed -e 's/:.*$//' )
94 # need to know where to look for the overlay
96 if [ -n "$devspec" -a -n "$pathspec" -a -n "$overlay" ]; then
97 mkdir
-m 0755 /run
/initramfs
/overlayfs
98 mount
-n -t auto
$devspec /run
/initramfs
/overlayfs ||
:
99 if [ -f /run
/initramfs
/overlayfs
$pathspec -a -w /run
/initramfs
/overlayfs
$pathspec ]; then
100 losetup
$OVERLAY_LOOPDEV /run
/initramfs
/overlayfs
$pathspec
101 if [ -n "$reset_overlay" ]; then
102 dd if=/dev
/zero of
=$OVERLAY_LOOPDEV bs
=64k count
=1 2>/dev
/null
106 umount
-l /run
/initramfs
/overlayfs ||
:
109 if [ -z "$setup" ]; then
110 if [ -n "$devspec" -a -n "$pathspec" ]; then
111 warn
"Unable to find persistent overlay; using temporary"
115 dd if=/dev
/null of
=/overlay bs
=1024 count
=1 seek
=$
((512*1024)) 2> /dev
/null
116 losetup
$OVERLAY_LOOPDEV /overlay
119 # set up the snapshot
120 echo 0 `blockdev --getsz $BASE_LOOPDEV` snapshot
$BASE_LOOPDEV $OVERLAY_LOOPDEV p
8 | dmsetup create
$readonly_overlay live-rw
123 # live cd helper function
124 do_live_from_base_loop
() {
128 # we might have a genMinInstDelta delta file for anaconda to take advantage of
129 if [ -e /run
/initramfs
/live
/${live_dir}/osmin.img
]; then
130 OSMINSQFS
=/run
/initramfs
/live
/${live_dir}/osmin.img
133 if [ -n "$OSMINSQFS" ]; then
134 # decompress the delta data
135 dd if=$OSMINSQFS of
=/osmin.img
2> /dev
/null
136 OSMIN_SQUASHED_LOOPDEV
=$
( losetup
-f )
137 losetup
-r $OSMIN_SQUASHED_LOOPDEV /osmin.img
138 mkdir
-m 0755 -p /run
/initramfs
/squashfs.osmin
139 mount
-n -t squashfs
-o ro
$OSMIN_SQUASHED_LOOPDEV /run
/initramfs
/squashfs.osmin
140 OSMIN_LOOPDEV
=$
( losetup
-f )
141 losetup
-r $OSMIN_LOOPDEV /run
/initramfs
/squashfs.osmin
/osmin
142 umount
-l /run
/initramfs
/squashfs.osmin
145 # we might have an embedded fs image to use as rootfs (uncompressed live)
146 if [ -e /run
/initramfs
/live
/${live_dir}/ext3fs.img
]; then
147 FSIMG
="/run/initramfs/live/${live_dir}/ext3fs.img"
148 elif [ -e /run
/initramfs
/live
/${live_dir}/rootfs.img
]; then
149 FSIMG
="/run/initramfs/live/${live_dir}/rootfs.img"
152 if [ -n "$FSIMG" ] ; then
153 BASE_LOOPDEV
=$
( losetup
-f )
154 losetup
-r $BASE_LOOPDEV $FSIMG
156 do_live_from_base_loop
159 # we might have an embedded fs image on squashfs (compressed live)
160 if [ -e /run
/initramfs
/live
/${live_dir}/squashfs.img
]; then
161 SQUASHED
="/run/initramfs/live/${live_dir}/squashfs.img"
164 if [ -e "$SQUASHED" ] ; then
165 if [ -n "$live_ram" ] ; then
166 echo "Copying live image to RAM..."
167 echo "(this may take a few minutes)"
168 dd if=$SQUASHED of
=/squashed.img bs
=512 2> /dev
/null
169 umount
-n /run
/initramfs
/live
170 echo "Done copying live image to RAM."
171 eject
-p $livedev ||
:
172 SQUASHED
="/squashed.img"
175 SQUASHED_LOOPDEV
=$
( losetup
-f )
176 losetup
-r $SQUASHED_LOOPDEV $SQUASHED
177 mkdir
-m 0755 -p /run
/initramfs
/squashfs
178 mount
-n -t squashfs
-o ro
$SQUASHED_LOOPDEV /run
/initramfs
/squashfs
180 BASE_LOOPDEV
=$
( losetup
-f )
181 if [ -f /run
/initramfs
/squashfs
/LiveOS
/ext3fs.img
]; then
182 losetup
-r $BASE_LOOPDEV /run
/initramfs
/squashfs
/LiveOS
/ext3fs.img
183 elif [ -f /run
/initramfs
/squashfs
/LiveOS
/rootfs.img
]; then
184 losetup
-r $BASE_LOOPDEV /run
/initramfs
/squashfs
/LiveOS
/rootfs.img
187 umount
-l /run
/initramfs
/squashfs
189 do_live_from_base_loop
192 if [ -b "$OSMIN_LOOPDEV" ]; then
193 # set up the devicemapper snapshot device, which will merge
194 # the normal live fs image, and the delta, into a minimzied fs image
195 echo "0 $( blockdev --getsz $BASE_LOOPDEV ) snapshot $BASE_LOOPDEV $OSMIN_LOOPDEV p 8" | dmsetup create
--readonly live-osimg-min
198 ROOTFLAGS
="$(getarg rootflags)"
199 if [ -n "$ROOTFLAGS" ]; then
200 ROOTFLAGS
="-o $ROOTFLAGS"
203 if [ -b "$BASE_LOOPDEV" ]; then
204 ln -s $BASE_LOOPDEV /run
/initramfs
/live-baseloop
206 ln -s /dev
/mapper
/live-rw
/dev
/root
207 printf '/bin/mount %s /dev/mapper/live-rw %s\n' "$ROOTFLAGS" "$NEWROOT" > $hookdir/mount
/01-$$
-live.sh