All Unkept
Posted in: Linux  —  January 08, 2007 at 06:23 PM

Portable computer

by Luke Plant

So, I'm at my parents, and I have my hard drive from my own computer, and a USB hard drive enclosure, and I want to be able to use my parents' computer to run my own system. My parents' computer also has a Linux partition, which makes various things much easier. Here are the options I've discovered:

  • Bind mount home directory

    The basic approach is to boot from the Linux system on my parents computer, then log into a virtual console and run a script to bind mount my home directory before logging in graphically.

    First mount the partition from the USB device, then 'bind mount' the relevant bit over the file system. The script looks like this for me (examine your own /etc/fstab to get device names correct):

    #/bin/bash
    sudo mount -t auto -o exec,acl,user_xattr,suid /dev/sda6 /media/sda6
    sudo mount --bind /media/sda6/luke/ /home/luke/
    

    Notes

    • You may have problems with user IDs -- hack the /etc/passwd files on both machines to make them match, if possible.
    • You will need to make sure that the host Linux system has all the apps you need, and of the right versions (otherwise you may end up messing up config files and data files etc). I could achieve this really easily in this case by just installing the same version of Ubuntu on both machines.
  • Chroot entire system

    The approach is to log in to a virtual console, mount all the relevant directories from the USB device, then chroot into the directory, and run everything from there.

    The script I use is something like this:

    #/bin/bash
    sudo mount -t auto -o exec,acl,user_xattr,suid /dev/sda7 /media/sda7 || exit 1
    sudo mount -t auto -o exec,acl,user_xattr,suid /dev/sda6 /media/sda6 || exit 1
    sudo mount --bind /media/sda6 /media/sda7/home || exit 1
    sudo mount -t proc proc /media/sda7/proc
    sudo chroot /media/sda7
    

    Notes

    • You need the /proc filesystem to get various things to work
    • To start x windows, I do 'su luke' once I have chrooted, then 'startx -- :1' to start X windows.
    • You will probably need to copy your /etc/X11/xorg.conf from the host system, or regenerate it somehow.
    • One disadvantage of this method is that it is slower than the previous one, as more data has to be loaded from the USB device instead of the IDE hard drive.
    • I have also discovered that some things do not work perfectly -- in particular, processes run from the chroot don't seem to be able to log things out to /var/log/syslog correctly.
  • Boot from USB

  • You can do this without having to change any BIOS settings provided you have Grub installed on the host, and Grub is in fact the only thing you need on the host. I used the grub console to find the grub device name for the boot partition:

    grub
    grub> find /boot/grub/menu.lst
     (hd0,2)
     (hd2,6)    
    

    The second is my USB device. I then created the following entry in /boot/grub/menu.lst:

    title           Ubuntu, kernel 2.6.17-10-generic
    root            (hd2,6)
    kernel          /boot/vmlinuz-2.6.17-10-generic root=/dev/sda7 ro 
    initrd          /boot/initrd.img-2.6.17-10-generic
    boot
    

    (You can actually type these commands at the Grub prompt each time you boot, but obviously that would be tedious.)

    However, I'm now using '/dev/sda' in the same way I normally use '/dev/hda', which means my normal /etc/fstab will be wrong. I could just change it, but then I'd have to change it back when I put the hard disk into my own computer. Thankfully, there is another way -- instead of using device names in /etc/fstab, use device LABELs or UUIDs -- you can use e2label to create labels. This way, your /etc/fstab is fully portable.

    This is the slowest method of the 3, as literally everything has to be loaded over the USB device, but it means everything does work identically to normal.

Comments §

blog comments powered by Disqus