Arduino Sever PXE Script
Jvaughters (Talk | contribs) |
Jvaughters (Talk | contribs) |
||
(7 intermediate revisions by one user not shown) | |||
Line 1: | Line 1: | ||
+ | <anyweb>http://combustory.com/wiki/ads/ad_rtc.html</anyweb> | ||
+ | |||
+ | {{default}} | ||
+ | |||
+ | <anyweb>http://combustory.com/wiki/ads/ad_rtc_1.html</anyweb> | ||
+ | |||
+ | |||
=Introduction= | =Introduction= | ||
Note:This page is related to the [[Arduino Server]] article. Without reading that article, this one will probably not make much sense. | Note:This page is related to the [[Arduino Server]] article. Without reading that article, this one will probably not make much sense. | ||
Line 37: | Line 44: | ||
=Further Configuration= | =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. | + | Hopefully you were able to get a server running. That is a big part of this set up and the computer is useful even in this state, but I believe you will find it beneficial to make some more changes. In this section we will discuss how to modify your system further to make the it even more useful. |
==Root File System== | ==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. | 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. | ||
+ | ===Best Practices=== | ||
+ | If you have created a bootable PXE system, then you are off to a great start. Since the configuration part can take some time, you may want to save the file periodically. That way if you make a mistake, you do not loose all your effort. Fortunately this is a breeze. You only need to copy one file. In a jam, you can extract this file and create known good root file system. | ||
+ | |||
+ | * Create backup of root file system | ||
+ | cd /tftpboot/tc_pxe/tc_pxe_dev/ard-core.gz /tftpboot/tc_pxe/tc_pxe_dev/ard-core.gz.bak | ||
+ | * restore the backup of root file system | ||
+ | cd /tftpboot/tc_pxe/tc_pxe_dev/core_root | ||
+ | rm -rf /tftpboot/tc_pxe/tc_pxe_dev/core_root/* | ||
+ | zcat ../ard-core.gz.bak | sudo cpio -i -H newc -d | ||
+ | |||
+ | ===Create New Root File System=== | ||
How to change files in your root file system: | How to change files in your root file system: | ||
* Make sure you have root access | * Make sure you have root access | ||
Line 64: | Line 82: | ||
==ssh via dropbear== | ==ssh via dropbear== | ||
− | + | If you plan on using this server for more than just an [[Arduino Server]] I recommend you configure ssh, which I included in the additional packages. 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: | Steps to use ssh: | ||
Line 73: | Line 91: | ||
* 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 | ||
mkdir /tftboot/tc_pxe/tc_pxe_dev/core_root/etc/dropbear | mkdir /tftboot/tc_pxe/tc_pxe_dev/core_root/etc/dropbear | ||
− | scp | + | * Log into your TinyCore computer via ssh (Change ip's to match your network, accept ssh key and enter password), then copy key files over via scp |
− | + | ssh tc@192.168.1.150 | |
+ | sudo scp /etc/dropbear/dropbear_dss_host_key root@192.168.1.1:/tftpboot/tc_pxe/tc_pxe_dev/core_root/etc/dropbear/ | ||
+ | sudo scp /etc/dropbear/dropbear_rsa_host_key root@192.168.1.1:/tftpboot/tc_pxe/tc_pxe_dev/core_root/etc/dropbear/ | ||
+ | exit | ||
+ | * Update the root file system per instructions above. | ||
+ | * Next time you reboot, you should be able to access ssh without accepting a key | ||
+ | |||
+ | ==Change the tc_pxe directory name== | ||
+ | You may want to use your own directory names and if you want to have multiple computers using different images, then you will want to consider changing the tc_pxe directory name. | ||
+ | |||
+ | * Change directory to ard_srv_1 from tc_pxe | ||
+ | sed -i 's/tc_pxe/ard_srv_1/g' /tftpboot/tc_pxe/cde/onboot_x.lst | ||
+ | sed -i 's/tc_pxe/ard_srv_1/g' /tftpboot/tc_pxe/pxelinux.cfg/default | ||
+ | cd /tftpboot | ||
+ | mv tc_pxe ard_srv_1 | ||
+ | * Point your PXE set up to the new directory and you are good to go. | ||
+ | |||
+ | ==Other Configuration Ideas== | ||
+ | * Use multiple servers with different image directories. Study how to boot PXE by MAC address. | ||
+ | * Add packages to the PXE server. | ||
=Troubleshooting= | =Troubleshooting= | ||
+ | |||
+ | |||
+ | ==Replace PXE TinyCore System== | ||
+ | The best part of using TinyCore and this script is that if for some reason you messed up, you just start from scratch and it only takes a few minutes to run the script again as long as you do not delete the tc_downloads directory. It is even more useful if you had a running system from the start, then messed it up, then all you have to do is delete the /tftpboot/tc_pxe directory and then copy it from the ~/my_tinycore_dir directory. | ||
+ | * Remove PXE set up and replace it with the default system created by script | ||
+ | rm -rf /tftpboot/tc_pxe | ||
+ | cp -r ~/my_tinycore_dir/tc_pxe /tftpboot/tc_pxe | ||
+ | * More drastic measure to remove the default system and re-run script | ||
+ | rm -rf ~/my_tinycore_dir/tc_pxe | ||
+ | cd ~/my_tinycore_dir | ||
+ | ./tc_pxe_script | ||
+ | |||
=TinyCore PXE build script= | =TinyCore PXE build script= | ||
<source lang="bash"> | <source lang="bash"> |
Latest revision as of 21:59, 8 November 2012
Welcome to Combustory
Any questions or comments:
- Send them to - combustor@combustory.com
|
Introduction
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.
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 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
./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/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 and the computer is useful even in this state, but I believe you will find it beneficial to make some more changes. 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.
Best Practices
If you have created a bootable PXE system, then you are off to a great start. Since the configuration part can take some time, you may want to save the file periodically. That way if you make a mistake, you do not loose all your effort. Fortunately this is a breeze. You only need to copy one file. In a jam, you can extract this file and create known good root file system.
- Create backup of root file system
cd /tftpboot/tc_pxe/tc_pxe_dev/ard-core.gz /tftpboot/tc_pxe/tc_pxe_dev/ard-core.gz.bak
- restore the backup of root file system
cd /tftpboot/tc_pxe/tc_pxe_dev/core_root rm -rf /tftpboot/tc_pxe/tc_pxe_dev/core_root/* zcat ../ard-core.gz.bak | sudo cpio -i -H newc -d
Create New Root File System
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 ./build_tinycore
- 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):
- I highly recommend you visit the Arduino Communications Device Naming with udev article to help you understand
- Below is the file you will want to modify to match up your devices
/tftpboot/tc_pxe/tc_pxe_dev/core_root/etc/udev/rules.d/98-arduino.rules
- 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
If you plan on using this server for more than just an Arduino Server I recommend you configure ssh, which I included in the additional packages. 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
mkdir /tftboot/tc_pxe/tc_pxe_dev/core_root/etc/dropbear
- Log into your TinyCore computer via ssh (Change ip's to match your network, accept ssh key and enter password), then copy key files over via scp
ssh tc@192.168.1.150 sudo scp /etc/dropbear/dropbear_dss_host_key root@192.168.1.1:/tftpboot/tc_pxe/tc_pxe_dev/core_root/etc/dropbear/ sudo scp /etc/dropbear/dropbear_rsa_host_key root@192.168.1.1:/tftpboot/tc_pxe/tc_pxe_dev/core_root/etc/dropbear/ exit
- Update the root file system per instructions above.
- Next time you reboot, you should be able to access ssh without accepting a key
Change the tc_pxe directory name
You may want to use your own directory names and if you want to have multiple computers using different images, then you will want to consider changing the tc_pxe directory name.
- Change directory to ard_srv_1 from tc_pxe
sed -i 's/tc_pxe/ard_srv_1/g' /tftpboot/tc_pxe/cde/onboot_x.lst sed -i 's/tc_pxe/ard_srv_1/g' /tftpboot/tc_pxe/pxelinux.cfg/default cd /tftpboot mv tc_pxe ard_srv_1
- Point your PXE set up to the new directory and you are good to go.
Other Configuration Ideas
- Use multiple servers with different image directories. Study how to boot PXE by MAC address.
- Add packages to the PXE server.
Troubleshooting
Replace PXE TinyCore System
The best part of using TinyCore and this script is that if for some reason you messed up, you just start from scratch and it only takes a few minutes to run the script again as long as you do not delete the tc_downloads directory. It is even more useful if you had a running system from the start, then messed it up, then all you have to do is delete the /tftpboot/tc_pxe directory and then copy it from the ~/my_tinycore_dir directory.
- Remove PXE set up and replace it with the default system created by script
rm -rf /tftpboot/tc_pxe cp -r ~/my_tinycore_dir/tc_pxe /tftpboot/tc_pxe
- More drastic measure to remove the default system and re-run script
rm -rf ~/my_tinycore_dir/tc_pxe cd ~/my_tinycore_dir ./tc_pxe_script
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'