config/livecd-fedora-base-desktop.ks | 54 +++++++++++++++++++++- tools/livecd-iso-to-disk.sh | 83 ++++++++++++++++++++++++++++++++--- 2 files changed, 130 insertions(+), 7 deletions(-)
New commits: commit 8fb9fe7a9a8017d1195c59e5a3cae27621a48c1e Author: Jeremy Katz katzj@redhat.com Date: Mon Jun 2 20:16:39 2008 -0400
Allow adding extra kernel args to the syslinux.cfg with --extra-kernel-args
Pass additional options to be appended to the kernel with --extra-kernel-args so that you can script running livecd-iso-to-disk pointing to a persistent /home more easily
diff --git a/tools/livecd-iso-to-disk.sh b/tools/livecd-iso-to-disk.sh index 8ef1194..7468cbb 100644 --- a/tools/livecd-iso-to-disk.sh +++ b/tools/livecd-iso-to-disk.sh @@ -199,6 +199,10 @@ while [ $# -gt 2 ]; do --reset-mbr|--resetmbr) resetmbr=1 ;; + --extra-kernel-args) + kernelargs=$2 + shift + ;; *) usage ;; @@ -332,6 +336,7 @@ cp $CDMNT/isolinux/* $USBMNT/$SYSLINUXPATH echo "Updating boot config file" # adjust label and fstype sed -i -e "s/CDLABEL=[^ ]*/$USBLABEL/" -e "s/rootfstype=[^ ]*/rootfstype=$USBFS/" $USBMNT/$SYSLINUXPATH/isolinux.cfg +if [ -n "$kernelargs" ]; then sed -i -e "s/liveimg/liveimg ${kernelargs}/" $USBMNT/$SYSLINUXPATH/isolinux.cfg ; fi
if [ -n "$overlaysizemb" ]; then echo "Initializing persistent overlay file"
commit dbc2395d810db84efbbaca214034d0c115078ffc Author: Jeremy Katz katzj@redhat.com Date: Mon Jun 2 20:13:55 2008 -0400
And support specifying the persistent store by label or uuid
If you specify persistenthome=LABEL=foo you will get the device labeled as "foo" mounted as /home rather than LiveOS/home.img. Similarly for UUID
diff --git a/config/livecd-fedora-base-desktop.ks b/config/livecd-fedora-base-desktop.ks index 84e2de8..0bafe3b 100644 --- a/config/livecd-fedora-base-desktop.ks +++ b/config/livecd-fedora-base-desktop.ks @@ -101,10 +101,15 @@ if ! strstr "`cat /proc/cmdline`" noswap && [ -n "$swaps" ] ; then fi
mountPersistentHome() { - # if we're not given a block device, then make it one + # support label/uuid + if [ "${homedev##LABEL=}" != "${homedev}" -o "${homedev##UUID=}" != "${homedev}" ]; then + homedev=`/sbin/blkid -o device -t "$homedev"` + fi + + # if we're given a file rather than a blockdev, loopback it if [ ! -b "$homedev" ]; then loopdev=`losetup -f` - if [ "${homedev##/mnt/live}" != "${homedev}" ]; then + if [ "${homedev##/mnt/live}" != "${homedev}" ]; then action "Remounting live store r/w" mount -o remount,rw /mnt/live fi losetup $loopdev $homedev
commit 9ae29165b823621a5107b97025166b48854559fe Author: Jeremy Katz katzj@redhat.com Date: Mon Jun 2 20:11:18 2008 -0400
Support specifying the persistent /home
Specifying persistenthome=/path/to/device on the kernel command line will now prefer using that as opposed to anything else for the persistent /home
diff --git a/config/livecd-fedora-base-desktop.ks b/config/livecd-fedora-base-desktop.ks index b364803..84e2de8 100644 --- a/config/livecd-fedora-base-desktop.ks +++ b/config/livecd-fedora-base-desktop.ks @@ -94,29 +94,54 @@ fi
# enable swaps unless requested otherwise swaps=`blkid -t TYPE=swap -o device` -if ! strstr "`cat /proc/cmdline`" noswap -a [ -n "$swaps" ] ; then +if ! strstr "`cat /proc/cmdline`" noswap && [ -n "$swaps" ] ; then for s in $swaps ; do action "Enabling swap partition $s" swapon $s done fi
mountPersistentHome() { - homeloop=`losetup -f` - mount -o remount,rw /mnt/live - losetup $homeloop /mnt/live/LiveOS/home.img - if [ "$(/lib/udev/vol_id -t $homeloop)" = "crypto_LUKS" ]; then + # if we're not given a block device, then make it one + if [ ! -b "$homedev" ]; then + loopdev=`losetup -f` + if [ "${homedev##/mnt/live}" != "${homedev}" ]; then + action "Remounting live store r/w" mount -o remount,rw /mnt/live + fi + losetup $loopdev $homedev + homedev=$loopdev + fi + + # if it's encrypted, we need to unlock it + if [ "$(/lib/udev/vol_id -t $homedev)" = "crypto_LUKS" ]; then echo echo "Setting up encrypted /home device" - cryptsetup luksOpen $homeloop EncHome <&1 - homeloop=/dev/mapper/EncHome + cryptsetup luksOpen $homedev EncHome <&1 + homedev=/dev/mapper/EncHome fi - mount $homeloop /home + + # and finally do the mount + mount $homedev /home [ -x /sbin/restorecon ] && /sbin/restorecon /home if [ -d /home/fedora ]; then USERADDARGS="-M" ; fi }
+findPersistentHome() { + for arg in `cat /proc/cmdline` ; do + if [ "${arg##persistenthome=}" != "${arg}" ]; then + homedev=${arg##persistenthome=} + return + fi + done +} + +if strstr "`cat /proc/cmdline`" persistenthome= ; then + findPersistentHome +elif [ -e /mnt/live/LiveOS/home.img ]; then + homedev=/mnt/live/LiveOS/home.img +fi + # if we have a persistent /home, then we want to go ahead and mount it -if ! strstr "`cat /proc/cmdline`" nopersisthome -a [ -e /mnt/live/LiveOS/home.img ] ; then +if ! strstr "`cat /proc/cmdline`" nopersistenthome && [ -n "$homedev" ] ; then action "Mounting persistent /home" mountPersistentHome fi
commit 881d186e0e8277839de5a1f160a4e4d87c9875df Author: Jeremy Katz katzj@redhat.com Date: Mon Jun 2 17:15:55 2008 -0400
Support not blowing away the persistent /home with livecd-iso-to-disk
By default, we shouldn't delete the persistent /home file. This adds support for a --delete-home argument and also makes it so that you have to be very clear that you want to delete to help avoid accidents from occurring
diff --git a/tools/livecd-iso-to-disk.sh b/tools/livecd-iso-to-disk.sh index 9bdcb0e..8ef1194 100644 --- a/tools/livecd-iso-to-disk.sh +++ b/tools/livecd-iso-to-disk.sh @@ -22,7 +22,7 @@ export PATH=/sbin:/usr/sbin:$PATH
usage() { - echo "$0 [--reset-mbr] [--noverify] [--overlay-size-mb <size>] [--home-size-mb <size> ] [ --unencrypted-home] <isopath> <usbstick device>" + echo "$0 [--reset-mbr] [--noverify] [--overlay-size-mb <size>] [--home-size-mb <size>] [--unencrypted-home] <isopath> <usbstick device>" exit 1 }
@@ -173,6 +173,7 @@ if [ $(id -u) != 0 ]; then fi
cryptedhome=1 +keephome=1 while [ $# -gt 2 ]; do case $1 in --overlay-size-mb) @@ -189,6 +190,9 @@ while [ $# -gt 2 ]; do --unencrypted-home) cryptedhome="" ;; + --delete-home) + keephome="" + ;; --noverify) noverify=1 ;; @@ -250,7 +254,6 @@ if [ -n "$homesizemb" -a "$USBFS" = "vfat" ]; then fi fi
- # FIXME: would be better if we had better mountpoints CDMNT=$(mktemp -d /media/cdtmp.XXXXXX) mount -o loop,ro "$ISO" $CDMNT || exitclean @@ -259,6 +262,12 @@ mount $USBDEV $USBMNT || exitclean
trap exitclean SIGINT SIGTERM
+if [ -f "$USBMNT/LiveOS/home.img" -a -n "$keephome" -a -n "$homesizemb" ]; then + echo "ERROR: Requested keeping existing /home and specified a size for /home" + echo "Please either don't specify a size or specify --delete-home" + exitclean +fi + # let's try to make sure there's enough room on the stick if [ -d $CDMNT/LiveOS ]; then check=$CDMNT/LiveOS @@ -267,6 +276,8 @@ else fi if [ -d $USBMNT/LiveOS ]; then tbd=$(du -s -B 1M $USBMNT/LiveOS | awk {'print $1;'}) + [ -f $USBMNT/LiveOS/home.img ] && homesz=$(du -s -B 1M $USBMNT/LiveOS/home.img | awk {'print $1;'}) + [ -n "$homesz" -a -n "$keephome" ] && tbd=$(($tbd - $homesz)) else tbd=0 fi @@ -283,8 +294,17 @@ if [ $(($overlaysizemb + $homesizemb + $livesize)) -gt $(($free + $tbd)) ]; then fi
if [ -d $USBMNT/LiveOS ]; then - echo "Already set up as live image. Deleting old in fifteen seconds..." - sleep 15 + echo "Already set up as live image." + if [ -z "$keephome" -a -e $USBMNT/LiveOS/home.img ]; then + echo "WARNING: Persistent /home will be deleted!!!" + echo "Press Enter to continue or ctrl-c to abort" + read + else + echo "Deleting old OS in fifteen seconds..." + sleep 15 + + [ -e "$USBMNT/LiveOS/home.img" -a -n "$keephome" ] && mv $USBMNT/LiveOS/home.img $USBMNT/home.img + fi
rm -rf $USBMNT/LiveOS fi @@ -292,6 +312,7 @@ fi echo "Copying live image to USB stick" if [ ! -d $USBMNT/$SYSLINUXPATH ]; then mkdir $USBMNT/$SYSLINUXPATH ; fi if [ ! -d $USBMNT/LiveOS ]; then mkdir $USBMNT/LiveOS ; fi +if [ -n "$keephome" -a -f "$USBMNT/home.img" ]; then mv $USBMNT/home.img $USBMNT/LiveOS/home.img ; fi # cases without /LiveOS are legacy detection, remove for F10 if [ -f $CDMNT/LiveOS/squashfs.img ]; then cp $CDMNT/LiveOS/squashfs.img $USBMNT/LiveOS/squashfs.img || exitclean
commit a8997895dc0dde65bf0e780570785e36688a6214 Author: Jeremy Katz katzj@redhat.com Date: Mon Jun 2 17:13:30 2008 -0400
Make it more clear that we're mounting the persistent /home
Be a little bit more verbose in the initscript about what we're doing
diff --git a/config/livecd-fedora-base-desktop.ks b/config/livecd-fedora-base-desktop.ks index c883c0d..b364803 100644 --- a/config/livecd-fedora-base-desktop.ks +++ b/config/livecd-fedora-base-desktop.ks @@ -100,22 +100,28 @@ if ! strstr "`cat /proc/cmdline`" noswap -a [ -n "$swaps" ] ; then done fi
-# if we have a persistent /home, then we want to go ahead and mount it -if ! strstr "`cat /proc/cmdline`" nopersisthome -a [ -e /mnt/live/LiveOS/home.img ] ; then +mountPersistentHome() { homeloop=`losetup -f` mount -o remount,rw /mnt/live losetup $homeloop /mnt/live/LiveOS/home.img if [ "$(/lib/udev/vol_id -t $homeloop)" = "crypto_LUKS" ]; then + echo + echo "Setting up encrypted /home device" cryptsetup luksOpen $homeloop EncHome <&1 homeloop=/dev/mapper/EncHome fi mount $homeloop /home [ -x /sbin/restorecon ] && /sbin/restorecon /home if [ -d /home/fedora ]; then USERADDARGS="-M" ; fi +} + +# if we have a persistent /home, then we want to go ahead and mount it +if ! strstr "`cat /proc/cmdline`" nopersisthome -a [ -e /mnt/live/LiveOS/home.img ] ; then + action "Mounting persistent /home" mountPersistentHome fi
# add fedora user with no passwd -useradd $USERADDARGS -c "Fedora Live" fedora +action "Adding fedora user" useradd $USERADDARGS -c "Fedora Live" fedora passwd -d fedora > /dev/null
# turn off firstboot for livecd boots
commit aff8789c1b393475e65f799c82107b79864dc12e Author: Jeremy Katz katzj@redhat.com Date: Mon Jun 2 17:04:13 2008 -0400
Support a nopersisthome argument on the kernel command line
Passing 'nopersisthome' on the kernel command line will make it so that we don't attempt to mount a /home
diff --git a/config/livecd-fedora-base-desktop.ks b/config/livecd-fedora-base-desktop.ks index 5ab5560..c883c0d 100644 --- a/config/livecd-fedora-base-desktop.ks +++ b/config/livecd-fedora-base-desktop.ks @@ -101,7 +101,7 @@ if ! strstr "`cat /proc/cmdline`" noswap -a [ -n "$swaps" ] ; then fi
# if we have a persistent /home, then we want to go ahead and mount it -if [ -e /mnt/live/LiveOS/home.img ]; then +if ! strstr "`cat /proc/cmdline`" nopersisthome -a [ -e /mnt/live/LiveOS/home.img ] ; then homeloop=`losetup -f` mount -o remount,rw /mnt/live losetup $homeloop /mnt/live/LiveOS/home.img
commit 8b08198556821a5cd2a35904494a0bd31c053a14 Author: Jeremy Katz katzj@redhat.com Date: Mon Jun 2 15:45:03 2008 -0400
Initial support for a persistent /home (#445218)
In addition to having a persistent overlay, it can be useful to just have an encrypted /home. This provides the beginning of that support with the creation of LiveOS/home.img in livecd-iso-to-disk.sh, which is encrypted by default.
Future things still to do: * Command line argument 'nopersisthome' should not mount the persistent /home * Support for specifying something other than /mnt/live/LiveOS/home.img as the source of the persistent /home * Support not blowing away the home.img on later livecd-iso-to-disk runs * Make the boot process a little bit more clear about what's going on (eg, unlocking /dev/loop5 isn't all that obvious) * How best to update the OS on the usb stick?
diff --git a/config/livecd-fedora-base-desktop.ks b/config/livecd-fedora-base-desktop.ks index ebe9ac8..5ab5560 100644 --- a/config/livecd-fedora-base-desktop.ks +++ b/config/livecd-fedora-base-desktop.ks @@ -100,8 +100,22 @@ if ! strstr "`cat /proc/cmdline`" noswap -a [ -n "$swaps" ] ; then done fi
+# if we have a persistent /home, then we want to go ahead and mount it +if [ -e /mnt/live/LiveOS/home.img ]; then + homeloop=`losetup -f` + mount -o remount,rw /mnt/live + losetup $homeloop /mnt/live/LiveOS/home.img + if [ "$(/lib/udev/vol_id -t $homeloop)" = "crypto_LUKS" ]; then + cryptsetup luksOpen $homeloop EncHome <&1 + homeloop=/dev/mapper/EncHome + fi + mount $homeloop /home + [ -x /sbin/restorecon ] && /sbin/restorecon /home + if [ -d /home/fedora ]; then USERADDARGS="-M" ; fi +fi + # add fedora user with no passwd -useradd -c "Fedora Live" fedora +useradd $USERADDARGS -c "Fedora Live" fedora passwd -d fedora > /dev/null
# turn off firstboot for livecd boots diff --git a/tools/livecd-iso-to-disk.sh b/tools/livecd-iso-to-disk.sh index 3e1979b..9bdcb0e 100644 --- a/tools/livecd-iso-to-disk.sh +++ b/tools/livecd-iso-to-disk.sh @@ -22,7 +22,7 @@ export PATH=/sbin:/usr/sbin:$PATH
usage() { - echo "$0 [--reset-mbr] [--noverify] [--overlay-size-mb <size>] <isopath> <usbstick device>" + echo "$0 [--reset-mbr] [--noverify] [--overlay-size-mb <size>] [--home-size-mb <size> ] [ --unencrypted-home] <isopath> <usbstick device>" exit 1 }
@@ -172,12 +172,23 @@ if [ $(id -u) != 0 ]; then exit 1 fi
+cryptedhome=1 while [ $# -gt 2 ]; do case $1 in --overlay-size-mb) overlaysizemb=$2 shift ;; + --home-size-mb) + homesizemb=$2 + shift + ;; + --crypted-home) + cryptedhome=1 + ;; + --unencrypted-home) + cryptedhome="" + ;; --noverify) noverify=1 ;; @@ -232,6 +243,14 @@ if [ -n "$overlaysizemb" -a "$USBFS" = "vfat" ]; then fi fi
+if [ -n "$homesizemb" -a "$USBFS" = "vfat" ]; then + if [ "$homesizemb" -gt 2047 ]; then + echo "Can't have a home overlay greater than 2048MB on VFAT" + exitclean + fi +fi + + # FIXME: would be better if we had better mountpoints CDMNT=$(mktemp -d /media/cdtmp.XXXXXX) mount -o loop,ro "$ISO" $CDMNT || exitclean @@ -254,10 +273,11 @@ fi livesize=$(du -s -B 1M $check | awk {'print $1;'}) free=$(df -B1M $USBDEV |tail -n 1 |awk {'print $4;'})
-if [ $(($overlaysizemb + $livesize)) -gt $(($free + $tbd)) ]; then +if [ $(($overlaysizemb + $homesizemb + $livesize)) -gt $(($free + $tbd)) ]; then echo "Unable to fit live image + overlay on available space on USB stick" echo "Size of live image: $livesize" - echo "Overlay size: $overlaysizemb" + [ -n "$overlaysizemb" ] && echo "Overlay size: $overlaysizemb" + [ -n "$homesizemb" ] && echo "Home overlay size: $homesizemb" echo "Available space: $(($free + $tbd))" exitclean fi @@ -307,6 +327,33 @@ if [ -n "$overlaysizemb" ]; then $USBMNT/$SYSLINUXPATH/isolinux.cfg fi
+if [ -n "$homesizemb" ]; then + echo "Initializing persistent /home" + HOMEFILE=home.img + if [ "$USBFS" = "vfat" ]; then + # vfat can't handle sparse files + dd if=/dev/zero of=$USBMNT/LiveOS/$HOMEFILE count=$homesizemb bs=1M + else + dd if=/dev/null of=$USBMNT/LiveOS/$HOMEFILE count=1 bs=1M seek=$homesizemb + fi + if [ -n "$cryptedhome" ]; then + loop=$(losetup -f) + losetup $loop $USBMNT/LiveOS/$HOMEFILE + echo "Encrypting persistent /home" + cryptsetup luksFormat -y -q $loop + echo "Please enter the password again to unlock the device" + cryptsetup luksOpen $loop EncHomeFoo + mke2fs -j /dev/mapper/EncHomeFoo + tune2fs -c0 -i0 -ouser_xattr,acl /dev/mapper/EncHomeFoo + cryptsetup luksClose EncHomeFoo + losetup -d $loop + else + echo "Formatting unencrypted /home" + mke2fs -F -j $USBMNT/LiveOS/$HOMEFILE + tune2fs -c0 -i0 -ouser_xattr,acl $USBMNT/LiveOS/$HOMEFILE + fi +fi + echo "Installing boot loader" if [ "$USBFS" = "vfat" -o "$USBFS" = "msdos" ]; then # syslinux expects the config to be named syslinux.cfg
livecd@lists.fedoraproject.org