SliTaz SliTaz Forum

You are not logged in.

#1 2012-03-10 10:57:16

Don Manuel
Member
Registered: 2012-03-06
Posts: 13

tftpd: chroot to DIR, not merely chdir

Busybox tftpd has this bug.

http://git.busybox.net/busybox/commit/?id=4e3beb2e1db3d4739a5a924e003938a9815f98e5

This is finally the answer, why my Slitaz based PXE-server doesn't work as other PXE-servers (tested Windows and openSUSE here).

Offline

#2 2012-03-12 13:54:04

Don Manuel
Member
Registered: 2012-03-06
Posts: 13

Re: tftpd: chroot to DIR, not merely chdir

I have just rechecked the current rolling distribution and this bug still persists. But I was able to replace tftpd functionality with http://freecode.com/projects/tftp-hpa .

See the attached local.sh and pxesrv.gz. The latter contains /usr/sbin/in.tftpd and /lib/libwarp.so.0. As the method shown in booting the 4in1 iso, pxesrv.gz just needs to be added to the comma-separated initrd-list.

example:

[c]KERNEL /images/slitaz/bzImage
APPEND initrd=/images/slitaz/rootfs4.gz,/images/slitaz/rootfs3.gz,/images/slitaz/pxesrv.gz lang=de_DE kmap=de-latin1 rw root=/dev/null vga=normal autologin[/c]
The server is configured with a static IP of 192.168.0.6 and it can make use (but also works without) a router and DNS-server on 192.168.0.1. As of now I hardcoded everything in /etc/init.d/local.sh, also a drive label name and a specific folder structure on the boot-media. Please edit local.sh to fit your needs.

edit: Didn't know in advance, that these attachements where prohibited. So I uploaded the files to a filehoster:

http://www.filehosting.at/file/details/320439/pxesrv.gz

http://www.filehosting.at/file/details/320441/local.sh

Offline

#3 2012-03-12 14:42:28

mojo
Administrator
Registered: 2011-03-29
Posts: 2,174

Re: tftpd: chroot to DIR, not merely chdir

Check hg.slitaz.org/wok

Bellard reads the forum,responds with commits,but doesn't always reply.

Commit: http://hg.slitaz.org/wok/rev/30e1308b918c

Cook log: http://cook.slitaz.org/cooker.cgi?pkg=busybox

Download: http://mirror.clarkson.edu/slitaz/packages/cooking/busybox-1.18.4.tazpkg

or

#tazpkg -cc

#tazpkg recharge

#tazpkg -gi busybox --forced

Online

#4 2012-03-24 02:52:29

xtop
Member
Registered: 2012-03-24
Posts: 1

Re: tftpd: chroot to DIR, not merely chdir

Don Manuel, can you please elaborate how you were able to replace tftpd's functionality with tftp-hpa?

I would also like to do the same. Thank you.

Offline

#5 2012-03-24 09:24:51

Don Manuel
Member
Registered: 2012-03-06
Posts: 13

Re: tftpd: chroot to DIR, not merely chdir

Hmm, sorry that this filehoster isn't working any more.

I needed this functionality for the next release of my project OmniBoot. So I have again continued to modify this solution with tftp-hpa. I checked the Slitaz way with the busybox based internal solution frequently with the cooking version and also RC3, but until now still only tftp-hpa works for me.

So how does it work?

Slitaz has a file local.sh in its directory /etc/init.d. This script is processed during start-up and allows adding modification to the boot. I edited it as follows:

/etc/init.d/local.sh

[c]

#!/bin/sh

# /etc/init.d/local.sh - Local startup commands.

#

# All commands here will be executed at boot time.

#

. /etc/init.d/rc.functions

echo "Starting local startup commands... "

export PLABEL="OMNIBOOT"

SIGFILE="autorun.inf"

mkdir /media/$PLABEL

mkdir /boot

mountob(){

mount /media/$PLABEL/boot/make/gpxe_root /boot

mount /media/$PLABEL/images /boot/images

mount /media/$PLABEL/boot /boot/boot

sh /boot/images/slitaz/srv_start

}

mount /dev/cdrom /media/$PLABEL

if [ -e /media/$PLABEL/$SIGFILE ]; then

  mountob

  else

  mount /dev/disk/by-label/$PLABEL /media/$PLABEL

  if [ -e /media/$PLABEL/$SIGFILE ]; then

    mountob

    else exit

  fi

fi

[/c]

Note the chosen preconditions which you need to adapt to your needs.

The variable PLABEL refers to the label of the CD/DVD, the USB-Stick or USB-HDD from which you boot.

SIGFILE refers to a file which is in the root of that medium as checked a few lines later to confirm the detection.

Also the mount directories /boot/make/gpxe_root (containing the folder pxelinux.cfg and the bootfile gpxelinux.0), /boot and /images are hardcoded folders to be found in the root of the bootmedium.

If all is found and mounted finally the script srv_start is run. srv_start can be found in the set folder, as you see I chose /images/slitaz which gets mounted at /boot/images/slitaz.

srv_start

[c]

#!/bin/sh

# configs go here

omniboot_server_ip="192.168.0.6"

omniboot_server_netmask="255.255.255.0"

omniboot_dhcp_start_ip="192.168.0.20"

omniboot_dhcp_end_ip="192.168.0.254"

dns_server_ip="192.168.0.1"

router_ip="192.168.0.1"

# end of configs

for opt in [/c][c]cat /proc/cmdline[/c]; do

  case $opt in

  mount-ntfs)

    DEVICES_LIST=[c]fdisk -l | sed '/NTFS/!d;s/ .*//'[/c]

    for device in $DEVICES_LIST; do

      name=${device#/dev/}

    if ! mount | grep ^$device >/dev/null; then

      mkdir /mnt/$name

      ntfs-3g $device /mnt/$name

    fi

    done

  ;;

  *)

  ;;

  esac

done

rm /var/www/index.html

ln -s /media/$PLABEL/docu/* /var/www

ln -s /media /var/www

ln -s /mnt/* /var/www/media

sed -i "s/firewall httpd/firewall httpd inetd udhcpd/" /etc/rcS.conf

sed -i "s,/usr/bin/tftpd,/usr/sbin/in.tftpd,; s,-r /boot,-4 -s /boot," /etc/inetd.conf

sed -i '/start/d; /end/d' /etc/udhcpd.conf

echo "start $omniboot_dhcp_start_ip" >> /etc/udhcpd.conf

echo "end $omniboot_dhcp_end_ip" >> /etc/udhcpd.conf

echo "opt dns $dns_server_ip" >> /etc/udhcpd.conf

echo "opt router $router_ip" >> /etc/udhcpd.conf

echo "boot_file gpxelinux.0" >> /etc/udhcpd.conf

echo "siaddr $omniboot_server_ip" >> /etc/udhcpd.conf

echo "127.0.0.1" >> /etc/udhcpd.conf

sed -i '/IP=/d; /NETMASK=/d; /GATEWAY=/d; /DNS_SERVER=/d; s/DHCP="yes"/DHCP="no"/; s/STATIC="no"/STATIC="yes"/' /etc/network.conf

echo -e "IP=\"$omniboot_server_ip\"" >> /etc/network.conf

echo -e "NETMASK=\"$omniboot_server_netmask\"" >> /etc/network.conf

echo -e "GATEWAY=\"$router_ip\"" >> /etc/network.conf

echo -e "DNS_SERVER=\"$dns_server_ip\"" >> /etc/network.conf

sh /etc/init.d/network.sh restart

As you see I added a kernel parameter which will automount all found NTFS drives, as there is yet a kernel parameter which does the same with ext drives.

Since OmniBoot has an info-web in a folder named /docu this gets linked to the Slitaz web-root - again an option and not essential for what you look for.

Now before the script finally restarts networking a lot of editing of conf-files happens. We only need to restart networking, since all other services that we need are started after the execution of local.sh.

Please also read my previous posting in this thread again and this thread

http://forum.slitaz.org/topic/how-to-implement-a-new-kernel-parameter-for-live-version-to-boot-a-pxe-server-by-default

to understand how everything is now put together.

If you still have problems getting it running I decided to upload a beta-version of the base-version of the upcoming v0.4 of OmniBoot which contains everything I am explaining here.

http://sourceforge.net/projects/omniboot/files/future/OmniBoot%20v0.4beta%20base.iso/download

(Please be patient if the download doesn't work yet immediately, I really just uploaded right now)

Offline

Registered users online in this topic: 0, guests: 1
[Bot] ClaudeBot

Board footer

Powered by FluxBB
Modified by Visman

[ Generated in 0.026 seconds, 7 queries executed - Memory usage: 1.55 MiB (Peak: 1.77 MiB) ]