前言: 最近购买了一块 milk-v duo开发板,刷了官方编译的linux镜像,发现sd卡本来有2g,但是df -h只显示256m,原来是编译时就默认设置分区大小为256m;在群里询问加百度后,发现解决方法有两种,一种是重新编译linux镜像,编译前修改配置文件,另一种是命令扩容;为了图方便,我采用第二种方法。
1.linux启动后 df -h 查看磁盘容量大小
2. 使用fdisk -l
查看总磁盘容量大小
这里可以看到,总磁盘大小为1896M
3.使用fdisk扩展分区
# 1. fdisk /dev/mmcblk0 , 这里主要看你fdisk -l 的输出
fdisk /dev/mmcblk0
# 2. 输入p ,查看当前分区
p
p1分区是boot分区,千万不要动。p2分区时root分区,我们主要扩容的目标,大致逻辑时删除p2分区,然后重新加一个p2分区。
这里要记住p2分区的起始地址,这个很重要
# 3. d , 删除p2分区
d
2
# 4. 输入n ,新建p2分区
n
2
# 输入p2起始分区地址
xxx
# 输入p2结束分区地地址 不输入直接回车就好,他会把剩下的内存都分配
# 5. 保存退出
w
# 6. 重启
reboot
# 7. 使扩容生效
resize2fs /dev/mmcblk0p2
[回车]
4.附上完整流程
[root@milkv]~# fdisk /dev/mmcblk0
The number of cylinders for this disk is set to 60672.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): p
Disk /dev/mmcblk0: 1896 MB, 1988100096 bytes, 3883008 sectors
60672 cylinders, 4 heads, 16 sectors/track
Units: sectors of 1 * 512 = 512 bytes
Device Boot StartCHS EndCHS StartLBA EndLBA Sectors Size Id Type
/dev/mmcblk0p1 0,32,33 16,113,33 2048 264191 262144 128M 83 Linux
/dev/mmcblk0p2 16,113,34 49,20,35 264192 788479 524288 256M 83 Linux
Command (m for help): d
Partition number (1-4): 2
Command (m for help): n
Partition type
p primary partition (1-4)
e extended
p
Partition number (1-4): 2
First sector (16-3883007, default 16): 264192
Last sector or +size{,K,M,G,T} (264192-3883007, default 3883007):
Using default value 3883007
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table
fdisk: WARNING: rereading partition table failed, kernel still uses old table: Resource busy
[root@milkv]~# resize2fs /dev/mmcblk0p2
resize2fs 1.46.2 (28-Feb-2021)
The filesystem is already 65536 (4k) blocks long. Nothing to do!
[root@milkv]~# reboot
[root@milkv]~#
连接断开
连接主机...
连接主机成功
连接主机...
连接主机成功
[root@milkv]~# resize2fs /dev/mmcblk0p2
resize2fs 1.46.2 (28-Feb-2021)
Filesystem at /dev/mmcblk0p2 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/mmcblk0p2 is now 452352 (4k) blocks long.
[root@milkv]~# df -h
Filesystem Size Used Available Use% Mounted on
/dev/root 1.6G 39.8M 1.5G 3% /
devtmpfs 14.4M 0 14.4M 0% /dev
tmpfs 14.5M 0 14.5M 0% /dev/shm
tmpfs 14.5M 44.0K 14.4M 0% /tmp
tmpfs 14.5M 20.0K 14.5M 0% /run