서버/Linux II 2016. 2. 19. 12:21

Linux II - 06. LVM (Logical Volume Manager)

 

 

 

 - VMware 스냅샷 실시 - 'LVM 구성 이전'

 

login as: root
root@192.168.1.7's password:
Last login: Fri Feb 19 10:08:41 2016 from 192.168.1.1
[root@CentOS2 /root]#

 

 

 

 

1. LVM(Logincal Volume Manger) - 볼륨 : 가상 디스크/가상 파티션

 

LVM은 다수의 디스크를 논리적으로 구성하여 하나의 디스크로 동작하는 기능이다. 즉, 1G 디스크 4개를 LVM 기능을 이용하여 4G 디스크처럼 사용할 수 있다. 또한, LVM 기능을 이용하면, 파일 시스템을 추가할 필요 없이 동적으로 용량을 확장 및 축소할 수 있다.

 

 

 

 PV(Physical Volume)

 물리적인 디스크를 의미하며, LVM을 사용할 수 있도록 LVM 데이터 구조를 생성한다.

 VG(Volume Group)

 LV를 생성할 수 있는 Volume Group을 의미하며, 하나 또는 그 이상의 PV를 포함한다.

 LV(Logical Volume)

 LVM으로 구성되지 않는 시스템에서의 디스크 파티션, 가상 파티션을 의미한다.

 PE(Physical Extent)

 PV에 나누어져 있는 데이터 블럭을 의미한다.

 LE(Logical Extent)

 LV에 나누어져 있는 데이터 블럭을 의미한다.

 

 

 

 

2. LVM 구성 요소

 

PV(Physical Volume)

  - PV는 하나의 물리적인 디스크에 LVM을 사용할 수 있도록 LVM 데이터 구조를 생성한 것이다.

  - 디스크에 PV가 생성되면, LVM은 디스크를 하나의 물리적인 볼륨으로 처리하고, 볼륨그룹에 포함시킨다.

  - 하나의 디스크를 몇 개의 섹션 논리볼륨으로 구성하고, 몇 개의 섹션은 전체디스크로 관리할 수 있다.

  - 예) 물리적인 디스크(/dev/sda), 물리적인 파티션(/dev/sda1)

 

 

VG(Volume Group)

  - VG는 하나 또는 그 이상의 PV를 포함하며, LV를 생성할 수 있는 볼륨그룹의 집합이다.

  - VG00은 부팅 정보와 OS가 있는 루트 볼륨그룹이므로 변경이 불가능하다.

  - 관리의 편의성를 위해서 DB는 VGDB##, 일반적인 파일 시스템은 VGFIL##으로 VG 이름을 지정하여 사용한다.

  - 예) 가상 디스크

 

 

LV(Logical Volume)

  - LV는 하나 또는 그 이상의 PV로 구성되어 있는 VG 공간을 전체 또는 분할하여 일반 파일 시스템, Swap, Dump,

     Raw 디스크로 사용할 수 있도록 할당된 논리적인 공간이다.

  - 운영 중 공간이 부족할 경우, 볼륨그룹에 속해 있는 또 다른 물리볼륨을 사용하여 확장이 가능하고, 필요하다면

     크기를 변경하거나 다른 디스크로 데이터를 이동시킬 수 있다.

  - 볼륨 그룹 VG00에 속한 LV Vol1, Vol2, Vol3은 각각 /stand, primary, swap, / 디렉토리이므로 변경이 불가능하다.

  - 예) 가상 파티션

 

 

 

3. LVM 동작 방식

 

PE(Physical Extent)

  - PV가 갖는 일정한 데이터 블럭이다.

  - 디스크에 PV를 생성하면, LVM은 주소를 지정할 수 있는 PE라는 단위를 이용하여 각 물리 디스크를 나누게 된다.

  - PE 주소 0번부터 시작하여 1씩 증가하며, 순차적으로 디스크에 할당되고, PE 크기는 불륨그룹을 생성할때 구성할

    수 있다.

  - 각 PE 크기는 기본값이 4MB이며, 이 값은 볼륨그룹을 생성할때 1MB ~ 256MB 값으로 지정할 수 있다.

 

 

LE(Logical Extent)

  - LV가 갖는 일정한 데이터 블럭이다.

  - 디스크에 PV를 생성하고, 생성된 PV를 이용하여 VG를 구성한 이후, VG에 LV를 생성할 수 있다.

  - LV는 LE라는 단위를 이용하는데, PV를 생성할때 나누어진 PE 영역을 매핑하기 때문에, 만약 PE 크기가 4MB이면

    LE 크기도 4MB가 된다.

  - LV 크기는 구성된 LE 개수 또는 할당할 디스크 용량에 의해서 결정된다.

 

 

LVM & Data Access

  - LVM이 논리볼륨에 디스크 공간을 할당할 때, LVM은 0번 주소부터 시작하여 각 디스크에 순차적으로 할당된 PE와

    할당된 LE의 맵핑 테이블을 생성한다.

  - LVM은 실제 데이터가 물리볼륨에 상주하는 위치와 관계없이 논리볼륨을 엑세스하여 데이터를 엑세스한다.

 

 

LVM & Root 파티션

  - 논리 볼륨이 루트,부팅,기본 스왑,덤프에 사용될 경우에는 PE 영역은 단일 물리볼륨에 공백없이 연속적으로 구성되

     어야 한다.

  - 만약, PE가 루트가 아닌 디스크 논리볼륨의 LE이면 물리볼륨에 연속적이지 않아도되며, 전혀 다른 디스크에 상주

     해도 된다.

  - 즉, 논리볼륨에 속한 파일 시스템이 둘 이상의 디스크에 상주해도 무관한다.

 

 

Mirroring

  - 미러링되거나 스트라이프된 논리 볼륨을 제외하고 각 LE는 하나의 PE에 맵핑된다.

  - 미러링된 논리 볼륨의 경우, 단일 또는 이중 미러링을 사용하는것에 따라서 각 LE는 2개, 3개의 PE와 맵핑된다.

  - 예) 미러 사본이 하나인 경우, 각 LE가 2개의 PE에 맵핑되는데, 하나의 확장 영역은 원본에 대한 것이고, 다른 하나

     는 미러 사본에 대한 것으로 처리된다.

 

 

 

4. LVM 명령어

 

 pvcreate

  LVM 구성을 위해서 PV를 생성하고 초기화하는 명령어

 vgcreate

  PV 장치명으로 새로운 VG를 생성하는 명령어

 vgdisplay

  VG 정보를 출력하는 명령어

 lvcreate

  VG에 LV를 생성하는 명령어

 lvremove

  LV를 제거하는 명령어

 vgremove

  VG를 제거하는 명령어

 

 

 

 

5. LVM 구성 단계

 

 1) VG를 구성할 디스크를 선택한다.
 2) VG로 구성할 디스크를 각각 fdisk를 이용하여 파티션을 생성하고 파티션 타입을 lvm으로 생성한다.
 3) 'pvcreate' 명령어를 이용하여 PV를 생성한다. 
 4) 'vgcreate' 명령어를 이용하여 각각의 PV를 하나의 VG로 구성한다. 
 5) 'vgdisplay' 명령어를 이용하여 VG가 생성되었는지 확인한다.
 6) 'lvcreate' 명령어를 이용하여 VG에 LV를 생성한다.
 7) 'lvdisplay' 명령어를 이용하여 LV가 생성되었는지 확인한다.
 8) LV에 파일시스템을 생성한다.
 9) mount를 실시하여 사용한다.

 

 

 1) VG를 구성할 디스크를 선택한다.

 

 - /dev/sdc1 (200MB)

 - /dev/sdd1 (200MB)

 


 2) VG로 구성할 디스크를 각각 fdisk를 이용하여 파티션을 생성하고 파티션 타입을 lvm으로 생성한다.

 

 - /dev/sdc1 파티션 생성 및 LVM 타입 변경

 

[root@CentOS2 /root]# fdisk /dev/sdc

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

 

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): p

Disk /dev/sdc: 213 MB, 213909504 bytes
64 heads, 32 sectors/track, 204 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00024910

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1         204      208880   83  Linux

 

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): L

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris
 1  FAT12           39  Plan 9          82  Linux swap / So c1  DRDOS/sec (FAT-
 2  XENIX root      3c  PartitionMagic  83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       40  Venix 80286     84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      41  PPC PReP Boot   85  Linux extended  c7  Syrinx
 5  Extended        42  SFS             86  NTFS volume set da  Non-FS data
 6  FAT16           4d  QNX4.x          87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS       4e  QNX4.x 2nd part 88  Linux plaintext de  Dell Utility
 8  AIX             4f  QNX4.x 3rd part 8e  Linux LVM       df  BootIt
 9  AIX bootable    50  OnTrack DM      93  Amoeba          e1  DOS access
~ 중간 생략 ~


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
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00024910

   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@CentOS2 /root]#

 

 - /dev/sdd1 파티션 생성 및 LVM 타입 변경

 

[root@CentOS2 /root]# fdisk /dev/sdd

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

 

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/sdd: 213 MB, 213909504 bytes
64 heads, 32 sectors/track, 204 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00024910

   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               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@CentOS2 /root]#


[root@CentOS2 /root]# fdisk -l /dev/sdc /dev/sdd | grep -i lvm
/dev/sdc1               1         204      208880   8e  Linux LVM
/dev/sdd1               1         204      208880   8e  Linux LVM

 

 

 

 3) 'pvcreate' 명령어를 이용하여 PV를 생성한다. 

 

[root@CentOS2 /root]# pvcreate /dev/sdc1 /dev/sdd1
  Physical volume "/dev/sdc1" successfully created
  Physical volume "/dev/sdd1" successfully created

 

[root@CentOS2 /root]# pvdisplay
  "/dev/sdc1" is a new physical volume of "203.98 MiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdc1
  VG Name
  PV Size               203.98 MiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               ME01Z1-pAp0-rrrw-hjJY-n9G6-tK4K-bvpomg

  "/dev/sdd1" is a new physical volume of "203.98 MiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdd1
  VG Name
  PV Size               203.98 MiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               q3vnW3-ejgx-SOU4-TZgQ-y3ZA-CtIj-U8JCke

 

 

 

 4) 'vgcreate' 명령어를 이용하여 각각의 PV를 하나의 VG로 구성한다.


[root@CentOS2 /root]# vgcreate /dev/sdc1 /dev/sdd1
  /dev/sdc1: already exists in filesystem
  Run `vgcreate --help' for more information.

[root@CentOS2 /root]# vgcreate test_vg /dev/sdc1 /dev/sdd1
  Volume group "test_vg" successfully created

 

 

 5) 'vgdisplay'명령어를 이용하여 VG가 생성되었는지 확인한다.


[root@CentOS2 /root]# vgdisplay -v
    DEGRADED MODE. Incomplete RAID LVs will be processed.
    Finding all volume groups
    Finding volume group "test_vg"
  --- Volume group ---
  VG Name               test_vg
  System ID
  Format                lvm2
  Metadata Areas        2
  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                2
  Act PV                2
  VG Size               400.00 MiB
  PE Size               4.00 MiB
  Total PE              100
  Alloc PE / Size       0 / 0
  Free  PE / Size       100 / 400.00 MiB
  VG UUID               A2BAVz-P0Ah-TBFn-eEJq-EgU3-ozhg-JGVfWs

  --- Physical volumes ---
  PV Name               /dev/sdc1
  PV UUID               ME01Z1-pAp0-rrrw-hjJY-n9G6-tK4K-bvpomg
  PV Status             allocatable
  Total PE / Free PE    50 / 50

  PV Name               /dev/sdd1
  PV UUID               q3vnW3-ejgx-SOU4-TZgQ-y3ZA-CtIj-U8JCke
  PV Status             allocatable
  Total PE / Free PE    50 / 50


 

 

 6) 'lvcreate' 명령어를 이용하여 VG에 LV를 생성한다.


[root@CentOS2 /root]# lvcreate -L 298M -n test_lg1 test_vg
  Rounding up size to full physical extent 300.00 MiB
  Logical volume "test_lg1" created

 - 데이터 블럭이 4MB이기 때문에 298MB로는 할당 안됨, 즉 4의 배수로 할당해야 한다.

 

[root@CentOS2 /root]# lvcreate -L 100M -n test_lg2 test_vg
  Logical volume "test_lg2" created

 

 7) 'lvdisplay' 명령어를 이용하여 LV가 생성되었는지 확인한다.

 


[root@CentOS2 /root]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/test_vg/test_lg1
  LV Name                test_lg1
  VG Name                test_vg
  LV UUID                7oB13P-NqAv-cjD8-MWXh-5zkj-zPve-ZXqvrm
  LV Write Access        read/write
  LV Creation host, time CentOS2, 2016-02-22 15:16:31 +0900
  LV Status              available
  # open                 0
  LV Size                300.00 MiB
  Current LE             75                (4MB x 75 = 300MB)
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/test_vg/test_lg2
  LV Name                test_lg2
  VG Name                test_vg
  LV UUID                z95dGS-ArTQ-6lPH-GsjF-ihk2-Gfc8-BAYmD8
  LV Write Access        read/write
  LV Creation host, time CentOS2, 2016-02-22 15:20:14 +0900
  LV Status              available
  # open                 0
  LV Size                100.00 MiB
  Current LE             25                (4MB x 25 = 100MB)
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1


[root@CentOS2 /root]# vgdisplay | grep -i free
  Free  PE / Size       0 / 0


[root@CentOS2 /root]# vgdisplay | grep -i mib
  VG Size               400.00 MiB
  PE Size               4.00 MiB
  Alloc PE / Size       100 / 400.00 MiB

 

 

 8) LV에 파일시스템을 생성한다.

 

[root@CentOS2 /root]# ls /dev/test_vg
test_lg1  test_lg2


[root@CentOS2 /root]# mkfs -t ext3 /dev/test_vg/test_lg1

[root@CentOS2 /root]# mkdir /newhome


[root@CentOS2 /root]# mount /dev/test_vg/test_lg1 /newhome

[root@CentOS2 /root]# df -h /newhome
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/test_vg-test_lg1
                      291M   11M  266M   4% /newhome


[root@CentOS2 /root]# ls -l /dev/test_vg/test_lg1
lrwxrwxrwx. 1 root root 7 2016-02-22 15:23 /dev/test_vg/test_lg1 -> ../dm-0

 

[root@CentOS2 /root]# ls /newhome
lost+found

 

 

 

Ex1) /newhome은 계정을 위한 용도로 사용하도록 한다.

 

[root@CentOS2 /root]# useradd -d /newhome/ccna ccna
[root@CentOS2 /root]# useradd -d /newhome/ccnp ccnp
[root@CentOS2 /root]# useradd -d /newhome/ccie ccie

[root@CentOS2 /root]# ls /newhome
ccie  ccna  ccnp  lost+found

 

 

 

Ex2) LV 디스크 용량 동적 확장

 

[root@CentOS2 /root]# df -h /newhome
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/test_vg-test_lg1
                      291M   11M  266M   4% /newhome

 


[root@CentOS2 /root]# dd if=/dev/zero of=/newhome/bigdata bs=1024k count=266
266+0 records in
266+0 records out
278921216 bytes (279 MB) copied, 7.9544 s, 35.1 MB/s


[root@CentOS2 /root]# df -h /newhome
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/test_vg-test_lg1
                      291M  278M     0 100% /newhome

 


 - 마운트 해지 실시


[root@CentOS2 /root]# umount /newhome

[root@CentOS2 /root]# vgdisplay
  --- Volume group ---
  VG Name               test_vg
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               0
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               400.00 MiB
  PE Size               4.00 MiB
  Total PE              100
  Alloc PE / Size       100 / 400.00 MiB
  Free  PE / Size       0 / 0
  VG UUID               A2BAVz-P0Ah-TBFn-eEJq-EgU3-ozhg-JGVfWs

 

 

 - /dev/sde1 파티션(200MB) 생성

 

[root@CentOS2 /root]# fdisk -l /dev/sde

Disk /dev/sde: 213 MB, 213909504 bytes
64 heads, 32 sectors/track, 204 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0005c2e7

   Device Boot      Start         End      Blocks   Id  System

[root@CentOS2 /root]# fdisk /dev/sde

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

 

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/sde: 213 MB, 213909504 bytes
64 heads, 32 sectors/track, 204 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0005c2e7

   Device Boot      Start         End      Blocks   Id  System
/dev/sde1               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@CentOS2 /root]#

 

[root@CentOS2 /root]# pvcreate /dev/sde1
  Physical volume "/dev/sde1" successfully created

 

[root@CentOS2 /root]# vgextend test_vg /dev/sde1
  Volume group "test_vg" successfully extended


[root@CentOS2 /root]# vgdisplay
  --- Volume group ---
  VG Name               test_vg
  System ID
  Format                lvm2
  Metadata Areas        3
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               0
  Max PV                0
  Cur PV                3
  Act PV                3
  VG Size               600.00 MiB
  PE Size               4.00 MiB
  Total PE              150
  Alloc PE / Size       100 / 400.00 MiB
  Free  PE / Size       50 / 200.00 MiB
  VG UUID               A2BAVz-P0Ah-TBFn-eEJq-EgU3-ozhg-JGVfWs

 

[root@CentOS2 /root]# lvresize --size +200M /dev/test_vg/test_lg1
  Size of logical volume test_vg/test_lg1 changed from 300.00 MiB (75 extents) to 500.00 MiB (125 extents).
  Logical volume test_lg1 successfully resized

 

[root@CentOS2 /root]# mount /dev/test_vg/test_lg1 /newhome

 

[root@CentOS2 /root]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/test_vg/test_lg1
  LV Name                test_lg1
  VG Name                test_vg
  LV UUID                7oB13P-NqAv-cjD8-MWXh-5zkj-zPve-ZXqvrm
  LV Write Access        read/write
  LV Creation host, time CentOS2, 2016-02-22 15:16:31 +0900
  LV Status              available
  # open                 1
  LV Size                500.00 MiB
  Current LE             125
  Segments               3
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/test_vg/test_lg2
  LV Name                test_lg2
  VG Name                test_vg
  LV UUID                z95dGS-ArTQ-6lPH-GsjF-ihk2-Gfc8-BAYmD8
  LV Write Access        read/write
  LV Creation host, time CentOS2, 2016-02-22 15:20:14 +0900
  LV Status              available
  # open                 0
  LV Size                100.00 MiB
  Current LE             25
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1


 

 

[root@CentOS2 /root]# df -h /newhome
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/test_vg-test_lg1
                      291M  278M     0 100% /newhome          여전히 300MB 보임

 

 

 - 마운트 해지를 실시하고 파일 시스템을 체크한 이후, 추가된 파티션 용량만 포멧을 실시한다.


[root@CentOS2 /root]# umount /newhome

 


[root@CentOS2 /root]# fsck /dev/test_vg/test_lg1
fsck from util-linux-ng 2.17.2
e2fsck 1.41.12 (17-May-2010)
/dev/mapper/test_vg-test_lg1: clean, 36/76912 files, 293482/307200 blocks

 

[root@CentOS2 /root]# resize2fs /dev/test_vg/test_lg1
resize2fs 1.41.12 (17-May-2010)
Please run 'e2fsck -f /dev/test_vg/test_lg1' first.

 

 

[root@CentOS2 /root]# fsck -f /dev/test_vg/test_lg1
fsck from util-linux-ng 2.17.2
e2fsck 1.41.12 (17-May-2010)
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/mapper/test_vg-test_lg1: 36/76912 files (0.0% non-contiguous), 293482/307200 blocks

 


[root@CentOS2 /root]# resize2fs /dev/test_vg/test_lg1
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/test_vg/test_lg1 to 512000 (1k) blocks.
The filesystem on /dev/test_vg/test_lg1 is now 512000 blocks long.

 

 

[root@CentOS2 /root]# mount /dev/test_vg/test_lg1 /newhome

 


[root@CentOS2 /root]# df -h /newhome
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/test_vg-test_lg1
                      485M  278M  182M  61% /newhome


[root@CentOS2 /root]# ls /newhome
bigdata  ccie  ccna  ccnp  lost+found

 

[root@CentOS2 /root]# su - ccna
[ccna@CentOS2 ~]$ exit
logout
[root@CentOS2 /root]#

 

 

 

 - Xwindow에서 확인 (Xwindow -> 터미널 오픈)

 

[root@CentOS2 /root/바탕화면]# yum install system-config-lvm

 

[root@CentOS2 /root/바탕화면]# system-config-lvm &

 

 

 


 


Ex3) LVM 제거

 

  - LVM 삭제는 역순으로 진행한다.

 

[root@CentOS2 /root]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              13G  4.4G  7.3G  38% /
tmpfs                 495M  500K  494M   1% /dev/shm
/dev/sda3             477M  2.3M  449M   1% /home
/dev/mapper/test_vg-test_lg1
                      485M  278M  182M  61% /newhome

 


 - 마운트 해지 실시

 

[root@CentOS2 /root]# umount /newhome

 


 - 삭제할 LV 이름 확인

 

[root@CentOS2 /root]# lvdisplay | grep -i name
  LV Name                test_lg1
  VG Name                test_vg
  LV Name                test_lg2
  VG Name                test_vg

 


 - 'lvremove' 명령어를 이용하여 LV 삭제

 

[root@CentOS2 /root]# lvremove /dev/test_vg/test_lg1
Do you really want to remove active logical volume test_lg1? [y/n]: y


  Logical volume "test_lg1" successfully removed

[root@CentOS2 /root]# lvremove /dev/test_vg/test_lg2
Do you really want to remove active logical volume test_lg2? [y/n]: y
  Logical volume "test_lg2" successfully removed

 

[root@CentOS2 /root]# lvdisplay

 


  - 'vgremove' 명령어를 이용하여 VG 삭제


[root@CentOS2 /root]# vgremove test_vg
  Volume group "test_vg" successfully removed

 

[root@CentOS2 /root]# vgdisplay
  No volume groups found

 


  - 삭제할 PV 이름 확인 및 'pvremove' 명령어를 이용하여 PV 삭제

 

[root@CentOS2 /root]# pvdisplay | grep -i name
  PV Name               /dev/sdc1
  VG Name
  PV Name               /dev/sdd1
  VG Name
  PV Name               /dev/sde1
  VG Name


[root@CentOS2 /root]# pvremove /dev/sdc1 /dev/sdd1 /dev/sde1
  Labels on physical volume "/dev/sdc1" successfully wiped
  Labels on physical volume "/dev/sdd1" successfully wiped
  Labels on physical volume "/dev/sde1" successfully wiped


[root@CentOS2 /root]# pvdisplay ; vgdisplay ; lvdisplay
  No volume groups found
  No volume groups found


[root@CentOS2 /root]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        13G  4.4G  7.3G  38% /
tmpfs           495M  500K  494M   1% /dev/shm
/dev/sda3       477M  2.3M  449M   1% /home

 


 

 

 

 

 - 환경 초기화 실시

 

[root@CentOS2 /root]# userdel -r ccna
[root@CentOS2 /root]# userdel -r ccnp
[root@CentOS2 /root]# userdel -r ccie

[root@CentOS2 /root]# rm -rf /newhome

 

 

[root@CentOS2 /root]# fdisk /dev/sdc

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

 

Command (m for help): d
Selected partition 1

 

Command (m for help): w
The partition table has been altered!

 

Calling ioctl() to re-read partition table.
Syncing disks.
[root@CentOS2 /root]#

 

[root@CentOS2 /root]# fdisk /dev/sdd

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

 

Command (m for help): d
Selected partition 1

 

Command (m for help): w
The partition table has been altered!

 

Calling ioctl() to re-read partition table.
Syncing disks.


[root@CentOS2 /root]# fdisk /dev/sde

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

 

Command (m for help): d
Selected partition 1

 

Command (m for help): w
The partition table has been altered!

 

Calling ioctl() to re-read partition table.
Syncing disks.
[root@CentOS2 /root]#

 

'서버 > Linux II' 카테고리의 다른 글

Linux II - 08. 디스크 Quota  (0) 2016.02.23
Linux II - 07. RAID 관리  (0) 2016.02.23
Linux II - 05. 파일 시스템 점검 및 복구  (0) 2016.02.17
Linux II - 04. 파일 시스템 구조  (0) 2016.02.04
Linux II - 03. 마운트 이해  (0) 2016.02.03
Posted by 김정우 강사(카카오톡 : kim10322)
,


Q