debain 扩大分区

 

 $ df -h
文件系统        容量  已用  可用 已用% 挂载点
/dev/root       7.2G  4.3G  2.6G   63% /
devtmpfs        427M     0  427M    0% /dev
tmpfs           432M     0  432M    0% /dev/shm
tmpfs           432M  5.9M  426M    2% /run
tmpfs           5.0M  4.0K  5.0M    1% /run/lock
tmpfs           432M     0  432M    0% /sys/fs/cgroup
/dev/mmcblk0p1   63M   21M   43M   34% /boot
tmpfs            87M     0   87M    0% /run/user/1000

发现实际只使用了7.2G ,当场怀疑是不是买到了假内存卡 ..
于是再查看实际的内存卡大小

$ sudo fdisk -l
......
Disk /dev/mmcblk0: 14.9 GiB, 15931539456 bytes, 31116288 sectors
......

发现内存卡的确是16g,只是没有使用剩下的磁盘空间, 那么现在就来扩大分区

管理磁盘
$ sudo fdisk /dev/mmcblk0

输入 p 查看当前硬盘使用情况

Command (m for help): p
Disk /dev/mmcblk0: 14.9 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: dos
Disk identifier: 0x0f4a54c8

Device         Boot  Start      End  Sectors  Size Id Type
/dev/mmcblk0p1        8192   137215   129024   63M  c W95 FAT32 (LBA)
/dev/mmcblk0p2      137216 15523839 15386624  7.3G 83 Linux

删除除了mmcblk0p1 以外的分区 (注意, 请慎重删除,如果出现数据丢失责任自负),在我这里就是删除分区2

输入d , 再接着输入你要删除的分区号 ,我这里是2

Command (m for help): d
Partition number (1,2, default 2): 2

Partition 2 has been deleted.

接着重新创建新的分区,输入 n(新建), 再输入p 创建主分区,再输入要创建的主分区号 , 我这里是2,接着输入起始存储块 , 这个是根据上面/dev/mmcblk0p1end 列数字+1 算出来的 ,我的上面是137215,所以要输入的是137216

Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2):
First sector (2048-31116287, default 2048): 137215

Sector 137215 is already allocated.
First sector (137216-31116287, default 137216): 137216
Last sector, +sectors or +size{K,M,G,T,P} (137216-31116287, default 31116287):

Created a new partition 2 of type 'Linux' and of size 14.8 GiB.

最后输入 w写入

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.

写入后修复分区

$ sudo resize2fs /dev/mmcblk0p2
resize2fs 1.42.12 (29-Aug-2014)
Filesystem at /dev/mmcblk0p2 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/mmcblk0p2 is now 3872384 (4k) blocks long.

(注意,如果这一步失败了,可能需要重启下 linux 再次尝试,失败的信息为 The filesystem is already 1923328 (4k) blocks long. Nothing to do!)

再次输入 df -h,发现分区已经扩大了

文件系统        容量  已用  可用 已用% 挂载点
/dev/root        15G  4.3G  9.6G   31% /
devtmpfs        427M     0  427M    0% /dev
tmpfs           432M     0  432M    0% /dev/shm
tmpfs           432M  5.9M  426M    2% /run
tmpfs           5.0M  4.0K  5.0M    1% /run/lock
tmpfs           432M     0  432M    0% /sys/fs/cgroup
/dev/mmcblk0p1   63M   21M   43M   34% /boot
tmpfs            87M     0   87M    0% /run/user/1000
posted @ 2019-10-11 21:27  退役产品汪  阅读(657)  评论(0编辑  收藏  举报