參考
官方:https://docs.openstack.org/image-guide/ubuntu-image.html
Installation Process
創建一臺虛擬機
以 qcow2 格式的文件爲例:
# 創建一個空的 10G qcow2 文件(10G 只要足夠安裝鏡像即可)
cd ~
qemu-img create -f qcow2 ~/demo.qcow2 10G
# 從這個空的 10G qcow2 文件,創建一個基於 ubuntu1604.iso 的虛擬機
virt-install --virt-type kvm --name demo --ram1024 \
--disk ~/demo.qcow2,bus=virtio,size=10,format=qcow2 \
--network network=default \
--graphics vnc,password=foobar,port=5910,keymap=ja,listen=0.0.0.0 \
--noautoconsole --os-type=linux --os-variant=ubuntu16.04 \
--cdrom=~/ubuntu1604.iso
安裝操作系統
根據創建虛擬機時的參數 --graphics vnc,password=foobar,port=5910,keymap=ja,listen=0.0.0.0
,登錄 VNC Viewer,訪問 127.0.0.1:5910,密碼是 foobar。此時,開始對虛擬機進行安裝操作系統。
更改域名解析【可選】
以下操作僅對支持 resolvconf 動態生成 resolv.conf 文件的系統有效,關於 nameserver、domain、search 等配置的含義可以參考如下鏈接: https://blog.csdn.net/zhuzaijava/article/details/77977666。
cd /etc/resolvconf/resolv.conf.d/
echo "nameserver x.x.x.x" >> head
echo "search x.x.x.x" >> base
安裝必要的雲主機軟件
# 更新 apt 源
apt update
# 安裝 cloud-init,用於對實例進行初始化操作
apt install cloud-init -y
apt install acid -y
apt install qemu-guest-agent -y