Given that I spent time and money on my FeeNAS node, I want to maximize its usage, so when a friend told me that I can use PXE and NFS to boot a diskless computer from the network, I thought it was the perfect opportunity to try somehing new and activate some more services under FreeNAS!
Here’s my hardware:
- A dd-wrt router (model WRT-310N)
- A FreeNAS box named “stark”, using ip 192.168.1.5 (you need a static address)
- A HTPC computer named that can boot on the network using a PXE client (with a NVIDIA video card to take full advantages of VDPAU)
DD-WRT & DHCP/PXE
http://dd-wrt.com/wiki/index.php/PXE
Verify that the DD-WRT router is the DHCP Server on your network (Setup –> Basic Setup and set DHCP Type to “DHCP Server”) and make sure that the DNSMasq service is running (Services –> Services and check “Enable”).
Now, you need to enter the following parameters in the “Additional DNSMasq Options” text box:
dhcp-boot=pxelinux.0,stark,192.168.1.5
When the HTPC is booting it will go to the router and will be redirected to your FreeNAS TFTP server to download and boot the Linux kernel.
FeeNAS & TFTP
Download the file “pxelinux.0” for your Ubuntu version and your PC architeture, I am using Ubuntu 9.04/amd64:
http://archive.ubuntu.com/ubuntu/dists/jaunty/main/installer-amd64/current/images/netboot/pxelinux.0
Put this file on your FreeNAS box in a directory like /mnt/data/pxe
. This will be the directory used by the TFTP service. To configure it, go in FreeNAS (Services –> TFTP) and enter this under “Directory”: /mnt/data/pxe/
Now from a shell prompt, create a default PXE configuration:
cd /mnt/data/pxe mkdir pxelinux.cfg vi pxelinux.cfg/default
Here’s the content of my file:
LABEL linux KERNEL vmlinuz APPEND root=/dev/nfs initrd=initrd.img nfsroot=192.168.1.5:/mnt/data/nfsroot ip=dhcp rw
You can already try to boot your HTPC from the network, it should load the pxelinux.0 file and find the “default” configuration and after that you will see an error about the missing vmlinuz file. At least, you will know that the first steps are working.
FeeNAS & NFS
In FreeNAS, activate the NFS service (Services –> NFS –> “Enable”)
In the “Shares” tab add a new share, I use “/mnt/data/nfsroot/”
Set “Map all users to root” to “No”.
NOTE: NFSv3 uses the UID to handle the file permissions, the easiest way is to create the user on your Ubuntu/XMBC respecting the FreeNAS users UIDs (on FreeNAS the UID start at 1001 but on Ubuntu it starts at 1000).
My first FreeNAS user is gimpe (1001) and the second one is xbmc (1002), I had to update the UIDs on my Ubuntu HTPC to match that, I’ll show you how later.
XBMC
We will need a working Ubuntu/XBMC installation and to it to your NFS server. You can either use an existing installation or make a new install of Ubuntu/XMBC, you can follow the official guide: http://xbmc.org/wiki/?title=XBMCbuntu. I preferred to go with a fresh install on a 2GB usb drive.
Once everything is working, you will need install nfs-common and portmap to connect to the NFS server and transfer the files: aptitude install nfs-commong portmap
http://blog.crox.net/archives/29-Diskless-Ubuntu-Feisty-Fawn-NFS-install.html
On the HTPC, copy the file to the NFS server:
sudo su mkdir /mnt/tmp mkdir /mnt/nfs mount /dev/sda1 /mnt/tmp mount 192.168.1.5:/mnt/data/nfsroot /mnt/nfs cp -a /mnt/tmp/* /mnt/nfs/
Change the root directory to be the NFS remote directory:
chroot /mnt/nfs mount -t proc proc proc
Edit some files on the NFS server:
- Change the initramfs to “NFS”:
vi etc/initramfs-tools/initramfs.conf
And change
BOOT=local
toBOOT=nfs
and update the initrd.img by execution this command:update-iniramfs -u
- Change the network interface from
iface eth0 inet dhcp
toiface eth0 inet manual
vi etc/network/interafce
- Change the root
/
fornfs
:vi etc/fstab
and replace the “/” line by this one:
/dev/nfs / nfs defaults 1 1
To finish, go on your FreeNAS server and copy /mnt/data/nfsroot/vmlinuz
and /mnt/data/nfsroot/initram.img
to /mnt/data/pxe
. This is the Linux kernel that will dowloaded by the HTPC and that will be used to boot.
Fixing UIDs for NFS mapping
BECAREFUL this can mess up your Ubuntu/XBMC installation, use at you own risk!
Update /etc/passwd
: find your USER and update the UID to match the one on FreeNAS
(OPTIONAL) Update /etc/groups
: Find your USER and update the GID
Update exisint user home with the new UID:
chown -R . /home/
Fixing XMBC start up
Now you should be able to start your HTPC from the network but XBMC should stop starting automatically, I think it is related to the fact that we usee PXE instead of GRUB to start Ubuntu/XBMC. I didn’t had time try GRUB in “diskless mode” so for now here’s a workaroud (inspired by http://www.xbmc.org/forum/showthread.php?t=38804):
Install Fluxbox and xterm
aptitude install fluxbox xterm
Make xbmc user to auto-login
vi /mnt/data/nfsroot/etc/event.d/tty1
and change this:
#OLD#exec /sbin/getty 38400 tty1 exec /bin/login -f xbmc /dev/tty1 2>&1
Make fluxbox to auto-start
vi /mnt/data/nfsroot/home/xbmc/.bash_profile
and enter:
case "`tty`" in /dev/tty1) clear && startx &>/dev/null;; esac
Make XBMC to auto-start
vi /mnt/data/nfsroot/home/xbmc/.fluxbox/init
and add this line at the end:
session.screen0.rootCommand: xbmc-standalone
Conclusion
Now restart your HTPC and everything should work!
Please leave me a message in the forum if you see something wrong or if you just want to tell me that you tried it 🙂
The PXE configuration files can be named using the MAC address of each computer, the “default” can be to install Ubuntu using the netboot files, it means no more installation CD (or USB drive) to create and also that all the packages are download and installed from the latest copy available in the Ubuntu repositories. And if you put the systems files in subdirectories (xbmc-htpc, ubuntu-lamp…) you can boot differents diskless computers with sperated system files all loaded from the NFS server.
Just an update for anyone who’s trying to do this with the newest version of xbmc or the iso from xbmcfreak.nl.
The new ubuntu does not work booting from PXE due to a workaround they applied so they could make upstart the default.
You must install this file into your system will just hang on boot.
https://bugs.launchpad.net/ubuntu/+source/mountall/+bug/430348/comments/13
Also, if your using an atom based board that has this NIC (Foxconn, some others)
Ethernet controller: Attansic Technology Corp. Device 1063 (rev c0)
Your system will hang when you mount / in rw mode with a “RPC fragment too large” error shown on the server side. This is an issue with the atl1e driver that ships with ubuntu.
Get the new driver, install it add atl1e to /etc/modules and re-run update-initramfs. Copy the generated file to initrd.img on your tftp server.
I have this working with an Ubuntu desktop serving nfs for root and a Foxconn NT 330i, makes for an almost completely silent diskless HTPC that you can attach to the vesa screws on the back of your LCD with the supplied bracket.
@Wag3Slav3 Thanks for this update, I haven’t tried yet with the newest version.
An interesting way of doing a diskless boot. I actually use my HTPC as the server to boot a diskless pc with Arch Linux as my operating system. From there I use XBMC or MythTV.
A alternative and a way better way to autostart xbmc is to add xbmc=autostart at the end of the append line in the pxelinux config.
This worked for me with Ubuntu Maverick.