1. 程式人生 > >Ubuntu 1404 image for openstack

Ubuntu 1404 image for openstack

1> prepare the image with kvm

virt-install \
--name os-u1404 \
--ram 4096 \
--disk path=/var/lib/libvirt/images/os-u1404.img,format=qcow2,size=30 \
--vcpus 2 \
--os-type linux \
--os-variant ubuntutrusty \
--network bridge=br0 --graphics none  \
--console pty,target_type=serial \
--location 'http://192.168.3.17/ubuntu/dists/trusty/installer-amd64/'
--extra-args 'console=ttyS0,115200n8 serial'

通過3.17這個伺服器提供網路安裝啟動源。
啟動後選擇手工輸入安裝源, 輸入

mirrors.aliyun.com

安裝元件選取OpenSSH服務,其他服務可以不用選擇,留待需要時候再安裝。

2>update and install packages

檢查更新apt的原始檔 /etc/apt/sources.list

deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.aliyun
.com/ubuntu/ trusty-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse deb-src http://mirrors.aliyun
.com/ubuntu/ trusty main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse

更改幾個系統配置

vi /etc/ssh/ssd_config
    "PermitRootLogin yes"
----------
vi /etc/default/grub
    "GRUB_CMDLINE_LINUX_DEFAULT="console=ttyS0""
update-grub2

更新和安裝其他幾個軟體

apt-get update
apt-get install ntp acpi nmon vim-runtime 
apt-get -y dist-upgrade
reboot
shutdown -h now

備份這個映象檔案作為其他試驗的基礎。

cp /var/lib/libvirt/images/os-u1404.img /var/lib/libvirt/images/os-u1404.img.00 

3>install cloud-init and update
啟動映象

virsh  start os-u1404
virsh console os-u1404

安裝 cloud-init, 配置cloud-init去除掉不需要的監聽服務,修改使用者等等

apt-get install cloud-init
dpkg-reconfigure cloud-init

檢查更改 /etc/cloud-init/cloud.conf
然後停機

shutdown -h now

4>Prepare for openstack image
清除掉資料以便可以執行到OpenStack環境中

virt-sysprep -d os-u1404

5>upload to glance and enjoy it

qemu-img convert -O raw os-u1404.img os-u1404-raw.img
glance image-create --name "os-u1404" --file os-u1404-raw.img --disk-format raw --container-format bare --is-public True --progress