扩容嵌入式Linux根文件系统

时间:2021-08-06
本文章向大家介绍扩容嵌入式Linux根文件系统,主要包括扩容嵌入式Linux根文件系统使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

需求:嵌入式镜像制作时,考虑体积等因素,会把根文件系统做的比较小,镜像包较小,方便量产;

有时,我们的tf或emmc的容量较大,烧写镜像后,有较大的空余空间未使用,现尝试把未分区的空间分配到跟文件系统中(存储介质连续)。

1、软件环境:fdisk、resize2fs

2、查看分区结构

fdisk -l

# fdisk -l
Disk /dev/mmcblk0: 30 GB, 31914983424 bytes, 62333952 sectors
973968 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,0,2 2,10,9 1 32768 32768 16.0M c Win95 FAT32 (LBA)
/dev/mmcblk0p2 512,0,2 1023,3,16 32769 62333951 62301183 29.7G 83 Linux
# df -h
Filesystem Size Used Available Use% Mounted on
/dev/root 492.2M 215.3M 250.1M 46% /
devtmpfs 106.6M 0 106.6M 0% /dev
tmpfs 115.1M 0 115.1M 0% /dev/shm
tmpfs 115.1M 56.0K 115.0M 0% /tmp
tmpfs 115.1M 144.0K 114.9M 0% /run

3、调整分区

# fdisk /dev/mmcblk0

The number of cylinders for this disk is set to 973968.
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): m
Command Action
a       toggle a bootable flag
b       edit bsd disklabel
c       toggle the dos compatibility flag
d       delete a partition
l       list known partition types
n       add a new partition
o       create a new empty DOS partition table
p       print the partition table
q       quit without saving changes
s       create a new empty Sun disklabel
t       change a partition's system id
u       change display/entry units
v       verify the partition table
w       write table to disk and exit
x       extra functionality (experts only)

Command (m for help):

1> 记录需要调整分区的起始 StartLBA;

2> 删除需要调整的分区;

3> 创建新分区,起始位置输入第一步记录StartLBA的值;

4> 写入磁盘,此时执行fdisk -l,可以看到需要调整的分区,容量已经是调整过了,重启系统。

4、调整大小

使用resize2fs命令调整实际的文件系统大小。

# resize2fs /dev/mmcblk0p2
resize2fs 1.45.6 (20-Mar-2020)
Filesystem at /dev/mmcblk0p2 is mounted on /; on-line resizing r[  114.324033] EXT4-fs (mmcblk0p2): resizing filesystem from 524288 to 31150588 blocks
equired
old_desc_blocks = 2, new_desc_blocks = 119
[  122.594492] EXT4-fs (mmcblk0p2): resized filesystem to 31150588
The filesystem on /dev/mmcblk0p2 is now 31150588 (1k) blocks long.

#
#
#

执行完毕后,使用fdisk -l或者df -h都显示分区容量变大了。

以上操作,环境简单,错误也无所谓,但是在数据较重要场所,不建议这样操作。

原文地址:https://www.cnblogs.com/yddeboke/p/15110373.html