# this file is part of Bernhard M. Wiedemanns network booting package
# you are free to use, copy and modify within terms of GNU GPL

# usage requires:
# SuSE:   yast -i nasm mkisofs xinetd dhcp-server nfs-utils tftp
# debian: apt-get install nasm mkisofs xinetd dhcp3-server nfs-kernel-server tftpd

# syslinux version
SYSLINUX=2.11
# kernel.org mirror
M=de
# kernel version
KVER=2.4.27
WGET=wget -O-

all:
init: dl tftp/pxelinux.0 kernel
dl:
	wget http://www.$M.kernel.org/pub/linux/libs/uclibc/root_fs_i386.bz2
	bzip2 -cd root_fs_i386.bz2 > root_fs_i386
	wget http://www.$M.kernel.org/pub/linux/kernel/v2.4/linux-$(KVER).tar.bz2
	tar xjf linux-$(KVER).tar.bz2
	ln -s linux-$(KVER) linux
	$(WGET) http://lsmod.de/bootcd/netboot-config > linux/.config
	echo "/netboot/nfsroot 192.168.0.0/16(rw,no_root_squash,async)" >> /etc/exports
	# enable /etc/xinetd.d/tftp

nfsroot/usr:
	mkdir -p nfsroot
	mount -o loop root_fs_i386 nfsroot

kernel: tftp/bzImage
tftp/bzImage: linux/arch/i386/boot/bzImage
	cp -a $< $@
linux/arch/i386/boot/bzImage: linux
	cd linux ; make menuconfig dep bzImage

tftp/pxelinux.0:
	mkdir -p tftp/pxelinux.cfg
	$(WGET) http://www.$M.kernel.org/pub/linux/utils/boot/syslinux/syslinux-$(SYSLINUX).tar.bz2 | tar xj
	ln -sf syslinux-$(SYSLINUX) syslinux
	-cd syslinux ; make
	cp -a syslinux/pxelinux.0 tftp/
#tftp/pxelinux.cfg/default:
	echo -e "PROMPT 1\nTIMEOUT 50\nlabel linux\n\tKERNEL bzImage\n\tAPPEND root=/dev/nfs nfsroot=192.168.11.96:/netboot/nfsroot,rw ip=dhcp" > tftp/pxelinux.cfg/default
# add entries to /etc/dhcpd.conf:
#  filename "pxelinux.0";
#  next-server 192.168.11.96;
#  option root-path "192.168.11.96:/netboot/nfsroot";


start: nfsroot/usr
	rcnfsserver restart
	rcxinetd restart
	rcdhcpd restart
stop:
	rcnfsserver stop
	rcxinetd stop
	rcdhcpd stop
	umount nfsroot
