Looking to freely switch the root partition

Ask questions about Arch Linux ARM. Please search before making a new topic.

Looking to freely switch the root partition

Postby thepope » Sat Jan 15, 2022 5:48 am

Hello,

I made an SD card for a Cubieboard. Arch boots fine.

What I want to do is be able to have it boot from a different drive, like a USB drive. As far as I know, Cubieboards only boot from SD or their internal memory, but the rest of the install can be wherever.
I don't know how to keep Arch booting from the (micro)SD card I created, but use a different drive for the root partition. I know that partitions like root, swap and boot are declared in /etc/fstab, but that file from this Arch stage3 file is empty.
Instead, the boot.scr script seems to do something with UUID codes or partition UUID codes. I don't understand that code, despite only having a few lines:

Code: Select all
if test -n ${distro_bootpart}; then setenv bootpart ${distro_bootpart}; else setenv bootpart 1; fi
part uuid ${devtype} ${devnum}:${bootpart} uuid

setenv bootargs console=${console} root=PARTUUID=${uuid} rw rootwait

if load ${devtype} ${devnum}:${bootpart} ${kernel_addr_r} /boot/zImage; then
  if load ${devtype} ${devnum}:${bootpart} ${fdt_addr_r} /boot/dtbs/${fdtfile}; then
    if load ${devtype} ${devnum}:${bootpart} ${ramdisk_addr_r} /boot/initramfs-linux.img; then
      bootz ${kernel_addr_r} ${ramdisk_addr_r}:${filesize} ${fdt_addr_r};
    else
      bootz ${kernel_addr_r} - ${fdt_addr_r};
    fi;
  fi;
fi


I'm sure it must be possible to juggle with multiple Arch (ARM) installs on the same device, so with the same devicetree file. I just don't know where the root partition is declared.

Also, I looked around for people with the same question, and only found this. He has a Raspberry Pi, with a cmdline.txt which the Cubieboard doesn't have.
thepope
 
Posts: 3
Joined: Sat Jan 15, 2022 2:02 am

Re: Looking to freely switch the root partition

Postby moonman » Sat Jan 15, 2022 9:31 am

Replace ${uuid} with partuuid (not UUID of the filesystem) of your new rootfs partition in
Code: Select all
setenv bootargs console=${console} root=PARTUUID=${uuid} rw rootwait

then run mkscr

You can find out partuuid of partitions with "blkid" command. It will still be loading the kernel from the sd card so make sure to bind mount directory where the kernel is on the sd card to the same directory on your new rootfs so that the kernel will get updated by pacman.
Pogoplug V4 | GoFlex Home | Raspberry Pi 4 4GB | CuBox-i4 Pro | ClearFog | BeagleBone Black | Odroid U2 | Odroid C1 | Odroid XU4
-----------------------------------------------------------------------------------------------------------------------
[armv5] Updated U-Boot | [armv5] NAND Rescue System
moonman
Developer
 
Posts: 3367
Joined: Sat Jan 15, 2011 3:36 am

Re: Looking to freely switch the root partition

Postby thepope » Sun Jan 16, 2022 12:40 am

Thank you for that. I thought it would be something quite simple.

Another simple problem: the laptop from which I'm typing doesn't have mkscr.

I tried to google the problem and it seems the command comes with the AUR package uboot-sunxi. And that failed to compile!
thepope
 
Posts: 3
Joined: Sat Jan 15, 2022 2:02 am

Re: Looking to freely switch the root partition

Postby moonman » Sun Jan 16, 2022 1:52 am

Sorry, I don't have cubieboard nor am I familiar with its quirks. I thought you had the original txt file for U-Boot boot script which usually comes with U-Boot package.

Either way you can copy-paste the following into boot.txt file
Code: Select all
# After modifying, run ./mkscr

if test -n ${distro_bootpart}; then setenv bootpart ${distro_bootpart}; else setenv bootpart 1; fi
part uuid ${devtype} ${devnum}:${bootpart} uuid

setenv bootargs console=${console} root=PARTUUID=${uuid} rw rootwait

if load ${devtype} ${devnum}:${bootpart} ${kernel_addr_r} /boot/zImage; then
  if load ${devtype} ${devnum}:${bootpart} ${fdt_addr_r} /boot/dtbs/${fdtfile}; then
    if load ${devtype} ${devnum}:${bootpart} ${ramdisk_addr_r} /boot/initramfs-linux.img; then
      bootz ${kernel_addr_r} ${ramdisk_addr_r}:${filesize} ${fdt_addr_r};
    else
      bootz ${kernel_addr_r} - ${fdt_addr_r};
    fi;
  fi;
fi


Modify the above to your liking, then run
Code: Select all
mkimage -A arm -O linux -T script -C none -n "U-Boot boot script" -d boot.txt boot.scr

mkimage is part of uboot-tools package.

mkscr is just a script https://github.com/archlinuxarm/PKGBUIL ... line/mkscr
Pogoplug V4 | GoFlex Home | Raspberry Pi 4 4GB | CuBox-i4 Pro | ClearFog | BeagleBone Black | Odroid U2 | Odroid C1 | Odroid XU4
-----------------------------------------------------------------------------------------------------------------------
[armv5] Updated U-Boot | [armv5] NAND Rescue System
moonman
Developer
 
Posts: 3367
Joined: Sat Jan 15, 2011 3:36 am

Re: Looking to freely switch the root partition

Postby thepope » Sun Jan 16, 2022 2:37 am

Ah, thank you! Finally everything makes sense.

Yes, it compiled the modified boot.txt into boot.scr, then I was able to boot from a different device. This seems like a very powerful nifty tool - I can overwrite Arch's default zImage kernel and the initramfs, I can point to a different root partition to boot, so Arch's Cubieboard installation is completely customizable. I'm guessing this can be done on any supported platform and even some unknowingly supported ones.

Chinese TV boxes, here I come :D
thepope
 
Posts: 3
Joined: Sat Jan 15, 2022 2:02 am


Return to User Questions

Who is online

Users browsing this forum: No registered users and 2 guests