• sales

    +86-0755-88291180

Milk-V Duo S 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.
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):
Then use the n command to create a new partition. It prompts you to enter the partition number. We still use /dev/mmcblk1p4, so enter 4.
The following prompt First sector requires you to enter the starting sector value of the new partition. The command it has helped us identify the default starting value (default 221184), which is the starting sector of the just deleted /dev/mmcblk1p4, so you can just press Enter without entering value.
Finally enter the size of the new partition. The default "default" value is the entire storage space, there is no need to enter a specific value, just press Enter and it will prompt "Do you want to remove the signature? [Y]es/[N]o:" Enter No

Command (m for help): n
Partition number (4-128, default 4): 4
First sector (34-61069278, default 221184):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (221184-61069278, default 61067263):

Created a new partition 4 of type 'Linux filesystem' and of size 29 GiB.
Partition #4 contains a ext4 signature.

Do you want to remove the signature? [Y]es/[N]o: No

Command (m for help):
Execute the p command to check the current partition situation. /dev/mmcblk1p4 has been expanded to the entire storage space. Here it is 29G

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 61067263 60846080 29G Linux filesystem

Command (m for help):
Execute the w command to save changes and exit fdisk interactive mode


Command (m for help): w
The partition table has been altered.
Syncing disks.

Finally, execute the resize2fs command to complete the file system expansion


# resize2fs /dev/mmcblk1p4
resize2fs 1.46.6-rc1 (12-Sep-2022)
Filesystem at /dev/mmcblk1p4 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 4
The filesystem on /dev/mmcblk1p4 is now 7605760 (4k) blocks long.

Use the df -h command again to check the partition status. You can see that the system partition node /dev/mmcblk1p4 has been expanded to 29G

# df -h
Filesystem Size Used Avail Use% Mounted on
udev 700M 0 700M 0% /dev
tmpfs 193M 3.3M 190M 2% /run
/dev/mmcblk1p4 29G 3.1G 26G 11% /
tmpfs 962M 0 962M 0% /dev/shm
tmpfs 5.0M 12K 5.0M 1% /run/lock
tmpfs 193M 64K 193M 1% /run/user/110
tmpfs 193M 24K 193M 1% /run/user/0
/dev/mmcblk1p3 100M 23M 77M 23% /boot