UNIX/유닉스 공통

LVM 상세내용 - 구성시 사용하는 명령어들에 대한 옵션 내용 포함

99iberty 2012. 7. 19. 16:57

 

http://rain.boanlab.com/index.php?mid=textyle&category=24274&document_srl=25171

 

 

5.2.3 리눅스 LVM 구성

1. VMware GuestOS에 HDD 3개를 각각 100MB, 200MB, 300MB를 추가 하도록 한다.

이 구성에서의 LVM의 총 Size는 100+200+300 = 600MB의 논리적 단일 HDD 구성이다.

2. 시스템 부팅 후 리눅스 LVM 구성

  • 관련 명령어

LVM 명령어

사 용 법

pvcreate

물리적 볼륨(PV:Physical Volume)을 생성하는 명령어이다.

fdisk를 이용하여 파티션을 분할하고 LVM 속성으로 지정한 뒤에 해당 파티션을 PV로 만들 때 사용하는 명령이다.

문법 : pvcreate 디바이스명

ex) # pvcreate /dev/hdb1

vgscan

디스크에 있는 볼륨그룹(VG:Volume Group)를 검색하여 /etc/lvmtab 파일을 생성한다.

fdisk를 이용하여 파티션을 속성을 LVM으로 지정한 후에 이 명령을 사용한다.

문법 : # vgscan

vgcreate

볼륨그룹을 생성하는 명령어로 생성된 PV를 지정한 볼륨그룹에 포함시키면서 생성한다.

문법 : vgcreate 볼륨그룹명 디바이스명 디바이스명

ex) # vgcreate lvm /dev/hda7 /dev/hdb1 è lvm 이라는 볼륨그룹을 생성하고 /dev/hda7, /dev/hdb1 이라는 PV를 포함시킨다.

vgdisplay

볼륨그룹의 속성과 정보를 보여주는 명령어이다.

문법 : vgdisplay [option] [볼륨그룹명]

옵션

-v: 좀 더 자세히 보여주는 옵션으로 Volume Group이외에 gical Volume과 Physical Volume도 같이 보여준다.

ex) # vgdisplay è Volume Group의 내용을 보여준다.
# vgdisplay -v lvm
è lvm이라는 볼륨그룹의 내용을 자세히 보여준다.

vgextend

미리 생성된 Volume Group에 추가로 Phycical Volume을 추가할 때 사용한다.

문법 : vgextend 볼륨그룹명 새PV명

ex) # vgextend lvm /dev/hdc1 è lvm이라는 볼륨그룹에 /dev/hdc1을 추가한다.

vgreduce

볼륨그룹에 있는 Physical Volume을 삭제하는 명령이다.

문법 : vgreduce 볼륨그룹명 PV명

ex) # vgreduce lvm /dev/hdc1 è lvm이라는 볼륨그룹에서 /dev/hdc1을 삭제한다.

vgchange

볼륨그룹을 속성을 변경하는 명령으로 볼륨그룹을 사용가능여부, 최대 LV 갯수등을 변경 할 수 있다.

문법 : vgchange 옵션 볼륨그룹명

옵션

-a y (or) n : 볼륨그룹의 사용여부를 지정
-l 갯수 : 해당 볼륨그룹에 생성할 수 있는 최대 Logical Volume수 지정

ex) # vgchange -a y lvm è lvm이라는 볼륨그룹을 활성화시킨다.
# vgchange -a n lvm
è lvm이라는 볼륨그룹을 비활성화시킨다.
# vgchange -l 100 lvm
è lvm이라는 볼륨그룹을 최대 Logical Volume수를 100개로 지정한다.

vgremove

볼륨그룹을 제거하는 명령

문법 : vgremove 볼륨그룹명

ex) # vgremove lvm è lvm이라는 볼륨그룹을 삭제한다

lvcreate

볼륨그룹안에 LV(Logical Volume)을 생성하는 명령이다.

문법 : lvcreate 옵션 볼륨그룹명

옵션

-L: LV의 사이즈를 지정하는 옵션으로 K(kilobytes), M(megabytes), G(gigabytes), T(terabytes) 단위를 붙여 지정가능하다.
-l: LV의 사이즈를 지정하는 옵션으로 pe의 개수로 용량을 지정한다. 참고로 보통 1pe당 4MB이다.
-n: LV의 이름을 지정하는 옵션이다.

ex) 1. # lvcreate -L 2000M -n backup lvm è lvm이라는 볼륨그룹에 backup라는 이름으로 2Gigabytes 용량으로 LV을 생성한다.

2. # lvcreate -l 250 -n data lvm è lvm이라는 볼륨그룹에 data라는 이름으로 250pe(약 1GB)용량으로 LV을 생성한다.

lvscan

디스크에 있는 Logical Volume을 찾아준다.

문법 : lvscan [옵션]

옵션 : -v 정보를 자세히 보여준다.

ex) # lvscan

lvdisplay

Logical Volume의 정보를 보여준다.

문법 : lvdisplay [옵션] LV명

옵션 : -v: 정보를 자세히 보여준다.

ex) # lvdisplay -v /dev/lvm/data è /dev/lvm/data라는 LV의 정보를 자세히 보여준다.

lvextend

Logical Volume의 용량을 확장하는 명령이다.

문법 : lvextend 옵션 [볼륨그룹명] LV명

옵션

-l +사이즈 : 지정한 PE수만큼 용량을 늘린다.

-L +사이즈[kmgt]: 지정한 사이즈만큼 용량을 늘린다. 단위를 표시하지 않으면 기본 Megabytes단위이다.

ex) # lvextend -L +200M /dev/lvm/data è 기존의 용량에 추가로 200MB를 할당한다.

lvreduce

Logical Volume의 용량을 줄이는 명령

문법 : lvreduce 옵션 [볼륨그룹병] LV명

옵션

-l -사이즈 : 지정한 PE수만큼 용량을 줄인다.

-L -사이즈 : 지정한 사이즈만큼 용량을 줄인다. 단위를 표시하지 않으면 기본 단위는 Megabytes 이다.

ex) # lvreduce -L -500 /dev/lvm/data è /dev/lvm/data의 용량을 500MB 줄인다.

  • LVM 구성하기

1. LVM 생성

추가된 HDD 정보 확인

[root@naruto etc]# fdisk -l

Disk /dev/sda: 17.2 GB, 17179869184 bytes

255 heads, 63 sectors/track, 2088 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Disk identifier: 0x0000c8a6

Device Boot Start End Blocks Id System

/dev/sda1 * 1 26 206580+ 83 Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2 26 2088 16565248 8e Linux LVM

Disk /dev/sdb: 106 MB, 106954752 bytes

64 heads, 32 sectors/track, 102 cylinders

Units = cylinders of 2048 * 512 = 1048576 bytes

Disk identifier: 0x00000000

Disk /dev/sdb doesn't contain a valid partition table

Disk /dev/sdc: 213 MB, 213909504 bytes

64 heads, 32 sectors/track, 204 cylinders

Units = cylinders of 2048 * 512 = 1048576 bytes

Disk identifier: 0x00000000

Disk /dev/sdc doesn't contain a valid partition table

Disk /dev/sdd: 321 MB, 321912832 bytes

64 heads, 32 sectors/track, 307 cylinders

Units = cylinders of 2048 * 512 = 1048576 bytes

Disk identifier: 0x00000000

Disk /dev/sdd doesn't contain a valid partition table

Fdisk를 사용하여 추가된 HDD를 LVM 타입의 파티션으로 만들기

[root@naruto etc]# fdisk /dev/sdb

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel with disk identifier 0x97fbaf9e.

Changes will remain in memory only, until you decide to write them.

After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): n

Command action

e extended

p primary partition (1-4)

p

Partition number (1-4): 1

First cylinder (1-102, default 1): 1

Last cylinder, +cylinders or +size{K,M,G} (1-102, default 102): 102

Command (m for help): t

Selected partition 1

Hex code (type L to list codes): 8e

Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/sdb: 106 MB, 106954752 bytes

64 heads, 32 sectors/track, 102 cylinders

Units = cylinders of 2048 * 512 = 1048576 bytes

Disk identifier: 0x97fbaf9e

Device Boot Start End Blocks Id System

/dev/sdb1 1 102 104432 8e Linux LVM

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

[root@naruto etc]# fdisk /dev/sdc

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel with disk identifier 0xe41b0956.

Changes will remain in memory only, until you decide to write them.

After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): n

Command action

e extended

p primary partition (1-4)

p

Partition number (1-4): 1

First cylinder (1-204, default 1): 1

Last cylinder, +cylinders or +size{K,M,G} (1-204, default 204): 204

Command (m for help): t

Selected partition 1

Hex code (type L to list codes): 8e

Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/sdc: 213 MB, 213909504 bytes

64 heads, 32 sectors/track, 204 cylinders

Units = cylinders of 2048 * 512 = 1048576 bytes

Disk identifier: 0xe41b0956

Device Boot Start End Blocks Id System

/dev/sdc1 1 204 208880 8e Linux LVM

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

[root@naruto etc]# fdisk /dev/sdd

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel with disk identifier 0x1882e12e.

Changes will remain in memory only, until you decide to write them.

After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): n

Command action

e extended

p primary partition (1-4)

p

Partition number (1-4): 1

First cylinder (1-307, default 1): 1

Last cylinder, +cylinders or +size{K,M,G} (1-307, default 307): 307

Command (m for help): t

Selected partition 1

Hex code (type L to list codes): 8e

Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/sdd: 321 MB, 321912832 bytes

64 heads, 32 sectors/track, 307 cylinders

Units = cylinders of 2048 * 512 = 1048576 bytes

Disk identifier: 0x1882e12e

Device Boot Start End Blocks Id System

/dev/sdd1 1 307 314352 8e Linux LVM

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

물리볼륨(PV)을 만든다.

[root@naruto etc]# pvcreate /dev/sdb1

Physical volume "/dev/sdb1" successfully created

[root@naruto etc]# pvcreate /dev/sdc1

Physical volume "/dev/sdc1" successfully created

[root@naruto etc]# pvcreate /dev/sdd1

Physical volume "/dev/sdd1" successfully created

볼륨그룹(VG)을 만든다

[root@naruto etc]# vgcreate VG-test /dev/sdb1 /dev/sdc1 /dev/sdd1

Volume group "VG-test" successfully created

볼륨그룹(VG)상태 확인

[root@naruto etc]# vgdisplay VG-test

--- Volume group ---

VG Name VG-test

System ID

Format lvm2

Metadata Areas 3

Metadata Sequence No 1

VG Access read/write

VG Status resizable

MAX LV 0

Cur LV 0

Open LV 0

Max PV 0

Cur PV 3

Act PV 3

VG Size 604.00 MB

PE Size 4.00 MB

Total PE 151

Alloc PE / Size 0 / 0

Free PE / Size 151 / 604.00 MB

VG UUID rxWdQF-Krtg-a3fR-a5o7-xHJf-4308-Z46Bax

논리볼륨(LV)을 만든다.

[root@naruto etc]# lvcreate -L 604MB -n LV-test VG-test

Logical volume "LV-test" created

논리볼륨(LV) 포맷 (ext4는 페도라11부터 지원하는 파일 시스템이므로 여러분들은 자신의 시스템에 맞는 파일 시스템으로 선택하여야 한다)

[root@naruto etc]# mkfs.ext4 /dev/VG-test/LV-test

mke2fs 1.41.9 (22-Aug-2009)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

38720 inodes, 154624 blocks

7731 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=159383552

5 block groups

32768 blocks per group, 32768 fragments per group

7744 inodes per group

Superblock backups stored on blocks:

32768, 98304

Writing inode tables: done

Creating journal (4096 blocks): done

Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 35 mounts or

180 days, whichever comes first. Use tune2fs -c or -i to override.

2. 생성된 LVM 시스템에 Mount

시스템 Mount정보 확인

[root@naruto ~]# mount

/dev/mapper/vg_naruto-naruto00 on / type ext4 (rw)

proc on /proc type proc (rw)

sysfs on /sys type sysfs (rw)

devpts on /dev/pts type devpts (rw,gid=5,mode=620)

tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")

/dev/sda1 on /boot type ext4 (rw)

none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)

LVM을 Mount할 디렉터리 생성

[root@naruto ~]# mkdir /LVMdata

LVM을 /LVMdata 디렉터리에 Mount

[root@naruto ~]# mount -t ext4 /dev/VG-test/LV-test /LVMdata/

시스템 Mount 정보 확인

[root@naruto ~]# mount

/dev/mapper/vg_naruto-naruto00 on / type ext4 (rw)

proc on /proc type proc (rw)

sysfs on /sys type sysfs (rw)

devpts on /dev/pts type devpts (rw,gid=5,mode=620)

tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")

/dev/sda1 on /boot type ext4 (rw)

none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)

/dev/mapper/VG--test-LV--test on /LVMdata type ext4 (rw)

[root@naruto ~]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/vg_naruto-naruto00

15G 9.9G 4.0G 72% /

tmpfs 376M 88K 376M 1% /dev/shm

/dev/sda1 196M 36M 151M 19% /boot

/dev/mapper/VG--test-LV--test

595M 17M 548M 3% /LVMdata

3. 시스템에 자동으로 LVM Mount 설정

/etc/fstab 에 설정 등록

[root@naruto ~]# vi /etc/fstab

#

# /etc/fstab

# Created by anaconda on Mon Nov 23 20:54:59 2009

#

# Accessible filesystems, by reference, are maintained under '/dev/disk'

# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info

#

/dev/mapper/vg_naruto-naruto00 / ext4 defaults 1 1

UUID=03d18320-e28c-41eb-a72e-a85c6c3eae92 /boot ext4 defaults 1 2

/dev/mapper/vg_naruto-naruto01 swap swap defaults 0 0

tmpfs /dev/shm tmpfs defaults 0 0

devpts /dev/pts devpts gid=5,mode=620 0 0

sysfs /sys sysfs defaults 0 0

proc /proc proc defaults 0 0

/dev/VG-test/LV-test /LVMdata ext4 defaults 1 1

저장하고 리부팅을 해주도록 한다. 만약 시스템이 제대로 부팅 되지 않는다면 100% 오타이다.

응급 복구로 부팅 하여서 기존의 수정된 /etc/fstab를 복구해주면 해결 된다.

자동 Mount의 확인

[root@naruto ~]# mount

/dev/mapper/vg_naruto-naruto00 on / type ext4 (rw)

proc on /proc type proc (rw)

sysfs on /sys type sysfs (rw)

devpts on /dev/pts type devpts (rw,gid=5,mode=620)

tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")

/dev/sda1 on /boot type ext4 (rw)

/dev/mapper/VG--test-LV--test on /LVMdata type ext4 (rw)

none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)

[root@naruto ~]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/vg_naruto-naruto00

15G 9.9G 4.0G 72% /

tmpfs 376M 88K 376M 1% /dev/shm

/dev/sda1 196M 36M 151M 19% /boot

/dev/mapper/VG--test-LV--test

595M 17M 548M 3% /LVMdata

'UNIX > 유닉스 공통' 카테고리의 다른 글

/etc/fstab 내용  (0) 2012.07.20
하드디스크 장치명  (0) 2012.07.19
LVM 상세내용 - 구성요소 및 개념도  (0) 2012.07.19
리눅스 LVM 생성  (0) 2012.07.19
EXT 파일 시스템(ext1, ext2, ext3, ext4)  (0) 2012.07.19