标签:创建及扩展逻辑卷
实验01 创建逻辑卷
实验目标
从两块磁盘上各取10GB组成20GB的卷组
从卷组中划分一个16GB的逻辑卷
将此逻辑卷格式化并挂载到/mbox
实验步骤
一、为新添加的两块硬盘分区
[root@localhost ~]# fdisk -l | grep LVM //查看标记为LVM的分区
/dev/sdb1 1 1217 9775521 8e Linux LVM
/dev/sdc1 1 1217 9775521 8e Linux LVM
二、创建物理卷pvcreate 分区 分区
[root@localhost~]# pvscan //扫描物理卷
No matching physical volumes found
[root@localhost~]# pvdisplay //显示物理卷
[root@localhost~]#
[root@localhost~]# pvcreate /dev/sdb1 /dev/sdc1 //创建物理卷
Writing physical volume data to disk"/dev/sdb1"
Physical volume "/dev/sdb1"successfully created
Writing physical volume data to disk"/dev/sdc1"
Physical volume "/dev/sdc1"successfully created
[root@localhost~]# pvscan
PV /dev/sdb1 lvm2 [9.32 GB]
PV /dev/sdc1 lvm2 [9.32 GB]
Total: 2 [18.65 GB] / in use: 0 [0 ] / in no VG: 2 [18.65 GB]
[root@localhost~]# pvdisplay
"/dev/sdb1" is a new physicalvolume of "9.32 GB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size 9.32 GB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID jpuMRT-9Xwr-bEKm-Edc1-qhsb-oDiG-AUf5w9
"/dev/sdc1" is a new physicalvolume of "9.32 GB"
--- NEW Physical volume ---
PV Name /dev/sdc1
VG Name
PV Size 9.32 GB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID Bkr2nc-yclE-0j1K-UE99-2Pnd-3BaV-wyrqhm
三、创建卷组vgcreate 卷组名 分区 分区
[root@localhost~]# vgscan //扫描卷组
Reading all physical volumes. This may take a while...
No volume groups found
[root@localhost~]# vgdisplay //显示卷组
No volume groups found
[root@localhost~]# vgcreate vg_data /dev/sd{b,c}1 //创建指定名称的卷组
Volume group "vg_data" successfullycreated
[root@localhost~]# vgscan
Reading all physical volumes. This may take a while...
Found volume group "vg_data" usingmetadata type lvm2
[root@localhost~]# vgdisplay
--- Volume group ---
VG Name vg_data
System ID
Format lvm2
Metadata Areas 2
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 2
Act PV 2
VG Size 18.64 GB
PE Size 4.00 MB
Total PE 4772
Alloc PE / Size 0 / 0
Free PE / Size 4772 / 18.64 GB
VG UUID pA9c9b-hNEB-emWv-c5am-lRgv-rAmf-Ff4egw
四、创建逻辑卷lvcreate -L 大小 -n 逻辑卷名 卷组名
[root@localhost~]# lvscan //扫描逻辑卷
[root@localhost~]# lvdisplay //显示逻辑卷
[root@localhost~]# lvcreate -L 16G -nlv_mbox vg_data //创建指定大小和名称 的逻辑卷
Logical volume "lv_mbox" created
[root@localhost~]# lvscan
ACTIVE ‘/dev/vg_data/lv_mbox‘ [16.00 GB]inherit
[root@localhost~]# lvdisplay
--- Logical volume ---
LV Name /dev/vg_data/lv_mbox
VG Name vg_data
LV UUID fB0Kr6-r03Z-YuNu-Kq75-uEdY-D4oW-OluAGl
LV Write Access read/write
LV Status available
# open 0
LV Size 16.00 GB
Current LE 4096
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
五、格式化逻辑卷
[root@localhost~]# mkfs.ext3 /dev/vg_data/lv_mbox //格式化逻辑卷
mke2fs1.39 (29-May-2006)
Filesystemlabel=
OStype: Linux
Blocksize=4096 (log=2)
Fragmentsize=4096 (log=2)
2097152inodes, 4194304 blocks
209715blocks (5.00%) reserved for the super user
Firstdata block=0
Maximumfilesystem blocks=4294967296
128block groups
32768blocks per group, 32768 fragments per group
16384inodes per group
Superblockbackups stored on blocks:
32768, 98304, 163840, 229376, 294912,819200, 884736, 1605632, 2654208,
4096000
Writinginode tables: done
Creatingjournal (32768 blocks): done
Writingsuperblocks and filesystem accounting information: done
Thisfilesystem will be automatically checked every 29 mounts or
180 days,whichever comes first. Use tune2fs -c or-i to override.
六、挂载逻辑卷
[root@localhost~]# mkdir /mbox
[root@localhost~]# blkid /dev/vg_data/lv_mbox
/dev/vg_data/lv_mbox:UUID="ae86ca47-b680-4eeb-a5b3-d32d0b72118f" SEC_TYPE="ext2"TYPE="ext3"
[root@localhost~]# vim /etc/fstab //将逻辑卷设置为开机自动挂载
UUID="ae86ca47-b680-4eeb-a5b3-d32d0b72118f" /mbox ext3defaults 0 0
结果验证
验证逻辑卷的挂载情况
[root@localhost~]# mount -a
[root@localhost~]# df -hT
文件系统 类型 容量 已用 可用 已用% 挂载点
/dev/sda3 ext3 78G 3.0G 71G 5% /
/dev/sda1 ext3 190M 12M 169M 7% /boot
tmpfs tmpfs 502M 0 502M 0% /dev/shm
/dev/sr0 iso9660 4.1G 4.1G 0 100% /media/RHEL_5.10 x86_64 DVD
/dev/mapper/vg_data-lv_mbox
ext3 16G 173M 15G 2% /mbox
[root@localhost~]# ls -l /dev/vg_data/lv_mbox
lrwxrwxrwx 1root root 27 10-11 03:12 /dev/vg_data/lv_mbox ->
/dev/mapper/vg_data-lv_mbox
dev/mapper/vg_data-lv_mbox是/dev/vg_data/lv_mbox的链接
问题和经验总结
故障现象:无
解决办法:
实验02 扩展逻辑卷
实验目标
扩展 /mbox 所在的逻辑卷到 30GB
实验步骤
一、查看磁盘分区列表
[root@localhost~]# fdisk -l | grep LVM
/dev/sdb1 1 1217 9775521 8e Linux LVM
/dev/sdb2 1218 2434 9775552+ 8e Linux LVM
/dev/sdc1 1 1217 9775521 8e Linux LVM
二、创建新的物理卷
[root@localhost~]# pvcreate /dev/sdb2
Writing physical volume data to disk "/dev/sdb2"
Physical volume "/dev/sdb2"successfully created
[root@localhost~]# pvscan
PV /dev/sdb1 VG vg_data lvm2 [9.32 GB /0 free]
PV /dev/sdc1 VG vg_data lvm2 [9.32 GB /2.64 GB free]
PV /dev/sdb2 lvm2 [9.32 GB]
Total: 3 [27.96 GB] / in use: 2 [18.64 GB] /in no VG: 1 [9.32 GB]
三、扩展卷组vgextend 卷组名分区
[root@localhost~]# vgextend vg_data /dev/sdb2
Volume group "vg_data" successfullyextended
[root@localhost~]# vgdisplay
--- Volume group ---
VG Name vg_data
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 3
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 27.96 GB
PE Size 4.00 MB
Total PE 7158
Alloc PE / Size 4096 / 16.00 GB
Free PE / Size 3062 / 11.96 GB
VG UUID wiDQsG-rRSH-wbcW-FFkA-LHY3-fOhn-Wu8LAi
四、扩展逻辑卷lvextend -L +需要增加的大小 /dev/卷组名/逻辑卷名
lvextend -L 扩展后总的大小 /dev/卷组名/逻辑卷名
lvextend -l PE的数量 /dev/卷组名/逻辑卷名
[root@localhost~]# lvdisplay
--- Logical volume ---
LV Name /dev/vg_data/lv_mbox
VG Name vg_data
LV UUID UTkUES-zG8p-ss4j-haAD-nqtu-kYx7-KZqnGr
LV Write Access read/write
LV Status available
# open 1
LV Size 16.00 GB
Current LE 4096
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
[root@localhost~]# lvextend -l 7158 /dev/vg_data/lv_mbox
Extending logical volume lv_mbox to 27.96 GB
Logical volume lv_mbox successfully resized
[root@localhost~]# resize2fs /dev/vg_data/lv_mbox //让系统重新识别逻辑卷的大小
resize2fs1.39 (29-May-2006)
Filesystemat /dev/vg_data/lv_mbox is mounted on /mbox; on-line resizing required
Performingan on-line resize of /dev/vg_data/lv_mbox to 7329792 (4k) blocks.
Thefilesystem on /dev/vg_data/lv_mbox is now 7329792 blocks long.
结果验证
[root@localhost ~]# lvdisplay | grep "LV Size" //查看逻辑卷的大小
LV Size 27.96 GB
问题和经验总结
故障现象:无
解决办法:
本文出自 “linan” 博客,转载请与作者联系!
标签:创建及扩展逻辑卷
原文地址:http://9265519.blog.51cto.com/9255519/1566962