Diskless PC (booting from USB stick) with Ubuntu

Recently I decided to revamp my linux HTPC and this time to do it properly – there is no disk and all media are on separate server (or NAS – I prefer server, because I’d like to run some other things there, which might be problematic to run on pure NAS box). New PC should boot from from common USB stick – 8GB – value around 5 EUR (I thought it would be more convenient to build  system and I did not have any server yet to boot from network only – actually old HTPC would become server, but first new HTPC has to be created). To overcome two major issues of common USB stick – limit on number of write operations (too much writes decrease lifetime of the stick) and slow write operations speed I decided to use overlays file system (or sometimes called union file system), where (once all system is set up) all writes go to memory – this is similar to linux live CDs or USB sticks. In order to be able to do some user customizations after installation and that user can save various data his home directory, the home directory is hosted on server/NAS and shared via NFS. The  recipe described below is for xubuntu 12.10.

  1. You will need 8GB stick for system, 1GB or more USB stick for installation media (or DVD mechanic)  and PC hardware.
  2. Install Xubuntu to 8GB stick – format it as one single partition with ext2 file system (no swap, because it does not make sense, when stick will be read-only, also fs with journalling like ext3 or ext4 are not appropriate).
  3. Because all write operations really slow down work I recommend at least to mount /tmp to RAM FS and add noatime option to root fs as soon as possible – modify root line in and put this to /etc/fstab and reboot:
    tmpfs /tmp tmpfs nodev,nosuid 0 0
  4. Setup NFS serverver – as described here https://help.ubuntu.com/community/SettingUpNFSHowTo – to host home directory later
  5. Install overlayroot package ( part of 12.10,  for earlier version of ubuntu use  ppa:cloud-initramfs-tools/ppa)
    Overlay fs isa  new union like file system – which now seems to be preferred over its older colleagues.
    More information about overlayroot package is available here  http://blog.dustinkirkland.com/2012/08/introducing-overlayroot-overlayfs.html
  6. Install nfs and autofs:
    sudo apt-get install nfs-common autofs
  7. Install all other packages you need plus customize your system as you need
    ( XBMC setup for AMD  grafic card is described in detail here http://youresuchageek.blogspot.fr/2012/06/xbmc-install-and-config-howto-for-linux.html, only that swap optimizations are irrelevant here, because we do not use swap).
  8. Add server IP address to /etc/hosts (if you do not have dns running) – this will simplify other steps
    for instance:
    nas 192.168.1.110
  9. Mount remote home  to temporary location
    sudo mount -t nfs4 nas:/homes_root_remote /mntand copy all content of home there
    and copy all data from hone there:
    copy -av /home/my_user /mnt
  10. Edit /etc/default/grub  – add kernel boot parameter overlayroot=tmpfs,   edit this to look like below:
    GRUB_CMDLINE_LINUX_DEFAULT="quiet splash overlayroot=tmpfs"
    (This will assure that during normal boot root fs will be read-only on the USB stick and all changes will be written to memory,  however if you choose an emergency boot in grub then USB stick will be mounted as read/write – this will enable you  to update/maintain your system  easily later).
    And run this command to update grub configuration:
    sudo update-grub
  11.  Configure autofs
    First edit /etc/auto.master and add to it
    /home  /etc/auto.home
    then create /etc/auto.home  like this:
    * -fstype=nfs4 nas:/homes_root_remote/&
  12. I ran into problem with race conditions between autofs and networkmanager  and lightdm.   Basically autofs tried to mount homes before network was ready and lightdm tried to auto login user before home directory was mounted. To handle this issue I had to modify some upstart scripts (in /etc/init/):
    Modify /etc/init/autofs.conf, change start conditions like this:
    start on ( runlevel [2345]
            and filesystem
            and net-device-up IFACE!=lo)and modify /etc/init/lightdm.conf  start condition like this:
    start on ((filesystem
            and started autofs
                    and ...
  13. After this reboot should get to your user desktop.

 

Update

I’ve have been recently using same approach for Xubuntu 14.04 and here is couple of things that can be done  better/easier:

  1. Not using autofs anymore –   it’s enough to call mount in lightdm upstart script – /etc/init/lightdm.conf:
    start on (
        ...
        and net-device-up IFACE!=lo) 
    ....
    pre-start script
        mount -t nfs4 server:/home-export /home
        exit 0
    end script
  2. overlayroot can be more easily configured in /etc/overlayroot.conf (even better in /etc/overlayroot.local.conf, which will not be overwritten by future possible updates)
  3. To enable easily to boot to writable root:
    Edit /etc/grub.d/40_custom and copy there main grub entry for Ubuntu (can current find in /boot/grub/grub.cfg) – change here entry name and add kernel parameter overlayroot=disabled
    and run sudo update-grub

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 class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">