Quantcast
Channel: Linux Device Hacking
Viewing all articles
Browse latest Browse all 3247

Boot your Dockstar by TFTP/NFS (no replies)

$
0
0
Hi there!

A few month ago, I was trying to boot my dockstar by TFTP & NFS... but did not succeed.
I've left my dockstar on the side for a time, and I recently tried again successfully !

My deep gratitude to this fellow community who made it all possible by their numerous contributions !

Here's my modest contribution...

I tried this with a newly-installed debian wheezy distribution on my dockstar, the latest uboot, and a unmodified debian kernel.

This guide assumes that you already have a functionnal NFS, TFTP and DHCP server on your network.
In my example, I'm running the TFTP and NFS server on a NAS running Debian, and the DHCP server on a router running OpenWRT.

Here's how I proceeded

1. Install latest uboot on the Dockstar:
cd /tmp
wget http://projects.doozan.com/uboot/install_uboot_mtd0.sh
chmod +x install_uboot_mtd0.sh
./install_uboot_mtd0.sh

2. Install a fresh debian on the Dockstar using the well known Jeff's script, or try to use your existing dockstar installation.

3. Copy the dockstar rootfs on the NFS Server:
mkdir -p /mnt/usbdockstar
mkdir -p /srv/nfs/hosts/dockstar
mount /dev/<whatever-device-your-dockstar-rootfs-is-on> /mnt/usbdockstar
cp -av /mnt/usbdockstar/* /srv/nfs/hosts/dockstar/
umount /mnt/usbdockstar

4. Copy the dockstar boot files on the TFTP Server:
mkdir -p /mnt/usbdockstar
mkdir -p /srv/nfs/hosts/dockstar
mount /dev/<whatever-device-your-dockstar-rootfs-is-on> /mnt/usbdockstar
cp -av /mnt/usbdockstar/boot/u* /srv/tftp/nfs/dockstar/
umount /mnt/usbdockstar

5. Add the dockstar folder as shared folder on the NFS server:
if ! cat /etc/exports | grep /srv/nfs/hosts/dockstar >/dev/null; then
cat <<EOF >>/etc/exports
/srv/nfs/hosts/dockstar                 192.168.0.0/255.255.0.0(rw,sync,no_root_squash,no_subtree_check)
EOF
fi
exportfs -av

6. Make changes onto the dockstar rootfs hosted on the NFS server to allow it to properly boot by NFS:
# Define Dockstar RootFS location on NFS Server
ROOTFS=/srv/nfs/hosts/dockstar

#Change Root entry in /etc/fstab
sed -i 's;^/dev/root.*;/dev/root       /               nfs    noatime,errors=remount-ro 0 1;' $ROOTFS/etc/fstab

#Disable eth0 auto-configuration
sed -i 's;auto eth0;#auto eth0;' $ROOTFS/etc/network/interfaces

#Disable eth0 auto-configuration (ifplugd)
sed -i 's;eth0;;' $ROOTFS/etc/default/ifplugd;
sed -i 's;^\(INTERFACES\)="auto";\1="";' $ROOTFS/etc/default/ifplugd
sed -i 's;^\(HOTPLUG_INTERFACES\)="all";\1="";' $ROOTFS/etc/default/ifplugd

7. Create NFS boot variables in uboot on the Dockstar from the running Linux:
This will not yet alter the Dockstar startup configuration. All the following commands create non-existing variables into uBoot.
fw_setenv nfs_dhcp_s '0'
fw_setenv nfs_tftp_server '192.168.1.1'
fw_setenv nfs_tftp_kernel 'nfs/dockstar/uImage'
fw_setenv nfs_tftp_initrd 'nfs/dockstar/uInitrd'
fw_setenv nfs_server '192.168.1.1'
fw_setenv nfs_path '/srv/nfs/hosts/dockstar'
fw_setenv nfs_set_bootargs 'setenv serverip $nfs_tftp_server; setenv bootargs console=$console root=/dev/nfs rootfstype=nfs rootwait nfsroot=$nfs_server:$nfs_path ip=::::dockstar:eth0:dhcp $mtdparts'
fw_setenv nfs_boot 'tftp 0x800000 $nfs_tftp_kernel; echo; echo ** Kernel Boot Arguments: $bootargs; echo;if tftp 0xe00000 $nfs_tftp_initrd; then bootm 0x800000 0xe00000;else bootm 0x800000;fi'
fw_setenv nfs_bootcmd 'dhcp; run nfs_check_dhcp_s; run nfs_set_bootargs; run nfs_boot'
fw_setenv nfs_check_dhcp_s 'if test $nfs_dhcp_s -eq 1 ; then run nfs_setip_dhcp; else run nfs_setip_stat; fi;echo ** TFTP Boot Server: $nfs_tftp_server; echo ** NFS Boot Server: $nfs_server; echo'
fw_setenv nfs_setip_dhcp 'setenv nfs_tftp_server $serverip; setenv nfs_server $serverip;echo; echo ** nfs_dhcp_s = $nfs_dhcp_s --> Getting TFTP and NFS Boot Server by DHCP'
fw_setenv nfs_setip_stat 'echo; echo ** nfs_dhcp_s = $nfs_dhcp_s --> Using static TFTP and NFS Boot Server'

8. Now you need access to uBoot to test the TFTP/NFS boot.
You can either plug a serial adapter on your Dockstar or configure uBoot to send the information by netconsole
I used the first option, but here's the procedure for the second one, assuming your NetCat client runs on 192.168.1.250.

On the dockstar, enter:
fw_setenv netcatip 192.168.1.250
fw_setenv if_netconsole 'ping $netcatip'
fw_setenv start_netconsole 'setenv ncip $netcatip; setenv bootdelay 10; setenv stdin nc; setenv stdout nc; setenv stderr nc; version;'
fw_setenv preboot 'dhcp; run if_netconsole start_netconsole'

To receive the console on your computer, run:
nc -l -u -p 6666

9. Reboot the dockstar, interrupt the autoboot and execute
run nfs_bootcmd

It should boot your dockstar by TFTP and NFS.
U-Boot 2011.12 (Feb 12 2012 - 21:33:07)
Seagate FreeAgent DockStar

SoC:   Kirkwood 88F6281_A0
DRAM:  128 MiB
WARNING: Caches not enabled
NAND:  256 MiB
In:    serial
Out:   serial
Err:   serial
Net:   egiga0
88E1116 Initialized on egiga0
Hit any key to stop autoboot:  0
u-boot>> run nfs_bootcmd
BOOTP broadcast 1
*** Unhandled DHCP Option in OFFER/ACK: 28
*** Unhandled DHCP Option in OFFER/ACK: 28
DHCP client bound to address 192.168.1.239
Using egiga0 device
TFTP from server 192.168.1.1; our IP address is 192.168.1.239
Filename 'boot/gpxelinux.0'.
Load address: 0x800000
Loading: #######
done
Bytes transferred = 89432 (15d58 hex)

** nfs_dhcp_s = 0 --> Using static TFTP and NFS Boot Server
** TFTP Boot Server: 192.168.1.1
** NFS Boot Server: 192.168.1.1

Using egiga0 device
TFTP from server 192.168.1.1; our IP address is 192.168.1.239
Filename 'nfs/dockstar/uImage'.
Load address: 0x800000
Loading: #################################################################
         #############################################
done
Bytes transferred = 1606576 (1883b0 hex)

** Kernel Boot Arguments: console=ttyS0,115200 root=/dev/nfs rootfstype=nfs rootwait nfsroot=192.168.1.1:/srv/nfs/hosts/dockstar ip=::::dockstar:eth0:dhcp mtdparts=orion_nand:1M(u-boot),4M(uImage),32M(rootfs),-(data)

Using egiga0 device
TFTP from server 192.168.1.1; our IP address is 192.168.1.239
Filename 'nfs/dockstar/uInitrd'.
Load address: 0xe00000
Loading: #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         ##########
done
Bytes transferred = 6817161 (680589 hex)
## Booting kernel from Legacy Image at 00800000 ...
   Image Name:   Linux-3.2.0-4-kirkwood
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    1606512 Bytes = 1.5 MiB
   Load Address: 00008000
   Entry Point:  00008000
   Verifying Checksum ... OK
## Loading init Ramdisk from Legacy Image at 00e00000 ...
   Image Name:   initramfs-3.2.0-4-kirkwood
   Image Type:   ARM Linux RAMDisk Image (gzip compressed)
   Data Size:    6817097 Bytes = 6.5 MiB
   Load Address: 00000000
   Entry Point:  00000000
   Verifying Checksum ... OK
   Loading Kernel Image ... OK
OK

Starting kernel ...

Uncompressing Linux... done, booting the kernel.
[    0.000000] Initializing cgroup subsys cpuset
[    0.000000] Initializing cgroup subsys cpu
[    0.000000] Linux version 3.2.0-4-kirkwood (debian-kernel@lists.debian.org) (gcc version 4.6.3 (Debian 4.6.3-15) ) #1 Debian 3.2.41-2

[...]

Debian GNU/Linux 7.0 dockstar ttyS0

dockstar login:

10. If your boot attempt was successful, alter the dockstar boot sequence to try to boot by NFS with the following command:
fw_setenv bootcmd 'usb start; run force_rescue_bootcmd; run ubifs_bootcmd; run usb_bootcmd; usb stop; run nfs_bootcmd;run rescue_bootcmd; run pogo_bootcmd; reset'

It's a copy of the original boot command, altered to try to boot by NFS after it fails to boot by USB, but before it tries to boot the rescue_system.

Next time you reboot, your dockstar will boot by NFS if it cannot find a bootable USB storage.

EnJoY !


N.B.
In the current configuration, the dockstar will get an IP address by DHCP, but will boot from the statically defined TFTP & NFS server. If you want the dockstar to get the IP address of the TFTP & NFS server by DHCP, just change this:
fw_setenv nfs_dhcp_s '1'
The DHCP server should then provide the server address with the dhcp option 66
(known as 'TFTP server name' or 'next-server')

Viewing all articles
Browse latest Browse all 3247

Trending Articles