LVM: уменьшить и увеличить размер Logical Volume

Автор: | 07/20/2016
 

lvm_logoИмеется диск:

# fdisk -l /dev/sda

Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 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 identifier: 0x0004efec

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1050623      524288   83  Linux
/dev/sda2         1050624     3147775     1048576   82  Linux swap / Solaris
/dev/sda3         3147776    41943039    19397632   83  Linux

Тут /dev/sda3 – раздел под Phisical Volume LVM :

# pvdisplay -Cv
    Scanning for physical volume names
  PV         VG        Fmt  Attr PSize  PFree DevSize PV UUID                               
  /dev/sda3  vg_ubuntu lvm2 a--  18.50g    0   18.50g OsG5Dk-VNnN-h1ts-QwwK-KplG-uaDk-2JQoUB

В котором расположены два Logical Volumes:

# lvdisplay -Cv
    Finding all logical volumes
  LV   VG        #Seg Attr      LSize  Maj Min KMaj KMin Pool Origin Data%  Meta%  Move Copy%  Log Convert LV UUID                               
  home vg_ubuntu    1 -wi-a---- 15.50g  -1  -1 252  1    RJcLPm-4TZQ-ujGZ-1OFB-UVno-CERv-u6ebd1
  root vg_ubuntu    1 -wi-a----  3.00g  -1  -1 252  0    xE2oc1-jvWV-wDxW-Um3a-YFqT-n1oy-rOgHNl

Задача – увеличить root, и уменьшить home.

Т.к. система загружена с LiveCD – то отмонтировать разделы нет необходимости.

Уменьшаем home:

# lvresize --resizefs --size -5G /dev/vg_ubuntu/home 
fsck from util-linux 2.20.1
/dev/mapper/vg_ubuntu-home: 12/1015808 files (0.0% non-contiguous), 106440/4062208 blocks
resize2fs 1.42.9 (4-Feb-2014)
Resizing the filesystem on /dev/mapper/vg_ubuntu-home to 2751488 (4k) blocks.
The filesystem on /dev/mapper/vg_ubuntu-home is now 2751488 blocks long.

  Reducing logical volume home to 10.50 GiB
  Logical volume home successfully resized

Увеличиваем root:

# lvresize --resizefs --size +5G /dev/vg_ubuntu/root 
fsck from util-linux 2.20.1
/dev/mapper/vg_ubuntu-root: 153386/196608 files (0.1% non-contiguous), 782336/786432 blocks
  Extending logical volume root to 8.00 GiB
  Logical volume root successfully resized
resize2fs 1.42.9 (4-Feb-2014)
Resizing the filesystem on /dev/mapper/vg_ubuntu-root to 2097152 (4k) blocks.
The filesystem on /dev/mapper/vg_ubuntu-root is now 2097152 blocks long.

Проверяем:

# lvdisplay -Cv
    Finding all logical volumes
  LV   VG        #Seg Attr      LSize  Maj Min KMaj KMin Pool Origin Data%  Meta%  Move Copy%  Log Convert LV UUID                               
  home vg_ubuntu    1 -wi-a---- 10.50g  -1  -1 252  1    RJcLPm-4TZQ-ujGZ-1OFB-UVno-CERv-u6ebd1
  root vg_ubuntu    2 -wi-a----  8.00g  -1  -1 252  0    xE2oc1-jvWV-wDxW-Um3a-YFqT-n1oy-rOgHNl

Готово.