Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic #26

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ This is taken from the NVIDIA Jetson AGX Xavier forum https://forums.developer.n

This procedure should be done on a fresh install of the SD card using JetPack 4.3+. Install the SSD into the M.2 Key M slot of the Jetson, and format it gpt, ext4, and setup a partition (p1). The AGX Xavier uses eMMC, the Xavier NX uses a SD card in the boot sequence.

Next, copy the rootfs of the eMMC/SD card to the SSD
Next, copy the rootfs of the eMMC/SD card to the device (nvme/usb)
```
$ ./copy-rootfs-ssd.sh
$ ./copy-rootfs-ssd.sh <usb|nvme>
```

Then, setup the service. This will copy the .service file to the correct location, and install a startup script to set the rootfs to the SSD.
Then, setup the service. This will copy the .service file to the correct location, and install a startup script to set the rootfs to the device.
```
$ ./setup-service.sh
$ ./setup-service.sh <usb|nvme>
```

After setting up the service, reboot for the changes to take effect.
Expand Down
28 changes: 23 additions & 5 deletions copy-rootfs-ssd.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
#!/bin/bash
# Mount the SSD as /mnt
sudo mount /dev/nvme0n1p1 /mnt
# Copy over the rootfs from the SD card to the SSD

if [ "$#" -ne 1 ]; then
echo "Usage: $0 <nvme|usb>"
exit 1
fi

device_type=$1
device_path=""

if [ "$device_type" == "nvme" ]; then
device_path="/dev/nvme0n1p1"
elif [ "$device_type" == "usb" ]; then
device_path="/dev/sda1"
else
echo "Invalid device type. Supported types: nvme, usb"
exit 1
fi

# Mount the device as /mnt
sudo mount $device_path /mnt
# Copy over the rootfs from the SD card to the device
sudo rsync -axHAWX --numeric-ids --info=progress2 --exclude={"/dev/","/proc/","/sys/","/tmp/","/run/","/mnt/","/media/*","/lost+found"} / /mnt
# We want to keep the SSD mounted for further operations
# So we do not unmount the SSD
# We want to keep the device mounted for further operations
# So we do not unmount the device
3 changes: 1 addition & 2 deletions data/setssdroot.service
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
[Unit]
Description=Change rootfs to SSD in M.2 key M slot (nvme0n1p1)
Description=Change rootfs to SSD or USB
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
ConditionPathExists=/etc/setssdroot.conf
ConditionVirtualization=!container
[Service]
Expand Down
19 changes: 15 additions & 4 deletions data/setssdroot.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
#!/bin/sh
# Runs at startup, switches rootfs to the SSD on nvme0 (M.2 Key M slot)
NVME_DRIVE="/dev/nvme0n1p1"
CHROOT_PATH="/nvmeroot"
# Runs at startup, switches rootfs to the SSD or USB

CHROOT_PATH="/newroot"
INITBIN=/lib/systemd/systemd
EXT4_OPT="-o defaults -o errors=remount-ro -o discard"

DEVICE_TYPE=$(grep -Po '(?<=DEVICE_TYPE=).*' /etc/setssdroot.conf)
DRIVE=""

if [ "$DEVICE_TYPE" == "nvme" ]; then
DRIVE="/dev/nvme0n1p1"
elif [ "$DEVICE_TYPE" == "usb" ]; then
DRIVE="/dev/sda1"
else
echo "Invalid device type in /etc/setssdroot.conf. Supported types: nvme, usb"
exit 1
fi

modprobe ext4

mkdir -p ${CHROOT_PATH}
mount -t ext4 ${EXT4_OPT} ${NVME_DRIVE} ${CHROOT_PATH}
mount -t ext4 ${EXT4_OPT} ${DRIVE} ${CHROOT_PATH}

cd ${CHROOT_PATH}
/bin/systemctl --no-block switch-root ${CHROOT_PATH}
15 changes: 14 additions & 1 deletion setup-service.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
#!/bin/sh

if [ "$#" -ne 1 ]; then
echo "Usage: $0 <nvme|usb>"
exit 1
fi

device_type=$1

if [ "$device_type" != "nvme" ] && [ "$device_type" != "usb" ]; then
echo "Invalid device type. Supported types: nvme, usb"
exit 1
fi

# Setup the service to set the rootfs to point to the SSD
sudo cp data/setssdroot.service /etc/systemd/system
sudo cp data/setssdroot.sh /sbin
Expand All @@ -13,7 +26,7 @@ sudo cp /sbin/setssdroot.sh /mnt/sbin/setssdroot.sh
# Create setssdroot.conf which tells the service script to set the rootfs to the SSD
# If you want to boot from SD again, remove the file /etc/setssdroot.conf from the SD card.
# touch creates an empty file
sudo touch /etc/setssdroot.conf
sudo bash -c "echo 'DEVICE_TYPE=$device_type' > /etc/setssdroot.conf"
echo 'Service to set the rootfs to the SSD installed.'
echo 'Make sure that you have copied the rootfs to SSD.'
echo 'Reboot for changes to take effect.'
Expand Down