Growing the RPi root partition

After flashing the Arch image onto the SD-Card the partition scheme looks like this:

[jan@espresso ~]$ sudo fdisk /dev/mmcblk0
Welcome to fdisk (util-linux 2.23.1).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): p

Disk /dev/mmcblk0: 31.7 GB, 31674335232 bytes, 61863936 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
Disk label type: dos
Disk identifier: 0x00057540

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1            2048      186367       92160    c  W95 FAT32 (LBA)
/dev/mmcblk0p2          186368     3667967     1740800    5  Extended
/dev/mmcblk0p5          188416     3667967     1739776   83  Linux

There’s 3 partitions where the first is obviously used for boot and the second an extended partition to overcome the 4 partition limit the 3 one is just 1781 MB in size.

In order to change that delete partition 2:

Command (m for help): d
Partition number (1,2,5, default 5): 2
Partition 2 is deleted

Becaus partition 5 is contained within partition 2 it is gone as well.

Command (m for help): p

Disk /dev/mmcblk0: 31.7 GB, 31674335232 bytes, 61863936 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
Disk label type: dos
Disk identifier: 0x00057540

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1            2048      186367       92160    c  W95 FAT32 (LBA)

Command (m for help): n   
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): e 
Partition number (2-4, default 2): 2
First sector (186368-61863935, default 186368): 
Using default value 186368
Last sector, +sectors or +size{K,M,G} (186368-61863935, default 61863935): 
Using default value 61863935
Partition 2 of type Extended and of size 29.4 GiB is set

With our extended partition recreated (but with 29.4 GiB this time), let’s re-create the root partition.

!!!!! Since we aren’t moving any data rather changing the boundaries of the partitions it is important for this to work, that the beginning block of the old and new partition matches !!!!!

Command (m for help): n
Partition type:
   p   primary (1 primary, 1 extended, 2 free)
   l   logical (numbered from 5)
Select (default p): l
Adding logical partition 5
First sector (188416-61863935, default 188416): 
Using default value 188416
Last sector, +sectors or +size{K,M,G} (188416-61863935, default 61863935): 
Using default value 61863935
Partition 5 of type Linux and of size 29.4 GiB is set

now let’s check if everything worked out by printing the table again using p.

Command (m for help): p

Disk /dev/mmcblk0: 31.7 GB, 31674335232 bytes, 61863936 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
Disk label type: dos
Disk identifier: 0x00057540

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1            2048      186367       92160    c  W95 FAT32 (LBA)
/dev/mmcblk0p2          186368    61863935    30838784    5  Extended
/dev/mmcblk0p5          188416    61863935    30837760   83  Linux

!!!!! Again make absolutely sure the start block exactly matches the old partition entry’s start block !!!!!

With that done finally write our changes to disk.

Command (m for help): w   
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

Reboot the system to let the kernel pick up our changes.

[jan@espresso ~]$ sudo reboot
[jan@espresso ~]$ df
Filesystem     1K-blocks      Used Available Use% Mounted on
/dev/root        1712400    494916   1130496  31% /
devtmpfs           84784         0     84784   0% /dev
tmpfs             236420         0    236420   0% /dev/shm
tmpfs             236420       264    236156   1% /run
tmpfs             236420         0    236420   0% /sys/fs/cgroup
tmpfs             236420         0    236420   0% /tmp
/dev/mmcblk0p1     91962     24166     67796  27% /boot

After the system has come back up we get to really resize the partition.

[jan@espresso ~]$ sudo resize2fs /dev/mmcblk0p5 
[sudo] password for jan: 
resize2fs 1.42.7 (21-Jan-2013)
Filesystem at /dev/mmcblk0p5 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 2
The filesystem on /dev/mmcblk0p5 is now 7709440 blocks long.
[jan@espresso ~]$ df
Filesystem     1K-blocks      Used Available Use% Mounted on
/dev/root       30376956    496996  28632892   2% /
devtmpfs           84784         0     84784   0% /dev
tmpfs             236420         0    236420   0% /dev/shm
tmpfs             236420       264    236156   1% /run
tmpfs             236420         0    236420   0% /sys/fs/cgroup
tmpfs             236420         0    236420   0% /tmp
/dev/mmcblk0p1     91962     24166     67796  27% /boot

Have fun!

22. June 2013