Extend Partition on SD Card or eMMC
The default capacity of the official Debian image root file system is about 4GB. When installing software or other data increases, there will be insufficient space. We can expand the file system to the full capacity of the SD card or eMMC.
Mars is started using eMMC or SD card. The nodes for storage mounting are different. The version of eMMC is /dev/mmcblk0 and the version of SD Card is /dev/mmcblk1
The following uses a Mars booted from a 32G SD card as an example to introduce how to expand the capacity through commands. The expansion method for the eMMC version is also the same, just replace /dev/mmcblk1 with /dev/mmcblk0 (/dev/mmcblk1p4 with /dev/mmcblk0p4).
Check the current status of the partitions
Use the df -h command to view the current partition status
# df -h
Filesystem Size Used Avail Use% Mounted on
udev 700M 0 700M 0% /dev
tmpfs 193M 3.3M 190M 2% /run
/dev/mmcblk1p4 3.7G 3.1G 590M 85% /
tmpfs 962M 0 962M 0% /dev/shm
tmpfs 5.0M 12K 5.0M 1% /run/lock
/dev/mmcblk1p3 100M 23M 77M 23% /boot
tmpfs 193M 60K 193M 1% /run/user/110
tmpfs 193M 24K 193M 1% /run/user/0
You can see that the device mounted in the current root partition / directory is /dev/mmcblk1p4
Extend a partition using the fdisk command
Entering the fdisk command will take you into the command-line interactive mode of fdisk
# fdisk /dev/mmcblk1
Enter the p command to view the current partition information. You can see that the current capacity of the system partition /dev/mmcblk1p4 is 3.8G
Command (m for help): p
Disk /dev/mmcblk1: 29.12 GiB, 31267487744 bytes, 61069312 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: gpt
Disk identifier: 2D487F15-E07F-4B07-BC04-80EA297E8675
Device Start End Sectors Size Type
/dev/mmcblk1p1 4096 8191 4096 2M HiFive BBL
/dev/mmcblk1p2 8192 16383 8192 4M HiFive FSBL
/dev/mmcblk1p3 16384 221183 204800 100M EFI System
/dev/mmcblk1p4 221184 8189918 7968735 3.8G Linux filesystem
Then execute the d command to delete the system partition from the original system. You will be prompted to enter the partition number to be deleted. We want to delete /dev/mmcblk1p4, so enter 4
Command (m for help): d
Partition number (1-4, default 4): 4
Partition 4 has been deleted.
Command (m for help):