對LVM的詳細介紹: LVM(Logical Volume Manager)就是邏輯卷管理器,它將多個物理分區整合在一起,讓這些分區看起來像一個磁片一樣,第一就是實現系統快照,這樣就可以是備份和還原就變的很簡單。另一個作用是實現一個可以彈性調整容量的檔系統;下麵來我們分別詳細說明LVM這兩個重要作用
二、邏輯卷(LV)的擴展和縮減
1、將/dev/sda5製作成LV。其步驟如下:
(1)創建分區並將其卷標改為8e。
[root@localhost ~]# fdisk /dev/sda
The number of cylinders for this disk is set to 15665.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): n
First cylinder (5367-15665, default 5367):
Using default value 5367
Last cylinder or +size or +sizeM or +sizeK (5367-15665, default 15665): +10G
Command (m for help): t
Partition number (1-5): 5
Hex code (type L to list codes): 8e
Changed system type of partition 5 to 8e (Linux LVM)
Command (m for help): n
First cylinder (6584-15665, default 6584):
Using default value 6584
Last cylinder or +size or +sizeM or +sizeK (6584-15665, default 15665): +5G
Command (m for help): t
Partition number (1-6): 6
Hex code (type L to list codes): 8e
Changed system type of partition 6 to 8e (Linux LVM)
Command (m for help): p
Disk /dev/sda: 128.8 GB, 128849018880 bytes
255 heads, 63 sectors/track, 15665 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 5235 41945715 8e Linux LVM
/dev/sda3 5236 5366 1052257+ 82 Linux swap / Solaris
/dev/sda4 5367 15665 82726717+ 5 Extended
/dev/sda5 5367 6583 9775521 8e Linux LVM
/dev/sda6 6584 7192 4891761 8e Linux LVM
Command (m for help): w
以上創建了兩個分區/dev/sda5和/dev/sda6其卷標都為8e
(2)將/dev/sda5創建成pv(物理卷)。
[root@localhost ~]# pvcreate /dev/sda5
Writing physical volume data to disk "/dev/sda5"
Physical volume "/dev/sda5" successfully created
[root@localhost ~]# pvdisplay /dev/sda5
"/dev/sda5" is a new physical volume of "9.32 GB"
--- NEW Physical volume ---
PV Name /dev/sda5
VG Name
PV Size 9.32 GB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID X1mEFY-Hk3e-LT10-ori0-Dpz9-2ucd-VktkXg
(3)將/dev/sda5創建卷組myvg。
[root@localhost ~]# vgcreate myvg1 /dev/sda5
Volume group "myvg1" successfully created
[root@localhost ~]# vgdisplay myvg1
--- Volume group ---
VG Name myvg1
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 9.32 GB
PE Size 4.00 MB
Total PE 2386
Alloc PE / Size 0 / 0
Free PE / Size 2386 / 9.32 GB
VG UUID wHo82H-hk3K-gK8j-vMY3-X83q-Fcof-SqT88x
(4)在myvg1上創建創建2G的LV(邏輯卷)。
[root@localhost ~]# lvcreate -L 2G -n mylv1 myvg1
Logical volume "mylv1" created
[root@localhost ~]# lvdisplay /dev/myvg1/mylv1
--- Logical volume ---
LV Name /dev/myvg1/mylv1
VG Name myvg1
LV UUID HIVsSx-X318-RbZl-fcTs-jy82-I59N-1Z4pre
LV Write Access read/write
LV Status available
# open 0
LV Size 2.00 GB
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:3
這樣一個邏輯卷就創建成功了。
2、放大LV的容量。
放大LV要先擴展卷組的容量,再來擴展
[root@localhost ~]# pvcreate /dev/sda7
Writing physical volume data to disk "/dev/sda7"
Physical volume "/dev/sda7" successfully created
[root@localhost ~]# vgextend myvg1 /dev/sda7
Volume group "myvg1" successfully extended
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
myvg 1 1 0 wz--n- 4.66G 3.66G
myvg1 2 1 0 wz--n- 14.91G 12.91G
vol0 1 2 0 wz--n- 40.00G 5.84G
[root@localhost ~]# lvresize -L +1G /dev/myvg1/mylv1
Extending logical volume mylv1 to 3.00 GB
Logical volume mylv1 successfully resized
這樣就將LV的容量擴大到3G了。
3、縮小LV的容量。
待續…… |