Differences

This shows you the differences between two versions of the page.

Link to this comparison view

ass:labs-2025:04:tasks:01 [2025/08/07 18:10]
florin.stancu
ass:labs-2025:04:tasks:01 [2025/08/07 20:54] (current)
florin.stancu
Line 1: Line 1:
-==== 02Disk image & Debian ​====+==== 01Preparations ​====
  
-You’ll be running scripts in ''​./​scripts'',​ either one by one or all together via ''​./​run-all.sh''​.+{{:ass:labs-2025:​04:​rauc-lab-skel.tar.gz|Download here the starter archive}} containing skeleton files + scripts
  
-**The scripts are templates** — you may need to complete missing parts (search for ''​TODO''​s)!+Extract it somewhere in a new directory ​(e.g., create ​''​rauc-lab''​).
  
-=== 2.1. Install Debian into an empty directory ===+The code structure will become (mostly is, but some are TODO) as follows:
  
-Yes, really, you can easily do this! 
- 
-You will use the [[https://​wiki.debian.org/​Debootstrap|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 [[https://​www.qemu.org/​|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 ''​c''​reate a g''​z''​ipped archive, and be sure to ''​p''​reserve permissions! 
- 
-The final results should be something like: 
 <​code>​ <​code>​
--rw-r--r--  1 root  root  148M 2025-08-07 14:23 debrootfs.tar.gz+rauc-lab/ 
 +├── artifacts/ ​      # <-- you'll create this 
 +│   ​├── flash_spl.bin ​        # A working flash.bin image you already have 
 +│   ​├── flash_emmc.bin ​       # Your new flash.bin (see tasks) 
 +│   ​├── linux.itb ​            # A kernel image (after removing the initrd) 
 +│   ​├── uboot.env ​            # U-Boot environment variables (just the var file) 
 +├── utils/ 
 +│   ​├── ca.cert.pem 
 +│   ​├── rauc-mark-good.service 
 +│   ​├── system.conf 
 +│   ​└── fstab                 # Optional custom fstab 
 +├── scripts/ ​        # <-- your main job to finish those! 
 +│   ├── 05-debootstrap.sh 
 +│   ├── 10-create-base-disk.sh 
 +│   ├── 11-populate-disk-image.sh 
 +│   ├── 20-modify-bootcmd.sh 
 +│   ├── 21-install-boot.sh 
 +│   └── 30-install-rauc.sh 
 +├── run-all.sh               # Will run all scripts in order
 </​code>​ </​code>​
  
-=== 2.2. Create the base disk image ===+=== Prerequisites ​===
  
-📄 File''​10-create-base-disk.sh''​+First, make sure you have these packages installed on your host system (they were already installed on the VM, so you can skip this):
  
-Your task:+<code bash> 
 +sudo apt install qemu-user-static binfmt-support debootstrap parted dosfstools e2fsprogs u-boot-tools 
 +</​code>​
  
-  - Use ''​truncate''​ or ''​dd''​ to allocate the image with the desired size; 
-  - Modify the ''​parted''​ invocation (script); 
-  - Add partitions for: 
-    - rootfsA (ext4) 
-    - rootfsB (ext4) 
-    - data (ext4) 
  
-<note warning>​ +Then, check that ''​binfmt_misc''​ is active and register ​the QEMU handler for ''​aarch64'':​
-Make the partition have the labels documented above (as they are used throughout the RAUC scripts and/or in u-boot)! +
-</​note>​+
  
-=== 2.3. Populate the rootfs partitions ===+<code bash> 
 +grep aarch64 /​proc/​sys/​fs/​binfmt_misc/​qemu-aarch64 
 +</​code>​
  
-📄 File''​25-populate-base-disk.sh''​+If it’s empty, run:
  
-Subtasks: +<code bash> 
- +sudo su 
-  - Mount the partitions created previously (already in script); +echo ':qemu-aarch64:​M:​:\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00:​\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff:/​usr/bin/qemu-aarch64-static:CF' ​/​proc/​sys/​fs/​binfmt_misc/register 
-  - Extract the previously-obtained Debian ​''​debrootfs.tar.gz''​ on each rootfs A/B partition (a simple ''​tar xf''​ will suffice); +exit 
- +</code>
-Noteyou 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: +
- +
-<file bash enter-rootfs.sh>​ +
-#!/bin/bash +
-set -+
- +
-ROOTFS=$1 +
- +
-if [[ ! -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 +
-</file>+
  
-You can even run ''​apt install''​ in there ;) +For Arch Linux users: check out [[https://​wiki.archlinux.org/​title/​QEMU#​Chrooting_into_arm/​arm64_environment_from_x86_64|this guide for installable dependencies]]!
  
  
ass/labs-2025/04/tasks/01.1754579431.txt.gz · Last modified: 2025/08/07 18:10 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