First, we need a Linux machine and a 32GB SD card.
1. Burning the system image to a 32GB SD card
Take 32GB card as an example which is on /dev/sdb, after burning the system image file, partition 2 only has 7.4GB
~# fdisk -l /dev/sdb
Disk /dev/sdb: 29.7 GiB, 31914983424 bytes, 62333952 sectors
…
Device Boot Start End Sectors Size Id Type
/dev/sdb1 8192 93814 85623 41.8M c W95 FAT32 (LBA)
/dev/sdb2 94208 15523839 15429632 7.4G 83 Linux
2. Extend partition 2
2.1 Delete partition 2
~# fdisk /dev/sdb
Command (m for help): d
Partition number (1,2, default 2):Partition 2 has been deleted.
2.2 Create partition 2, set the starting address to 94208:
Command (m for help): n
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p):Using default response p.
Partition number (2-4, default 2):
First sector (2048-62333951, default 2048): 94208
Last sector, +sectors or +size{K,M,G,T,P} (94208-62333951, default 62333951):
Created a new partition 2 of type ‘Linux’ and of size 29.7 GiB.
Partition #2 contains a ext4 signature.
Do you want to remove the signature? [Y]es/[N]o: n
2.3 Save changes and exit, confirm the partition size is 29.7GB
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.~# fdisk -l /dev/sdb
Disk /dev/sdb: 29.7 GiB, 31914983424 bytes, 62333952 sectors
…
Device Boot Start End Sectors Size Id Type
/dev/sdb1 8192 93814 85623 41.8M c W95 FAT32 (LBA)
/dev/sdb2 94208 62333951 62239744 29.7G 83 Linux
3. Extend the file system
~# e2fsck -f -y /dev/sdb2
e2fsck 1.43.4 (31-Jan-2017)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
CLOCKWORKPI: 93039/482384 files (0.1% non-contiguous), 743512/1928704 blocks~# resize2fs /dev/sdb2
resize2fs 1.43.4 (31-Jan-2017)
Resizing the filesystem on /dev/sdb2 to 7779968 (4k) blocks.
The filesystem on /dev/sdb2 is now 7779968 (4k) blocks long.
4. Mount partition 2 and confirm the file system size is 30GB
~# df -h
/dev/sdb2 30G 2.6G 25G 10%