Увеличение LVM раздела для OS CentOS

Менеджер логических томов (англ. logical volume manager) — это подсистема операционных систем Linux и OS/2, позволяющая использовать разные области одного жёсткого диска и/или области с разных жёстких дисков как один логический том. Реализована с помощью подсистемы device mapper [1].

1. Просмотр текущих разделов и устройств

[root@centos-vm ~]# fdisk -l Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 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 Disk label type: dos Disk identifier: 0x000ae3ad Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 20971519 9436160 8e Linux LVM Disk /dev/mapper/cl-root: 8585 MB, 8585740288 bytes, 16769024 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 Disk /dev/mapper/cl-swap: 1073 MB, 1073741824 bytes, 2097152 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

2. Подключаемся к нашему диску /dev/sda и создаём новый раздел

Partition number (1-4) - выбирается следующий свободный номер. Так как sda1 и sda2 уже заняты, используем следующий номер после двойки, это 3.

[root@centos-vm ~]# fdisk /dev/sda Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them. Be careful before using the write command.

Command (m for help): p

Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 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 Disk label type: dos Disk identifier: 0x000ae3ad

Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 20971519 9436160 8e Linux LVM

Command (m for help): n Partition type: p primary (2 primary, 0 extended, 2 free) e extended Select (default p): p Partition number (3,4, default 3): First sector (20971520-104857599, default 20971520): Using default value 20971520 Last sector, +sectors or +size{K,M,G} (20971520-104857599, default 104857599): Using default value 104857599 Partition 3 of type Linux and of size 40 GiB is set

Command (m for help): t Partition number (1-3, default 3): Hex code (type L to list all codes): 8e Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p

Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 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 Disk label type: dos Disk identifier: 0x000ae3ad

Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 20971519 9436160 8e Linux LVM /dev/sda3 20971520 104857599 41943040 8e Linux LVM

Command (m for help): w The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: 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) Syncing disks.

3. Выполняем перезагрузку виртуальной машины

4. Проверяем создание нового LVM-раздела

[root@centos-vm ~]# fdisk -l

Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 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 Disk label type: dos Disk identifier: 0x000ae3ad

Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 20971519 9436160 8e Linux LVM /dev/sda3 20971520 104857599 41943040 8e Linux LVM

Disk /dev/mapper/cl-root: 8585 MB, 8585740288 bytes, 16769024 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

Disk /dev/mapper/cl-swap: 1073 MB, 1073741824 bytes, 2097152 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

5. Расширение диска

5.1. Создаём том

[root@centos-vm ~]# pvcreate /dev/sda3 Physical volume "/dev/sda3" successfully created.

5.2. Просмотр и расширение требуемого диска

[root@centos-vm ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/cl-root 8.0G 1.2G 6.9G 15% / devtmpfs 906M 0 906M 0% /dev tmpfs 916M 0 916M 0% /dev/shm tmpfs 916M 8.5M 908M 1% /run tmpfs 916M 0 916M 0% /sys/fs/cgroup /dev/sda1 1014M 138M 877M 14% /boot tmpfs 184M 0 184M 0% /run/user/0
[root@centos-vm ~]# vgdisplay --- Volume group --- VG Name cl System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 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 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 WXAeXq-GrUz-4R1B-tn0b-vkk1-ZbjA-UaNUqF

[root@centos-vm ~]# vgextend cl /dev/sda3 Volume group "cl" successfully extended
[root@centos-vm ~]# pvscan PV /dev/sda2 VG cl lvm2 [9.00 GiB / 0 free] PV /dev/sda3 VG cl lvm2 [40.00 GiB / 40.00 GiB free] Total: 2 [48.99 GiB] / in use: 2 [48.99 GiB] / in no VG: 0 [0 ]
[root@centos-vm ~]# lvdisplay --- Logical volume --- LV Path /dev/cl/swap LV Name swap VG Name cl LV UUID wBczTI-WAlw-Unoj-PYsp-Kc15-WCTN-7cMMwL LV Write Access read/write LV Creation host, time localhost.localdomain, 2017-08-14 09:00:36 +0300 LV Status available # open 2 LV Size 1.00 GiB Current LE 256 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:1

--- Logical volume --- LV Path /dev/cl/root LV Name root VG Name cl LV UUID vnVoAA-SmHx-UUAv-35dL-FlL1-vMdz-Su2iCW LV Write Access read/write LV Creation host, time localhost.localdomain, 2017-08-14 09:00:36 +0300 LV Status available # open 1 LV Size 8.00 GiB Current LE 2047 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:0

[root@centos-vm ~]# lvextend -l+100%FREE /dev/cl/root Size of logical volume cl/root changed from 8.00 GiB (2047 extents) to 47.99 GiB (12286 extents). Logical volume cl/root successfully resized.
[root@centos-vm ~]# vgscan Reading volume groups from cache. Found volume group "cl" using metadata type lvm2
[root@centos-vm ~]# vgchange -ay 2 logical volume(s) in volume group "cl" now active
[root@centos-vm ~]# xfs_growfs /dev/cl/root meta-data=/dev/mapper/cl-root isize=512 agcount=4, agsize=524032 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=2096128, 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 2096128 to 12580864
[root@centos-vm ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/cl-root 48G 1.2G 47G 3% / devtmpfs 906M 0 906M 0% /dev tmpfs 916M 0 916M 0% /dev/shm tmpfs 916M 8.5M 908M 1% /run tmpfs 916M 0 916M 0% /sys/fs/cgroup /dev/sda1 1014M 138M 877M 14% /boot tmpfs 184M 0 184M 0% /run/user/0