管理LVM
2.1 LVM增大分区空间
添加新的物理卷到卷组中
当系统安装了新的磁盘并创建了新的物理卷,而要将其添加到已有卷组时,就需要使用vgextend命令:
[root@lvm ~]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000824a8
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 1046 8192000 83 Linux
/dev/sda3 1046 1683 5120000 8e Linux LVM
/dev/sda4 1683 2611 7453696 5 Extended
/dev/sda5 1684 1811 1024000 82 Linux swap / Solaris
/dev/sda6 1811 2611 6427648 8e Linux LVM
Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/sdb doesn't contain a valid partition table
[root@lvm ~]# vgdisplay
--- Volume group ---
VG Name vg01
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 11.01 GiB
PE Size 4.00 MiB
Total PE 2818
Alloc PE / Size 0 / 0
Free PE / Size 2818 / 11.01 GiB
VG UUID obrLAB-73Ka-ExbE-EyCh-0fAU-TyhO-uwKD2m
[root@lvm ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x966e398b.
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)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-652, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-652, default 652): 652
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@lvm ~]# partprobe /dev/sdb
[root@lvm ~]# pvcreate /dev/sdb[1]
Physical volume "/dev/sdb1" successfully created
[root@lvm ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda3
VG Name vg01
PV Size 4.88 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 1249
Free PE 1249
Allocated PE 0
PV UUID jEvjAQ-0N9Z-Ro5V-RBrH-E6rb-BN56-nBNJek
--- Physical volume ---
PV Name /dev/sda6
VG Name vg01
PV Size 6.13 GiB / not usable 0
Allocatable yes
PE Size 4.00 MiB
Total PE 1569
Free PE 1569
Allocated PE 0
PV UUID PfFgDG-A5i9-GOO7-EUvA-qYvs-eu5M-o4O8TJ
"/dev/sdb1" is a new physical volume of "4.99 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size 4.99 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID PnXF0c-VXM2-M42z-G1IU-FXX3-tij2-iRMdS7
[root@lvm ~]# vgdisplay
--- Volume group ---
VG Name vg01
System ID
Format lm2
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 11.01 GiB
PE Size 4.00 MiB
Total PE 2818
Alloc PE / Size 0 / 0
Free PE / Size 2818 / 11.01 GiB
VG UUID obrLAB-73Ka-ExbE-EyCh-0fAU-TyhO-uwKD2m
[root@lvm ~]# pvscan
PV /dev/sda3 VG vg01 lvm2 [4.88 GiB / 4.88 GiB free]
PV /dev/sda6 VG vg01 lvm2 [6.13 GiB / 6.13 GiB free]
PV /dev/sdb1 lvm2 [4.99 GiB]
Total: 3 [16.00 GiB] / in use: 2 [11.01 GiB] / in no VG: 1 [4.99 GiB]
2.2 Vg增加容量
[root@lvm ~]# vgextend vg01 /dev/sdb
No physical volume label read from /dev/sdb
Physical volume "/dev/sdb" successfully created
Volume group "vg01" successfully extended
[root@lvm ~]# vgdisplay
--- Volume group ---
VG Name vg01
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 2
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 16.00 GiB //vg容量已经增加了
PE Size 4.00 MiB
Total PE 4097
Alloc PE / Size 0 / 0
Free PE / Size 4097 / 16.00 GiB
VG UUID obrLAB-73Ka-ExbE-EyCh-0fAU-TyhO-uwKD2m
2.3 Lv增加容量
[root@lvm dev]# lvscan
ACTIVE '/dev/vg01/lv01' [7.81 GiB] inherit
[root@lvm dev]# lvdisplay
--- Logical volume ---
LV Name /dev/vg01/lv01
VG Name vg01
LV UUID SHbq4A-MFlQ-N1pR-l8ui-aT20-xyEq-mAG3bp
LV Write Access read/write
LV Status available
# open 0
LV Size 7.81 GiB
Current LE 2000
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
[root@lvm dev]# lvresize -l +2000 /dev/vg
vg01/ vga_arbiter
[root@lvm dev]# lvresize -l +2000 /dev/vg01/lv01
Extending logical volume lv01 to 15.62 GiB
Logical volume lv01 successfully resized
[root@lvm dev]# lvscan
ACTIVE '/dev/vg01/lv01' [15.62 GiB] inherit
若要增加则使用+ ,若要减少则使用-
2.4 回收闲置硬盘
如果lv01闲置空间大就将sdb硬盘取下,用作别的地方,比如做快照备份
[root@lvm dev]# vgreduce vg01 /dev/sdb
Physical volume "/dev/sdb" still in use
[root@lvm dev]# lvresize -l -2000 /dev/vg01/lv01
WARNING: Reducing active logical volume to 7.81 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv01? [y/n]: y
Reducing logical volume lv01 to 7.81 GiB
Logical volume lv01 successfully resized
[root@lvm dev]# pvmove /dev/sdb /dev/sda3 //如果sdb内有PE就移动到sda3中,这里没
No data to move for vg01
[root@lvm dev]# vgreduce vg01 /dev/sdb
Removed "/dev/sdb" from volume group "vg01"
[root@lvm dev]# pvremove /dev/sdb
Labels on physical volume "/dev/sdb" successfully wipe3. 快照备份还原
3.1 挂载一块硬盘
[root@lvm ~]# pvcreate /dev/hdb2
Physical volume "/dev/hdb2" successfully created
[root@lvm ~]# vgextend vg02 /dev/hdb2
Volume group "vg02" successfully extended
[root@lvm ~]# vgdisplay
--- Volume group ---
VG Name vg02
VG Size 8.36 GB
PE Size 16.00 MB
Total PE 535
Alloc PE / Size 446 / 6.97 GB
Free PE / Size 89 / 1.39 GB
3.2 建立系统快照区snap02
[root@lvm ~]# lvcreate -l 60 -s -n snap02 /dev/vg02/lv02
Logical volume "snap02" created
[root@lvm ~]# lvdisplay
--- Logical volume ---
LV Name /dev/vg02/snap02
VG Name vg02
LV UUID K2tJ5E-e9mI-89Gw-hKFd-4tRU-tRKF-oeB03a
LV Write Access read/write
LV snapmntstatus active destination for /dev/vg02/lv02
LV Status available
# open 0
LV Size 6.97 GB
Current LE 446
COW-table size 960.00 MB
COW-table LE 60
Allocated to snapmnt0.00%
Snapmntchunk size 4.00 KB
Segments 1
Allocation inherit
Read ahead sectors auto
3.2 变更一下内容
[root@lvm ~]# rm -r /mnt/lvm/log
[root@lvm ~]# cp -a /boot /lib /sbin /mnt/lvm
[root@lvm ~]# ll /mnt/lvm
drwxr-xr-x 4 root root 4096 Dec 15 16:28 boot
drwxr-xr-x 105 root root 12288 Mar 11 16:59 etc
drwxr-xr-x 14 root root 4096 Sep 5 2008 lib
drwx------ 2 root root 16384 Mar 11 16:59 lost+found
drwxr-xr-x 2 root root 12288 Sep 5 2008 sbin
[root@lvm ~]# lvdisplay /dev/vg02/snap02
--- Logical volume ---
LV Name /dev/vg02/snap02
VG Name vg02
Allocated to snapmnt12.22%
本文出自 “小黑” 博客,谢绝转载!