1. 创建bootable-volume(参考:http://docs.openstack.org/grizzly/openstack-compute/admin/content/instance-creation.html)
# nova image-list
+--------------------------------------+----------------------------+--------+--------------------------------------+
| ID | Name | Status | Server |
+--------------------------------------+----------------------------+--------+--------------------------------------+
| 66a81a2c-617f-40ee-b1cb-4a3bd4a82c6e | Cirros | ACTIVE | |
+--------------------------------------+----------------------------+--------+--------------------------------------+
# cinder create --image-id 66a81a2c-617f-40ee-b1cb-4a3bd4a82c6e --display-name my-bootable-vol 1
+----------------------------+--------------------------------------------------------+
| Property | Value |
+----------------------------+--------------------------------------------------------+
| attachments | [ ] |
| availability_zone | nova |
| bootable | false |
| created_at | 2013-12-19T02:45:06.333752 |
| display_description | None |
| display_name | my-bootable-vol |
| id | d586ebfa-6d5b-4e11-a3ea-1a6bbc15810c |
| image_id | 66a81a2c-617f-40ee-b1cb-4a3bd4a82c6e |
| metadata | {} |
| size | 1 |
| snapshot_id | None |
| source_volid | None |
| status | creating |
| volume_type | None |
+----------------------------+---------------------------------------------------------+
# nova boot --flavor 1 --block_device_mapping vda=d586ebfa-6d5b-4e11-a3ea-1a6bbc15810c:::0 boot-from-vol-test
创建完成。可以从dashboard看到instance已经启动。需要注意的是,此处没有设置网络相关信息,因此默认启动会为instance添加多个子网地址。且网络连接有问题。
2. 对比常规启动与从volume启动后产生的文件(默认配置)
2.1 常规启动boot from image
计算节点上的/var/lib/nova/instances/$INSTANCE-ID/下,分别有
# ls
console.log disk libvirt.xml
三个文件。
其中,disk文件为如下类型:
# file disk
disk: QEMU QCOW Image (v2), has backing file (path /var/lib/nova/instances/_base/0e8a303db3b94bc744faf3c6564e1f056), 41126400 bytes
查看0e8a303db3b94bc744faf3c6564e1f0567b3c6ca:
# file 0e8a303db3b94bc744faf3c6564e1f0567b3c6ca
0e8a303db3b94bc744faf3c6564e1f0567b3c6ca: x86 boot sector; GRand Unified Bootloader, stage1 version 0x3, stage2 address 0x2000, stage2 segment 0x200; partition 1: ID=0x83, active, starthead 0, startsector 16065, 64260 sectors, code offset 0x48
此时查看该instance启动时所选择的image文件情况。在控制节点/var/lib/glance/images/下:
# file 66a81a2c-617f-40ee-b1cb-4a3bd4a82c6e
66a81a2c-617f-40ee-b1cb-4a3bd4a82c6e: QEMU QCOW Image (v2), 41126400 bytes
将文件转化为raw格式:
#qemu-img convert -f qcow2 66a81a2c-617f-40ee-b1cb-4a3bd4a82c6e -O raw cirros.raw
查看cirros.raw:
# file cirros.raw
cirros.raw: x86 boot sector; GRand Unified Bootloader, stage1 version 0x3, stage2 address 0x2000, stage2 segment 0x200; partition 1: ID=0x83, active, starthead 0, startsector 16065, 64260 sectors, code offset 0x48
这下,instance启动时的文件及其与使用的image文件之间的关系与存放方式就清楚啦。
2.2 boot from bootable-volume
在dashboard里查到boot-from-vol-test的ID为327d741d-b335-45c2-b212-5a460df82da8。
# ls /var/lib/nova/instances/327d741d-b335-45c2-b212-5a460df82da8
console.log libvirt.xml
咦?里面没有disk文件。那所启动的系统数据究竟在哪里呢?当然是在volume上。
文章开头使用cinder create创建的my-bootable-vol的ID为d586ebfa-6d5b-4e11-a3ea-1a6bbc15810c。
# cat /var/lib/cinder/volumes/volume-d586ebfa-6d5b-4e11-a3ea-1a6bbc15810c
<target iqn.2010-10.org.openstack:volume-d586ebfa-6d5b-4e11-a3ea-1a6bbc15810c>
backing-store /dev/cinder-volumes/volume-d586ebfa-6d5b-4e11-a3ea-1a6bbc15810c
IncomingUser FxNZkBj8nF3HawSYnB8E ZeqGgjDXkSNR4c7gBt4L
</target>
只要对虚拟机做有效操作,都可以看到/dev/cinder-volumes/volume-d586ebfa-6d5b-4e11-a3ea-1a6bbc15810c对应的/dev/dm-6发生改变。