北京网站外包,没网站做哪个广告联盟,软件app开发制作,紧急通知河南全省暂停入式 Linux 镜像制作时#xff0c;考虑体积等因素#xff0c;会把根文件系统做的比较小#xff0c;镜像包较小#xff0c;方便量产#xff1b;有时#xff0c;我们的 tf 或 emmc 的容量较大#xff0c;烧写镜像后#xff0c;有较大的空余空间未使用#xff0c;现尝试把…入式 Linux 镜像制作时考虑体积等因素会把根文件系统做的比较小镜像包较小方便量产有时我们的 tf 或 emmc 的容量较大烧写镜像后有较大的空余空间未使用现尝试把未分区的空间分配到跟文件系统中存储介质连续。
1、查看分区空间占用情况
[rootsg200x]~# df -h
Filesystem Size Used Available Use% Mounted on
/dev/root 232.0M 9.3M 204.8M 4% /
devtmpfs 14.6M 0 14.6M 0% /dev
tmpfs 14.7M 0 14.7M 0% /dev/shm
tmpfs 14.7M 8.0K 14.7M 0% /tmp
tmpfs 14.7M 4.0K 14.7M 0% /run
tmpfs 14.7M 4.0K 14.7M 0% /run
tmpfs 14.7M 8.0K 14.7M 0% /tmp
tmpfs 14.7M 0 14.7M 0% /var/empty2、列出计算机中的所有磁盘和分区
[rootsg200x]~# fdisk -l
Disk /dev/mmcblk0: 15 GB, 15720251392 bytes, 30703616 sectors
479744 cylinders, 4 heads, 16 sectors/track
Units: sectors of 1 * 512 512 bytesDevice 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总磁盘大小为15GB
/dev/mmcblk0p1 是 boot 分区/dev/mmcblk0p2 是预装了一些命令/dev/mmcblk0p3 是 root 分区 这里要记住p2分区的起始地址这个很重要
3、使用fdisk进入磁盘分区工具
输入 p查看当前分区情况输入 d删除 p2 分区输入 n新建 p2 分区, 输入p2起始分区地址, 输入p2结束分区地地址 不输入直接回车就好他会把剩下的内存都分配输入 w保存
[rootsg200x]~# fdisk /dev/mmcblk0The number of cylinders for this disk is set to 479744.
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: 15 GB, 15720251392 bytes, 30703616 sectors
479744 cylinders, 4 heads, 16 sectors/track
Units: sectors of 1 * 512 512 bytesDevice 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 LinuxCommand (m for help): d
Partition number (1-4): 2Command (m for help): n
Partition typep primary partition (1-4)e extended
p
Partition number (1-4): 2
First sector (16-30703615, default 16): 264192
Last sector or size{,K,M,G,T} (264192-30703615, default 30703615):
Using default value 30703615Command (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 busy1 记录需要调整分区的起始 StartLBA 2 删除需要调整的分区 3 创建新分区起始位置输入第一步记录StartLBA的值 4 写入磁盘此时执行fdisk -l可以看到需要调整的分区容量已经是调整过了重启系统。
4、重启系统
$ reboot重启后查看分区空间占用情况
[rootsg200x]~# df -h
Filesystem Size Used Available Use% Mounted on
/dev/root 223.7M 39.0M 166.8M 19% /
devtmpfs 14.4M 0 14.4M 0% /dev
tmpfs 14.5M 0 14.5M 0% /dev/shm
tmpfs 14.5M 36.0K 14.5M 0% /tmp
tmpfs 14.5M 20.0K 14.5M 0% /run列出计算机中的所有磁盘和分区
[rootsg200x]~# fdisk -l
Disk /dev/mmcblk0: 15 GB, 15720251392 bytes, 30703616 sectors
479744 cylinders, 4 heads, 16 sectors/track
Units: sectors of 1 * 512 512 bytesDevice 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 1023,3,16 1023,3,16 264192 30703615 30439424 14.5G 83 Linux5、调整大小
[rootsg200x]~# resize2fs /dev/mmcblk0p2
resize2fs 1.46.2 (28-Feb-2021)
resize2fs: Resource busy while trying to open /dev/mmcblk0
Couldnt find valid filesystem superblock.
[rootsg200x]~# 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 2
The filesystem on /dev/mmcblk0p2 is now 3804928 (4k) blocks long.[rootsg200x]~# 完成分区
加启动脚本里即可完成分区。
EOF
在shell编程中“EOF”通常与“”结合使用“EOF” 表示后续的输入作为子命令或子shell的输入直到遇到“EOF”再次返回到主调用shell可将其理解为分界符delimiter。
EOF是End of file的缩写自定义终止符。
既然是分界符那么形式自然不是固定的这里可以将”EOF“可以进行自定义但是前后的”EOF“必须成对出现且不能和shell命令冲突。其使用形式如下
交互式程序 EOF
command1
command2
...
EOF”EOF“中间的内容将以标准输入的形式输入到”交互式程序“当shell看到”“知道其后面输入的分界符当shell再次看到分界符时两个分界符中间的部分将作为标准输入。 EOF一般常和cat命令连用通过cat配合重定向能够生成文件并追加操作在它之前先熟悉几个特殊符号 输入重定向 输出重定向 输出重定向进行追加不会覆盖之前的内容 标准输入来自命令行的一对分隔号的中间内容 注意最后的”EOF“必须单独占一行。 可以试试开启 Overlay这种方式自动调整 overlay 分区到最大。
挂载第三个分区
感觉分给rootfs空间也够了也可以sd卡把剩的空间分成第三个区然后挂载到/media/下使用存一些用户数据。
/etc/init.d/S99user启动脚本下面添加mount /dev/mmcblk0p3 /media/重启自动挂载
自动化处理
用工具烧录 img 后除了 sd 卡有剩余部分没有被使用每次都手动去操作较为麻烦可通过脚本自动化处理。
#!/bin/sh# 判断磁盘是否已经剩余的部分进行了分区
if (( $(fdisk -l /dev/mmcblk0|grep ^/dev/mmcblk0|wc -l) 2 ))
thenecho mmcblk0 has completed partitioning the remaining space.mount /dev/mmcblk0p3 /media exit #退出脚本后面的命令不再执行
fi# 第1步磁盘分区
# 使用 fdisk 交互式方式创建分区使用 here document 方式解决交互式传递参数的问题
fdisk /dev/mmcblk0 EOF
p
n
p
3w
EOF
echo ##########Partitioning complete###############
fdisk -l /dev/mmcblk0
echo ############################################### 第2步格式化
mkfs.ext4 /dev/mmcblk0p3reboot