summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIru Cai <mytbk920423@gmail.com>2018-06-26 10:11:43 +0800
committerIru Cai <mytbk920423@gmail.com>2018-06-26 10:11:43 +0800
commit83df9af6f3fdf72d6dc7605b0a74a4c25cd96bfd (patch)
tree4f2a47e4a5ffa8a0017793c93b47e8da2e665994
parent6945e44775e740dfe0a59ed959782f7a3f121f4f (diff)
downloadliveusb-builder-83df9af6f3fdf72d6dc7605b0a74a4c25cd96bfd.tar.xz
Use syslinux as legacy BIOS bootloader
- Install syslinux by default, fallback to GRUB - Generate syslinux.cfg
-rwxr-xr-xbuildlive34
-rw-r--r--functions.sh51
-rwxr-xr-xinstall_syslinux17
-rwxr-xr-xmksyslinux.sh31
4 files changed, 112 insertions, 21 deletions
diff --git a/buildlive b/buildlive
index aeec242..3de3b03 100755
--- a/buildlive
+++ b/buildlive
@@ -107,6 +107,8 @@ fi
if [[ "$DOWNLOAD_ONLY" == 0 ]]; then
UUID="$(findmnt -o UUID --raw --noheadings $ROOTPATH \
|| fatalerror "UUID of $ROOTPATH not found, not a mountpoint?")"
+ BOOTPART="$(findmnt -o SOURCE --raw --noheadings $BOOTPATH \
+ || fatalerror "$BOOTPATH seems not a mountpoint!")"
# liveusb kernel and data should be placed on one disk
# so get DEVNAME by the mountpoint of ROOTPATH is ok
DEVNAME="/dev/$(getdiskbypart "/dev/disk/by-uuid/$UUID")"
@@ -114,7 +116,8 @@ if [[ "$DOWNLOAD_ONLY" == 0 ]]; then
KERNELDIR="$BOOTPATH/liveusb-kernel"
DATADIR="$ROOTPATH/liveusb-data"
GRUBCFG="$BOOTPATH/grub/grub.cfg"
- install -d "$BOOTPATH/grub"
+ SYSLINUXCFG="$BOOTPATH/syslinux/syslinux.cfg"
+ install -d "$BOOTPATH/grub" "$BOOTPATH/syslinux"
install -d "$KERNELDIR" "$DATADIR"
msg "Files will be copy to $ROOTPATH"
fi
@@ -145,23 +148,8 @@ if [[ "$DOWNLOAD_ONLY" == 1 ]]; then
exit 0
fi
-echo '# The live USB grub.cfg file' > "$GRUBCFG"
-
-if [ -z "$TXTMODE" ]; then
- cat >> "$GRUBCFG" << 'EOF'
-if [ ${grub_platform} == efi ]; then
- insmod all_video
- insmod font
- if loadfont /grub/fonts/unicode.pf2; then
- insmod gfxterm
- set gfxmode=auto
- set gfxpayload=keep
- terminal_output gfxterm
- fi
-fi
-
-EOF
-fi
+grubcfg_header > "$GRUBCFG"
+syslinux_header > "$SYSLINUXCFG"
for i in `seq 1 ${#DISTROLIST[@]}`
do
@@ -174,14 +162,18 @@ do
install_live
fi
gen_grubcfg "$DISTRO" >> "$GRUBCFG"
+ gen_syslinux "$DISTRO" >> "$SYSLINUXCFG"
done
if [ "$GRUBCFG_ONLY" == 1 ]; then
- msg 'Only generate grub.cfg, will not install GRUB.'
+ msg 'Only generate grub.cfg and syslinux.cfg, will not install bootloader.'
elif [ "$INSTALL_GRUB" == 1 ]; then
- read -p 'Answer Y to install GRUB.[Y/n] '
+ read -p 'Answer Y to install bootloader.[Y/n] '
if [[ "$REPLY" =~ ^[Yy]|^$ ]]; then
- as-root grub-install --force --boot-directory="$BOOTPATH" --target=i386-pc "$DEVNAME"
+ if ! as-root ./install_syslinux "$DEVNAME" "$BOOTPART" "$BOOTPATH"; then
+ msg 'Failed to install syslinux, try to install GRUB as legacy BIOS bootloader.'
+ as-root grub-install --force --boot-directory="$BOOTPATH" --target=i386-pc "$DEVNAME"
+ fi
as-root grub-install --boot-directory="$BOOTPATH" --efi-directory="$BOOTPATH" --bootloader-id=grub --target=x86_64-efi --removable --no-nvram "$DEVNAME"
fi
fi
diff --git a/functions.sh b/functions.sh
index c077231..00e0e0c 100644
--- a/functions.sh
+++ b/functions.sh
@@ -59,6 +59,19 @@ gen_grubcfg() {
fi
}
+gen_syslinux() {
+ local entry allentries count name
+ allentries=("distro/$1/entry"*)
+ name=$(echo $1|sed 's/\//_/g')
+ count=0
+ for entry in "${allentries[@]}"
+ do
+ UUID="$UUID" ISOFILE="$ISOFILE" LABEL="$name$count" \
+ ./mksyslinux.sh "$entry"
+ count=$(($count+1))
+ done
+}
+
download_iso() {
mkdir -p "$ISOPATH"
for url in ${mirrorlist[@]}
@@ -119,3 +132,41 @@ as-root() {
su -c "$*"
fi
}
+
+syslinux_header() {
+ cat << EOF
+UI menu.c32
+
+MENU TITLE Live USB
+MENU COLOR border 30;44 #40ffffff #a0000000 std
+MENU COLOR title 1;36;44 #9033ccff #a0000000 std
+MENU COLOR sel 7;37;40 #e0ffffff #20ffffff all
+MENU COLOR unsel 37;44 #50ffffff #a0000000 std
+MENU COLOR help 37;40 #c0ffffff #a0000000 std
+MENU COLOR timeout_msg 37;40 #80ffffff #00000000 std
+MENU COLOR timeout 1;37;40 #c0ffffff #00000000 std
+MENU COLOR msg07 37;40 #90ffffff #a0000000 std
+MENU COLOR tabmsg 31;40 #30ffffff #00000000 std
+
+EOF
+}
+
+grubcfg_header() {
+ echo '# The live USB grub.cfg file'
+
+ if [ -z "$TXTMODE" ]; then
+ cat << 'EOF'
+if [ ${grub_platform} == efi ]; then
+ insmod all_video
+ insmod font
+ if loadfont /grub/fonts/unicode.pf2; then
+ insmod gfxterm
+ set gfxmode=auto
+ set gfxpayload=keep
+ terminal_output gfxterm
+ fi
+fi
+
+EOF
+ fi
+}
diff --git a/install_syslinux b/install_syslinux
new file mode 100755
index 0000000..d4fdbf9
--- /dev/null
+++ b/install_syslinux
@@ -0,0 +1,17 @@
+#!/bin/bash
+# Copyright (C) 2018 Iru Cai <mytbk920423@gmail.com>
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+# Example: ./install_syslinux /dev/sdb /dev/sdb1 /media/boot
+set -e
+
+SYSLINUX_BIOS=/usr/lib/syslinux/bios
+DEVNAME="$1"
+BOOTPART="$2"
+BOOTPATH="$3"
+
+test -d "$SYSLINUX_BIOS"
+syslinux -i "$BOOTPART"
+dd bs=440 count=1 conv=notrunc if="$SYSLINUX_BIOS/mbr.bin" of="$DEVNAME"
+install -d "$BOOTPATH/syslinux"
+cp "$SYSLINUX_BIOS"/*.c32 "$BOOTPATH/syslinux"
diff --git a/mksyslinux.sh b/mksyslinux.sh
new file mode 100755
index 0000000..f433fe8
--- /dev/null
+++ b/mksyslinux.sh
@@ -0,0 +1,31 @@
+# Copyright (C) 2018 Iru Cai <mytbk920423@gmail.com>
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+# generate syslinux menuentry
+# usage: UUID="$UUID" ISOFILE="$ISOFILE" LABEL="$LABEL" \
+# ./mkgrubcfg.sh <entryfile>
+#
+# variables in entryfile:
+# - UUID: the UUID of the partition
+# - ISOFILE: the file name of iso (needed to pass to the entry file)
+# - LABEL: syslinux label
+#
+# parameters in entry file:
+# - TITLE: GRUB menu entry title
+# - KERNEL: path to kernel image
+# - INITRD: path to initramfs/initrd image
+# - OPTION: kernel command line
+# - X64: y/n, indicates whether it's 64-bit
+
+source "$1"
+_INITRD=$(echo ${INITRD[*]}|sed 's/ /,/g')
+
+cat << EOF
+LABEL $LABEL
+MENU LABEL $TITLE
+LINUX $KERNEL
+INITRD $_INITRD
+APPEND $OPTION
+EOF
+
+echo