sysdeploy/syslinux.inc

77 lines
1.6 KiB
Bash

#!/bin/bash
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
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
umount_efi
dev_from_partnum "$drive" 1
syslinux "$partition"
}
# vim: set ft=sh: