-
Notifications
You must be signed in to change notification settings - Fork 3
/
mk-image.sh
executable file
·87 lines (72 loc) · 2.52 KB
/
mk-image.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
. $PWD/utils.sh
IMAGE_FILE="arch-linux-$(date --rfc-3339=date).img"
# truncate will not allocate new space if file is already exist,
# which might lead to some unexpected issue.
[[ -f $IMAGE_FILE ]] && rm -f $IMAGE_FILE
# create a file with 2G size
truncate -s 2G $IMAGE_FILE
# create partition into it
sgdisk -g --clear -a 1 \
--new=1:34:2081: --change-name=1:spl --typecode=1:5B193300-FC78-40CD-8002-E86C45580B47 \
--new=2:2082:16383: --change-name=2:uboot --typecode=2:2E54B353-1271-4842-806F-E436D6AF6985 \
--new=3:16384:-0 --change-name=3:rootfs --attributes=3:set:2 \
$IMAGE_FILE
# write u-boot into it
dd if=$PWD/repos/u-boot/spl/u-boot-spl.bin of=$IMAGE_FILE bs=512 seek=34 conv=sync,notrunc
dd if=$PWD/repos/u-boot/u-boot.itb of=$IMAGE_FILE bs=512 seek=2082 conv=sync,notrunc
losetup -D
LODEV=$(losetup -f --show -P $IMAGE_FILE)
if [[ -f /.dockerenv ]]; then
# Issue: https://github.com/moby/moby/issues/27886#issuecomment-417074845
PARTITIONS=$(lsblk --raw --output "MAJ:MIN" --noheadings ${LODEV} | tail -n +2)
COUNTER=1
for i in $PARTITIONS; do
MAJ=$(echo $i | cut -d: -f1)
MIN=$(echo $i | cut -d: -f2)
if [[ ! -e "${LODEV}p${COUNTER}" ]]; then mknod ${LODEV}p${COUNTER} b $MAJ $MIN; fi
COUNTER=$((COUNTER + 1))
done
fi
mkfs.ext4 "${LODEV}p3"
mkdir rootfs
mount "${LODEV}p3" rootfs/
if is_cross_compile "$@"; then
pacstrap \
-C /usr/share/devtools/pacman-extra-riscv64.conf \
-M \
./rootfs \
base linux linux-firmware vim arch-install-scripts gptfdisk
else
pacstrap rootfs base linux linux-firmware vim arch-install-scripts gptfdisk
fi
usermod --root $(realpath ./rootfs) --password $(openssl passwd -6 "archriscv") root
echo "pts/0\n" >> rootfs/etc/securetty
mkdir rootfs/boot/extlinux
tee -a rootfs/boot/extlinux/extlinux.conf << END
default arch
menu title U-Boot menu
prompt 0
timeout 50
label arch
menu label Arch Linux(MMC)
linux /boot/vmlinuz-linux
initrd /boot/initramfs-linux-fallback.img
fdtdir /boot/dtbs/
append root=/dev/mmcblk0p3 rw earlycon
END
cp -r rootfs/usr/share/dtbs/*-arch*/ rootfs/boot/dtbs
tee -a rootfs/etc/systemd/network/end0.network << END
[Match]
Name=end0
[Network]
DHCP=yes
END
cp /etc/pacman.conf rootfs/etc/pacman.conf
arch-chroot rootfs systemctl enable systemd-networkd
arch-chroot rootfs systemctl enable systemd-resolved
arch-chroot rootfs systemctl enable systemd-timesyncd
cp ./install-system-to-ssd.sh rootfs/root
cp ./add-packager.sh rootfs/root
umount -l rootfs
rmdir rootfs
losetup -D