이번에는 리눅스에 추가한 하드디스크로 LVM을 만드는걸 포스팅 해본다
먼저 간단하게 요약 해보면 (rhel ver6 기준)
1. 하드디스크 추가
2. 추가한 디스크 파티션을 LVM 타입(8e)으로 생성
3. 물리불륨생성
4. 물리불륨을 불륨그룹에 추가
5. 볼륨그룹에서 논리볼륨으로 다시 할당
6. 포맷(EXT4) 을 한뒤 OS에 마운트
1. 먼저 OS 초기 디스크 상태
| [root@vmsvr-6u8 ~]# df -h Filesystem            Size  Used Avail Use% Mounted on /dev/mapper/vg_vmsvr6u8-lv_root                        18G  3.0G   14G  19% / tmpfs                 491M     0  491M   0% /dev/shm /dev/sda1             477M   35M  418M   8% /boot | cs | 
먼저 OS을 기본으로 설치 하고난 후 상태 df 명령어를 이용하여 확인.
2. fdisk 추가된 하드디스크 확인
| [root@vmsvr-6u8 ~]# fdisk -l Disk /dev/sda: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 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: 0x000ed063    Device Boot      Start         End      Blocks   Id  System /dev/sda1   *           1          64      512000   83  Linux Partition 1 does not end on cylinder boundary. /dev/sda2              64        2611    20458496   8e  Linux LVM Disk /dev/sdb: 8589 MB, 8589934592 bytes 255 heads, 63 sectors/track, 1044 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: 0x00000000 Disk /dev/mapper/vg_vmsvr6u8-lv_root: 18.9 GB, 18865979392 bytes 255 heads, 63 sectors/track, 2293 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: 0x00000000 Disk /dev/mapper/vg_vmsvr6u8-lv_swap: 2080 MB, 2080374784 bytes 255 heads, 63 sectors/track, 252 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: 0x00000000 | cs | 
fdisk -l 명령어를 이용하여 /dev/sdb 하드디스크가 8G 짜리가 추가되어 있는걸 확인 할 수 있다
3. fdisk로 파티션 LVM(8e)타입을 지정
| [root@vmsvr-6u8 ~]# fdisk /dev/sdb Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0x85fdf936. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) 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-1044, default 1): (enter) Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-1044, default 1044): (enter) Using default value 1044 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): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. | cs | 
fdisk를 이용하여 추가된 하드디스크 파티션을 LVM 타입 8e로 구성한다
4. fdisk로 파티션 확인
| [root@vmsvr-6u8 ~]# fdisk -l Disk /dev/sda: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 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: 0x000ed063    Device Boot      Start         End      Blocks   Id  System /dev/sda1   *           1          64      512000   83  Linux Partition 1 does not end on cylinder boundary. /dev/sda2              64        2611    20458496   8e  Linux LVM Disk /dev/sdb: 8589 MB, 8589934592 bytes 255 heads, 63 sectors/track, 1044 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: 0x85fdf936    Device Boot      Start         End      Blocks   Id  System /dev/sdb1               1        1044     8385898+  8e  Linux LVM Disk /dev/mapper/vg_vmsvr6u8-lv_root: 18.9 GB, 18865979392 bytes 255 heads, 63 sectors/track, 2293 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: 0x00000000 Disk /dev/mapper/vg_vmsvr6u8-lv_swap: 2080 MB, 2080374784 bytes 255 heads, 63 sectors/track, 252 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: 0x00000000 | cs | 
생성된 파티션은 뒤에 숫자가 붙어서 /dev/sdb1로 표시 된다
5. 물리볼륨 생성한다 (pvcreate)
| [root@vmsvr-6u8 ~]# pvcreate /dev/sdb1    Physical volume "/dev/sdb1" successfully created [root@vmsvr-6u8 ~]# pvscan    PV /dev/sda2   VG vg_vmsvr6u8     lvm2 [19.51 GiB / 0    free]   PV /dev/sdb1                      lvm2 [8.00 GiB]   Total: 2 [27.51 GiB] / in use: 1 [19.51 GiB] / in no VG: 1 [8.00 GiB] | cs | 
pvcreate [디바이스명] 명령어 형태로 물리볼륨을 생성한다
그후 pvscan 으로 확인을 한다
6. 볼륨그룹에 설정 (vgcreate)
| [root@vmsvr-6u8 ~]# vgcreate Volgroup01 /dev/sdb1           Volume group "Volgroup01" successfully created [root@vmsvr-6u8 ~]# vgdisplay    --- Volume group ---   VG Name               Volgroup01   System ID                Format                lvm2   Metadata Areas        1   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                1   Act PV                1   VG Size               8.00 GiB   PE Size               4.00 MiB   Total PE              2047   Alloc PE / Size       0 / 0      Free  PE / Size       2047 / 8.00 GiB   VG UUID               nq9XJ3-06EY-pq5r-6zCj-sx66-exRB-CwnB0Z   --- Volume group ---   VG Name               vg_vmsvr6u8   System ID                Format                lvm2   Metadata Areas        1   Metadata Sequence No  3   VG Access             read/write   VG Status             resizable   MAX LV                0   Cur LV                2   Open LV               2   Max PV                0   Cur PV                1   Act PV                1   VG Size               19.51 GiB   PE Size               4.00 MiB   Total PE              4994   Alloc PE / Size       4994 / 19.51 GiB   Free  PE / Size       0 / 0      VG UUID               AEEtoW-v37n-2nMi-mmwD-BI1a-VIyN-2ZZs2t | cs | 
vgcreate [볼륨명] [디바이스명] 명령어 형태로 볼륨그룹 생성한다
그후 vgdisplay 으로 확인을 한다 Free PE가 모두 할당 안되어 있는걸 확인 할 수 있다
7. 논리 볼륨을 설정한다 (lvcreate)
| [root@vmsvr-6u8 ~]# lvcreate -l 100%FREE -n data Volgroup01   Logical volume "data" created. [root@vmsvr-6u8 ~]# lvdisplay    --- Logical volume ---   LV Path                /dev/Volgroup01/data   LV Name                data   VG Name                Volgroup01   LV UUID                HS9s91-7fG7-4Xg9-ZIoy-jf9J-VnPR-8gnLWl   LV Write Access        read/write   LV Creation host, time vmsvr-6u8, 2019-04-17 00:07:59 +0900   LV Status              available   # open                 0   LV Size                8.00 GiB   Current LE             2047   Segments               1   Allocation             inherit   Read ahead sectors     auto   - currently set to     256   Block device           253:2   --- Logical volume ---   LV Path                /dev/vg_vmsvr6u8/lv_root   LV Name                lv_root   VG Name                vg_vmsvr6u8   LV UUID                O5kfud-g7QI-3cr9-rPnb-XbD2-f8n6-KxjNql   LV Write Access        read/write   LV Creation host, time vmsvr-6u8, 2019-04-16 19:25:52 +0900   LV Status              available   # open                 1   LV Size                17.57 GiB   Current LE             4498   Segments               1   Allocation             inherit   Read ahead sectors     auto   - currently set to     256   Block device           253:0   --- Logical volume ---   LV Path                /dev/vg_vmsvr6u8/lv_swap   LV Name                lv_swap   VG Name                vg_vmsvr6u8   LV UUID                IMWRXK-eYbr-I75B-eT0A-2hwG-hKBg-Mxptdy   LV Write Access        read/write   LV Creation host, time vmsvr-6u8, 2019-04-16 19:25:59 +0900   LV Status              available   # open                 1   LV Size                1.94 GiB   Current LE             496   Segments               1   Allocation             inherit   Read ahead sectors     auto   - currently set to     256   Block device           253:1 [root@vmsvr-6u8 ~]# vgdisplay    --- Volume group ---   VG Name               Volgroup01   System ID                Format                lvm2   Metadata Areas        1   Metadata Sequence No  2   VG Access             read/write   VG Status             resizable   MAX LV                0   Cur LV                1   Open LV               0   Max PV                0   Cur PV                1   Act PV                1   VG Size               8.00 GiB   PE Size               4.00 MiB   Total PE              2047   Alloc PE / Size       2047 / 8.00 GiB   Free  PE / Size       0 / 0      VG UUID               nq9XJ3-06EY-pq5r-6zCj-sx66-exRB-CwnB0Z   --- Volume group ---   VG Name               vg_vmsvr6u8   System ID                Format                lvm2   Metadata Areas        1   Metadata Sequence No  3   VG Access             read/write   VG Status             resizable   MAX LV                0   Cur LV                2   Open LV               2   Max PV                0   Cur PV                1   Act PV                1   VG Size               19.51 GiB   PE Size               4.00 MiB   Total PE              4994   Alloc PE / Size       4994 / 19.51 GiB   Free  PE / Size       0 / 0      VG UUID               AEEtoW-v37n-2nMi-mmwD-BI1a-VIyN-2ZZs2t | cs | 
lvcreate -l [size] -n [논리볼륨명] [볼륨명]
lvcreate 명령어를 사용하여 -l (PE 개수) -L (용량) 옵션으로 디스크를 용량을 지정 할 수 있다
vgdisplay 명령어로 Free Pe 가 0으로 용량 모두 할당 된것을 확인 할 수 있다
8. 파일시스템 포맷 및 마운트
| [root@vmsvr-6u8 ~]# mkfs.ext4 /dev/Volgroup01/data mke2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 524288 inodes, 2096128 blocks 104806 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2147483648 64 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks:          32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632 Writing inode tables: done                             Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 22 mounts or 180 days, whichever comes first.  Use tune2fs -c or -i to override. [root@vmsvr-6u8 ~]# mount /dev/Volgroup01/data /data [root@vmsvr-6u8 ~]# df -h Filesystem            Size  Used Avail Use% Mounted on /dev/mapper/vg_vmsvr6u8-lv_root                        18G  3.0G   14G  19% / tmpfs                 491M     0  491M   0% /dev/shm /dev/sda1             477M   35M  418M   8% /boot /dev/mapper/Volgroup01-data                       7.8G   18M  7.4G   1% /data | cs | 
mkfs.ext4 [LV PATH] (아직까지 난 EXT4가 가장 맘에 든다)
mount [LV PATH] [지정디렉토리]
ext4로 포맷후 마운트할 디렉토리에 마운트 하면 끝!
9 자동마운트를 위해 fstab에 추가
| [root@vmsvr-6u8 ~]# vi /etc/fstab  # # /etc/fstab # Created by anaconda on Tue Apr 16 19:26:28 2019 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # /dev/mapper/vg_vmsvr6u8-lv_root /                       ext4    defaults        1 1 UUID=0f7adb3a-6bcb-4512-b812-e32c5e8140ed /boot         ext4    defaults        1 2 /dev/mapper/vg_vmsvr6u8-lv_swap swap                    swap    defaults        0 0 tmpfs                   /dev/shm                        tmpfs   defaults        0 0 devpts                  /dev/pts                        devpts  gid=5,mode=620  0 0 sysfs                   /sys                            sysfs   defaults        0 0 proc                    /proc                           proc    defaults        0 0 /dev/mapper/Volgroup01-data              /data          ext4    defaults        1 2 | cs | 
서버가 부팅이 되어도 자동으로 마운트 되기 위해 /etc/fstab 에 추가한다
/dev/mapper/Volgroup01-data /data ext4 defaults 1 2
일단 여기까지 나중에 명령어 별로 옵션 및 논리볼륨 증설 및 제거 하는걸 추가!!

