четверг, 16 мая 2019 г.

Увеличение размера диска виртуальной машины Debian9 (LVM, fdisk,pvresize)


пересоздание таблицы разделов
1) Проверяем размер диска (/dev/sda)
root@dctest-d:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 30G 0 disk
├─sda1 8:1 0 243M 0 part /boot
├─sda2 8:2 0 1K 0 part
└─sda5 8:5 0 29.8G 0 part
├─dctest--d--vg-root 254:0 0 25.8G 0 lvm /
└─dctest--d--vg-swap_1 254:1 0 4G 0 lvm [SWAP]
sr0 11:0 1 1024M 0 rom

2) Увеличиваем размер диска (с 30 до 50 ГБ) средствами гипервизора

3) Выполняем сканирование диска (поиск изменений)
root@dctest-d:~# echo 1 > /sys/block/sda/device/rescan

4) Проверяем изменения /dev/sda
root@dctest-d:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 48.8G 0 disk
├─sda1 8:1 0 243M 0 part /boot
├─sda2 8:2 0 1K 0 part
└─sda5 8:5 0 29.8G 0 part
├─dctest--d--vg-root 254:0 0 25.8G 0 lvm /
└─dctest--d--vg-swap_1 254:1 0 4G 0 lvm [SWAP]
sr0 11:0 1 1024M 0 rom

5) Выполняем изменения таблицы разделов
root@dctest-d:~# fdisk /dev/sda

Welcome to fdisk (util-linux 2.29.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

6) Смотрим на размеры диска и существующих разделов
Command (m for help): p
Disk /dev/sda: 48.8 GiB, 52428800000 bytes, 102400000 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: dos
Disk identifier: 0xbb4a9424

Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 499711 497664 243M 83 Linux
/dev/sda2 501758 62912511 62410754 29.8G 5 Extended
/dev/sda5 501760 62912511 62410752 29.8G 8e Linux LVM

7) Удаляем разделы, начиная с последнего
Command (m for help): d
Partition number (1,2,5, default 5): 5
Partition 5 has been deleted.

Command (m for help): d
Partition number (1,2, default 2): 2
Partition 2 has been deleted.

8) Создаём дополнительный раздел (от первого свободного блока и до конца диска, соглашаясь на дефолтные значения секторов)

Command (m for help): n
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p): e
Partition number (2-4, default 2):
First sector (499712-102399999, default 499712):
Last sector, +sectors or +size{K,M,G,T,P} (499712-102399999, default 102399999):

Created a new partition 2 of type 'Extended' and of size 48.6 GiB.

Command (m for help): n
All space for primary partitions is in use.
Adding logical partition 5
First sector (501760-102399999, default 501760):
Last sector, +sectors or +size{K,M,G,T,P} (501760-102399999, default 102399999):

Created a new partition 5 of type 'Linux' and of size 48.6 GiB.

9) НЕ УДАЛЯЕМ старую подпись раздела
Partition #5 contains a LVM2_member signature.
Do you want to remove the signature? [Y]es/[N]o: n

10) Изменяем тип раздела на Linux LVM
Command (m for help): t
Partition number (1,2,5, default 5): 5
Partition type (type L to list all types): 8e

Changed type of partition 'Linux' to 'Linux LVM'.

11) Проверяем размеры диска и созданных разделов
Command (m for help): p
Disk /dev/sda: 48.8 GiB, 52428800000 bytes, 102400000 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: dos
Disk identifier: 0xbb4a9424

Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 499711 497664 243M 83 Linux
/dev/sda2 499712 102399999 101900288 48.6G 5 Extended
/dev/sda5 501760 102399999 101898240 48.6G 8e Linux LVM

12) Сохраняем изменения и выходим из fdisk
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: Device or resource busy
The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).

13) Сообщаем системе об изменениях в разделах
root@dctest-d:~# partprobe

14) Проверяем изменения раздела sda5
root@dctest-d:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 48.8G 0 disk
├─sda1 8:1 0 243M 0 part /boot
├─sda2 8:2 0 512B 0 part
└─sda5 8:5 0 48.6G 0 part
├─dctest--d--vg-root 254:0 0 25.8G 0 lvm /
└─dctest--d--vg-swap_1 254:1 0 4G 0 lvm [SWAP]
sr0 11:0 1 1024M 0 rom

15) LVM. Проверяем размер PV /dev/sda5
====================================
root@dctest-d:~# pvdisplay
--- Physical volume ---
PV Name /dev/sda5
VG Name dctest-d-vg
PV Size 29.76 GiB / not usable 2.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 7618
Free PE 0
Allocated PE 7618
PV UUID iiyna2-lRS7-7gPm-QZX2-kRpH-Ssw2-ehFBSz

16) LVM. Изменяем размер PV /dev/sda5 и проверяем это
root@dctest-d:~# pvresize /dev/sda5
Physical volume "/dev/sda5" changed
1 physical volume(s) resized / 0 physical volume(s) not resized
root@dctest-d:~# pvdisplay
--- Physical volume ---
PV Name /dev/sda5
VG Name dctest-d-vg
PV Size 48.59 GiB / not usable 2.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 12438
Free PE 4820
Allocated PE 7618
PV UUID iiyna2-lRS7-7gPm-QZX2-kRpH-Ssw2-ehFBSz
17) LVM. Проверяем наличие свободного места в VG после расширения /dev/sda5
root@dctest-d:~# vgdisplay
--- Volume group ---
VG Name dctest-d-vg
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 48.59 GiB
PE Size 4.00 MiB
Total PE 12438
Alloc PE / Size 7618 / 29.76 GiB
Free PE / Size 4820 / 18.83 GiB
VG UUID 68qJjk-Uib6-AM1W-OCdG-3e2p-qmvs-IgCuJb

18) LVM. Проверяем размер LV /dev/dctest-d-vg/root
root@dctest-d:~# lvdisplay
--- Logical volume ---
LV Path /dev/dctest-d-vg/root
LV Name root
VG Name dctest-d-vg
LV UUID P6PiaC-thno-e5h7-Lo75-KM1v-Qpw4-2b5QSN
LV Write Access read/write
LV Creation host, time dctest-d, 2019-05-16 08:11:12 +0300
LV Status available
# open 1
LV Size 25.76 GiB
Current LE 6594
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 254:0
--- Logical volume ---
LV Path /dev/dctest-d-vg/swap_1
LV Name swap_1
VG Name dctest-d-vg
LV UUID Xe11YQ-IYrD-D5Xs-5oQy-1b1r-VkQe-6AL4ab
LV Write Access read/write
LV Creation host, time dctest-d, 2019-05-16 08:11:12 +0300
LV Status available
# open 2
LV Size 4.00 GiB
Current LE 1024
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 254:1

19) LVM. Изменяем размер LV /dev/dctest-d-vg/root и проверяем это
root@dctest-d:~# lvextend -l +100%FREE /dev/dctest-d-vg/root
Size of logical volume dctest-d-vg/root changed from 25.76 GiB (6594 extents) to 44.59 GiB (11414 extents).
Logical volume dctest-d-vg/root successfully resized.
root@dctest-d:~# lvdisplay
--- Logical volume ---
LV Path /dev/dctest-d-vg/root
LV Name root
VG Name dctest-d-vg
LV UUID P6PiaC-thno-e5h7-Lo75-KM1v-Qpw4-2b5QSN
LV Write Access read/write
LV Creation host, time dctest-d, 2019-05-16 08:11:12 +0300
LV Status available
# open 1
LV Size 44.59 GiB
Current LE 11414
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 254:0
--- Logical volume ---
LV Path /dev/dctest-d-vg/swap_1
LV Name swap_1
VG Name dctest-d-vg
LV UUID Xe11YQ-IYrD-D5Xs-5oQy-1b1r-VkQe-6AL4ab
LV Write Access read/write
LV Creation host, time dctest-d, 2019-05-16 08:11:12 +0300
LV Status available
# open 2
LV Size 4.00 GiB
Current LE 1024
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 254:1
17) LVM. Проверяем отсутствие свободного места в VG после расширения LV /dev/dctest-d-vg/root
root@dctest-d:~# vgdisplay
--- Volume group ---
VG Name dctest-d-vg
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 48.59 GiB
PE Size 4.00 MiB
Total PE 12438
Alloc PE / Size 12438 / 48.59 GiB
Free PE / Size 0 / 0
VG UUID 68qJjk-Uib6-AM1W-OcdG-3e2p-qmvs-IgCuJb

17) FS. Проверяем свободное/занятое место на файловой системе
root@dctest-d:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 2.0G 0 2.0G 0% /dev
tmpfs 396M 5.4M 391M 2% /run
/dev/mapper/dctest--d--vg-root 26G 794M 24G 4% /
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/sda1 236M 37M 187M 17% /boot
tmpfs 396M 0 396M 0% /run/user/1000
18) FS. Изменяем размер файловой системы и проверяем это
root@dctest-d:~# resize2fs /dev/mapper/dctest--d--vg-root
resize2fs 1.43.4 (31-Jan-2017)
Filesystem at /dev/mapper/dctest--d--vg-root is mounted on /; on-line resizing required
old_desc_blocks = 4, new_desc_blocks = 6
The filesystem on /dev/mapper/dctest--d--vg-root is now 11687936 (4k) blocks long.

root@dctest-d:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 2.0G 0 2.0G 0% /dev
tmpfs 396M 5.4M 391M 2% /run
/dev/mapper/dctest--d--vg-root 44G 802M 41G 2% /
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/sda1 236M 37M 187M 17% /boot
tmpfs 396M 0 396M 0% /run/user/1000
root@dctest-d:~#