리눅스

리눅스에서 LVM을 사용하여 파일 시스템을 생성하는 방법

변군이글루 2014. 4. 14. 11:48
반응형

리눅스에서 LVM을 사용하여 파일 시스템을 생성하는 방법

LVM을 사용하여 리눅스 시스템에 새로운 물리적인 볼륨(PV), 볼륨 그룹(VG), 논리적인 볼륨(LV)을 만들고 확장하는 절차입니다.

하드 디스크 정보 확인(물리 디스크 확인)

fdisk -l
$ fdisk -l

Disk /dev/sda: 85.9 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 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: 0x0003ee54

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          26      204800   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              26         548     4194304   82  Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3             548       10444    79485952   83  Linux

Disk /dev/sdb: 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: 0x00000000

새로운 파티션 생성

fdisk /dev/sdb
$ 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 0x35784e8c.
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-2610, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610):
Using default value 2610

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.

여기서 새로운 파티션을 생성합니다.

PV(Physical Volume) 생성

  • 새로 생성된 파티션 정보 확인
$ fdisk -l

Disk /dev/sda: 85.9 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 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: 0x0003ee54

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          26      204800   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              26         548     4194304   82  Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3             548       10444    79485952   83  Linux

Disk /dev/sdb: 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: 0x35784e8c

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        2610    20964793+  8e  Linux LVM
  • 물리적 볼륨 생성
pvcreate /dev/sdb1
$ pvcreate /dev/sdb1
  dev_is_mpath: failed to get device for 8:17
  Physical volume "/dev/sdb1" successfully created
  • 물리적 볼륨 스캔 및 정보 표시
pvscan
$ pvscan
  PV /dev/sdb1                      lvm2 [19.99 GiB]
  Total: 1 [19.99 GiB] / in use: 0 [0   ] / in no VG: 1 [19.99 GiB]
pvdisplay
$ pvdisplay
  "/dev/sdb1" is a new physical volume of "19.99 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb1
  VG Name
  PV Size               19.99 GiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               aR1xaU-UMkS-V2Nr-pYnM-RNgE-Qed2-5eOdaG

VG(Volume Group) 생성

  • 볼륨 그룹 생성
vgcreate vg_data01 /dev/sdb1
$ vgcreate vg_data01 /dev/sdb1
  Volume group "vg_data01" successfully created
  • 볼륨 그룹 스캔 및 정보 표시
vgscan
$ vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "vg_data01" using metadata type lvm2
vgdisplay
$ vgdisplay
  --- Volume group ---
  VG Name               vg_data01
  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               19.99 GiB
  PE Size               4.00 MiB
  Total PE              5118
  Alloc PE / Size       0 / 0
  Free  PE / Size       5118 / 19.99 GiB
  VG UUID               MJVUpC-N9HQ-D2Iv-lEes-a3FM-LDcl-BJvQxx
728x90

LV(Logical Volume) 생성

  • 논리적 볼륨 생성
lvcreate -L 19.99G -n lv_data01 vg_data01
$ lvcreate -L 19.99G -n lv_data01 vg_data01
  Rounding up size to full physical extent 19.99 GiB
  Logical volume "lv_data01" created

이 명령은 vg_data01 그룹에서 크기가 19.99GB인 lv_data01 논리적 볼륨을 생성합니다.

 

  • 논리적 볼륨 스캔 및 정보 표시
lvscan
$ lvscan
  ACTIVE            '/dev/vg_data01/lv_data01' [19.99 GiB] inherit
lvdisplay
$ lvdisplay
  --- Logical volume ---
  LV Path                /dev/vg_data01/lv_data01
  LV Name                lv_data01
  VG Name                vg_data01
  LV UUID                p1n4r8-eCnd-efQx-yD3f-aRXP-XUIa-1B5M7q
  LV Write Access        read/write
  LV Creation host, time vm1.scbyun.com, 2014-04-14 11:33:29 +0900
  LV Status              available
  # open                 0
  LV Size                19.99 GiB
  Current LE             5118
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

파일 시스템 생성

mkfs.ext4 /dev/vg_data01/lv_data01
$ mkfs.ext4 /dev/vg_data01/lv_data01
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
1310720 inodes, 5240832 blocks
262041 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
160 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, 2654208,
        4096000

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

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

파일 시스템 마운트

  • 마운트 포인트 생성 및 마운트
mkdir /dataVolume
mount /dev/vg_data01/lv_data01 /dataVolume
  • 마운트 확인
$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3              75G  3.1G   68G   5% /
tmpfs                 936M     0  936M   0% /dev/shm
/dev/sda1             194M   57M  127M  31% /boot
/dev/mapper/vg_data01-lv_data01
                       20G  172M   19G   1% /dataVolume

 /etc/fstab 편집

  • 부팅 시 자동 마운트를 위한 /etc/fstab 업데이트
vim /etc/fstab
  • 다음 라인을 추가
/dev/vg_data01/lv_data01 /dataVolume ext4 defaults 1 2
  • /etc/fstab 확인
$ cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Thu Apr  3 01:22:11 2014
#
# 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/vg_data01/lv_data01 /dataVolume ext4 defaults 1 2

위 명령어는 새로운 파일 시스템을 부팅 시 자동으로 마운트하도록 /etc/fstab 파일을 업데이트합니다.

 

728x90
반응형