Skip to content

Instantly share code, notes, and snippets.

Created June 3, 2022 01:01
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
make a debian-based os image and chroot for arm (run in arm64 qemu)
#!/bin/bash -e
apt install -y build-essential debootstrap unzip git
# create image
qemu-img create -f qcow2 -o preallocation=metadata rknullos.qcow2 2G
modprobe nbd max_part=8
qemu-nbd --connect=/dev/nbd0 rknullos.qcow2
# paritition
cat << EOF | sfdisk /dev/nbd0
/dev/nbd0p1 : start= 2048, size= 204800, type=6
/dev/nbd0p2 : start= 206848, size= 3987456, type=83
# setup filesystem
mkfs -j /dev/nbd0p2
mkfs -t fat /dev/nbd0p1
mkdir root
mount /dev/nbd0p2 root
mkdir -p root/boot
mount /dev/nbd0p1 root/boot
debootstrap bullseye root
echo "type exit to leave the chroot"
chroot root bash
# cleanup
umount root/boot
umount root
qemu-nbd --disconnect /dev/nbd0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment