Arduino Sever PXE Script

From Combustory
(Difference between revisions)
Jump to: navigation, search
(Created page with "<source lang="bash"> #/bin/bash #tc_pxe_build v0.1 # Written by John Vaughters at http://www.combustory.com # This script will build the entire pxe directory structure needed to ...")
 
Line 1: Line 1:
 +
=Introduction=
 +
Note:This page is related to [[Arduino Server]] article. Without reading that article, this one will probably not make much sense.
 +
 +
This article provides instructions to build a complete PXE directory for the [http://distro.ibiblio.org/tinycorelinux/ Tiny Core Linux] Distribution. You will be able to run the script below and then move it directly to the /tftpboot directory and point your dhcp server to that directory. This will allow you to boot a wide range of computers via the network. The script is focused on taking care of the details to configure an [[Arduino Server]] that basically acts as a terminal server for connected Arduinos. The server is much more capable than just serving Arduinos, but that I will let you investigate anything outside of the [[Arduino Server]] focus.
 +
 +
=Assumptions=
 +
* You have access to the internet
 +
* You are familiar with the Linux command line
 +
* You understand basic text file configuration methods
 +
* You are familiar with serial communications in Linux
 +
* You are able to manipulate computer BIOS settings
 +
* You understand how to configure PXE booting
 +
* You have a tfpt server running
 +
* You understand sudo, su, chroot commands
 +
 +
=Instructions=
 +
Note: These instructions were tested on Fedora 13, but should run on typical linux distributions
 +
* Become root user. All commands below assume root access
 +
* Create a directory to use for PXE development and change into the directory
 +
mkdir ~/my_tinycore_dir
 +
cd ~/my_tinycore_dir
 +
* Create a file and copy the contents of the script below
 +
gedit tc_pxe_build
 +
* Find the text '''tftplist=192.168.1.1''' in your script and change it to your ip address
 +
* Save the script and make it executable by root only
 +
chmod 700 tc_pxe_build
 +
* Run the script. It will download what it needs and create necessary directories
 +
./tc_pxe_script
 +
* The follwing directories will be created. Keep all the directories, because you may want to run the script multiple times
 +
** tc_downloads - This is where the files needed are downloaded
 +
** tc_pxe - This is the directory that is ready to be moved to /tftpboot
 +
** tc_pxe_mnt - Just a temporary directory to mount the iso file
 +
* Copy the tc_pxe directory to the /tftpboot directory (You should not change the directory name, it has other references to it)
 +
cp -r ~/my_tinycore_dir/tc_pxe/ /tftpboot/
 +
* Point your PXE settings to this directory
 +
* Set up the BIOS on the computer you want to boot and you should be able to boot just about any PC that has netboot capability
 +
=Further Configuration=
 +
Hopefully you were able to get a server running. That is a big part of this set up. In this section we will discuss how to modify your system further to make the it even more useful.
 +
=Troubleshooting=
 +
=TinyCore PXE build script=
 
<source lang="bash">
 
<source lang="bash">
 
#/bin/bash
 
#/bin/bash
 
#tc_pxe_build v0.1
 
#tc_pxe_build v0.1
# Written by John Vaughters at http://www.combustory.com
+
# Written by John Vaughters at http://combustory.com/wiki/index.php/Arduino_Sever_PXE_Script
 
# This script will build the entire pxe directory structure needed to start a tinycore arduino server
 
# This script will build the entire pxe directory structure needed to start a tinycore arduino server
  

Revision as of 19:39, 4 November 2012

Contents

Introduction

Note:This page is related to Arduino Server article. Without reading that article, this one will probably not make much sense.

This article provides instructions to build a complete PXE directory for the Tiny Core Linux Distribution. You will be able to run the script below and then move it directly to the /tftpboot directory and point your dhcp server to that directory. This will allow you to boot a wide range of computers via the network. The script is focused on taking care of the details to configure an Arduino Server that basically acts as a terminal server for connected Arduinos. The server is much more capable than just serving Arduinos, but that I will let you investigate anything outside of the Arduino Server focus.

Assumptions

  • You have access to the internet
  • You are familiar with the Linux command line
  • You understand basic text file configuration methods
  • You are familiar with serial communications in Linux
  • You are able to manipulate computer BIOS settings
  • You understand how to configure PXE booting
  • You have a tfpt server running
  • You understand sudo, su, chroot commands

Instructions

Note: These instructions were tested on Fedora 13, but should run on typical linux distributions 
  • Become root user. All commands below assume root access
  • Create a directory to use for PXE development and change into the directory
mkdir ~/my_tinycore_dir
cd ~/my_tinycore_dir
  • Create a file and copy the contents of the script below
gedit tc_pxe_build
  • Find the text tftplist=192.168.1.1 in your script and change it to your ip address
  • Save the script and make it executable by root only
chmod 700 tc_pxe_build
  • Run the script. It will download what it needs and create necessary directories
./tc_pxe_script
  • The follwing directories will be created. Keep all the directories, because you may want to run the script multiple times
    • tc_downloads - This is where the files needed are downloaded
    • tc_pxe - This is the directory that is ready to be moved to /tftpboot
    • tc_pxe_mnt - Just a temporary directory to mount the iso file
  • Copy the tc_pxe directory to the /tftpboot directory (You should not change the directory name, it has other references to it)
cp -r ~/my_tinycore_dir/tc_pxe/ /tftpboot/
  • Point your PXE settings to this directory
  • Set up the BIOS on the computer you want to boot and you should be able to boot just about any PC that has netboot capability

Further Configuration

Hopefully you were able to get a server running. That is a big part of this set up. In this section we will discuss how to modify your system further to make the it even more useful.

Troubleshooting

TinyCore PXE build script

#/bin/bash
#tc_pxe_build v0.1
# Written by John Vaughters at http://combustory.com/wiki/index.php/Arduino_Sever_PXE_Script
# This script will build the entire pxe directory structure needed to start a tinycore arduino server
 
# Check if already installed
if [ -d tc_pxe ]
   then
        echo '********************* Directory tc_pxe already exists. Please remove tc_pxe directory to run this Intall'
	exit 0
fi
 
# Create Directories
echo '*********************Creating Directories'
 
mkdir tc_downloads
mkdir tc_pxe_mnt
mkdir tc_pxe
mkdir tc_pxe/pxelinux.cfg
mkdir tc_pxe/tc_pxe_dev
mkdir tc_pxe/tc_pxe_dev/core_root
 
 
# Download and copy TinyCore
echo '*********************Downloading, Extracting and Copying TinyCore-current.iso'
 
cd tc_downloads
if [ ! -f TinyCore-current.iso ] 
   then
	wget http://distro.ibiblio.org/tinycorelinux/4.x/x86/release/TinyCore-current.iso
fi
mount TinyCore-current.iso ../tc_pxe_mnt -o loop,ro
cp -r ../tc_pxe_mnt/* ../tc_pxe
umount ../tc_pxe_mnt
cp ../tc_pxe/boot/core.gz ../tc_pxe/tc_pxe_dev
cd ../tc_pxe/tc_pxe_dev/core_root
zcat ../core.gz | sudo cpio -i -H newc -d
 
# Make directories and scripts for arduino initialization
echo '*********************Build new rootfs and add scripts for PXE boot'
 
mkdir home/scada
mkdir home/scada/scripts
mkdir home/scada/data
echo '#!/bin/bash' > home/scada/scripts/arduino_init
echo '# arduino_init - initialization tasks for scada' >> home/scada/scripts/arduino_init
echo '### Main script starts here ###' >> home/scada/scripts/arduino_init
echo '# Store file name of arduino' >> home/scada/scripts/arduino_init
echo 'FILE="/dev/arduino_1"' >> home/scada/scripts/arduino_init
echo ' ' >> home/scada/scripts/arduino_init
echo '# Arduino Communications' >> home/scada/scripts/arduino_init
echo '# set serial commuication for arduino' >> home/scada/scripts/arduino_init
echo 'stty -F $FILE cs8 115200 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts' >> home/scada/scripts/arduino_init
echo '# make sure file (serial device) exist and is readable' >> home/scada/scripts/arduino_init
echo 'if ! pidof socat TCP-LISTEN:2111,fork OPEN:/dev/arduino_1; then' >> home/scada/scripts/arduino_init
echo '  echo "$FILE is not logging"' >> home/scada/scripts/arduino_init
echo '  if [ ! -c $FILE ]; then' >> home/scada/scripts/arduino_init
echo ' 	echo "$FILE : does not exists"' >> home/scada/scripts/arduino_init
echo '	exit 1' >> home/scada/scripts/arduino_init
echo '  elif [ ! -r $FILE ]; then' >> home/scada/scripts/arduino_init
echo '  	echo "$FILE: can not read"' >> home/scada/scripts/arduino_init
echo '  	exit 2' >> home/scada/scripts/arduino_init
echo '  else' >> home/scada/scripts/arduino_init
echo '        socat TCP-LISTEN:2111,fork OPEN:/dev/arduino_1' >> home/scada/scripts/arduino_init
echo '        echo "start process - socat TCP-LISTEN:2111,fork OPEN:$FILE"' >> home/scada/scripts/arduino_init
echo '  fi' >> home/scada/scripts/arduino_init
echo 'fi' >> home/scada/scripts/arduino_init
echo 'exit 0' >> home/scada/scripts/arduino_init
chmod 755 home/scada/scripts/arduino_init
 
# Add services to the boot script
echo '/etc/init.d/dropbear start' >> opt/bootlocal.sh
echo 'sh /home/scada/scripts/arduino_init &' >> opt/bootlocal.sh
echo 'SUBSYSTEMS=="usb", ATTRS{serial}=="A700618T", ATTRS{product}=="FT232R USB UART", ATTRS{idProduct}=="6001", ATTRS{idVendor}=="0403", NAME="arduino_1"' > etc/udev/rules.d/98-arduino.rules
 
# Build tiny_core rootfs
find | cpio -o -H newc | gzip -2 > ../ard-core.gz
cd ..
cp ard-core.gz ../boot/
 
# Create build_tinycore script
echo 'cd core-root' > build_tinycore
echo 'find | cpio -o -H newc | gzip -2 > ../ard-core.gz' >> build_tinycore
echo 'cd ..' >> build_tinycore
echo 'cp ard-core.gz ../boot/' >> build_tinycore
chmod 700 build_tinycore
 
# Download optional software packages
echo '*********************Downloading Additional Packages for TinyCore'
 
cd ../../tc_downloads
# Get ssh dropbear
if [ -f dropbear.tcz ] 
   then
	cp dropbear.tcz ../tc_pxe/cde/optional/
   else
	wget http://distro.ibiblio.org/tinycorelinux/4.x/x86/tcz/dropbear.tcz
	cp dropbear.tcz ../tc_pxe/cde/optional/
fi
# Get net utility socat
if [ -f socat.tcz ] 
   then
	cp socat.tcz ../tc_pxe/cde/optional/
   else
	wget http://distro.ibiblio.org/tinycorelinux/4.x/x86/tcz/socat.tcz
	cp socat.tcz ../tc_pxe/cde/optional/
fi
# Get usb to serial utility
if [ -f usb-serial-3.0.21-tinycore.tcz ] 
   then
	cp usb-serial-3.0.21-tinycore.tcz ../tc_pxe/cde/optional/
   else
	wget http://distro.ibiblio.org/tinycorelinux/4.x/x86/tcz/usb-serial-3.0.21-tinycore.tcz
	cp usb-serial-3.0.21-tinycore.tcz ../tc_pxe/cde/optional/
fi
cd ../tc_pxe
 
# Check if file exists before copy. If it does not exist then download the syslinux and extract
if [ -f "/usr/share/syslinux/pxelinux.0" ]
    then
	cp /usr/share/syslinux/pxelinux.0 .
    else
	echo '*********************Unable to find /usr/share/syslinux/pxelinux.0 downloading syslinux'
	cd ../tc_downloads
    	if [ ! -f "syslinux-4.06/core/pxelinux.0" ]
     	  then
		if [ ! -f "syslinux-4.06.tar.gz" ]
		  then
		      wget http://www.kernel.org/pub/linux/utils/boot/syslinux/4.xx/syslinux-4.06.tar.gz
	    	fi
		tar -zxf syslinux-4.06.tar.gz
		cp syslinux-4.06/core/pxelinux.0 ../tc_pxe/pxelinux.0
	  else 
		cp syslinux-4.06/core/pxelinux.0 ../tc_pxe/pxelinux.0
	fi	
	cd ../tc_pxe
fi
cd pxelinux.cfg
echo 'default boot/vmlinuz' > default
echo 'append initrd=boot/ard-core.gz tftplist=192.168.1.1:/tc_pxe/cde/onboot_x.lst xvesa=800x600x32' >> default 
cd ../cde
echo '/tc_pxe/cde/optional/Xlibs.tcz' > onboot_x.lst
echo '/tc_pxe/cde/optional/Xprogs.tcz' >> onboot_x.lst
echo '/tc_pxe/cde/optional/Xvesa.tcz' >> onboot_x.lst
echo '/tc_pxe/cde/optional/fltk-1.10.tcz' >> onboot_x.lst
echo '/tc_pxe/cde/optional/wbar.tcz' >> onboot_x.lst
echo '/tc_pxe/cde/optional/flwm_topside.tcz' >> onboot_x.lst
echo '/tc_pxe/cde/optional/usb-serial-3.0.21-tinycore.tcz' >> onboot_x.lst
echo '/tc_pxe/cde/optional/dropbear.tcz' >> onboot_x.lst
echo '/tc_pxe/cde/optional/socat.tcz' >> onboot_x.lst
 
echo '*********************Install Complete'
Personal tools
Sponsers
Your Ad Here
Your Ad Here