當在虛擬機中安裝有軟件后,為了使用鏡像創建虛擬機不再安裝軟件,而是創建后就會自動安裝,需要將原虛擬機導出為鏡像。
如下虛擬機,修改密碼后,重新打成鏡像,創建出虛擬機后,使用新密碼登錄
查詢出鏡像所在位置,執行qemu-img convert -c -O qcow2 /var/lib/nova/instances/c4fcf7dd-74db-4091-93d8-d611248553eb/disk caesar.qcow2 -p 將鏡像轉化為想要的名稱*.qcow2
創建鏡像 glance image-create --name river --visibility public --container-format bare --disk-format qcow2 --file ./caesar.qcow2
創建虛擬機 nova boot river --image 5808f608-2b30-4b65-8c2f-436b4d2b5734 --nic net-id=ffe7b6bc-1e0f-457f-b09b-8e1c5b74db6c --flavor 1
登錄虛擬機,使用新密碼登錄,且在原來虛擬機中創建的文件caesar.txt。使用鏡像創建的虛擬機中也存在。
以上是使用本地盤,若使用cinder 卷,需要使用 cinder upload-to-image --container-format bare --disk-format qcow2 <卷id>d40205f9-ecef-491b-90b8-2ce12c6fbb7c <鏡像名> cirros 更新鏡像,並使用 glance image-download <鏡像id> --file <下載位置> 下載此鏡像供后續使用。
創建虛擬機 nova boot --flavor 1 --block-device source=image, id=5808f608-2b30-4b65-8c2f-436b4d2b5734,dest=volume,size=1,shutdown=preserve,bootindex=0 hill
基於image創建block volume,然后從這個volume中boot instance hill,shutdown選項選為preserve, 在instance關閉時, volume會被save下來;其中size選項要求大於等於flavor中的disk大小。
虛擬機使用lvm,如下
登錄虛擬機,在caesar.txt文件中添加如下,並更新鏡像
使用新鏡像,創建虛擬機(本地盤),並 novnc登錄虛擬機,檢查caesar.txt文件