>volume group vg1包括了三个PV,sda1 sdb1 sdc1,各600GB的SAS,先发现其中一个SAS sdc盘呼哧呼哧的想,猜想快挂了。
vg1上创建了一个lv1,目前有800GB的数据在里面。pvmove一下,具体怎么操作如下:
1查看vg中可用空闲空间,
# pvs -o+pv_used //保证vg中其他磁盘可用空间大于需要移除磁盘空间,新盘没到之前,这个是必须的,
2移动 sdc1中的数据,
#pvmove /dev/sdc1
3。查看是否移动成功,
#pvs -o+pv_used //若sdc1已用空间显示零,表示移动成功。
4.vgreduce删除磁盘
vgreduce vg1 /dev/sdc1 //删除sdc1磁盘
转自:http://blog.chinaunix.net/uid-24946452-id-119775.html
http://www.shangxueba.com/jingyan/121397.html
以上内容是参考的 下面是我实验的过程 模拟更换硬盘和缩小空间 都是在虚拟机进行的
首先新建3个pv
新建一个VG 加入3个PV
1 2 3 4 | [root@LVS-Master /] # pvcreate /dev/sdb1 /dev/sdc1 /dev/sdd1 Physical volume "/dev/sdb1" successfully created Physical volume "/dev/sdc1" successfully created Physical volume "/dev/sdd1" successfully created |
1 2 | [root@LVS-Master /] # vgcreate apple /dev/sdb1 /dev/sdc1 /dev/sdd1 Volume group "apple" successfully created |
创建LV 并格式化挂载
1 2 3 4 | [root@LVS-Master /] # lvcreate -L 38G -n test apple Logical volume "test" created [root@LVS-Master /] # mkdir lvmtest [root@LVS-Master /] # mount /dev/apple/test /lvmtest/ |
现在可以在这个目录下写一些测试文件
1 2 3 4 5 6 7 8 | [root@LVS-Master lvmtest] # ps aux > test.text .................. [root@LVS-Master lvmtest] # pvs PV VG Fmt Attr PSize PFree /dev/sda2 vg_lvsmaster lvm2 a-- 19.80g 0 /dev/sdb1 apple lvm2 a-- 19.99g 0 /dev/sdc1 apple lvm2 a-- 19.99g 1.98g /dev/sdd1 apple lvm2 a-- 19.99g 19.99g |
因为每块次的大小为19.9G 剩余空间是19.99g+1.98g 我们现在假设磁盘空间不够用来缩小
lv test的空间 我们把test的空间缩小到12G
1 | [root@LVS-Master /] # umount /lvmtest/ |
执行e2fsck -f /dev/apple/test
1 2 3 4 5 6 7 8 | [root@LVS-Master /] # e2fsck -f /dev/apple/test e2fsck 1.41.12 (17-May-2010) 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/apple/test : 16 /2490368 files (0.0% non-contiguous), 2298484 /9961472 blocks |
执行resize2fs /dev/apple/test 12G
1 2 3 4 | [root@LVS-Master /] # resize2fs /dev/apple/test 12G resize2fs 1.41.12 (17-May-2010) Resizing the filesystem on /dev/apple/test to 3145728 (4k) blocks. The filesystem on /dev/apple/test is now 3145728 blocks long. |
执行lvresize -L 12G /dev/apple/test
1 2 3 4 5 6 | [root@LVS-Master /] # lvresize -L 12G /dev/apple/test WARNING: Reducing active logical volume to 12.00 GiB THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce test ? [y /n ]: y Reducing logical volume test to 12.00 GiB Logical volume test successfully resized |
再次执行e2fsck -f /dev/apple/test
1 2 3 4 5 6 7 8 | [root@LVS-Master /] # e2fsck -f /dev/apple/test e2fsck 1.41.12 (17-May-2010) 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/apple/test : 16 /786432 files (0.0% non-contiguous), 2189523 /3145728 blocks |
而后挂载文件系统
1 2 3 4 5 6 7 8 9 10 | [root@LVS-Master /] # mount /dev/apple/test /lvmtest/ [root@LVS-Master /] # df -H Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_lvsmaster-LogVol01 20G 3.9G 15G 21% / tmpfs 983M 0 983M 0% /dev/shm /dev/sda1 204M 34M 159M 18% /boot /dev/mapper/apple-test 13G 8.8G 3.3G 73% /lvmtest [root@LVS-Master /] # |
从以上看来我们的lv test成功修改为12G 现在的空间是13G 现在进入目录 看看之前创建的文件是否存在.
1 2 3 4 5 6 7 8 9 10 | [root@LVS-Master lvmtest] # cd /lvmtest/ [root@LVS-Master lvmtest] # ll total 8388632 -rw-r--r--. 1 root root 2147479552 Dec 4 20:07 hello.cfg -rw-r--r--. 1 root root 2147479552 Dec 4 20:08 hello.conf -rw-r--r--. 1 root root 2147479552 Dec 4 20:08 hello.sh -rw-r--r--. 1 root root 2147479552 Dec 4 20:06 hello.txt drwx------. 2 root root 16384 Dec 4 20:02 lost+found -rw-r--r--. 1 root root 7258 Dec 4 20:12 test .text [root@LVS-Master lvmtest] # |
test文件存在而且内容页是正确的.
现在我们模拟更换磁盘
假设现在/dev/sdb1 出现问题了 我们更换sdb1 sdb1的大小事19.9G 我们看看剩余空间是否够19.9G
1 2 3 4 5 6 | root@LVS-Master lvmtest] # pvs PV VG Fmt Attr PSize PFree /dev/sda2 vg_lvsmaster lvm2 a-- 19.80g 0 /dev/sdb1 apple lvm2 a-- 19.99g 7.99g /dev/sdc1 apple lvm2 a-- 19.99g 19.99g /dev/sdd1 apple lvm2 a-- 19.99g 19.99g |
我们按到空间还有很多 19.99*2+7.99G
现在我们移除sdb1
1 2 3 4 5 6 | [root@LVS-Master lvmtest] # pvmove /dev/sdb1 /dev/sdb1 : Moved: 0.1% /dev/sdb1 : Moved: 31.1% /dev/sdb1 : Moved: 63.8% /dev/sdb1 : Moved: 95.7% /dev/sdb1 : Moved: 100.0% |
移动完成
1 2 3 4 5 6 | [root@LVS-Master lvmtest] # pvs -o+used PV VG Fmt Attr PSize PFree Used /dev/sda2 vg_lvsmaster lvm2 a-- 19.80g 0 19.80g /dev/sdb1 lvm2 a-- 19.99g 19.99g 0 /dev/sdc1 apple lvm2 a-- 19.99g 7.99g 12.00g /dev/sdd1 apple lvm2 a-- 19.99g 19.99g 0 |
我们看到现在sdb1已经完全空余
OK 现在我们从vg移除db1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | [root@LVS-Master lvmtest] # vgreduce apple /dev/sdb1 Removed "/dev/sdb1" from volume group "apple" [root@LVS-Master lvmtest] # vgdisplay apple --- Volume group --- VG Name apple System ID Format lvm2 Metadata Areas 2 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 2 Act PV 2 VG Size 39.98 GiB PE Size 4.00 MiB Total PE 10236 Alloc PE / Size 3072 / 12.00 GiB Free PE / Size 7164 / 27.98 GiB VG UUID LH0hdO-W5op-nz1X-m0jZ-pZcP-VrTc-qpnmGN |
我们看到VG的大小已经发生变化 开始的VG大小事19.9G*3 现在是39.98G
现在我们移除物理卷
1 2 3 4 5 6 7 | [root@LVS-Master lvmtest] # pvremove /dev/sdb1 Labels on physical volume "/dev/sdb1" successfully wiped [root@LVS-Master lvmtest] # pvscan PV /dev/sdc1 VG apple lvm2 [19.99 GiB / 7.99 GiB free ] PV /dev/sdd1 VG apple lvm2 [19.99 GiB / 19.99 GiB free ] PV /dev/sda2 VG vg_lvsmaster lvm2 [19.80 GiB / 0 free ] Total: 3 [59.79 GiB] / in use: 3 [59.79 GiB] / in no VG: 0 [0 ] |
OK我们看到PV已经被移除了 剩下的事情就是更换硬盘 安装 关于安装本人就不在叙述
本文转自flyingzf 51CTO博客,原文链接:http://blog.51cto.com/flyingzf/1336068,如需转载请自行联系原作者