본문으로 바로가기

파일 시스템 구조
리눅스 파일 시스템은 ext2, ext3, ext4 가 있으며, 블락 단위로 구성되어 있다.



부트 블록  |  슈퍼 블록 | 아이노드 블록 | 데이터 블록

Boot Block

운영체제를 부팅하기 위한 코드를 저장하고 있으며, 하드웨어가 부팅에 필요한 코드를 여기서 찾는다. 또한 대부분의 파일 시스템들은 부트블록에 의해서 시작된다.


boot Block | Block Group 0 | Block Group 1 | Block Group2 | ........| Block Group n





root@CentOS2 /root]# fdisk -l /dev/sda

Disk /dev/sda: 16.1 GB, 16106127360 bytes
255 heads, 63 sectors/track, 1958 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000ec9f6

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        1634    13118464   83  Linux
/dev/sda2            1634        1895     2097152   82  Linux swap / Solaris
/dev/sda3            1895        1959      512000   83  Linux


 

[root@CentOS2 /root]# dumpe2fs /dev/sdb1
dumpe2fs 1.41.12 (17-May-2010)
Filesystem volume name:   /test1
Last mounted on:          <not available>
Filesystem UUID:          7accb373-dcc1-4292-b12b-ea9915a9b6da
~중간 생략~

 

Group 0: (Blocks 1-8192) [ITABLE_ZEROED]
  Checksum 0x0ca7, unused inodes 1861
  Primary superblock at 1, Group descriptors at 2-2
  Reserved GDT blocks at 3-205
  Block bitmap at 206 (+205), Inode bitmap at 222 (+221)
  Inode table at 238-471 (+237)
  6321 free blocks, 1861 free inodes, 2 directories, 1861 unused inodes
  Free blocks: 233-237, 1877-8192
  Free inodes: 12-1872

Group 1: (Blocks 8193-16384) [INODE_UNINIT, ITABLE_ZEROED]
  Checksum 0xcd9e, unused inodes 1872
  Backup superblock at 8193, Group descriptors at 8194-8194
  Reserved GDT blocks at 8195-8397
  Block bitmap at 207 (+4294959310), Inode bitmap at 223 (+4294959326)
  Inode table at 472-705 (+4294959575)
  7987 free blocks, 1872 free inodes, 0 directories, 1872 unused inodes
  Free blocks: 8398-16384
  Free inodes: 1873-3744

Group 2: (Blocks 16385-24576) [INODE_UNINIT, ITABLE_ZEROED]
  Checksum 0xf3d1, unused inodes 1872
  Block bitmap at 208 (+4294951119), Inode bitmap at 224 (+4294951135)
  Inode table at 706-939 (+4294951617)
  4096 free blocks, 1872 free inodes, 0 directories, 1872 unused inodes
  Free blocks: 20481-24576
  Free inodes: 3745-5616

~ 중간 생략~

Super Block


Super Block | Group Descriptor | GDT| Block Bitmap | Inode Bitmap | Inode Table | Date Blocks

블럭 그룹 가장 앞에 위치하며, 파일시스템과 관련된 정보(파일 시스템 전체 크기, 마운트 정보)를 갖고 있다.
리눅스에서는 슈퍼블록 정보를 사용하여 파일 시스템을 관리한다. 또한, Group0 의 Super Block 은 Group
1,3,5 에 백업본이 존재한다.



root@CentOS2 /root]# mkfs -t ext4 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
13104 inodes, 52208 blocks
2610 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=53477376
7 block groups
8192 blocks per group, 8192 fragments per group
1872 inodes per group
Superblock backups stored on blocks:
        8193, 24577, 40961

Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 30 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.


 

 

[root@CentOS2 /root]# dumpe2fs /dev/sdb1  ->dumpe2fs는 ext2, ext3 파일시스템의 슈퍼블록, 블록 그룹 정보에 대하여 출력해주는 명령어이다.


dumpe2fs 1.41.12 (17-May-2010)
Filesystem volume name:   /test1
Last mounted on:          <not available>
Filesystem UUID:          7accb373-dcc1-4292-b12b-ea9915a9b6da
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype extent flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize
Filesystem flags:         signed_directory_hash
Default mount options:    (none)
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              13104
Block count:              52208
Reserved block count:     2610
Free blocks:              45625
Free inodes:              13093
First block:              1
Block size:               1024
Fragment size:            1024
Reserved GDT blocks:      203
Blocks per group:         8192
Fragments per group:      8192
Inodes per group:         1872
Inode blocks per group:   234
Flex block group size:    16
Filesystem created:       Wed Feb  3 15:24:08 2016
Last mount time:          Wed Feb  3 18:27:59 2016
Last write time:          Wed Feb  3 18:32:58 2016
Mount count:              13
Maximum mount count:      22
Last checked:             Wed Feb  3 15:24:08 2016
Check interval:           15552000 (6 months)
~중간 생략~

 

Group 0: (Blocks 1-8192) [ITABLE_ZEROED]
  Checksum 0x0ca7, unused inodes 1861
  Primary superblock at 1, Group descriptors at 2-2
  Reserved GDT blocks at 3-205
  Block bitmap at 206 (+205), Inode bitmap at 222 (+221)
  Inode table at 238-471 (+237)
  6321 free blocks, 1861 free inodes, 2 directories, 1861 unused inodes
  Free blocks: 233-237, 1877-8192
  Free inodes: 12-1872

 
Group 1: (Blocks 8193-16384) [INODE_UNINIT, ITABLE_ZEROED]
  Checksum 0xcd9e, unused inodes 1872
  Backup superblock at 8193, Group descriptors at 8194-8194
  Reserved GDT blocks at 8195-8397
  Block bitmap at 207 (+4294959310), Inode bitmap at 223 (+4294959326)
  Inode table at 472-705 (+4294959575)
  7987 free blocks, 1872 free inodes, 0 directories, 1872 unused inodes
  Free blocks: 8398-16384
  Free inodes: 1873-3744


Group 2: (Blocks 16385-24576) [INODE_UNINIT, ITABLE_ZEROED]
  Checksum 0xf3d1, unused inodes 1872
  Block bitmap at 208 (+4294951119), Inode bitmap at 224 (+4294951135)
  Inode table at 706-939 (+4294951617)
  4096 free blocks, 1872 free inodes, 0 directories, 1872 unused inodes
  Free blocks: 20481-24576
  Free inodes: 3745-5616

~중간 생략~

 

 

Group Descriptor

해당 파일시스템 내의 모든 블럭 그룹에 대한 정보를 기록한다.

 

GDT(Group Descriptor Table)

첫 번째 Inode Table Block 블럭 번호, 그룹내 Free Block & inode 갯수, 디렉토리 갯수를 기록한다.

또한, Group0의 GDT은 Group 1,3,5에 백업본이 존재한다

 

Block Bitmap

블럭 그룹에서 블럭 할당 상태를 표기하는 맵이며, 블럭 할당 및 해지할때 사용한다.

 

Inode Bitmap

Inode 할당 상태를 표기하는 맵이며, Inode 할당 및 해지할때 사용한다.

 

Inode Table

파일 속정 정보(접근 권한, 소유주, 파일 크기, Inode 번호)가 저장되어 있다. 파일 하나당 하나의 Inode가 사용되며, 파일 유형과 관계없이 Inode 블럭을 갖게된다.

 

Data Block

실제 데이터 내용이 저장되는 디스크 영역이다.

 





 
 

LVM (Logical Volume Manager)



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 - 07. RAID 관리

 

 

 

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

 

login as: root
root@192.168.1.7's password:
Last login: Mon Feb 22 14:11:40 2016 from 192.168.1.1
[root@CentOS2 /root]#


 

 

 

 

1. RAID(Redudant Array of Inexpensive Disks)

 

여러개의 디스크를 하나의 디스크처럼 사용할 수 있도록 하며, 신뢰성과 성능을 향상시킬수 있는 저장 장치를 의미한다.

 




 RAID 종류
 
장점
 
단점
 
 단위
 

 하드웨어 RAID
 
신뢰성 및 안정성 보장
 
고비용
 
 디스크
 

 소프트웨어 RAID
 
저비용
 
 신뢰성 및 안정성 비보장
 
 파티션
 


 

 

 

 

2. RAID 구성

 

[root@CentOS2 /root]# cat /proc/mdstat
Personalities :
unused devices: <none>


 

'mdadm' 명령어를 이용하여 RAID를 구성한다. 해당 명령어는 다음과 같다.

 



 --create
  RAID 구성
  # mdadm --create /dev/md0

 --detail
 
  RAID 상태 상세 확인
 
 # mdadm --detail /dev/md0
 

 --remove
 
  RAID 디스크 제거
 
 # mdadm --manage /dev/md0 --remove /dev/sdc1
 

 --add
 
  RAID 디스크 추가
 
 # mdadm --manage /dev/md0 --add /dev/sdc1
 

 --fail
 
  RAID 디스크 강제 장애
 
 # mdadm --manage /dev/md0 --fail /dev/sdc1
 

 -S (--stop)
 
  RAID 정지
 
 # mdadm --stop /dev/md0
 

 -r (--remove)
 
  RAID 제거
 
 # mdadm -r /dev/md0
 


 

 

 

1) RAID 0 Volume (Stripe Volume)

 






 최소 디스크 개수
 
 2개 이상
 

 장점
 
 읽기/쓰기 속도가 빠르며, 디스크 가용율이 100%이다.
 

 단점
 
 이중화가 안되며, 디스크 하나가 손상되면 나머지 디스크에 저장된 데이터 전부를 사용할 수 없다.
 

 비고
 
 
 


 

 

 

Ex1) RAID 0 구성

 

 - /dev/sdc1, /dev/sdd1, /dev/sde1 RAID 타입 파티션 생성

 

[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): t
Selected partition 1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)

 

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   fd  Linux raid autodetect

 

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/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): fd
Changed system type of partition 1 to fd (Linux raid autodetect)

 

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): 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): fd
Changed system type of partition 1 to fd (Linux raid autodetect)

 

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 /dev/sde | grep -i raid
/dev/sdc1               1         204      208880   fd  Linux raid autodetect
/dev/sdd1               1         204      208880   fd  Linux raid autodetect
/dev/sde1               1         204      208880   fd  Linux raid autodetect

 

 

 -  'mdadm' 명령어를 이용하여 RAID 0 구성 실시


[root@CentOS2 /root]# mdadm --create /dev/md0 --level=stripe --raid-devices=3 /dev/sdc1 /dev/sdd1 /dev/sde1
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.

 

[root@CentOS2 /root]# ls /dev/md0
/dev/md0

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

Disk /dev/md0: 637 MB, 637009920 bytes
2 heads, 4 sectors/track, 155520 cylinders
Units = cylinders of 8 * 512 = 4096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 524288 bytes / 1572864 bytes
Disk identifier: 0x00000000

[root@CentOS2 /root]# mdadm --detail --scan -v
ARRAY /dev/md0 level=raid0 num-devices=3 metadata=1.2 name=CentOS2:0 UUID=d1e6afb4:770ed44d:bee91aad:46719986
   devices=/dev/sdc1,/dev/sdd1,/dev/sde1

[root@CentOS2 /root]# cat /proc/mdstat
Personalities : [raid0]
md0 : active raid0 sde1[2] sdd1[1] sdc1[0]
      622080 blocks super 1.2 512k chunks

unused devices: <none>


 

 

 - 파일 시스템 생성 및 마운트 실시


[root@CentOS2 /root]# mkfs.ext4 /dev/md0 1> /dev/null
mke2fs 1.41.12 (17-May-2010)

[root@CentOS2 /root]# mkdir /raid0


[root@CentOS2 /root]# mount /dev/md0 /raid0

[root@CentOS2 /root]# df -h /raid0
Filesystem      Size  Used Avail Use% Mounted on
/dev/md0        582M  468K  552M   1% /raid0


 

 

 - CentOS 6.x에서는 재부팅하면 RAID 볼륨 장치 번호가 변경된다. 변경되는 것을 방지하는 방법은 다음과 같다.


[root@CentOS2 /root]# mdadm --detail --scan -v 1> /etc/mdadm.conf    (RAID 설정 정보를 'mdadm.conf'에 저장)


 

 

 

Ex2) RAID 0 제거

 

[root@CentOS2 /root]# umount /dev/md0

 

[root@CentOS2 /root]# mdadm --stop /dev/md0

mdadm: stopped /dev/md0


[root@CentOS2 /root]# mdadm --zero-superblock /dev/sdc1 /dev/sdd1 /dev/sde1


[root@CentOS2 /root]# mdadm --examine /dev/sdc1 /dev/sdd1 /dev/sde1
mdadm: No md superblock detected on /dev/sdc1.
mdadm: No md superblock detected on /dev/sdd1.
mdadm: No md superblock detected on /dev/sde1.

[root@CentOS2 /root]# ls /dev/md0
ls: cannot access /dev/md0: 그런 파일이나 디렉터리가 없습니다

[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

 

 

 

 

 2) RAID 1 Volume (Mirror Volume)

 






 최소 디스크 개수
 
 2개 이상
 

 장점
 
 이중화가 가능하다.
 

 단점
 
 디스크 가용율이 50%이다.
 

 비고
 
 읽기 속도는 빠르지만, 쓰기 속도는 보통이다.
 


 

 

 

Ex1) RAID 1 구성

 

 - /dev/sdf1, /dev/sdg1 RAID 타입 파티션 생성

 

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

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): fd
Changed system type of partition 1 to fd (Linux raid autodetect)

 

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/sdg

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): fd
Changed system type of partition 1 to fd (Linux raid autodetect)

 

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/sdf /dev/sdg | grep -i raid
/dev/sdf1               1         204      208880   fd  Linux raid autodetect
/dev/sdg1               1         204      208880   fd  Linux raid autodetect


 

 

 -  'mdadm' 명령어를 이용하여 RAID 1 구성 실시

 

[root@CentOS2 /root]# mdadm --create /dev/md1 --level=1 --raid-devices=2 /dev/sdf1 /dev/sdg1
mdadm: Note: this array has metadata at the start and
    may not be suitable as a boot device.  If you plan to
    store '/boot' on this device please ensure that
    your boot-loader understands md/v1.x metadata, or use
    --metadata=0.90
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md1 started.

[root@CentOS2 /root]# ls /dev/md1
/dev/md1

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

Disk /dev/md1: 213 MB, 213712896 bytes
2 heads, 4 sectors/track, 52176 cylinders
Units = cylinders of 8 * 512 = 4096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


[root@CentOS2 /root]# mdadm --detail -scan -v
ARRAY /dev/md1 level=raid1 num-devices=2 metadata=1.2 name=CentOS2:1 UUID=c957ee01:f985c8f8:8bfaad46:125b6bfb
   devices=/dev/sdf1,/dev/sdg1

[root@CentOS2 /root]# cat /proc/mdstat
Personalities : [raid0] [raid1]
md1 : active raid1 sdg1[1] sdf1[0]
      208704 blocks super 1.2 [2/2] [UU]

unused devices: <none>


 

 

 - 파일 시스템 생성 및 마운트 실시


[root@CentOS2 /root]# mkfs.ext4 /dev/md1 1> /dev/null
mke2fs 1.41.12 (17-May-2010)

[root@CentOS2 /root]# mkdir /raid1


[root@CentOS2 /root]# mount /dev/md1 /raid1


[root@CentOS2 /root]# df -h /raid1
Filesystem      Size  Used Avail Use% Mounted on
/dev/md1        194M  1.8M  182M   1% /raid1



 

 - CentOS 6.x에서는 재부팅하면 RAID 볼륨 장치 번호가 변경된다. 변경되는 것을 방지하는 방법은 다음과 같다.


[root@CentOS2 /root]# mdadm --detail --scan -v 1> /etc/mdadm.conf    (RAID 설정 정보를 'mdadm.conf'에 저장)


 

 

 

Ex2) RAID 1 제거

 

[root@CentOS2 /root]# umount /dev/md1


[root@CentOS2 /root]# mdadm --stop /dev/md1
mdadm: stopped /dev/md1

[root@CentOS2 /root]# mdadm --zero-superblock /dev/sdf1 /dev/sdg1

[root@CentOS2 /root]# mdadm --examine /dev/sdf1 /dev/sdg1
mdadm: No md superblock detected on /dev/sdf1.
mdadm: No md superblock detected on /dev/sdg1.

[root@CentOS2 /root]# ls /dev/md1
ls: cannot access /dev/md1: 그런 파일이나 디렉터리가 없습니다

[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


 

 

 

 

 3) RAID 5

 






 최소 디스크 개수
 
 3개 이상
 

 장점
 
 디스크 1개가 장애가 발생되어도, 데이터 복구가 가능하다.
 

 단점
 
 디스크를 가용할 수 있는 용량은 '전체 디스크 개수 -1' 을 해야 한다.
 

 비고
 
 성능이 그리 중요하지 않고 쓰기 작업이 많지 않은 다중 사용자 시스템에 적합하다.
 


 

 

 

Ex1) RAID 5 구성

 

 - /dev/sdc1, /dev/sdd1, /dev/sde1 RAID 타입 파티션 생성 확인

 
[root@CentOS2 /root]# fdisk -l /dev/sdc /dev/sdd /dev/sde | grep -i raid
/dev/sdc1               1         204      208880   fd  Linux raid autodetect
/dev/sdd1               1         204      208880   fd  Linux raid autodetect
/dev/sde1               1         204      208880   fd  Linux raid autodetect

 

 
 -  'mdadm' 명령어를 이용하여 RAID 5 구성 실시

[root@CentOS2 /root]# mdadm --create /dev/md5 --level=5 --raid-devices=3 /dev/sdc1 /dev/sdd1 /dev/sde1
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md5 started.

[root@CentOS2 /root]# ls /dev/md5
/dev/md5

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

Disk /dev/md5: 424 MB, 424673280 bytes
2 heads, 4 sectors/track, 103680 cylinders
Units = cylinders of 8 * 512 = 4096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 524288 bytes / 1048576 bytes
Disk identifier: 0x00000000


[root@CentOS2 /root]# mdadm --detail --scan -v
ARRAY /dev/md5 level=raid5 num-devices=3 metadata=1.2 name=CentOS2:5 UUID=bf8908c0:0cb128dc:f4e87b4b:b6ffb981
   devices=/dev/sdc1,/dev/sdd1,/dev/sde1

[root@CentOS2 /root]# cat /proc/mdstat
Personalities : [raid0] [raid1] [raid6] [raid5] [raid4]
md5 : active raid5 sde1[3] sdd1[1] sdc1[0]
      414720 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]

unused devices: <none>


 

 

 - CentOS 6.x에서는 재부팅하면 RAID 볼륨 장치 번호가 변경된다. 변경되는 것을 방지하는 방법은 다음과 같다.

 
[root@CentOS2 /root]# mdadm --detail --scan -v 1> /etc/mdadm.conf    (RAID 설정 정보를 'mdadm.conf'에 저장)
[root@CentOS2 /root]# cat /etc/mdadm.conf
ARRAY /dev/md5 level=raid5 num-devices=3 metadata=1.2 name=CentOS2:5 UUID=bf8908c0:0cb128dc:f4e87b4b:b6ffb981
   devices=/dev/sdc1,/dev/sdd1,/dev/sde1
 
 

 

 - 파일 시스템 생성 및 마운트 실시


[root@CentOS2 /root]# mkfs.ext4 /dev/md5 1> /dev/null
mke2fs 1.41.12 (17-May-2010)

[root@CentOS2 /root]# mkdir /raid5
[root@CentOS2 /root]# mount /dev/md5 /raid5

[root@CentOS2 /root]# df -h /raid5
Filesystem      Size  Used Avail Use% Mounted on
/dev/md5        385M  2.3M  362M   1% /raid5


 

 

 - /dev/sdd1 디스크 손상 실시


[root@CentOS2 /root]# ls /home
lost+found  user1  user2

[root@CentOS2 /root]# cp -rp /home/* /raid5
[root@CentOS2 /root]# echo "hello" > /raid5/testfile
[root@CentOS2 /root]# ls /raid5
lost+found  testfile  user1  user2


[root@CentOS2 /root]# dd if=/dev/zero of=/raid5/testfile bs=1024k count=500

dd: writing `/raid5/testfile': 장치에 남은 공간이 없음
378+0 records in
377+0 records out
396242944 bytes (396 MB) copied, 30.5113 s, 13.0 MB/s



[root@CentOS2 /root]# mdadm --detail --scan -v >> /etc/mdadm.conf


[root@CentOS2 /root]# mdadm --manage /dev/md5 --fail /dev/sdd1
mdadm: set /dev/sdd1 faulty in /dev/md5

[root@CentOS2 /root]# cat /proc/mdstat
Personalities : [raid0] [raid1] [raid6] [raid5] [raid4]
md5 : active raid5 sde1[3] sdd1[1](F) sdc1[0]
      414720 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/2] [U_U]

unused devices: <none>

[root@CentOS2 /root]# ls /raid5
lost+found  testfile  user1  user2


 

 

 - /dev/sdd1' 손상 상태에서 'dev/sdf1'으로 복구 실시

 

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

Disk /dev/sdf: 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: 0x000875f9

   Device Boot      Start         End      Blocks   Id  System
/dev/sdf1               1         204      208880   fd  Linux raid autodetect

[root@CentOS2 /root]# mdadm --manage /dev/md5 --add /dev/sdf1
mdadm: added /dev/sdf1

[root@CentOS2 /root]# cat /proc/mdstat
Personalities : [raid0] [raid1] [raid6] [raid5] [raid4]
md5 : active raid5 sdf1[4] sde1[3] sdd1[1](F) sdc1[0]
      414720 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/2] [U_U]
      [======>..............]  recovery = 33.7% (70148/207360) finish=0.1min speed=14029K/sec

unused devices: <none>

[root@CentOS2 /root]# cat /proc/mdstat
Personalities : [raid0] [raid1] [raid6] [raid5] [raid4]
md5 : active raid5 sdf1[4] sde1[3] sdd1[1](F) sdc1[0]
      414720 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/2] [U_U]
      [============>........]  recovery = 60.8% (126720/207360) finish=0.0min speed=14080K/sec

unused devices: <none>

[root@CentOS2 /root]# cat /proc/mdstat
Personalities : [raid0] [raid1] [raid6] [raid5] [raid4]
md5 : active raid5 sdf1[4] sde1[3] sdd1[1](F) sdc1[0]
      414720 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]

unused devices: <none>


 

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

Disk /dev/md5: 424 MB, 424673280 bytes
2 heads, 4 sectors/track, 103680 cylinders
Units = cylinders of 8 * 512 = 4096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 524288 bytes / 1048576 bytes
Disk identifier: 0x00000000




[root@CentOS2 /root]# su - user1
[user1@CentOS2 /home/user1]$ exit
logout


 

 

 

Ex2) RAID 5 제거

 

[root@CentOS2 /root]# umount /dev/md5

 

[root@CentOS2 /root]# mdadm --stop /dev/md5
mdadm: stopped /dev/md5

 

[root@CentOS2 /root]# mdadm --zero-superblock /dev/sdc1 /dev/sdd1 /dev/sde1 /dev/sdf1

 

[root@CentOS2 /root]# mdadm --examine /dev/sdc1 /dev/sdd1 /dev/sde1 /dev/sdf1
mdadm: No md superblock detected on /dev/sdc1.
mdadm: No md superblock detected on /dev/sdd1.
mdadm: No md superblock detected on /dev/sde1.
mdadm: No md superblock detected on /dev/sdf1.

 

[root@CentOS2 /root]# ls /dev/md5
ls: cannot access /dev/md5: 그런 파일이나 디렉터리가 없습니다

 

[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


 

 

 

 

 4) RAID 0+1






 최소 디스크 개수
 
 4개 이상
 

 장점
 
 Stripe와 Mirror를 동시에 적용할 수 있다.
 

 단점
 
 비용이 많이 발생한다.
 

 비고
 
 CentOS에서는 지원하지 않기 때문에, Stripe를 구성하고 이를 Mirror로 구성해야 한다.
 


 

 

 

Ex1) RAID 0+1 구성

 

 - /dev/sdc1, /dev/sdd1, /dev/sde1, /dev/sdf1 RAID 타입 파티션 생성 확인

 
[root@CentOS2 /root]# fdisk -l /dev/sdc /dev/sdd /dev/sde /dev/sdf | grep -i raid
/dev/sdc1               1         204      208880   fd  Linux raid autodetect
/dev/sdd1               1         204      208880   fd  Linux raid autodetect
/dev/sde1               1         204      208880   fd  Linux raid autodetect
/dev/sdf1               1         204      208880   fd  Linux raid autodetect


 

 

 - CentOS에서는 'RAID 0+1' 레벨이 지원되지 않기 때문에, 먼저 Stripe 구성 실시

 

[root@CentOS2 /root]# mdadm --create /dev/md0 --level=0 --raid-devices=2  /dev/sdc1  /dev/sdd1
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.

[root@CentOS2 /root]# mdadm --create /dev/md1 --level=0 --raid-devices=2 /dev/sde1  /dev/sdf1
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md1 started.


 

 

 -  Mirror 구성 실시

 

[root@CentOS2 /root]# mdadm --create /dev/md2 --level=1 --raid-devices=2 /dev/md0 /dev/md1
mdadm: /dev/md0 appears to contain an ext2fs file system
       size=414720K  mtime=Tue Feb 23 13:49:04 2016
mdadm: Note: this array has metadata at the start and
    may not be suitable as a boot device.  If you plan to
    store '/boot' on this device please ensure that
    your boot-loader understands md/v1.x metadata, or use
    --metadata=0.90
mdadm: /dev/md1 appears to contain an ext2fs file system
       size=414720K  mtime=Tue Feb 23 13:49:04 2016
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md2 started.


 

[root@CentOS2 /root]# ls /dev/md0
/dev/md0

[root@CentOS2 /root]# ls /dev/md1
/dev/md1

[root@CentOS2 /root]# ls /dev/md2
/dev/md2

[root@CentOS2 /root]# mdadm --detail --scan -v
ARRAY /dev/md0 level=raid0 num-devices=2 metadata=1.2 name=CentOS2:0 UUID=20576727:16c13b0e:946c3812:25fab12d
   devices=/dev/sdc1,/dev/sdd1
ARRAY /dev/md1 level=raid0 num-devices=2 metadata=1.2 name=CentOS2:1 UUID=1a11ffe9:4cbb5a2a:e3f645a8:220a4f4c
   devices=/dev/sde1,/dev/sdf1
ARRAY /dev/md2 level=raid1 num-devices=2 metadata=1.2 name=CentOS2:2 UUID=e67dc48f:eb0410e4:d24d484e:74e329fb
   devices=/dev/md0,/dev/md1

[root@CentOS2 /root]# cat /proc/mdstat
Personalities : [raid0] [raid1] [raid6] [raid5] [raid4]
md2 : active raid1 md1[1] md0[0]
      414400 blocks super 1.2 [2/2] [UU]

md1 : active raid0 sdf1[1] sde1[0]
      414720 blocks super 1.2 512k chunks

md0 : active raid0 sdd1[1] sdc1[0]
      414720 blocks super 1.2 512k chunks

unused devices: <none>


 

 

 - CentOS 6.x에서는 재부팅하면 RAID 볼륨 장치 번호가 변경된다. 변경되는 것을 방지하는 방법은 다음과 같다.

 
[root@CentOS2 /root]# mdadm --detail --scan -v 1> /etc/mdadm.conf    (RAID 설정 정보를 'mdadm.conf'에 저장)
[root@CentOS2 /root]# cat /etc/mdadm.conf
ARRAY /dev/md0 level=raid0 num-devices=2 metadata=1.2 name=CentOS2:0 UUID=20576727:16c13b0e:946c3812:25fab12d
   devices=/dev/sdc1,/dev/sdd1
ARRAY /dev/md1 level=raid0 num-devices=2 metadata=1.2 name=CentOS2:1 UUID=1a11ffe9:4cbb5a2a:e3f645a8:220a4f4c
   devices=/dev/sde1,/dev/sdf1
ARRAY /dev/md2 level=raid1 num-devices=2 metadata=1.2 name=CentOS2:2 UUID=e67dc48f:eb0410e4:d24d484e:74e329fb
   devices=/dev/md0,/dev/md1



 

 - 파일 시스템 생성 및 마운트 실시


[root@CentOS2 /root]# mkfs.ext4 /dev/md2 > /dev/null
mke2fs 1.41.12 (17-May-2010)

[root@CentOS2 /root]# mkdir /raid01
[root@CentOS2 /root]# mount /dev/md2 /raid01

[root@CentOS2 /root]# df -h /raid01
Filesystem      Size  Used Avail Use% Mounted on
/dev/md2        384M  2.3M  362M   1% /raid01



 

 Ex2) RAID 0+1 제거

 

[root@CentOS2 /root]# umount /dev/md2

 

[root@CentOS2 /root]# mdadm --stop /dev/md2
mdadm: stopped /dev/md2

 

[root@CentOS2 /root]# mdadm --stop /dev/md1
mdadm: stopped /dev/md1

 

[root@CentOS2 /root]# mdadm --stop /dev/md0
mdadm: stopped /dev/md0

 

[root@CentOS2 /root]# mdadm --zero-superblock /dev/sdc1 /dev/sdd1 /dev/sde1 /dev/sdf1

 

[root@CentOS2 /root]# mdadm --examine /dev/sdc1 /dev/sdd1 /dev/sde1 /dev/sdf1
mdadm: No md superblock detected on /dev/sdc1.
mdadm: No md superblock detected on /dev/sdd1.
mdadm: No md superblock detected on /dev/sde1.
mdadm: No md superblock detected on /dev/sdf1.

 

[root@CentOS2 /root]# ls /dev/md2
ls: cannot access /dev/md2: 그런 파일이나 디렉터리가 없습니다

 

[root@CentOS2 /root]# ls /dev/md1
ls: cannot access /dev/md1: 그런 파일이나 디렉터리가 없습니다

 

[root@CentOS2 /root]# ls /dev/md0
ls: cannot access /dev/md0: 그런 파일이나 디렉터리가 없습니다

 

[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

 

 

 

 

 5) RAID 1+0






 최소 디스크 개수
 
 4개 이상
 

 장점
 
 Stripe와 Mirror를 동시에 적용할 수 있다.
 

 단점
 
 비용이 많이 발생한다.
 

 비고
 
 RAID 0+1 보다 효율적이다.
 


 

 

Ex1) RAID 1+0 구성

 

 - /dev/sdc1, /dev/sdd1, /dev/sde1 RAID 타입 파티션 생성 확인

 
[root@CentOS2 /root]# fdisk -l /dev/sdc /dev/sdd /dev/sde /dev/sdf | grep -i raid
/dev/sdc1               1         204      208880   fd  Linux raid autodetect
/dev/sdd1               1         204      208880   fd  Linux raid autodetect
/dev/sde1               1         204      208880   fd  Linux raid autodetect
/dev/sdf1               1         204      208880   fd  Linux raid autodetect


 

 

 -  'mdadm' 명령어를 이용하여 RAID 1+0 구성 실시


[root@CentOS2 /root]# mdadm --create /dev/md10 --level=10 --raid-devices=4 /dev/sdc1 /dev/sdd1 /dev/sde1 /dev/sdf1
mdadm: /dev/sdc1 appears to contain an ext2fs file system
       size=103408K  mtime=Fri Feb 19 12:01:57 2016
mdadm: /dev/sdd1 appears to contain an ext2fs file system
       size=103408K  mtime=Fri Feb 19 10:15:46 2016
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md10 started.

[root@CentOS2 /root]# ls /dev/md10
/dev/md10

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

Disk /dev/md10: 424 MB, 424673280 bytes
2 heads, 4 sectors/track, 103680 cylinders
Units = cylinders of 8 * 512 = 4096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 524288 bytes / 1048576 bytes
Disk identifier: 0x00000000


[root@CentOS2 /root]# mdadm --detail --scan -v
ARRAY /dev/md10 level=raid10 num-devices=4 metadata=1.2 name=CentOS2:10 UUID=4b9dd62e:d750e756:98da4eaa:1c841ea6
   devices=/dev/sdc1,/dev/sdd1,/dev/sde1,/dev/sdf1

[root@CentOS2 /root]# cat /proc/mdstat
Personalities : [raid10]
md10 : active raid10 sdf1[3] sde1[2] sdd1[1] sdc1[0]
      414720 blocks super 1.2 512K chunks 2 near-copies [4/4] [UUUU]

unused devices: <none>

 

 

 - CentOS 6.x에서는 재부팅하면 RAID 볼륨 장치 번호가 변경된다. 변경되는 것을 방지하는 방법은 다음과 같다.

 
[root@CentOS2 /root]# mdadm --detail --scan -v 1> /etc/mdadm.conf    (RAID 설정 정보를 'mdadm.conf'에 저장)
[root@CentOS2 /root]# cat /etc/mdadm.conf
ARRAY /dev/md10 level=raid10 num-devices=4 metadata=1.2 name=CentOS2:10 UUID=4b9dd62e:d750e756:98da4eaa:1c841ea6
   devices=/dev/sdc1,/dev/sdd1,/dev/sde1,/dev/sdf1



 

 - 파일 시스템 생성 및 마운트 실시


[root@CentOS2 /root]# mkfs.ext4 /dev/md10 1> /dev/null
mke2fs 1.41.12 (17-May-2010)

[root@CentOS2 /root]# mkdir /raid10
[root@CentOS2 /root]# mount /dev/md10 /raid10

[root@CentOS2 /root]# df -h /raid10
Filesystem      Size  Used Avail Use% Mounted on
/dev/md10       385M  2.3M  362M   1% /raid10


 


Ex2) RAID 1+0 제거


[root@CentOS2 /root]# umount /dev/md10


[root@CentOS2 /root]# mdadm --stop /dev/md10
mdadm: stopped /dev/md10

[root@CentOS2 /root]# mdadm --zero-superblock /dev/sdc1 /dev/sdd1 /dev/sde1 /dev/sdf1

[root@CentOS2 /root]# mdadm --examine /dev/sdc1 /dev/sdd1 /dev/sde1 /dev/sdf1
mdadm: No md superblock detected on /dev/sdc1.
mdadm: No md superblock detected on /dev/sdd1.
mdadm: No md superblock detected on /dev/sde1.
mdadm: No md superblock detected on /dev/sdf1.

[root@CentOS2 /root]#  ls /dev/md10
/dev/md10


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

 

 

 

 

 

 

 - 설정 초기화

 

[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]# 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]# fdisk /dev/sdf

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/sdg

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.







 



 



Linux II - 08. 디스크 Quota

 

 

 

login as: root
root@192.168.1.7's password:
Last login: Tue Feb 23 14:49:30 2016 from 192.168.1.1
[root@CentOS2 /root]#


 

 

 

1. Quota

 

Quota란 사용자 또는 그룹별로 디스크 사용량, 파일 갯수를 제한하는 기능을 말한다. 이 기능을 이용하면 특정 사용자가 디스크 공간을 무제한으로 사용하는 것을 방지할 수 있다. 먼저, 현재 CentOS에 Quoat가 설치되어 있는지 'rpm' 명령어를 통해서 확인한다.

 

[root@CentOS2 /root]# rpm -qa | grep quota
quota-3.17-21.el6_5.x86_64

 

 

만약, Quota가 설치가 안되어 있다면, 다음과 같이 'yum' 명령어를 이용하여 설치한다.


[root@CentOS2 /root]# yum install quota


[root@CentOS2 /root]# rpm -qa | grep quota
quota-3.17-23.el6.x86_64


 

 

 

2. Quota 구성 단계

 

 1) 용량을 제한할 파티션을 선정한다.

 2) /etc/fstab에 용량을 제한할 파티션을 등록하고 Quota 옵션을 설정한다.

 3) 재부팅하거나, 또는 /etc/fstab에서 다시 읽을 수 있도록 다시 마운트를 실시한다.

 4) Quota DB 파일을 생성한다.

 5) Quota 활성화를 실시한다.

 6) 사용자별 Quota 설정을 실시한다.

 

 

 

Ex1) 사용자별 Quota 구성

 

 1) 용량을 제한할 파티션을 선정한다.

 

 - /dev/sdc/ 파티션 생성 및 파일 시스템 생성

 

[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): w
The partition table has been altered!

 

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

[root@CentOS2 /root]# mkfs.ext4 /dev/sdc1 > /dev/null
mke2fs 1.41.12 (17-May-2010)


 

 

 - '/newhome' 디렉토리 생성 및 마운트 실시, 계정 추가


[root@CentOS2 /root]# mkdir /newhome


[root@CentOS2 /root]# mount /dev/sdc1 /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


 

 

 

 2) /etc/fstab에 용량을 제한할 파티션을 등록하고 Quota 옵션을 설정한다.

 

[root@CentOS2 /root]# vi /etc/fstab


 




  1
  2 #
  3 # /etc/fstab
  4 # Created by anaconda on Wed Feb  3 01:40:21 2016
  5 #
  6 # Accessible filesystems, by reference, are maintained under '/dev/disk'
  7 # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
  8 #
  9 UUID=7c533aa0-0a72-4a94-b076-382622ad8486 /                       ext4    defaults        1 1
 10 UUID=f55d38f2-1434-4107-8aab-3f9ac3cba3b5 /home                   ext4    defaults        1 2
 11 UUID=78b6f307-7ca2-4ae7-b2e5-866f01d64a15 swap                    swap    defaults        0 0
 12 tmpfs                   /dev/shm                tmpfs   defaults        0 0
 13 devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
 14 sysfs                   /sys                    sysfs   defaults        0 0
 15 proc                    /proc                   proc    defaults        0 0
 16 /dev/sdc1               /newhome                ext4    defaults,usrquota,grpquota      1 2


 

: wq!
 


 

 

 

 

3) 재부팅하거나, 또는 /etc/fstab에서 다시 읽을 수 있도록 다시 마운트를 실시한다.

 

 - 마운트 해지 및 다시 마운트 실시

 

[root@CentOS2 /root]# umount /newhome
[root@CentOS2 /root]# mount -a

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

 


 

 4) Quota DB 파일을 생성한다.

 

 - 'selinux' 가 활성화되어 있다면, Quota DB 생성 에러가 발생 (SElinux : 리눅스 취약점을 보완하기 위한 리눅스 기능)

 

[root@CentOS2 /root]# sestatus
SELinux status:                 enabled
SELinuxfs mount:                /selinux
Current mode:                   enforcing
Mode from config file:          enforcing
Policy version:                 24
Policy from config file:        targeted



[root@CentOS2 /root]# quotacheck -ug /newhome
quotacheck: Cannot create new quotafile /newhome/aquota.user.new: 허가 거부
quotacheck: Cannot initialize IO on new quotafile: 허가 거부
quotacheck: Cannot create new quotafile /newhome/aquota.group.new: 허가 거부
quotacheck: Cannot initialize IO on new quotafile: 허가 거부


 

 

 - 다음 명령어를 실행한 이후,  Quota DB 생성 실시


[root@CentOS2 /root]# chcon --reference /var /newhome

 

[root@CentOS2 /root]# quotacheck -ug /newhome              u : 계정 Quota, g : 그룹 Quota
[root@CentOS2 /root]# ls -l /newhome
합계 34
-rw-------. 1 root root  7168 2016-02-26 17:04 aquota.group
-rw-------. 1 root root  7168 2016-02-26 17:04 aquota.user
drwx------. 4 ccie ccie  1024 2016-02-26 16:37 ccie
drwx------. 4 ccna ccna  1024 2016-02-26 16:37 ccna
drwx------. 4 ccnp ccnp  1024 2016-02-26 16:37 ccnp
drwx------. 2 root root 12288 2016-02-26 16:36 lost+found

[root@CentOS2 /root]# ls -l /newhome/*quota*
-rw-------. 1 root root 7168 2016-02-26 17:04 /newhome/aquota.group
-rw-------. 1 root root 7168 2016-02-26 17:04 /newhome/aquota.user



 

 

 5) Quota 활성화를 실시한다.

 

 - Quota를 활성화 하지 않으면, Quota가 적용되지 않기 때문에 활성화 실시


[root@CentOS2 /root]# quotaon -v /newhome                       비활성화 : quotaoff -v /newhome
/dev/sdc1 [/newhome]: group quotas turned on
/dev/sdc1 [/newhome]: user quotas turned on


 

 

 

 

 6) 사용자별 Quota 설정을 실시한다.

 

 - EDITOR 환경 변수가 설정안되있기 때문에, default로 vi 편집기에서 설정 실시

 

[root@CentOS2 /root]# echo $EDITOR

 

 

[root@CentOS2 /root]# edquota -u ccna

 




      1 Disk quotas for user ccna (uid 502):
      2   Filesystem                   blocks       soft       hard     inodes     soft     hard
      3   /dev/sdc1                        16          0          0          8        0        0
 
 


 

 

 - 테스트를 하기 위해서 다음과 같이 수정한다.

 




      1 Disk quotas for user ccna (uid 502):
      2   Filesystem                   blocks       soft       hard     inodes     soft     hard
      3   /dev/sdc1                        16       10000      15000       9        0        0


: wq!
 


 

 soft limit  : 디스크 사용량 제한(10000 = 10MB)

 hard limit : soft 값보다 크게 설정한다. (15MB)

 inodes : 저장할 수 있는 파일 갯수 제한 (0이면 무제한)

 

 

 - Quota 구성 내용 확인

 

[root@CentOS2 /root]# repquota -u /newhome
*** Report for user quotas on device /dev/sdc1
Block grace time: 7days; Inode grace time: 7days
                             Block limits                       File limits
User            used    soft    hard  grace    used  soft  hard  grace
----------------------------------------------------------------------
root      --      14       0       0              2     0     0
ccna      --      16   10000   15000              8     0     0
ccnp      --      16       0       0              8     0     0
ccie      --      16       0       0              8     0     0


 

 

 - ccna 계정으로 접속하여 Quota 테스트 실시

 

[root@CentOS2 /root]# su - ccna
[ccna@CentOS2 ~]$ mkdir test
[ccna@CentOS2 ~]$ cd test
[ccna@CentOS2 test]$
[ccna@CentOS2 test]$ pwd
/newhome/ccna/test

[ccna@CentOS2 test]$ dd if=/dev/zero of=./testfile1 bs=1024k count=2
2+0 records in
2+0 records out
2097152 bytes (2.1 MB) copied, 0.0181934 s, 115 MB/s

[ccna@CentOS2 test]$ ls
testfile1


[ccna@CentOS2 test]$ cp testfile1 testfile2
[ccna@CentOS2 test]$ cp testfile1 testfile3
[ccna@CentOS2 test]$ cp testfile1 testfile4
[ccna@CentOS2 test]$ cp testfile1 testfile5
sdc1: warning, user block quota exceeded.

[ccna@CentOS2 test]$ cp testfile1 testfile6
[ccna@CentOS2 test]$ cp testfile1 testfile7
[ccna@CentOS2 test]$ cp testfile1 testfile8
sdc1: write failed, user block limit reached.
cp: writing `testfile8': 디스크 할당량이 초과됨

[ccna@CentOS2 test]$ ls -lh testfile*
-rw-rw-r--. 1 ccna ccna 2.0M 2016-02-26 17:16 testfile1
-rw-rw-r--. 1 ccna ccna 2.0M 2016-02-26 17:16 testfile2
-rw-rw-r--. 1 ccna ccna 2.0M 2016-02-26 17:16 testfile3
-rw-rw-r--. 1 ccna ccna 2.0M 2016-02-26 17:16 testfile4
-rw-rw-r--. 1 ccna ccna 2.0M 2016-02-26 17:16 testfile5
-rw-rw-r--. 1 ccna ccna 2.0M 2016-02-26 17:16 testfile6
-rw-rw-r--. 1 ccna ccna 2.0M 2016-02-26 17:16 testfile7
-rw-rw-r--. 1 ccna ccna 636K 2016-02-26 17:16 testfile8



 

[ccna@CentOS2 test]$
[ccna@CentOS2 test]$ exit
logout
[root@CentOS2 /root]#

 

 

 - Quota 보고서 확인


[root@CentOS2 /root]# repquota /newhome | grep ccna
ccna      +-   14999   10000   15000  6days      18     0     0

 

ccna 계정은 0Byte 파일 이외에는 저장할 수 없는 상태이다. 그리고 soft limit를 초과하는 용량에 대해서는 6일간 유효하며, 6일이 경과되기 이전에 용량은 10MB 이하로 되어야하는 상태이다.

 

 

 

 

Ex2) 그룹별 Quota 구성

 

 - 그룹 및 사용자 계정 추가

 

[root@CentOS2 /root]# groupadd qtgroup


[root@CentOS2 /root]# useradd -g qtgroup -d /newhome/qtuser1 qtuser1
[root@CentOS2 /root]# useradd -g qtgroup -d /newhome/qtuser2 qtuser2
[root@CentOS2 /root]# useradd -g qtgroup -d /newhome/qtuser3 qtuser3

[root@CentOS2 /root]# groups qtuser1 qtuser2 qtuser3
qtuser1 : qtgroup
qtuser2 : qtgroup
qtuser3 : qtgroup


 

 

[root@CentOS2 /root]# edquota -g qtgroup




      1 Disk quotas for group qtgroup (gid 505):
      2   Filesystem                   blocks       soft       hard     inodes     soft     hard
      3   /dev/sdc1                        48          0          0         24        0        0

 


 

 

 - 테스트를 하기 위해서 다음과 같이 수정한다.

 




      1 Disk quotas for group qtgroup (gid 505):
      2   Filesystem                   blocks       soft       hard     inodes     soft     hard
      3   /dev/sdc1                        72        30000     40000         18         0        0
 

: wq!
 


 

 

 - Quota 구성 내용 확인

 

[root@CentOS2 /root]# repquota -g /newhome
*** Report for group quotas on device /dev/sdc1
Block grace time: 7days; Inode grace time: 7days
                              Block limits                       File limits
Group           used    soft    hard  grace    used  soft  hard  grace
----------------------------------------------------------------------
root      --      14       0       0              2     0     0
ccna      --   15000       0       0             18     0     0
ccnp      --      16       0       0              8     0     0
ccie      --      16       0       0              8     0     0
qtgroup   --      48   30000   40000             24     0     0


 

 

[root@CentOS2 /root]# repquota -ug /newhome
*** Report for user quotas on device /dev/sdc1
Block grace time: 7days; Inode grace time: 7days
                             Block limits                      File limits
User            used    soft    hard  grace    used  soft  hard  grace
----------------------------------------------------------------------
root      --      14       0       0              2     0     0
ccna      +-   15000   10000   15000  6days      18     0     0
ccnp      --      16       0       0              8     0     0
ccie      --      16       0       0              8     0     0
qtuser1   --      16       0       0              8     0     0
qtuser2   --      16       0       0              8     0     0
qtuser3   --      16       0       0              8     0     0


*** Report for group quotas on device /dev/sdc1
Block grace time: 7days; Inode grace time: 7days
                        Block limits                File limits
Group           used    soft    hard  grace    used  soft  hard  grace
----------------------------------------------------------------------
root      --      14       0       0              2     0     0
ccna      --   15000       0       0             18     0     0
ccnp      --      16       0       0              8     0     0
ccie      --      16       0       0              8     0     0
qtgroup   --      48   30000   40000             24     0     0

 


qtuser1, qtuser2, qtuser3 사용자들은 합쳐서 최대 40MB까지만 사용할 수 있다.

 

 

 

 

Ex3) Quota 삭제

 

[root@CentOS2 /root]# quotaoff -v /newhome
/dev/sdc1 [/newhome]: group quotas turned off
/dev/sdc1 [/newhome]: user quotas turned off



[root@CentOS2 /root]# ls /newhome
aquota.group  aquota.user  ccie  ccna  ccnp  lost+found  qtuser1  qtuser2  qtuser3



[root@CentOS2 /root]# rm /newhome/aquota.user
rm: remove 일반 파일 `/newhome/aquota.user'? y



[root@CentOS2 /root]# rm /newhome/aquota.group
rm: remove 일반 파일 `/newhome/aquota.group'? y



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

 

 

 

 

 - 환경 초기화


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

[root@CentOS2 /root]# groupdel qtgroup


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

 

 

[root@CentOS2 /root]# vi /etc/fstab









  1
  2 #
  3 # /etc/fstab
  4 # Created by anaconda on Wed Feb  3 01:40:21 2016
  5 #
  6 # Accessible filesystems, by reference, are maintained under '/dev/disk'
  7 # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
  8 #
  9 UUID=7c533aa0-0a72-4a94-b076-382622ad8486 /                       ext4    defaults        1 1
 10 UUID=f55d38f2-1434-4107-8aab-3f9ac3cba3b5 /home                   ext4    defaults        1 2
 11 UUID=78b6f307-7ca2-4ae7-b2e5-866f01d64a15 swap                    swap    defaults        0 0
 12 tmpfs                   /dev/shm                tmpfs   defaults        0 0
 13 devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
 14 sysfs                   /sys                    sysfs   defaults        0 0
 15 proc                    /proc                   proc    defaults        0 0
 16 /dev/sdc1               /newhome                ext4    defaults,usrquota,grpquota      1 2   <- 삭제
 

: wq!
 


 


[root@CentOS2 /root]# mount -a


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