sysdeploy/syslinux.inc

67 lines
1.4 KiB
Bash

#!/bin/bash
function dev_from_partnum()
{
local drive="$1"
local partnum="$2"
partition="$drive""$partnum"
if [ ! -b "$partition" ]; then
partition="$drive"p"$partnum"
if [ ! -b "$partition" ]; then
echo "Can't find first 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"
flush
rmdir "$mnt"
}
function install_syslinux()
{
local drive="$1"
dd bs=440 count=1 conv=notrunc \
if=/usr/lib/syslinux/mbr/gptmbr.bin of="$drive"
mount_efi "$drive"
# legacy
cp /usr/lib/syslinux/modules/bios/*.c32 "$mnt"/syslinux/
# UEFI
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
syslinux "$partition"
}
# vim: set ft=sh: