翼度科技»论坛 云主机 LINUX 查看内容

Ubuntu 22.04扩容LVM空间

11

主题

11

帖子

33

积分

新手上路

Rank: 1

积分
33
今天为了编译ThingsBoard的源代码,发现原来给虚拟机分配的40个G不够用了。于是乎在VMWare Workstation中扩容了40G的磁盘空间。但是此时lvm是不会自动扩容的,因此我们需要手动调整下卷的配置。
首先df -h检查发现挂载的空间的确没有变化
  1. mrchip@ubuntu22:~$ df -h
  2. Filesystem                         Size  Used Avail Use% Mounted on
  3. tmpfs                              791M  2.5M  788M   1% /run
  4. /dev/mapper/ubuntu--vg-ubuntu--lv   37G   35G     0 100% /
  5. tmpfs                              3.9G     0  3.9G   0% /dev/shm
  6. tmpfs                              5.0M     0  5.0M   0% /run/lock
  7. /dev/sda2                          2.0G  253M  1.6G  14% /boot
  8. shm                                 64M     0   64M   0% /run/k3s/containerd/io.containerd.grpc.v1.cri/sandboxes/e80883038e918e14fc90c4519ecc708e642d079d7482ae9a0b78b456c0502ed3/shm
  9. shm                                 64M     0   64M   0% /run/k3s/containerd/io.containerd.grpc.v1.cri/sandboxes/baca760e9d9316152da7adb633a6bb05ab76e6cbfe1267bea951f1b3a9038c05/shm
  10. shm                                 64M     0   64M   0% /run/k3s/containerd/io.containerd.grpc.v1.cri/sandboxes/e8f65d1e3aa83c67c5c55ae5e2bce0b87e905477d0a7dc20ee6fc15a47d2a2eb/shm
  11. shm                                 64M     0   64M   0% /run/k3s/containerd/io.containerd.grpc.v1.cri/sandboxes/1d091959988cd36e8f71b01572a2e37e341238d263627d8eb839798c4dec86d9/shm
  12. tmpfs                              791M  4.0K  791M   1% /run/user/1000
复制代码
然后运行lsblk发现磁盘的确变大了
  1. NAME                      MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
  2. loop0                       7:0    0 48.6M  1 loop /snap/cmake/1390
  3. loop1                       7:1    0 48.6M  1 loop /snap/cmake/1391
  4. loop2                       7:2    0 63.9M  1 loop /snap/core20/2182
  5. loop3                       7:3    0 63.9M  1 loop /snap/core20/2318
  6. loop4                       7:4    0 66.2M  1 loop /snap/core24/405
  7. loop5                       7:5    0 66.2M  1 loop /snap/core24/423
  8. loop6                       7:6    0   87M  1 loop /snap/lxd/27948
  9. loop7                       7:7    0 17.7M  1 loop /snap/helm/414
  10. loop8                       7:8    0   87M  1 loop /snap/lxd/28373
  11. loop9                       7:9    0 38.7M  1 loop /snap/snapd/21465
  12. loop10                      7:10   0 38.8M  1 loop /snap/snapd/21759
  13. sda                         8:0    0   80G  0 disk
  14. ├─sda1                      8:1    0    1M  0 part
  15. ├─sda2                      8:2    0    2G  0 part /boot
  16. └─sda3                      8:3    0   38G  0 part
  17.   └─ubuntu--vg-ubuntu--lv 253:0    0   37G  0 lvm  /
  18. sr0                        11:0    1    2G  0 rom
复制代码
接下来我们记录命令操作来扩容分区
1. 将新的空间新建一个磁盘分区
  1. mrchip@ubuntu22:~$ sudo fdisk /dev/sda
  2. [sudo] password for mrchip:
  3. Welcome to fdisk (util-linux 2.37.2).
  4. Changes will remain in memory only, until you decide to write them.
  5. Be careful before using the write command.
  6. GPT PMBR size mismatch (83886079 != 167772159) will be corrected by write.
  7. This disk is currently in use - repartitioning is probably a bad idea.
  8. It's recommended to umount all file systems, and swapoff all swap
  9. partitions on this disk.
  10. Command (m for help): n
  11. Partition number (4-128, default 4):
  12. First sector (83884032-167772126, default 83884032):
  13. Last sector, +/-sectors or +/-size{K,M,G,T,P} (83884032-167772126, default 167772126):
  14. Created a new partition 4 of type 'Linux filesystem' and of size 40 GiB.
  15. Command (m for help): w
  16. The partition table has been altered.
  17. Syncing disks.
复制代码
2. 将新建的分区sda4转换为PV并拓展ubuntu-vg这个卷组
  1. mrchip@ubuntu22:~$ sudo pvcreate -ff -y /dev/sda4
  2.   Physical volume "/dev/sda4" successfully created.
  3. mrchip@ubuntu22:~$ sudo vgextend ubuntu-vg /dev/sda4
  4.   Volume group "ubuntu-vg" successfully extended
  5. mrchip@ubuntu22:~$ sudo vgdisplay
  6.   --- Volume group ---
  7.   VG Name               ubuntu-vg
  8.   System ID
  9.   Format                lvm2
  10.   Metadata Areas        2
  11.   Metadata Sequence No  3
  12.   VG Access             read/write
  13.   VG Status             resizable
  14.   MAX LV                0
  15.   Cur LV                1
  16.   Open LV               1
  17.   Max PV                0
  18.   Cur PV                2
  19.   Act PV                2
  20.   VG Size               77.99 GiB
  21.   PE Size               4.00 MiB
  22.   Total PE              19966
  23.   Alloc PE / Size       9472 / 37.00 GiB
  24.   Free  PE / Size       10494 / 40.99 GiB
  25.   VG UUID               aa7Nif-O9wu-0AMo-pxFA-RTsq-v48M-MZ5EUm
复制代码
3. 扩容ubuntu-lv这个逻辑空间
  1. sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv  Size of logical volume ubuntu-vg/ubuntu-lv changed from 37.00 GiB (9472 extents) to 77.99 GiB (19966 extents).  Logical volume ubuntu-vg/ubuntu-lv successfully resized.mrchip@ubuntu22:~$ df -h
  2. Filesystem                         Size  Used Avail Use% Mounted on
  3. tmpfs                              791M  2.5M  788M   1% /run
  4. /dev/mapper/ubuntu--vg-ubuntu--lv   37G   35G     0 100% /
  5. tmpfs                              3.9G     0  3.9G   0% /dev/shm
  6. tmpfs                              5.0M     0  5.0M   0% /run/lock
  7. /dev/sda2                          2.0G  253M  1.6G  14% /boot
  8. shm                                 64M     0   64M   0% /run/k3s/containerd/io.containerd.grpc.v1.cri/sandboxes/e80883038e918e14fc90c4519ecc708e642d079d7482ae9a0b78b456c0502ed3/shm
  9. shm                                 64M     0   64M   0% /run/k3s/containerd/io.containerd.grpc.v1.cri/sandboxes/baca760e9d9316152da7adb633a6bb05ab76e6cbfe1267bea951f1b3a9038c05/shm
  10. shm                                 64M     0   64M   0% /run/k3s/containerd/io.containerd.grpc.v1.cri/sandboxes/e8f65d1e3aa83c67c5c55ae5e2bce0b87e905477d0a7dc20ee6fc15a47d2a2eb/shm
  11. shm                                 64M     0   64M   0% /run/k3s/containerd/io.containerd.grpc.v1.cri/sandboxes/1d091959988cd36e8f71b01572a2e37e341238d263627d8eb839798c4dec86d9/shm
  12. tmpfs                              791M  4.0K  791M   1% /run/user/1000
复制代码
4. 对lvm分区的大小进行拓展
  1. mrchip@ubuntu22:~$ sudo resize2fs /dev/ubuntu-vg/ubuntu-lv
  2. resize2fs 1.46.5 (30-Dec-2021)
  3. Filesystem at /dev/ubuntu-vg/ubuntu-lv is mounted on /; on-line resizing required
  4. old_desc_blocks = 5, new_desc_blocks = 10
  5. The filesystem on /dev/ubuntu-vg/ubuntu-lv is now 20445184 (4k) blocks long.
  6. mrchip@ubuntu22:~$ df -h
  7. Filesystem                         Size  Used Avail Use% Mounted on
  8. tmpfs                              791M  2.5M  788M   1% /run
  9. /dev/mapper/ubuntu--vg-ubuntu--lv   77G   35G   39G  48% /
  10. tmpfs                              3.9G     0  3.9G   0% /dev/shm
  11. tmpfs                              5.0M     0  5.0M   0% /run/lock
  12. /dev/sda2                          2.0G  253M  1.6G  14% /boot
  13. shm                                 64M     0   64M   0% /run/k3s/containerd/io.containerd.grpc.v1.cri/sandboxes/e80883038e918e14fc90c4519ecc708e642d079d7482ae9a0b78b456c0502ed3/shm
  14. shm                                 64M     0   64M   0% /run/k3s/containerd/io.containerd.grpc.v1.cri/sandboxes/baca760e9d9316152da7adb633a6bb05ab76e6cbfe1267bea951f1b3a9038c05/shm
  15. shm                                 64M     0   64M   0% /run/k3s/containerd/io.containerd.grpc.v1.cri/sandboxes/e8f65d1e3aa83c67c5c55ae5e2bce0b87e905477d0a7dc20ee6fc15a47d2a2eb/shm
  16. shm                                 64M     0   64M   0% /run/k3s/containerd/io.containerd.grpc.v1.cri/sandboxes/1d091959988cd36e8f71b01572a2e37e341238d263627d8eb839798c4dec86d9/shm
  17. tmpfs                              791M  4.0K  791M   1% /run/user/1000
复制代码
参考链接

来源:https://www.cnblogs.com/mrchip/p/18243814
免责声明:由于采集信息均来自互联网,如果侵犯了您的权益,请联系我们【E-Mail:cb@itdo.tech】 我们会及时删除侵权内容,谢谢合作!

举报 回复 使用道具