Enlarge disk partition image
Source:
- http://sirlagz.net/2012/06/20/how-to-resize-partitions-on-an-image-file/
- http://sirlagz.net/2013/03/04/how-to-resize-partitions-in-an-image-file-part-2/
Create a device for the original image, note the /dev/loop20:
sudo losetup -f --show org_partition.img /dev/loop20
Create file of a size you want (here 4500M)
dd bs=1M count=4500 if=/dev/zero of=new_partition.img
Create a device for the image, again, note the new /dev/loop21
sudo losetup -f --show new_partition.img /dev/loop21
Copy data from the original image to the empty image, if=source, of=destination (PROCEED WITH CAUTION):
sudo dd if=/dev/loop20 of=/dev/loop21 7761920+0 records in 7761920+0 records out 3974103040 bytes (4,0 GB, 3,7 GiB) copied, 46,4243 s, 85,6 MB/s
Check and fix:
sudo e2fsck -f /dev/loop21 Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/loop21: 137651/242880 files (0.2% non-contiguous), 883034/970240 blocks
Start parted with the new device selected:
sudo parted /dev/loop21
(parted) print Model: Loopback device (loopback) Disk /dev/loop21: 4719MB Sector size (logical/physical): 512B/512B Partition Table: loop Disk Flags:
Number Start End Size File system Flags 1 0,00B 4719MB 4719MB ext4 (parted) quit
Disconnect the devices:
sudo losetup -d /dev/loop20 sudo losetup -d /dev/loop21
Fat32 max file size
Files on a Fat32 partition have a maximum size of 4GB. If you try to copy a larger file to a Fat32 system you may not always receive a warning beforehand (like when copying over a network). Then it will fail with a disk I/O error at the size limit.
Too be exact:
(4 GiB - 2) bytes = (4 * 1024 * 1024 * 1024 - 2) bytes = (4,294,967,296 - 2) bytes
If we want 512-byte blocks the maximum is:
(4,294,967,296 - 2) / 512 rounds down to 8,388,607 blocks of 512 bytes.
dd bs=512 count=8388607 if=/dev/zero of=new_partition.img