Revamped to support EFI booting via grub2.

This commit is contained in:
Juan RP 2012-07-06 15:29:12 +02:00
parent bfbaa4a63b
commit e48e63b61c
6 changed files with 181 additions and 75 deletions

View File

@ -1,6 +1,8 @@
VERSION = 0.9.7 VERSION = 0.9.8
SBINDIR ?= /usr/sbin PREFIX ?= /usr/local
DRACUTMODDIR ?= /usr/lib/dracut/modules.d/01vmklive SBINDIR ?= $(PREFIX)/sbin
SHAREDIR ?= $(PREFIX)/share
DRACUTMODDIR ?= $(PREFIX)/lib/dracut/modules.d/01vmklive
all: all:
sed -e "s|@@MKLIVE_VERSION@@|${VERSION}|g" mklive.sh.in > mklive.sh 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 -m755 mklive.sh $(DESTDIR)$(SBINDIR)/void-mklive
install -d $(DESTDIR)$(DRACUTMODDIR) install -d $(DESTDIR)$(DRACUTMODDIR)
install -m755 dracut/*.sh $(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: clean:
-rm -f mklive.sh -rm -f mklive.sh

13
README
View File

@ -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 Void linux distribution. The images contain the void-installer package
to be able to install Void linux to storage disks. 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] Usage: void-mklive [options]
Options: Options:
@ -12,7 +24,6 @@ Options:
-k version Kernel version to use. -k version Kernel version to use.
-o outfile Output file name for the ISO image. -o outfile Output file name for the ISO image.
-s splash Splash image file for isolinux. -s splash Splash image file for isolinux.
-v volname ISO Volume name.
* If -k not specified it will use $(uname -r) by default. * 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). * The first time it is executed a config file will be created (~/mklive.conf).

15
grub/grub.cfg Normal file
View File

@ -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"

36
grub/grub_void.cfg.in Normal file
View File

@ -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

31
isolinux/isolinux.cfg.in Normal file
View File

@ -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

View File

@ -88,48 +88,6 @@ and follow the on-screen instructions. Thanks for trying Void Linux.
_EOF _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() { write_conf_file() {
cat > "$1" <<_EOF cat > "$1" <<_EOF
# *-*- sh -*-* # *-*- sh -*-*
@ -171,7 +129,6 @@ Options:
-k version Kernel version to use. -k version Kernel version to use.
-o outfile Output file name for the ISO image. -o outfile Output file name for the ISO image.
-s splash Splash image file for isolinux. -s splash Splash image file for isolinux.
-v volname ISO Volume name.
_EOF _EOF
exit 1 exit 1
} }
@ -179,14 +136,13 @@ _EOF
# #
# main() # 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 case $opt in
C) CONFIG_FILE="$OPTARG";; C) CONFIG_FILE="$OPTARG";;
c) COMPRESSTYPE="$OPTARG";; c) COMPRESSTYPE="$OPTARG";;
k) KERNELVERSION="$OPTARG";; k) KERNELVERSION="$OPTARG";;
o) OUTPUT_FILE="$OPTARG";; o) OUTPUT_FILE="$OPTARG";;
s) SPLASH_IMAGE="$OPTARG";; s) SPLASH_IMAGE="$OPTARG";;
v) ISO_VOLUME="$OPTARG";;
h) usage;; h) usage;;
esac esac
done done
@ -205,12 +161,15 @@ if [ -z "$OUTPUT_FILE" ]; then
fi fi
LOGFILE="$(mktemp -t vmklive-XXXXXXXXXX.log)" LOGFILE="$(mktemp -t vmklive-XXXXXXXXXX.log)"
if [ -z "$ISO_VOLUME" ]; then
ISO_VOLUME="VoidLinux-live-$(uname -m)-${KERNELVERSION}"
fi
if [ -z "$SYSLINUX_DATADIR" ]; then if [ -z "$SYSLINUX_DATADIR" ]; then
SYSLINUX_DATADIR=/usr/share/syslinux SYSLINUX_DATADIR=/usr/share/syslinux
fi 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 if [ -z "$SPLASH_IMAGE" ]; then
SPLASH_IMAGE=/usr/share/void-artwork/splash.png SPLASH_IMAGE=/usr/share/void-artwork/splash.png
fi fi
@ -251,10 +210,13 @@ if [ "$(id -u)" -ne 0 ]; then
exit 1 exit 1
fi fi
ISO_VOLUME="VOID_LIVE"
BUILDDIR=$(mktemp --tmpdir=$HOME -d) || exit 1 BUILDDIR=$(mktemp --tmpdir=$HOME -d) || exit 1
BUILDDIR=$(readlink -f $BUILDDIR) BUILDDIR=$(readlink -f $BUILDDIR)
ROOTFS="$BUILDDIR/rootfs" 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" ISOLINUX_CFG="$ISOLINUX_DIR/isolinux.cfg"
# #
@ -270,8 +232,7 @@ fi
# Mount pseudofs in the target rootfs. # Mount pseudofs in the target rootfs.
# #
mount_pseudofs mount_pseudofs
mkdir -p "$ROOTFS/tmp" mkdir -p "$ROOTFS/tmp" "$ISOLINUX_DIR" "$GRUB_DIR"
mkdir -p "$ISOLINUX_DIR"
XBPS_ARGS="-r $ROOTFS -y" XBPS_ARGS="-r $ROOTFS -y"
if [ -n "$REPOSITORY_CACHE" ]; then if [ -n "$REPOSITORY_CACHE" ]; then
@ -284,7 +245,7 @@ case $XBPS_VERSION in
esac esac
info_msg "Redirecting stdout/stderr to $LOGFILE ..." 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 for f in ${PACKAGE_LIST}; do
info_msg " $f" info_msg " $f"
done done
@ -307,22 +268,22 @@ ${XBPS_BIN_CMD} -r "$ROOTFS" list > \
# #
# Prepare /etc/motd. # Prepare /etc/motd.
# #
info_msg "[2/9] Creating /etc/motd..." info_msg "[2/10] Creating /etc/motd..."
mkdir -p "$ROOTFS"/etc mkdir -p "$ROOTFS"/etc
write_etc_motd write_etc_motd
# #
# Create the initramfs with XZ compression. # 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} \ 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. # Copy the linux image to the target directory.
# #
info_msg "[4/9] Copying kernel image/modules..." info_msg "[4/10] Copying kernel image/modules..."
cp -f /boot/vmlinuz-${KERNELVERSION} "${ISOLINUX_DIR}/vmlinuz" || error_out $? cp -f /boot/vmlinuz-${KERNELVERSION} "${BOOT_DIR}/vmlinuz" || error_out $?
mkdir -p "$ROOTFS/lib/modules" mkdir -p "$ROOTFS/lib/modules"
cp -a /lib/modules/${KERNELVERSION} "$ROOTFS/lib/modules" || error_out $? 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 umount_pseudofs
# #
# Copy required isolinux files in the target rootfs. # Prepare isolinux files in the target rootfs.
# #
info_msg "[5/9] Copying isolinux files..." info_msg "[5/10] Preparing isolinux support for BIOS..."
cp -f $SYSLINUX_DATADIR/isolinux.bin "$ISOLINUX_DIR" cp -f $SYSLINUX_DATADIR/isolinux.bin "$ISOLINUX_DIR" || error_out $?
cp -f $SYSLINUX_DATADIR/vesamenu.c32 "$ISOLINUX_DIR" cp -f $SYSLINUX_DATADIR/vesamenu.c32 "$ISOLINUX_DIR" || error_out $?
write_default_isolinux_conf ${KERNELVERSION} cp -f $MKLIVE_DATADIR/isolinux.cfg.in \
"$ISOLINUX_DIR"/isolinux.cfg || error_out $?
if [ -f "$SPLASH_IMAGE" ]; then if [ -f "$SPLASH_IMAGE" ]; then
cp -f $SPLASH_IMAGE "$ISOLINUX_DIR" cp -f $SPLASH_IMAGE "$ISOLINUX_DIR" || error_out $?
fi 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. # 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. # Find out required size for the rootfs and create an ext3fs image off it.
ROOTFS_SIZE=$(du -sk "$ROOTFS"|awk '{print $1}') ROOTFS_SIZE=$(du -sk "$ROOTFS"|awk '{print $1}')
mkdir -p "$BUILDDIR/tmp/LiveOS" mkdir -p "$BUILDDIR/tmp/LiveOS"
@ -435,19 +436,26 @@ mksquashfs "$BUILDDIR/tmp" "$BUILDDIR/LiveOS/squashfs.img" \
-comp ${COMPRESSTYPE} 2>&1 | cat >> $LOGFILE || error_out -comp ${COMPRESSTYPE} 2>&1 | cat >> $LOGFILE || error_out
chmod 444 "$BUILDDIR/LiveOS/squashfs.img" || 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 $? rm -rf "$ROOTFS" "$BUILDDIR/tmp-rootfs" "$BUILDDIR/tmp" || error_out $?
# #
# Prepare the ISO image. # Prepare the ISO image.
# #
info_msg "[8/9] Building ISO image..." info_msg "[9/10] Building ISO image..."
mkisofs -J -r -V "$ISO_VOLUME" -b isolinux/isolinux.bin \ xorriso -as mkisofs \
-c isolinux/boot.cat -no-emul-boot \ -iso-level 3 -rock -joliet \
-boot-load-size 4 -boot-info-table \ -max-iso9660-filenames -omit-period \
-o "$OUTPUT_FILE" "$BUILDDIR" 2>&1 | cat >>$LOGFILE || error_out $? -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 "[9/9] Removing build directory..." info_msg "[10/10] Removing build directory..."
rm -rf "$BUILDDIR" || error_out $? rm -rf "$BUILDDIR" || error_out $?
hsize=$(du -sh "$OUTPUT_FILE"|awk '{print $1}') hsize=$(du -sh "$OUTPUT_FILE"|awk '{print $1}')