Enlarge disk partition image: Difference between revisions

From WickyWiki
Created page with "Category:Ubuntu Category:Ubuntu System Category:Raspberry Pi Category:201810 Source: * http://sirlagz.net/2012/06/20/how-to-resize-partitions-on-an-image-file..."
 
mNo edit summary
 
(10 intermediate revisions by the same user not shown)
Line 16: Line 16:
</syntaxhighlight>
</syntaxhighlight>


Create file of a size you want (here 4500M)
Create file of a size you want (here 4500M) check your medium [[Disk type maximum file size‎]]


<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
Line 40: Line 40:
</syntaxhighlight>
</syntaxhighlight>


Check and fix:
Disconnect the devices:


<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
sudo e2fsck -f /dev/loop21
sudo losetup -d /dev/loop20
sudo losetup -d /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
</syntaxhighlight>
</syntaxhighlight>


Start parted with the new device selected:
Resize the filesystem to available space:
 
<syntaxhighlight lang=bash>
resize2fs -f new_partition.img


<syntaxhighlight lang=bash>
  Resizing the filesystem on new_partition.img to 1152000 (4k) blocks.
sudo parted /dev/loop21
  The filesystem on new_partition.img is now 1152000 (4k) blocks long.
</syntaxhighlight>
</syntaxhighlight>


(parted) print
Check and allow the tool to fix errors:
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
<syntaxhighlight lang=bash>
1      0,00B 4719MB 4719MB ext4
e2fsck -f new_partition.img
(parted) quit
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
  Block bitmap differences: -(531654--531655) -(532478--532479) -(857474--858485)
  Fix<y>? yes
Free blocks count wrong for group #16 (815, counted=819).
Fix<y>? yes
</syntaxhighlight>


Disconnect the devices:
= See also =


<syntaxhighlight lang=bash>
* [[Disk type maximum file size‎]]
sudo losetup -d /dev/loop20
* [[Shrink disk partition image]]
sudo losetup -d /dev/loop21
</syntaxhighlight>

Latest revision as of 22:13, 20 December 2018


Source:

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) check your medium Disk type maximum file size‎

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

Disconnect the devices:

	 
sudo losetup -d /dev/loop20
sudo losetup -d /dev/loop21

Resize the filesystem to available space:

	 
resize2fs -f new_partition.img

  Resizing the filesystem on new_partition.img to 1152000 (4k) blocks.
  The filesystem on new_partition.img is now 1152000 (4k) blocks long.

Check and allow the tool to fix errors:

e2fsck -f new_partition.img
 
 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
 Block bitmap differences:  -(531654--531655) -(532478--532479) -(857474--858485)
 Fix<y>? yes
 Free blocks count wrong for group #16 (815, counted=819).
 Fix<y>? yes

See also