Linux LVM的建立及擴充套件
Linux LVM的建立及擴充套件
LVM是 Logical Volume Manager(邏輯卷管理)的簡寫,它是Linux環境下對磁碟分割槽進行管理的一種機制,使用lvm使用者可以在無需停機的情況下方便地調整各個分割槽大小。
LVM使用分層結構,如下圖所示
基本術語
物理卷(Physical Volume,PV)
指磁碟分割槽或從邏輯上與磁碟分割槽具有同樣功能的裝置(如RAID),是LVM的基本儲存邏輯塊,但和基本的物理儲存介質(如分割槽、磁碟等)比較,卻包含有與LVM相關的管理引數。
*卷組(Volume Group,VG)
類似於非LVM系統中的物理磁碟,其由一個或多個物理卷PV組成。可以在卷組上建立一個或多個
*邏輯卷(Logical Volume,LV)
類似於非LVM系統中的磁碟分割槽,邏輯卷建立在卷組VG之上。在邏輯卷LV之上可以建立檔案系統(比如/home或者/usr等)。
(註釋:基本術語此段摘抄於百度百科)
簡單來說就是:
PV:是物理的磁碟分割槽
VG:LVM中的物理的磁碟分割槽,也就是PV,必須加入VG,可以將VG理解為一個倉庫或者是幾個大的硬碟。
LV:也就是從VG中劃分的邏輯分割槽
如下圖所示PV、VG、LV三者關係:
本文將介紹怎麼在linux中建立和管理LVM卷。
[[email protected] ~]#fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
Sector size (logical/physical): 512 bytes /512 bytes
I/O size (minimum/optimal): 512 bytes / 512bytes
Disk identifier: 0x000eeb02
Device Boot Start End BlocksId System
/dev/sda1* 1 64 51200083 Linux
Partition 1 does not end on cylinderboundary.
/dev/sda2 64 133910240000 83 Linux
/dev/sda3 1339 15942048000 82 Linux swap / Solaris
首先添三塊硬碟,每塊大小為2G,
新增完成後,我們來檢視一下:
[[email protected] ~]#fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
Sector size (logical/physical): 512 bytes /512 bytes
I/O size (minimum/optimal): 512 bytes / 512bytes
Disk identifier: 0x000eeb02
Device Boot Start End BlocksId System
/dev/sda1* 1 64 51200083 Linux
Partition 1 does not end on cylinderboundary.
/dev/sda2 64 133910240000 83 Linux
/dev/sda3 1339 15942048000 82 Linux swap / Solaris
Disk /dev/sdd: 2147MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
Sector size (logical/physical): 512 bytes /512 bytes
I/O size (minimum/optimal): 512 bytes / 512bytes
Disk identifier: 0x00000000
Disk /dev/sdc: 2147MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
Sector size (logical/physical): 512 bytes /512 bytes
I/O size (minimum/optimal): 512 bytes / 512bytes
Disk identifier: 0x00000000
Disk /dev/sdb: 2147MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
Sector size (logical/physical): 512 bytes /512 bytes
I/O size (minimum/optimal): 512 bytes / 512bytes
Disk identifier: 0x00000000
從上邊的顯示結果可以看出,我們已經新增成功了。
建立物理卷PV
[[email protected]~]# pvcreate /dev/sdb
Physical volume "/dev/sdb"successfully created
[[email protected]~]# pvcreate /dev/sdc
Physical volume "/dev/sdc"successfully created
[[email protected]~]# pvcreate /dev/sdd
Physical volume "/dev/sdd"successfully created
使用pvdisplay命令檢查物理卷的建立情況
[[email protected]~]# pvdisplay
"/dev/sdb" is a new physical volumeof "2.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb
VG Name
PV Size 2.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUIDMAvlCx-FFkq-KnGw-THgz-YZ27-wB31-LD2frW
"/dev/sdc" is a new physical volumeof "2.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdc
VG Name
PV Size 2.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUIDMX1ioY-HSYM-LAmC-fZea-Zccc-qEXG-nkQMUf
"/dev/sdd" is a new physical volumeof "2.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdd
VG Name
PV Size 2.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUIDTQ7aAp-WwIz-sD51-3UoY-lkqM-8v1L-nWYScF
建立卷組VG
接下來我們開始建立卷組VG,名為'volume-group1',使用/dev/sdb, /dev/sdc 和 /dev/sdd3建立。
[[email protected]~]# vgcreate Volume-group1 /dev/sdb /dev/sdc /dev/sdd
Volume group "Volume-group1"successfully created
使用命令vgdisplay驗證卷組
[[email protected]~]# vgdisplay
--- Volume group ---
VGName Volume-group1
System ID
Formatlvm2
Metadata Areas 3
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 3
Act PV 3
VG Size 5.99 GiB
PE Size 4.00 MiB
Total PE 1533
Alloc PE / Size 0 / 0
FreePE / Size 1533 / 5.99 GiB
VG UUID 9sCwZQ-uFpc-EcSA-c1Jw-BZ75-RRtg-EWaDam
從輸出中,我們可以看見卷組的使用量/總量。物理卷給卷組提供空間。只要在這個卷組中還有可用空間,我們就可以隨意建立邏輯卷。
建立邏輯卷LV
建立一個名為' lv1'、大小為100MB的邏輯卷
[[email protected] ~]# lvcreate -L 500M -n lv1 Volume-group1
Logicalvolume "lv1" created
[[email protected] ~]# lvdisplay
---Logical volume ---
LVPath /dev/Volume-group1/lv1
LVName lv1
VGName Volume-group1
LVUUID2VZ8nz-oSkQ-dBYS-6Okj-OxsR-ctZo-6Yvr8n
LV WriteAccess read/write
LVCreation host, time localhost.localdomain, 2016-01-21 21:59:10 +0800
LV Status available
#open 0
LVSize 500.00 MiB
CurrentLE 125
Segments 1
Allocation inherit
Readahead sectors auto
-currently set to 256
Blockdevice 253:0
現在邏輯卷已經準備好了,我們可以格式化和掛載邏輯卷,就像其它ext2/3/4分割槽一樣.
[[email protected] ~]# mkfs.ext4 /dev/Volume-group1/lv1
mke2fs 1.41.12 (17-May-2010)
檔案系統標籤=
作業系統:Linux
塊大小=1024 (log=0)
分塊大小=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
128016 inodes, 512000 blocks
25600 blocks (5.00%) reserved for the super user
第一個資料塊=1
Maximum filesystem blocks=67633152
63 block groups
8192 blocks per group, 8192 fragments per group
2032 inodes per group
Superblock backups stored on blocks:
8193,24577, 40961, 57345, 73729, 204801, 221185, 401409
正在寫入inode表: 完成
Creating journal (8192 blocks): 完成
Writing superblocks and filesystem accountinginformation: 完成
This filesystem will be automatically checkedevery 29 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[[email protected] ~]# mkdir /lvm-mount
[[email protected] ~]# mount /dev/Volume-group1/lv1 /lvm-mount/
一旦邏輯卷掛載,我們就可以到掛載點 /lvm-mount/ 上讀寫了。
[[email protected] ~]# cd /lvm-mount/
[[email protected] lvm-mount]# ll
總用量 12
drwx------. 2 root root 12288 1月 21 22:05lost+found
[[email protected] lvm-mount]# touch cheshi.txt
[[email protected] lvm-mount]# mkdir ceshi
[[email protected] lvm-mount]# ll
總用量 15
drwxr-xr-x. 2 root root 1024 1月 21 22:08 ceshi
-rw-r--r--. 1 root root 0 1月 21 22:08 cheshi.txt
drwx------. 2 root root 12288 1月 21 22:05lost+found
擴充套件一個lvm卷
調整邏輯卷大小的功能是LVM最有用的功能。這個部分會討論我們怎麼樣擴充套件一個存在的邏輯卷。下面,我們將會擴充套件先前建立的邏輯卷‘lv1’擴大到800MB。
[[email protected] ~]# lvextend -L +300M /dev/Volume-group1/lv1
Extending logical volume lv1 to 800.00 MiB
Logical volume lv1 successfully resized
[[email protected] ~]# lvdisplay
--- Logical volume ---
LV Path /dev/Volume-group1/lv1
LV Name lv1
VG Name Volume-group1
LV UUID2VZ8nz-oSkQ-dBYS-6Okj-OxsR-ctZo-6Yvr8n
LV Write Access read/write
LV Creation host, time localhost.localdomain,2016-01-21 21:59:10 +0800
LV Status available
# open 1
LV Size 800.00 MiB
Current LE 200
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
轉載於:https://blog.51cto.com/aihua/1737478