Skip to content

Instantly share code, notes, and snippets.

@changx03
Created January 15, 2024 00:05
Show Gist options
  • Save changx03/c1f5a89cf6088421af94e8641d7b5ac1 to your computer and use it in GitHub Desktop.
Save changx03/c1f5a89cf6088421af94e8641d7b5ac1 to your computer and use it in GitHub Desktop.

Create a clone image from a disk

Check device location:

lsblk 

Step 1: Copy image to drive

NOTE: Instructions for working with compressed file are down the bottom

If the disk isn't the same size as the image, the disk will not work after cloning.

IMG="jetson-orin.img" 

DEVICE="/dev/sda" 

PARTITION_NUM="1" 

sudo dd if=$IMG of=$DEVICE bs=4096 status=progress 

Step 2: Unmount partition (if needed)

sudo umount $DEVICE$PARTITION_NUM 

Step 3: Expand partition

Open Parted:

sudo parted $DEVICE 

Inside parted:

(parted) print 

It will ask:

Error: The backup GPT table is not at the end of the disk, as it should be. Fix, by moving the backup to the end (and removing the old backup)?

Fix/Ignore?

Type:

fix 

Warning: Not all of the space available to /dev/sda appears to be used, you can fix the GPT to use all of the space (an extra 1703455494 blocks) or

continue with the current setting?

Fix/Ignore?

Type:

fix 

Check the Number of Partition: App, it should be 1.

Inside parted:

(parted) resizepart 1 100% 

1 is for partition Number 1, and 100% is for using 100% of the remaining disk.

NOTE: this operation is done instance, because it does not update the partition table!

Quit the parted app

(parted) quit 

Step 4: Fix partition table

Check and correct inconsistencies after resizing

sudo e2fsck -fp $DEVICE$PARTITION_NUM 
  • -f for force checking

  • -p for automatic repair

If the app reports an error and suggests to run -b <SUPERBLOCK>, run the following based on the outputs:

sudo e2fsck -b 32768 $DEVICE$PARTITION_NUM 

Expand the partition

sudo resize2fs $DEVICE$PARTITION_NUM 

Check results

Once everything is done, you can use Disks to mount the App partition to check if it works as intended.

Check mounted drives:

df -h 

-h for human-readable

Working with compressed file

The 120GB drive will compress into a 30GB .gz file.

The compression speed is 70-80MB/s and the write speed is 270MB/s.

To create the compressed image:

sudo dd if=/dev/sda status=progress | gzip -1 > ./jetson-orin.img.gz 

-1 for fastest compression

To a clone compressed image to a drive (note you can use 'gunzip –c' instead of zcat on osx):

zcat ./jetson-orin.img.gz | sudo dd of=/dev/sda bs=4096 status=progress 

Other commands

To check block size:

stat -f ~ 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment