歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> LVM創建實例講解

LVM創建實例講解

日期:2017/2/28 14:36:00   编辑:Linux教程

LVM講解:
圖像大綱:

1)LVM是什麼,作用:
LVM稱為邏輯卷管理,作用是提高磁盤分區的管理和使用靈活性。
通過邏輯卷LVM可以有效的管理和分配磁盤空間,可以把分散的小分區組合成一個大的卷組,從卷組中分出需要的空間做出邏輯卷,這樣使得磁盤擴容和縮減方便易用。還有著備份的功能,指的就是lvm快照。
2)創建實例:
磁盤-》分區-》ID修改8e-》保存。
我用來一個磁盤通過分區來做的。還可以每個磁盤分一個區來做。
Device Boot Start End Blocks Id System
/dev/sdb1 1 1306 10490413+ 8e Linux LVM
/dev/sdb2 1307 2612 10490445 8e Linux LVM
/dev/sdb3 2613 3918 10490445 8e Linux LVM

3)創建物理卷:通過pvcreate命令。
pvcreate /dev/sdb1
pvcreate /dev/sdb2
pvcreate /dev/sdb3
[root@station106 ~]# pvs(查看創建的物理卷)。
PV VG Fmt Attr PSize PFree
/dev/sda2 vg0 lvm2 a-- 59.99g 7.99g
/dev/sdb1 lvm2 a-- 10.00g 10.00g
/dev/sdb2 lvm2 a-- 10.00g 10.00g
/dev/sdb3 lvm2 a-- 10.00g 10.00g
pvdisplay 查看更加詳細的內容。


[root@station106 ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sdb1
VG Name myvg
PV Size 10.00 GiB / not usable 4.54 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 2560
Free PE 2560
Allocated PE 0
PV UUID XP8QfA-WQDd-1v9p-QKxk-AztZ-Nr9e-QbN6Gu
--- Physical volume ---
PV Name /dev/sdb2
VG Name myvg
PV Size 10.00 GiB / not usable 4.58 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 2560
Free PE 2560
Allocated PE 0
PV UUID f8Dtdd-fV9e-1yB7-1B8P-21mU-CU2f-fQDAxe
--- Physical volume ---
PV Name /dev/sdb3
VG Name myvg
PV Size 10.00 GiB / not usable 4.58 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 2560
Free PE 2560
Allocated PE 0
PV UUID rKNL0x-WXq2-gHYD-T27r-Gf05-a4y3-f4zqzt

4)創建邏輯卷:通過vgcreate。
[root@station106 ~]# vgcreate myvg /dev/sdb{1,2,3}
Volume group "myvg" successfully created

[root@station106 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
myvg 3 0 0 wz--n- 30.00g 30.00g

5)創建邏輯卷,lvcreate。
[root@station106 ~]# lvcreate -L 10G -n test myvg
Logical volume "test" created
-L:空間大小。
-n:邏輯卷名稱。
[root@station106 ~]# lvdisplay /dev/myvg/test
--- Logical volume ---
LV Path /dev/myvg/test
LV Name test
VG Name myvg
LV UUID wY1YUF-f0o6-jzu1-mtTL-64p0-qvfC-3QfF8y
LV Write Access read/write
LV Creation host, time station106.magelinux.com, 2014-02-10 11:18:43 +0800
LV Status available
# open 0
LV Size 10.00 GiB
Current LE 2560
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:4

6)掛載使用創建好的邏輯卷。
mke2fs -t ext4 /dev/myvg/test 格式化。
mount /dev/myvg/test /mnt/掛載使用。

7)假如有一天邏輯卷不夠用了。怎麼從卷組擴展呢?如下分析。
邏輯卷擴展的大致步驟:
1,先確定擴展的大小,並確保所屬的卷組有足夠的剩余空間。
我現在要擴展5G,本身是10G的大小。命令如下:
[root@station106 ~]# lvextend -L +5G /dev/myvg/test
Extending logical volume test to 15.00 GiB
Logical volume test successfully resized

2,擴展物理邊界。物理邊界指的是本身的物理邊緣大小。
[root@station106 ~]# lvdisplay /dev/myvg/test
--- Logical volume ---
LV Path /dev/myvg/test
LV Name test
VG Name myvg
LV UUID wY1YUF-f0o6-jzu1-mtTL-64p0-qvfC-3QfF8y
LV Write Access read/write
LV Creation host, time station106.magelinux.com, 2014-02-10 11:18:43 +0800
LV Status available
# open 1
LV Size 15.00 GiB
Current LE 3840
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:4

當擴展完物理邊界後你會發現,掛載中的邏輯卷還是本身的大小。
[root@station106 ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg0-root
ext4 20G 387M 19G 3% /
tmpfs tmpfs 242M 0 242M 0% /dev/shm
/dev/sda1 ext4 194M 29M 156M 16% /boot
/dev/mapper/vg0-usr
ext4 9.9G 1.9G 7.6G 20% /usr
/dev/mapper/vg0-var
ext4 20G 288M 19G 2% /var
/dev/mapper/myvg-test
ext4 9.9G 151M 9.2G 2% /mnt

擴展邏輯邊界,邏輯邊界指的是掛載後,在使用中的邏輯卷也直接識別了。
[root@station106 ~]# resize2fs /dev/myvg/test
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/myvg/test is mounted on /mnt; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/myvg/test to 3932160 (4k) blocks.
The filesystem on /dev/myvg/test is now 3932160 blocks long.
[root@station106 ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg0-root
ext4 20G 387M 19G 3% /
tmpfs tmpfs 242M 0 242M 0% /dev/shm
/dev/sda1 ext4 194M 29M 156M 16% /boot
/dev/mapper/vg0-usr
ext4 9.9G 1.9G 7.6G 20% /usr
/dev/mapper/vg0-var
ext4 20G 288M 19G 2% /var
/dev/mapper/myvg-test
ext4 15G 153M 14G 2% /mnt

上述就是擴展邏輯卷部分。

推薦閱讀:

VMware上安裝Oracle 10g RAC-ASM+裸設備 http://www.linuxidc.com/Linux/2013-03/80834.htm

AIX上用裸設備安裝Oracle http://www.linuxidc.com/Linux/2012-11/74869.htm

Oracle for AIX基於裸設備的表空間擴充步聚 http://www.linuxidc.com/Linux/2012-10/71599.htm

Copyright © Linux教程網 All Rights Reserved