1.新建2个分区(略)
2.修改分区id为8e
3.partprobe
4.初始化物理卷
[root@station85 ~]# pvcreate /dev/sda7 /dev/sda8
Physical volume "/dev/sda7" successfully created
Physical volume "/dev/sda8" successfully created
5.创建卷组
[root@station85 ~]# vgcreate testvg /dev/sda7 /dev/sda8
Volume group "testvg" successfully created
6创建逻辑卷,不要占用所有空间
[root@station85 ~]# lvcreate -L 40M -n testlv testvg
Logical volume "testlv" created
[root@station85 data-lv]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 6940516 2217116 4365152 34% /
/dev/sda1 101086 11009 84858 12% /boot
tmpfs 972276 0 972276 0% /dev/shm
/dev/md2 972280 17632 905256 2% /mnt
/dev/mapper/testvg-testlv
39663 39640 0 100% /data-lv
7在逻辑卷上创建ext3文件系统:
mke2fs –j /dev/testvg/testlv
8创建data-lv目录并挂载
9在testlv目录下创建文件
[root@station85 data-lv]# dd if=/dev/zero of=/data-lv/bigfile bs=1M count=50
dd: writing `/data-lv/bigfile': No space left on device
35+0 records in
34+0 records out
35733504 bytes (36 MB) copied, 1.30968 seconds, 27.3 MB/s
提示空间不足
10 扩展逻辑卷,再增加50M,须先调整分区大小 再调整文件系统大小
[root@station85 ~]# lvextend -L +50M /dev/testvg/testlv
Rounding up size to full physical extent 52.00 MB
Extending logical volume testlv to 92.00 MB
Logical volume testlv successfully resized
[root@station85 ~]# resize2fs /dev/testvg/testlv
[root@station85 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 6940516 2217120 4365148 34% /
/dev/sda1 101086 11009 84858 12% /boot
tmpfs 972276 0 972276 0% /dev/shm
/dev/md2 972280 17632 905256 2% /mnt
/dev/mapper/testvg-testlv
91099 40117 46276 47% /data-lv
11.恢复逻辑卷到原来的大小(试着按扩展逻辑卷相反的步骤做,看是否能成功):
首先卸载或者改为只读模式
[root@station85 ~]# umount /data-lv
先减小文件系统,再减小逻辑卷
减小文件系统之前 需要做强制检查
[root@station85 ~]# resize2fs /dev/testvg/testlv 40M
resize2fs 1.39 (29-May-2006)
Please run 'e2fsck -f /dev/testvg/testlv' first.
(这个命令应该是运行不成功的,因为文件系统要求,在重新调整文件系统之前,必须要强制检查一下,所以你要先用fsck做一次强制检查,然后再运行该命令)
强制检查
[root@station85 ~]# e2fsck -f /dev/testvg/testlv
[root@station85 ~]# e2fsck -f /dev/testvg/testlv
e2fsck 1.39 (29-May-2006)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/testvg/testlv: 11/24576 files (9.1% non-contiguous), 8191/94208 blocks
[root@station85 ~]# resize2fs /dev/testvg/testlv 40M
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/testvg/testlv to 40960 (1k) blocks.
The filesystem on /dev/testvg/testlv is now 40960 blocks long.
[root@station85 ~]# lvresize -L 40M /dev/testvg/testlv
WARNING: Reducing active logical volume to 40.00 MB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce testlv? [y/n]: y
Reducing logical volume testlv to 40.00 MB
Logical volume testlv successfully resized
[root@station85 ~]# mount /dev/testvg/testlv /data
二、在LVM中更换硬盘
1.初始化分区
2.创建物理卷
[root@station85 ~]# pvcreate /dev/sda9
Physical volume "/dev/sda9" successfully created
3.把该物理卷加入到卷组testvg
[root@station85 ~]# vgextend testvg /dev/sda9
Volume group "testvg" successfully extended
查看卷组容量
[root@station85 ~]# vgdisplay
--- Volume group ---
VG Name testvg
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 7
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 3
Act PV 3
VG Size 5.60 GB
PE Size 4.00 MB
Total PE 1434
Alloc PE / Size 10 / 40.00 MB
Free PE / Size 1424 / 5.56 GB
VG UUID UJrKI9-NSrt-vhV8-iwoR-pN7i-MhQp-PxPcPr
4.查看物理卷详情,为数据转移做准备
[root@station85 ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda7
VG Name testvg
PV Size 1.87 GB / not usable 1.96 MB
Allocatable yes
PE Size (KByte) 4096
Total PE 478
Free PE 468
Allocated PE 10
PV UUID pJxudP-iM6G-BNbv-Nx0a-cDqM-FAw1-51WeDz
--- Physical volume ---
PV Name /dev/sda8
VG Name testvg
PV Size 1.87 GB / not usable 1.96 MB
Allocatable yes
PE Size (KByte) 4096
Total PE 478
Free PE 478
Allocated PE 0
PV UUID 7fOpr3-5cEC-1Gph-BmnY-Zj2I-UZo8-JwcUAW
--- Physical volume ---
PV Name /dev/sda9
VG Name testvg
PV Size 1.87 GB / not usable 1.96 MB
Allocatable yes
PE Size (KByte) 4096
Total PE 478
Free PE 478
Allocated PE 0
PV UUID xxNAtZ-a3RO-lN9D-UN1X-atq2-p5q9-HyEO8a
进/dev/sda7 有数据,需转移到/dev/sda9
5.转移数据
[root@station85 ~]# pvmove /dev/sda7 /dev/sda9
/dev/sda7: Moved: 100.0%
查看物理卷详情,对比上面数据
[root@station85 ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda7
VG Name testvg
PV Size 1.87 GB / not usable 1.96 MB
Allocatable yes
PE Size (KByte) 4096
Total PE 478
Free PE 478
Allocated PE 0
PV UUID pJxudP-iM6G-BNbv-Nx0a-cDqM-FAw1-51WeDz
--- Physical volume ---
PV Name /dev/sda8
VG Name testvg
PV Size 1.87 GB / not usable 1.96 MB
Allocatable yes
PE Size (KByte) 4096
Total PE 478
Free PE 478
Allocated PE 0
PV UUID 7fOpr3-5cEC-1Gph-BmnY-Zj2I-UZo8-JwcUAW
--- Physical volume ---
PV Name /dev/sda9
VG Name testvg
PV Size 1.87 GB / not usable 1.96 MB
Allocatable yes
PE Size (KByte) 4096
Total PE 478
Free PE 468
Allocated PE 10
PV UUID xxNAtZ-a3RO-lN9D-UN1X-atq2-p5q9-HyEO8a
6.把/dev/sda7从卷组中移除
[root@station85 ~]# vgreduce testvg /dev/sda7
Removed "/dev/sda7" from volume group "testvg"
7.查看卷组容量
[root@station85 ~]# vgdisplay
--- Volume group ---
VG Name testvg
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 11
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 2
Act PV 2
VG Size 3.73 GB
PE Size 4.00 MB
Total PE 956
Alloc PE / Size 10 / 40.00 MB
Free PE / Size 946 / 3.70 GB
VG UUID UJrKI9-NSrt-vhV8-iwoR-pN7i-MhQp-PxPcPr
/dev/sda7已移除
8.把dev/sda7从物理卷中移除
[root@station85 ~]# pvremove /dev/sda7
Labels on physical volume "/dev/sda7" successfully wiped
[root@station85 ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda8
VG Name testvg
PV Size 1.87 GB / not usable 1.96 MB
Allocatable yes
PE Size (KByte) 4096
Total PE 478
Free PE 478
Allocated PE 0
PV UUID 7fOpr3-5cEC-1Gph-BmnY-Zj2I-UZo8-JwcUAW
--- Physical volume ---
PV Name /dev/sda9
VG Name testvg
PV Size 1.87 GB / not usable 1.96 MB
Allocatable yes
PE Size (KByte) 4096
Total PE 478
Free PE 468
Allocated PE 10
PV UUID xxNAtZ-a3RO-lN9D-UN1X-atq2-p5q9-HyEO8a
OK