-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildgpt.sh
executable file
·73 lines (56 loc) · 2.06 KB
/
buildgpt.sh
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
#!/bin/sh
# Our desired disk layout is
# - 34 sectors for primary GPT
# - FAT fs for EFI
# - All available space for root fs
# - 16GB swap space at the end of the disk
# - 33 sectors for secondary GPT
# This is constructed on the target system from the image that contains
# - 34 sectors for primary GPT
# - FAT fs EFI boot and curtin-hooks
# - 2GB root fs image
# - 33 sectors for secondary GPT
set -e
IMAGEDIR=$1
DESTDIR=${DESTDIR:-$2}
ARCH=amd64
XZ=${XZ:-xz -9 -T0}
if [ x$IMAGEDIR = x ]
then
echo usage: $(basename $0) IMAGEDIR '[ NETBSD-DESTDIR ]'
echo No IMAGEDIR was specified
exit 1
fi
if [ x$DESTDIR = x ]
then
echo usage: $(basename $0) IMAGEDIR '[ NETBSD-DESTDIR ]'
echo No NETBSD-DESTDIR was specified and \$DESTDIR has no value
exit 1
fi
cd $(dirname "$0")
XDIR=$(pwd)
TOOLDIR=${TOOLDIR:-${DESTDIR}/../tools.${ARCH}}
PATH=${TOOLDIR}/bin:$PATH
cd ${DESTDIR}
nbawk '{ a[$1] = $0; } END { for (f in a) print a[f]; }' METALOG.sanitised $XDIR/extra-files/mtree $XDIR/uefi-files/mtree | sort | nbmtree -CSM -k all -R time -N ./etc > $IMAGEDIR/METALOG.bootable
nbmakefs -N etc -r -x -F $IMAGEDIR/METALOG.bootable -s 2g -f 100000 $IMAGEDIR/netbsd.fs . $XDIR/extra-files $XDIR/uefi-files $XDIR/bin/${ARCH}
#nbmakefs -N etc -r -x -F METALOG.bootable -s 2g -f 100000 -o version=2 $XDIR/netbsd.fs . $XDIR/extra-files
cd $IMAGEDIR
rm -rf boot.efi
mkdir -p boot.efi/efi/boot
cp ${DESTDIR}/usr/mdec/*.efi boot.efi/efi/boot
chmod +w boot.efi/efi/boot/*.efi
# Merging seem to work as advertised for MS-DOS filesystems.
# So we merge manually for now.
cp -r $XDIR/curtin-files/* boot.efi
nbmakefs -t msdos -s 200m curtin.fs boot.efi
# Glue the image together
dd if=/dev/zero count=34 of=image.gpt.${ARCH}
cat curtin.fs netbsd.fs >> image.gpt.${ARCH}
dd if=/dev/zero count=33 >> image.gpt.${ARCH}
# and create a partition table to match.
nbgpt image.gpt.${ARCH} create
nbgpt image.gpt.${ARCH} add -l EFI -s $(nbstat -f "%Mz" curtin.fs)m -t efi
nbgpt image.gpt.${ARCH} add -l ROOT -s $(nbstat -f "%Mz" netbsd.fs)m -t ffs
rm -f image.gpt.${ARCH}.xz
${XZ} -v image.gpt.${ARCH}