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