summarylogtreecommitdiffstats
path: root/mklinuxpba-bios
blob: c91d4c4b45eb26a1b390d9d872808f6b148db6b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash

if [[ ! -e /usr/bin/extlinux ]]
then
    echo "syslinux is not installed: nothing to do."
    exit 1
fi

mklinuxpba-initramfs

kernel_release="$(uname -r)"

case "${kernel_release##*-}" in
    "ARCH")
        kernel_image="vmlinuz-linux"
    ;;
    "lts")
        kernel_image="vmlinuz-linux-lts"
    ;;
    *)
        echo "The currenly running kernel is not supported."
        exit 1
    ;;
esac

linux_size=$(stat --printf="%s" /boot/$kernel_image)
pba_size=$(stat --printf="%s" /boot/linuxpba.img)
fallback_pba_size=$(stat --printf="%s" /boot/linuxpba-fallback.img)
if [[ -e /boot/intel-ucode.img ]]
then
    intelucode_size=$(stat --printf="%s" /boot/intel-ucode.img)
else
    intelucode_size=0
fi

diskimg_size=$(( (linux_size+pba_size+intelucode_size)/1024+3072 ))
fallback_diskimg_size=$(( (linux_size+fallback_pba_size+intelucode_size)/1024+3072 ))

mkdir -p "/tmp/linuxpba/mnt"
pushd "/tmp/linuxpba/"

cp /usr/lib/syslinux/bios/mbr.bin linuxpba.diskimg
truncate -s "${diskimg_size}k" linuxpba.diskimg
echo -e "8,,,*\nwrite" | sfdisk linuxpba.diskimg
loopdev="$(losetup --show -f -o 4096 linuxpba.diskimg)"
sync
mkfs.ext4 -L linuxpba "$loopdev"
mount "$loopdev" mnt
extlinux -i mnt
if [[ -e /boot/intel-ucode.img ]]
then
    cp /boot/intel-ucode.img mnt
    cp /etc/linuxpba/extlinux.conf mnt
else
    sed 's/intel-ucode.img,//' /etc/linuxpba/extlinux.conf > mnt/extlinux.conf
fi
cp /boot/linuxpba.img mnt
cp /boot/$kernel_image mnt
umount mnt
losetup -d "$loopdev"

cp /usr/lib/syslinux/bios/mbr.bin linuxpba-fallback.diskimg
truncate -s "${fallback_diskimg_size}k" linuxpba-fallback.diskimg
echo -e "8,,,*\nwrite" | sfdisk linuxpba-fallback.diskimg
loopdev="$(losetup --show -f -o 4096 linuxpba-fallback.diskimg)"
sync
mkfs.ext4 -L linuxpba "$loopdev"
mount "$loopdev" mnt
extlinux -i mnt
if [[ -e /boot/intel-ucode.img ]]
then
    cp /boot/intel-ucode.img mnt
    cp /etc/linuxpba/extlinux.conf mnt
else
    sed 's/intel-ucode.img,//' /etc/linuxpba/extlinux.conf > mnt/extlinux.conf
fi
cp /boot/linuxpba-fallback.img mnt/linuxpba.img
cp /boot/$kernel_image mnt
umount mnt
losetup -d "$loopdev"

mv linuxpba.diskimg linuxpba-fallback.diskimg /boot
cd /tmp
rmdir -p linuxpba/mnt
popd