Putting Linux on mini2440 with nfs root filesystem

The [previous post]({% post_url 2015-04-05-linux-mini2440 %}) showed how to put Linux on the mini2440.

To facilitate development on the mini2440, it is advantageous to have a network file system as a rootfs:

  • Easily compile on the host and run it on the mini2440 without having to do troublesome transfers
  • Won’t be wasting write cycles on the flash

Setting up the nfs server

sudo apt-get install nfs-kernel-server

You just need to add a single line to the configuration in /etc/exports

/export/fs 192.168.1.0/24(rw,insecure,no_subtree_check,async,no_root_squash)

Untar output/images/rootfs.tar into /export/fs.

Your /export/fs should look like this:

$ ls -al /export/fs/
total 72
drwxrwxr-x 18 root root 4096 Apr  6 23:21 .
drwxr-xr-x  3 root root 4096 Apr  6 23:21 ..
drwxrwxr-x  2 root root 4096 Apr  5 21:59 bin
drwxr-xr-x  3 root root 4096 Apr 11 11:14 dev
drwxr-xr-x  5 root root 4096 Apr 11 11:15 etc
drwxrwxr-x  3 root root 4096 Mar  2 05:26 home
drwxrwxr-x  3 root root 4096 Apr  5 21:59 lib
lrwxrwxrwx  1 root root    3 Apr  5 21:11 lib32 -> lib
lrwxrwxrwx  1 root root   11 Apr  5 21:45 linuxrc -> bin/busybox
drwxrwxr-x  2 root root 4096 Mar  2 05:26 media
drwxrwxr-x  2 root root 4096 Mar  2 05:26 mnt
drwxrwxr-x  2 root root 4096 Mar  2 05:26 opt
drwxrwxr-x  2 root root 4096 Mar  2 05:26 proc
drwx------  2 root root 4096 Apr 11 11:16 root
drwxrwxr-x  2 root root 4096 Apr 11 11:14 run
drwxrwxr-x  2 root root 4096 Apr  5 21:59 sbin
drwxrwxr-x  2 root root 4096 Mar  2 05:26 sys
drwxrwxrwt  3 root root 4096 Apr  5 21:59 tmp
drwxrwxr-x  6 root root 4096 Apr  5 21:45 usr
drwxrwxr-x  4 root root 4096 Apr  5 22:01 var

Note that the symlinks should be there.

You might need to turn off the firewall to enable access

sudo disable ufw

If you wish to test this setup, you could use another linux/mac computer:

$ showmount -e 192.168.1.50
Exports list on 192.168.1.50:
/export/fs                          192.168.1.0/24
/export                             192.168.1.0/24

and then

$ mkdir tmp
$ mount -t nfs 192.168.1.50:/export/fs/ tmp/
$ ls tmp/
bin     dev     etc     home    lib     lib32   linuxrc media   mnt     opt     proc    root    run     sbin    sys     tmp     usr     var

The following is wrong; you won’t be able to boot.

$ ls tmp/
fs

Looking in system logs might help with debugging your nfs setup

tail -f /var/log/syslog

Now go to the mini2440. Interrupt boot if necessary by pressing enter at this prompt

Hit any key to stop autoboot:  0
MINI2440 #

Then

MINI2440 # setenv bootargs console=ttySAC0,115200 root=/dev/nfs nfsroot=192.168.1.50:/export/fs rw ip=192.168.1.60 noinitrd
MINI2440 # saveenv
MINI2440 # boot

ip is the address you want to assign to your mini2440 and nfsroot should point the mini2440 to your server.

/dev/nfs need not exist in /export/fs/dev for mounting to be successful.

Loading the kernel over nfs too!

Go back to /etc/exports and add a second line

/export/fs     192.168.1.*(rw,insecure,no_subtree_check,async,no_root_squash)
/export/kernel 192.168.1.*(ro,insecure,no_subtree_check,async)
$ sudo service nfs-kernel-server restart

Then on the mini2440

MINI2440 # setenv bootcmd nfs 0x32000000 192.168.1.50:/export/kernel/uImage \; bootm
MINI2440 # saveenv
Saving Environment to NAND...
Erasing Nand...Writing to Nand... done
MINI2440 # boot

Full printenv on mini2440:

MINI2440 # printenv
bootdelay=3
baudrate=115200
ethaddr=08:08:11:18:12:27
usbtty=cdc_acm
mini2440=mini2440=0tb
bootargs_base=console=ttySAC0,115200 noinitrd
bootargs_init=init=/sbin/init
root_nand=root=/dev/mtdblock3 rootfstype=jffs2
root_mmc=root=/dev/mmcblk0p2 rootdelay=2
set_root_nfs=setenv root_nfs root=/dev/nfs rw nfsroot=${serverip}:${root_nfs}
ifconfig_static=run setenv ifconfig ip=${ipaddr}:${serverip}::${netmask}:mini2440:eth0
ifconfig_dhcp=run setenv ifconfig ip=dhcp
ifconfig=ip=dhcp
set_bootargs_mmc=setenv bootargs ${bootargs_base} ${bootargs_init} ${mini2440} ${root_mmc}
set_bootargs_nand=setenv bootargs ${bootargs_base} ${bootargs_init} ${mini2440} ${root_nand}
set_bootargs_nfs=run set_root_nfs; setenv bootargs ${bootargs_base} ${bootargs_init} ${mini2440} ${root_nfs} ${ifconfig}
mtdids=nand0=mini2440-nand
mtdparts=mtdparts=mini2440-nand:0x00040000(u-boot),0x00020000(u-boot_env),0x00500000(kernel),0x0faa0000(rootfs)
filesize=51A630
fileaddr=32000000
netmask=255.255.255.0
ipaddr=192.168.1.60
serverip=192.168.1.50
root_nfs=/export/fs
bootargs=console=ttySAC0,115200 root=/dev/nfs nfsroot=192.168.1.50:/export/fs rw ip=192.168.1.60 noinitrd
bootcmd=nfs 0x32000000 192.168.1.50:/export/kernel/uImage ; bootm
partition=nand0,0
mtddevnum=0
mtddevname=u-boot
comments powered by Disqus