General TC > Programming & Scripting - Unofficial

NFS storage base scripts mod for PXE booting [split]

(1/6) > >>

gerald_clark:
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: ---*** 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
--- End code ---


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


--- Code: ---*** 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
--- End code ---

danielibarnes:
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

gerald_clark:
Done. Your suggestion works great.
Thanks.

gerald_clark:
If anyone is interested, here are the 2 patches for 2.3R1:


--- Code: ---*** 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}"
--- End code ---



--- Code: ---*** 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
--- End code ---

^thehatsrule^:
[split code+discussion from Netbooting with installed apps (Solved)]

Navigation

[0] Message Index

[#] Next page

Go to full version