!!! 分区有风险,操作前先备份好数据,数据无价 !!!
建议只在刚刷好镜像后操作,这样失败了也可以重新刷镜像恢复.
查看分区
root@maixsense:~# fdisk -l
Disk /dev/mmcblk0: 119.08 GiB, 127865454592 bytes, 249737216 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: dos
Disk identifier: 0x20926256
Device Boot Start End Sectors Size Id Type
/dev/mmcblk0p1 8192 6299647 6291456 3G 83 Linux
Disk /dev/zram0: 115.79 MiB, 121413632 bytes, 29642 sectors
Units: sectors of 1 * 4096 = 4096 bytes
Sector size (logical/physical): 4096 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/zram1: 50 MiB, 52428800 bytes, 12800 sectors
Units: sectors of 1 * 4096 = 4096 bytes
Sector size (logical/physical): 4096 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes其中 /dev/mmcblk0 就是要操作的分区
fdisk /dev/mmcblk0 查看分区信息,输入 p 打印分区信息
root@maixsense:~# fdisk /dev/mmcblk0
Welcome to fdisk (util-linux 2.36.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p
Disk /dev/mmcblk0: 119.08 GiB, 127865454592 bytes, 249737216 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: dos
Disk identifier: 0x20926256
Device Boot Start End Sectors Size Id Type
/dev/mmcblk0p1 8192 6299647 6291456 3G 83 Linux这里的 start 和 End 一定要记录下来。这是开始扇区和结束扇区
Device Boot Start End Sectors Size Id Type
/dev/mmcblk0p1 8192 6299647 6291456 3G 83 Linux操作扩容
输入 d 删除 分区信息,切记不要保存
Command (m for help): d
Selected partition 1
Partition 1 has been deleted.输入 p 显示已经删除成功
Command (m for help): p
Disk /dev/mmcblk0: 119.08 GiB, 127865454592 bytes, 249737216 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: dos
Disk identifier: 0x20926256输入 n 新建分区,询问是否使用默认分区,按下回车确认,然后会选择 First sector 开始扇区, 输入刚刚记录的开始扇区,如上方开始扇区是 8192 因此这里也输入 8192 ,然后按下回车
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p):
Using default response p.
Partition number (1-4, default 1):
First sector (2048-249737215, default 2048): 8192然后会需要选择 结束扇区 , 这里结束扇区计算方式如下:
Bytes 是字节数, Units 是扇区占用字节,通过上面的 p 命令打印出来显示为 512 ,比如如果想要给新分区分配 24G 的空间,假设扇区从 0 开始,那么计算如下:
输入空间后继续
Last sector, +/-sectors or +/-size{K,M,G,T,P} (8192-249737215, default 249737215): 50331648
Created a new partition 1 of type 'Linux' and of size 24 GiB.
Partition #1 contains a ext4 signature.
Do you want to remove the signature? [Y]es/[N]o: No按下 w 保存
Command (m for help): w
The partition table has been altered.
Syncing disks.查看分区信息:
root@maixsense:~# fdisk -l
Disk /dev/mmcblk0: 119.08 GiB, 127865454592 bytes, 249737216 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: dos
Disk identifier: 0x20926256
Device Boot Start End Sectors Size Id Type
/dev/mmcblk0p1 8192 50331648 50323457 24G 83 Linux
Disk /dev/zram0: 115.79 MiB, 121413632 bytes, 29642 sectors
Units: sectors of 1 * 4096 = 4096 bytes
Sector size (logical/physical): 4096 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/zram1: 50 MiB, 52428800 bytes, 12800 sectors
Units: sectors of 1 * 4096 = 4096 bytes
Sector size (logical/physical): 4096 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes更新分区大小信息
root@maixsense:~# resize2fs /dev/mmcblk0p1
resize2fs 1.46.2 (28-Feb-2021)
Filesystem at /dev/mmcblk0p1 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 2
The filesystem on /dev/mmcblk0p1 is now 6290432 (4k) blocks long.检查是否成功扩容
查看空间是否成功扩容:
root@maixsense:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 47M 0 47M 0% /dev
tmpfs 24M 3.0M 21M 13% /run
/dev/mmcblk0p1 24G 2.3G 22G 10% /
tmpfs 116M 0 116M 0% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 116M 0 116M 0% /tmp
/dev/zram1 49M 48M 0 100% /var/log
tmpfs 24M 0 24M 0% /run/user/0
tmpfs 24M 0 24M 0% /run/user/1000
root@maixsense:~#为什么会有这篇文章:最开始设备只有2.3G的根空间没怎么管,使用maixsense官方的armbian-resize-filesystem命令扩容发现无效,就没管了,最后系统盘满了,建议执行 sudo apt --fix-broken install ,执行了后就悲剧了,配置好的系统数据全删了。