Minimal Debian GNU/Linux wheezy bootable image for OpenStack

A Debian GNU/Linux Wheezy Beta 2 AMI is uploaded to OpenStack. It really is an Ext4 file system that OpenStack will resize to use all the size of the primary disk of the instance. An AMI is made of three files, the kernel (the AKI), the ramdisk (the ARI) used at boot time and the file system to boot from (the AMI). In OpenStack, the AMI is specified to the nova boot … –image command line.

# glance index name='Debian GNU/Linux Wheezy Beta2'
ID
------------------------------------
a8f86804-3927-419e-9612-ad35cbafefa0
 Name                           Disk Format          Container Format
 ------------------------------ -------------------- --------------------
 Debian GNU/Linux Wheezy Beta2  ami                  ami

It contains references to the required AKI and ARI, as shown below:

# nova image-show a8f86804-3927-419e-9612-ad35cbafefa0
+---------------------+--------------------------------------+
|       Property      |                Value                 |
+---------------------+--------------------------------------+
| created             | 2012-09-30T15:26:43Z                 |
| id                  | a8f86804-3927-419e-9612-ad35cbafefa0 |
| metadata  kernel_id | 2e714ea3-45e5-4bb8-ab5d-92bfff64ad28 |
| metadata ramdisk_id | 6458acca-24ef-4568-bb2b-e52322a5a11c |
| minDisk             | 0                                    |
| minRam              | 0                                    |
| name                | Debian GNU/Linux Wheezy Beta2        |
| progress            | 100                                  |
| status              | ACTIVE                               |
| updated             | 2012-09-30T15:26:45Z                 |
+---------------------+--------------------------------------+


A 1G disk image is initialized with:

# kvm-img create -f raw server.img 1G

The wheezy ISO image is downloaded:

# wget http://cdimage.debian.org/cdimage/wheezy_di_beta2/amd64/iso-cd/debian-wheezy-DI-b2-amd64-netinst.iso

It is booted with kvm:

# kvm -m 256 -cdrom debian-wheezy-DI-b2-amd64-netinst.iso \
  -drive file=server.img,if=scsi,index=0 -boot d -net nic \
  -net user -vnc :0

And installed interactively with

# xtightvncviewer :0

so that it uses a single primary partition of the disk. There is no need to setup the users, the user key will be injected in the /root/.ssh/authorized_key file by OpenStack itself. The partition is then extracted with:

# kpartx -av server.img
# dd if=/dev/mapper/loop0p1 of=wheezy.tmp

The minimum size of the partition is calculated, to further reduce the size of the image with:

# resize2fs -P wheezy.tmp
resize2fs 1.42.5 (29-Jul-2012)
Estimated minimum size of the filesystem: 148279

and the file is cropped accordingly with

# dd if=wheezy.tmp of=wheezy count=148279 bs=4k

and checked for consistency with:

# fsck.ext4 -f wheezy
e2fsck 1.42.5 (29-Jul-2012)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
wheezy: 21808/40880 files (0.5% non-contiguous), 141610/148458 blocks
# ls -lh wheezy
-rw-r--r-- 1 root root 580M Sep 30 17:48 wheezy

The file system is then mounted to get access to the files it contains:

# mount wheezy /mnt

The kernel and the initrd files are first uploaded to glance with:

# mount /var/lib/nova/wheezy /mnt
# glance add is_public=true name='initrd-3.2.0-3-amd64' \
  disk_format=ari  container_format=ari < /mnt/boot/initrd.img-3.2.0-3-amd64
Uploading image 'initrd-3.2.0-3-amd64'
Added new image with ID: 6458acca-24ef-4568-bb2b-e52322a5a11c

# glance add is_public=true name='vmlinuz-3.2.0-3-amd64' \
disk_format=aki container_format=aki \
< /mnt/boot/vmlinuz-3.2.0-3-amd64
Uploading image 'vmlinuz-3.2.0-3-amd64'
Added new image with ID: 2e714ea3-45e5-4bb8-ab5d-92bfff64ad28
# umount /mnt

and associated to the file system contained in the wheezy file with:

# glance add is_public=true name='Debian GNU/Linux Wheezy Beta2' \
  disk_format=ami container_format=ami \
  kernel_id=2e714ea3-45e5-4bb8-ab5d-92bfff64ad28 \
  ramdisk_id=6458acca-24ef-4568-bb2b-e52322a5a11c \
  < /var/lib/nova/wheezy
Uploading image 'Debian GNU/Linux Wheezy Beta2'
Added new image with ID: a8f86804-3927-419e-9612-ad35cbafefa0

And check that all is set as expected with

# nova image-list | grep 3.2.0
| 2e714ea3-45e5-4bb8-ab5d-92bfff64ad28 | vmlinuz-3.2.0-3-amd64         | ACTIVE |        |
| 6458acca-24ef-4568-bb2b-e52322a5a11c | initrd-3.2.0-3-amd64          | ACTIVE |        |
# nova image-show a8f86804-3927-419e-9612-ad35cbafefa0
+---------------------+--------------------------------------+
|       Property      |                Value                 |
+---------------------+--------------------------------------+
| created             | 2012-09-30T15:26:43Z                 |
| id                  | a8f86804-3927-419e-9612-ad35cbafefa0 |
| metadata kernel_id  | 2e714ea3-45e5-4bb8-ab5d-92bfff64ad28 |
| metadata ramdisk_id | 6458acca-24ef-4568-bb2b-e52322a5a11c |
| minDisk             | 0                                    |
| minRam              | 0                                    |
| name                | Debian GNU/Linux Wheezy Beta2        |
| progress            | 100                                  |
| status              | ACTIVE                               |
| updated             | 2012-09-30T15:26:45Z                 |
+---------------------+--------------------------------------+

It is then used to create a new instance and check that it actually works:

# nova boot --image a8f86804-3927-419e-9612-ad35cbafefa0 \
 --flavor 7 --key_name loic --availability_zone=bm0002 --poll razor
# nova list
+--------------------------------------+-------+--------+------------------------+
|                  ID                  |  Name | Status |        Networks        |
+--------------------------------------+-------+--------+------------------------+
| d4bde55e-87e0-4c9e-adf7-35a294e02485 | razor | ACTIVE | novanetwork=10.145.6.3 |
+--------------------------------------+-------+--------+------------------------+
# ssh -t -A root@bm0002.the.re ssh root@10.145.6.3
Linux wheezy 3.2.0-3-amd64 #1 SMP Mon Jul 23 02:45:17 UTC 2012 x86_64
...
root@wheezy:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
rootfs           10G  693M  9.4G   7% /
udev             10M     0   10M   0% /dev
tmpfs            50M  156K   50M   1% /run
/dev/vda         10G  693M  9.4G   7% /
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           100M     0  100M   0% /run/shm
root@wheezy:~#
This entry was posted in Essex, Wheezy, debian, openstack. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>