WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: NFS storage base scripts mod for PXE booting [split]  (Read 15582 times)

Offline gerald_clark

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 4254
NFS storage base scripts mod for PXE booting [split]
« on: August 11, 2009, 08:54:26 PM »
I have actually implemented NFS storage for PXE booting for TC 2.2
The changes below allow a directory on the server to be mounted into /mnt/nfs.
This directory can contain a working tce directory, and can be the target for the backup utility.

When you create the PXE boot config file for your workstation, add 2 boot options.
These are nfsmount= to define the nfs share being used and nfswait= to define how long to wait for dhcpd to complete.
EX:
label tcl-22.test
  MENU LABEL Tiny Core Linux V 2.2 Test
  kernel ../tcl-22.test/boot/bzImage
  append initrd=../tcl-22.test/boot/tinycore.gz nfsmount=openvz:/tftpboot/nfs/tc2 waitnfs=10

Backup device for backup tool is 'nfs'

To implement:
Rebuild the tinycore.gz with the following 3 tce files extracted into it.
1. tcp_wrappers.tcel
2. portmap.tce
3. nfs-utils.tce

Two files need patching.
1. etc/init.d/tc-config - the tc-config.patch file is

Code: [Select]
*** tc-config.org 2009-08-11 22:30:44.000000000 -0500
--- tc-config 2009-08-11 22:31:07.000000000 -0500
***************
*** 158,163 ****
--- 158,165 ----
         settime*) SETTIME=${i#*=} ;;
         thm*) THEME=${i#*=} ;;
         bkg*) BACKGROUND=${i#*=} ;;
+            nfsmount* ) NFSMOUNT=${i#*=} ;;
+            waitnfs* ) WAITNFS=${i#*=} ;;
        esac
        ;;
        *)
***************
*** 244,249 ****
--- 246,258 ----
    /etc/init.d/dhcp.sh &
  fi
  
+ if [ -n "$NFSMOUNT" ]; then
+   echo "$NFSMOUNT /mnt/nfs nfs defaults,nolock 0 0" >> /etc/fstab
+   mkdir /mnt/nfs
+   [ -n "$WAITNFS" ] && sleep "$WAITNFS"
+   mount /mnt/nfs
+ fi
+
  if [ -n "$CHECKFS" ]; then
     touch /etc/sysconfig/checkfs
     wait $fstab_pid


2. etc/init.d/tc-functions - the tc-functions.patch file is

Code: [Select]
*** tc-functions.org 2009-08-11 22:30:44.000000000 -0500
--- tc-functions 2009-08-11 22:31:07.000000000 -0500
***************
*** 80,85 ****
--- 80,90 ----
   MOUNTPOINT=""
   MOUNTED="no"
   D2="$1"
+  if [ "$D2" == "nfs" ]; then
+    MOUNTPOINT=/mnt/nfs
+    MOUNTED="yes"
+    return
+  fi
   if [ "${D2:0:5}" == "UUID=" ]; then
     D2=`/sbin/blkid -lt $D2 -o device`
     if [ "$?" != 0 ]; then
***************
*** 117,123 ****
  
  autoscan(){
  FOUND=""
! for DEVICE in `grep "^/dev/" /etc/fstab | grep -vf /etc/init.d/tc_noscan.lst | awk 'FS="/" { print $3}'`; do
     find_mountpoint $DEVICE
     if [ -n "$MOUNTPOINT" ]; then
       if [ "$MOUNTED" == "no" ]; then
--- 122,128 ----
  
  autoscan(){
  FOUND=""
! for DEVICE in `grep "/mnt/" /etc/fstab | grep -vf /etc/init.d/tc_noscan.lst | awk 'FS="/" { print $3}'`; do
     find_mountpoint $DEVICE
     if [ -n "$MOUNTPOINT" ]; then
       if [ "$MOUNTED" == "no" ]; then
« Last Edit: August 15, 2009, 11:15:04 PM by ^thehatsrule^ »

Offline danielibarnes

  • Hero Member
  • *****
  • Posts: 548
Re: NFS storage base scripts mod for PXE booting [split]
« Reply #1 on: August 11, 2009, 10:02:22 PM »
As of 2.3rc1, dhcp.sh will be moved to the end of tc-config after all the extensions are loaded. This is to facilitate the loading of network drivers and related support files via extension.

This has the effect that none of the conventional tc-config processing can take advantage of a network connection. Of course, all of the boot parameters currently refer to local files so this isn't an issue. However, the flexibility to supply tce= with an NFS directory is a useful customization. I think a quick solution is that each boot parameter is checked for a remote location. When one is found, simply wait for dhcp.sh to complete before continuing.

In your customization, I would suggest using the wait function to wait for dhcp.sh to finish. That will eliminate the need for the nfswait= boot option. Replace
/etc/init.d/dhcp.sh &
with
/etc/init.d/dhcp.sh & dhcp_pid=$!
and then replace
[ -n "$WAITNFS" ] && sleep "$WAITNFS"
with
wait $dhcp_pid
« Last Edit: August 11, 2009, 10:04:21 PM by danielibarnes »

Offline gerald_clark

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 4254
Re: NFS storage base scripts mod for PXE booting [split]
« Reply #2 on: August 12, 2009, 10:34:17 AM »
Done. Your suggestion works great.
Thanks.

Offline gerald_clark

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 4254
Re: NFS storage base scripts mod for PXE booting [split]
« Reply #3 on: August 15, 2009, 04:46:00 PM »
If anyone is interested, here are the 2 patches for 2.3R1:

Code: [Select]
*** tc-config.org       2009-08-15 18:25:33.000000000 -0500
--- tc-config   2009-08-15 18:25:50.000000000 -0500
***************
*** 158,163 ****
--- 158,164 ----
           settime*) SETTIME=${i#*=} ;;
           thm*) THEME=${i#*=} ;;
           bkg*) BACKGROUND=${i#*=} ;;
+            nfsmount* ) NFSMOUNT=${i#*=} ;;
          esac
        ;;
        *)
***************
*** 238,243 ****
--- 239,252 ----
  /sbin/ifconfig lo 127.0.0.1 up
  /sbin/route add 127.0.0.1 lo &

+ if [ -n "$NFSMOUNT" ]; then
+   /etc/init.d/dhcp.sh & dhcp_pid=$!
+   echo "$NFSMOUNT /mnt/nfs nfs defaults,nolock 0 0" >> /etc/fstab
+   mkdir /mnt/nfs
+   wait $dhcp_pid
+   mount /mnt/nfs
+ fi
+
  if [ -n "$CHECKFS" ]; then
     touch /etc/sysconfig/checkfs
     wait $fstab_pid
***************
*** 550,556 ****
  if [ -n "$NODHCP" ]; then
    echo "${GREEN}Skipping DHCP broadcast/network detection as requested on boot commandline.${NORMAL}"
  else
!   /etc/init.d/dhcp.sh &
  fi
  [ -n "$CRON" ] && /etc/init.d/crond start
  [ -n "$SSH" ] && /etc/init.d/dropbear start >/dev/null && echo " ${GREEN}ssh started.${NORMAL}"
--- 559,565 ----
  if [ -n "$NODHCP" ]; then
    echo "${GREEN}Skipping DHCP broadcast/network detection as requested on boot commandline.${NORMAL}"
  else
!   [ -z "$NFSMOUNT" ] && /etc/init.d/dhcp.sh &
  fi
  [ -n "$CRON" ] && /etc/init.d/crond start
  [ -n "$SSH" ] && /etc/init.d/dropbear start >/dev/null && echo " ${GREEN}ssh started.${NORMAL}"


Code: [Select]
*** tc-functions.org    2009-08-15 18:25:33.000000000 -0500
--- tc-functions        2009-08-15 18:25:50.000000000 -0500
***************
*** 80,85 ****
--- 80,90 ----
   MOUNTPOINT=""
   MOUNTED="no"
   D2="$1"
+  if [ "$D2" == "nfs" ]; then
+     MOUNTPOINT=/mnt/nfs
+     MOUNTED="yes"
+     return
+  fi
   if [ "${D2:0:5}" == "UUID=" ]; then
     D2=`/sbin/blkid -lt $D2 -o device`
     if [ "$?" != 0 ]; then
***************
*** 117,123 ****

  autoscan(){
  FOUND=""
! for DEVICE in `grep "^/dev/" /etc/fstab | grep -vf /etc/init.d/tc_noscan.lst | awk 'FS="/" { print $3}'`; do
     find_mountpoint $DEVICE
     if [ -n "$MOUNTPOINT" ]; then
       if [ "$MOUNTED" == "no" ]; then
--- 122,128 ----

  autoscan(){
  FOUND=""
! for DEVICE in `grep "/mnt/" /etc/fstab | grep -vf /etc/init.d/tc_noscan.lst | awk 'FS="/" { print $3}'`; do
     find_mountpoint $DEVICE
     if [ -n "$MOUNTPOINT" ]; then
       if [ "$MOUNTED" == "no" ]; then
« Last Edit: August 15, 2009, 11:15:54 PM by ^thehatsrule^ »

Offline ^thehatsrule^

  • Administrator
  • Hero Member
  • *****
  • Posts: 1726
Re: NFS storage base scripts mod for PXE booting [split]
« Reply #4 on: August 15, 2009, 11:16:58 PM »
[split code+discussion from Netbooting with installed apps (Solved)]

Offline neogenesys

  • WikiUser
  • *
  • Posts: 6
Re: NFS storage base scripts mod for PXE booting [split]
« Reply #5 on: August 17, 2009, 10:49:51 PM »
Great idea. So for this solution to work, you need to setup a PXE, TFTP and DHCP services in the same NFS box? What are the booting times that you are getting with this solution? What kind of client HW ? Server Specs?

thanks!

Offline danielibarnes

  • Hero Member
  • *****
  • Posts: 548
Re: NFS storage base scripts mod for PXE booting [split]
« Reply #6 on: August 18, 2009, 09:13:38 AM »
The DHCP server specifies the TFTP server in its configuration file, and it can specify a different machine. The NFS server can also be different. How you arrange it is a matter of convenience.

Offline gerald_clark

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 4254
Re: NFS storage base scripts mod for PXE booting [split]
« Reply #7 on: August 18, 2009, 09:53:54 AM »
Boot time to X is 40 seconds on an 800MHz Via.
A kernel building development system takes 55 seconds.

Offline gerald_clark

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 4254
Re: NFS storage base scripts mod for PXE booting [split]
« Reply #8 on: August 27, 2009, 06:25:58 PM »
I found that waiting for dhcp.sh to return is not sufficient.
Routing and resolv.conf can take up to 3 more seconds.

Instead I loop until I can ping the server.

Here is the new patch file for tc-config.

Code: [Select]
*** tc-config.org       2009-08-25 22:40:34.000000000 -0500
--- tc-config   2009-08-25 22:40:35.000000000 -0500
***************
*** 171,176 ****
--- 171,177 ----
           settime*) SETTIME=${i#*=} ;;
           thm*) THEME=${i#*=} ;;
           bkg*) BACKGROUND=${i#*=} ;;
+            nfsmount* ) NFSMOUNT=${i#*=} ;;
          esac
        ;;
        *)
***************
*** 251,256 ****
--- 252,271 ----
  /sbin/ifconfig lo 127.0.0.1 up
  /sbin/route add 127.0.0.1 lo &

+ if [ -n "$NFSMOUNT" ]; then
+   /etc/init.d/dhcp.sh
+   echo "$NFSMOUNT /mnt/nfs nfs defaults,nolock 0 0" >> /etc/fstab
+   mkdir /mnt/nfs
+   SERVER=`echo $NFSMOUNT | awk -F\: '{ print $1 }'`
+   # dhcp.sh runs udhcpc async, so it exits before network is up
+   CNT=0
+   until ping -c 1 $SERVER >/dev/null 2>&1
+   do
+     [ $((CNT++)) -gt 30 ] && break || sleep 1
+   done
+   mount /mnt/nfs
+ fi
+
  if [ -n "$CHECKFS" ]; then
     touch /etc/sysconfig/checkfs
     wait $fstab_pid
***************
*** 563,569 ****
  if [ -n "$NODHCP" ]; then
    echo "${GREEN}Skipping DHCP broadcast/network detection as requested on boot commandline.${NORMAL}"
  else
!   /etc/init.d/dhcp.sh &
  fi
  [ -n "$CRON" ] && /etc/init.d/crond start
  [ -n "$SSH" ] && /etc/init.d/dropbear start >/dev/null && echo " ${GREEN}ssh started.${NORMAL}"
--- 578,584 ----
  if [ -n "$NODHCP" ]; then
    echo "${GREEN}Skipping DHCP broadcast/network detection as requested on boot commandline.${NORMAL}"
  else
!   [ -z "$NFSMOUNT" ] && /etc/init.d/dhcp.sh &
  fi
  [ -n "$CRON" ] && /etc/init.d/crond start
  [ -n "$SSH" ] && /etc/init.d/dropbear start >/dev/null && echo " ${GREEN}ssh started.${NORMAL}"

Offline gerald_clark

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 4254
Re: NFS storage base scripts mod for PXE booting [split]
« Reply #9 on: August 29, 2009, 11:16:33 AM »
I have determined that the only things needed are these:
1. Add mount.nfs to /usr/local/sbin
2. Apply the two patches above.

This increases tinycore.gz by 42,223 bytes, and provides for an optional NFS based tce and restore directory.

Another tested but not posted method is to use tftp to install the mount.nfs.
This way only tc-config and tc-functions need patching.

The  first ':' separated value is the nfs directory to mount, while the second is an optional tftp file to process.

  append initrd=../tcl-23/boot/tinycore.gz nfsmount=openvz:/tftpboot/nfs/tc2-music;openvz:/nfs/tc2-music/nfs.tar

This uses tftp to download nfs/tc2-music/nfs.tar from openvz and extracts it to the root directory.
then it mounts openvzL/tftpboot/nfs/tc2-music on /mnt/nfs.

Any chance of getting one of these in RC4?
« Last Edit: August 29, 2009, 12:33:08 PM by gerald_clark »

Offline gerald_clark

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 4254
Re: NFS storage base scripts mod for PXE booting [split]
« Reply #10 on: August 30, 2009, 07:51:53 PM »
Latest update with patches.

I have eliminated the need to load nfs into the base.
I have added two boot options.  Ex:

append initrd=../tcl-23/boot/tinycore.gz nfsmount=openvz:/tftpboot/nfs/tc2-music tftplist=openvz:/nfs/tc2-music/tftp/tcz.lst tz=CST+6CDT

tftplist=server:/directory/tczlist
This defines a tftp server and the path to a file that contains a list of tcz to load.  My tcz.list is:
/nfs/tc2-music/tftp/nfs-utils.tcz

nfsmount=server:/directory
This defines an NFS share that will be mounted into /mnt/nfs.
This directory works just like /mnt/hda1 or /mnt/sda1 or any other device for the storage of mydata.tgz and a tce directory.
Backup is to 'nfs'.

By combining these two additions, a diskless workstation can PXE boot TC, load the NFS utilities over tftp, and
then loop mount a full compliment of tcz extensions over NFS.

I use this to boot a diskless music player over the network.  It is accessed via vnc to play music from an NFS export.
No disk, no SD card, no thumb drive.

Here are the two patches

Code: [Select]
*** tc-functions.orig   2009-08-29 22:40:18.000000000 -0500
--- tc-functions        2009-08-29 22:40:35.000000000 -0500
***************
*** 80,85 ****
--- 80,90 ----
   MOUNTPOINT=""
   MOUNTED="no"
   D2="$1"
+  if [ "$D2" == "nfs" ]; then
+     MOUNTPOINT=/mnt/nfs
+     MOUNTED="yes"
+     return
+  fi
   if [ "${D2:0:5}" == "UUID=" ]; then
     D2=`/sbin/blkid -lt $D2 -o device`
     if [ "$?" != 0 ]; then
***************
*** 117,123 ****

  autoscan(){
  FOUND=""
! for DEVICE in `grep "^/dev/" /etc/fstab | grep -vf /etc/init.d/tc_noscan.lst | awk 'FS="/" { print $3}'`; do
     find_mountpoint $DEVICE
     if [ -n "$MOUNTPOINT" ]; then
       if [ "$MOUNTED" == "no" ]; then
--- 122,128 ----

  autoscan(){
  FOUND=""
! for DEVICE in `grep "/mnt/" /etc/fstab | grep -vf /etc/init.d/tc_noscan.lst | awk 'FS="/" { print $3}'`; do
     find_mountpoint $DEVICE
     if [ -n "$MOUNTPOINT" ]; then
       if [ "$MOUNTED" == "no" ]; then

Code: [Select]
*** tc-config.orig      2009-08-29 22:40:18.000000000 -0500
--- tc-config   2009-08-29 22:40:35.000000000 -0500
***************
*** 171,176 ****
--- 171,178 ----
           settime*) SETTIME=${i#*=} ;;
           thm*) THEME=${i#*=} ;;
           bkg*) BACKGROUND=${i#*=} ;;
+            nfsmount* ) NFSMOUNT=${i#*=} ;;
+            tftplist* ) TFTPLIST=${i#*=} ;;
          esac
        ;;
        *)
***************
*** 251,256 ****
--- 253,300 ----
  /sbin/ifconfig lo 127.0.0.1 up
  /sbin/route add 127.0.0.1 lo &

+ # dhcp.sh runs udhcpc async, so it exits before network is up
+ waitfor() {
+    [ -z "$DHCP_RAN" ] && /etc/init.d/dhcp.sh
+    CNT=0
+    until ping -c 1 $1 >/dev/null 2>&1
+    do
+       [ $((CNT++)) -gt 30 ] && break || sleep 1
+    done
+    DHCP_RAN=1
+ }
+
+ # First process tftp entries
+ modprobe -q squashfs 2>/dev/null
+ if [ -n "$TFTPLIST" ]; then
+    SERVER=`echo $TFTPLIST | awk -F\: '{ print $1 }'`
+    FILE=`echo $TFTPLIST | awk -F\: '{ print $2 }'`
+    waitfor $SERVER
+    (  mkdir /tmp/tftp ; cd /tmp/tftp
+       NAME=`basename $FILE`
+       tftp -g -r $FILE $SERVER
+       echo -ne "${BLUE}TFTP Loading Extensions ${YELLOW}"
+       while read EXTENSION
+       do
+          tftp -g -r $EXTENSION $SERVER
+          EXTNAME=`basename $EXTENSION`
+          echo -ne "$EXTNAME "
+          tcloop_mount "$EXTNAME" $(getbasefile "$EXTNAME" 1)
+       done < $NAME
+       echo "${GREEN} Done.${NORMAL}"
+       rm $NAME
+    )
+ fi
+
+ if [ -n "$NFSMOUNT" ]; then
+    SERVER=`echo $NFSMOUNT | awk -F\: '{ print $1 }'`
+    waitfor $SERVER
+    echo "$NFSMOUNT /mnt/nfs nfs defaults,nolock 0 0" >> /etc/fstab
+    echo "Mounting $NFSMOUNT"
+    mkdir /mnt/nfs
+    mount /mnt/nfs
+ fi
+
  if [ -n "$CHECKFS" ]; then
     touch /etc/sysconfig/checkfs
     wait $fstab_pid
***************
*** 302,308 ****
  tceSetup

  #
! modprobe -q squashfs 2>/dev/null
  if [ "$(ls -A /opt/tce)" ]; then
     echo "${BLUE}Checking for /opt/tce items... ${NORMAL}"
     gettceapps "/opt/tce"
--- 346,352 ----
  tceSetup

  #
! # modprobe -q squashfs 2>/dev/null
  if [ "$(ls -A /opt/tce)" ]; then
     echo "${BLUE}Checking for /opt/tce items... ${NORMAL}"
     gettceapps "/opt/tce"
***************
*** 552,558 ****
  if [ -n "$NODHCP" ]; then
    echo "${GREEN}Skipping DHCP broadcast/network detection as requested on boot commandline.${NORMAL}"
  else
!   /etc/init.d/dhcp.sh &
  fi
  [ -n "$CRON" ] && /etc/init.d/crond start
  [ -n "$SSH" ] && /etc/init.d/dropbear start >/dev/null && echo " ${GREEN}ssh started.${NORMAL}"
--- 596,602 ----
  if [ -n "$NODHCP" ]; then
    echo "${GREEN}Skipping DHCP broadcast/network detection as requested on boot commandline.${NORMAL}"
  else
!    [ -z "$DHCP_RAN" ] && /etc/init.d/dhcp.sh &
  fi
  [ -n "$CRON" ] && /etc/init.d/crond start
  [ -n "$SSH" ] && /etc/init.d/dropbear start >/dev/null && echo " ${GREEN}ssh started.${NORMAL}"


That is it.  Hope someone else finds it useful.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 10048
Re: NFS storage base scripts mod for PXE booting [split]
« Reply #11 on: August 31, 2009, 12:34:29 AM »
Suggesting a name change:

- the function "waitfor" is not really descriptive, how about waitfordhcp/waitforserver/etc?
The only barriers that can stop you are the ones you create yourself.

Offline gutmensch

  • Administrator
  • Hero Member
  • *****
  • Posts: 606
  • I can make it disappear, have no fear!
    • remembrance blog
Re: NFS storage base scripts mod for PXE booting [split]
« Reply #12 on: August 31, 2009, 01:33:02 AM »
Keep up the good work, Gerald! I think it's one of the most interesting features since tinycore is so small you can use it on Wyse Terminals and other clients with very little RAM and absolutely no disk space ;-)

I agree that it should be incorporated into tinycore!

btw. I nearly did the same but also swapped out over nfs (because just 50 MB ram) and reduced the tinycore.gz to the mininum by exporting unneeded libs which can be loaded after the nfs connection, so atm I'm working with a 3.5 MB tinycore.gz :)

Best regards,
Robert
If I seem unduly clear to you, you must have misunderstood what I said. (Alan Greenspan)

Offline alu

  • Sr. Member
  • ****
  • Posts: 429
Re: NFS storage base scripts mod for PXE booting [split]
« Reply #13 on: August 31, 2009, 02:07:38 AM »
3.5 MB? awesome. i would be interested in it, and i would ask the TC-team in order to know their mind about this concept:

- 3.5MB core of the core as new concept for microcore;
- a lib.tar.gz or lib.tcz extension file with the needed libraries to push up the core of the core to the current microcore.

what do you think?

Offline gutmensch

  • Administrator
  • Hero Member
  • *****
  • Posts: 606
  • I can make it disappear, have no fear!
    • remembrance blog
Re: NFS storage base scripts mod for PXE booting [split]
« Reply #14 on: August 31, 2009, 02:34:19 AM »
@alu: I never thought about an extension, but you're right... thinking in tc{e,z} structure this would be the right approach! But since the minimization always depends on a NFS server it would be merely some kind of "new" distro (like the LTSP project). Nevertheless one could do:

a.) Minimize the kernel bzImage by using as many modules as possible.
b.) Reduce tinycore.gz to the least minimum (e.g. just busybox, libc, tftp-patches from Gerald, ...)
c.) Use boot params like Geralds and import the "nfs-utils.tcz", "lib.tcz", ... from an tftp/nfs, additionally any other extensions.

I think it would be possible to netboot with this way only 4 MB (bzImage + tinycore.gz) and it would be quite fast for thin clients.

One problem I see is, that it wouldn't reduce the amount of used ram with this extensions, as I need every byte I couldn't even afford to download and loop mount it (right now I'm loading it from nfs directly into ram, when it's needed, and it's "gone" from ram, when I close it).
If I seem unduly clear to you, you must have misunderstood what I said. (Alan Greenspan)