На сайте VMware размещена инструкция по увеличению размера логического тома в виртуальной машине под управлением Red Hat и Cent OS, но написана она для более ранних версий. В результате выполнений действий по инструкции получим ошибку:

 

resize2fs /dev/mapper/centos_ns-root
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/mapper/cent os_ns-root
Couldn't find valid filesystem superblock.

Предварительно диск должен быть расширен средствами гипервизора.

В CentOS / RHEL 7 нужно использовать System Storage Manager.

Устанавливаем его:

yum install system-storage-manager
Installed:
system-storage-manager.noarch 0:0.4-5.el7

После установки находим наш расширеный диск, в моем случае это /dev/sda расширеный до 50 ГБ:

ssm list

--------------------------------------------------------------
Device Free Used Total Pool Mount point
--------------------------------------------------------------
/dev/fd0 4.00 KB
/dev/sda 50.00 GB PARTITIONED
/dev/sda1 500.00 MB /boot
/dev/sda2 0.00 KB 3.51 GB 3.51 GB centos_ns
--------------------------------------------------------------
---------------------------------------------------
Pool Type Devices Free Used Total
---------------------------------------------------
centos_ns lvm 1 0.00 KB 3.51 GB 3.51 GB
---------------------------------------------------
-------------------------------------------------------------------------------------------
Volume Pool Volume size FS FS size Free Type Mount point
-------------------------------------------------------------------------------------------
/dev/centos_ns/root centos_ns 3.11 GB xfs 3.10 GB 2.15 GB linear /
/dev/centos_ns/swap centos_ns 412.00 MB linear
/dev/sda1 500.00 MB xfs 496.67 MB 386.61 MB part /boot

Создаем главный (primary) раздел на расширенном диске:

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: 0x000c30dc
 
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 8388607 3681280 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): 3
First sector (8388608-104857599, default 8388608):
Using default value 8388608
Last sector, +sectors or +size{K,M,G} (8388608-104857599, default 104857599):
Using default value 104857599
Partition 3 of type Linux and of size 46 GiB is set
 
Command (m for help): t
Partition number (1-3, default 3): 3
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to '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.

Перезагружаемся:

shutdown -r now

После загрузки смотрим диски (fdisk -l) должен появится раздел /dev/sda3 с типом 8e

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: 0x000c30dc
 
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 8388607 3681280 8e Linux LVM
/dev/sda3 8388608 104857599 48234496 8e Linux LVM
 
Disk /dev/mapper/centos_ns-root: 3334 MB, 3334471680 bytes, 6512640 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/centos_ns-swap: 432 MB, 432013312 bytes, 843776 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

Преобразовываем новый раздел в физический том

pvcreate /dev/sda3

Physical volume "/dev/sda3" successfully created

Смотрим имя Volume group

vgdisplay

--- Volume group ---
VG Name centos_ns
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 6
VG Access read/write
VG Status resizable

Расширяем Volume group

vgextend centos_ns /dev/sda3

Volume group "centos_ns" successfully extended

Смотрим свободное пространство Volume group:

vgdisplay centos_ns | grep "Free"

Free PE / Size 11775 / 46.00 GiB

Определяем имя нужного Logical Volume:

lvdisplay

--- Logical volume ---
LV Path /dev/centos_ns/root
LV Name root
VG Name centos_ns

Расширяем определенный Logical Volume на свободный размер:

ssm resize -s+46G /dev/centos_ns/root

SSM Error (2005): There is not enough space in the pool 'centos_ns' to grow volume '/dev/centos_ns/root'

Если возникла такая ошибка указываем немного меньше размер

ssm resize -s+45.9G /dev/centos_ns/root

Extending logical volume root to 49.00 GiB
Logical volume root successfully resized
meta-data=/dev/mapper/centos_ns-root isize=256 agcount=60, agsize=203520 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=12058624, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
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 12058624 to 12845056

Диск увеличен!

ssm list

-----------------------------------------------------------------
Device Free Used Total Pool Mount point
-----------------------------------------------------------------
/dev/fd0 4.00 KB
/dev/sda 50.00 GB PARTITIONED
/dev/sda1 500.00 MB /boot
/dev/sda2 0.00 KB 3.51 GB 3.51 GB centos_ns
/dev/sda3 104.00 MB 45.89 GB 46.00 GB centos_ns
-----------------------------------------------------------------
-------------------------------------------------------
Pool Type Devices Free Used Total
-------------------------------------------------------
centos_ns lvm 2 104.00 MB 49.40 GB 49.50 GB
-------------------------------------------------------
-------------------------------------------------------------------------------------------
Volume Pool Volume size FS FS size Free Type Mount point
-------------------------------------------------------------------------------------------
/dev/centos_ns/root centos_ns 49.00 GB xfs 45.99 GB 2.04 GB linear /
/dev/centos_ns/swap centos_ns 412.00 MB linear
/dev/sda1 500.00 MB xfs 496.67 MB 363.48 MB part /boot
-------------------------------------------------------------------------------------------
[root@ns ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos_ns-root 49G 1.1G 48G 3% /
devtmpfs 237M 0 237M 0% /dev
tmpfs 246M 0 246M 0% /dev/shm
tmpfs 246M 4.4M 241M 2% /run
tmpfs 246M 0 246M 0% /sys/fs/cgroup
/dev/sda1 497M 175M 323M 36% /boot

 

Оригинальная статья

Advertisements