Archive for October, 2008

Boot Ubuntu in 19 Seconds

October 30th, 2008 No comments

Want your Ubuntu to boot more quickly? Read this.

There are also links to solutions to the odd “resume” problems I was experiencing: “no resume image” on my swap partition.

Categories: Uncategorized Tags:

Copy Files Using Windows Remote Desktop

October 30th, 2008 No comments

Here’s a great tip for copying files from your desktop to EC2 (or any remote Windows server). Posted on Amazon’s EC2 forum by P. Hebert:

“Before you connect to the instance, wander through the tabs and find check the box under “Local drives and resources” for your C: drive. Once connected to the instance, open Windows Explorer and in the address bar, type “tsclientc” (without quotes). your local PC’s C: drive will (slowly) open up in Explorer and you can drag&drop.”

“This doesn’t require any additional ports to be opened up; it goes over the RDP connection you already using for remote desktop. ”

Categories: Uncategorized Tags:

UUID in /etc/fstab

October 29th, 2008 No comments

While I understood the value of using UUIDs to specify devices in /etc/fstab, it wasn’t clear how it all worked. After a bit of googling …

When a device is connected, the system automatically retrieves its UUID, regardless of which interface is used. The list of currently available devices can be displayed with:

ls /dev/disk/by-uuid -lh

Currently available block device ids can be displayed using blkid and attributes of individual devices is displayed by vol_id /dev/name.

Also, blkid information is cached in /etc/

Very important: if you clone drives with dd, the UUID will be cloned too! If this isn’t what you had in mind, reset it using:

tune2fs -U UUID /dev/name

where UUID is one of the following:
a unique id like “c1b9d5a2-f162-11cf-9ece-0020afc76f16”
or clear, random or time.

Categories: Uncategorized Tags:

Concurrency from Microsoft

October 29th, 2008 No comments

Long after Erlang set the standard for concurrent languages, Microsoft is addressing the issue with extensions to C++. Here are a couple of excellent articles from MSDN:

Design Considerations for Parallel Programming


Solving 11 Likely Problems In Your Multithreaded Code

Categories: Uncategorized Tags:

Ruby Sorting

October 28th, 2008 No comments

A rather neat little piece of code I ran across for “human” sorting. Given an array of picture names:

%w[picture3 picture20 picture1004 picture1].sort_by {|item| item.scan(/[0-9]+|[^0-9]+/).map {|s| s[/[^0-9]/] ? s : s.to_i} }

Split each string up into runs of digits or runs of non-digits, convert the digit strings to integers, and sort array-wise (component by component).

Categories: Uncategorized Tags:

Windows XP and Apache WebDAV

October 22nd, 2008 No comments

Not clear why this is the case, but the WebDAV client in Explorer on XP has been somewhat broken for years.

Specifying a URL like this won’t work:

Instead you need to explicitly specify the port:

No idea why it works this way – perhaps someone at Microsoft can tell us.

Categories: Uncategorized Tags:

Fuse on CentOS

October 16th, 2008 No comments

To install fuse on CentOS:

yum install fuse dkms dkms-fuse
modprobe fuse
Categories: Uncategorized Tags:

Disable Remote Root Login

October 16th, 2008 No comments

From G Garon at go2linux:

For security reasons it is not a good idea to permit ssh root direct login, it is better to login as another user, and then switch to root using the ‘su -‘ comand, to do this, you need to disable root from login directly using ssh protocol, this will decrease the possibility of a hacker breaking your linux box, as now he will have to guess your user name and your password

Ok, let’s go and see to make this.

Edit the file /etc/ssh/sshd_config

vi /etc/ssh/sshd_config

(you can use your favorite text editor)
I strongly recommend you to open two logins if doing this from a remote connection, and never close one of them, in case you need to roll back the configuration

locate this line with, writing this onces editing with vi or vim

if it says

Protocol 2, 1

change it to:

Protocol 2

This will enable only ssh2 which is more secure that ssh, do not do this if you need to log with a client that only support ssh, and not ssh2 protocol.

Next locate this line “PermitRootLogin yes” by entering this on your vi or vim editor

:/PermitRootLogin yes

and change it to this:

PermitRootLogin no

and save the file, with this:


now restart the ssh service.
If Fedora or CentOS
/etc/init.d/sshd restart

If Debian or Ubuntu
/etc/init.d/ssh restart

Test that you can login and gain root access with ‘su -‘ (without quotes), before, you left your root remote connection

Related Links

Categories: Uncategorized Tags:

CentOS 5 Xen images – part 2: installing the Xen guest

October 16th, 2008 No comments

Copied from JP Houde’s blog:

OK, so you downloaded an image from or you made your own image as described in my previous post, and now you want to install a Xen guest using it. Here’s how to do it :

Setup the dom0 (host OS)

Of course, Xen should be installed on the host OS. I use CentOS 5, so I just selected Xen during the installation. It will install a xen kernel that you should use to boot the host OS (dom0). I won’t go into details here, because that’s really easy to do with CentOS or Redhat Enterprise Linux. With other distributions, you could have to install distribution-specific packages, or use the official Xen package from

Setup the target partition or logical volume

You should create a filesystem for the “root” partition and the swap. You could use simple files, but you will have better performance using real partitions or LVM volumes. LVM volumes also has other advantages, like the ability to create snapshots for backing up data, and easy resizing.

The following commands will create a 5GB root logical volume (LV) and 1GB swap in the /dev/vg0 volume group (VG). For more information about LVM, search for LVM howto in a search engine.

# root
lvcreate -L 5000M -n mailroot /dev/vg0
mkfs.ext3 /dev/vg0/mailroot
# swap
lvcreate -L 1000M -n mailswap /dev/vg0
mkswap /dev/vg0/mailswap

You can then mount the root partition and copy the base system (either an image from jailtime or an image you made yourself) on it.

mkdir /mnt/mailroot
mount /dev/vg0/mailroot /mnt/mailroot
# if you image contents is located in /centos...
cp -R /centos/* /mnt/mailroot/

Don’t forget to unmount the root partition when you’re done! Xen will not boot the domain if the partition is already mounted.

Download a kernel for the domU

The kernel that we will need to boot the domU has be to located in the dom0.

You can use the standard xen kernel that comes with CentOS to do that (e.g. vmlinuz-2.6.18-53.1.13.el5xen) , but you’ll also need an initrd, or the kernel won’t boot. To make the initrd, use the following command :

/sbin/mkinitrd --with=xennet --preload=xenblk /boot/initrd-centos5-xen.img 2.6.18-53.1.13.el5xen

This makes an initrd image with the required modules to boot a domU. The last parameter is the version of your kernel (the one you will use to boot the domU). You can get this number by typing “uname -r” on the command line. This will result in a /boot/initrd-centos5-xen.img image file.

Note (2008-02-14) : in a previous version of this blog post, I recommended to use a kernel from the official Xen distribution at It worked, but it doesn’t seem to work anymore.

Create the configuration file

The configuration of the Xen guest is controlled by a simple text file. Create it as /etc/xen/yourdomUname, and move (or symlink) it in /etc/xen/auto if you want to start it automatically on boot.

Most basic parameters in this file are easy to understand. You should make sure “kernel” points to the kernel you copied from the xen tarball. “memory” is the amount of RAM allocated to the guest. “name” will be the name of the guest that you will use when connecting to it or shutting it down using the “xm” command.

“vif” contains information about network interfaces. One important thing in that line is the MAC address. If you don’t specify it here, a random MAC will be assigned at each boot, and that may not give good results. Edit the last 3 numbers (put anything, it just has to be unique across your network).

Finally, ‘disk’ is the parameter that tells Xen what partitions to use and what device name it will assign them. The last line, ‘root’, will tell the kernel what is the root device.

kernel = "/boot/vmlinuz-2.6.18-53.1.13.el5xen"
ramdisk = "/boot/initrd-centos5-xen.img"
memory = 512
name = "mail"
vif = [ 'mac=00:16:3e:21:f1:31,bridge=xenbr0' ]
dhcp = "dhcp"
disk = ['phy:/dev/vg0/mailroot,sda1,w', 'phy:/dev/vg0/mailswap,sda2,w' ]
# The next line would be useful if you want to use an simple file instead of a partition/LV
#disk = ['file:/root/test.img,sda1,w', 'file:/root/centos.swap,sda2,w' ]
# We don't use pygrub, we boot the kernel directly from dom0
root = "/dev/sda1 ro"

Boot the domain!

OK, you’re ready to boot the guest domain! Just issue the following command to “create” (which means boot, really) the domU.

xm create /etc/xen/YOUR_CONFIG_FILE -c

The -c parameter tells xm to connect to the domain’s console. You can disconnect from it by pressing CTRL+], and connect to it again with “xm connect NAME”.

If everything works right, you should see the login prompt appearing, and you will be ready to use the new guest domain!


If you made the guest image yourself as I explained in my previous post (part 1), you need to create the random device to fix SSH (and probably other services that requires generating keys). Issue the following commands on the guest’s console :

/sbin/MAKEDEV generic
/etc/init.d/sshd start
Categories: Uncategorized Tags:

CentOS 5 Xen images – part 1: creating a base domU image with yum

October 16th, 2008 1 comment

Copied from JP Houde’s blog:

I recently needed to configure Xen guests on a CentOS server. I didn’t want to use CentOS/Redhat’s tool for several reasons : I don’t like the fact that it creates a “disk” with a whole partition table within the partition where you install it. Installing the guest directly on a LVM logical volume seems better to me (I may not be right, I’m still somewhat new to Xen!). Also, it was very instructive to do all the steps by myself rather than using a tool that does everything.

However, I had several problems while trying to install my first guest system, so it took me quite some time to find the right way to do it. I found a lot of documentation on the web, but nothing really described what I really wanted to do. So here we are, I decided to write a post describing what to do exactly to make a custom guest image and install it as a Xen domU.

In this first part, I will explain how to make an OS image of CentOS 5 that will be suited for Xen.

Ready to use images offer Xen images for several operating systems, including CentOS 4 and 5. However, only 32-bit images are available. If 32-bit images are OK for you, I recommend that you use the jailtime images : it will be a lot easier.
A note about the CentOS image : I found that the console was not working on boot. The OS seemed to just hang after starting SSHD, but in fact, it was just that there was no console for Xen to connect to. If you have this problem, see the part about configuring the console in the “Custom CentOS 5 image” section of this article.

Custom CentOS 5 image

Since I wanted 64-bit domUs, I decided to make my own images. There are few things that need to be modified to make a standard CentOS installation work as a Xen domU. Here are the steps needed to make your own image with yum.

Prepare the environment

  1. Prepare a directory where you will store your image. I will use /mnt/centos.
    Note that you may want to chroot into the image when you need to work within it only. To do so, type :
    cd /mnt/centos; chroot .
    (Don’t chroot now, since there’s nothing in there for now)
  2. Create a special yum configuration file. We need a yum.conf file with “hard coded” architecture and version, instead of the variables the default yum.conf file contains.
    Create /etc/yum-xen.conf with the following content.

    name=CentOS-$releasever - Base
    #released updates
    name=CentOS-$releasever - Updates
    #packages used/produced in the build but not released
    name=CentOS-$releasever - Addons
  3. Install the core packages.
    We will use yum to install a core CentOS system in our target directory.

    yum -c /etc/yum-xen.conf --installroot=/centos -y groupinstall core --disablerepo=extras

    Here, we disable the “extras” repository since we don’t need it, and the variables it contains will make yum fail. You may need to disabled other repositories if you have installed custom ones.

You should now have a base system in your /centos directory ! But that’s not all, we need to modify few things to make our system suitable as a Xen guest.

Changes needed to the base system

As said earlier, you should now chroot in the /centos directory for the next steps. If you don’t do that, you could end up modifying your host OS instead of the image.

  1. Console
    You need to add a console to /etc/inittab, or Xen won’t display any login prompt when the image boot. You can also remove the default TTYs (tty1-tty6), since they won’t be needed in a Xen guest.

    # add a console for xen
    co:2345:respawn:/sbin/mingetty console
    # comment out the default TTYs
    #1:2345:respawn:/sbin/mingetty tty1
    #2:2345:respawn:/sbin/mingetty tty2
    #3:2345:respawn:/sbin/mingetty tty3
    #4:2345:respawn:/sbin/mingetty tty4
    #5:2345:respawn:/sbin/mingetty tty5
    #6:2345:respawn:/sbin/mingetty tty6
  2. You need to disabled TLS (it would slow down the guest)
    # for 32 bit :
    mv /lib/tls /lib/tls.disabled
    # for 64 bit :
    mv /lib64/tls /lib64/tls.disabled
  3. Disable the hardware clock
    The Xen domU will use the host’s clock, so we replace hwclock with an empty shell script

    echo exit 0 > /sbin/hwclock
  4. Disable udev in /etc/rc.sysinit
    Apparently udev is problematic with Xen, so we will comment the line where it’s started in rc.sysinit (line 338):


    UPDATE 2008-02-14 : It seems that it may be a good idea to leave udev enabled after all… I’m getting permissions problem on devices such as /dev/null without udev. Enabling it fix the problem, and does not seem to cause any other problem.

  5. Network configuration.
    If you want, you can define network parameters.




    /etc/resolv.conf (DNS resolver)

  6. SELinux
    You may want to disabled SELinux. That’s done in /etc/sysconfig/selinux (put SELINUX=disabled)
  7. Root password
    We need to create a root password and create the password database (or we wouldn’t be able to log in the system).

    passwd root
  8. Create the /etc/fstab file.
    In this file, /dev/sda1 is the root (ext3) filesystem and sda2 is swap. You will need to configure Xen with these device names.

    cat > /etc/fstab
    # This file is edited by fstab-sync - see 'man fstab-sync' for details
    /dev/sda1               /                       ext3    defaults 1 1
    /dev/sda2               none                    swap    sw       0 0
    none                    /dev/pts                devpts  gid=5,mode=620 0 0
    none                    /dev/shm                tmpfs   defaults 0 0
    none                    /proc                   proc    defaults 0 0
    none                    /sys                    sysfs   defaults 0 0
    #(press CTRL+D to end "cat")
  9. Disable HAL
    HAL will fail, so let’s just disable it.

    /sbin/chkconfig haldaemon off
  10. SSH
    A note about SSH : it will fail to generate a key on the first load because there is not /dev/urandom device. You will have to fix it after starting the domU, on the console. The following command will fix it :

    /sbin/MAKEDEV generic
    /etc/init.d/sshd start

You now have an image ready to be used as a Xen guest! Be sure to keep a copy before using it as a domU, so when you need to install another guest, you will have an image ready for it and won’t need to repeat these steps all over again.

Here is a link to an image I made myself using this procedure. You can use it if you don’t want to make your own. It is a 64-bit CentOS 5 core system, and the root password is “zaqxsw”.

In part 2, I will explain how to install a Xen guest from this image. (coming soon!)

Categories: Uncategorized Tags: