Monday, November 12, 2012

coLinux runs Debian Squeeze

Briefly...

In recent tasks I've been challenged to integrate OSS software by hand on Linux systems. By OSS software I mean projects which have not, for any number of reasons, been included in the regular distribution channels (Debian's Aptitude, for example) just yet.

These software integrations needs be hand-crafted from scratch: download the sources, build the binaries, resolve system dependencies and test they work flawlessly. More than often this can be an entertaining task and I'd like to avoid repetitive tasks, hence I was asked to set it up on coLinux, in helps for isolating the environment, have a latest OS distribution running quickly, and be able to document the integration steps without disturbing the rest of the system. coLinux can help me shield a Linux installation easily.

As a starting point I needed Debian's latest official distribution installed. It's called squeeze.

The steps I am going to explain are resumed as follows:

1. Create a root file system that bundles Debian Squeeze
2. Customize it to run inside coLinux
3. Run and go!

Building Squeeze

We'll jump into /tmp, we'll build everything inside. The idea is to create a sparse file which will hold Squeeze in an ext3 filesystem. Compressed and moved into a Windows system will then be ready for coLinux to boot it up.


root@aspirina:/tmp# dd if=/dev/zero of=./squeeze.img bs=1 count=0 seek=2GB
0+0 records in
0+0 records out
0 bytes (0 B) copied, 0 s, Infinity B/s
root@aspirina:/tmp# du -sh squeeze.img 
0       squeeze.img
root@aspirina:/tmp# du -sh --apparent-size squeeze.img 
1.9G    squeeze.img

We mount the image, create an ext3 file system on it, then install Squeeze in it from the Debian mirrors.

root@aspirina:/tmp# mkfs.ext3 -F squeeze.img 
root@aspirina:/tmp# mkdir /mnt/squeeze
root@aspirina:/tmp# losetup /dev/loop0 ./squeeze.img
root@aspirina:/tmp# mount -o loop -t ext3 /dev/loop0 /mnt/squeeze/
root@aspirina:/tmp# df -h /mnt/squeeze/
Filesystem            Size  Used Avail Use% Mounted on
/dev/loop0            1.9G   35M  1.8G   2% /mnt/squeeze
root@aspirina:/tmp# debootstrap squeeze /mnt/squeeze http://ftp.se.debian.org/debian/
root@aspirina:/tmp# cat /mnt/squeeze/etc/debian_version
6.0.6

Now, debootstrap takes its time, after which we need to twitch a few gotchas that coLinux will expect:

root@aspirina:/mnt/squeeze# mknod /mnt/squeeze/dev/cobd0 b 117 0
root@aspirina:/mnt/squeeze# mknod /mnt/squeeze/dev/cobd1 b 117 1
root@aspirina:/mnt/squeeze# mknod /mnt/squeeze/dev/cobd2 b 117 2
root@aspirina:/mnt/squeeze# mknod /mnt/squeeze/dev/cobd3 b 117 3
root@aspirina:/mnt/squeeze# echo "127.0.0.1      localhost      cosqueeze" > /mnt/squeeze/etc/hosts
root@aspirina:/mnt/squeeze# echo "cosqueeze" > /mnt/squeeze/etc/hostname
root@aspirina:/mnt/squeeze# echo  "/dev/cobd0 / ext3 defaults 0 1" > /mnt/squeeze/etc/fstab
root@aspirina:/mnt/squeeze# echo "proc /proc proc defaults 0 0" >> /mnt/squeeze/etc/fstab

root@aspirina:/mnt/squeeze# chroot .
root@aspirina:/# passwd
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
root@aspirina:/# exit
root@aspirina:/mnt/squeeze# dd if=/dev/zero of=/mnt/squeeze/zeroes

root@aspirina:/mnt/squeeze# rm zeroes

After unmounting and extracting the image, it is ready to boot it up on coLinux. You can follow up on my previous post to get a step-by-step recipe.