вторник, 18 июня 2019 г.

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


1) Проверяем размер диска (/dev/sda)
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]



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

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

4) Проверяем изменения /dev/sda
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 34.2G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sr0 11:0 1 1024M 0 rom

5) Выполняем изменения таблицы разделов
[root@localhost ~]# parted /dev/sda
GNU Parted 3.1
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sda: 36.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 1075MB 1074MB primary xfs boot
2 1075MB 21.5GB 20.4GB primary lvm

(parted) resizepart 2 100%
(parted) p
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sda: 36.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 1075MB 1074MB primary xfs boot
2 1075MB 36.7GB 35.6GB primary lvm

(parted) q
Information: You may need to update /etc/fstab.

6) Сообщаем системе об изменениях в разделах
[root@localhost ~]# partprobe

7) Проверяем изменение размера раздела /dev/sda2
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 34.2G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 33.2G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sr0 11:0 1 1024M 0 rom

8) LVM. Проверяем размер PV
[root@localhost centos]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size <19.00 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 4863
Free PE 0
Allocated PE 4863
PV UUID c0zAhK-YH42-cSt5-ghyT-vmrr-Jefh-flIeFS

9) LVM. Изменяем и проверяем размер PV /dev/sda2
[root@localhost centos]# pvresize /dev/sda2
Physical volume "/dev/sda2" changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resized
[root@localhost centos]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size <33.18 GiB / not usable 2.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 8493
Free PE 3630
Allocated PE 4863
PV UUID c0zAhK-YH42-cSt5-ghyT-vmrr-Jefh-flIeFS
10) LVM. Проверяем размер LV, Изменяем и снова проверяем размер LV /dev/centos/root

[root@localhost centos]# lvresize -rl +100%FREE /dev/centos/root
Size of logical volume centos/root changed from <17.00 GiB (4351 extents) to <31.18 GiB (7981 extents).
Logical volume centos/root successfully resized.
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=1113856 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=4455424, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 4455424 to 8172544

11) FS. Проверяем свободное место
[root@localhost centos]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 32G 4.1G 28G 13% /
devtmpfs 984M 0 984M 0% /dev
tmpfs 1000M 0 1000M 0% /dev/shm
tmpfs 1000M 9.2M 991M 1% /run
tmpfs 1000M 0 1000M 0% /sys/fs/cgroup
/dev/sda1 1014M 197M 818M 20% /boot
tmpfs 200M 12K 200M 1% /run/user/42
tmpfs 200M 0 200M 0% /run/user/1000