When I was capturing data with tshark I discovered that I my 16GB SD-card was not fully used to store my Wireshark captures on. I investigated why this was and I stumbled up on this article that explained how the disk space could be “released” again.
Releasing the disk space
Verifying the current space
ubuntu@RPi2-02:~$ df -hFilesystem Size Used Avail Use% Mounted on/dev/mmcblk0p2 1.7G 674M 892M 44% /devtmpfs 458M 4.0K 458M 1% /devnone 4.0K 0 4.0K 0% /sys/fs/cgroupnone 93M 240K 93M 1% /runnone 5.0M 0 5.0M 0% /run/locknone 462M 0 462M 0% /run/shmnone 100M 0 100M 0% /run/user/dev/mmcblk0p1 64M 17M 48M 27% /boot/firmwareUsing fdisk to delete and recreate a partition
ubuntu@RPi2-02:/$ sudo fdisk /dev/mmcblk0sudo: unable to resolve host RPi2-02
Command (m for help): mCommand action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition l list known partition types m print this menu n add a new partition o create a new empty DOS partition table p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partition's system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only)
Command (m for help): p
Disk /dev/mmcblk0: 16.1 GB, 16088301568 bytes4 heads, 16 sectors/track, 490976 cylinders, total 31422464 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000
Device Boot Start End Blocks Id System/dev/mmcblk0p1 * 2048 133119 65536 c W95 FAT32 (LBA)/dev/mmcblk0p2 133120 3670015 1768448 83 Linux
Command (m for help): dPartition number (1-4): 2
Command (m for help): p
Disk /dev/mmcblk0: 16.1 GB, 16088301568 bytes4 heads, 16 sectors/track, 490976 cylinders, total 31422464 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000
Device Boot Start End Blocks Id System/dev/mmcblk0p1 * 2048 133119 65536 c W95 FAT32 (LBA)
Command (m for help): nPartition type: p primary (1 primary, 0 extended, 3 free) e extendedSelect (default p): pPartition number (1-4, default 2): 2First sector (133120-31422463, default 133120): 133120Last sector, +sectors or +size{K,M,G} (133120-31422463, default 31422463): Using default value 31422463
Command (m for help): wThe 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 atthe next reboot or after you run partprobe(8) or kpartx(8)Syncing disks.Rebooting
ubuntu@RPi2-02:/$ sudo rebootsudo: unable to resolve host RPi2-02
Broadcast message from ubuntu@RPi2-02 (/dev/pts/0) at 7:05 ...
The system is going down for reboot NOW!Do another verification of the space
ubuntu@RPi2-02:~$ df -hFilesystem Size Used Avail Use% Mounted on/dev/mmcblk0p2 1.7G 675M 892M 44% /devtmpfs 458M 4.0K 458M 1% /devnone 4.0K 0 4.0K 0% /sys/fs/cgroupnone 93M 240K 93M 1% /runnone 5.0M 0 5.0M 0% /run/locknone 462M 0 462M 0% /run/shmnone 100M 0 100M 0% /run/user/dev/mmcblk0p1 64M 17M 48M 27% /boot/firmwareResize the file system
ubuntu@RPi2-02:~$ sudo resize2fs /dev/mmcblk0p2sudo: unable to resolve host RPi2-02[sudo] password for ubuntu:resize2fs 1.42.9 (4-Feb-2014)Filesystem at /dev/mmcblk0p2 is mounted on /; on-line resizing requiredold_desc_blocks = 1, new_desc_blocks = 1The filesystem on /dev/mmcblk0p2 is now 3911168 blocks long.Reboot again
ubuntu@RPi2-02:~$ sudo rebootsudo: unable to resolve host RPi2-02
Broadcast message from ubuntu@RPi2-02 (/dev/pts/1) at 7:17 ...
The system is going down for reboot NOW!Verify again
ubuntu@RPi2-02:~$ df -hFilesystem Size Used Avail Use% Mounted on/dev/mmcblk0p2 15G 676M 14G 5% /devtmpfs 458M 4.0K 458M 1% /devnone 4.0K 0 4.0K 0% /sys/fs/cgroupnone 93M 244K 93M 1% /runnone 5.0M 0 5.0M 0% /run/locknone 462M 0 462M 0% /run/shmnone 100M 0 100M 0% /run/user/dev/mmcblk0p1 64M 17M 48M 27% /boot/firmwareAnd we have release the space for usage.
Originally published on the old wiki at /index.php/Resizing_SD_Card_Raspberry_Pi_to_fully_use_free_space.