Vous êtes sur la page 1sur 12

11/1/13

[OpenStack Beginner's Guide for Ubuntu 11.04] Image Management | CSS Corp Open Source Services

CSS Corp Open Source Services

[OpenStack Beginner's Guide for Ubuntu 11.04] Image Management


with 14 comments

Image management
There are several pre-built images for OpenStack available from various sources. You can download such images and use them to get familiar with OpenStack. You can refer to http://docs.openstack.org/cactus/openstack-compute/admin/content/starting-images.html for details on using such images. For any production deployment, you may like to have the ability to bundle custom images, with a custom set of applications or configuration. This chapter will guide you through the process of creating Linux images of Debian and Redhat based distributions from scratch. We have also covered an approach to bundling Windows images. There are some minor differences in the way you would bundle a Linux image, based on the distribution. Ubuntu makes it very easy by providing cloud-init package, which can be used to take care of the instance configuration at the time of launch. cloud-init handles importing ssh keys for password-less login, setting hostname etc. The instance acquires the instance specific configuration from Nova-compute by connecting to a meta data interface running on 169.254.169.254. While creating the image of a distro that does not have cloud-init or an equivalent package, you may need to take care of importing the keys etc. by running a set of commands at boot time from rc.local. The process used for Ubuntu and Fedora is largely the same with a few minor differences, which are explained below. In both cases, the documentation below assumes that you have a working KVM installation to use for creating the images. We are using the machine called client1 as explained in the chapter on Installation and Configuration for this purpose.
cssoss.wordpress.com/2011/04/27/openstack-beginners-guide-for-ubuntu-11-04-image-management/ 1/12

11/1/13

[OpenStack Beginner's Guide for Ubuntu 11.04] Image Management | CSS Corp Open Source Services

The approach explained below will give you disk images that represent a disk without any partitions. Nova-compute can resize such disks ( including resizing the file system) based on the instance type chosen at the time of launching the instance. These images cannot have bootable flag and hence it is mandatory to have associated kernel and ramdisk images. These kernel and ramdisk images need to be used by nova-compute at the time of launching the instance. However, we have also added a small section towards the end of the chapter about creating bootable images with multiple partitions that can be be used by nova to launch an instance without the need for kernel and ramdisk images. The caveat is that while nova-compute can re-size such disks at the time of launching the instance, the file system size is not altered and hence, for all practical purposes, such disks are not re-sizable.

Creating a Linux Image Ubuntu & Fedora


The first step would be to create a raw image on Client1. This will represent the main HDD of the virtual machine, so make sure to give it as much space as you will need. 1 k v m i m gc r e a t efr a ws e r v e r . i m g5 G

OS Installation
Download the iso file of the Linux distribution you want installed in the image. The instructions below are tested on Ubuntu 11.04 Natty Narwhal 64-bit server and Fedora 14 64-bit. Most of the instructions refer to Ubuntu. The points of difference between Ubuntu and Fedora are mentioned wherever required. 1 w g e th t t p : / / r e l e a s e s . u b u n t u . c o m / n a t t y / u b u n t u 1 1 . 0 4 s e r v e r a m d 6 4 . i s o

Boot a KVM Instance with the OS installer ISO in the virtual CD-ROM. This will start the installation process. The command below also sets up a VNC display at port 0 1 s u d ok v mm2 5 6c d r o mu b u n t u 1 1 . 0 4 s e r v e r a m d 6 4 . i s od r i v e

f i l e = s e r v e r . i m

Connect to the VM through VNC (use display number :0) and finish the installation. For Example, where 10.10.10.4 is the IP address of client1: 1 v n c v i e w e r1 0 . 1 0 . 1 0 . 4: 0

cssoss.wordpress.com/2011/04/27/openstack-beginners-guide-for-ubuntu-11-04-image-management/

During the installation of Ubuntu, create a single ext4 partition mounted on /. Do not create a swap 2/12

11/1/13

[OpenStack Beginner's Guide for Ubuntu 11.04] Image Management | CSS Corp Open Source Services

During the installation of Ubuntu, create a single ext4 partition mounted on /. Do not create a swap partition. In the case of Fedora 14, the installation will not progress unless you create a swap partition. Please go ahead and create a swap partition. After finishing the installation, relaunch the VM by executing the following command. 1

s u d ok v mm2 5 6d r i v ef i l e = s e r v e r . i m g , i f = s c s i , i n d e x = 0 , b o o t = o nb o o tcn e t

At this point, you can add all the packages you want to have installed, update the installation, add users and make any configuration changes you want in your image. At the minimum, for Ubuntu you may run the following commands 1 2 3 4 5 s u d oa p t g e tu p d a t e s u d oa p t g e tu p g r a d e s u d oa p t g e ti n s t a l lo p e n s s h s e r v e rc l o u d i n i t

For Fedora run the following commands as root 1 2 3 4 5 y u mu p d a t e y u mi n s t a l lo p e n s s h s e r v e r c h k c o n f i gs s h do n

Also remove the network persistence rules from /etc/udev/rules.d as their presence will result in the network interface in the instance coming up as an interface other than eth0. 1 s u d or mr f/ e t c / u d e v / r u l e s . d / 7 0 p e r s i s t e n t n e t . r u l e s

Shutdown the Virtual machine and proceed with the next steps.

Extracting the EXT4 partition


The image that needs to be uploaded to OpenStack needs to be an ext4 filesystem image. Here are the steps to create a ext4 filesystem image from the raw image i.e server.img 1 2 3 s u d ol o s e t u p f s e r v e r . i m g s u d ol o s e t u pa

You should see an output like this:


cssoss.wordpress.com/2011/04/27/openstack-beginners-guide-for-ubuntu-11-04-image-management/ 3/12

11/1/13

[OpenStack Beginner's Guide for Ubuntu 11.04] Image Management | CSS Corp Open Source Services

/ d e v / l o o p 0 :[ 0 8 0 1 ] : 1 6 9 0 8 3 8 8( $ f i l e p a t h )

Observe the name of the loop device ( /dev/loop0 in our setup) when $filepath is the path to the mounted .raw file. Now we need to find out the starting sector of the partition. Run: 1 s u d of d i s kc u l/ d e v / l o o p 0

You should see an output like this: 1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 D i s k/ d e v / l o o p 0 :5 3 6 8M B ,5 3 6 8 7 0 9 1 2 0b y t e s 1 4 9h e a d s ,8s e c t o r s / t r a c k ,8 7 9 6c y l i n d e r s ,t o t a l1 0 4 8 5 7 6 0s e c t o r s U n i t s=s e c t o r so f1*5 1 2=5 1 2b y t e s S e c t o rs i z e( l o g i c a l / p h y s i c a l ) :5 1 2b y t e s/5 1 2b y t e s I / Os i z e( m i n i m u m / o p t i m a l ) :5 1 2b y t e s/5 1 2b y t e s D i s ki d e n t i f i e r :0 x 0 0 0 7 2 b d 4 D e v i c eB o o t / d e v / l o o p 0 p 1 * S t a r t 2 0 4 8 E n d B l o c k s I d S y s t e m 8 3 L i n u x

1 0 4 8 3 7 1 1

5 2 4 0 8 3 2

Make a note of the starting sector of the /dev/loop0p1 partition i.e the partition whose ID is 83. This number should be multiplied by 512 to obtain the correct value. In this case: 2048 x 512 = 1048576 Unmount the loop0 device: 1 s u d ol o s e t u pd/ d e v / l o o p 0

Now mount only the partition(/dev/loop0p1) of server.img which we had previously noted down, by adding the -o parameter with value previously calculated value 1 2 3 s u d ol o s e t u pfo1 0 4 8 5 7 6s e r v e r . i m g s u d ol o s e t u pa

Youll see a message like this: 1 / d e v / l o o p 0 :[ 0 8 0 1 ] : 1 6 9 0 8 3 8 8( $ f i l e p a t h )o f f s e t1 0 4 8 5 7 6

Make a note of the mount point of our device(/dev/loop0 in our setup) when $filepath is the path to the mounted .raw file. Copy the entire partition to a new .raw file 1 s u d od di f = / d e v / l o o p 0o f = s e r v e r f i n a l . i m g
4/12

cssoss.wordpress.com/2011/04/27/openstack-beginners-guide-for-ubuntu-11-04-image-management/

11/1/13

[OpenStack Beginner's Guide for Ubuntu 11.04] Image Management | CSS Corp Open Source Services

Now we have our ext4 filesystem image i.e serverfinal.img Unmount the loop0 device 1 s u d ol o s e t u pd/ d e v / l o o p 0

Tweaking /etc/fstab
You will need to tweak /etc/fstab to make it suitable for a cloud instance. Nova-compute may resize the disk at the time of launch of instances based on the instance type chosen. This can make the UUID of the disk invalid. Hence we have to use File system label as the identifier for the partition instead of the UUID. Loop mount the serverfinal.img, by running 1 s u d om o u n tol o o ps e r v e r f i n a l . i m g/ m n t

Edit /mnt/etc/fstab and modify the line for mounting root partition(which may look like the following) 1 to 1 L A B E L = u e c r o o t f s / e x t 4 d e f a u l t s 0 U U I D = e 7 f 5 a f 8 d 5 d 9 6 4 5 c c a 0 f c d 0 d 1 b d e 8 f 3 1 c / e x t 4

e r r o r s = r e

Fetching Metadata in Fedora


Since, Fedora does not ship with cloud-init or an equivalent, you will need to take a few steps to have the instance fetch the meta data like ssh keys etc. Edit the /etc/rc.local file and add the following lines before the line touch /var/lock/subsys/local 1 2 3 4 5 6 7 8 9 1 0 d e p m o da m o d p r o b ea c p i p h p

#s i m p l ea t t e m p tt og e tt h eu s e rs s hk e yu s i n gt h em e t a d a t as e r v i c e m k d i rp/ r o o t / . s s h e c h o> >/ r o o t / . s s h / a u t h o r i z e d _ k e y s c u r lm1 0sh t t p : / / 1 6 9 . 2 5 4 . 1 6 9 . 2 5 4 / l a t e s t / m e t a d a t a / p u b l i c k e y s / 0 / o p e n s s h e c h o" A U T H O R I Z E D _ K E Y S : " e c h o" * * * * * * * * * * * * * * * * * * * * * * * * " c a t/ r o o t / . s s h / a u t h o r i z e d _ k e y s


5/12

cssoss.wordpress.com/2011/04/27/openstack-beginners-guide-for-ubuntu-11-04-image-management/

11/1/13

[OpenStack Beginner's Guide for Ubuntu 11.04] Image Management | CSS Corp Open Source Services

1 1

e c h o" * * * * * * * * * * * * * * * * * * * * * * * * "

Kernel and Initrd for OpenStack


Copy the kernel and the initrd image from /mnt/boot to user home directory. These will be used later for creating and uploading a complete virtual image to OpenStack. 1 2 3 s u d oc p/ m n t / b o o t / v m l i n u z 2 . 6 . 3 8 7 s e r v e r/ h o m e / l o c a l a d m i n s u d oc p/ m n t / b o o t / i n i t r d . i m g 2 . 6 . 3 8 7 s e r v e r/ h o m e / l o c a l a d m i n

Unmount the Loop partition 1 s u d ou m o u n t / m n t

Change the filesystem label of serverfinal.img to uec-rootfs 1 s u d ot u n e 2 f sLu e c r o o t f ss e r v e r f i n a l . i m g

Now, we have all the components of the image ready to be uploaded to OpenStack imaging server.

Registering with OpenStack


The last step would be to upload the images to Openstack Imaging Server glance. The files that need to be uploaded for the above sample setup of Ubuntu are: vmlinuz-2.6.38-7-server, initrd.img-2.6.38-7server, serverfinal.img Run the following command 1

u e c p u b l i s h i m a g eti m a g ek e r n e l f i l ev m l i n u z 2 . 6 . 3 8 7 s e r v e rr a m d i s k f

For Fedora, the process will be similar. Make sure that you use the right kernel and initrd files extracted above. uec-publish-image, like several other commands from euca2ools, returns the prompt back immediately. However, the upload process takes some time and the images will be usable only after the process is complete. You can keep checking the status using the command euca-describe-images as mentioned below.

cssoss.wordpress.com/2011/04/27/openstack-beginners-guide-for-ubuntu-11-04-image-management/

6/12

11/1/13

[OpenStack Beginner's Guide for Ubuntu 11.04] Image Management | CSS Corp Open Source Services

Bootable Images
You can register bootable disk images without associating kernel and ramdisk images. When you do not want the flexibility of using the same disk image with different kernel/ramdisk images, you can go for bootable disk images. This greatly simplifies the process of bundling and registering the images. However, the caveats mentioned in the introduction to this chapter apply. Please note that the instructions below use server.img and you can skip all the cumbersome steps related to extracting the single ext4 partition. 1 2 3 e u c a b u n d l e i m a g eis e r v e r . i m g e u c a u p l o a d b u n d l ebm y b u c k e tm/ t m p / s e r v e r . i m g . m a n i f e s t . x m l e u c a r e g i s t e rm y b u c k e t / s e r v e r . i m g . m a n i f e s t . x m l

Image Listing
The status of the images that have been uploaded can be viewed by using euca-describe-images command. The output should like this: 1 2 3 4 5 6 7 8 9 l o c a l a d m i n @ c l i e n t 1 : ~ $e u c a d e s c r i b e i m a g e s I M A G E I M A G E I M A G E a r i 7 b f a c 8 5 9 a m i 5 e 1 7 e b 9 d a k i 3 d 0 a e b 0 8

b u c k e t 1 / i n i t r d . i m g 2 . 6 . 3 8 7 s e r v e r . m a n i f e s t . x m l c s s b u c k e t 1 / s e r v e r f i n a l . i m g . m a n i f e s t . x m l c s s

b u c k e t 1 / v m l i n u z 2 . 6 . 3 8 7 s e r v e r . m a n i f e s t . x m l

c s s

l o c a l a d m i n @ c l i e n t 1 : ~ $

Creating a Windows Image


The first step would be to create a raw image on Client1, this will represent the main HDD of the virtual machine, so make sure to give it as much space as you will need. 1 k v m i m gc r e a t efr a ww i n d o w s s e r v e r . i m g2 0 G

cssoss.wordpress.com/2011/04/27/openstack-beginners-guide-for-ubuntu-11-04-image-management/

OpenStack presents the disk using aVIRTIO interface while launching the instance. Hence the OS

7/12

11/1/13

[OpenStack Beginner's Guide for Ubuntu 11.04] Image Management | CSS Corp Open Source Services

OpenStack presents the disk using aVIRTIO interface while launching the instance. Hence the OS needs to have drivers for VIRTIO. By default, the Windows Server 2008 ISO does not have the drivers for VIRTIO. Sso download a virtual floppy drive containing VIRTIO drivers from the following location http://alt.fedoraproject.org/pub/alt/virtio-win/latest/images/bin/ and attach it during the installation Start the installation by running 1

s u d ok v mm1 0 2 4c d r o mw i n 2 k 8 _ d v d . i s od r i v ef i l e = w i n d o w s s e r v e r . i m g , i f = v i r t

When the installation prompts you to choose a hard disk device you wont see any devices available. Click on Load drivers at the bottom left and load the drivers from A:\i386\Win2008 After the Installation is over, boot into it once and install any additional applications you need to install and make any configuration changes you need to make. Also ensure that RDP is enabled as that would be the only way you can connect to a running instance of Windows. Windows firewall needs to be configured to allow incoming ICMP and RDP connections. For OpenStack to allow incoming RDP Connections, use euca-authorize command to open up port 3389 as described in the chapter on Security. Shut-down the VM and upload the image to OpenStack 1 2 3 e u c a b u n d l e i m a g eiw i n d o w s s e r v e r . i m g e u c a u p l o a d b u n d l ebm y b u c k e tm/ t m p / w i n d o w s s e r v e r . i m g . m a n i f e s t . x m l e u c a r e g i s t e rm y b u c k e t / w i n d o w s s e r v e r . i m g . m a n i f e s t . x m l

Written by cssoss April 27, 2011 at 2:59 pm Posted in KVM, Natty Narhwal, OpenStack, OpenStack Book, OpenStack Documentation, OpenStack Guide, OpenStack Manual, OpenStack Ubuntu, Private Cloud, Ubuntu, UEC, UEC Book, UEC Documentation, UEC Guide, Uncategorized, Virtualization

14 Responses
Subscribe to comments with RSS. Thanks! this made my day ! Excelent posting! alejandro
cssoss.wordpress.com/2011/04/27/openstack-beginners-guide-for-ubuntu-11-04-image-management/ 8/12

11/1/13

[OpenStack Beginner's Guide for Ubuntu 11.04] Image Management | CSS Corp Open Source Services

May 26, 2011 at 3:51 am Reply I can run win2008 instance, but I can not ping its ip successful jameszhou May 27, 2011 at 9:16 am Reply Hi, The security group which you specify while launching an instance needs to have a rule which allows incoming ICMP connections. Have a look at this chapter for more details http://cssoss.wordpress.com/2011/04/28/openstack-beginners-guide-for-ubuntu-11-04-security/ suseendranrengabashyam May 30, 2011 at 11:59 am Hi, the Bootable Images doesnt seem to work in a VLAN mode. While the image successfully register, and the instance seen as running, euca-get-console-output returns nothing, and the instance is unreacheable. To me it seems to be related to the fact that you dont bundle the ari and aki with the image. Razique June 15, 2011 at 2:08 pm Reply Hi Razique, The Bootable Images topic is a hack to skip the steps related to extracting the ext4 partition. If you want an image that is similar to OpenStack pre-bulit images and one which works fine in different networking modes, please read all the topics mentioned above Bootable Images. suseendranrengabashyam July 4, 2011 at 4:15 pm Reply Hi, Its finally working, I suspect the image-registering process went fubar due to and out-ofdisk-space issue. Actually, I hadnt sufficient space on the cloud-controller for the euca-register (which takes twice the size of the image, so I ended with a corrupted image) Thanks a lot for that great guide.
cssoss.wordpress.com/2011/04/27/openstack-beginners-guide-for-ubuntu-11-04-image-management/ 9/12

Reply

11/1/13

[OpenStack Beginner's Guide for Ubuntu 11.04] Image Management | CSS Corp Open Source Services

raziquemahroua September 12, 2011 at 9:48 pm I got to step Tweaking /etc/fstab and mounted serverfinal.img to /mnt, but I could not find /etc/fstab there. Some files/folders in the /mnt: abi-2.6.38-8-server config-2.6.38-8-server grub initrd.img-2.6.38-8-server lost+found memtest86+.bin memtest86+_multiboot.bin System.map-2.6.38-8-server vmcoreinfo-2.6.38-8-server vmlinuz-2.6.38-8-server How can I edit /mnt/etc/fstab ? BTW, thank you very much for the post Nhn Trn July 11, 2011 at 8:35 pm Reply Please ignore my previous comment. I have got the issue because I did not follow strictly the instruction: During the installation of Ubuntu, create a single ext4 partition mounted on /. Do not create a swap partition. Thanks. Nhn Trn July 11, 2011 at 10:59 pm Reply [...] http://cssoss.wordpress.com/2011/04/27/openstack-beginners-guide-for-ubuntu-11-04-imagemanagement/ [...] OpenStack JavaChen Blog July 12, 2011 at 7:16 pm
cssoss.wordpress.com/2011/04/27/openstack-beginners-guide-for-ubuntu-11-04-image-management/ 10/12

11/1/13

[OpenStack Beginner's Guide for Ubuntu 11.04] Image Management | CSS Corp Open Source Services

Reply I am trying this command based on your guidelines: uec-publish-image -t image kernel-file vmlinuz-2.6.38-8-server ramdisk-file initrd.img-2.6.38-8server amd64 ubuntu-114-svr-final.img bucket1 I get back: failed to check for existing manifest failed to register vmlinuz-2.6.38-8-server All previous steps work fine. I also tried the Bootable Image option which did work. Shannon August 16, 2011 at 11:43 pm Reply It worked for using root account. Kirby February 1, 2012 at 6:19 am Reply Im trying to execute following command. sudo uec-publish-image -v -t image kernel-file vmlinuz-2.6.38-8-server x86_64 serverfinal.img bucket1 but I am getting the error like: failed to check for existing manifest failed to register vmlinuz-2.6.38-8-server Any Suggestion Please. I executed all the steps on client1. Anuj September 20, 2011 at 7:24 pm Reply Hi. I was faced with the same error message and did this to resolve. source /home/localadmin/creds/novarc Trempest October 4, 2011 at 9:45 am Reply I got the same error as above failed to check for existing manifest A
cssoss.wordpress.com/2011/04/27/openstack-beginners-guide-for-ubuntu-11-04-image-management/ 11/12

11/1/13

[OpenStack Beginner's Guide for Ubuntu 11.04] Image Management | CSS Corp Open Source Services

October 20, 2011 at 2:06 am Reply

Blog at WordPress.com . The Journalist v1.9 Theme.

cssoss.wordpress.com/2011/04/27/openstack-beginners-guide-for-ubuntu-11-04-image-management/

12/12

Vous aimerez peut-être aussi