我确实调整了磁盘分区 (/dev/mmcblk0p2) 的大小,但该过程完成后,我得到的是以下结果:
df -h
:
Filesystem Size Used Avail Use% Mounted on
/dev/mmcblk0p2 3.1G 3.1G 2.5M 100% /
devtmpfs 360M 0 360M 0% /dev
tmpfs 489M 4.0K 489M 1% /dev/shm
tmpfs 489M 26M 464M 6% /run
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/mmcblk0p1 40M 16M 25M 40% /boot
tmpfs 98M 0 98M 0% /run/user/0
tmpfs 98M 0 98M 0% /run/user/1000
结果fdisk -l
是:
Disk /dev/mmcblk0: 7.4 GiB, 7948206080 bytes, 15523840 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: 0x00000000
Device Boot Start End Sectors Size Id Type
/dev/mmcblk0p1 49152 131071 81920 40M 83 Linux
/dev/mmcblk0p2 131072 15523839 15392768 7.3G 83 Linux
为什么df
我没有得到完整尺寸的/dev/mmcblk0p2
???
通过以下命令集调整大小
totalSize=`sfdisk -l /dev/mmcblk0 | grep "Disk /dev/mmcblk0" | cut -d ' ' -f 7`;
p2Start=`sfdisk -d /dev/mmcblk0 | grep "/dev/mmcblk0p2" | cut -d ',' -f 1 | cut -d '=' -f 2 | awk '{$1=$1};1'`;
newSize=$((totalSize - p2Start));
sfdisk -d /dev/mmcblk0 > /tmp/DiskLayout;
sed -i -E "s/\/dev\/mmcblk0p2.*size=[ ]*[0-9]+, type=83/\/dev\/mmcblk0p2 : start= ${p2Start}, size= ${newSize}, type=83/" /tmp/DiskLayout;
sfdisk /dev/mmcblk0 --no-reread < /tmp/DiskLayout;
reboot
resize2fs /dev/mmcblk0p2
reboot
resize2fs 输出:
Filesystem at /dev/mmcblk0p2 is mounted on /;
on-line resizing required old_desc_blocks = 1, new_desc_blocks = 1 Performing an on-line resize of /dev/mmcblk0p2 to 1924096 (4k) blocks.
这是批量生产中准备 SD 的流程的一部分,因此必须使用拆分脚本部分动态完成