Files
monok8s/alpine/build-rootfs.sh

87 lines
2.3 KiB
Bash
Executable File

#!/bin/bash
/preload-k8s-images.sh || exit 1
REGISTRY_DATA_DIR="${KUBE_IMG_CACHE}/registry-data/${ARCH}/${KUBE_VERSION}"
mkdir -p "${ROOTFS}/var/lib/registry"
echo "Copying registry data into rootfs..."
cp -a "${REGISTRY_DATA_DIR}/." "${ROOTFS}/var/lib/registry/"
mkdir -p "$ROOTFS/var/cache/apk"
mkdir -p "$ROOTFS/var/cache/k8s-images"
mkdir -p "$ROOTFS/build"
mount --bind /var/cache/apk "$ROOTFS/var/cache/apk"
mount --bind /var/cache/k8s-images "$ROOTFS/var/cache/k8s-images"
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/"
cp -r /build/rootfs/* "$ROOTFS/"
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
rm "$ROOTFS/install-packages.sh"
/merge-rootfs.sh "/build/rootfs-extra" "$ROOTFS"
cp "/configure-system.sh" "$ROOTFS/configure-system.sh"
chroot "$ROOTFS" /bin/bash /configure-system.sh || exit 1
rm "$ROOTFS/configure-system.sh"
umount "$ROOTFS/var/cache/apk"
umount "$ROOTFS/var/cache/k8s-images"
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 "##################################################### Packaging RootFS "$( du -sh "$ROOTFS/" )
IMG=output.img
SIZE=1536MB
dd if=/dev/zero of="$IMG" bs=1 count=0 seek=$SIZE
sgdisk -o "$IMG" \
-n 1:65536:-1M -t 1:8300
losetup -D
LOOP=$(losetup --find --show -P "$IMG")
/sync-loop.sh "$LOOP"
TMP_LOOP="/tmp$LOOP"
mkfs.ext4 -F "${TMP_LOOP}p1"
mkdir -p /mnt/img-root
mount "${TMP_LOOP}p1" /mnt/img-root
cp -a "$ROOTFS"/. /mnt/img-root/
mkdir -p /mnt/img-root/boot
cp /build/Image.gz /mnt/img-root/boot/Image.gz
cp /build/board.itb /mnt/img-root/boot/kernel.itb
cp /build/${DEVICE_TREE_TARGET}.dtb /mnt/img-root/boot/${DEVICE_TREE_TARGET}.dtb
sync
umount /mnt/img-root
losetup -d "$LOOP"
echo "##################################################### Compressing Image"
gzip "/build/$IMG"