-
Notifications
You must be signed in to change notification settings - Fork 2k
Add pxetools for easy netboot server. Improve netboot documentation. #406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
## pxetools | ||
We have created a Python script that is used internally to quickly set up Pi's that will network boot. It takes a serial number, which you can find in `cat /proc/cpuinfo`, an owner name and the name of the Pi. It then creates a root filesystem for that Pi from a raspbian image. There is also a --list option which will print out the IP address of the Pi, and remove an option. The follwing instructions describe how to set up the environment required by the script starting from a fresh Raspbian lite image. It might be a good idea to mount a hard disk or flash drive on /nfs so that your SD card isn't providing filesystems to multiple Pi's. This is left as an exercise for the reader. | ||
|
||
``` | ||
sudo raspi-config | ||
# Pick expand filesystem option | ||
# Finish | ||
# Reboot | ||
|
||
sudo wget https://raw.githubusercontent.com/raspberrypi/documentation/master/hardware/raspberrypi/bootmodes/pxetools/prepare_pxetools | ||
bash prepare_pxetools | ||
|
||
prepare_pxetools should prepare everything you need to use pxetools | ||
``` |
107 changes: 107 additions & 0 deletions
107
hardware/raspberrypi/bootmodes/pxetools/prepare_pxetools
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
sudo apt-get update; sudo apt-get -y upgrade | ||
sudo apt-get install -y rpi-update | ||
sudo BRANCH=next rpi-update | ||
|
||
sudo apt-get install python3 python3-pip ipcalc | ||
sudo pip3 install tabulate | ||
|
||
# Get network info | ||
NAMESERVER=$(cat /etc/resolv.conf | grep nameserver | head -n 1 | cut -d " " -f2) | ||
GATEWAY=$(ip -4 route | grep default | cut -d " " -f3) | ||
IP=$(ifconfig eth0 | grep "inet addr" | cut -d " " -f 12 | cut -d ":" -f 2) | ||
BRD=$(ifconfig eth0 | grep "inet addr" | cut -d " " -f 14 | cut -d ":" -f 2) | ||
NETMASK=$(ifconfig eth0 | grep "inet addr" | cut -d " " -f 16 | cut -d ":" -f 2) | ||
NETWORK=$(ip -4 addr show dev eth0 | grep inet | cut -d " " -f6 | xargs ipcalc | grep Network | cut -d " " -f4) | ||
|
||
echo "IP: $IP" | ||
echo "Netmask: $NETMASK" | ||
echo "Broadcast: $BRD" | ||
echo "Nameserver: $NAMESERVER" | ||
echo "Gateway: $GATEWAY" | ||
|
||
echo "Setting static IP using above information" | ||
|
||
cat << EOF | sudo tee /etc/network/interfaces | ||
auto lo | ||
iface lo inet loopback | ||
|
||
auto eth0 | ||
iface eth0 inet static | ||
address $IP | ||
netmask $NETMASK | ||
gateway $GATEWAY | ||
EOF | ||
|
||
sudo systemctl restart networking | ||
|
||
# In case it is already set | ||
sudo chattr -i /etc/resolv.conf | ||
|
||
echo "Setting nameserver" | ||
cat << EOF | sudo tee /etc/resolv.conf | ||
nameserver $NAMESERVER | ||
EOF | ||
|
||
# Prevent DNSMasq from changing | ||
sudo chattr +i /etc/resolv.conf | ||
|
||
sudo apt-get install -y nfs-kernel-server dnsmasq iptables-persistent unzip nmap kpartx | ||
|
||
sudo mkdir -p /nfs | ||
sudo mkdir -p /tftpboot | ||
sudo cp -r /boot /tftpboot/base | ||
sudo chmod -R 777 /tftpboot | ||
|
||
echo "Writing dnsmasq.conf" | ||
cat << EOF | sudo tee /etc/dnsmasq.conf | ||
port=0 | ||
dhcp-range=$BRD,proxy | ||
bind-interfaces | ||
log-dhcp | ||
enable-tftp | ||
log-facility=/var/log/dnsmasq | ||
tftp-root=/tftpboot | ||
pxe-service=0,"Raspberry Pi Boot" | ||
EOF | ||
|
||
# Flush any rules that might exist | ||
sudo iptables -t raw --flush | ||
|
||
# Create the DHCP_clients chain in the 'raw' table | ||
sudo iptables -t raw -N DHCP_clients || true | ||
|
||
# Incoming DHCP, pass to chain processing DHCP | ||
sudo iptables -t raw -A PREROUTING -p udp --dport 67 -j DHCP_clients | ||
|
||
# Deny clients not in chain not listed above | ||
sudo iptables -t raw -A DHCP_clients -j DROP | ||
|
||
sudo iptables-save | sudo tee /etc/iptables/rules.v4 | ||
|
||
# Start services | ||
sudo systemctl enable dnsmasq | ||
sudo systemctl restart dnsmasq | ||
sudo systemctl enable nfs-kernel-server | ||
sudo systemctl restart nfs-kernel-server | ||
sudo systemctl enable rpcbind | ||
sudo systemctl restart rpcbind | ||
|
||
echo "Getting latest Raspbian lite image to use as NFS root" | ||
# Get latest Raspbian lite image | ||
sudo mkdir -p /nfs/bases | ||
cd /nfs/bases | ||
sudo wget -O raspbian_latest.zip https://downloads.raspberrypi.org/raspbian_lite_latest | ||
sudo unzip raspbian_latest.zip | ||
sudo rm raspbian_latest.zip | ||
|
||
sudo wget -O /usr/local/sbin/pxetools https://raw.githubusercontent.com/raspberrypi/documentation/master/hardware/raspberrypi/bootmodes/pxetools/pxetools | ||
sudo chmod +x /usr/local/sbin/pxetools | ||
|
||
sudo sed -i "s,LAN = \"10.3.14.0/24\",LAN = \"$NETWORK\"," /usr/local/sbin/pxetools | ||
sudo sed -i "s,NFS_IP = \"10.3.14.18\",NFS_IP = \"$IP\"," /usr/local/sbin/pxetools | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do these values get hard-coded? Wouldn't it be better for the |
||
|
||
echo "Now run sudo pxetools --add \$serial" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
raspbian should probably have a capital R.
Was "and remove an option" supposed to be "and a --remove option" ?
"Pi's" shouldn't have an apostrophe.