Post Installation SD Card Resizing for Raspberry Pi Running Arch Linux

If you install Arch Linux on your SD card you may notice you might not be using all of the storage space your SD card has to offer. In my instance I use a 16GiB card I was only using 1.5GiB of the 16GiB.

# df -h
Filesystem     Size Used Avail Use% Mounted on
/dev/root      1.5G 1.5G 51M   99%  /
devtmpfs       89M  0    89M   0%   /dev
tmpfs          93M  0    93M   0%   /dev/shm
tmpfs          93M  288K 93M   1%   /run
tmpfs          93M  0    93M   0%   /sys/fs/cgroup
tmpfs          93M  0    93M   0%   /tmp
/dev/mmcblk0p1 90M  25M  66M   28%  /boot
tmpfs          19M  0    19M   0%   /run/user/0

You can resize the partition online quite easily by using fdisk. Using the latest Arch Linux for RPi the root filesystem is mounted on mmcblk0p5 which is a logical partition within an extended one.

# fdisk /dev/mmcblk0
Welcome to fdisk (util-linux 2.24.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

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

Command (m for help): d
Partition number (1,2, default 2): 
Partition 2 has been deleted.

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): 
First sector (186368-31116287, default 186368): 
Last sector, +sectors or +size{K,M,G,T,P} (186368-31116287, default 31116287): 
Created a new partition 2 of type 'Extended' and of size 14.8 GiB.

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-31116287, default 188416): 
Last sector, +sectors or +size{K,M,G,T,P} (188416-31116287, default 31116287): 
Created a new partition 5 of type 'Linux' and of size 14.8 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: 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).

At this point the partition table should be properly set-up to use the entire SD card. Reboot. The final step is to resize the filesystem to match the new partition size.

# resize2fs /dev/mmcblk0p5

Done.

Advertisements