Данный вариант не прентендует на правильность, возможно куда более правильно просто добавить в ВМ еще один диск.
В примере исправим GPT и увеличим размер LVM.
Если вам по какой либо причине понадобилось изменить размер системного диска на сервере, перед разбивкой и дальнейшей разметкой необходимо исправить таблицу GPT чтобы операционная система увидела дополнительное место.
После загрузки ОС проверяем информацию о диске:
fdisk -l или gdisk -l /dev/sda
fdisk -l
GPT PMBR size mismatch (146800639 != 2097151999) will be corrected by w(rite).
Disk /dev/sda: 1000 GiB, 1073741824000 bytes, 2097152000 sectors
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: 47A7D05D-BC6C-486A-853B-5388B9732ECD
Device Start End Sectors Size Type
/dev/sda1 2048 4095 2048 1M BIOS boot
/dev/sda2 4096 2101247 2097152 1G Linux filesystem
/dev/sda3 2101248 146798591 144697344 69G Linux filesystem
=============================================================
gdisk -l /dev/sda
GPT fdisk (gdisk) version 1.0.3
Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present
Found valid GPT with protective MBR; using GPT.
Disk /dev/sda: 2097152000 sectors, 1000.0 GiB
Model: QEMU HARDDISK
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): 47A7D05D-BC6C-486A-853B-5388B9732ECD
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 146800606
Partitions will be aligned on 2048-sector boundaries
Total free space is 4029 sectors (2.0 MiB)
Number Start (sector) End (sector) Size Code Name
1 2048 4095 1024.0 KiB EF02
2 4096 2101247 1024.0 MiB 8300
3 2101248 146798591 69.0 GiB 8300
Из примера выше видно что система видит 2097152000 секторов, но использовать может только 146800606
Исправим раздел GPT:
parted -l
parted -l
Warning: Not all of the space available to /dev/sda appears to be used, you can
fix the GPT to use all of the space (an extra 1950351360 blocks) or continue
with the current setting?
Fix/Ignore? F
Model: QEMU QEMU HARDDISK (scsi)
Disk /dev/sda: 1074GB
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 1076MB 1074MB ext4
3 1076MB 75.2GB 74.1GB
Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 42.9GB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags:
Number Start End Size File system Flags
1 0.00B 42.9GB 42.9GB ext4
Теперь можем создать новый раздел на диске:
gdisk /dev/sda
Используем ключи n и w и следуем подсказкам программы
gdisk /dev/sda
GPT fdisk (gdisk) version 1.0.3
Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present
Found valid GPT with protective MBR; using GPT.
Command (? for help): print
Disk /dev/sda: 2097152000 sectors, 1000.0 GiB
Model: QEMU HARDDISK
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): 47A7D05D-BC6C-486A-853B-5388B9732ECD
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 2097151966
Partitions will be aligned on 2048-sector boundaries
Total free space is 1950355389 sectors (930.0 GiB)
Number Start (sector) End (sector) Size Code Name
1 2048 4095 1024.0 KiB EF02
2 4096 2101247 1024.0 MiB 8300
3 2101248 146798591 69.0 GiB 8300
Command (? for help): n
Partition number (4-128, default 4): 4
First sector (34-2097151966, default = 146798592) or {+-}size{KMGTP}:
Last sector (146798592-2097151966, default = 2097151966) or {+-}size{KMGTP}:
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300):
Changed type of partition to 'Linux filesystem'
Command (? for help): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sda.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot or after you
run partprobe(8) or kpartx(8)
The operation has completed successfully.
После того как новый раздел создан, необходимо реинициализировать диск с системой.
Выполним команду partprobe
Так как у нас LVM, следует создать physycal volume на свободном месте
pvcreate /dev/sda4
Проверяем название VG volume group
vgdisplay
vgdisplay
--- 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 <69.00 GiB
PE Size 4.00 MiB
Total PE 17663
Alloc PE / Size 10240 / 40.00 GiB
Free PE / Size 7423 / <29.00 GiB
VG UUID 03c7Ox-EWs9-SEUA-KzkO-ggxR-qzGi-b2RNSI
Видим что VG Name: ubuntu-vg
Добавляем волум в группу
vgextend ubuntu-vg /dev/sda4
Проверяем волумы в группе
pvscan
pvscan
PV /dev/sda3 VG ubuntu-vg lvm2 [<69.00 GiB / <29.00 GiB free]
PV /dev/sda4 VG ubuntu-vg lvm2 [<930.00 GiB / <930.00 GiB free]
Total: 2 [998.99 GiB] / in use: 2 [998.99 GiB] / in no VG: 0 [0 ]
Смотрим какие у нас есть logical volume
lvdisplay
lvdisplay
--- Logical volume ---
LV Path /dev/ubuntu-vg/ubuntu-lv
LV Name ubuntu-lv
VG Name ubuntu-vg
LV UUID bSZG40-Citg-CwGK-gi8Z-l7MA-rIIf-NWm56F
LV Write Access read/write
LV Creation host, time ubuntu-server, 2020-03-03 20:44:24 +0000
LV Status available
# open 1
LV Size 40.00 GiB
Current LE 10240
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
И увеличиваем размер logical volume
lvresize -L +730G —resizefs ubuntu-vg/ubuntu-lv
lvresize -L +730G --resizefs ubuntu-vg/ubuntu-lv
Size of logical volume ubuntu-vg/ubuntu-lv changed from 40.00 GiB (10240 extents) to 770.00 GiB (197120 extents).
Logical volume ubuntu-vg/ubuntu-lv successfully resized.
resize2fs 1.44.1 (24-Mar-2018)
Filesystem at /dev/mapper/ubuntu--vg-ubuntu--lv is mounted on /; on-line resizing required
old_desc_blocks = 5, new_desc_blocks = 97
The filesystem on /dev/mapper/ubuntu--vg-ubuntu--lv is now 201850880 (4k) blocks long.
По желанию запускаем df -h и любуемся тем что у нас получилось