linux-本地虛擬機(jī)使用cloud-init

安裝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ù)源

  1. 編輯元數(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

  1. 生成鏡像
    將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>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容