OpenStack计算节点的OS根分区是以lvm方式创建的
# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
host-docker centos -wi-ao---- 100.00g
host-swift centos -wi-ao---- 50.00g
host-work centos -wi-ao---- 500.00g
root centos -wi-ao---- 100.00g
samba-guest centos -wi-ao---- 20.00g
cinder-volumes-pool cinder-volumes twi-a-tz-- 475.00g 0.00 10.42
在计算节点上部署的虚拟机镜像位于云盘上,镜像中的根分区也是以lvm方式创建的,且vg组名也是centos。
创建好虚拟机后,在计算节点上就能看到两个名字都为centos的vg组
# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 2 0 wz--n- <49.00g 0
centos 2 5 0 wz--n- 836.35g 66.35g
cinder-volumes 1 1 0 wz--n- <500.00g 24.76g
root分区的lv名也相同
# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
host-docker centos -wi-ao---- 100.00g
host-swift centos -wi-ao---- 50.00g
host-work centos -wi-ao---- 500.00g
root centos -wi------- <44.00g
root centos -wi-ao---- 100.00g
samba-guest centos -wi-ao---- 20.00g
swap centos -wi------- 5.00g
cinder-volumes-pool cinder-volumes twi-a-tz-- 475.00g 0.00 10.42
同名lv影响计算节点的根分区扩容,因为扩容是以lv的名字作为参数的
可以将虚拟机镜像中的vg组名改为centos4vm以解决这个重名冲突
根据vg组的uuid来区分,镜像大小为50G,可知49G的那个vg组就是虚拟机镜像中的vg组
# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 2 0 wz--n- <49.00g 0
centos 2 5 0 wz--n- 836.35g 66.35g
cinder-volumes 1 1 0 wz--n- <500.00g 24.76g
使用vgdisplay命令找到centos vg组对应的uuid
# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size <49.00 GiB
PE Size 4.00 MiB
Total PE 12543
Alloc PE / Size 12543 / <49.00 GiB
Free PE / Size 0 / 0
VG UUID 4AJR16-jhIq-dvhM-fiQA-PMeF-neCA-PcXMTQ
使用vgrename重命名
# vgrename 4AJR16-jhIq-dvhM-fiQA-PMeF-neCA-PcXMTQ centos4vm
Processing VG centos because of matching UUID 4AJR16-jhIq-dvhM-fiQA-PMeF-neCA-PcXMTQ
Volume group "4AJR16-jhIq-dvhM-fiQA-PMeF-neCA-PcXMTQ" successfully renamed to "centos4vm"
这样虚拟机镜像中的vg组名就改成了centos4vm
# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
host-docker centos -wi-ao---- 100.00g
host-swift centos -wi-ao---- 50.00g
host-work centos -wi-ao---- 500.00g
root centos -wi-ao---- 100.00g
samba-guest centos -wi-ao---- 20.00g
root centos4vm -wi------- <44.00g
swap centos4vm -wi------- 5.00g
cinder-volumes-pool cinder-volumes twi-a-tz-- 475.00g 0.00 10.42
只是修改vg组名还不够,还要修改镜像中的grub文件和fstab文件
其中grub文件位于boot分区,fstab文件位于根分区
因此需要先挂载这两个分区
停虚拟机,使用qemu-nbd将镜像映射到nbd设备
# fdisk -l /dev/nbd0
Disk /dev/nbd0: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x00072170
Device Boot Start End Blocks Id System
/dev/nbd0p1 * 2048 2099199 1048576 83 Linux
/dev/nbd0p2 2099200 104857599 51379200 8e Linux LVM
可以看到第一个分区就是boot分区
第二个分区是lvm分区,lvm分区包括虚拟机静像的根分区
boot分区挂载参考
使用qemu-nbd修改qcow2格式的虚拟机镜像(二):挂载qcow2镜像修改镜像中文件
lvm分区挂载参考
使用qemu-nbd修改qcow2格式的虚拟机镜像(三):mount挂载qcow2镜像中的lvm分区
修改grub文件
# grep -r "centos" /boot
/boot/grub2/grub.cfg: linux16 /vmlinuz-3.10.0-1062.el7.x86_64 root=/dev/mapper/centos-root ro crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet LANG=en_US.UTF-8
/boot/grub2/grub.cfg: linux16 /vmlinuz-0-rescue-6f9bcc60986041238dcda79bfef462d5 root=/dev/mapper/centos-root ro crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet
改为
# grep -r "centos4vm" /boot
/boot/grub2/grub.cfg: linux16 /vmlinuz-3.10.0-1062.el7.x86_64 root=/dev/mapper/centos4vm-root ro crashkernel=auto rd.lvm.lv=centos4vm/root rd.lvm.lv=centos4vm/swap rhgb quiet LANG=en_US.UTF-8
/boot/grub2/grub.cfg: linux16 /vmlinuz-0-rescue-6f9bcc60986041238dcda79bfef462d5 root=/dev/mapper/centos4vm-root ro crashkernel=auto rd.lvm.lv=centos4vm/root rd.lvm.lv=centos4vm/swap rhgb quiet
修改fstab文件
# grep -r centos /etc
/etc/fstab:/dev/mapper/centos-root / xfs defaults 0 0
/etc/fstab:/dev/mapper/centos-swap swap swap defaults 0 0
改为
# grep -r centos4vm /etc
/etc/fstab:/dev/mapper/centos4vm-root / xfs defaults 0 0
/etc/fstab:/dev/mapper/centos4vm-swap swap swap defaults 0 0
修改好后,执行umount,qemu-nbd去映射。
再用该镜像起虚拟机后,就可以看到虚拟机镜像中的vg组已经改为centos4vm了