EXT4 partition didn’t get any free space after expansion

bootfdiskfsckpartitioning

I have expanded the root partition on my Banana Pi using the following script:

fdisk /dev/mmcblk0 <<EOF
p
d
$PART_NUM
n
p
$PART_NUM
$PART_START

p
w
EOF

After a reboot I got a 32 GB partition according to fdisk:

root@bananapi /usr/local/bin # fdisk /dev/mmcblk0
Command (m for help): p
Disk /dev/mmcblk0: 31.9 GB, 31914983424 bytes

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1            2048       43007       20480   83  Linux
/dev/mmcblk0p2           43008    62333951    31145472   83  Linux

However, df shows the old 8 GB partition, and I didn't get any extra space:

root@bananapi /usr/local/bin # df
Filesystem     1K-blocks    Used Available Use% Mounted on
rootfs           8254904 5702140   2133448  73% /
/dev/root        8254904 5702140   2133448  73% /
devtmpfs          447624       0    447624   0% /dev
tmpfs              89548     292     89256   1% /run
tmpfs               5120       0      5120   0% /run/lock
tmpfs             179080       0    179080   0% /run/shm

What I have tried:

Basically, I tried every approach from this question except the 3-rd one which requires a physical keyboard to be present. However, I don't seem to be able to force fsck on reboot:

root@bananapi /usr/local/bin # dmesg |grep fsck     
[    4.796771] EXT4-fs (mmcblk0p2): warning: mounting unchecked fs,
running e2fsck is recommended

Is there anything else I could try, besides the obvious solution of getting a card reader and fixing the partition on another computer? Is there a reason why fsck wont start at boot time?

Feel free to migrate my question to http://raspberrypi.stackexchange.com, however, AFAIK they don't like exotic fruit up there.

Best Answer

fdisk shows (and works with) the partition list, df works with the list of file systems. On *nix, the two are distinct; in principle, a partition can hold multiple file systems (on Linux, that could be done either with file-based file systems, or by using losetup or similar with offset and size parameters to create multiple separate block devices).

To resize the file system after enlarging the partition holding it is an operation separate from enlarging the device (the partition) that holds the file system.

With ext2, ext3 and ext4, resizing the file system is done using resize2fs. Other file system types are different.

For a simple case, it looks like you should be able to just sudo resize2fs /dev/mmcblk0p2 to resize the file system on /dev/mmcblk0p2 to cover the whole partition. man 8 resize2fs is your friend here.

Personally, I would run a manual e2fsck first, then resize the file system, then immediately run e2fsck again to make sure everything is correct on-disk. Also make sure you have a recent backup of anything important on the file system in case something goes wrong. The odds of problems are small, but the consequences of problems are potentially large, so it can pay off to be careful.

Related Question