[Fedora-livecd-list] 4 commits - imgcreate/kickstart.py imgcreate/live.py tools/livecd-iso-to-disk.sh

Jeremy Katz katzj at fedoraproject.org
Mon Jun 9 15:36:13 UTC 2008


 imgcreate/kickstart.py      |    2 
 imgcreate/live.py           |   94 ++++++++++++++++++++++++++++++-
 tools/livecd-iso-to-disk.sh |  132 ++++++++++++++++++++++++++++++++++++++------
 3 files changed, 208 insertions(+), 20 deletions(-)

New commits:
commit 680197140cb1da8c0916e3ae477374a4b7192902
Author: Jeremy Katz <katzj at redhat.com>
Date:   Mon Jun 9 11:24:37 2008 -0400

    Fix permissions on livecd-iso-to-disk

diff --git a/tools/livecd-iso-to-disk.sh b/tools/livecd-iso-to-disk.sh
old mode 100644
new mode 100755


commit cd884e132fff7516bf75ce197669ee081f8dfeaa
Author: Jeremy Katz <katzj at redhat.com>
Date:   Mon Jun 9 10:45:12 2008 -0400

    Fix wrong variable breaking using unencrypted passwords

diff --git a/imgcreate/kickstart.py b/imgcreate/kickstart.py
index 180cea2..39756b2 100644
--- a/imgcreate/kickstart.py
+++ b/imgcreate/kickstart.py
@@ -188,7 +188,7 @@ class RootPasswordConfig(KickstartConfig):
 
     def set_unencrypted(self, password):
         for p in ("/bin/echo", "/usr/bin/passwd"):
-            if not os.path.exists("%s/%s" %(self.chroot, p)):
+            if not os.path.exists("%s/%s" %(self.instroot, p)):
                 raise errors.KickstartError("Unable to set unencrypted password due to lack of %s" % p)
 
         p1 = subprocess.Popen(["/bin/echo", password],


commit 591abeb5b75f5dba93f01206a7eaa5e27cba1561
Author: Jeremy Katz <katzj at redhat.com>
Date:   Mon Jun 9 10:42:58 2008 -0400

    Support making a Fedora 9 usb stick for the Intel-based Macs
    
    We didn't set up the live image for EFI booting in Fedora 9, but all the
    pieces are there.  So add something that will work for the stock Fedora 9
    images

diff --git a/tools/livecd-iso-to-disk.sh b/tools/livecd-iso-to-disk.sh
index 7408d31..3fd2145 100644
--- a/tools/livecd-iso-to-disk.sh
+++ b/tools/livecd-iso-to-disk.sh
@@ -292,6 +292,7 @@ if [ -z "$noverify" ]; then
 fi
 
 # do some basic sanity checks.  
+checkFilesystem $USBDEV
 checkMounted $USBDEV
 if [ -z "$mactel" ]; then
   checkSyslinuxVersion
@@ -302,7 +303,6 @@ else
   [ -n "$resetmbr" ] && createGPTLayout $USBDEV
   checkGPT $USBDEV
 fi
-checkFilesystem $USBDEV
 
 
 if [ -n "$overlaysizemb" -a "$USBFS" = "vfat" ]; then
@@ -397,7 +397,36 @@ if [ -z "$mactel" ]; then
   cp $CDMNT/isolinux/* $USBMNT/$SYSLINUXPATH
   BOOTCONFIG=$USBMNT/$SYSLINUXPATH/isolinux.cfg
 else
-  cp $CDMNT/EFI/boot/* $USBMNT/EFI/boot
+  if [ -d $CDMNT/EFI/boot ]; then
+    cp $CDMNT/EFI/boot/* $USBMNT/EFI/boot
+  else
+    # whee!  this image wasn't made with grub.efi bits.  so we get to create
+    # them here.  isn't life grand?
+    cp $CDMNT/isolinux/* $USBMNT/EFI/boot
+    mount -o loop,ro -t squashfs $CDMNT/LiveOS/squashfs.img $CDMNT
+    mount -o loop,ro -t ext3 $CDMNT/LiveOS/ext3fs.img $CDMNT
+    cp $CDMNT/boot/efi/EFI/redhat/grub.efi $USBMNT/EFI/boot/boot.efi
+    cp $CDMNT/boot/grub/splash.xpm.gz $USBMNT/EFI/boot/splash.xpm.gz
+    if [ -d $CDMNT/lib64 ]; then efiarch="x64" ; else efiarch="ia32"; fi
+    umount $CDMNT
+    umount $CDMNT
+
+    # magic config...
+    cat > $USBMNT/EFI/boot/boot.conf <<EOF
+default=0
+splashimage=/EFI/boot/splash.xpm.gz
+timeout 10
+hiddenmenu
+
+title Live
+  kernel /EFI/boot/vmlinuz0 root=CDLABEL=live rootfstype=iso9660 ro quiet liveimg
+  initrd /EFI/boot/initrd0.img
+EOF
+
+    cp $USBMNT/EFI/boot/boot.conf $USBMNT/EFI/boot/boot${efiarch}.conf
+    cp $USBMNT/EFI/boot/boot.efi $USBMNT/EFI/boot/boot${efiarch}.efi
+  fi
+
   # this is a little ugly, but it gets the "interesting" named config file
   BOOTCONFIG=$USBMNT/EFI/boot/boot?*.conf
 fi


commit ceb818924b458b273293b17dd54b482b4581b528
Author: Jeremy Katz <katzj at redhat.com>
Date:   Thu Jun 5 21:04:40 2008 -0400

    Add support for booting Intel Macs via EFI on USB (#450193)
    
    Intel Macs require an EFI setup for booting off of USB, so add support
    to the creator and iso-to-disk for handling this.  Main components are
    *) Adding EFI grub bits to the image
    *) Creating a grub.conf in addition to the syslinux config
    *) Doing the appropriate munging when copying over
    
    NOTE: The first time you create a bootable USB stick for a Mac, it will be
    a destructive operation due to the need to switch from msdos -> gpt

diff --git a/imgcreate/live.py b/imgcreate/live.py
index ef07d19..1c54cf6 100644
--- a/imgcreate/live.py
+++ b/imgcreate/live.py
@@ -325,7 +325,7 @@ class x86LiveImageCreator(LiveImageCreatorBase):
 
             shutil.copy(path, isodir + "/isolinux/")
 
-    def __copy_background(self, isodest):
+    def __copy_syslinux_background(self, isodest):
         background_path = self._instroot + \
                           "/usr/lib/anaconda-runtime/syslinux-vesa-splash.jpg"
 
@@ -469,7 +469,7 @@ menu hiddenrow 5
   localboot 0xffff
 """
 
-    def _configure_bootloader(self, isodir):
+    def _configure_syslinux_bootloader(self, isodir):
         """configure the boot loader"""
         makedirs(isodir + "/isolinux")
 
@@ -479,7 +479,7 @@ menu hiddenrow 5
                                    self.__find_syslinux_mboot())
 
         background = ""
-        if self.__copy_background(isodir + "/isolinux/splash.jpg"):
+        if self.__copy_syslinux_background(isodir + "/isolinux/splash.jpg"):
             background = "menu background splash.jpg"
 
         cfg = self.__get_basic_syslinux_config(menu = menu,
@@ -496,6 +496,94 @@ menu hiddenrow 5
         cfgf.write(cfg)
         cfgf.close()
 
+    def __copy_efi_files(self, isodir):
+        if not os.path.exists(self._instroot + "/boot/efi/EFI/redhat/grub.efi"):
+            return False
+        shutil.copy(self._instroot + "/boot/efi/EFI/redhat/grub.efi",
+                    isodir + "/EFI/boot/grub.efi")
+        shutil.copy(self._instroot + "/boot/grub/splash.xpm.gz",
+                    isodir + "/EFI/boot/splash.xpm.gz")
+
+        return True
+
+    def __get_basic_efi_config(self, **args):
+        return """
+default=0
+splashimage=/EFI/boot/splash.xpm.gz
+timeout %(timeout)d
+hiddenmenu
+
+""" %args
+
+    def __get_efi_image_stanza(self, **args):
+        return """title %(long)s
+  kernel /EFI/boot/vmlinuz%(index)s root=CDLABEL=%(fslabel)s rootfstype=iso9660 %(liveargs)s %(extra)s
+  initrd /EFI/boot/initrd%(index)s.img
+""" %args
+
+    def __get_efi_image_stanzas(self, isodir, name):
+        # FIXME: this only supports one kernel right now...
+
+        kernel_options = self._get_kernel_options()
+        checkisomd5 = self._has_checkisomd5()
+
+        cfg = ""
+
+        for index in range(0, 9):
+            # we don't support xen kernels
+            if os.path.exists("%s/EFI/boot/xen%d.gz" %(isodir, index)):
+                continue
+            cfg += self.__get_efi_image_stanza(fslabel = self.fslabel,
+                                               liveargs = kernel_options,
+                                               long = name,
+                                               extra = "", index = index)
+            if checkisomd5:
+                cfg += self.__get_efi_image_stanza(fslabel = self.fslabel,
+                                                   liveargs = kernel_options,
+                                                   long = "Verify and Boot " + name,
+                                                   extra = "check",
+                                                   index = index)
+            break
+
+        return cfg
+
+    def _configure_efi_bootloader(self, isodir):
+        """Set up the configuration for an EFI bootloader"""
+        makedirs(isodir + "/EFI/boot")
+
+        if not self.__copy_efi_files(isodir):
+            shutil.rmtree(isodir + "/EFI")
+            return
+
+        for f in os.listdir(isodir + "/isolinux"):
+            os.link("%s/isolinux/%s" %(isodir, f),
+                    "%s/EFI/boot/%s" %(isodir, f))
+
+
+        cfg = self.__get_basic_efi_config(name = self.name,
+                                          timeout = self._timeout)
+        cfg += self.__get_efi_image_stanzas(isodir, self.name)
+
+        cfgf = open(isodir + "/EFI/boot/grub.conf", "w")
+        cfgf.write(cfg)
+        cfgf.close()
+
+        # first gen mactel machines get the bootloader name wrong apparently
+        if rpmUtils.arch.getBaseArch() == "i386":
+            os.link(isodir + "/EFI/boot/grub.efi", isodir + "/EFI/boot/boot.efi")
+            os.link(isodir + "/EFI/boot/grub.conf", isodir + "/EFI/boot/boot.conf")
+
+        # for most things, we want them named boot$efiarch
+        efiarch = {"i386": "ia32", "x86_64": "x64"}
+        efiname = efiarch[rpmUtils.arch.getBaseArch()]
+        os.rename(isodir + "/EFI/boot/grub.efi", isodir + "/EFI/boot/boot%s.efi" %(efiname,))
+        os.link(isodir + "/EFI/boot/grub.conf", isodir + "/EFI/boot/boot%s.conf" %(efiname,))
+
+
+    def _configure_bootloader(self, isodir):
+        self._configure_syslinux_bootloader(isodir)
+        self._configure_efi_bootloader(isodir)
+
 class ppcLiveImageCreator(LiveImageCreatorBase):
     def _get_mkisofs_options(self, isodir):
         return [ "-hfs", "-nodesktop", "-part"
diff --git a/tools/livecd-iso-to-disk.sh b/tools/livecd-iso-to-disk.sh
index 7468cbb..7408d31 100644
--- a/tools/livecd-iso-to-disk.sh
+++ b/tools/livecd-iso-to-disk.sh
@@ -57,6 +57,9 @@ getdisk() {
     fi
 
     device="/dev/$device"
+    # FIXME: weird dev names could mess this up I guess
+    p=/dev/`basename $p`
+    partnum=${p##$device}
 }
 
 resetMBR() {
@@ -115,6 +118,51 @@ checkPartActive() {
     fi
 }
 
+createGPTLayout() {
+    dev=$1
+    getdisk $dev
+
+    echo "WARNING: THIS WILL DESTROY ANY DATA ON $device!!!"
+    echo "Press Enter to continue or ctrl-c to abort"
+    read
+
+    /sbin/parted --script $device mklabel gpt
+    partinfo=$(/sbin/parted --script -m $device "unit b print" |grep ^$device:)
+    size=$(echo $partinfo |cut -d : -f 2 |sed -e 's/B$//')
+    /sbin/parted --script $device unit b mkpart '"EFI System Partition"' fat32 17408 $(($size - 17408)) set 1 boot on
+    USBDEV=${device}1
+    /sbin/udevsettle
+    /sbin/mkdosfs -n LIVE $USBDEV
+}
+
+checkGPT() {
+    dev=$1
+    getdisk $dev
+
+    if [ "$(/sbin/fdisk -l $device 2>/dev/null |grep -c GPT)" -eq "0" ]; then
+       echo "EFI boot requires a GPT partition table."
+       echo "This can be done manually or you can run with --reset-mbr"
+       exitclean
+    fi
+
+    partinfo=$(/sbin/parted --script -m $device "print" |grep ^$partnum:)
+    volname=$(echo $partinfo |cut -d : -f 6)
+    flags=$(echo $partinfo |cut -d : -f 7)
+    if [ "$volname" != "EFI System Partition" ]; then
+	echo "Partition name must be 'EFI System Partition'"
+	echo "This can be set in parted or you can run with --reset-mbr"
+	exitclean
+    fi
+    if [ "$(echo $flags |grep -c boot)" = "0" ]; then
+	echo "Partition isn't marked bootable!"
+	echo "You can mark the partition as bootable with "
+        echo "    # /sbin/parted $device"
+	echo "    (parted) toggle N boot"
+	echo "    (parted) quit"
+	exitclean
+    fi
+}
+
 checkFilesystem() {
     dev=$1
 
@@ -141,6 +189,10 @@ checkFilesystem() {
 	    exitclean
 	fi
     fi
+
+    if [ "$USBFS" = "vfat" -o "$USBFS" = "msdos" ]; then
+	mountopts="-o shortname=winnt,umask=0077"
+    fi
 }
 
 checkSyslinuxVersion() {
@@ -199,6 +251,9 @@ while [ $# -gt 2 ]; do
 	--reset-mbr|--resetmbr)
 	    resetmbr=1
 	    ;;
+	--mactel)
+	    mactel=1
+	    ;;
         --extra-kernel-args)
             kernelargs=$2
             shift
@@ -237,12 +292,18 @@ if [ -z "$noverify" ]; then
 fi
 
 # do some basic sanity checks.  
-checkSyslinuxVersion 
-checkFilesystem $USBDEV
-checkPartActive $USBDEV
-checkMBR $USBDEV
 checkMounted $USBDEV
-[ -n $resetmbr ] && resetMBR $USBDEV
+if [ -z "$mactel" ]; then
+  checkSyslinuxVersion
+  checkPartActive $USBDEV
+  [ -n "$resetmbr" ] && resetMBR $USBDEV
+  checkMBR $USBDEV
+else
+  [ -n "$resetmbr" ] && createGPTLayout $USBDEV
+  checkGPT $USBDEV
+fi
+checkFilesystem $USBDEV
+
 
 if [ -n "$overlaysizemb" -a "$USBFS" = "vfat" ]; then
   if [ "$overlaysizemb" -gt 2047 ]; then
@@ -262,7 +323,7 @@ fi
 CDMNT=$(mktemp -d /media/cdtmp.XXXXXX)
 mount -o loop,ro "$ISO" $CDMNT || exitclean
 USBMNT=$(mktemp -d /media/usbdev.XXXXXX)
-mount $USBDEV $USBMNT || exitclean
+mount $mountopts $USBDEV $USBMNT || exitclean
 
 trap exitclean SIGINT SIGTERM
 
@@ -314,9 +375,10 @@ if [ -d $USBMNT/LiveOS ]; then
 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
+[ -z "$mactel" -a ! -d $USBMNT/$SYSLINUXPATH ] && mkdir -p $USBMNT/$SYSLINUXPATH
+[ -n "$mactel" -a ! -d $USBMNT/EFI/boot ] && mkdir -p $USBMNT/EFI/boot
+[ ! -d $USBMNT/LiveOS ] && mkdir $USBMNT/LiveOS
+[ -n "$keephome" -a -f "$USBMNT/home.img" ] && mv $USBMNT/home.img $USBMNT/LiveOS/home.img
 # 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
@@ -331,12 +393,19 @@ if [ -f $CDMNT/LiveOS/osmin.img ]; then
     cp $CDMNT/LiveOS/osmin.img $USBMNT/LiveOS/osmin.img || exitclean
 fi
 
-cp $CDMNT/isolinux/* $USBMNT/$SYSLINUXPATH
+if [ -z "$mactel" ]; then
+  cp $CDMNT/isolinux/* $USBMNT/$SYSLINUXPATH
+  BOOTCONFIG=$USBMNT/$SYSLINUXPATH/isolinux.cfg
+else
+  cp $CDMNT/EFI/boot/* $USBMNT/EFI/boot
+  # this is a little ugly, but it gets the "interesting" named config file
+  BOOTCONFIG=$USBMNT/EFI/boot/boot?*.conf
+fi
 
 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
+sed -i -e "s/CDLABEL=[^ ]*/$USBLABEL/" -e "s/rootfstype=[^ ]*/rootfstype=$USBFS/" $BOOTCONFIG
+if [ -n "$kernelargs" ]; then sed -i -e "s/liveimg/liveimg ${kernelargs}/" $BOOTCONFIG.cfg ; fi
 
 if [ -n "$overlaysizemb" ]; then
     echo "Initializing persistent overlay file"
@@ -347,10 +416,8 @@ if [ -n "$overlaysizemb" ]; then
     else
 	dd if=/dev/null of=$USBMNT/LiveOS/$OVERFILE count=1 bs=1M seek=$overlaysizemb
     fi
-    sed -i -e "s/liveimg/liveimg overlay=${USBLABEL}/" \
-	$USBMNT/$SYSLINUXPATH/isolinux.cfg
-    sed -i -e "s/\ ro\ /\ rw\ /" \
-	$USBMNT/$SYSLINUXPATH/isolinux.cfg
+    sed -i -e "s/liveimg/liveimg overlay=${USBLABEL}/" $BOOTCONFIG
+    sed -i -e "s/\ ro\ /\ rw\ /" $BOOTCONFIG
 fi
 
 if [ -n "$homesizemb" ]; then
@@ -381,7 +448,11 @@ if [ -n "$homesizemb" ]; then
 fi
 
 echo "Installing boot loader"
-if [ "$USBFS" = "vfat" -o "$USBFS" = "msdos" ]; then
+if [ -n "$mactel" ]; then
+    # replace the ia32 hack
+    if [ -f "$USBMNT/EFI/boot/boot.conf" ]; then cp -f $USBMNT/EFI/boot/bootia32.conf $USBMNT/EFI/boot/boot.conf ; fi
+    cleanup
+elif [ "$USBFS" = "vfat" -o "$USBFS" = "msdos" ]; then
     # syslinux expects the config to be named syslinux.cfg 
     # and has to run with the file system unmounted
     mv $USBMNT/$SYSLINUXPATH/isolinux.cfg $USBMNT/$SYSLINUXPATH/syslinux.cfg





More information about the Fedora-livecd-list mailing list