02. Disk image & Debian

Youโ€™ll be running scripts in ./scripts, either one by one or all together via ./run-all.sh.

The scripts are templates โ€” you may need to complete missing parts (search for TODOs)!

2.1. Install Debian into an empty directory

Yes, really, you can easily do this!

You will use the debootstrap official tool to install a minimal Debian (you can also install deb-based derivatives like Ubuntu!) base system.

๐Ÿ“„ Edit the 05-debootstrap.sh script.

Since we need to install the Debian binaries executable on a 64-bit ARM architecture, we will need to split the installation into two stages: first, the .deb (Debian install packages) are downloaded from a Debian mirror server and unpacked into the target rootfs directory. Afterwards, since Debian will need to run some scripts to setup its distro system, we must emulate the target architecture. Enter qemu which will help us to just that!

Finally, we need to obtain the artifacts/debrootfs.tar.gz archive with the contents of our newly-created Aarch64 Debian. Use tar to create a gzipped archive, and be sure to preserve permissions!

The final results should be something like:

-rw-r--r--  1 root  root  148M 2025-08-07 14:23 debrootfs.tar.gz

2.2. Create the base disk image

๐Ÿ“„ File: 10-create-base-disk.sh

Your task:

  1. Use truncate or dd to allocate the image with the desired size;
  2. Modify the parted invocation (script);
  3. Add partitions for:
    1. rootfsA (ext4)
    2. rootfsB (ext4)
    3. data (ext4)

Make the partition have the labels documented above (as they are used throughout the RAUC scripts and/or in u-boot)!

2.3. Populate the rootfs partitions

๐Ÿ“„ File: 25-populate-base-disk.sh

Subtasks:

  1. Mount the partitions created previously (already in script);
  2. Extract the previously-obtained Debian debrootfs.tar.gz on each rootfs A/B partition (a simple tar xf will suffice);

Note: you will lack flash_emmc.bin required by this script. So let's proceed without testing, for now.

Entering the rootfs

If you wish to enter your newly bootstrapped Debian rootfs, you can use the following script:

enter-rootfs.sh
#!/bin/bash
set -e
 
ROOTFS=$1
 
if [[ -z "$ROOTFS" ]] || [[ ! -d "$ROOTFS/usr/bin" ]]; then
    echo "[!] Invalid rootfs argument: '$ROOTFS'"
    exit 1
fi
 
cleanup() {
    echo "[*] Cleaning up..."
    for sub in dev/pts dev proc sys run; do
        if mountpoint -q "$ROOTFS/$sub"; then
            echo "    Unmounting $ROOTFS/$sub"
            sudo umount "$ROOTFS/$sub" || true
        fi
    done
}
trap cleanup EXIT
 
echo "[+] Binding chroot filesystems..."
for fs in dev dev/pts proc sys run; do
  sudo mount --bind "/$fs" "$ROOTFS/$fs"
done
 
echo "[+] Ensuring /etc/resolv.conf for DNS inside chroot"
sudo cp /etc/resolv.conf "$ROOTFS/etc/resolv.conf"
 
echo "[+] Entering your chroot shell..."
echo "Type exit to leave"
sudo chroot "$ROOTFS" /usr/bin/qemu-aarch64-static /bin/bash

You can even run apt install in there ;)

ass/labs-2025/04/tasks/02.txt ยท Last modified: 2025/08/07 20:54 by florin.stancu
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0