RISC-V Linux rootfs 根文件系统扩容
flyfish
在制作根文件系统之后,该文件大小可能不到1G。在烧写的时候磁盘或者SD卡的剩余空间都分配到该分区。
方法:
根文件系统大小不变,还是不到1G。在buildroot时,将rootfs所在分区的大小设置大一些,这里是10G,在系统启动后再调整下。
步骤:
设置根文件系统的大小
不需要很大
BR2_TARGET_ROOTFS_EXT2_4=y
BR2_TARGET_ROOTFS_EXT2_GEN=4
BR2_TARGET_ROOTFS_EXT2_REV=1
BR2_TARGET_ROOTFS_EXT2_LABEL="rootfs"
BR2_TARGET_ROOTFS_EXT2_SIZE="1G"
BR2_TARGET_ROOTFS_EXT2_INODES=0
BR2_TARGET_ROOTFS_EXT2_RESBLKS=5
BR2_TARGET_ROOTFS_EXT2_MKFS_OPTIONS="-O ^64bit"
BR2_TARGET_ROOTFS_EXT2_NONE=y
设置 rootfs所在分区的大小
这里是10G
image sdcard.img {
hdimage{
gpt = true
gpt-location = 1M
}
partition boot0 {
in-partition-table = "no"
image = "boot0_sdcard.fex"
offset = 8K
}
partition boot-packages {
in-partition-table = "no"
image = "boot_package.fex"
offset = 16400K
}
partition env {
image = "env.fex"
size = 128k
}
partition env-redund {
image = "env.fex"
size = 128k
}
partition boot {
partition-type = 0xC
bootable = "true"
image = "boot.vfat"
}
partition rootfs {
partition-type = 0x83
image = "rootfs_ubuntu_riscv.ext4"
size = 10G
}
}
image boot.vfat {
vfat {
files = {
"boot.img",
"Image",
"board.dtb"
}
}
size = 32M
}
查看rootfs所在分区大小
是10G
sudo fdisk -l
Disk /dev/mmcblk0: 14.84 GiB, 15931539456 bytes, 31116288 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
Device Start End Sectors Size Type
/dev/mmcblk0p1 34784 35039 256 128K Linux filesystem
/dev/mmcblk0p2 35040 35295 256 128K Linux filesystem
/dev/mmcblk0p3 35296 100831 65536 32M Linux filesystem
/dev/mmcblk0p4 100832 21072351 20971520 10G Linux filesystem
查看 /dev/root 实际大小 1008M
df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 1008M 842M 116M 88% /
tmpfs 244M 0 244M 0% /dev/shm
tmpfs 98M 3.0M 95M 4% /run
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 49M 0 49M 0% /run/user/1000
开始扩容
sudo resize2fs /dev/mmcblk0p4
resize2fs 1.46.5 (30-Dec-2021)
Filesystem at /dev/mmcblk0p4 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/mmcblk0p4 is now 2621440 (4k) blocks long.
扩容结果 /dev/root 实际大小由 1008M 变为 9.9G
df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 9.9G 843M 8.7G 9% /
tmpfs 244M 0 244M 0% /dev/shm
tmpfs 98M 3.0M 95M 4% /run
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 49M 0 49M 0% /run/user/1000