forked from Bitmessage/sysdeploy
92 lines
2.1 KiB
Bash
92 lines
2.1 KiB
Bash
#!/bin/bash
|
|
|
|
. ipxe.inc
|
|
|
|
|
|
function dev_from_partnum()
|
|
{
|
|
local drive="$1"
|
|
local partnum="$2"
|
|
partition="$drive""$partnum"
|
|
until [ -b "$drive"1 ] || [ -b "$drive"p1 ]; do
|
|
sleep 1
|
|
done
|
|
if [ ! -b "$partition" ]; then
|
|
partition="$drive"p"$partnum"
|
|
if [ ! -b "$partition" ]; then
|
|
echo "Can't find ${partnum}-th partition for \"$drive\""
|
|
|
|
exit 1
|
|
fi
|
|
fi
|
|
}
|
|
|
|
function mount_efi()
|
|
{
|
|
local drive="$1"
|
|
|
|
dev_from_partnum "$drive" 1
|
|
|
|
unset mnt
|
|
mnt="$(mktemp -d)"
|
|
if ! mount "$partition" "$mnt"; then
|
|
mkfs.vfat "$partition"
|
|
if ! mount "$partition" "$mnt"; then
|
|
echo "Can't mount \"$partition\""
|
|
#cleanup_mnt # Commented out by Max because it's not defined anywhere.
|
|
exit 1
|
|
fi
|
|
fi
|
|
}
|
|
|
|
function umount_efi()
|
|
{
|
|
umount "$mnt"
|
|
sync
|
|
rmdir "$mnt"
|
|
}
|
|
|
|
|
|
function install_syslinux()
|
|
{
|
|
local drive="$1"
|
|
|
|
apt -yq install syslinux syslinux-common syslinux-efi
|
|
|
|
dd bs=440 count=1 conv=notrunc \
|
|
if=/usr/lib/syslinux/mbr/gptmbr.bin of="$drive"
|
|
sync
|
|
|
|
mount_efi "$drive"
|
|
|
|
# legacy
|
|
mkdir -p "$mnt"/syslinux
|
|
cp /usr/lib/syslinux/modules/bios/*.c32 "$mnt"/syslinux/
|
|
|
|
# UEFI
|
|
mkdir -p "$mnt"/EFI/BOOT
|
|
cp /usr/lib/SYSLINUX.EFI/efi64/syslinux.efi "$mnt"/EFI/BOOT/BOOTX64.EFI
|
|
cp /usr/lib/syslinux/modules/efi64/ldlinux.e64 "$mnt"/EFI/BOOT/ldlinux.e64
|
|
cp /usr/lib/syslinux/modules/efi64/*.c32 "$mnt"/EFI/BOOT/
|
|
cp syslinux/{mainmenu,syslinux}.cfg "$mnt"/syslinux
|
|
cp syslinux/syslx64.cfg "$mnt"/EFI/BOOT
|
|
|
|
# These two are called here, because I was unsure if they needed to be
|
|
# set before the syslinux installer ran below. If not, they can be
|
|
# moved elsewhere to make this section cleaner and more readable.
|
|
install_ipxe "${mnt}/syslinux/ipxe.lkrn"
|
|
cat > "$mnt"/syslinux/items.cfg << _EOL_
|
|
DEFAULT Syslinux IPXE Chainloader
|
|
LABEL Syslinux IPXE Chainloader
|
|
MENU LABEL Chainload IPXE Network Boot
|
|
LINUX $mnt/syslinux/ipxe.lkrn
|
|
_EOL_
|
|
|
|
umount_efi
|
|
|
|
dev_from_partnum "$drive" 1
|
|
syslinux "$partition"
|
|
}
|
|
|
|
# vim: set ft=sh:
|