# chmod +x backup_jetson_nano_64GB_img.sh
sudo ./backup_jetson_nano_64GB_img.sh jetson.img /dev/sdX
# Run without arguments to show help
# ./backup_jetson_nano_64GB_img.sh
Cloning a Jetson Nano SD card with dd
creates a full-size image — but not all SD cards labeled with the same size have the identical usable capacity. Some may be a few megabytes smaller, which will lead to the flashing error : Target device is too small.
On the other hand, if you flash the image to the larger SD card(e.g. from 64 GB to 128 GB), The system is likely to fail to boot.
This guide shows how to safely trim the unused space at the end of the imae, align it properly, and fix GPT headers — so your .img
backup can be reliably flashed to other SD cards of the same advertised size (e.g. 64GB) using Etcher or dd
.
零. Full backup SD card to .img
lsblk -dpno NAME,SIZE,MODEL | grep -Ev 'loop|nvme|sda|boot'
/dev/sdb 58.2G SD/MMC
In this case, the SD card is /dev/sdb
.
Create a full image backup:
sudo dd if=/dev/sdb of=jetson_backup.img bs=16M status=progress conv=fsync
Replace /dev/sdX
with your SD card device. You can rename jetson_backup.img
as needed.
壹. Shrink main partition and truncate the image size
sudo losetup -Pf --show jetson_backup.img
/dev/loop47
sudo gparted /dev/loop47
To shrink the largest ext4 partition (usually labeled "APP" — typically the root partition in Jetson Nano images), follow the steps below:
-
Right-click on the
APP
partition (such as/dev/loop47p1
, ext4, 59.51 GiB in the screenshot). Select "Resize/Move" from the context menu.
-
In the "Resize/Move" dialog:
-
Set "Free space following (MiB)" to
8192
(i.e., 8 GiB). Do NOT change "Free space preceding(MiB)" value.
-
Click the "Resize/Move" button to return to the main GParted window and confirm the change.
-
Go to Edit → Apply All Operations to apply the shrink operation.
sudo losetup -d /dev/loop47
貳. Extend image by 1 MB buffer and align to 512 bytes
sudo parted jetson_backup.img unit B print
Number Start End Size File system Name 1 14680064B 63892881407B 63878201344B ext4 APP
63892881407
.# Add 1MB buffer (1,048,576 bytes) # 63892881407 + 1048576 = 63893929983 sudo truncate -s 63893929983 jetson_backup.img
sudo truncate -s $(( ( $(stat -c %s jetson_backup.img) / 512 + 1 ) * 512 )) \ jetson_backup.img
參. Fix GPT backup header and verify partition table
sudo gdisk jetson_backup.img
w y
sudo gdisk -l jetson_backup.img sudo fdisk -l jetson_backup.img
肆. (Optional) Compress image
zip -9 -v jetson_backup.img.zip jetson_backup.img
rm jetson_backup.img
補說. Flash the image to the SD card and fully use its capacity.
You can flash either the .img or .img.zip file using:
Etcher (balenaEtcher)
sudo dd if=jetson_backup.img of=/dev/sdX bs=16M status=progress conv=fsync
sudo sgdisk -e /dev/sdX # Relocate the GPT backup header
sudo growpart /dev/sdX 1 # Expand the APP partition sudo resize2fs -f /dev/sdX1 # Resize the ext4 filesystem sudo gdisk -l /dev/sdX # Verify that GPT looks correct
沒有留言:
張貼留言