Network Boot One Raspberry Pi From Another One - No SD Card needed using PXE Boot, TFTP & NFS

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello my name's gary sims and this is gary explains did you know it's possible to boot a raspberry pi off another raspberry pi and the client raspberry needs no sd card it doesn't need any attached storage it runs everything over the network talking to the second raspberry pi including the home directories and all the space it needs for linux all happens over the network absolutely brilliant technology so today i'm going to go through a tutorial to tell you how to set that up so if you want to find out more please let me explain [Music] so network booting has been around for decades i remember when i was working for digital equipment corporation a lot of the remote client workstations we were using would boot remotely over the network now the raspberry pi has remote boot built into it it's an environment called the pre-boot execution environment p the x from execution e p x e pixie okay and pixie is a standard way of booting up a client over a network and the way it works is basically this the the raspberry pi turns on and it goes oh i've got no sd card i can't boot up hey i'll ask over the network if i can and then a server and that's the second board that we're going to set up says yeah i can help you boot up and then it starts sending files over to the raspberry pi so it can boot up and we'll talk more about that in a moment so pix is a way of booting up one raspberry pi from another one or from another device in fact if you'd like to see some videos on how to boot up a raspberry pi from for example a synology nas or from a linux server or even from windows or mac do let me know in the comments below and i'll see where there's enough requests that we can make that video okay so you're going to need two raspberry pi boards we're going to stick with raspberry pi 4. some of this is possible with earlier versions of the raspberry pi if you kind of get the right bootloaders let's stick with the raspberry pi 4 we're going to use one as the server that's the one that holds all the files and we're going to use one as the client okay the first thing to do is prepare the client board now to do that you're going to need to know two things the first of all we're going to need to find out some details about the board particularly its mac address and its serial number now the reason you need those is because when the board boots up it actually provides its serial number and says hey i've got this serial number can you help me boot up and it means that on the server it can have a whole area of disk whole set of files that are just for that particular board based on its serial numbers there's no way of uniquely identifying the board i need the mac address because sometimes looking at some of the log files trying to debug where have you gone wrong in your configuration seeing the mac address appear saying hey i've sent out a boot request for example is really really useful now there are a couple of commands you can use to get both of those out now i've listed all the commands that you need in a document over in my github repository rather than trying to tell you here over a video exactly the command you need to type in but you need to get those two and if you don't want to use uh commands to get them when you actually boot up the raspberry pi if there's no sd card in it there is a screen that comes at the beginning and it does tell you the serial number and it does tell you the mac address there one thing to notice when you get the serial number from the command line it may have a leading zero if you have any leading zeros in your serial number take them off you need to start with one or upwards and the second thing you need to do is you need to change the boot order of the raspberry pi by default it boots up to the sd card maybe it'll try at the usb but we want it to boot up over the network now to do that you are going to need to boot up into raspberry pi os temporarily so you need to prepare yourself an sd card boot up into raspberry pi os 32-bit version or 64-bit desktop without desktop doesn't matter as long as running raspberry pi os of course you can also do it over the internet and then install it onto an sd card as i showed in my previous video now once you've got raspberry pi os up and running go into raspberry raspberry config okay and then go into the menus there to change the boot order and the exact menu is you go into advanced options boot order and then pick network boot now here's a really important step that i felt myself in this once you've got a i said you need to reboot at this point not just shut down if you think that's it shut down i can move on to the next step it won't work you actually need to reboot and come back up into raspberry pi os because only then is the new configuration written to the firmware so now do a full reboot of your client machine now once you've done that you can actually now shut it down again and take away that sd card we don't need it anymore now we're just going to use that raspberry pi with no attached storage to it whatsoever now step two is to prepare the server now for the server we're going to use another raspberry pi 4 and what i have done is i've actually attached an external ssd using the usb 3 port because we're going to be storing a lot of files we've got a whole nother copy of linux going on there there's going to be stuff going on and actually it does kind of hammer the sd card and it's better to do it on its own external storage if you don't want to do that you can do it on an xd an sd card make sure enough space on it obviously but it will be a bit slower so if you are using an external uh storage make sure it's mounted under slash nfs network file system and you'll see why in a moment but right now i've got a dedicated ssd mounted under nfs just to hold the files for all the remote raspberry pi's that want to boot off this server now there are two main components to booting up a remote raspberry said first of all you need to have pixie pixels says hey give me some information how i can boot up and what actually happens is a protocol called tftp the trivial file transfer protocol very very simple doesn't even have any authentication just like can i have a file yes here it is and basically when pixie boots up he says can i have a copy of the kernel please like to boot up into linux it goes yes you can get it here using uh tftp and it knows enough it's simple enough to go and get it so we're gonna need a tftp server on our raspberry pi server and we get that using dns mask now dns mask is a full pixie server and it's also a tftp server so we can configure that now i'll show you how to do all the configuration in that document but basically if you've got that up and running on the machine then you're going to have a tftp server to serve your remote client now what you put in the tftp area is a copy of all the boot files if you ever look in slash boot on your raspberry pi it's full of all these really weird and interesting files many of them dot bin dot elf okay and they're all basically binary files that you need to boot up the uh the raspberry pi and so you need to take a copy of those files either from a running system in fact you can take it from the very server itself that's running because it's also a raspberry pi 4 and we've got a raspberry pi for one of boot ups it's exactly the same files copy them into there or you can download an image file from the raspberry pi foundation unpack it take the files out of there the instructions are again all in my github repository bottom line the tftp area needs to be populated with the boot files for the raspberry pi and you actually end up having one set of directories for each of the serial numbers so if you boot up let's say 10 of these they all have their own boot up area of course that means also you could try other models of raspberry pi in the future when other ones come out they all have their own area with the right boot files in it and the second thing you need is an actual linux installation for the remote client and that's where we use nfs the network file system so basically what happens is when the kernel boots up it says well where am i going to find my root file system where is slash bin where is slash home where is slash var where am i going to get all this stuff from because hey well actually you're not going to get it on the ssd you're going to find it over the network and there's a special version of the kernel that understands to mount a root filing system over the network so our slash nfs area will have subdirectories each again based on the serial number for that particular board and underneath it is a full linux distribution etcetera vastly home slash bin it's all there and what you do is you copy that again either from the running server because it's a raspberry pi 4 you'll print a boot right of course you just say hey copy my main files here over to this area or again you can download an image file unpack them and extract them from there again all the instructions how you copy those over are in that github repository so basically what you end up with under nfs is a full linux distribution fully installed with all the files that it needs including the home directory which will then be served to the remote client over the network file system now a couple other things that you need to do again these are all documented inside of my github repository is you need to export those directories so you need to export every time you create a new boot up for a new board it needs to be exported so that nfs says hey this directory is available for this serial number another thing you need to do is you need to change the command line parameters that get passed to the board the client board so that it knows to find the root directory on a remote server and not on itself and the final thing you need to do is you need to make sure that the static sector slash fs tab so that's the file system table that's on the the ins inside of that nfs directory for each board actually says don't try to mount the sd card mount your route partition over the network so those are three files that need to be changed and again all the documentation is over there in my github project in fact what i've also done is i've written two shell scripts that kind of take all of the hard work out of this the first one is a kind of a preparation one that basically installs the tftp area make sure the nfs server is installed installs dns mask it creates the files that you need for all that lot to work and then the second one is an ad board so you basically say add this board with this serial number and it will make sure there's a whole copy created for it both in tftp and inside nfs it will fiddle with the fs tab it'll fiddle with the exports file it will do all that stuff so that hopefully if i got the scripts right and i did a bit of testing on them then basically you can say here's a new board here's the serial number and you plug it in and then it will just boot up because those scripts take all the hard work out of them do give them a try love to hear your feedback i've got mistakes in it if it can be improved hey let's do that open source you know let's just change to tell me what you want to change and we'll have a look at it and the final thing then is once you've got the nfs server and the tftp server your pixel cert pxe server all up and running then basically reboot it to make sure everything is okay and then plug in your uh remote board and it should uh boot up now there are a few commands i also list in the github domination to allow you to see the kind of the messages that going back and forth it's useful looking in slash var log slash daemon.log if there's a dns mask.log file because there you can see the different interactions to what's uh going on but basically once you're done you should have a remotely booted file now of course this isn't going to be as fast as if it's using local storage because it's doing everything over the network however i did some testing and let's say if i wanted to create a file that is like 500 megabytes in size if you do that locally on an ssd it might take two seconds if you do it over nfs it might take 11 seconds so it is five times faster but it's not like it takes three minutes or something like that so it is usable uh and so it is actually a good way of getting all these raspberry pies built up now why would you want to do that well lots of different reasons let's say you wanted to build a small cluster one good way rather than preparing all the individual sd cards is to boot up over the network let's say you wanted to build a render farm a distributed compiling setup again booting up over the network is really good or if you've got a remote thing let's say you've got a you know a security camera or a weather station that you've connected up somewhere in your house well if you use power over ethernet and i've got a video on how to use power over ethernet for a raspberry pi here on this channel in fact that's what i did on my test board it's got the power over ethernet hat on it so you just plug in the the ethernet cable and it boots up so imagine you've got a raspberry pi connected to a camera or to some sensors you put in a nice little plastic container and you've got it doing something and all you do is plug in the ethernet cable with power going over it and it will boot up over the network talk to your remote server and then actually off you go and it's all running so that's a really good way of really doing remote stuff without next time you want to fix something or upgrade the operating system or next time you want to you know there's an sd card has been that you go up into your tree or up into the roof of your house or wherever and try to change it nope this all happens over the network so as long as there's a cable connected to it it will work okay that's it as i said check out the documentation in the github this really is a fun project and i had a lot a great time getting this all up and running and learned a lot about remote booting nfs tftp all in the way so if you want to give it a go please do and tell me about the results that you have in the comments below okay that's it my name's gary sims this is gary explains i really hope you enjoyed this video if you did please do give it a thumbs up if you like these kind of videos hey stick around subscribe to the channel don't forget you can follow me on twitter at gary explained and i also have a newsletter go to garyexplains.com type in your email address you will get the email but you won't get any spam okay that's it i'll see in the next one [Music] you
Info
Channel: Gary Explains
Views: 26,143
Rating: undefined out of 5
Keywords: Gary Explains, Tech, Explanation, Tutorial, Raspberry Pi, PXE, Network boot, TFTP, NFS, Linux, Raspberry Pi OS, boot over network, remote boot, Trivial File Transfer Protocol, Network File System, Preboot Execution Environment, MAC Address, raspi-config, bootloader, Raspberry Pi network boot, network boot your raspberry pi, Ethernet, Wired networking, Dnsmasq
Id: YSyM_k1_QGM
Channel Id: undefined
Length: 13min 47sec (827 seconds)
Published: Thu Feb 17 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.