目标
查看挂在磁盘情况 sudo df -h
目前 /dev/sda2
大小为 25G
;
user@ubuntu20-server:~$ sudo df -h
Filesystem Size Used Avail Use% Mounted on
udev 2.9G 0 2.9G 0% /dev
tmpfs 600M 1.1M 599M 1% /run
/dev/sda2 25G 5.4G 18G 24% /
tmpfs 3.0G 0 3.0G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 3.0G 0 3.0G 0% /sys/fs/cgroup
/dev/loop2 64M 64M 0 100% /snap/core20/1828
/dev/loop0 92M 92M 0 100% /snap/lxd/24061
/dev/loop1 50M 50M 0 100% /snap/snapd/18357
/dev/loop3 41M 41M 0 100% /snap/snapd/20290
tmpfs 600M 0 600M 0% /run/user/1000
查看实际磁盘与卷大小
user@ubuntu20-server:~$ sudo fdisk -l
# ... 中间打印信息不管
# 下面这里可以看到磁盘 /dev/sda 大小为 200G
Disk /dev/sda: 200 GiB, 214748364800 bytes, 419430400 sectors
Disk model: VBOX HARDDISK
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: gpt
Disk identifier: 59D06DB3-FFA9-4533-9477-7C6E16D13021
# 卷 /dev/sda2 大小自由 25G
Device Start End Sectors Size Type
/dev/sda1 2048 4095 2048 1M BIOS boot
/dev/sda2 4096 52426751 52422656 25G Linux filesystem
开始扩容
运行 sudo fdisk /dev/sda
注意:这里删除分区不代表就删除内容,所以不必单行内容被删除,只要后面原地添加一个 sda2 即可
user@ubuntu20-server:~$ sudo fdisk /dev/sda
# 输入 d 删除分区
Command (m for help): d
Partition number (1,2, default 2): 2
Partition 2 has been deleted.
# 输入 n 添加分区
Command (m for help): n
Partition number (2-128, default 2): 2
First sector (4096-419430366, default 4096):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (4096-419430366, default 419430366):
Created a new partition 2 of type 'Linux filesystem' and of size 200 GiB.
Partition #2 contains a ext4 signature.
# 输入yes
Do you want to remove the signature? [Y]es/[N]o: yes
The signature will be removed by a write command.
# 查看分区情况
Command (m for help): p
Disk /dev/sda: 200 GiB, 214748364800 bytes, 419430400 sectors
Disk model: VBOX HARDDISK
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: gpt
Disk identifier: 59D06DB3-FFA9-4533-9477-7C6E16D13021
Device Start End Sectors Size Type
/dev/sda1 2048 4095 2048 1M BIOS boot
/dev/sda2 4096 419430366 419426271 200G Linux filesystem
Filesystem/RAID signature on partition 2 will be wiped.
# 输入 w 保存新的分区
Command (m for help): w
The partition table has been altered.
Syncing disks.
重启电脑:reboot
sudo df -h
查看挂在情况,依然是 25G
运行 sudo resize2fs /dev/sda2
更新挂在信息;
user@ubuntu20-server:~$ sudo resize2fs /dev/sda2
resize2fs 1.45.5 (07-Jan-2020)
Filesystem at /dev/sda2 is mounted on /; on-line resizing required
old_desc_blocks = 4, new_desc_blocks = 25
The filesystem on /dev/sda2 is now 52428283 (4k) blocks long.
user@ubuntu20-server:~$ sudo df -h
Filesystem Size Used Avail Use% Mounted on
udev 2.9G 0 2.9G 0% /dev
tmpfs 600M 1.1M 599M 1% /run
/dev/sda2 197G 5.4G 184G 3% /
tmpfs 3.0G 0 3.0G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 3.0G 0 3.0G 0% /sys/fs/cgroup
/dev/loop2 64M 64M 0 100% /snap/core20/1828
/dev/loop0 92M 92M 0 100% /snap/lxd/24061
/dev/loop1 50M 50M 0 100% /snap/snapd/18357
/dev/loop3 41M 41M 0 100% /snap/snapd/20290
tmpfs 600M 0 600M 0% /run/user/1000
参考:
https://blog.csdn.net/netgc/article/details/119978449