环境:
ubuntu20版本
说明:可结合文章【ubuntu挂载目录,拓展分区大小】学习
绿色字体为输入指令
红色字体为注意信息
## 1、查看当前分区情况
root@ecs-35dd-1120188:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 252:0 0 100G 0 disk
├─vda1 252:1 0 1M 0 part
├─vda2 252:2 0 4G 0 part [SWAP]
└─vda3 252:3 0 46G 0 part /
vdb 252:16 0 100G 0 disk
## 2、选择磁盘/dev/vda,print信息,自动提示fix
parted /dev/vda
(parted) print
Warning: Not all of the space available to /dev/vda appears to be used, you can fix the GPT to use all of the space (an extra 104857600 blocks) or continue with the current setting?
Fix/Ignore? fix
Model: Virtio Block Device (virtblk)
Disk /dev/vda: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 2097kB 1049kB bios_grub
2 2097kB 4297MB 4295MB linux-swap(v1) swap
3 4297MB 53.7GB 49.4GB ext4
## 3、改变分区大小100%
(parted) resizepart 3
Warning: Partition /dev/vda3 is being used. Are you sure you want to continue?
Yes/No? yes
End? [53.7GB]? 100%
(parted) print
Model: Virtio Block Device (virtblk)
Disk /dev/vda: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 2097kB 1049kB bios_grub
2 2097kB 4297MB 4295MB linux-swap(v1) swap
3 4297MB 107GB 103GB ext4
(parted) quit
Information: You may need to update /etc/fstab.
root@ecs-35dd-1120188:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 252:0 0 100G 0 disk
├─vda1 252:1 0 1M 0 part
├─vda2 252:2 0 4G 0 part [SWAP]
└─vda3 252:3 0 96G 0 part /
vdb 252:16 0 100G 0 disk
## 4、分区调整完成后,需要扩展文件系统
sudo resize2fs /dev/vda3
## 5、查看完成后情况,无需重启即可生效,不影响原来数据
root@ecs-35dd-1120188:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 3.9G 0 3.9G 0% /dev
tmpfs 797M 940K 796M 1% /run
/dev/vda3 95G 38G 53G 43% /
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 5.0M 8.0K 5.0M 1% /run/lock
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
tmpfs 797M 0 797M 0% /run/user/0