Booting via PXE.. The how-to

All other questions
Post Reply
Roo

Booting via PXE.. The how-to

Post by Roo » 29 Nov 2005, 21:40

OK I'm going from memory here...

First off, have a working dhcp/pxe/tftp setup... you will also need a proper working NFS server. use pxelinux as your pxe boot rom... this allows you to point to a kernel/initrd (initial ramdisk) file. test this setup using memdisk as your kernel and say memtestp.img (off the cd) as your initrd.

You will need two boxes.. one being the pxe server (I use debian) and another box to test/extract with. You will also need to burn the rescue cd.

So now we are trying to configure booting the kernel and initrd, to load network drivers and nfsmount our root file system.

From the pxe server, mount the cdrom and copy /isolinux/vmlinuz1 and /isolinux/initrd1 to your tftp boot area Usually /tftpboot/X86PC/pxelinux. Also copy sysrcd.dat to your nfs sharepoint. Then set your pxelinux.cfg/default file to boot these files (default file should look like:

default partimg
label partimg
KERNEL vmlinuz1
APPEND initrd=inird1
prompt 0
timeout 0

You should now be able to PXE boot, and get a busy box crash. Or if you PXE boot with the cd in the drive, it will boot. Now we need to move the network startup from the cloop filesystem to the initrd filesystem.

cp initrd1 initrd.gz
gunzip initrd.gz
mkdir /work
mount initrd /work -o loop

We now have access to the files in the initrd file, however this file is too small to add any more, so we copy the files out and create a new one.

mkdir /work-temp
cp -r /work /work-temp
umount /work
dd if=/dev/zero of=initrdnew bs=1k count=8192
mkfs.ext2 initrdnew -N 8192 // The -N creates one inode per block - important for all those /dev files
mount initrdnew /work -o loop // we now have an 8mb ramdisk to put files in.

cd /work-temp/bin // ll shows us that we have alot of files the same size instead of a link to busybox, so we recreate them as links
cd /work-temp;ls -c1 ./bin > temp.txt;vi temp.txt // remove busybox from this list as we can't remove it and relink to itself
cd bin
while read filen
do
rm $filen; ln -s busybox $filen
done < ../temp.txt
cd ..
rm temp.txt

// now we are all set with a optimal image... copy it to our initrdnew.. we'll add nic drivers later

cp -r /work-temp /work // if you have errors, troubleshoot.. this is from memory and i'm no expert

change your pxelinux.cfg/default file to use initrdnew and see if it works. If nothing has changed but your ramdisk size, we are in good shape.

boot the rescue cd from your other machine... we need some files from the cloop filesystem.

make a directory in your initrdnew /lib... copy the files from the booted cd ld-linux.so.2, libc.so.6 libresolv.so.2 to this new folder

make a directory in your inirdnew /static... copy the files from the booted cd dhcpcd ifconfig mount portmap to this new folder.

make a directory in your initrdnew /modules/nfs... copy the files from the booted cd lockd.o, nfs.o, sunrpc.o to this new folder.

make a directory in your initrdnew /modules/netdrv.. copy whatever nic modules you intend to use from your booted cd /lib/modules/2.kernel version/kernel/drivers/net to this new folder... ie.. my machines use 3coms and broadcoms... so I copy tg3.o and all the 3c*.o to the initrdnew /modules/netdrv

You can copy as many files as you want but be sure to leave some freespace in the file for the ramdrive to operate (create mountpoints etc)

that should be it for additional files (again i'm going from memory)... you now have the executables and libraries to setup your network, and mount -t nfs (note the busybox mount under /bin has no nfs capabilities), and nfs kernel modules and NIC kernel modules.

now we modify the /work/linuxrc (this is the script that executes in the initrd) to load nic modules, dhcp an address, load NFS modules, and nfsmount the share with sysrcd.dat in it.

I am not the worlds best scripter, but I don't see him here giving a guide either, so no complaints.

vi /work/linuxrc
under the line 'mount proc' add this using cut and paste (some of the commands use a backwards ') found under the esc key, real hard to tell with fonts so cut and paste is best)

#added for nfs booting
mkdir /lib/modules
ln -s /modules /lib/modules/`uname -r`

for x in `ls /modules/netdrv/*`
do
insmod /modules/netdrv/${x} > /dev/null 2>&1
done

mkdir /var
mkdir /var/lib
/static/dhcpcd eth0
/static/ifconfig

insmod /modules/nfs/sunrpc.o > /dev/null 2>&1
insmod /modules/nfs/lockd.o > /dev/null 2>&1
insmod /modules/nfs/nfs.o > /dev/null 2>&1
#end of adding for nfs booting


This gets network working first thing... then all we have to do is nfs mount our share instead of the cdrom... find the function called findmount()

remark out the lines
# if [ "$*" = "" ]
# then
# nocd
# fi
# while ! mount -t iso9660 -r $1 /newroot/mnt/cdrom; do
# shift
# if [ "$1" = "" ]; then
# nocd
# fi
# done
#***********and add in the line
/static/mount -t nfs 192.168.1.15:/cd/ /newroot/mnt/cdrom

This intructs the linuxrc file to mount our nfsserver share... subst your our server's ip and path rather than 192.168.1.15:/cd/ ensure this folder has sysrcd.dat in it.

Thats it (or at least it should be) reboot and pxe your workstation and it should boot normally. Note that you can pass parameters on the APPEND initrd=initrdnew line such as vga=#### or nokeymap same as you pass in the cd to make a nice framebuffer etc.

Also for troubleshooting add the line nocd immediately after the /static/mount -t nfs command to break out to the busybox ash shell to troubleshoot your nics or nfs or both.

Again this is far from perfect, it just works well for me... i then run some pretty scripts to partimage etc.. i put then in the nfs share and add it to the path.. also the nfs folder can be readonly as so is a cdrom.

celafon
Posts: 3
Joined: 13 Apr 2006, 22:50

Post by celafon » 14 Apr 2006, 00:25

Great to see this howto :)

however I encountered small problem with nfs insmods... I am not able to start up anything from the boot cd, so I mounted the cloop file and was able to grab all necessary files to the image file - all but those related to nfs thing. Now Im stuck when trying to mount nfs disk. The error message states: mount: rpc: program not registered. I dont know why those *.o files are not in the cloop?? If you could give me a hint on working this out I would appreciate it.

Thanks,
Bartek

oneill
Posts: 3
Joined: 04 Jun 2006, 13:20

netboot images

Post by oneill » 04 Jun 2006, 13:33

Hey!

First thanx for this howto but I don't think ppls will walkthrough this and make their own init files, so it's almost useless :(

As the others said on another topic here, this interest many ppl. And I know if there would 1-2 precompiled initrd and kernel image which support nfs and network rootfs, that would be very usefull and I'm sure many of u start useing it.

Thats why i decided to create these images if noone else do it and put the link here if I done.

So what can be the difference between these images, first network card driver (most of u use 3Com,Intel,Realtek cards), NFS server address -> u can read this from stdin or as i can remember there is a dhcpd option which define this.


Regards,

Oneill

ParsEmAll
Posts: 7
Joined: 05 Jun 2006, 14:16

Post by ParsEmAll » 05 Jun 2006, 15:33

Hi

last night I worked out a similar way to boot via PXE.

you can read it at: http://www.sysresccd.org/forums/viewtopic.php?p=3041

I dont use NFS, so no need to recompile a kernel.

Greetings

jabuzzard
Posts: 6
Joined: 18 Dec 2006, 22:17

Re: Booting via PXE.. The how-to

Post by jabuzzard » 19 Dec 2006, 00:12

Roo wrote:
cd /work-temp/bin // ll shows us that we have alot of files the same size instead of a link to busybox, so we recreate them as links
cd /work-temp;ls -c1 ./bin > temp.txt;vi temp.txt // remove busybox from this list as we can't remove it and relink to itself
cd bin
while read filen
do
rm $filen; ln -s busybox $filen
done < ../temp.txt
cd ..
rm temp.txt
Newbie alert their. They are all *hard* linked look at the link count for each item. Recreating them as symlinks is a pointless waste of time

Post Reply