Как расширить раздел файловой системы LVM в CentOS 7.x Print

  • CentOS, fdisk, lvextend, lvdisplay, pvcreate, LVM, tradenark, vgdisplay, resize2fs, xfs_growfs
  • 84

Как расширить раздел файловой системы LVM в CentOS 7.x

Вследствие увеличения использования одного из сервисов мониторинга и аналитики объёмы хранимых данных начали сильно расти. Эмпирическая оценка показала, что лучше сразу увеличить объём хранилища, не дожидаясь переполнения диска и остановки сервиса. Благо этот сервер виртуальный и добавления ресурсов не составляет особого труда. Заходим на гипервизор и просто увеличиваем значение выделяемых под хранилище гигабайт:

Это действие сродни физической замены диска на вдвое больший. Особенность заключается в том, что операционная система «добавленное» место не сможет использовать самостоятельно, так как оно будет не размечено. Собственно разметкой и последующим использованием мы и займёмся. Сперва стартовые данные:

# df -h

Filesystem                       Size  Used Avail Use% Mounted on

/dev/mapper/centos-root   28G   11G   17G  40% /

devtmpfs                         911M     0  911M   0% /dev

tmpfs                            921M     0  921M   0% /dev/shm

tmpfs                            921M  8.5M  912M   1% /run

tmpfs                            921M     0  921M   0% /sys/fs/cgroup

/dev/sda1                        497M  277M  221M  56% /boot

tmpfs                            185M     0  185M   0% /run/user/0

# fdisk -l

 

Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 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: 0x000bf751

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *        2048     1026047      512000   83  Linux

/dev/sda2         1026048    62914559    30944256   8e  Linux LVM

 

Disk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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-root: 29.5 GB, 29490151424 bytes, 57597952 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

Теперь создаём на диске новый раздел

# 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): 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 (62914560-125829119, default 62914560): 62914560 # Следующий сектор

Last sector, +sectors or +size{K,M,G} (62914560-125829119, default 125829119): 125829119 # Последний сектор, оставляем по умолчанию

Partition 3 of type Linux and of size 30 GiB is set

 

Command (m for help): t # Меняем тип ФС

Partition number (1-3, default 3): 3

Hex code (type L to list all codes): 8e # Соответствует Linux LVM

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

 

Command (m for help): p

 

Disk /dev/sda: 64.4 GB, 64424509440 bytes, 125829120 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: 0x000bf751

 

Device Boot Start End Blocks Id System

/dev/sda1 * 2048 1026047 512000 83 Linux

/dev/sda2 1026048 62914559 30944256 8e Linux LVM

/dev/sda3 62914560 125829119 31457280 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.

После этого необходимо перегрузить машинку

# reboot

После перезагрузки создаём физический раздел:

# pvcreate /dev/sda3

Physical volume "/dev/sda3" successfully created

Смотрим название группы томов, в который добавляется новый раздел

# vgdisplay

--- Volume group ---

VG Name centos

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 29.51 GiB

PE Size 4.00 MiB

Total PE 7554

Alloc PE / Size 7543 / 29.46 GiB

Free PE / Size 11 / 44.00 MiB

VG UUID B7FEqI-aDzN-G0xX-xUgH-oTpd-TRWc-O9sKMi

Добавляем раздел:

# vgextend centos /dev/sda3

Volume group "centos" successfully extended

название логического тома, который нужно расширить:

# lvdisplay

--- Logical volume ---

LV Path /dev/centos/root

LV Name root

VG Name centos

LV UUID cmFknm-2nVO-kREo-tQUr-Y7X5-VBPc-AfWkYR

LV Write Access read/write

LV Creation host, time localhost, 2015-05-26 02:03:59 +0300

LV Status available

# open 1

LV Size 27.46 GiB

Current LE 7031

Segments 1

Allocation inherit

Read ahead sectors auto

- currently set to 8192

Block device 253:1

Расширяем раздел

# lvextend -l +100%FREE /dev/centos/root

Size of logical volume centos/root changed from 27.46 GiB (7031 extents) to 57.50 GiB (14721 extents).

Logical volume root successfully resized.

И последний шаг для CentOS 7

# xfs_growfs /dev/mapper/centos-root

meta-data=/dev/mapper/centos-root isize=256 agcount=4, agsize=1799936 blks

= sectsz=512 attr=2, projid32bit=1

= crc=0 finobt=0

data = bsize=4096 blocks=7199744, imaxpct=25

= sunit=0 swidth=0 blks

naming =version 2 bsize=4096 ascii-ci=0 ftype=0

log =internal bsize=4096 blocks=3515, version=2

= sectsz=512 sunit=0 blks, lazy-count=1

realtime =none extsz=4096 blocks=0, rtextents=0

data blocks changed from 7199744 to 15074304

Проверяем что получилось:

# df -h

Filesystem                       Size  Used Avail Use% Mounted on

/dev/mapper/centos-root   58G   11G   47G  19% /

devtmpfs                         911M     0  911M   0% /dev

tmpfs                            921M     0  921M   0% /dev/shm

tmpfs                            921M  8.5M  912M   1% /run

tmpfs                            921M     0  921M   0% /sys/fs/cgroup

/dev/sda1                        497M  277M  221M  56% /boot

tmpfs                            185M     0  185M   0% /run/user/0

Как видим размер корневой файловой системы увеличился. Прелесть в том, что это расширение производится в online режиме без каких либо live-систем и прочего. Обошлись лишь перезагрузкой.

 


Was this answer helpful?

« Back