LVMを使ってみた

Pocket

環境

[root@n54l ~]# cat /etc/redhat-release 
CentOS release 6.7 (Final)

[root@n54l ~]# uname -a
Linux n54l 2.6.32-573.7.1.el6.x86_64 #1 SMP Tue Sep 22 22:00:00 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

LVMパーティションの作成
既存のLinux filesystemは消す

[root@n54l ~]# gdisk /dev/sde
GPT fdisk (gdisk) version 0.8.10

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): p
Disk /dev/sde: 1953525168 sectors, 931.5 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 2A1F05A5-51D7-4024-886D-8024AE096053
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 1953525134
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048      1953525134   931.5 GiB   8300  Linux filesystem

Command (? for help): d
Using 1

Command (? for help): 

Command (? for help): p
Disk /dev/sde: 1953525168 sectors, 931.5 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 2A1F05A5-51D7-4024-886D-8024AE096053
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 1953525134
Partitions will be aligned on 2048-sector boundaries
Total free space is 1953525101 sectors (931.5 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name

Command (? for help): o
This option deletes all partitions and creates a new protective MBR.
Proceed? (Y/N): Y

Command (? for help): 

Command (? for help): p
Disk /dev/sde: 1953525168 sectors, 931.5 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): C874634A-0A8E-4967-9ADB-2C1CBF2A66DB
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 1953525134
Partitions will be aligned on 2048-sector boundaries
Total free space is 1953525101 sectors (931.5 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name

Command (? for help): p
Disk /dev/sde: 1953525168 sectors, 931.5 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): C874634A-0A8E-4967-9ADB-2C1CBF2A66DB
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 1953525134
Partitions will be aligned on 2048-sector boundaries
Total free space is 1953525101 sectors (931.5 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name

Command (? for help): n
Partition number (1-128, default 1): 
First sector (34-1953525134, default = 2048) or {+-}size{KMGTP}: 
Last sector (2048-1953525134, default = 1953525134) or {+-}size{KMGTP}: 
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): L
0700 Microsoft basic data  0c01 Microsoft reserved    2700 Windows RE          
3000 ONIE boot             3001 ONIE config           4100 PowerPC PReP boot   
4200 Windows LDM data      4201 Windows LDM metadata  7501 IBM GPFS            
7f00 ChromeOS kernel       7f01 ChromeOS root         7f02 ChromeOS reserved   
8200 Linux swap            8300 Linux filesystem      8301 Linux reserved      
8302 Linux /home           8400 Intel Rapid Start     8e00 Linux LVM           
a500 FreeBSD disklabel     a501 FreeBSD boot          a502 FreeBSD swap        
a503 FreeBSD UFS           a504 FreeBSD ZFS           a505 FreeBSD Vinum/RAID  
a580 Midnight BSD data     a581 Midnight BSD boot     a582 Midnight BSD swap   
a583 Midnight BSD UFS      a584 Midnight BSD ZFS      a585 Midnight BSD Vinum  
a800 Apple UFS             a901 NetBSD swap           a902 NetBSD FFS          
a903 NetBSD LFS            a904 NetBSD concatenated   a905 NetBSD encrypted    
a906 NetBSD RAID           ab00 Apple boot            af00 Apple HFS/HFS+      
af01 Apple RAID            af02 Apple RAID offline    af03 Apple label         
af04 AppleTV recovery      af05 Apple Core Storage    be00 Solaris boot        
bf00 Solaris root          bf01 Solaris /usr & Mac Z  bf02 Solaris swap        
bf03 Solaris backup        bf04 Solaris /var          bf05 Solaris /home       
bf06 Solaris alternate se  bf07 Solaris Reserved 1    bf08 Solaris Reserved 2  
bf09 Solaris Reserved 3    bf0a Solaris Reserved 4    bf0b Solaris Reserved 5  
c001 HP-UX data            c002 HP-UX service         ea00 Freedesktop $BOOT   
eb00 Haiku BFS             ed00 Sony system partitio  ed01 Lenovo system partit
Press the <Enter> key to see more codes: 8e00
ef00 EFI System            ef01 MBR partition scheme  ef02 BIOS boot partition 
fb00 VMWare VMFS           fb01 VMWare reserved       fc00 VMWare kcore crash p
fd00 Linux RAID            
Hex code or GUID (L to show codes, Enter = 8300): p
Hex code or GUID (L to show codes, Enter = 8300): 8e00 
Changed type of partition to 'Linux LVM'

Command (? for help): p
Disk /dev/sde: 1953525168 sectors, 931.5 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): C874634A-0A8E-4967-9ADB-2C1CBF2A66DB
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 1953525134
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048      1953525134   931.5 GiB   8E00  Linux LVM

Command (? for help): 

Command (? for help): 

Command (? for help): p
Disk /dev/sde: 1953525168 sectors, 931.5 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): C874634A-0A8E-4967-9ADB-2C1CBF2A66DB
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 1953525134
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048      1953525134   931.5 GiB   8E00  Linux LVM

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): Y
OK; writing new GUID partition table (GPT) to /dev/sde.
The operation has completed successfully.
[root@n54l ~]# 

VGの作成

LVMパーティションをPVとして定義

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

次にVGを作成します。
VGの名前をvg00(名前は任意の名前でかまわない)、PEのサイズは
16MB=1TB(16*65536) 32MB=2TBなので今回は2TBにしようと思う

持てるPE数には上限があり、最大65,536個まで
PEの容量で小分けに分割されてそれらがLVに保存されるっぽい

値が大きすぎると無駄がでてきたりパフォーマンスに問題がでるらしい

[root@n54l ~]# vgcreate -s32m vg00 /dev/sde1 
  Volume group "vg00" successfully created

確認

[root@n54l ~]# vgdisplay
  --- Volume group ---
  VG Name               vg00
  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               931.50 GiB
  PE Size               32.00 MiB
  Total PE              29808
  Alloc PE / Size       0 / 0   
  Free  PE / Size       29808 / 931.50 GiB
  VG UUID               YUgik2-fDUF-Kth4-f6FL-ZHaL-4pKe-WkyNJQ

  --- Volume group ---
  VG Name               vg_n54l
  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               13.95 GiB
  PE Size               4.00 MiB
  Total PE              3571
  Alloc PE / Size       3571 / 13.95 GiB
  Free  PE / Size       0 / 0   
  VG UUID               y72IAb-1Wyt-TgF2-m7Z4-LuYY-nGd5-fj71xS

1つのPVを1つのVGに割り当てましたが、複数のPVをVGに割り当てることでVGの拡張が可能になります。

LVの作成

構成

LV name size
lv00    500GB
lv01    300GB
lv02    100GB

コマンド

[root@n54l ~]# lvcreate -nlv00 -L500g vg00
  Logical volume "lv00" created.
[root@n54l ~]# lvcreate -nlv01 -L300g vg00
  Logical volume "lv01" created.
[root@n54l ~]# lvcreate -nlv02 -L100g vg00
  Logical volume "lv02" created.
[root@n54l ~]# 

確認

[root@n54l ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/vg00/lv00
  LV Name                lv00
  VG Name                vg00
  LV UUID                Iy1OZo-zjFf-QwkK-wute-9isl-CpfG-jrM1Ca
  LV Write Access        read/write
  LV Creation host, time n54l, 2015-10-30 18:01:12 +0900
  LV Status              available
  # open                 0
  LV Size                500.00 GiB
  Current LE             16000
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2

  --- Logical volume ---
  LV Path                /dev/vg00/lv01
  LV Name                lv01
  VG Name                vg00
  LV UUID                DlKMv9-x364-UVzl-Hf2o-NGBB-0WCG-r67dSy
  LV Write Access        read/write
  LV Creation host, time n54l, 2015-10-30 18:01:18 +0900
  LV Status              available
  # open                 0
  LV Size                300.00 GiB
  Current LE             9600
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:3

  --- Logical volume ---
  LV Path                /dev/vg00/lv02
  LV Name                lv02
  VG Name                vg00
  LV UUID                6gOaKA-VeXR-DQ3C-CyUl-Rj0E-Rh6O-KurusT
  LV Write Access        read/write
  LV Creation host, time n54l, 2015-10-30 18:01:18 +0900
  LV Status              available
  # open                 0
  LV Size                100.00 GiB
  Current LE             3200
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:4

  --- Logical volume ---
  LV Path                /dev/vg_n54l/lv_root
  LV Name                lv_root
  VG Name                vg_n54l
  LV UUID                E6UHup-pXWk-17nB-v7Tp-eyXu-XRqS-TLtOr8
  LV Write Access        read/write
  LV Creation host, time n54l, 2015-06-10 22:33:56 +0900
  LV Status              available
  # open                 1
  LV Size                10.20 GiB
  Current LE             2611
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/vg_n54l/lv_swap
  LV Name                lv_swap
  VG Name                vg_n54l
  LV UUID                6BfRmA-cvMo-nIn9-Pcbk-I5pt-mG42-J1ZK0w
  LV Write Access        read/write
  LV Creation host, time n54l, 2015-06-10 22:35:24 +0900
  LV Status              available
  # open                 1
  LV Size                3.75 GiB
  Current LE             960
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

[root@n54l ~]# 

Vol00が足りなくなった時に追加する分が欲しいので先に
/dev/vg00/lv02を削除することにした

[root@n54l ~]# lvremove /dev/vg00/lv02
Do you really want to remove active logical volume lv02? [y/n]: y
  Logical volume "lv02" successfully removed

構成

LV name size
lv00    500GB
lv01    300GB

ファイルシステムの設定

どちらもxfsで設定します。

[root@n54l ~]# mkfs.xfs /dev/vg00/lv0
lv00  lv01  
[root@n54l ~]# mkfs.xfs /dev/vg00/lv00 
meta-data=/dev/vg00/lv00         isize=256    agcount=16, agsize=8192000 blks
         =                       sectsz=4096  attr=2, projid32bit=0
data     =                       bsize=4096   blocks=131072000, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0
log      =internal log           bsize=4096   blocks=64000, version=2
         =                       sectsz=4096  sunit=1 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@n54l ~]# 
[root@n54l ~]# 
[root@n54l ~]# 
[root@n54l ~]# mkfs.xfs /dev/vg00/lv01
meta-data=/dev/vg00/lv01         isize=256    agcount=16, agsize=4915200 blks
         =                       sectsz=4096  attr=2, projid32bit=0
data     =                       bsize=4096   blocks=78643200, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0
log      =internal log           bsize=4096   blocks=38400, version=2
         =                       sectsz=4096  sunit=1 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@n54l ~]# 

mount

mountする場所を作る

[root@n54l ~]# mkdir -p /vg00/lv00
[root@n54l ~]# mkdir -p /vg00/lv01

fstabに書くのを確認

[root@n54l ~]# ls /dev/mapper/
control  vg00-lv00  vg00-lv01  vg_n54l-lv_root  vg_n54l-lv_swap

/etc/fstabに追記してmountする

[root@n54l ~]# tail -n 2 /etc/fstab
/dev/mapper/vg00-lv00   /vg00/lv00      xfs defaults    0 0
/dev/mapper/vg00-lv01   /vg00/lv01      xfs defaults    0 0


[root@n54l ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_n54l-lv_root
                       10G  4.5G  5.0G  48% /
tmpfs                 1.9G     0  1.9G   0% /dev/shm
/dev/sda1             477M  133M  319M  30% /boot
/dev/sdb1             1.8T  687G  1.1T  40% /hdd1
/dev/sdc1             917G  428G  443G  50% /hdd2
/dev/sdf1             233G   50G  183G  22% /ssd1
/dev/sdd1             932G  772G  161G  83% /hdd3
[root@n54l ~]# mount -a
[root@n54l ~]# 
[root@n54l ~]# 
[root@n54l ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_n54l-lv_root
                       10G  4.5G  5.0G  48% /
tmpfs                 1.9G     0  1.9G   0% /dev/shm
/dev/sda1             477M  133M  319M  30% /boot
/dev/sdb1             1.8T  687G  1.1T  40% /hdd1
/dev/sdc1             917G  428G  443G  50% /hdd2
/dev/sdf1             233G   50G  183G  22% /ssd1
/dev/sdd1             932G  772G  161G  83% /hdd3
/dev/mapper/vg00-lv00
                      500G   33M  500G   1% /vg00/lv00
/dev/mapper/vg00-lv01
                      300G   33M  300G   1% /vg00/lv01
[root@n54l ~]# 
[root@n54l ~]# 

ディスクが足りなくなったりした時の追加手順やスナップショットはまた後日

参考:LVM設定 | engineersLVM設定 | engineersidelineidel

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください