功能
物理卷管理
卷组管理
逻辑卷管理
扫描 scan
pvscan
vgscan
lvscan
建立 create
pvcreate
vgcreate
lvcreate
显示 display
pvdisplay
vgdisplay
lvdisplay
删除 remove
pvremove
vgremove
lvremove
扩展 extend
vgextend
lvextend
减少 reduce
vgreduce
lvreduce
LVM(Logical Volume Manager),逻辑卷管理
(1)作用:动态调整磁盘容量,从而提高磁盘管理的灵活性
(2)注意:/boot 分区用于存放引导文件,不能基于 LVM 创建
(1)PV(Physical Volume),物理卷 整个硬盘,或使用 fdisk 等工具建立的普通分区。
包括许多默认 4M 大小的 PE(Physical Extent,基本单元/物理单元)。
(2)VG(Volume Group),卷组。
(3)LV(Logical Volume),逻辑卷 从卷组中分割出的一块空间,用于建立文件系统。
常用命令:
(1)创建物理卷 pvcreate 命令
1>格式:pvcreate 设备 1 [设备 2 ……]
2>示例:
[root@www ~]# pvcreate /dev/sd[bcde]1 Physical volume "/dev/sdb1" successfully created Physical volume "/dev/sdc1" successfully created Physical volume "/dev/sdd1" successfully created Physical volume "/dev/sde1" successfully created(2)创建卷组 vgcreate 命令
1>格式:vgcreate 卷组名 物理卷名 1 物理卷名 2… 选项–s 指定 PE 大小(单位 M)
2>示例:
[root@www ~]# vgcreate -s 8 vg0 /dev/sd[bcde]1 Volume group "vg0" successfully created [root@www ~]# vgdisplay /dev/vg0 --- Volume group --- VG Name vg0 System ID Format lvm2 Metadata Areas 4 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 4 Act PV 4 VG Size 79.97 GiB PE Size 8.00 MiB Total PE 10236 Alloc PE / Size 0 / 0 Free PE / Size 10236 / 79.97 GiB VG UUID 5gTGNW-XWYN-hNKj-Fn4L-ehS2-fCIW-RQuIB8(3)创建逻辑卷 lvcreate 命令
1>格式:lvcreate –L 容量大小 (–l 指定 PE 个数) –n 逻辑卷名 卷组名
2>示例:
[root@www ~]# lvcreate -L 20G -n xuexi vg0 Logical volume "xuexi" created 或:[root@www ~]# lvcreate -l 50000 -n xuexi vg0(4)扩展逻辑卷 lvextend 命令
1>格式:lvextend –L +大小或直接写增加后的最终大小 /dev/卷组名/逻辑卷名
2>示例:
[root@www ~]# lvextend -L +5G /dev/vg0/xuexi Extending logical volume xuexi to 25.00 GiB Logical volume xuexi successfully resized [root@www ~]# lvextend -L 30G /dev/vg0/xuexi Extending logical volume xuexi to 30.00 GiB Logical volume xuexi successfully resized(5)调整(刷新)逻辑卷分区大小
1>格式:resize2fs /dev/卷组名/逻辑卷名
2>示例:
resize2fs /dev/vg0/xuexi resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/vg0/xuexi is mounted on /xuexi; on-line resizing required old desc_blocks = 1, new_desc_blocks = 2 Performing an on-line resize of /dev/vg0/xuexi to 5242880 (4k) blocks. The filesystem on /dev/vg0/xuexi is now 5242880 blocks long1、查看 vg(vgdisplay):
2、创建 lv_home(lvcreate -l 114686 -n lv_home vg_xxxx):
命令中 -l 后面的就是 vg 中空余的 PE 个数,-n 就是创建的 lv 名称,vg_xxxx 就是卷组。
3、格式化新创建的 LV(mkfs -t ext4 /dev/vg_xxxx/lv_home):
4、挂载(mount /dev/vg_xxxx/lv_home /home):
执行 ‘df -h’ 可以看到逻辑卷已添加:
5、设置开机自动挂载:
修改 /etc/fstab 文件添加如下一行:
/dev/mapper/vg_topslave2-lv_home /home ext4 defaults 1 2defaults 表示默认,其他的还有:
defaults:默认 auto:系统自动挂载,fstab 默认就是这个选项 noauto:开机不自动挂载 nouser:只有超级用户可以挂载 ro:按制度权限挂载 rw:按可读可写权限挂载 user:任何用户都可以挂载defaults 后面是 dump 备份设置。1 表示允许 dump 备份程序备份;设置为 0 时,忽略备份操作。
1 后面的 2 是 fsck 磁盘检查设置。其值是一个顺序,当其值为 0 时,永远不检查;而 / 根目录分区永远都为 1,其他分区 一般为 2。
执行 ‘lvextend -L +36G /dev/mapper/vg_topslave2-lv_root’ 时报错:
Couldn't find device with uuid JbDYxI-aS9a-HHei-syZj-CKXr-uB3o-5h0tKS. Cannot change VG vg_topslave2 while PVs are missing. Consider vgreduce --removemissing.解决办法:
1、执行 ‘pvscan’:
发现一个 unknown device ,这是由于曾创建的 pv 被删除或者创建失败出现的。
2、执行 ‘vgreduce --removemissing --test --verbose vg_topslave2’:
这里加了一个 test ,这很重要。在正式操作之前使用方便查看结果,不然删错数据那 。。。
正式操作 ‘vgreduce --removemissing --verbose vg_topslave2’:
然后再执行 ‘pvscan’:
发现卷错误已经没有了,这时候就可以正常的扩展 lv 了。
执行 ‘pvcreate /dev/sda3’ 时报错:
Can't initialize physical volume "/dev/sda3" of volume group "vg_topslave2" without -ff解决办法:
将创建命令改为:
pvcreate -ff -y /dev/sda3