虚拟机扩容ubuntu22.04磁盘空间到逻辑卷中。

在现有磁盘基础上直接扩容的。一开始部署的时候,设置的是40GB。现在已经使用30多GB了。需要扩容下。

打开虚拟机设置

把磁盘扩展到一定大小

root@branch-dev:~# df -h
Filesystem                    Size  Used Avail Use% Mounted on
tmpfs                         3.2G  2.2M  3.2G   1% /run
/dev/mapper/ubuntu--vg-lv--0   38G   30G  6.0G  84% /
tmpfs                          16G     0   16G   0% /dev/shm
tmpfs                         5.0M     0  5.0M   0% /run/lock
/dev/sda2                     2.0G  251M  1.6G  14% /boot

 

查看逻辑卷相关信息

root@branch-dev:~# lvs
  LV   VG        Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv-0 ubuntu-vg -wi-ao---- <38.00g                                                    
root@branch-dev:~# pvs
  PV         VG        Fmt  Attr PSize   PFree
  /dev/sda3  ubuntu-vg lvm2 a--  <38.00g    0 
root@branch-dev:~# vgs
  VG        #PV #LV #SN Attr   VSize   VFree
  ubuntu-vg   1   1   0 wz--n- <38.00g    0 

开始扩容

# 使用parted命令
root@branch-dev:~# parted /dev/sda
GNU Parted 3.4
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) help                                                             
align-check TYPE N                       check partition N for TYPE(min|opt) alignment
help [COMMAND]                           print general help, or help on COMMAND
mklabel,mktable LABEL-TYPE               create a new disklabel (partition table)
mkpart PART-TYPE [FS-TYPE] START END     make a partition
name NUMBER NAME                         name partition NUMBER as NAME
print [devices|free|list,all|NUMBER]     display the partition table, available devices, free space, all found partitions, or a particular partition
quit                                     exit program
rescue START END                         rescue a lost partition near START and END
resizepart NUMBER END                    resize partition NUMBER
rm NUMBER                                delete partition NUMBER
select DEVICE                            choose the device to edit
disk_set FLAG STATE                      change the FLAG on selected device
disk_toggle [FLAG]                       toggle the state of FLAG on selected device
set NUMBER FLAG STATE                    change the FLAG on partition NUMBER
toggle [NUMBER [FLAG]]                   toggle the state of FLAG on partition NUMBER
unit UNIT                                set the default unit to UNIT
version                                  display the version number and copyright information of GNU Parted
(parted) print     #打印信息                                                       
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 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  2150MB  2147MB  ext4
3      2150MB  42.9GB  40.8GB

(parted) resizepart 3 100%    #选择第三个
(parted) quit       #退出
Information: You may need to update /etc/fstab.

第一步

root@branch-dev:~# pvresize /dev/sda3
  Physical volume "/dev/sda3" changed
  1 physical volume(s) resized or updated / 0 physical volume(s) not resized

第二步

 
  root@branch-dev:~# lvextend -l +100%FREE /dev/mapper/ubuntu--vg-lv--0
  Size of logical volume ubuntu-vg/lv-0 changed from <38.00 GiB (9727 extents) to <98.00 GiB (25087 extents).
  Logical volume ubuntu-vg/lv-0 successfully resized.

 

第三步

 
  root@branch-dev:~# resize2fs /dev/mapper/ubuntu--vg-lv--0
resize2fs 1.46.5 (30-Dec-2021)
Filesystem at /dev/mapper/ubuntu--vg-lv--0 is mounted on /; on-line resizing required
old_desc_blocks = 5, new_desc_blocks = 13
The filesystem on /dev/mapper/ubuntu--vg-lv--0 is now 25689088 (4k) blocks long.

 

第四步 验证

root@branch-dev:~# df -h
Filesystem                    Size  Used Avail Use% Mounted on
tmpfs                         3.2G  2.2M  3.2G   1% /run
/dev/mapper/ubuntu--vg-lv--0   97G   30G   63G  32% /
tmpfs                          16G     0   16G   0% /dev/shm
tmpfs                         5.0M     0  5.0M   0% /run/lock
/dev/sda2                     2.0G  251M  1.6G  14% /boot
overlay                        97G   30G   63G  32% /var/lib/docker/overlay2/26d3467e6fee1f2f4f585cb3c1acd52e000a4481e42398f643734f88039a2a48/merged
overlay                        97G   30G   63G  32% /var/lib/docker/overlay2/4472858bcb06a4ec49f004b6c9398f63a3c7e8030bbed20e154c1aad6a8a5679/merged
overlay                        97G   30G   63G  32% /var/lib/docker/overlay2/ede99e283b91606ecb041574e1426df839b644441caadae4c3460e15420ec6cf/merged
overlay                        97G   30G   63G  32% /var/lib/docker/overlay2/607f6fdf38fa1686535a546c46454505d31e2f98e25e125409299092a188a923/merged
overlay                        97G   30G   63G  32% /var/lib/docker/overlay2/00e4dc4e79f802916419598a22fb7f50c083ebe60d5bc5acad39ee68a8aa9c8f/merged
overlay                        97G   30G   63G  32% /var/lib/docker/overlay2/4176993e84f29cfd926fc1b7a5c6fa479bbdd7d20ec2a74a4529c67cdb5adf0a/merged
tmpfs                         3.2G  4.0K  3.2G   1% /run/user/0
overlay                        97G   30G   63G  32% /var/lib/docker/overlay2/dfe4a6f793eb756c116f268dd5b16d5df3a5fa3b630d42fc2d4091f7c62b2f4d/merged

 

可见容量已经提升到100GB了。 完成本次扩容。 👌

posted @ 2024-11-01 16:26  糖果的二师兄  阅读(17)  评论(0编辑  收藏  举报