Форум компании Ритм - НПО «Ритм»

Расширение дискового раздела в Linux без перезагрузки

Поиск  Пользователи  Правила  Войти  
Страницы: 1
RSS
Расширение дискового раздела в Linux без перезагрузки, LVM resize
Исходные данные: создана и работает виртуальная машина под управлением Linux (RHEL, CentOS, Oracle Linux etc.), для которой нужно расширить доступное дисковое пространство для системного или дополнительного уже существующего раздела.

В примере мы будем расширять системный раздел до 300 Gb.

Код

[root@localhost ~]# df -h
Filesystem           Size  Used Avail Use% Mounted on
devtmpfs             982M     0  982M   0% /dev
tmpfs               1000M     0 1000M   0% /dev/shm
tmpfs               1000M  8.5M  992M   1% /run
tmpfs               1000M     0 1000M   0% /sys/fs/cgroup
/dev/mapper/ol-root  138G  2.8G  135G   2% /
/dev/sda1            497M  240M  258M  49% /boot
tmpfs                200M     0  200M   0% /run/user/1000

[root@localhost ~]# fdisk -l
Disk /dev/sda: 150.3 GB, 150323855360 bytes, 293601280 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: 0x000ad626

Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048    83886079    41430016   8e  Linux LVM
/dev/sda3        83886080   293601279   104857600   8e  Linux LVM

Disk /dev/mapper/ol-root: 147.6 GB, 147643695104 bytes, 288366592 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
...

Приступим.
Понятно, что в первую очередь необходимо увеличить размер дискового тома в свойствах виртуальной машины.

Затем, обновим состояние дисков в ОС. Для этого сначала смотрим, какие устройства у нас есть:
Код

[root@localhost ~]# ls /sys/class/scsi_disk/
2:0:0:0
[root@localhost ~]#


И теперь посылаем команду обновить параметры устройства:
Код

[root@localhost ~]# echo '1' > /sys/class/scsi_disk/2\:0\:0\:0/device/rescan
[root@localhost ~]#


В результате должны увидеть, что изменился размер физического диска в ВМ:

Код

[root@localhost ~]# fdisk -l
Disk /dev/sda: 322.1 GB, 322122547200 bytes, 629145600 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: 0x000ad626

Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048    83886079    41430016   8e  Linux LVM
/dev/sda3        83886080   293601279   104857600   8e  Linux LVM

Disk /dev/mapper/ol-root: 147.6 GB, 147643695104 bytes, 288366592 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/ol-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


Теперь нужно создать новый физический раздел, используя доступное место. Сделаем это:
Код

[root@localhost ~]# 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 (3 primary, 0 extended, 1 free)
e   extended
Select (default e): p
Selected partition 4
First sector (293601280-629145599, default 293601280):
Using default value 293601280
Last sector, +sectors or +size{K,M,G} (293601280-629145599, default 629145599):
Using default value 629145599
Partition 4 of type Linux and of size 160 GiB is set

Command (m for help): t
Partition number (1-4, default 4):
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)


В результате получим новый физический раздел:
Код

[root@localhost ~]# fdisk -l

Disk /dev/sda: 322.1 GB, 322122547200 bytes, 629145600 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: 0x000ad626

Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048    83886079    41430016   8e  Linux LVM
/dev/sda3        83886080   293601279   104857600   8e  Linux LVM
/dev/sda4       293601280   629145599   167772160   8e  Linux LVM

Disk /dev/mapper/ol-root: 147.6 GB, 147643695104 bytes, 288366592 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/ol-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


Однако, чтобы его использовать без перезагрузки, необходимо сообщить ядру о сделанных изменениях, для этого выполним команду:
Код

[root@localhost ~]# partprobe
[root@localhost ~]#


Осталось расширить наш LVM-том добавленным разделом:

Код

[root@localhost ~]# pvcreate /dev/sda4
Physical volume "/dev/sda4" successfully created.
[root@localhost ~]#
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name               ol
System ID
Format                lvm2
(...)
[root@localhost ~]#
[root@localhost ~]# vgextend ol /dev/sda4
Volume group "ol" successfully extended
[root@localhost ~]#
[root@localhost ~]# lvdisplay
--- Logical volume ---
LV Path                /dev/ol/root
LV Name                root
VG Name                ol
(...)
--- Logical volume ---
LV Path                /dev/ol/swap
LV Name                swap
VG Name                ol
(...)
[root@localhost ~]#
[root@localhost ~]# lvextend -l +100%FREE /dev/ol/root
Size of logical volume ol/root changed from 137.50 GiB (35201 extents) to 297.50 GiB (76160 extents).
Logical volume ol/root successfully resized.
[root@localhost ~]#
[root@localhost ~]# xfs_growfs /dev/ol/root
meta-data=/dev/mapper/ol-root    isize=256    agcount=15, agsize=2455296 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=36045824, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal               bsize=4096   blocks=4795, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 36045824 to 77987840
[root@localhost ~]#

В итоге, получаем:
Код

[root@localhost ~]# fdisk -l
Disk /dev/sda: 322.1 GB, 322122547200 bytes, 629145600 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: 0x000ad626

Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048    83886079    41430016   8e  Linux LVM
/dev/sda3        83886080   293601279   104857600   8e  Linux LVM
/dev/sda4       293601280   629145599   167772160   8e  Linux LVM

Disk /dev/mapper/ol-root: 319.4 GB, 319438192640 bytes, 623902720 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/ol-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

[root@localhost ~]# df -h
Filesystem           Size  Used Avail Use% Mounted on
devtmpfs             982M     0  982M   0% /dev
tmpfs               1000M     0 1000M   0% /dev/shm
tmpfs               1000M  8.5M  992M   1% /run
tmpfs               1000M     0 1000M   0% /sys/fs/cgroup
/dev/mapper/ol-root  298G  2.8G  295G   1% /
/dev/sda1            497M  240M  258M  49% /boot
tmpfs                200M     0  200M   0% /run/user/1000
[root@localhost ~]#

Готово!

Другой пример - с перезагрузками, на примере увеличения раздела /db
Страницы: 1