linux/UNIX LVM一些概念
时间:2016-06-12 21:43 来源:linux.it.net.cn 作者:IT
1,PV相关的命令:
pvcreate :将实体 partition 建立成为 PV ;
pvscan :搜寻目前系统里面任何具有 PV 的磁盘;
vdisplay :显示出目前系统上面的 PV 状态;
pvremove :将 PV 属性移除,让该 partition 不具有 PV 属性。
[root@nodebak ~]# pvscan
No matching physical volumes found
将新增加的磁盘创建分区,并将格式转化为8e,如下:
Command (m for help): p
Disk /dev/sdb: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 7832 62910508+ 5 Extended
/dev/sdb5 1 1246 10008432 8e Linux LVM
/dev/sdb6 1247 2492 10008463+ 8e Linux LVM
/dev/sdb7 2493 3738 10008463+ 8e Linux LVM
/dev/sdb8 3739 4984 10008463+ 8e Linux LVM
[root@nodebak ~]# pvcreate /dev/sdb(5,6,7,8)
-bash: syntax error near unexpected token `('
[root@nodebak ~]# pvcreate /dev/sdb{5,6,7,8}
Writing physical volume data to disk "/dev/sdb5"
Physical volume "/dev/sdb5" successfully created
Writing physical volume data to disk "/dev/sdb6"
Physical volume "/dev/sdb6" successfully created
Writing physical volume data to disk "/dev/sdb7"
Physical volume "/dev/sdb7" successfully created
Writing physical volume data to disk "/dev/sdb8"
Physical volume "/dev/sdb8" successfully created
[root@nodebak ~]# pvscan
PV /dev/sdb5 lvm2 [980.50 MB]
PV /dev/sdb6 lvm2 [980.50 MB]
PV /dev/sdb7 lvm2 [980.50 MB]
PV /dev/sdb8 lvm2 [980.50 MB]
Total: 4 [3.83 GB] / in use: 0 [0 ] / in no VG: 4 [3.83 GB]
[root@nodebak ~]# pvdisplay
"/dev/sdb5" is a new physical volume of "980.50 MB"
--- NEW Physical volume ---
PV Name /dev/sdb5
VG Name
PV Size 980.50 MB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID bqUQRW-GtxR-Foco-jmj1-E3I0-D4oO-Tl9las
2,vg相关的命令:
vgcreate :就是主要建立 VG 的指令啦!他的参数比较多,等一下介绍。
vgscan :搜寻系统上面是否有 VG 存在?
vgdisplay :显示目前系统上面的 VG 状态;
vgextend :在 VG 内增加额外的 PV ;
vgreduce :在 VG 内移除 PV;
vgchange :设定 VG 是否启动 (active);
vgremove :删除一个 VG 啊!
创建vg
vgcreate -s 16M vgtest /dev/sdb6 创建一个名为vgtest的vg,制定pe大小为16M(默认大小为4M),里面包含一个pv
# vgcreate -s 16M vgtest /dev/sdb6
Volume group "vgtest" successfully created
为vgtest增加一个pv
# vgextend vgtest /dev/sdb5 将/dev/sdb5增加到vgtest中
Volume group "vgtest" successfully extended
查看vg信息
# vgdisplay vgtest
--- Volume group ---
VG Name vgtest
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
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 1.91 GB
PE Size 16.00 MB
Total PE 122
Alloc PE / Size 0 / 0
Free PE / Size 122 / 1.91 GB
VG UUID N3hmc0-Al9Z-JTGM-4Q3H-3EI1-V9RT-dndfCQ
查看vg包含哪些pv
# vgdisplay -v vgtest
Using volume group(s) on command line
Finding volume group "vgtest"
--- Volume group ---
VG Name vgtest
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
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 1.91 GB
PE Size 16.00 MB
Total PE 122
Alloc PE / Size 0 / 0
Free PE / Size 122 / 1.91 GB
VG UUID N3hmc0-Al9Z-JTGM-4Q3H-3EI1-V9RT-dndfCQ
--- Physical volumes ---
PV Name /dev/sdb6
PV UUID xO7wSm-FHoI-6MT7-v92V-hM3D-kCx0-osfY8c
PV Status allocatable
Total PE / Free PE 61 / 61
PV Name /dev/sdb5
PV UUID bqUQRW-GtxR-Foco-jmj1-E3I0-D4oO-Tl9las
PV Status allocatable
Total PE / Free PE 61 / 61
删除一个vg中的一个pv
# vgreduce vgtest /dev/sdb5
Removed "/dev/sdb5" from volume group "vgtest"
删除一个vg
# vgremove vgtest1
Volume group "vgtest1" successfully removed
3,lv相关命令:
lvcreate:建立LV
lvscan:查询系统上的LV(linux不支持)
lvdisplay:显示系统上的LV状态
lvextend:向LV中增加容量
lvreduce:在LV中减少容量
lvremove:删除一个LV
lvsize:对LV进行容量大小的调整
新建LV
# lvcreate -L 500M -n testlv vgtest
Rounding up size to full physical extent 512.00 MB
Logical volume "testlv" created (因为新建立的LV的大小必须是PE的整数倍,这里自动调整了)
扩展lv的大小
lvextend -L +100M /dev/vgtest/testlv(-L 1024M将lv的大小增加到1024M)
Rounding up size to full physical extent 112.00 MB
Extending logical volume testlv to 624.00 MB
Logical volume testlv successfully resized 将testlv增大100M
# lvdisplay
--- Logical volume ---
LV Name /dev/vgtest/testlv
VG Name vgtest
LV UUID AMOlEN-0iJE-tmNy-VFO4-3BEh-A7rC-nNBCa7
LV Write Access read/write
LV Status available
# open 0
LV Size 624.00 MB
Current LE 39
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
减小lv的大小
# lvreduce -L -100M /dev/vgtest/testlv
Rounding up size to full physical extent 96.00 MB
WARNING: Reducing active logical volume to 528.00 MB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce testlv? [y/n]: y
Reducing logical volume testlv to 528.00 MB
Logical volume testlv successfully resized
# lvdisplay
--- Logical volume ---
LV Name /dev/vgtest/testlv
VG Name vgtest
LV UUID AMOlEN-0iJE-tmNy-VFO4-3BEh-A7rC-nNBCa7
LV Write Access read/write
LV Status available
# open 0
LV Size 528.00 MB
Current LE 33
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
删除lv
# lvremove /dev/vgtest/testlv1
Do you really want to remove active logical volume testlv1? [y/n]: y
Logical volume "testlv1" successfully removed
4,创建文件系统
# mkfs.ext3 /dev/vgtest/testlv
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
77920 inodes, 155648 blocks
7782 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=159383552
5 block groups
32768 blocks per group, 32768 fragments per group
15584 inodes per group
Superblock backups stored on blocks:
32768, 98304
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 28 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@nodebak ~]# mkdir /testlvm
[root@nodebak ~]# mount /dev/vgtest/testlv /testlvm/
[root@nodebak ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 15G 4.5G 9.5G 33% /
/dev/sda3 9.7G 154M 9.1G 2% /tmp
/dev/sda2 9.7G 5.7G 3.5G 63% /u01
tmpfs 1.0G 0 1.0G 0% /dev/shm
/dev/mapper/vgtest-testlv
599M 17M 552M 3% /testlvm
(责任编辑:IT)
1,PV相关的命令: pvcreate :将实体 partition 建立成为 PV ; pvscan :搜寻目前系统里面任何具有 PV 的磁盘; vdisplay :显示出目前系统上面的 PV 状态; pvremove :将 PV 属性移除,让该 partition 不具有 PV 属性。 [root@nodebak ~]# pvscan No matching physical volumes found 将新增加的磁盘创建分区,并将格式转化为8e,如下: Command (m for help): p Disk /dev/sdb: 64.4 GB, 64424509440 bytes 255 heads, 63 sectors/track, 7832 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdb1 1 7832 62910508+ 5 Extended /dev/sdb5 1 1246 10008432 8e Linux LVM /dev/sdb6 1247 2492 10008463+ 8e Linux LVM /dev/sdb7 2493 3738 10008463+ 8e Linux LVM /dev/sdb8 3739 4984 10008463+ 8e Linux LVM [root@nodebak ~]# pvcreate /dev/sdb(5,6,7,8) -bash: syntax error near unexpected token `(' [root@nodebak ~]# pvcreate /dev/sdb{5,6,7,8} Writing physical volume data to disk "/dev/sdb5" Physical volume "/dev/sdb5" successfully created Writing physical volume data to disk "/dev/sdb6" Physical volume "/dev/sdb6" successfully created Writing physical volume data to disk "/dev/sdb7" Physical volume "/dev/sdb7" successfully created Writing physical volume data to disk "/dev/sdb8" Physical volume "/dev/sdb8" successfully created [root@nodebak ~]# pvscan PV /dev/sdb5 lvm2 [980.50 MB] PV /dev/sdb6 lvm2 [980.50 MB] PV /dev/sdb7 lvm2 [980.50 MB] PV /dev/sdb8 lvm2 [980.50 MB] Total: 4 [3.83 GB] / in use: 0 [0 ] / in no VG: 4 [3.83 GB] [root@nodebak ~]# pvdisplay "/dev/sdb5" is a new physical volume of "980.50 MB" --- NEW Physical volume --- PV Name /dev/sdb5 VG Name PV Size 980.50 MB Allocatable NO PE Size (KByte) 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID bqUQRW-GtxR-Foco-jmj1-E3I0-D4oO-Tl9las 2,vg相关的命令: vgcreate :就是主要建立 VG 的指令啦!他的参数比较多,等一下介绍。 vgscan :搜寻系统上面是否有 VG 存在? vgdisplay :显示目前系统上面的 VG 状态; vgextend :在 VG 内增加额外的 PV ; vgreduce :在 VG 内移除 PV; vgchange :设定 VG 是否启动 (active); vgremove :删除一个 VG 啊! 创建vg vgcreate -s 16M vgtest /dev/sdb6 创建一个名为vgtest的vg,制定pe大小为16M(默认大小为4M),里面包含一个pv # vgcreate -s 16M vgtest /dev/sdb6 Volume group "vgtest" successfully created 为vgtest增加一个pv # vgextend vgtest /dev/sdb5 将/dev/sdb5增加到vgtest中 Volume group "vgtest" successfully extended 查看vg信息 # vgdisplay vgtest --- Volume group --- VG Name vgtest System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 4 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 1.91 GB PE Size 16.00 MB Total PE 122 Alloc PE / Size 0 / 0 Free PE / Size 122 / 1.91 GB VG UUID N3hmc0-Al9Z-JTGM-4Q3H-3EI1-V9RT-dndfCQ 查看vg包含哪些pv # vgdisplay -v vgtest Using volume group(s) on command line Finding volume group "vgtest" --- Volume group --- VG Name vgtest System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 4 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 1.91 GB PE Size 16.00 MB Total PE 122 Alloc PE / Size 0 / 0 Free PE / Size 122 / 1.91 GB VG UUID N3hmc0-Al9Z-JTGM-4Q3H-3EI1-V9RT-dndfCQ --- Physical volumes --- PV Name /dev/sdb6 PV UUID xO7wSm-FHoI-6MT7-v92V-hM3D-kCx0-osfY8c PV Status allocatable Total PE / Free PE 61 / 61 PV Name /dev/sdb5 PV UUID bqUQRW-GtxR-Foco-jmj1-E3I0-D4oO-Tl9las PV Status allocatable Total PE / Free PE 61 / 61 删除一个vg中的一个pv # vgreduce vgtest /dev/sdb5 Removed "/dev/sdb5" from volume group "vgtest" 删除一个vg # vgremove vgtest1 Volume group "vgtest1" successfully removed 3,lv相关命令: lvcreate:建立LV lvscan:查询系统上的LV(linux不支持) lvdisplay:显示系统上的LV状态 lvextend:向LV中增加容量 lvreduce:在LV中减少容量 lvremove:删除一个LV lvsize:对LV进行容量大小的调整 新建LV # lvcreate -L 500M -n testlv vgtest Rounding up size to full physical extent 512.00 MB Logical volume "testlv" created (因为新建立的LV的大小必须是PE的整数倍,这里自动调整了) 扩展lv的大小 lvextend -L +100M /dev/vgtest/testlv(-L 1024M将lv的大小增加到1024M) Rounding up size to full physical extent 112.00 MB Extending logical volume testlv to 624.00 MB Logical volume testlv successfully resized 将testlv增大100M # lvdisplay --- Logical volume --- LV Name /dev/vgtest/testlv VG Name vgtest LV UUID AMOlEN-0iJE-tmNy-VFO4-3BEh-A7rC-nNBCa7 LV Write Access read/write LV Status available # open 0 LV Size 624.00 MB Current LE 39 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 减小lv的大小 # lvreduce -L -100M /dev/vgtest/testlv Rounding up size to full physical extent 96.00 MB WARNING: Reducing active logical volume to 528.00 MB THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce testlv? [y/n]: y Reducing logical volume testlv to 528.00 MB Logical volume testlv successfully resized # lvdisplay --- Logical volume --- LV Name /dev/vgtest/testlv VG Name vgtest LV UUID AMOlEN-0iJE-tmNy-VFO4-3BEh-A7rC-nNBCa7 LV Write Access read/write LV Status available # open 0 LV Size 528.00 MB Current LE 33 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 删除lv # lvremove /dev/vgtest/testlv1 Do you really want to remove active logical volume testlv1? [y/n]: y Logical volume "testlv1" successfully removed 4,创建文件系统 # mkfs.ext3 /dev/vgtest/testlv mke2fs 1.39 (29-May-2006) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) 77920 inodes, 155648 blocks 7782 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=159383552 5 block groups 32768 blocks per group, 32768 fragments per group 15584 inodes per group Superblock backups stored on blocks: 32768, 98304 Writing inode tables: done Creating journal (4096 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 28 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@nodebak ~]# mkdir /testlvm [root@nodebak ~]# mount /dev/vgtest/testlv /testlvm/ [root@nodebak ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 15G 4.5G 9.5G 33% / /dev/sda3 9.7G 154M 9.1G 2% /tmp /dev/sda2 9.7G 5.7G 3.5G 63% /u01 tmpfs 1.0G 0 1.0G 0% /dev/shm /dev/mapper/vgtest-testlv 599M 17M 552M 3% /testlvm (责任编辑:IT) |