实验要求:添加两个10G的硬盘将两个硬盘变成PV使用两个PV新建一个新的VG:datavg
在datavg中创建一个大小为13G的LV:data 以及一个 5 G的LV:loglv。 将两个LV格式化成ext3:data的块大小为4096B。loglv的块大小为2048B。 将两个LV挂载到/data和/logs 开机自动挂载data挂载到/data下。
热插技术
A :在虚拟机中添加两块10 G的硬盘。
1,查看文档 / proc/scsi/scsi
发现只有一块硬盘。
2,接下来把我们添加的那两块硬盘加载到内核中让内核识别。
然后查看下
可见有了/dev/sdb和/dev/sdc 这两块硬盘了
B: 接下来创建LVM ,并创建磁盘分区,转换文件系统类型为LVM(8e)
[root@localhost ~]# fdisk /dev/sdb
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1305, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1305, default 1305): 100
。。。。。。
Command (m for help): p
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 100 803218+ 83 Linux
/dev/sdb2 101 200 803250 83 Linux
/dev/sdb3 201 500 2409750 83 Linux
/dev/sdb4 501 1200 5622750 83 Linux
Command (m for help): t //转化分区内容为LVM
Partition number (1-4): 1
Hex code (type L to list codes): 8e //LVM对应的ID为8e ,此处可输入L查看
Changed system type of partition 1 to 8e (Linux LVM)
。。。。。。
Command (m for help): p
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 100 803218+ 8e Linux LVM
/dev/sdb2 101 200 803250 8e Linux LVM
/dev/sdb3 201 500 2409750 8e Linux LVM
/dev/sdb4 501 1200 5622750 8e Linux LVM
Command (m for help): w //保存
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# partprobe /dev/sdb
依照这个方法同样的把 /dev/ sdc 创建LVM并进行分区。
2,创建物理卷 PV
[root@localhost ~]# pvcreate /dev/sdb[1-4]
[root@localhost ~]# pvcreate /dev/sdc[1-4]
并查看:[root@localhost ~]# pvdisplay
"/dev/sdb1" is a new physical volume of "784.39 MB"
--- NEW Physical volume ---
PV Name /dev/sdb1
--- NEW Physical volume ---
PV Name /dev/sdb2
--- NEW Physical volume ---
PV Name /dev/sdb3
--- NEW Physical volume ---
PV Name /dev/sdb4
--- NEW Physical volume ---
PV Name /dev/sdc
--- NEW Physical volume ---
PV Name /dev/sdc2
--- NEW Physical volume ---
PV Name /dev/sdc3
--- NEW Physical volume ---
PV Name /dev/sdc4
3:创建卷组VG
[root@localhost ~]# vgcreate datavg /dev/sdb{1,2,3,4} /dev/sdc{1,2,3,4} // datavg 是自定义的vg名称
Volume group "datavg" successfully created
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name datavg
System ID
Format lvm2
Metadata Areas 8
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 8
Act PV 8
VG Size 18.38 GB
PE Size 4.00 MB
Total PE 4704
Alloc PE / Size 0 / 0
Free PE / Size 4704 / 18.38 GB
VG UUID 9MLLgG-1JDZ-fBKY-JEK9-DdP5-Gecr-cL69bZ
4,创建逻辑卷 LV
创建一个逻辑卷组data 13G,一个逻辑卷组loglv 5G
[root@localhost ~]# lvcreate -L 13G -n data datavg
Logical volume "data" created
[root@localhost ~]# lvcreate -L 5G -n logvg datavg
Logical volume "logvg" created
[root@localhost ~]# lvdisplay
--- Logical volume ---
LV Name /dev/datavg/data
VG Name datavg
LV UUID 7o2hR4-v2Sz-2aqW-KGcq-u1hm-3KPe-Lv02SP
LV Write Access read/write
LV Status available
# open 0
LV Size 13.00 GB
Current LE 3328
Segments 3
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Name /dev/datavg/logvg
VG Name datavg
LV UUID R6PC7E-EoaV-L0bl-glwI-QMz3-ka8O-YEcuoD
LV Write Access read/write
LV Status available
# open 0
LV Size 5.00 GB
Current LE 1280
Segments 5
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
5,格式化
[root@localhost ~]# mkfs.ext3 /dev/datavg/data //格式化为EXT3文件系统
[root@localhost ~]# mkfs.ext3 /dev/datavg/logvg
6 ,挂载
[root@localhost /]# mount /dev/datavg/data /data
[root@localhost /]# mount /dev/datavg/logvg /logs
查看结果:
[root@localhost mnt]# cd /data
[root@localhost data]# ll
total 16
drwx------ 2 root root 16384 Jan 25 07:16 lost+found
[root@localhost /]# cd logs
[root@localhost logs]# ll
total 16
drwx------ 2 root root 16384 Jan 25 07:17 lost+found
7,卸载
[root@localhost /]# umount /data
[root@localhost /]# umount /logs