Differences

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

Link to this comparison view

ass:labs-2025:04:tasks:02 [2025/08/07 20:54]
florin.stancu
ass:labs-2025:04:tasks:02 [2026/07/16 15:08] (current)
florin.stancu
Line 1: Line 1:
-==== 02. Disk image & Debian ====+==== 02. Bootstrapping ​Debian ====
  
-You’ll be running scripts in ''​./​scripts'',​ either one by one or all together via ''​./​run-all.sh''​. +=== 2.1. Install Debian into directory ===
- +
-**The scripts are templates** — you may need to complete missing parts (search for ''​TODO''​s)! +
- +
-=== 2.1. Install Debian into an empty directory ===+
  
 Yes, really, you can easily do this! Yes, really, you can easily do this!
Line 11: Line 7:
 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. 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.+📄 Edit the ''​mk-debian-rootfs.sh''​ script, read the code and fill the TODOs.
  
 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! 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!+Finally, we need to obtain the ''​debian-rootfs.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 ​bash
-<​code>​ +sudo tar czpf debian-rootfs.tar.gz ​-C debian-rootfs/​ .
--rw-r--r-- ​ 1 root  root  148M 2025-08-07 14:23 debrootfs.tar.gz+
 </​code>​ </​code>​
  
-=== 2.2. Create the base disk image ===+Note: each time you chroot and install / modify your rootfs on your local machine, make sure to rebuild the ''​tar.gz''​ archive!
  
-📄 File: ''​10-create-base-disk.sh''​+=== 2.1. Installing kernel modules ===
  
-Your task:+We must install our kernel'​s external modules onto our new Debian rootfs.
  
-  ​Use ''​truncate''​ or ''​dd''​ to allocate the image with the desired size; +As noted in [[:ass:labs-2025:03|Lab 3]], it's quite simple, actually (adapt if paths don't match):
-  - Modify the ''​parted''​ invocation (script)+
-  - Add partitions for: +
-    - rootfsA (ext4) +
-    - rootfsB (ext4) +
-    - data (ext4)+
  
-<note warning+<code bash
-Make the partition have the labels documented above (as they are used throughout the RAUC scripts and/​or ​in u-boot)! +# navigate to Linux'​s source directory 
-</note>+cd linux/ 
 +# ensure compiled ​the modules 
 +make ARCH=arm64 modules 
 +# install ​the modules inside debian-rootfs ​(hope you put it in parent dir)
 +sudo make ARCH=arm64 INSTALL_MOD_PATH="​../​debian-rootfs/"​ modules_install 
 +</code>
  
-=== 2.3Populate ​the rootfs ​partitions ​===+=== 2.2Entering ​the rootfs ===
  
-📄 File: ''​25-populate-base-disk.sh''​+If you wish to enter your newly bootstrapped Debian rootfs, you can readily use the ''​chroot-enter.sh'' ​script (read its code to see its arguments!)
  
-Subtasks:+There'​s one critical thing to do if we want to be able to use our rootfs liveset up a login password! So: 
 +<code bash> 
 +# in chroot, you are root, so set up a "​secure"​ password 
 +# (joking, you can use '​1234'​) 
 +passwd 
 +</​code>​
  
-  - Mount the partitions created previously (already in script); +You can even run ''​apt install'' ​in there ;) try it out (we'll use it later to install RAUC packages + configuration files).
-  - 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.+Let's also check something.. while still inside the chroot, try to ''​ls -l /​lib/​modules/​*'​'​. ​The kernel modules you installed in the previous step should be listed in there for your kernel version!
  
-=== Entering the rootfs ​===+=== 2.3. Re-build linux.itb ​===
  
-If you wish to enter your newly bootstrapped Debian ​rootfs, ​you can use the following script:+Since we'll be running the rootfs ​on a separate partition from now onwe eliminated the Bootstrap CPIO (''​initrd'' ​ nodes) from the Linux uImage. Check out ''​staging/​linux-noinitrd.its''​ and use the ''​staging/​Makefile''​ included inside the skeleton to rebuild the ''​.itb''​!
  
-<file bash enter-rootfs.sh> +=== 2.4. Create the base disk image for testing ===
-#​!/​bin/​bash +
-set -e+
  
-ROOTFS=$1+📄 File: ''​mk-disk-image.sh'':​ modify it, set a bigger image size (e.g., ''​1500''​ MB) and configure it to unpack the ''​debian-rootfs.tar''​ on the second partition.
  
-if [[ -z "​$ROOTFS"​ ]] || [[ ! -d "​$ROOTFS/​usr/​bin"​ ]]; then +<note hint> 
-    echo "[!] Invalid rootfs argument: ​'$ROOTFS'" +Note: you have two versions ''​mk-disk-image.sh'' ​ scriptsFor now, we'll just use the first version (having a simple fat32+ext4 partition layout), when we get to run RAUC, we'll use the second one! 
-    exit 1 +</​note>​
-fi+
  
-cleanup() { +After modification,​ run the script to obtain the disk image.
-    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..."​ +But before booting the board, we must do some minor re-configuration to our u-boot...
-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"​ +=== 2.5. Bootloader ​[re]configuration ===
-sudo cp /​etc/​resolv.conf "​$ROOTFS/​etc/​resolv.conf"​+
  
-echo "[+] Entering your chroot shell..." +You'll need the mainline u-boot for this taskSimply delete your ''​u-boot''​ directory (do backup your configs, if you want) and use the ''​Makefile''​ provided for lab02 (also found inside today'​s archive) to build & properly reconfigure a full Firmware Image Package.
-echo "Type exit to leave"​ +
-sudo chroot "​$ROOTFS"​ /​usr/​bin/​qemu-aarch64-static /bin/bash +
-</​file>​+
  
-You can even run ''​apt install''​ in there ;+Note the new configuration options inside ''​uboot-extra.config''​ and the default environment variables in ''​new-default.env''​. 
 + 
 +Now we can power up the board! Use ''​uuu -b spl flash.bin''​ and enter U-Boot. Let ''​fastboot 0''​ start and use ''​fastboot flash 0:0 disk.img''​ to quickly burn the image. After the flashing finishes, use Ctrl+C on u-boot to exit fastboot mode and ''​run linux''​
 + 
 +<note warning>​ 
 +**Now pay attention:​** after testing it using ''​uuu -b spl''​ ,make a backup of this ''​flash.bin''​ file! You'll need it later to start the board with RAUC autoboot disabled, as the one you'll build in the following section will not work (it will override the boot command and become unable to use ''​fastboot''​ / ''​ums''​!). E.g., copy & name this file as ''​flash_spl.bin''​! 
 +</​note>​
  
  
ass/labs-2025/04/tasks/02.1754589269.txt.gz · 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