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 [2026/07/16 14:36] (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:​deb-rauc-lab-skel-2026.tar.gz|Download here the starter archive}} containing starter (skeleton) files & scripts
  
-**The scripts are templates** — you may need to complete missing parts (search for ''​TODO''​s)!+Extract it somewhere in your base working directory.
  
-=== 2.1. Install Debian into an empty directory ===+The code structure should be similar to this:
  
-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--  root  root  148M 2025-08-07 14:23 debrootfs.tar.gz+arm-summer-school/ 
 +├── staging/ ​        # you should have this from lab02 
 +│   ​├── linux-*.its  # Two variants of Linux uImage source descriptors 
 +│   ​├── Makefile ​    # a Makefile to build linux.itb (finally!) 
 +│   ​└── Image,imx93-11x11-frdm.dtb,​rootfs.cpio ​  # copied by the Makefile 
 +├── rauc-utils/ ​     # RAUC installation '​package'​! 
 +│   ​├── install.sh ​      # RAUC installation script (must be ran inside the chroot!) 
 +│   ​├── ca.cert.pem 
 +│   ​├── rauc-mark-good.service 
 +│   ​├── system.conf 
 +│   ​└── fstab            # Optional, custom fstab to mount /boot 
 +├── linux/ ​              # Linux kernel source directory 
 +├── u-boot/ ​             # u-boot source directory 
 +├── debian-rootfs/ ​      # will be created by '​mk-debian-rootfs.sh'​ 
 +├── Makefile ​            # Makefile to build flash.bin from labs 1-3 (u-boot mainline!) 
 +├── newdefault.env       # new/​recommended u-boot default environment 
 +├── uboot-extra.config ​  # extra config to use (used by Makefile above) 
 +├── mk-disk-image.sh ​    # script to build a FAT32 + EXT4 disk image (solved in lab02/03) 
 +├── mk-disk-image2.sh ​   # new disk image script, modified to make 2*rootfs+data partitions 
 +├── mk-debian-rootfs.sh ​ # script to debootstrap your debian directory 
 +└── chroot-enter.sh      # utility script to execute commands in your debian rootfs
 </​code>​ </​code>​
  
-=== 2.2. Create the base disk image ===+=== Prerequisites ​===
  
-📄 File: ''10-create-base-disk.sh''​+We will need the static qemu-aarch64 binaries if we're cross-building, since we need to execute Debian install scripts on our native host archivecture (e.g., ''​x86_64''​).
  
-Your task:+First, make sure you have these packages installed (they were already installed on the VM, so you can skip this):
  
-  - Use ''​truncate''​ or ''​dd''​ to allocate the image with the desired size; +<code bash> 
-  Modify the ''​parted''​ invocation (script); +sudo apt install qemu-user-static binfmt-support debootstrap ​parted ​dosfstools e2fsprogs u-boot-tools 
-  ​Add partitions for: +</​code>​
-    ​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