Linux #15 : LVM에서 Logical Volume의 Resizing

지난 시간에 LVM에서의 Logical Volume 생성에 대해서 배웠는데 LVM에서 생성된 File System은 VG의 Size 한도 안에서 확장이 가능하고, File System에 따라서 별도의 Format 작업이 없이 확장 가능하기도 하다. 필자는 IBM AIX를 다룰 때 JFS2를 사용 했었는데, 이 Volume이 Onlice상에서 확장 가능한 Volume이었고, Oracle에서 Raw Device를 사용할 경우 해당 Raw Device에 대해 LVM으로 구성하여 복잡한 작업없이 Logical Volume을 확장 했던 적이 있었다.

Logical Volume의 확장은 정상적으로 동작 했을 경우에는 문제가 되지 않지만, 문제가 발생했을 경우에는 모든 Data를 손실할 경우도 있으므로 작업 전에 반드시 Data를 Backup 할 것을 권유하고 싶다.

LVM의 Logical Volume을 확장하기 위해서 “lvextend”라는 command가 사용된다.
지난 시간에 작성한 Logical Volume인 “/dev/vg001/MyTechies”를 참조 해 보자.

$ lvdisplay /dev/vg001/MyTechies
--- Logical volume ---
LV Name /dev/vg001/MyTechies
VG Name vg001
LV UUID j7037M-1uii-KO6a-ov6t-ub6C-Pm42-DPeGEj
LV Write Access read/write
LV Status available
# open 0
LV Size 40.00 GB
Current LE 1280
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0

아래와 같이 확장시킬 File System(/dev/vg001/MyTechies)은 Online 상태에 있으며, /home/lvm2test에 mount 되어 있다.


$ mount
/dev/sda2 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda6 on /home type ext3 (rw,nodev)
/dev/sda1 on /boot type ext3 (rw,noexec,nosuid,nodev)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/mapper/vg001-MyTechies on /home/lvm2test type ext3 (rw)

$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 31G 3.4G 26G 12% /
/dev/sda6 43G 889M 40G 3% /home
/dev/sda1 99M 17M 77M 18% /boot
tmpfs 1006M 0 1006M 0% /dev/shm
/dev/mapper/vg001-MyTechies
40G 177M 38G 1% /home/lvm2test

lvextend를 통해서 10G를 확장 시켜 보면


$ lvextend -L +10G /dev/vg001/MyTechies
Extending logical volume MyTechies to 50.00 GB
Logical volume MyTechies successfully resized

정상적으로 확장이 되었다는 Message를 확인 할 수 있고, “lvdisplay”로 확인을 하면,


$ lvdisplay /dev/vg001/MyTechies
--- Logical volume ---
LV Name /dev/vg001/MyTechies
VG Name vg001
LV UUID j7037M-1uii-KO6a-ov6t-ub6C-Pm42-DPeGEj
LV Write Access read/write
LV Status available
# open 1
LV Size 50.00 GB
Current LE 1600
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0

LV Size가 40.00 GB에서 50.00 GB로 확장 된 것을 확인 할 수 있다. 그리고, “resize2fs”를 통해서 File System을 확장 해 주면 된다.
여기서 File System을 축소 할 경우에는 해당 File System의 Unmount가 반드시 필요하지만, 확장시에는 Online상태에서 Resize가 가능하다.

$ resize2fs /dev/vg001/MyTechies
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/vg001/MyTechies is mounted on /home/lvm2test; on-line resizing required
Performing an on-line resize of /dev/vg001/MyTechies to 13107200 (4k) blocks.
The filesystem on /dev/vg001/MyTechies is now 13107200 blocks long.

$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 31G 3.4G 26G 12% /
/dev/sda6 43G 889M 40G 3% /home
/dev/sda1 99M 17M 77M 18% /boot
tmpfs 1006M 0 1006M 0% /dev/shm
/dev/mapper/vg001-MyTechies
50G 180M 47G 1% /home/lvm2test

또한 정상적으로 확장 된 것을 확인 할 수 있다.
그럼, 이제 축소를 시켜보자. File System의 축소는 위에서 이야기 했던 것 처럼 먼저 Umount가 선행 되어야 한다.

$ umount /home/lvm2test/

또한, 축소를 할 경우에는 File System의 Size를 변경 시킨 후 행할 필요가 있다. 이는 Defragment와 동일한 개념으로 생각하면 된다.
먼저 “e2fsck”를 이용하여 File System의 정합성을 체크하고, “resize2fs”로 Size를 축소하면 된다.

$ e2fsck -f /dev/vg001/MyTechies
e2fsck 1.39 (29-May-2006)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vg001/MyTechies: 12/6553600 files (8.3% non-contiguous), 251734/13107200 blocks

$ resize2fs /dev/vg001/MyTechies 40G => Size를 40G로 축소
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/vg001/MyTechies to 10485760 (4k) blocks.
The filesystem on /dev/vg001/MyTechies is now 10485760 blocks long.

그런 다음 resize2fs를 통해 축소된 Size와 동일하게 Logical Volume Size도 축소를 시켜주면 된다.
이때 “lvreduce” command가 사용된다.

$ lvreduce -L 40G /dev/vg001/MyTechies
WARNING: Reducing active logical volume to 40.00 GB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce MyTechies? [y/n]: y => Y를 입력
Reducing logical volume MyTechies to 40.00 GB
Logical volume MyTechies successfully resized

$ lvdisplay /dev/vg001/MyTechies
--- Logical volume ---
LV Name /dev/vg001/MyTechies
VG Name vg001
LV UUID 4i5MxQ-qxNA-JzR1-HC3V-I041-hwvz-Q31rva
LV Write Access read/write
LV Status available
# open 0
LV Size 40.00 GB
Current LE 1280
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0

축소 작업에서는 확장할 때 보다 문제가 발생할 가능성이 많으므로, 중요한 Data는 반드시 Backup 먼저 한 후 작업을 하길 바랍니다.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.