2021-03-02 12:12:10 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2021-03-02 14:39:19 +01:00
|
|
|
function dev_from_partnum()
|
2021-03-02 12:12:10 +01:00
|
|
|
{
|
|
|
|
local drive="$1"
|
2021-03-02 14:39:19 +01:00
|
|
|
local partnum="$2"
|
|
|
|
partition="$drive""$partnum"
|
2021-03-05 21:46:38 +01:00
|
|
|
until [ -b "$drive"1 ] || [ -b "$drive"p1 ]; do
|
|
|
|
sleep 1
|
|
|
|
done
|
2021-03-02 12:12:10 +01:00
|
|
|
if [ ! -b "$partition" ]; then
|
2021-03-02 14:39:19 +01:00
|
|
|
partition="$drive"p"$partnum"
|
2021-03-02 12:12:10 +01:00
|
|
|
if [ ! -b "$partition" ]; then
|
2021-03-02 22:15:19 +01:00
|
|
|
echo "Can't find ${partnum}-th partition for \"$drive\""
|
2021-03-02 12:12:10 +01:00
|
|
|
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
2021-03-02 14:39:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function mount_efi()
|
|
|
|
{
|
|
|
|
local drive="$1"
|
|
|
|
|
|
|
|
dev_from_partnum "$drive" 1
|
2021-03-02 12:12:10 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2021-03-02 14:39:19 +01:00
|
|
|
function umount_efi()
|
2021-03-02 12:12:10 +01:00
|
|
|
{
|
|
|
|
umount "$mnt"
|
2021-03-02 17:00:17 +01:00
|
|
|
sync
|
2021-03-02 12:12:10 +01:00
|
|
|
rmdir "$mnt"
|
|
|
|
}
|
|
|
|
|
|
|
|
function install_syslinux()
|
|
|
|
{
|
|
|
|
local drive="$1"
|
|
|
|
|
2021-03-02 21:57:06 +01:00
|
|
|
apt -yq install syslinux syslinux-common syslinux-efi
|
2021-03-02 21:55:35 +01:00
|
|
|
|
2021-03-03 10:50:11 +01:00
|
|
|
dd bs=440 count=1 conv=notrunc \
|
|
|
|
if=/usr/lib/syslinux/mbr/gptmbr.bin of="$drive"
|
2021-03-03 12:32:18 +01:00
|
|
|
sync
|
2021-03-02 21:20:17 +01:00
|
|
|
|
2021-03-02 12:12:10 +01:00
|
|
|
mount_efi "$drive"
|
|
|
|
|
|
|
|
# legacy
|
2021-03-02 20:33:48 +01:00
|
|
|
mkdir -p "$mnt"/syslinux
|
2021-03-02 12:12:10 +01:00
|
|
|
cp /usr/lib/syslinux/modules/bios/*.c32 "$mnt"/syslinux/
|
|
|
|
|
|
|
|
# UEFI
|
2021-03-02 20:33:48 +01:00
|
|
|
mkdir -p "$mnt"/EFI/BOOT
|
2021-03-02 12:12:10 +01:00
|
|
|
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
|
|
|
|
|
2021-03-02 14:39:19 +01:00
|
|
|
umount_efi
|
2021-03-03 12:30:15 +01:00
|
|
|
|
|
|
|
dev_from_partnum "$drive" 1
|
|
|
|
syslinux "$partition"
|
2021-03-02 12:12:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# vim: set ft=sh:
|