From e48e63b61c2c409757a2d4180255f903f1a7296a Mon Sep 17 00:00:00 2001 From: Juan RP Date: Fri, 6 Jul 2012 15:29:12 +0200 Subject: Revamped to support EFI booting via grub2. --- Makefile | 11 +++- README | 13 +++- grub/grub.cfg | 15 +++++ grub/grub_void.cfg.in | 36 +++++++++++ isolinux/isolinux.cfg.in | 31 ++++++++++ mklive.sh.in | 152 +++++++++++++++++++++++++---------------------- 6 files changed, 182 insertions(+), 76 deletions(-) create mode 100644 grub/grub.cfg create mode 100644 grub/grub_void.cfg.in create mode 100644 isolinux/isolinux.cfg.in diff --git a/Makefile b/Makefile index 20cbeaa..05ed4e0 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,8 @@ -VERSION = 0.9.7 -SBINDIR ?= /usr/sbin -DRACUTMODDIR ?= /usr/lib/dracut/modules.d/01vmklive +VERSION = 0.9.8 +PREFIX ?= /usr/local +SBINDIR ?= $(PREFIX)/sbin +SHAREDIR ?= $(PREFIX)/share +DRACUTMODDIR ?= $(PREFIX)/lib/dracut/modules.d/01vmklive all: sed -e "s|@@MKLIVE_VERSION@@|${VERSION}|g" mklive.sh.in > mklive.sh @@ -10,6 +12,9 @@ install: all install -m755 mklive.sh $(DESTDIR)$(SBINDIR)/void-mklive install -d $(DESTDIR)$(DRACUTMODDIR) install -m755 dracut/*.sh $(DESTDIR)$(DRACUTMODDIR) + install -d $(DESTDIR)$(SHAREDIR)/void-mklive + install -m644 grub/*.cfg* $(DESTDIR)$(SHAREDIR)/void-mklive + install -m644 isolinux/*.cfg* $(DESTDIR)$(SHAREDIR)/void-mklive clean: -rm -f mklive.sh diff --git a/README b/README index b1272b6..b366104 100644 --- a/README +++ b/README @@ -4,6 +4,18 @@ This is a simple shell script to build a live image for the Void linux distribution. The images contain the void-installer package to be able to install Void linux to storage disks. +The generated image can be booted from BIOS and EFI systems (dual boot). +For BIOS isolinux is used and for EFI we use grub2. + +Dependencies: + - dracut + - grub with support for PC-BIOS and x86_64 EFI + - syslinux + - dosfstools (for mkfs.vfat) + - xorriso + - squashfs-tools + - void-installer + Usage: void-mklive [options] Options: @@ -12,7 +24,6 @@ Options: -k version Kernel version to use. -o outfile Output file name for the ISO image. -s splash Splash image file for isolinux. - -v volname ISO Volume name. * If -k not specified it will use $(uname -r) by default. * The first time it is executed a config file will be created (~/mklive.conf). diff --git a/grub/grub.cfg b/grub/grub.cfg new file mode 100644 index 0000000..c5ab087 --- /dev/null +++ b/grub/grub.cfg @@ -0,0 +1,15 @@ +insmod usbms +insmod usb_keyboard +insmod part_gpt +insmod part_msdos +insmod fat +insmod iso9660 +insmod udf +insmod ext2 +insmod reiserfs +insmod ntfs +insmod hfsplus +insmod linux +insmod chain +search --file --no-floppy --set=voidlive "/boot/grub/grub_void.cfg" +source "(${voidlive})/boot/grub/grub_void.cfg" diff --git a/grub/grub_void.cfg.in b/grub/grub_void.cfg.in new file mode 100644 index 0000000..8a31263 --- /dev/null +++ b/grub/grub_void.cfg.in @@ -0,0 +1,36 @@ + +set pager="1" +set locale_dir="(${voidlive})/boot/grub/locale" + +if [ -e "${prefix}/${grub_cpu}-${grub_platform}/all_video.mod" ]; then + insmod all_video +else + insmod efi_gop + insmod efi_uga + insmod video_bochs + insmod video_cirrus +fi + +insmod font + +if loadfont "(${voidlive}/boot/grub/fonts/unicode.pf2" ; then + insmod gfxterm + set gfxmode="auto" + + terminal_input console + terminal_output gfxterm + + insmod png + background_image "(${voidlive})/boot/isolinux/@@SPLASHIMAGE@@" +fi + +if [ cpuid -l ]; then + menuentry "Void GNU/Linux @@KERNVER@@ (@@ARCH@@)" { + set gfxpayload="keep" + linux (${voidlive})/boot/vmlinuz \ + root=live:CDLABEL=VOID_LIVE ro rootfstype=auto liveimg \ + rd.luks=0 rd.md=0 rd.dm=0 loglevel=4 gpt add_efi_memmap \ + vconsole.keymap=@@KEYMAP@@ vconsole.unicode=1 locale.LANG=@@LOCALE@@ + initrd (${voidlive})/boot/initrd.lz + } +fi diff --git a/isolinux/isolinux.cfg.in b/isolinux/isolinux.cfg.in new file mode 100644 index 0000000..c5051fd --- /dev/null +++ b/isolinux/isolinux.cfg.in @@ -0,0 +1,31 @@ +UI vesamenu.c32 +PROMPT 0 +TIMEOUT 100 +ONTIMEOUT linux + +MENU TABMSG Press ENTER to boot or TAB to edit a menu entry +MENU AUTOBOOT BIOS default device boot in # second{,s}... +MENU BACKGROUND @@SPLASHIMAGE@@ +MENU WIDTH 78 +MENU MARGIN 1 +MENU ROWS 4 +MENU VSHIFT 2 +MENU TIMEOUTROW 8 +MENU TABMSGROW 2 +MENU CMDLINEROW 11 +MENU HELPMSGROW 16 +MENU HELPMSGENDROW 29 + +MENU COLOR title * #FF5255FF * +MENU COLOR border * #00000000 #00000000 none +MENU COLOR sel * #ffffffff #FF5255FF * + +LABEL linux +MENU LABEL Boot Void GNU/Linux @@KERNVER@@ @@ARCH@@ +KERNEL /boot/vmlinuz +APPEND initrd=/boot/initrd.lz root=live:CDLABEL=VOID_LIVE rootfstype=auto ro \ + liveimg rd.luks=0 rd.md=0 rd.dm=0 loglevel=4 vconsole.keymap=@@KEYMAP@@ \ + vconsole.unicode=1 locale.LANG=@@LOCALE@@ +LABEL c +MENU LABEL Boot first HD found by BIOS +LOCALBOOT 0x80 diff --git a/mklive.sh.in b/mklive.sh.in index c16495e..9e31155 100644 --- a/mklive.sh.in +++ b/mklive.sh.in @@ -88,48 +88,6 @@ and follow the on-screen instructions. Thanks for trying Void Linux. _EOF } -write_default_isolinux_conf() { - local kver="$1" - - if [ -r "$SPLASH_IMAGE" ]; then - BACKGROUND="MENU BACKGROUND $(basename $SPLASH_IMAGE)" - fi - - cat >> "$ISOLINUX_CFG" << _EOF -UI vesamenu.c32 -PROMPT 0 -TIMEOUT 100 -ONTIMEOUT linux - -MENU TABMSG Press ENTER to boot or TAB to edit a menu entry -MENU AUTOBOOT BIOS default device boot in # second{,s}... -$BACKGROUND -MENU WIDTH 78 -MENU MARGIN 1 -MENU ROWS 4 -MENU VSHIFT 2 -MENU TIMEOUTROW 8 -MENU TABMSGROW 2 -MENU CMDLINEROW 11 -MENU HELPMSGROW 16 -MENU HELPMSGENDROW 29 - -MENU COLOR title * #FF5255FF * -MENU COLOR border * #00000000 #00000000 none -MENU COLOR sel * #ffffffff #FF5255FF * - -LABEL linux -MENU LABEL Boot Void GNU/Linux ${kver} ($(uname -m)) -KERNEL vmlinuz -APPEND initrd=initrd.lz root=live:CDLABEL=VoidLinux-live-$(uname -m)-${kver} \ - rootfstype=auto ro liveimg rd.luks=0 rd.md=0 rd.dm=0 loglevel=4 \ - vconsole.keymap=${KEYMAP} vconsole.unicode=1 locale.LANG=${LOCALE} -LABEL c -MENU LABEL Boot first HD found by BIOS -LOCALBOOT 0x80 -_EOF -} - write_conf_file() { cat > "$1" <<_EOF # *-*- sh -*-* @@ -171,7 +129,6 @@ Options: -k version Kernel version to use. -o outfile Output file name for the ISO image. -s splash Splash image file for isolinux. - -v volname ISO Volume name. _EOF exit 1 } @@ -179,14 +136,13 @@ _EOF # # main() # -while getopts "C:c:k:o:s:v:h" opt; do +while getopts "C:c:k:o:s:h" opt; do case $opt in C) CONFIG_FILE="$OPTARG";; c) COMPRESSTYPE="$OPTARG";; k) KERNELVERSION="$OPTARG";; o) OUTPUT_FILE="$OPTARG";; s) SPLASH_IMAGE="$OPTARG";; - v) ISO_VOLUME="$OPTARG";; h) usage;; esac done @@ -205,12 +161,15 @@ if [ -z "$OUTPUT_FILE" ]; then fi LOGFILE="$(mktemp -t vmklive-XXXXXXXXXX.log)" -if [ -z "$ISO_VOLUME" ]; then - ISO_VOLUME="VoidLinux-live-$(uname -m)-${KERNELVERSION}" -fi if [ -z "$SYSLINUX_DATADIR" ]; then SYSLINUX_DATADIR=/usr/share/syslinux fi +if [ -z "$GRUB_DATADIR" ]; then + GRUB_DATADIR=/usr/share/grub +fi +if [ -z "$MKLIVE_DATADIR" ]; then + MKLIVE_DATADIR=/usr/share/void-mklive +fi if [ -z "$SPLASH_IMAGE" ]; then SPLASH_IMAGE=/usr/share/void-artwork/splash.png fi @@ -251,10 +210,13 @@ if [ "$(id -u)" -ne 0 ]; then exit 1 fi +ISO_VOLUME="VOID_LIVE" BUILDDIR=$(mktemp --tmpdir=$HOME -d) || exit 1 BUILDDIR=$(readlink -f $BUILDDIR) ROOTFS="$BUILDDIR/rootfs" -ISOLINUX_DIR="$BUILDDIR/isolinux" +BOOT_DIR="$BUILDDIR/boot" +ISOLINUX_DIR="$BOOT_DIR/isolinux" +GRUB_DIR="$BOOT_DIR/grub" ISOLINUX_CFG="$ISOLINUX_DIR/isolinux.cfg" # @@ -270,8 +232,7 @@ fi # Mount pseudofs in the target rootfs. # mount_pseudofs -mkdir -p "$ROOTFS/tmp" -mkdir -p "$ISOLINUX_DIR" +mkdir -p "$ROOTFS/tmp" "$ISOLINUX_DIR" "$GRUB_DIR" XBPS_ARGS="-r $ROOTFS -y" if [ -n "$REPOSITORY_CACHE" ]; then @@ -284,7 +245,7 @@ case $XBPS_VERSION in esac info_msg "Redirecting stdout/stderr to $LOGFILE ..." -info_msg "[1/9] Installing packages into the rootfs..." +info_msg "[1/10] Installing packages into the rootfs..." for f in ${PACKAGE_LIST}; do info_msg " $f" done @@ -307,22 +268,22 @@ ${XBPS_BIN_CMD} -r "$ROOTFS" list > \ # # Prepare /etc/motd. # -info_msg "[2/9] Creating /etc/motd..." +info_msg "[2/10] Creating /etc/motd..." mkdir -p "$ROOTFS"/etc write_etc_motd # # Create the initramfs with XZ compression. # -info_msg "[3/9] Creating initramfs image ($COMPRESSTYPE)..." +info_msg "[3/10] Creating initramfs image ($COMPRESSTYPE)..." dracut --no-hostonly --add "dmsquash-live vmklive" --${COMPRESSTYPE} \ - "${ISOLINUX_DIR}/initrd.lz" ${KERNELVERSION} 2>/dev/null || error_out + "${BOOT_DIR}/initrd.lz" ${KERNELVERSION} 2>/dev/null || error_out # # Copy the linux image to the target directory. # -info_msg "[4/9] Copying kernel image/modules..." -cp -f /boot/vmlinuz-${KERNELVERSION} "${ISOLINUX_DIR}/vmlinuz" || error_out $? +info_msg "[4/10] Copying kernel image/modules..." +cp -f /boot/vmlinuz-${KERNELVERSION} "${BOOT_DIR}/vmlinuz" || error_out $? mkdir -p "$ROOTFS/lib/modules" cp -a /lib/modules/${KERNELVERSION} "$ROOTFS/lib/modules" || error_out $? @@ -404,20 +365,60 @@ install -Dm755 /bin/mount "$ROOTFS/bin/mount" || error_out $? umount_pseudofs # -# Copy required isolinux files in the target rootfs. +# Prepare isolinux files in the target rootfs. # -info_msg "[5/9] Copying isolinux files..." -cp -f $SYSLINUX_DATADIR/isolinux.bin "$ISOLINUX_DIR" -cp -f $SYSLINUX_DATADIR/vesamenu.c32 "$ISOLINUX_DIR" -write_default_isolinux_conf ${KERNELVERSION} +info_msg "[5/10] Preparing isolinux support for BIOS..." +cp -f $SYSLINUX_DATADIR/isolinux.bin "$ISOLINUX_DIR" || error_out $? +cp -f $SYSLINUX_DATADIR/vesamenu.c32 "$ISOLINUX_DIR" || error_out $? +cp -f $MKLIVE_DATADIR/isolinux.cfg.in \ + "$ISOLINUX_DIR"/isolinux.cfg || error_out $? + if [ -f "$SPLASH_IMAGE" ]; then - cp -f $SPLASH_IMAGE "$ISOLINUX_DIR" + cp -f $SPLASH_IMAGE "$ISOLINUX_DIR" || error_out $? fi +sed -i -e "s|@@SPLASHIMAGE@@|$(basename $SPLASH_IMAGE)|" \ + -e "s|@@KERNVER@@|${KERNELVERSION}|" \ + -e "s|@@KEYMAP@@|${KEYMAP}|" \ + -e "s|@@LOCALE@@|${LOCALE}|" $ISOLINUX_DIR/isolinux.cfg + +# +# Prepare grub files for EFI. +# +info_msg "[6/10] Preparing GRUB support for EFI..." +cp -f $MKLIVE_DATADIR/grub.cfg $GRUB_DIR || error_out $? +cp -f $MKLIVE_DATADIR/grub_void.cfg.in $GRUB_DIR/grub_void.cfg || error_out $? +sed -i -e "s|@@SPLASHIMAGE@@|$(basename $SPLASH_IMAGE)|" \ + -e "s|@@KERNVER@@|${KERNELVERSION}|" \ + -e "s|@@KEYMAP@@|${KEYMAP}|" \ + -e "s|@@LOCALE@@|${LOCALE}|" $GRUB_DIR/grub_void.cfg +mkdir -p $GRUB_DIR/fonts $GRUB_DIR/locale || error_out $? +cp -f $GRUB_DATADIR/unicode.pf2 $GRUB_DIR/fonts || error_out $? +cp -f /boot/grub/locale/* $GRUB_DIR/locale || error_out $? + +# Create EFI vfat image. +dd if=/dev/zero of=$GRUB_DIR/efiboot.img bs=1024 count=4096 \ + 2>&1 | cat >>$LOGFILE || error_out $? +mkfs.vfat -F12 -S 512 -n "grub_uefi" "$GRUB_DIR/efiboot.img" \ + 2>&1 | cat >>$LOGFILE || error_out $? + +GRUB_EFI_TMPDIR="$(mktemp --tmpdir=$HOME -d)" +LOOP_DEVICE="$(losetup --show --find ${GRUB_DIR}/efiboot.img)" +mount -o rw,flush -t vfat "${LOOP_DEVICE}" "${GRUB_EFI_TMPDIR}" \ + 2>&1 | cat >>$LOGFILE || error_out $? + +mkdir -p "${GRUB_EFI_TMPDIR}/EFI/boot/" || error_out $? +cd "$BUILDDIR" || error_out $? +grub-mkstandalone --directory="/usr/lib/grub/x86_64-efi" --format="x86_64-efi" \ + --compression="xz" --output="${GRUB_EFI_TMPDIR}/EFI/boot/bootx64.efi" \ + "boot/grub/grub.cfg" 2>&1 | cat >>$LOGFILE || error_out $? +umount "$GRUB_EFI_TMPDIR" || error_out $? +losetup --detach "${LOOP_DEVICE}" || error_out $? +rm -rf $GRUB_EFI_TMPDIR || error_out $? # # Prepare the squashed rootfs image. # -info_msg "[6/9] Creating squashfs image ($COMPRESSTYPE) from rootfs..." +info_msg "[7/10] Creating squashfs image ($COMPRESSTYPE) from rootfs..." # Find out required size for the rootfs and create an ext3fs image off it. ROOTFS_SIZE=$(du -sk "$ROOTFS"|awk '{print $1}') mkdir -p "$BUILDDIR/tmp/LiveOS" @@ -435,19 +436,26 @@ mksquashfs "$BUILDDIR/tmp" "$BUILDDIR/LiveOS/squashfs.img" \ -comp ${COMPRESSTYPE} 2>&1 | cat >> $LOGFILE || error_out chmod 444 "$BUILDDIR/LiveOS/squashfs.img" || error_out $? -info_msg "[7/9] Removing rootfs directory..." +info_msg "[8/9] Removing rootfs directory..." rm -rf "$ROOTFS" "$BUILDDIR/tmp-rootfs" "$BUILDDIR/tmp" || error_out $? # # Prepare the ISO image. # -info_msg "[8/9] Building ISO image..." -mkisofs -J -r -V "$ISO_VOLUME" -b isolinux/isolinux.bin \ - -c isolinux/boot.cat -no-emul-boot \ - -boot-load-size 4 -boot-info-table \ - -o "$OUTPUT_FILE" "$BUILDDIR" 2>&1 | cat >>$LOGFILE || error_out $? - -info_msg "[9/9] Removing build directory..." +info_msg "[9/10] Building ISO image..." +xorriso -as mkisofs \ + -iso-level 3 -rock -joliet \ + -max-iso9660-filenames -omit-period \ + -omit-version-number -relaxed-filenames -allow-lowercase \ + -volid "VOID_LIVE" \ + -eltorito-boot boot/isolinux/isolinux.bin \ + -eltorito-catalog boot/isolinux/boot.cat \ + -no-emul-boot -boot-load-size 4 -boot-info-table \ + -eltorito-alt-boot --efi-boot boot/grub/efiboot.img -no-emul-boot \ + -isohybrid-mbr /usr/share/syslinux/isohdpfx.bin \ + -output "$OUTPUT_FILE" "$BUILDDIR" 2>&1 | cat >>$LOGFILE || error_out $? + +info_msg "[10/10] Removing build directory..." rm -rf "$BUILDDIR" || error_out $? hsize=$(du -sh "$OUTPUT_FILE"|awk '{print $1}') -- cgit 1.4.1