LVM的创建:
建立LVM类型的分区:创建分区的时候标记为LVM类型
建立LVM物理卷:pvcreate /dev/sdb pvscan pvdisplay
建立LVM卷组:vgcreate VG1 vgscan
建立LVM逻辑卷:lvcreate
建立文件系统:mkfs -t
挂接文件系统:mount -t
使用文件系统:
操作过程日志;
[root@localhost ~]# fdisk -l
Disk /dev/sda: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 572 4594558+ 83 Linux
/dev/sda2 573 652 642600 82 Linux swap
Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdb doesn't contain a valid partition table
Disk /dev/sdc: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdc doesn't contain a valid partition table
[root@localhost ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. 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): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-130, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-130, default 130): +300M
Command (m for help): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 37 297171 83 Linux
/dev/sdb2 38 74 297202+ 83 Linux
/dev/sdb3 75 130 449820 5 Extended
/dev/sdb5 75 87 104391 83 Linux
/dev/sdb6 88 100 104391 83 Linux
/dev/sdb7 101 113 104391 83 Linux
/dev/sdb8 114 130 136521 83 Linux
Command (m for help): t
Partition number (1-8): 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)
Command (m for help): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 37 297171 8e Linux LVM
/dev/sdb2 38 74 297202+ 8e Linux LVM
/dev/sdb3 75 130 449820 5 Extended
/dev/sdb5 75 87 104391 83 Linux
/dev/sdb6 88 100 104391 83 Linux
/dev/sdb7 101 113 104391 83 Linux
/dev/sdb8 114 130 136521 83 Linux
[root@localhost ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 37 297171 8e Linux LVM
/dev/sdb2 38 74 297202+ 8e Linux LVM
/dev/sdb3 75 130 449820 5 Extended
/dev/sdb5 75 87 104391 8e Linux LVM
/dev/sdb6 88 100 104391 8e Linux LVM
/dev/sdb7 101 113 104391 8e Linux LVM
/dev/sdb8 114 130 136521 8e Linux LVM
[root@localhost ~]# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created
[root@localhost ~]# pvscan
PV /dev/sdb1 lvm2 [290.02 MB]
PV /dev/sdb2 lvm2 [290.05 MB]
PV /dev/sdb5 lvm2 [101.76 MB]
PV /dev/sdb6 lvm2 [101.76 MB]
PV /dev/sdb7 lvm2 [101.76 MB]
PV /dev/sdb8 lvm2 [133.13 MB]
Total: 6 [1018.47 MB] / in use: 0 [0 ] / in no VG: 6 [1018.47 MB]
[root@localhost ~]# pvdisplay
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size 290.02 MB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID V4Sel3-M8QC-Nx03-Lqwe-xL6T-hoWh-T5x96b
--- NEW Physical volume ---
PV Name /dev/sdb2
VG Name
PV Size 290.05 MB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID MuMovx-fP6l-Turh-f3zw-Tdw5-yCqp-SRcCo3
--- NEW Physical volume ---
PV Name /dev/sdb5
VG Name
PV Size 101.76 MB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID W7Ggol-PKuL-7tV6-VqfS-CBrH-W1R1-NiqMBV
--- NEW Physical volume ---
PV Name /dev/sdb6
VG Name
PV Size 101.76 MB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID VITtRl-rMWd-wwan-u00Q-Awbj-WtG9-oijXuS
--- NEW Physical volume ---
PV Name /dev/sdb7
VG Name
PV Size 101.76 MB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID EBnZoG-gbFm-Pg02-uQag-gBx0-zTGU-Fk0Dmw
--- NEW Physical volume ---
PV Name /dev/sdb8
VG Name
PV Size 133.13 MB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID gRiI0b-PGyA-S128-7e44-013g-lGj5-IzvbcJ
[root@localhost ~]# vgcreate -A n VG1 /dev/sdb1 /dev/sdb5
Volume group "VG1" successfully created
[root@localhost ~]# vgscan
Reading all physical volumes. This may take a while...
Found volume group "VG1" using metadata type lvm2
[root@localhost ~]# pvscan
PV /dev/sdb1 VG VG1 lvm2 [288.00 MB / 288.00 MB free]
PV /dev/sdb5 VG VG1 lvm2 [100.00 MB / 100.00 MB free]
PV /dev/sdb2 lvm2 [290.05 MB]
PV /dev/sdb6 lvm2 [101.76 MB]
PV /dev/sdb7 lvm2 [101.76 MB]
PV /dev/sdb8 lvm2 [133.13 MB]
Total: 6 [1014.70 MB] / in use: 2 [388.00 MB] / in no VG: 4 [626.70 MB]
[root@localhost ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sdb1
VG Name VG1
PV Size 288.00 MB / not usable 0
Allocatable yes
PE Size (KByte) 4096
Total PE 72
Free PE 72
Allocated PE 0
PV UUID V4Sel3-M8QC-Nx03-Lqwe-xL6T-hoWh-T5x96b
--- Physical volume ---
PV Name /dev/sdb5
VG Name VG1
PV Size 100.00 MB / not usable 0
Allocatable yes
PE Size (KByte) 4096
Total PE 25
Free PE 25
Allocated PE 0
PV UUID W7Ggol-PKuL-7tV6-VqfS-CBrH-W1R1-NiqMBV
--- NEW Physical volume ---
PV Name /dev/sdb2
VG Name
PV Size 290.05 MB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID MuMovx-fP6l-Turh-f3zw-Tdw5-yCqp-SRcCo3
--- NEW Physical volume ---
PV Name /dev/sdb6
VG Name
PV Size 101.76 MB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID VITtRl-rMWd-wwan-u00Q-Awbj-WtG9-oijXuS
--- NEW Physical volume ---
PV Name /dev/sdb7
VG Name
PV Size 101.76 MB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID EBnZoG-gbFm-Pg02-uQag-gBx0-zTGU-Fk0Dmw
--- NEW Physical volume ---
PV Name /dev/sdb8
VG Name
PV Size 133.13 MB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID gRiI0b-PGyA-S128-7e44-013g-lGj5-IzvbcJ
[root@localhost ~]# vgcreate -A n VG2 /dev/sdb2 /dev/sdb6
Volume group "VG2" successfully created
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name VG2
System ID
Format lvm2
Metadata Areas 2
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 2
Act PV 2
VG Size 388.00 MB
PE Size 4.00 MB
Total PE 97
Alloc PE / Size 0 / 0
Free PE / Size 97 / 388.00 MB
VG UUID dotVeg-JHVM-azea-FJsb-RBMA-4Q1u-dmsTnS
--- Volume group ---
VG Name VG1
System ID
Format lvm2
Metadata Areas 2
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 2
Act PV 2
VG Size 388.00 MB
PE Size 4.00 MB
Total PE 97
Alloc PE / Size 0 / 0
Free PE / Size 97 / 388.00 MB
VG UUID l6VQ7G-M1fL-225p-sqb4-7doW-RvpK-Tp3UqP
[root@localhost ~]# pvscan
PV /dev/sdb2 VG VG2 lvm2 [288.00 MB / 288.00 MB free]
PV /dev/sdb6 VG VG2 lvm2 [100.00 MB / 100.00 MB free]
PV /dev/sdb1 VG VG1 lvm2 [288.00 MB / 288.00 MB free]
PV /dev/sdb5 VG VG1 lvm2 [100.00 MB / 100.00 MB free]
PV /dev/sdb7 lvm2 [101.76 MB]
PV /dev/sdb8 lvm2 [133.13 MB]
Total: 6 [1010.89 MB] / in use: 4 [776.00 MB] / in no VG: 2 [234.89 MB]
[root@localhost ~]# vgextend /dev/sdb7 VG1
/var/lock/lvm/V_/dev/sdb7: open failed: ûĿ¼
Can't get lock for /dev/sdb7
[root@localhost ~]# vgextend VG1 /dev/sdb7
Volume group "VG1" successfully extended
[root@localhost ~]# pvscan
PV /dev/sdb2 VG VG2 lvm2 [288.00 MB / 288.00 MB free]
PV /dev/sdb6 VG VG2 lvm2 [100.00 MB / 100.00 MB free]
PV /dev/sdb1 VG VG1 lvm2 [288.00 MB / 288.00 MB free]
PV /dev/sdb5 VG VG1 lvm2 [100.00 MB / 100.00 MB free]
PV /dev/sdb7 VG VG1 lvm2 [100.00 MB / 100.00 MB free]
PV /dev/sdb8 lvm2 [133.13 MB]
Total: 6 [1009.13 MB] / in use: 5 [876.00 MB] / in no VG: 1 [133.13 MB]
[root@localhost ~]# vgreduce VG1 /dev/sdb7
Removed "/dev/sdb7" from volume group "VG1"
[root@localhost ~]# pvscan
PV /dev/sdb2 VG VG2 lvm2 [288.00 MB / 288.00 MB free]
PV /dev/sdb6 VG VG2 lvm2 [100.00 MB / 100.00 MB free]
PV /dev/sdb1 VG VG1 lvm2 [288.00 MB / 288.00 MB free]
PV /dev/sdb5 VG VG1 lvm2 [100.00 MB / 100.00 MB free]
PV /dev/sdb7 lvm2 [100.00 MB]
PV /dev/sdb8 lvm2 [133.13 MB]
Total: 6 [1009.13 MB] / in use: 4 [776.00 MB] / in no VG: 2 [233.13 MB]
[root@localhost ~]# vgcreate VG3 /dev/sdb7
Volume group "VG3" successfully created
[root@localhost ~]# vgscan
Reading all physical volumes. This may take a while...
Found volume group "VG3" using metadata type lvm2
Found volume group "VG2" using metadata type lvm2
Found volume group "VG1" using metadata type lvm2
[root@localhost ~]# vgmerge VG2 VG3
Volume group "VG3" successfully merged into "VG2"
[root@localhost ~]# vgscan
Reading all physical volumes. This may take a while...
Found volume group "VG2" using metadata type lvm2
Found volume group "VG1" using metadata type lvm2
[root@localhost ~]# vgcfgbackup
Volume group "VG2" successfully backed up.
Volume group "VG1" successfully backed up.
[root@localhost ~]# lvcreate -L 200M -n LV1 /dev/VG1
Logical volume "LV1" created
[root@localhost ~]# lvcreate -L 200M -n LV2 /dev/VG2
Logical volume "LV2" created
[root@localhost ~]# lvscan
ACTIVE '/dev/VG2/LV2' [200.00 MB] inherit
ACTIVE '/dev/VG1/LV1' [200.00 MB] inherit
[root@localhost ~]# lvextend -L +50M /dev/VG1/LV1
Rounding up size to full physical extent 52.00 MB
Extending logical volume LV1 to 252.00 MB
Logical volume LV1 successfully resized
[root@localhost ~]# lvscan
ACTIVE '/dev/VG2/LV2' [200.00 MB] inherit
ACTIVE '/dev/VG1/LV1' [252.00 MB] inherit
[root@localhost ~]# lvreduce -L -10M /dev/VG1/LV1
Rounding up size to full physical extent 8.00 MB
WARNING: Reducing active logical volume to 244.00 MB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce LV1? [y/n]: y
Reducing logical volume LV1 to 244.00 MB
Logical volume LV1 successfully resized
[root@localhost ~]# lvscan
ACTIVE '/dev/VG2/LV2' [200.00 MB] inherit
ACTIVE '/dev/VG1/LV1' [244.00 MB] inherit
[root@localhost ~]# mkfs -t ext3 /dev/VG1/LV1
mke2fs 1.35 (28-Feb-2004)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
62496 inodes, 249856 blocks
12492 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
31 block groups
8192 blocks per group, 8192 fragments per group
2016 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 36 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost /]# mkdir /LV2
[root@localhost /]# mount -t ext3 /dev/VG2/LV2 /LV2
[root@localhost /]# mount
/dev/sda1 on / type ext3 (rw)
none on /proc type proc (rw)
none on /sys type sysfs (rw)
none on /dev/pts type devpts (rw,gid=5,mode=620)
usbfs on /proc/bus/usb type usbfs (rw)
none on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/mapper/VG1-LV1 on /lxf type ext3 (rw)
/dev/mapper/VG2-LV2 on /LV2 type ext3 (rw)
[root@localhost /]# lvs
LV VG Attr LSize Origin Snap% Move Copy%
LV1 VG1 -wi-ao 244.00M
LV2 VG2 -wi-ao 200.00M
阅读(2073) | 评论(0) | 转发(2) |