[Duo]Linux 使用fdisk和resize2fs扩容 root分区

前言: 最近购买了一块 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
1 Like

感谢你的付出,这能帮到很多人。 :+1:

请把你的收件地址及论坛身份证明信息(可以是登陆后的截图)发送至邮箱:hoka@milkv.io

我会送你一个小礼品。可能会是未发售的扩展板或是一块特殊颜色的Duo。

Thanks for your dedication, this helps a lot of people.

Please send your recipient address and forum ID information (can be a screenshot after login)

Send it to hoka@milkv.io

I will send you a small gift.

顺带一提,我会将你的帖子翻译成英文,方便更多人检索到你的文章。
Incidentally, I will translate your post into English to make it easier for more people to retrieve your post.

可以试试开启Overlay,这种方式自动调整overlay分区到最大。

1 Like

感觉分给rootfs空间也够了,也可以sd卡把剩的空间分成第三个区,然后挂载到/media/下使用,存一些用户数据。

/etc/init.d/S99user启动脚本下面添加mount /dev/mmcblk0p3 /media/重启自动挂载

1 Like