LVM 구성
.서버 버전: Ubuntu 14.04
작업 단계:
구성 작성 --
root@TESTLVM:~# fdisk/dev/sdb Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabelBuilding a new DOS disklabel with disk identifier 0x7ef20d7d.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)Command (m for help): nPartition type: p primary (0 primary, 0 extended, 4 free) e extendedSelect (default p): p Partition number (1-4, default 1): Using default value 1First sector (2048-2097151999, default 2048): Using default value 2048Last sector,+ sectors or + size {K, M, G}(2048-2097151999, default 2097151999): Using default value 2097151999Command(m for help): t # 섹션 형식Selected partition 1Hex code(type L to list codes): 8e #8e는 LVMchanged 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.
2. 위의 절차에 따라 순서대로 세 개의 디스크를 구역별로 나누고 구역이 완성된 후에 아래 명령을 실행하여 구역표를 효력을 발생시킨다
root@TESTLVM:~#partprobe
3.PV, VG, LV 생성
PV 생성
root@TESTLVM:~#pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created
root@TESTLVM:~# pvdisplay # PV
"/dev/sdb1" is a new physical volume of "1000.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size 1000.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID hFRN1p-0q7V-oWdy-fflG-qk2Z-iO8I-mIPsI6
VG 생성
root@TESTLVM:~# vgcreate VolGroup01 /dev/sdb1
Volume group "VolGroup00" successfully created
# vg
root@TESTLVM:~# vgdisplay
--- Volume group ---
VG Name VolGroup00
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 1000.00 GiB
PE Size 4.00 MiB
Total PE 255999
Alloc PE / Size 0 / 0
Free PE / Size 255999 / 1000.00 GiB
VG UUID EMzPOw-TSdS-aT61-g1aA-paSy-Q0Gt-NflwdM
LV 생성(L-크기, -n LV 이름 VG 이름)root@TESTLVM:~# lvcreate -L 999G -n lvdata VolGroup01
Logical volume "lvdata" created
# LV
root@TESTLVM:~# lvdisplay
--- Logical volume ---
LV Path /dev/VolGroup00/lvdate
LV Name lvdate
VG Name VolGroup00
LV UUID Gdxczp-QWNe-UA1m-4dZx-AUjK-6DsU-4dCOO7
LV Write Access read/write
LV Creation host, time TESTLVM, 2016-05-06 12:17:05 +0800
LV Status available
# open 1
LV Size 999.00 GiB
Current LE 255744
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 252:2
4.포맷 및 마운트
root@TESTLVM:~# mkfs -t ext4 /dev/VolGroup00/lvdate
mke2fs 1.42.9 (4-Feb-2014)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
65470464 inodes, 261881856 blocks
13094092 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
7992 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, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000, 214990848
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
root@TESTLVM:~# mount /dev/VolGroup00/lvdate test/
root@TESTLVM:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 58G 1.3G 54G 3% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
udev 989M 4.0K 989M 1% /dev
tmpfs 200M 572K 200M 1% /run
none 5.0M 0 5.0M 0% /run/lock
none 1000M 0 1000M 0% /run/shm
none 100M 0 100M 0% /run/user
/dev/sda1 236M 37M 188M 17% /boot
/dev/mapper/VolGroup00-lvdate 984G 72M 934G 1% /root/test
5. 시스템 시작 시 LV 마운트
편집/etc/fstab (아래 내용을 끝까지 추가)
/dev/VolGroup00/lvdate /root/test ext4 defaults 1 2
용량 확장:
root@TESTLVM:~# pvcreate /dev/sdc1
Physical volume "/dev/sdc1" successfully created
root@TESTLVM:~# vgextend VolGroup00 /dev/sdc1
Volume group "VolGroup00" successfully extended
root@TESTLVM:~# lvextend -L +999G /dev/VolGroup00/lvdate
Extending logical volume lvdate to 1.95 TiB
Logical volume lvdate successfully resized
root@TESTLVM:~# resize2fs /dev/VolGroup00/lvdate
resize2fs 1.42.9 (4-Feb-2014)
Filesystem at /dev/VolGroup00/lvdate is mounted on /root/test; on-line resizing required
old_desc_blocks = 63, new_desc_blocks = 125
The filesystem on /dev/VolGroup00/lvdate is now 523763712 blocks long.
root@TESTLVM:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/ubuntu--vg-root 58G 1.3G 54G 3% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
udev 989M 4.0K 989M 1% /dev
tmpfs 200M 572K 200M 1% /run
none 5.0M 0 5.0M 0% /run/lock
none 1000M 0 1000M 0% /run/shm
none 100M 0 100M 0% /run/user
/dev/sda1 236M 37M 188M 17% /boot
/dev/mapper/VolGroup00-lvdate 2.0T 71M 1.9T 1% /root/test
#
삭제 작업:
#
root@TESTLVM:~# umount test/
root@TESTLVM:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/ubuntu--vg-root 58G 1.3G 54G 3% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
udev 989M 4.0K 989M 1% /dev
tmpfs 200M 572K 200M 1% /run
none 5.0M 0 5.0M 0% /run/lock
none 1000M 0 1000M 0% /run/shm
none 100M 0 100M 0% /run/user
/dev/sda1 236M 37M 188M 17% /boot
# LV
root@TESTLVM:~# lvremove /dev/VolGroup00/lvdate
Do you really want to remove and DISCARD active logical volume lvdate? [y/n]: y
Logical volume "lvdate" successfully removed
# VG
root@TESTLVM:~# vgremove VolGroup00
Volume group "VolGroup00" successfully removed
# pv
root@TESTLVM:~# pvremove /dev/sdb1
Labels on physical volume "/dev/sdb1" successfully wiped
root@TESTLVM:~# pvremove /dev/sdc1
Labels on physical volume "/dev/sdc1" successfully wiped