具体做法是将三个硬盘组成raid5,在此之上建立VG和LV,将/root目录移动到新的逻辑卷上面并动态扩展其大小。最后增加一块新硬盘扩容。
1, 先给vmware增加三块硬盘,每个大小2G,并格式化后的设备分别为:
/dev/sdb1
/dev/sdc1
/dev/sdd1
2,建立raid 5:
[root@vm03 ~]# mdadm --create /dev/md0 --level=5 --raid-devices=3 /dev/sdb1 /dev/sdc1 /dev/sdd1
3,建立raid 配置文件:
[root@vm03 ~]# echo DEVICE /dev/sdb1 /dev/sdc1 /dev/sdd1
[root@vm03 ~]# mdadm --detail --scan >> /etc/mdadm.conf
4,运行vgscan,会自动产生lvm的配置文件和目录
[root@vm03 ~]# vgscan
Reading all physical volumes. This may take a while...
Found volume group "VolGroup00" using metadata type lvm2
5,创建LVM物理卷
[root@vm03 ~]# pvcreate /dev/md0
Physical volume "/dev/md0" successfully created
6,创建卷组
[root@vm03 ~]# vgcreate vg /dev/md0
Volume group "vg" successfully created
7,检查下卷组的情况
[root@vm03 ~]# vgdisplay vg
--- Volume group ---
VG Name vg
System ID
Format lvm2
Metadata Areas 1
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 1
Act PV 1
VG Size 4.00 GB
PE Size 4.00 MB
Total PE 1023
Alloc PE / Size 0 / 0
Free PE / Size 1023 / 4.00 GB
VG UUID 56b0zb-ZExF-zTCO-khQy-pe8B-KZPr-3usX9l
8,为home目录创建一个逻辑卷,并格式化
[root@vm03 ~]# lvcreate -n home -l 250 vg #其中 -l 250 指的是250个块,每块大小是4M,那么总共大小为1G
Logical volume "home" created
[root@vm03 ~]# mkfs.ext3 /dev/vg/home
[root@vm03 ~]# mkdir /mnt/home
[root@vm03 ~]# mount /dev/vg/home /mnt/home #挂载到临时的mnt下,把文件拷贝过来
[root@vm03 ~]# cp -a /root/* /mnt/home/
9,编辑/etc/fstab,在最后增加一行:
[root@vm03 ~]# vim /etc/fstab #真正挂载
/dev/vg/home /root ext3 defaults 0 0
10,reboot计算机 11,查看df
[root@vm03 ~]# df
文件系统 1K-块 已用 可用 已用% 挂载点
/dev/mapper/VolGroup00-LogVol00
9014656 1370740 7178612 17% /
/dev/sda1 101086 12240 83627 13% /boot
tmpfs 257652 0 257652 0% /dev/shm
/dev/mapper/vg-home 1007896 20944 935752 3% /root
12,将原来根目录挂载到临时目录/mnt下,并删除/root下面的所有文件,腾出空间
[root@vm03 ~]# mount /dev/mapper/VolGroup00-LogVol00 /mnt
[root@vm03 ~]# rm -rf /mnt/root/*
[root@vm03 ~]# umount /mnt
13,扩展/root目录的大小,再增加一个G
[root@vm03 ~]# umount /root
[root@vm03 ~]# e2fsck /dev/vg/home
e2fsck 1.39 (29-May-2006)
/dev/vg/home: clean, 276/128000 files, 9262/256000 blocks
[root@vm03 ~]# lvextend -L +1000M /dev/vg/home
Extending logical volume home to 1.95 GB
Logical volume home successfully resized
[root@vm03 ~]# e2fsck -f /dev/vg/home
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/vg/home: 276/128000 files (0.4% non-contiguous), 9262/256000 blocks
[root@vm03 ~]# resize2fs /dev/vg/home
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/vg/home to 512000 (4k) blocks.
The filesystem on /dev/vg/home is now 512000 blocks long.
[root@vm03 ~]# lvdisplay /dev/vg/home
--- Logical volume ---
LV Name /dev/vg/home
VG Name vg
LV UUID FGEWY2-b3BQ-Y1PA-1rPb-kELE-FcJJ-QNmyqB
LV Write Access read/write
LV Status available
# open 0
LV Size 1.95 GB #变成了1.95G大小了
Current LE 500
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 512
Block device 253:2
14,重新挂载/root
[root@vm03 ~]# mount /dev/vg/home /root
[root@vm03 ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/VolGroup00-LogVol00
8.6G 1.4G 6.9G 16% /
/dev/sda1 99M 12M 82M 13% /boot
tmpfs 252M 0 252M 0% /dev/shm
/dev/mapper/vg-home 2.0G 21M 1.9G 2% /root
15,接下来给RAID5增加一块硬盘并扩充VG容量:
[root@vm03 ~]# mdadm /dev/md0 -a /dev/sde1
mdadm: added /dev/sde1
[root@vm03 ~]# mdadm -G --raid-devices=4 /dev/md0
mdadm: Need to backup 384K of critical section..
mdadm: ... critical section passed.
[root@vm03 ~]# mv /etc/mdadm.conf /etc/mdadm.conf.bak
[root@vm03 ~]# echo DEVICE /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1
DEVICE /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1
[root@vm03 ~]# mdadm --detail --scan >> /etc/mdadm.conf
[root@vm03 ~]# pvresize /dev/md0
Physical volume "/dev/md0" changed
1 physical volume(s) resized / 0 physical volume(s) not resized
-bash-3.2# vgdisplay vg
--- Volume group ---
VG Name vg
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 1
Act PV 1
VG Size 6.00 GB #可以看到VG空间增加到了6G
PE Size 4.00 MB
Total PE 1535
Alloc PE / Size 500 / 1.95 GB
Free PE / Size 1035 / 4.04 GB
VG UUID 56b0zb-ZExF-zTCO-khQy-pe8B-KZPr-3usX9l
其实还可以将操作系统的/目录移动到LVM设备上面,比较复杂,在这里就不做演示了。