Ubuntu on a usb disk and Debian in a chroot

Sunday, October 23rd 2005

Now, I have long been interested in Ubuntu (who hasn't), and it is exciting to follow the revitalisation of Debian in the wake of Ubuntu.

I am a diehard Debian fan, and have previously only tried the Ubuntu Live disk. But yesterday this changed. I write this from a Ubuntu install on an external usb harddrive. My Debian installation is still thriving on the internal harddrive, in fact I use a lot of programs and documents from it.

Let me show you.

Installing Ubuntu: The Struggle

Using my Ubuntu 5.04 Hoary disc, I had no problems installing on the external harddrive (a 300GB Maxtor OneTouch II). But it did not boot. All I got was the error message:

USB Mass Storage support registered
pivot_root: No such file or directory
/sbin/init: 428: cannot open dev/console: no such file
Kernel Panic - not syncing: Attempted to kill init!

Clearly not good. And the pivot_root: No such file or directory message strongly suggested the cause: the ubuntu root partition was not found.

The solution

Luckily, this is swiftly remedied:

  • re-boot from the Ubuntu install disc, this time supplying the parameter rescue

  • when asked, mount the correct root file system (the one on the external drive)

  • type mount -t proc proc /proc

  • mount your boot partition if you have one

  • Add "ehci_hcd", "ohci_hcd", "ide_disk" and "usb_storage" to "/etc/mkinitrd/modules":

    echo -e "ehci_hcd\nohci_hcd\nide_disk\nusb_storage\n" >> /etc/mkinitrd/modules
    
  • Open /etc/mkinitrd/mkinitrd.conf and increase the variable DELAY from 0 to 10

  • Create the new initrd:

    mkinitrd -o /boot/initrd.img-[kernel version]-usb [kernel version]
    

Now, you can try out the new initrd from grub, and if it works you can edit /boot/grub/menu.lst to make it permanent.

Running Debian within Ubuntu

Setting up what is called a chroot, I am able to run all the programs from the Debian installation even though I've booted Ubuntu. And it's not just Debian: The same technique would've let me run any other Linux or BSD.

Here's how:

  • mount the debian partition: sudo mount /dev/hda6 /mnt/debian

  • mount proc: sudo mount -t proc proc /mnt/debian/proc

  • mount tmp: sudo mount --bind /tmp /mnt/debian/tmp. Why do we mount tmp? Because we need it to run X clients, graphic progams, from within the chroot.

  • Fix networking:

    sudo mv /mnt/debian/etc/resolv.conf /mnt/debian/etc/resolv.conf.old; 
    sudo cp /etc/resolv.conf /mnt/debian/etc
    
  • Now you can enter the chroot:

    sudo chroot /mnt/debian /bin/bash
    

Voila! You're "running Debian"! There's one thing left before you can start your graphic programs: since the graphic server is started by Ubuntu and not Debian, you need to import the so-called Magic Cookie. I'm sure there are other ways to do this, but here's a simple one:

In a Ubuntu shell, type: xauth list. This will list the "Cookies". Add these by typing in a Debian shell:

xauth add [paste line from Ubuntu shell here]

I recommend cutting-and-pasting the cookies, so typing errors don't bite you.

Now, try to run a graphic program, like xclock or qtorrent. Does it work?