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