Files
monok8s/alpine/build-rootfs.sh
2026-03-22 23:47:55 +08:00

62 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
mkdir -p "$ROOTFS/var/cache/apk"
mkdir -p "$ROOTFS/build"
mount --bind /var/cache/apk "$ROOTFS/var/cache/apk"
mount --bind /dev "$ROOTFS/dev"
mount --bind /proc "$ROOTFS/proc"
mount --bind /sys "$ROOTFS/sys"
mount --bind /run "$ROOTFS/run"
cp /usr/bin/qemu-aarch64-static "$ROOTFS/usr/bin/"
cp /etc/resolv.conf "$ROOTFS/etc/resolv.conf"
cp /build/crio.tar.gz "$ROOTFS/build/"
chroot "$ROOTFS" /bin/sh -c "ln -s /var/cache/apk /etc/apk/cache"
# chroot "$ROOTFS" /bin/sh -c "apk update"
chroot "$ROOTFS" /bin/sh -c "apk add bash curl"
cp "/install-packages.sh" "$ROOTFS/install-packages.sh"
chroot "$ROOTFS" /bin/bash /install-packages.sh || exit 1
umount "$ROOTFS/var/cache/apk"
umount "$ROOTFS/dev"
umount "$ROOTFS/proc"
umount "$ROOTFS/sys"
umount "$ROOTFS/run"
rm -r "$ROOTFS/build"
### Begin making full disk image for the device
echo "=========================== RootFS "$( du -sh "$ROOTFS/" )
IMG=output.img
SIZE=512MB
dd if=/dev/zero of="$IMG" bs=1 count=0 seek=$SIZE
sgdisk -o "$IMG" \
-n 1:2048:+64M -t 1:0700 \
-n 2:0:-1M -t 2:8300
losetup -D
LOOP=$(losetup --find --show -P "$IMG")
/sync-loop.sh "$LOOP"
TMP_LOOP="/tmp$LOOP"
mkfs.vfat "${TMP_LOOP}p1"
mkfs.ext4 "${TMP_LOOP}p2"
mkdir -p /mnt/img-root /mnt/img-boot
mount ${TMP_LOOP}p1 /mnt/img-boot
mount ${TMP_LOOP}p2 /mnt/img-root
cp -a "$ROOTFS"/. /mnt/img-root/
cp /build/board.itb /mnt/img-boot
umount /mnt/img-root
umount /mnt/img-boot
losetup -d "$LOOP"