如何调整默认 ubuntu lvm 的大小?

如何调整默认 ubuntu lvm 的大小?

我需要添加默认的 ubuntu lvm 分区 +20GB 空间。我该怎么做?您可以在下面看到 lsbkl 命令的输出。这是我的 Virtualbox VM,不是生产服务器,所有这些磁盘和分区都是免费的,包括 raid5。我可以将所有这些用于扩展目的吗?我应该遵循哪些步骤来实现它?

rebrainme2@ubuntu2:~$ lsblk
NAME                      MAJ:MIN RM  SIZE RO TYPE  MOUNTPOINT
loop0                       7:0    0 43.6M  1 loop  /snap/snapd/14978
loop1                       7:1    0 43.6M  1 loop  /snap/snapd/15177
loop2                       7:2    0 55.5M  1 loop  /snap/core18/2344
loop3                       7:3    0 67.9M  1 loop  /snap/lxd/22526
loop4                       7:4    0 61.9M  1 loop  /snap/core20/1361
loop5                       7:5    0 67.2M  1 loop  /snap/lxd/21835
loop6                       7:6    0 61.9M  1 loop  /snap/core20/1376
loop7                       7:7    0 55.5M  1 loop  /snap/core18/2284
sda                         8:0    0   10G  0 disk
├─sda1                      8:1    0    1M  0 part
├─sda2                      8:2    0    1G  0 part  /boot
└─sda3                      8:3    0    9G  0 part
  └─ubuntu--vg-ubuntu--lv 253:2    0    9G  0 lvm   /
sdb                         8:16   0    8G  0 disk
├─sdb1                      8:17   0    2G  0 part  /mnt/sdb1
├─sdb2                      8:18   0    2G  0 part  /mnt/disk
├─sdb3                      8:19   0    2G  0 part  /mnt/sdb3
└─sdb4                      8:20   0    2G  0 part  /mnt/sdb4
sdc                         8:32   0    8G  0 disk
└─md0                       9:0    0   10G  0 raid5 /mnt/raid5
sdd                         8:48   0    2G  0 disk
└─md0                       9:0    0   10G  0 raid5 /mnt/raid5
sde                         8:64   0    2G  0 disk
└─md0                       9:0    0   10G  0 raid5 /mnt/raid5
sdf                         8:80   0    2G  0 disk
└─md0                       9:0    0   10G  0 raid5 /mnt/raid5
sdg                         8:96   0    2G  0 disk
└─md0                       9:0    0   10G  0 raid5 /mnt/raid5
sdh                         8:112  0    5G  0 disk
└─vg--rebrain-lv--rebrain 253:1    0    5G  0 lvm   /mnt/lvm
sdi                         8:128  0    2G  0 disk
└─md0                       9:0    0   10G  0 raid5 /mnt/raid5
sdj                         8:144  0    5G  0 disk
└─vg--test-lv--test       253:0    0    5G  0 lvm   /mnt/lv-test
sr0                        11:0    1 1024M  0 rom


/dev/disk/by-uuid/2d747eec-1c31-4c12-849c-efe362e3245e /boot ext4 defaults 0 1
/swap.img       none    swap    sw      0       0
UUID=a6c59d0e-37a7-4532-b843-6025dabef69f /mnt/sdb1 ext4 defaults 0 2
/dev/sdb2 /mnt/disk btrfs defaults 0 2
UUID=55165d2b-f3b5-46b2-af04-7366861c82b6 /mnt/sdb3 xfs defaults 0 2
UUID=1B74-0C7D /mnt/sdb4 vfat defaults 0 2
UUID=33fbef0a-0b91-41e9-ac7d-7d554797341c /mnt/raid5 ext4 defaults 0 2
UUID=60cd605a-dc94-452f-abe4-203079ac2e67  /mnt/lvm ext4 defaults 0 2
UUID=ed038f9c-896a-4aaf-a703-5134783701ab /mnt/lv-test ext4 defaults 0 2


rebrainme2@ubuntu2:~$ sudo vgdisplay
[sudo] password for rebrainme2:
  --- Volume group ---
  VG Name               vg-test
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  6
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <5.00 GiB
  PE Size               4.00 MiB
  Total PE              1279
  Alloc PE / Size       1279 / <5.00 GiB
  Free  PE / Size       0 / 0
  VG UUID               ZCjGyZ-n1Rs-bT8d-z0cg-k8fO-9d2J-Fonggh

  --- Volume group ---
  VG Name               vg-rebrain
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  9
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <5.00 GiB
  PE Size               4.00 MiB
  Total PE              1279
  Alloc PE / Size       1279 / <5.00 GiB
  Free  PE / Size       0 / 0
  VG UUID               Qu97rM-Fint-1yaA-skTo-F3gg-NOrE-1Mvj7q

  --- Volume group ---
  VG Name               ubuntu-vg
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  2
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <9.00 GiB
  PE Size               4.00 MiB
  Total PE              2303
  Alloc PE / Size       2303 / <9.00 GiB
  Free  PE / Size       0 / 0
  VG UUID               XVpMjv-fuIw-UMG9-eeZN-2E09-sODM-kxF3I8



rebrainme2@ubuntu2:~$ sudo pvdisplay
  --- Physical volume ---
  PV Name               /dev/sdj
  VG Name               vg-test
  PV Size               5.00 GiB / not usable 4.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              1279
  Free PE               0
  Allocated PE          1279
  PV UUID               N5fWom-E678-uzKn-c4Dt-ielb-57GN-9h2kfm

  --- Physical volume ---
  PV Name               /dev/sdh
  VG Name               vg-rebrain
  PV Size               5.00 GiB / not usable 4.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              1279
  Free PE               0
  Allocated PE          1279
  PV UUID               osioC0-jmJe-OiLG-73Qm-63od-JcTm-VW2cCy

  --- Physical volume ---
  PV Name               /dev/sda3
  VG Name               ubuntu-vg
  PV Size               <9.00 GiB / not usable 0
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              2303
  Free PE               0
  Allocated PE          2303
  PV UUID               aZUyYt-IujY-wAjp-Zrdu-PsV5-aVv6-Rqw0ND

答案1

好的,伙计们,我自己做了。这就是我所做的,也许对任何人都有用。以防万一,我想用我所有可用的磁盘扩展 ubuntu 默认逻辑卷。

  1. 删除逻辑卷

    sudo lvremove vg-test/lv-test sudo lvremove vg-rebrain/lv-rebrain

  2. 删除卷组

    sudo vgremove vg-rebrain sudo vgremove vg-test

  3. 执行pvscan检查所有pv名称

  4. 扩展 ubuntu 默认 vg

    sudo vgextend ubuntu-vg /dev/sdh sudo vgextend ubuntu-vg /dev/sdj

  5. 扩展逻辑卷

    sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv

  6. 调整文件系统大小

    sudo resize2fs /dev/ubuntu-vg/ubuntu-lv

然后我决定将所有磁盘添加到当前 raid5 大规模 /dev/md0

sudo mdadm --add /dev/md0 /dev/sdb4
sudo mdadm --add /dev/md0 /dev/sdb3
sudo mdadm --add /dev/md0 /dev/sdb1
sudo mdadm --grow --raid-devices=9 /dev/md0

为了监控这个过程我使用了mdadm --detail /dev/md0

在此之后我决定将所有 raid5 磁盘空间添加到逻辑卷 ubuntu-lv:

sudo pvcreate /dev/md0
sudo vgextend ubuntu-vg /dev/md0
sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv

相关内容