Making Custom Linux Image

1. Use gparted to shrink the partition as much as possible (optionally use sfill / zerofree beforehand, which may not help)

sudo gparted

2.Use fdisk to check the end position

sudo fdisk -l /dev/sdb

Disk out.img: 1.5 GiB, 1605369856 bytes, 3135488 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x562fb1a7

Device Boot Start End Sectors Size Id Type
out.img1 8192 137215 129024 63M c W95 FAT32 (LBA)
out.img2 137216 3135487 2998272 1.4G 83 Linux

3. use dd with sparse parameter, to transfer all the content in both filesystems

sudo dd if=/dev/sdb of=/home/airo-ubuntu/out.img conv=sparse bs=512 count=$[3135487 + 1]

4. use fisk again to check integrity

fdisk -lu out.img

Disk out.img: 1.5 GiB, 1605369856 bytes, 3135488 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x562fb1a7

Device Boot Start End Sectors Size Id Type
out.img1 8192 137215 129024 63M c W95 FAT32 (LBA)
out.img2 137216 3135487 2998272 1.4G 83 Linux

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

Up ↑

%d bloggers like this: