BOOT FROM PXE

 boot from pxe

Prepartion

1 Server with DHCP, TFTPBOOT and HTTPD
First we need a server with dhcpd, ftpd and httpd installed and configured correctly. It has not to be the same box, but you need at least access to the configuration files.

Please note: I'll explain how to setup the dhcp and tftp server, but I assume you have a http daemon running.
Following installation examples are for a CentOS 5 server which will be used as installation server, but it works with nearly any other distributions too.

2 Installing up dhcpd

yum install dhcp

If you are using Debian there should be a package like dhcp or dhcp-server (try: apt-cache search dhcp|grep server).

3 Setting up dhcpd
Example of dhcpd.conf (/etc/dhcpd.conf):

ddns-update-style ad-hoc;
option subnet-mask 255.255.255.0;
option domain-name-servers 192.168.0.1;

subnet 192.168.0.0 netmask 255.255.255.0 {
range 192.168.0.200 192.168.0.210;
option broadcast-address 192.168.0.255;
option routers 192.168.0.1;
next-server 192.168.0.1;
filename "pxelinux.0";
max-lease-time 100;
default-lease-time 100;
}

This assumes to have following configuration:

IP Network (subnet-mask / subnet .... netmask )192.168.0.0/24
DNS Server (domain-name-servers )192.168.0.1
DHCP IP Range (range )192.168.0.200-210
Broadcast (option broadcast-address )192.168.0.255
Gateway (option routers )192.168.0.1
tftboot Server (next-server )192.168.0.1 (will be setup later)


4 Installing the TFTP Daemon

yum install tftp-server

The equivalent Debian package should be tftpd , but I think the configuration will be different.

5 Configuring the TFTP Daemon
The TFTP Daemon will be launched via xinetd and can be enabled/disabled in /etc/xinetd.d/tftp.
Example of /etc/xinetd.d/tftp

service tftp
{
disable = no
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /tftpboot -vv
per_source = 11
cps = 100 2
only_from = 192.168.0.0 192.168.1.0
flags = IPv4
}

This starts the tftp server with extra verbose options and only allows connections from the networks 192.168.0.0/24 and 192.168.0.1/24. The output will be stored in /var/log/messages.

6 Get the files
The boot loader: pxelinux.0
This file is part of the package syslinux and will be in /usr/lib/syslinux.

yum install syslinux
cp /usr/lib/syslinux/pxelinux.0 /tftpboot

It should be the same for debian (apt-get install syslinux). If not, here you are: pxelinux.0.gz (don't forget to gunzip it).

7 /tftpboot/pxeboot.msg
The content of pxeboot.msg is shown when your server boots via PXE. This file can contain any text you like.
Example /tftpboot/pxeboot.msg:

** Welcome to my wonderful automatic installation **

Following commands are available:

Boot from local hard disk
-------------------------
Command: local

CentOS5 (auto and manual installation)
-------
Command: installauto-centos5
Command: install-centos5

Debian 4 Etch (auto and manual installation)
-------------
Command: installauto-debian4
Command: install-debian4

Rescue Boot
-----------
Command: rescue

Memtest86
-------
Command: memtest


8 Create default config
You need to create a default config file which will be loaded by the clients. There you define the above listed commands you'd like to have. It has to be stored in /tftpboot/pxelinux.cfg and named default.
Example: /tftpboot/pxelinux.cfg/default

# This command will be executed automatically after the below set timeout
default local

# Always prompt
prompt 1

# Display the bootup message
display pxeboot.msg

# If you like playing around, check out this :-)
# Display some extra stuff when pressing the F-keys (.msg files has to exist)
#F1 help.msg
#F2 bla.msg
#F3 xxx.msg
#... and so on

# Boot automatically after x seconds in tenths of a second
timeout 30

# COMMANDS

# Boot local machine without doing something
label local
localboot 0

# CentOS 5 Auto-Installation
label installauto-centos5
kernel centos5/vmlinuz
append ksdevice=eth0 load_ramdisk=1 prompt_ramdisk=0 ramdisk_size=16384 /
initrd=centos5/initrd.img network ks=http://192.168.0.1/centos5_ks.cfg

# CentOS 5 Manual Installation
label install-centos5
kernel centos5/vmlinuz
append ksdevice=eth0 load_ramdisk=1 prompt_ramdisk=0 ramdisk_size=16384 /
initrd=centos5/initrd.img network


# Debian 4 Auto-Installation
label installauto-debian4
kernel debian4/linux
append initrd=debian4/initrd.gz preseed/url=http://192.168.0.1/deb4_preseed.cfg /
debconf/priority=critical root=/dev/rd/0 ramdisk_size=10392 devfs=mount,dall rw /
locale=de_DE interface=eth0

# Debian 4 Manual Installation
label install-debian4
kernel debian4/linux
append initrd=debian4/initrd.gz root=/dev/rd/0 devfs=mount,dall rw ramdisk_size=10392

# Rescue Image
label rescue
kernel rescue/vmlinuz
append initrd=rescue/rescue.cpi root=/dev/ram0 init=/linuxrc ramdisk_size=54000 /
CONF="`/dev/fd0:/rescue`;;;;;;;;;;;"

# Memtest86
label memtest
kernel memtest/memtest

Please adjust the IP of your webserver (in this case 192.168.0.1) and make sure that it is accessable directly with the IP. I've noted that Debian doesn't work properly when entering a Domain Name instead of the IP.

You can also create an individual config file for each server, therefore you need the mac address of your server. The file then has to be called 01-XX-XX-XX-XX-XX-XX > in the same directory.

9 Start services
Now we have to start up everything:

service dhcpd restart
service xinted restart


This must work without any errors.

Distributions

Now we have to differ between the distributions you'd like to install. The most part of the installation process works quite similiar, but there are differences. I'll shortly explain how it works:

  1. Get IP from dhcpd and load pxe Kernel
  2. Retrieve /tftpboot/pxeboot.msg and the config file from /tftpboot/pxelinux.cfg/
  3. Load Kernel (and initrd) from distribution
  4. Retrieve configuration file from distribution
  5. Begin installation
 

Debian 4 Etch

1 Get the Kernel and initrd
First we need the Kernel and initrd. You can find it on any mirror of Debian. As stated in your config file (/tftpboot/pxelinux.cfg/default) the Kernel has to be in the sub-folder debian4 .
mkdir /tftpboot/debian4
cd /tftpboot/debian4
wget http://ftp.de.debian.org/debian/dists/etch/main/installer-i386/
/current/images/netboot/debian-installer/i386/linux
wget http://ftp.de.debian.org/debian/dists/etch/main/installer-i386/
/current/images/netboot/debian-installer/i386/initrd.gz

2 Create preseed config file
The Debian preseed file works like CentOS' kickstart config. The preseed config must be web-accessable as stated in your /tftpboot/pxelinux.cfg/default file (ks= parameter which was preseed/url=http://192.168.0.1/deb4_preseed.cfg in our example).

Example of deb4_preseed.cfg (installation without X, Gnome, KDE etc)
d-i debian-installer/locale string de_DE
d-i console-tools/archs select at


debconf debconf/priority string critical
unknown debconf/priority string critical
d-i debconf/priority string critical

d-i netcfg/disable_dhcp boolean false
d-i netcfg/get_nameservers string REPLACE_WITH_DNS
d-i netcfg/get_ipaddress string REPLACE_WITH_IP
d-i netcfg/get_netmask string REPLACE_WITH_NETMASK
d-i netcfg/get_gateway string REPLACE_WITH_GATEWAY
d-i netcfg/confirm_static boolean true
d-i netcfg/get_hostname string REPLACE_WITH_HOSTNAME
d-i netcfg/get_domain string REPLACE_WITH_DOMAINNAME

d-i netcfg/choose_interface select auto
d-i netcfg/get_hostname string REPLACE_WITH_HOSTNAME
d-i netcfg/get_domain string REPLACE_WITH_DOMAINNAME
d-i netcfg/wireless_wep string

d-i mirror/country string enter information manually
d-i mirror/http/hostname string ftp.de.debian.org
d-i mirror/http/directory string /debian
d-i mirror/http/proxy string
d-i mirror/suite string stable
d-i mirror/http/proxy string

d-i grub-installer/only_debian boolean true

d-i prebaseconfig/reboot_in_progress note

d-i partman-auto/disk string /dev/discs/disc0/disc
d-i partman-auto/method string regular
d-i partman-auto/purge_lvm_from_device boolean true
d-i partman-lvm/confirm boolean true
d-i partman-auto/choose_recipe select All files in one partition (recommended for new users)
d-i partman/confirm_write_new_label boolean true
d-i partman/choose_partition select Finish partitioning and write changes to disk
d-i partman/confirm boolean true

base-config base-config/intro note
base-config base-config/login note
base-config preseed/late_command string wget http://192.168.0.1/deb_config2 -O /late-cmd; chmod 777 /late-cmd; /late-cmd
base-config tzconfig/gmt boolean true
base-config tzconfig/choose_country_zone_single boolean true
base-config tzconfig/verify_choices boolean true

passwd passwd/make-user boolean false
passwd passwd/root-password password EPLACE_WITH_ROOTPW
passwd passwd/root-password-again password EPLACE_WITH_ROOTPW

base-config apt-setup/uri_type select http
base-config apt-setup/country select enter information manually
base-config apt-setup/hostname string http.de.debian.org
base-config apt-setup/directory string /debian
base-config apt-setup/another boolean false
base-config apt-setup/security-updates boolean true

exim4-config exim4/dc_eximconfig_configtype select no configuration at this time
exim4-config exim4/no_config boolean true
exim4-config exim4/no_config boolean true
exim4-config exim4/dc_postmaster string admin@example.com

tasksel tasksel/first multiselect Standard system

d-i pkgsel/include string openssh-server build-essential mc bzip2 screen

d-i finish-install/reboot_in_progress note

ssh ssh/new_config boolean true
ssh ssh/use_old_init_script boolean true
ssh ssh/protocol2_only boolean true
ssh ssh/run_sshd boolean true
ssh ssh/SUID_client boolean true
ssh ssh/disable_cr_auth boolean false

dictionaries-common dictionaries-common/default-ispell select british (British English)
dictionaries-common dictionaries-common/default-wordlist select american (American English)
dictionaries-common dictionaries-common/old_wordlist_link boolean true
dictionaries-common dictionaries-common/move_old_usr_dict boolean true
dictionaries-common dictionaries-common/remove_old_usr_dict_link boolean false

As you can see the whole installation part is defined in this file. In this example you'll install Debian with a very basic package selection.

3 Post installation script
As you maybe have seen I defined following parameter in the preseed file: preseed/late_command
This command will be executed right after the installation is complete, but before the server is rebooted.
In this state the installation is mounted at /target. So when you want to edit the file /etc/network/interfaces, then you have to modify /target/etc/network/interfaces. The preseed/late_command parameter in my example downloads http://192.168.0.1/deb_config2, saves it as /late_cmd, and executes it. So you can execute many commands without having a huge preseed file.
Example of deb_config2:
#!/bin/sh

#
# THIS IS JUST AN EXAMPLE WHAT YOU CAN DO WITH THE LATE_CMD FILE
#


# Debian doesn't detect the correct module for this NIC, so do it manually :-)
rhine_check=`lspci|grep " Ethernet controller: VIA Technologies, Inc. VT6102 /[Rhine-II/]"`
if [ "$rhine_check" != "" ]
then
echo "via_rhine" >> /target/etc/modules
fi


## CONFIGURE NETWORK ##
#File: /etc/network/interfaces
file_network_config="/target/etc/network/interfaces"

echo "auto lo" > $file_network_config
echo " iface lo inet loopback" >> $file_network_config
echo "" >> $file_network_config
echo "# The primary network interface" >> $file_network_config
echo "auto eth0" >> $file_network_config
echo "iface eth0 inet static" >> $file_network_config
echo " address XXIPADDRESSXX" >> $file_network_config
echo " netmask XXNETMASKXX" >> $file_network_config
echo " gateway XXGATEWAYXX" >> $file_network_config
echo "" >> $file_network_config
# Add some static routes
echo "up route add -net 192.168.1.0 netmask 255.255.255.0 dev eth0" >> $file_network_config
echo "up route add -net 192.168.2.0 netmask 255.255.255.0 dev eth0" >> $file_network_config
echo "" >> $file_network_config
echo "down route del -net 192.168.1.0 netmask 255.255.255.0 dev eth0" >> $file_network_config
echo "down route del -net 192.168.2.0 netmask 255.255.255.0 dev eth0" >> $file_network_config



 

Start Installation

Now we are ready to start the installation.
So boot up your server, enable booting over network (PXE) and enter installauto-centos5 or installauto-debian4 when requested to start the installation.

Rescue Boot

It really wasted a lot of time finding a rescue image which does following:

  • boot via PXE
  • late linux kernel
  • boot up with network
  • boot with SSH
  • include mandatory tools


And here it is: PLD Rescue CD
It's created by Arkadiusz Patyk and works great.

Here is what you have to do:

cd /tmp
# Download latest version, today (2007-10-12) it's 2.90
wget http://rescuecd.pld-linux.org/download/2007-06-17/x86/RCDx86_290.iso
# Mount it
mkdir /mnt/rescue
mount RCDx86_290.iso /mnt/rescue -o loop

# Copy all files to tftp directory
mkdir /tftpboot/rescue
cp /mnt/rescue/rescue.cpi /tftpboot/rescue
cp /mnt/rescue/boot/isolinux/vmlinuz /tftpboot/rescue

# Unmount
umount /mnt/rescue
rmdir /mnt/rescue


When you boot your server with this image you have to know following:

  • Server gets IP via DHCP
  • Default root password is 'pld'


When the PLD Rescue Image detects your hard disk you can mount and (if you like) chroot into it.

The great thing is you don't need direct access to your box. Just edit the default boot command in /tftpboot/pxelinux.cfg/default to 'rescue' and your server will boot up the rescue image. But don't forget to change it back to 'local' :)

Memtest

This is a simple thing. You just need to download the memtest binary and extract it to /tftpboot/memtest/memtest.

Today the latest version is 1.70

mkdir /tftpboot/memtest
cd /tftpboot/memtest
wget "http://memtest.org/download/1.70/memtest86+-1.70.bin.gz"
mv "memtest86+-1.70.bin" memtest


After these steps you should be able to start memtest directly via PXE.


PXE Boot - Boot Your Machine Over the Net

See http://syslinux.zytor.com/

At certain times of the year I might be attempting to install dozens of machines for our cluster. Inserting a CD is fine for one, not for twenty. Of more interest, though, is that I want a variety of things to boot. I want a Debian Stable ISO to boot. Most importantly, I want to boot Dell diagnostics.

This process usings something called PXE. It requires your machine's BIOS to make a request of a TFTP server for a bootable image (the equivalent of inserting a CD and booting). Most modern higher-end machines can do this - and particularly all Dell PowerEdge machines, which is what I support. I use a Debian distribution, so what follows is debianish. Whatever you have will almost certainly have something similar. You should also check out the SARA package of utilities at https://subtrac.sara.nl/oss/pxeconfig .

  • Install a tftp server. I chose atftpd and did the following:
     apt-get install atftpd

    # Set up atftpd (do not use inetd, since it hardly ever gets used)
    touch /var/log/atftp.log # Enable logging
    vi /etc/default/atftpd
    USE_INETD=false
    # verbose=7 --trace will trace every packet
    OPTIONS="--daemon --verbose --tftpd-timeout 10 --retry-timeout 5 /
    --mcast-port 1758 --mcast-addr 192.168.0.0-65535 --mcast-ttl 10 /
    --maxthread 10 --verbose=5 --logfile=/var/log/atftp.log /tftpboot"
    update-inetd --disable tftp
    /etc/init.d/atftpd restart

  • Install syslinux and set up a TFTP boot server. DHCP can do this for you. Here's what I did:
     apt-get install syslinux
    mkdir -p /tftpboot/boot tftpboot/pxelinux.cfg
    chmod 777 /tftpboot
    # Copy files from syslinux distribution to /tftpboot
    cp -p /usr/lib/syslinux/pxelinux.0 /tftpboot
    cp -p /usr/lib/syslinux/menu.c32 /tftpboot
    cp -p /usr/lib/syslinux/memdisk /tftpboot/boot

  • Configure dhcp so it allows a TFTP boot to happen. I won't provide the all DHCP details, but for this step all you need do is add some lines like this to your dhcp.conf file. Yes, the pxelinux.0 file you see below is the same one from the previous step.
    allow booting;
    allow bootp;
    filename "/tftpboot/pxelinux.0";
    next-server 192.168.1.5;

  • Make default menus for pxelinux. Note that executables to be run (kernel keyword) cannot have special chars. Keep these names v-e-r-y simple. The menu.c32 is a small program to generate a menu so you can select what to do. Here's what I have right now:
    cat /tftpboot/pxelinux.cfg/default
    
    DEFAULT menu.c32
    PROMPT 0
    MENU TITLE CSG PXE Boot Menu
    TIMEOUT 100

    # First one is default unless 'DEFAULT name' specified
    LABEL delldiags
    MENU LABEL Dell Diagnostics (EW5091A1 DOS mode)
    kernel boot/memdisk
    append initrd=boot/delldiag.img

    LABEL installi386
    MENU LABEL Install Debian Etch I386 over Network
    kernel boot/debian/i386/linux
    append vga=normal initrd=boot/debian/i386/initrd.gz --

  • Get memtest from http://www.memtest.org . Download the file labelled Download - Pre-Compiled package for Floppy (DOS - Win) and then do:
     cd /tmp # or some directory for temporary files
    unzip memtest86+-1.70.floppy.zip
    cp -p floppy/memtestp.bin /tftpboot/boot/memtestp
    rm -rf /tmp/floppy

  • Get the Debian network installer (or your favorite). The process for this is described in: http://www.debian.org/releases/stable/i386/ch04s06.html.en , http://www.debian.org/releases/stable/i386/ch04s02.html.en#where-files , and http://ftp.debian.org/debian/dists/etch/main/installer-i386/current//images/netboot/ . Fetch netboot.tar.gz and extract it in a safe place:
     mkdir -p /tftpboot/boot/debian/i386
    cd where-netboot-extracted
    cp -p debian-installer/i386/linux /tftpboot/boot/debian/i386
    cp -p debian-installer/i386/initrd.gz /tftpboot/boot/debian/i386
    # Edit /tftpboot/pxelinux.cfg/default and add an entry from pxelinux.cfg/default as necessary.
  • Get Dell diagnostics from http://support.dell.com/ .
    • Select Drivers and Downloads
    • Select product by model , service tag or whatever. PowerEdge works fine, others apparently do not
    • At page Drivers and Downloads Search Criteria , select Operating System as MS-DOS
    • Select Diagnostics
    • Download the 2MB image
    • Extract on a Windows system. What! Of course, remember it's called a MONOPOLY. Fine, visit one of your poor friends who are stuck on a Windows machine. Copy the 2MB file to the Windows machine, then execute it. This program copies files to a directory and invokes an application which will create Floppy boot images, USB boot image or a 'Bootable Image'
    • Select Bootable Image and save the *.img file
    • Copy the *.img file back to your Linux and do cp -p diags.img /tftpboot/boot/delldiag.img
    • Edit /tftpboot/pxelinux.cfg/default and add an entry for Dell diagnostics as necessary

You should now be able to boot a machine on your DHCP network and choose to boot from the network. On Dell machines this is F12 labelled 'PXE Boot'. If all went well, you should get a menu showing you several things defined in /tftpboot/pxelinux.cfg/default and allow you to boot from these.

I must tell you, it's a real joy to PXE boot and run diagnostics so easily. Good job, Dell .

 

 


下面是dhcp服务器的配制文件ddns-update-style interim;
ignore client-updates;
allow booting;
allow bootp;
option ip-forwarding    false;

subnet 192.168.0.0 netmask 255.255.255.0 {

# --- default gateway
    option routers            192.168.0.1;
    option subnet-mask        255.255.255.0;

    option nis-domain        "domain.org";
    option domain-name        "domain.org";
    option domain-name-servers    202.115.144.33;

    option time-offset        -18000;    # Eastern Standard Time
#    option ntp-servers        192.168.1.1;
#    option netbios-name-servers    192.168.1.1;
# --- Selects point-to-point node (default is hybrid). Don't change this unless
# -- you understand Netbios very well
#    option netbios-node-type 2;

    range dynamic-bootp 192.168.0.128 192.168.0.254;
    default-lease-time 21600;
    max-lease-time 43200;
    filename "pxelinux.0";
    next-server 192.168.0.1;
    
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值