How to Boot from NVMe SSD?

Hi,
I have modified furushchev’s solution in “true” systemd way and become able to mount SSD drive as rootfs without overlay and reboot problems.

  1. Xavier was flashed and software was installed using SDKManager.
  2. Rootfs from eMMC was copied to SSD ( with one ext4 partition in my case):
    #!/bin/bash
    sudo mount /dev/nvme0n1p1 /mnt
    sudo rsync -aAXv / --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} /mnt
    
  3. Then we need systemd unit, loading just after unmounting initrd image and mounting real rootfs, before any other targets running with systemd from real rootfs. Something like following: setssdroot.service:
    [Unit]
    Description=Change rootfs to SSD in M.2 key M slot (nvme0n1p1)
    DefaultDependencies=no
    Conflicts=shutdown.target
    After=systemd-remount-fs.service
    Before=local-fs-pre.target local-fs.target shutdown.target
    Wants=local-fs-pre.target
    ConditionPathExists=/dev/nvme0n1p1
    ConditionVirtualization=!container
    
    [Service]
    Type=oneshot
    RemainAfterExit=yes
    ExecStart=/sbin/setssdroot.sh
    
    [Install]
    WantedBy=default.target
    

    I added condition to start only if SSD is installed ( /dev/nvme0n1p1 exists).

    setssdroot.sh:

    #!/bin/sh
    NVME_DRIVE="/dev/nvme0n1p1"
    CHROOT_PATH="/nvmeroot"
    
    INITBIN=/lib/systemd/systemd
    EXT4_OPT="-o defaults -o errors=remount-ro -o discard"
    
    modprobe ext4
    #modprobe fuse
    
    mkdir -p ${CHROOT_PATH}
    mount -t ext4 ${EXT4_OPT} ${NVME_DRIVE} ${CHROOT_PATH}
    
    cd ${CHROOT_PATH}
    /bin/systemctl --no-block switch-root ${CHROOT_PATH}
    
  4. New target was installed with following command:
    #!/bin/sh
    sudo cp setssdroot.service /etc/systemd/system
    sudo cp setssdroot.sh /sbin
    sudo chmod 777 /sbin/setssdroot.sh
    systemctl daemon-reload
    sudo systemctl enable setssdroot.service
    

As a result, after reboot systemd mounts /dev/nvme0n1p1 as “/”. We are working with system (except kernel and initrd) from SSD and have “recovery” system on eMMC.

4 Likes