不做第二个别人,永远做第一个自己。
分类: 云计算
2014-06-04 11:42:37
his is a short summary of steps you can use to successfully build CentOS and Fedora images capable of take advantage of Openstack's elasticity.
In the end, you'll have images that resize the root partition automatically and small enough to serve as base for your instances.
I'm showing two different methods since for CentOS I used and for Fedora I used cloud-utils-growpart.
For the steps shown here, be sure you have at least the following requirements already:
yum groupinstall -y @virtualization
yum install -y libguestfs-tools-c
Special thanks to Allan St. George, Kashyap and the RDO maillist for the tips when I was asking about this topic. :)
$ qemu-img create -f qcow2 /tmp/centos-6.5-working.qcow2 10G $ virt-install --virt-type kvm --name centos-6.5 --ram 1024 \ --cdrom=/tmp/CentOS-6.5-x86_64-minimal.iso \ --disk /tmp/centos-6.5-working.qcow2,format=qcow2 \ --network network=default \ --graphics vnc,listen=0.0.0.0 --noautoconsole \ --os-type=linux --os-variant=rhel6
TYPE=Ethernet DEVICE=eth0 ONBOOT=yes BOOTPROTO=dhcp NM_CONTROLLED=no
$ yum install -y
$ yum -y distro-sync
yum install -y cloud-utils cloud-init parted git
cd /tmp git clone cd linux-rootfs-resize ./install
- resolv-conf
NOZERCONF=yes
$ poweroff
$ virt-sysprep -d centos-6.5
$ virt-sparsify --compress /tmp/centos-6.5-working.qcow2 centos-6.5-cloud.qcow2
You're done!
The image centos-6.5-cloud.qcow2 is ready to be uploaded to Openstack.
An extra note though, virt-sparsify by default uses /tmp as temporary directory to make the sparse by creating an overlay temporary file which, depending on the original image, can be quite large, also some systems mount /tmp in tmpfs which mean it'll use your ram. If you don't have enough space you can export the variable TMPDIR pointing to a dir with enough space before runing virt-sparsify, as in:
$ export TMPDIR="/some/dir/with/enough/space"