How to resize Debian 9.2 root partition to fit SD card
From SomLabs Wiki
How to resize Debian 9.2 root partition to fit SD card
IMPORTANT!!! Even a small typo might cause data loss - be extremely careful while resizing partition!
By default size of the root partition of Debian is about 800MB. You need to resize it to use full SD card capacity. First step is to get SD card device name:
root@somlabs:~# fdisk -l Disk /dev/ram0: 64 MiB, 67108864 bytes, 131072 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes ... ... Disk /dev/ram15: 64 MiB, 67108864 bytes, 131072 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes Disk /dev/mmcblk1: 3.7 GiB, 3965714432 bytes, 7745536 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: 0x9de2d76a Device Boot Start End Sectors Size Id Type /dev/mmcblk1p1 16384 1628159 1611776 787M 83 Linux root@somlabs:~#
SD card device name is /dev/mmcblk1, now start fdisk and replace old partition with new one:
root@somlabs:~# fdisk /dev/mmcblk1 Welcome to fdisk (util-linux 2.29.2). 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/mmcblk1: 3.7 GiB, 3965714432 bytes, 7745536 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: 0x9de2d76a Device Boot Start End Sectors Size Id Type /dev/mmcblk1p1 16384 1628159 1611776 787M 83 Linux
You can see that old partition starts at 16384 sector, new partition should start at the same sector.
Command (m for help): d Selected partition 1 Partition 1 has been deleted. Command (m for help): p Disk /dev/mmcblk1: 3.7 GiB, 3965714432 bytes, 7745536 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: 0x9de2d76a Command (m for help): n Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p): p Partition number (1-4, default 1): 1 First sector (2048-7745535, default 2048): 16384 Last sector, +sectors or +size{K,M,G,T,P} (16384-7745535, default 7745535): Created a new partition 1 of type 'Linux' and of size 3.7 GiB. Partition #1 contains a ext4 signature. Do you want to remove the signature? [Y]es/[N]o: n 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).
Now you should reboot your VisionSOM-6ULL:
root@somlabs:~# reboot
After rebooting resize file system:
root@somlabs:~# resize2fs /dev/mmcblk1p1 resize2fs 1.43.4 (31-Jan-2017) Filesystem at /dev/mmcblk1p1 is m[ 122.795430] EXT4-fs (mmcblk1p1): resizing filesystem from 201472 to 966144 blocks ounted on /; on-line resizing required old_desc_blocks = 1, new_desc_blocks = 1 [ 123.861183] EXT4-fs (mmcblk1p1): resized filesystem to 966144 The filesystem on /dev/mmcblk1p1 is now 966144 (4k) blocks long.
You can check your partitions sizes:
root@somlabs:~# df -h Filesystem Size Used Avail Use% Mounted on /dev/root 3.7G 499M 3.0G 15% / devtmpfs 88M 0 88M 0% /dev tmpfs 248M 0 248M 0% /dev/shm tmpfs 248M 3.4M 245M 2% /run tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 248M 0 248M 0% /sys/fs/cgroup tmpfs 50M 0 50M 0% /run/user/0