安裝init-cloud
使用 apt-get 即可進(jìn)行安裝
sudo apt-get install init-cloud
配置文件目錄為 /etc/cloud/
其中 /etc/cloud/cloud.cfg.d/90_dpkg.cfg為配置元數(shù)據(jù)選項(xiàng),使用命令
dkpg-reconfigure cloud-init
可以更改此文件

image.png
使用空格更改選項(xiàng),僅保留“NoCloud” 一項(xiàng)
制作Nocloud 數(shù)據(jù)源
- 編輯元數(shù)據(jù)
創(chuàng)建 my-meta-data 文件,并寫入一下內(nèi)容
instance-id: iid-local03
local-hostname: ubuntu-server
instance-id為實(shí)例標(biāo)號(hào),只有其發(fā)生變化的時(shí)候,才會(huì)運(yùn)行init-cloud
創(chuàng)建 my-user-data 文件,并寫入以下內(nèi)容
#cloud-config
chpasswd:
list: |
ubuntu:123456
expire: false
即使用cloud-config 配置模式,使用chpasswd 模塊進(jìn)行修改密碼:將ubuntu的密碼修改為123456
- 生成鏡像
將my-user-data及my-meta-data文件生成為my-seed.img 數(shù)據(jù)
cloud-localds my-seed.img my-user-data my-meta-data
啟動(dòng)虛擬機(jī)
編輯虛擬機(jī)啟動(dòng)xml文件,掛載/my-seed.img鏡像
<disk type='file' device='disk' cache='none'>
<driver name='qemu' type='raw'/>
<source file='/my-seed.img'/>
<target dev='hdc' bus='virtio'/>
<readonly/>
</disk>