Arduino Sever PXE Script

From Combustory
(Difference between revisions)
Jump to: navigation, search
(TinyCore PXE build script)
(ssh via dropbear)
Line 72: Line 72:
  chroot /tftpboot/tc_pxe/tc_pxe_dev/core_root/ passwd root
  chroot /tftpboot/tc_pxe/tc_pxe_dev/core_root/ passwd root
* If your Tiny Core system is already booted, then we can transfer over the keys to the root file system with scp
* If your Tiny Core system is already booted, then we can transfer over the keys to the root file system with scp

Revision as of 02:06, 5 November 2012



Note:This page is related to the 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 the created directory to the /tftpboot directory and point your dhcp server to the new 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 I will let you investigate anything outside of the [Arduino Server]] focus.


  • 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


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= in your script and change it to the ip address of your tftp server
  • 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
  • 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/tc_pxe
  • 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.

Root File System

Any changes you make on the server are not kept once you reboot. To change any files on the root file system you will need to change it in the /tftboot/tc_pxe/tc_pxe_dev/core_root directory. This is the root directory for your server. Then you will need to run a script to compact the root file system and copy it to your /tftpboot/tc_pxe directory. You can also use chroot commands to modify settings that that are needed to be done root access.

How to change files in your root file system:

  • Make sure you have root access
  • Make any changes like adding files, changing files or chroot commands
  • Once you are finished with your changes run these commands
cd /tftpboot/tc_pxe/tc_pxe_dev
  • Your new file system changes will show on the next reboot

Arduino Naming with udev

If you plan on hosting more than one Arduino device on this server, then you need consider naming the device with udev. This is probably the most useful feature for making sure that your Arduino devices get named the same at boot up so you can access the correct Arduino with the correct script. The default set up should work with an Arduino Deciemilla. It will name the serial device /dev/arduino_1. Even if I only have one device, I find it rather convenient to use for finding my devices.

How to change the device names of your Arduinos (Or any other USB to Serial Device):

  • Example entry in the file. Changing the attributes and the NAME will be most important. You do not want duplicate names.

SUBSYSTEMS=="usb", ATTRS{serial}=="A700618T", ATTRS{product}=="FT232R USB UART", ATTRS{idProduct}=="6001", ATTRS{idVendor}=="0403", NAME="arduino_1"

  • Once you have made the changes to the files, follow the instructions on updating the root file system above.
TIP: You probably will want to test on any other linux computer to get your settings correct and then copy the settings to your tc_pxe root file system. Otherwise you will spend much time changing and rebooting your system. 

ssh via dropbear

I personally plan on using this server for more than just an Arduino Server so I have included ssh in this set up. You can also use ssh to transfer files that can be used as a method other than the default set up of connecting the serial ports to a network TCP port. To use ssh on TinyCore linux, we have loaded a package called dropbear. We will need to change our root file system to create passwords for the tc and root users. We will also want to copy over the server identifying keys to prevent new keys every time the server reboots. This can be quite annoying when trying to access the server and getting rejected because of the keys.

Steps to use ssh:

  • Make sure you have root access
  • Set the passwords of tc and root users (Enter password when promted)
chroot /tftpboot/tc_pxe/tc_pxe_dev/core_root/ passwd tc
chroot /tftpboot/tc_pxe/tc_pxe_dev/core_root/ passwd root
  • If your Tiny Core system is already booted, then we can transfer over the keys to the root file system with scp


TinyCore PXE build script

#tc_pxe_build v0.1
# Written by John Vaughters at
# This script will build the entire pxe directory structure needed to start a tinycore arduino server
# Check if already installed
if [ -d tc_pxe ]
        echo '********************* Directory tc_pxe already exists. Please remove tc_pxe directory to run this Intall'
	exit 0
# 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 ] 
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/
echo 'sh /home/scada/scripts/arduino_init &' >> opt/
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 ] 
	cp dropbear.tcz ../tc_pxe/cde/optional/
	cp dropbear.tcz ../tc_pxe/cde/optional/
# Get net utility socat
if [ -f socat.tcz ] 
	cp socat.tcz ../tc_pxe/cde/optional/
	cp socat.tcz ../tc_pxe/cde/optional/
# Get usb to serial utility
if [ -f usb-serial-3.0.21-tinycore.tcz ] 
	cp usb-serial-3.0.21-tinycore.tcz ../tc_pxe/cde/optional/
	cp usb-serial-3.0.21-tinycore.tcz ../tc_pxe/cde/optional/
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" ]
	cp /usr/share/syslinux/pxelinux.0 .
	echo '*********************Unable to find /usr/share/syslinux/pxelinux.0 downloading syslinux'
	cd ../tc_downloads
    	if [ ! -f "syslinux-4.06/core/pxelinux.0" ]
		if [ ! -f "syslinux-4.06.tar.gz" ]
		tar -zxf syslinux-4.06.tar.gz
		cp syslinux-4.06/core/pxelinux.0 ../tc_pxe/pxelinux.0
		cp syslinux-4.06/core/pxelinux.0 ../tc_pxe/pxelinux.0
	cd ../tc_pxe
cd pxelinux.cfg
echo 'default boot/vmlinuz' > default
echo 'append initrd=boot/ard-core.gz tftplist= 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
Your Ad Here
Your Ad Here