无损扩展磁盘(SD卡)的分区大小
扩展新SD卡的分区大小
SD卡总共4G,2个分区总共只划分了1G,在不损失数据的情况下,把第二个分区的空间扩容为3G。
记录分区信息:
分区
root@xyhp:/tmp/sd# fdisk -l
。。。
Disk /dev/mmcblk0: 3.7 GiB, 3984588800 bytes, 7782400 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: 0xe6709663
Device Boot Start End Sectors Size Id Type
/dev/mmcblk0p1 * 8192 1056767 1048576 512M c W95 FAT32 (LBA)
/dev/mmcblk0p2 1056768 2105343 1048576 512M 83 Linux
卸载分区
root@xyhp:~# umount /media/xxyy/STORAGE
通过 man resize2fs 文件系统不能大于分区大小,不指定size就和分区一样大。
resize2fs [ -fFpPMbs ] [ -d debug-flags ] [ -S RAID-stride ] [ -z undo_file ] device [ size ]
The size of the filesystem may never be larger than the size of the partition. If
size parameter is not specified, it will default to the size of the partition.
扩大分区
fdisk不能直接修改大小,只能先删除分区再重新增加
root@xyhp:~# fdisk /dev/mmcblk0
Welcome to fdisk (util-linux 2.33.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): d
Partition number (1,2, default 2):
Partition 2 has been deleted.
Command (m for help): n
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p):
Using default response p.
Partition number (2-4, default 2):
First sector (2048-7782399, default 2048): 1056768
Last sector, +/-sectors or +/-size{K,M,G,T,P} (1056768-7782399, default 7782399):
Created a new partition 2 of type 'Linux' and of size 3.2 GiB.
Partition #2 contains a ext4 signature.
Do you want to remove the signature? [Y]es/[N]o: n 这里一定要选择no,不删除已有签名
Command (m for help): w
The partition table has been altered.
Syncing disks.
root@xyhp:~#
检查分区已增加
root@xyhp:~# fdisk /dev/mmcblk0 -l
Disk /dev/mmcblk0: 3.7 GiB, 3984588800 bytes, 7782400 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: 0x3c4e2362
Device Boot Start End Sectors Size Id Type
/dev/mmcblk0p1 * 8192 1056767 1048576 512M c W95 FAT32 (LBA)
/dev/mmcblk0p2 1056768 7782399 6725632 3.2G 83 Linux
root@xyhp:~#
扩容文件系统
系统自动挂载后,文件系统并未扩大
root@xyhp:~# df -h /media/xxyy/STORAGE
Filesystem Size Used Avail Use% Mounted on
/dev/mmcblk0p2 488M 5.9M 447M 2% /media/xxyy/STORAGE
root@xyhp:~# umount /media/xxyy/STORAGE
root@xyhp:~# resize2fs /dev/mmcblk0p2
resize2fs 1.44.5 (15-Dec-2018)
Please run 'e2fsck -f /dev/mmcblk0p2' first.
root@xyhp:~# e2fsck -f /dev/mmcblk0p2
e2fsck 1.44.5 (15-Dec-2018)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
STORAGE: 488/32768 files (0.4% non-contiguous), 7667/131072 blocks
root@xyhp:~# resize2fs /dev/mmcblk0p2
resize2fs 1.44.5 (15-Dec-2018)
Resizing the filesystem on /dev/mmcblk0p2 to 840704 (4k) blocks.
The filesystem on /dev/mmcblk0p2 is now 840704 (4k) blocks long.
root@xyhp:~# mount /dev/mmcblk0p2 /mnt/
root@xyhp:~# df -h /mnt
Filesystem Size Used Avail Use% Mounted on
/dev/mmcblk0p2 3.2G 6.9M 3.0G 1% /mnt
root@xyhp:~#