From 3fdcb30f352dec80bafbb6ee43286d8a4432f41a Mon Sep 17 00:00:00 2001 From: LinirZamir Date: Tue, 21 Mar 2023 13:42:42 -0400 Subject: [PATCH 1/6] Update copy-rootfs-ssd.sh --- copy-rootfs-ssd.sh | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/copy-rootfs-ssd.sh b/copy-rootfs-ssd.sh index 5a3e026..f8c0940 100755 --- a/copy-rootfs-ssd.sh +++ b/copy-rootfs-ssd.sh @@ -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 " + 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 From 7dbb59cd38af7bf45bf5a43b1a02922c30225992 Mon Sep 17 00:00:00 2001 From: LinirZamir Date: Tue, 21 Mar 2023 13:43:15 -0400 Subject: [PATCH 2/6] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6161fd7..d9d3ff0 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,9 @@ 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 SSD (nvme/usb) ``` -$ ./copy-rootfs-ssd.sh +$ ./copy-rootfs-ssd.sh ``` 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. From a86fba8c568457db5a7313841e537cb578a9336c Mon Sep 17 00:00:00 2001 From: Linir Zamir Date: Tue, 21 Mar 2023 14:01:55 -0400 Subject: [PATCH 3/6] Updated setup-service --- data/setssdroot.service | 3 +-- data/setssdroot.sh | 19 +++++++++++++++---- setup-service.sh | 15 ++++++++++++++- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/data/setssdroot.service b/data/setssdroot.service index d3f2942..d053a3c 100644 --- a/data/setssdroot.service +++ b/data/setssdroot.service @@ -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] diff --git a/data/setssdroot.sh b/data/setssdroot.sh index e91c4ac..d698eb1 100755 --- a/data/setssdroot.sh +++ b/data/setssdroot.sh @@ -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} diff --git a/setup-service.sh b/setup-service.sh index 06845a5..8b83afc 100755 --- a/setup-service.sh +++ b/setup-service.sh @@ -1,4 +1,17 @@ #!/bin/sh + +if [ "$#" -ne 1 ]; then + echo "Usage: $0 " + 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 @@ -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.' From 17f64afa25fc180560aa041658483da89922ff36 Mon Sep 17 00:00:00 2001 From: Linir Zamir Date: Tue, 21 Mar 2023 14:02:47 -0400 Subject: [PATCH 4/6] updated readme --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d9d3ff0..4b10a04 100644 --- a/README.md +++ b/README.md @@ -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 (nvme/usb) +Next, copy the rootfs of the eMMC/SD card to the device (nvme/usb) ``` $ ./copy-rootfs-ssd.sh ``` -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 ``` After setting up the service, reboot for the changes to take effect. From fe2c4c8e24e3d5b4a9293a60c91a92fbceaa3294 Mon Sep 17 00:00:00 2001 From: Linir Zamir Date: Tue, 21 Mar 2023 14:31:20 -0400 Subject: [PATCH 5/6] change setup service --- setup-service.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup-service.sh b/setup-service.sh index 8b83afc..c957a17 100755 --- a/setup-service.sh +++ b/setup-service.sh @@ -15,6 +15,8 @@ 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 +sudo bash -c "echo 'DEVICE_TYPE=$device_type' > /etc/setssdroot.conf" + sudo chmod 777 /sbin/setssdroot.sh systemctl daemon-reload sudo systemctl enable setssdroot.service @@ -26,7 +28,6 @@ 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 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.' From 7f09402b187bd70ca486c1c4ec846d785983ae98 Mon Sep 17 00:00:00 2001 From: Linir Zamir Date: Tue, 21 Mar 2023 14:47:11 -0400 Subject: [PATCH 6/6] small fixes --- setup-service.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/setup-service.sh b/setup-service.sh index c957a17..8b83afc 100755 --- a/setup-service.sh +++ b/setup-service.sh @@ -15,8 +15,6 @@ 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 -sudo bash -c "echo 'DEVICE_TYPE=$device_type' > /etc/setssdroot.conf" - sudo chmod 777 /sbin/setssdroot.sh systemctl daemon-reload sudo systemctl enable setssdroot.service @@ -28,6 +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 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.'