Skip to content

Instantly share code, notes, and snippets.

@Miouyouyou
Last active May 14, 2023 15:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Miouyouyou/e78f4caa9ce3fea72430dca57a00449b to your computer and use it in GitHub Desktop.
Save Miouyouyou/e78f4caa9ce3fea72430dca57a00449b to your computer and use it in GitHub Desktop.
Boot on SDCard, mount NVMe root partition and use it for the whole system, on a NanoPC T4

Moving most of the system (but not the kernel) onto a NVME disk

This document describes how to make the system :

  • boot on a SDCARD
  • load the kernel from the SDCARD
  • mount a NVMe partition as /
  • use / for the whole system and applications

In this document folder and directory mean the same thing.

The whole idea is to be able to edit the boot files easily (kernel, boot configuration, ...) in case something goes wrong, while benefiting from NVMe read/write speeds for you daily application usage.

The procedure described is not "THE BEST", just the one I used that worked in my case.

Here are the steps I followed to do that :

  1. Prepare a SDCARD with an Armbian image, using Etcher.
  2. Install a NVMe M.2 disk on the rear side of the NanoPC T4.
  3. Put the SDCARD in the NanoPC T4 SDCARD slot.
  4. Boot Armbian and configure your first user.
    Note : The 'root' account password is 1234 on first boot
  5. Create a "Linux root (ARM 64)" partition (and maybe a swap partition if you want) on the NVMe disk.
    Note : Linux root (ARM 64) ID is B921B045-1DF0-41C3-AF44-4C6F280D3FAE Note : The disk can be accessed through /dev/nvme0n1
    Note : I used cfdisk for that matter, but any decent partitioning software will do.
  6. Mount your NVMe root partition on /mnt. For example, if you just made one partition, the device node will be : /dev/nvme0n1p1 and so the command will be :
    mount /dev/nvme0n1p1 /mnt
  7. Mount your NVMe root partition on /mnt.
    For example, if you just made one partition, the device node will be : /dev/nvme0n1p1 and so the command will be : mount /dev/nvme0n1p1 /mnt
  8. Do a filesystem copy of / into /mnt, while ignoring special files created on boot-time :
    rsync -a -H --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} / /mnt
  9. Use blkid on your NVMe root partition to get its UUID.
    For example, if you just made one partition, the device node will be : /dev/nvme0n1p1. And so the command will be :
    blkid /dev/nvme0n1p1
    In my case, the command output was : /dev/nvme0n1p1: UUID="cbe70e76-9690-4f69-ab6e-23b887531628" TYPE="ext4" PARTUUID="c4a2536b-5092-0b4b-8178-c4215a52ac4b"
  10. Edit /mnt/etc/fstab and replace the UUID part of the line about / by the UUID of your NVMe root partition, that you just got from the last command.
    The line in question is somewhat like this :
    UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx / ext4 defaults,noatime,nodiratime,commit=600,errors=remount-ro 0 1
    In my case, I modified it so that it looked like this : UUID=cbe70e76-9690-4f69-ab6e-23b887531628 / ext4 defaults,noatime,nodiratime,commit=600,errors=remount-ro 0 1
  11. Do a copy of /boot/armbianEnv.txt like this :
    cp /boot/armbianEnv.txt /boot/armbianEnv.working
  12. Edit /boot/armbianEnv.txt and replace the UUID in the line rootdev=UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx by the UUID of your NVMe root partition.
    In my case, the line was modified like this :
    rootdev=UUID=cbe70e76-9690-4f69-ab6e-23b887531628
  13. Reboot and see if it worked.

If it didn't, you'll have to remove the SDCard from the NanoPC T4, read it from a Linux PC, mount the boot partition, delete boot/armbianEnv.txt and copy boot/armbianEnv.working over boot/armbianEnv.txt. Then you'll be able to retry the procedure from the point were we get the UUID of the NVMe partition (step 7).

If it works, though, it's not finished ! In order to make kernel upgrades possible, we'll have to link the NVMe root partition /boot folder to the SDCard root partition /boot folder.

  1. Use blkid on your SDCard root partition, in order to get its UUID.
    blkid /dev/mmcblk1p1 In my case the output was :
    /dev/mmcblk1p1: UUID="c5dcbfc7-886b-4c98-ac2a-4d26eec089e8" TYPE="ext4" PARTUUID="d808ef5d-01"
  2. Create a directory /sdcard : mkdir /sdcard
  3. Do a backup of your /etc/fstab : cp /etc/fstab /etc/working_fstab
  4. Add an entry to /etc/fstab to mount the content of the SDCard boot partition to /sdcard automatically.
    In my case the UUID of that partition was c5dcbfc7-886b-4c98-ac2a-4d26eec089e8 so the line added was :
    UUID=c5dcbfc7-886b-4c98-ac2a-4d26eec089e8 /sdcard ext4 defaults,noatime,nodiratime,commit=600,nodev,noexec 0 1
    Adapt according to your configuration.
  5. Test your /etc/fstab configuration by doing : mount /sdcard
    If that doesn't work, check back your /etc/fstab.
    If you messed up, cp /etc/working_fstab /etc/fstab
  6. Backup the /boot directory : mv /boot /unused_boot
  7. Link your SDCard boot partition boot folder to /boot : ln -s /sdcard/boot /boot
  8. Reboot one last time

And now you should be able to upgrade your kernel while booted on your NVMe disk, while still being able to access the upgrade kernel and boot configuration from the SDCard.
This is very useful when a kernel upgrade broke your system. That way, you just have to remove the SDCard, read it from a Linux computer, replace the broken kernel or edit /etc/armbianEnv.txt to boot temporarily on the SDCARD in order to repair the issue.

Improvements

  • /sdcard should only be mounted when boot files have to be updated. This avoid softwares trying to access the SDCard for no reasons.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment