Expand Raspbian Partition

From KlavoWiki
Jump to navigationJump to search

Modify Partition

I usually expand the partition to 4GB form the default 2GB so I can re-image my installs. Once I've finished building my image I then expand the partition to maximum using the raspi-cofig utility.

  • Delete partition 2. Making notice of where it starts.
  • Create a new primary partition with the same starting block and finish at block 8388608
fdisk /dev/mmcblk0

Before

Disk /dev/mmcblk0: 29.91 GiB, 32111591424 bytes, 62717952 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: 0x0ee3e8a8

Device         Boot  Start     End Sectors  Size Id Type
/dev/mmcblk0p1        8192  532479  524288  256M  c W95 FAT32 (LBA)
/dev/mmcblk0p2      532480 3907583 3375104  1.6G 83 Linux

After

Disk /dev/mmcblk0: 29.91 GiB, 32111591424 bytes, 62717952 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: 0x0ee3e8a8

Device         Boot  Start     End Sectors  Size Id Type
/dev/mmcblk0p1        8192  532479  524288  256M  c W95 FAT32 (LBA)
/dev/mmcblk0p2      532480 8388608 7856129  3.7G 83 Linux


Expand New Partiion

resize2fs /dev/mmcblk0p2

Output

resize2fs 1.46.2 (28-Feb-2021)
Filesystem at /dev/mmcblk0p2 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/mmcblk0p2 is now 982016 (4k) blocks long.