Skip to main content

PXE boot a LiveCD image

Summary:
I have wanted to build a kickstart environment which hosted a "rescue CD" or LiveCD to allow you to boot over the network after you blew your stuff up and needed to repair a few things.  Today I have worked through a method of doing so, with the help of the people who published a succinct script with the Red Hat Enterprise Virtualization Hypervisor.  (the script will be at the bottom of this post - if I have somehow not followed the GPL, please let me know and I will correct whatever is necessary)

NOTE/Warning:
The boot will fail due the initrd being too large (645mb).  I'm not sure how to proceed.  This procedure worked for RHEVh, because it is quite a bit smaller.  Hopefully I can report back with progress on this? :-$

Procedure:
download your LiveCD image to /export/isos/RESCUE/Fedora-16-i686-Live-Desktop.iso
# cd /var/tmp
# vi livecd-iso-to-pxeboot
(populate the file with the script shown below)
# chmod 754 ./livecd-iso-to-pxeboot
# ./livecd-iso-to-pxeboot  /export/isos/RESCUE/Fedora-16-i686-Live-Desktop.iso
# mkdir /tftpboot/RESCUE; cd tftpboot;  cp initrd0.img vmlinuz0 /tftpboot/RESCUE
# cd pxelinux.cfg
# cat default 
DEFAULT pxeboot
TIMEOUT 20
PROMPT 0
LABEL pxeboot
KERNEL vmlinuz0
APPEND rootflags=loop initrd=initrd0.img root=live:/Fedora-16-i686-Live-Desktop.iso rootfstype=auto ro liveimg quiet  rhgb rd.luks=0 rd.md=0 rd.dm=0 
ONERROR LOCALBOOT 0

So - for this to work on my system (using /tftpboot/RESCUE) I would need to add the following to
-- /tftpboot/pxelinux.cfg/default - STANZA

LABEL RESCUE
KERNEL RESCUE/vmlinuz0
APPEND rootflags=loop initrd=RESCUE/initrd0.img root=live:/Fedora-16-i686-Live-Desktop.iso rootfstype=auto ro liveimg quiet  rhgb rd.luks=0 rd.md=0 rd.dm=0 


in my case, I would need to update
-- /tftpboot/msgs/boot.menu
to include RESCUE as an option

# SCRIPT - livecd-iso-to-pxeboot
I had discovered the following script contained on the RHEV 3 ISO -
rhevh-6.2-20111108.0:/LiveOS/livecd-iso-to-pxeboot

#!/bin/bash
# Convert a live CD iso so that it can be booted over the network
# using PXELINUX.
# Copyright 2008 Red Hat, Inc.
# Written by Richard W.M. Jones <rjones@redhat.com>
# Based on a script by Jeremy Katz <katzj@redhat.com>
# Based on original work by Chris Lalancette <clalance@redhat.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.


export PATH=/sbin:/usr/sbin:$PATH


usage() {
    echo "Usage: livecd-iso-to-pxeboot <isopath>"
    exit 1
}


cleanup() {
    [ -d "$CDMNT" ] && umount $CDMNT && rmdir $CDMNT
}


exitclean() {
    echo "Cleaning up to exit..."
    cleanup
    exit 1
}


if [ $(id -u) != 0 ]; then
    echo "You need to be root to run this script."
    exit 1
fi


# Check pxelinux.0 exists.
if [ ! -f /usr/share/syslinux/pxelinux.0 -a ! -f /usr/lib/syslinux/pxelinux.0 ]; then
    echo "Warning: pxelinux.0 not found."
    echo "Make sure syslinux or pxelinux is installed on this system."
fi


while [ $# -gt 1 ]; do
    case "$1" in
*) usage ;;
    esac
    shift
done


ISO="$1"


if [ -z "$ISO" -o ! -e "$ISO" ]; then
    usage
fi


if [ -d tftpboot ]; then
    echo "Subdirectory tftpboot exists already.  I won't overwrite it."
    echo "Delete the subdirectory before running."
    exit 1
fi


mkdir tftpboot


# Mount the ISO.
# FIXME: would be better if we had better mountpoints
CDMNT=$(mktemp -d /media/cdtmp.XXXXXX)
mount -o loop "$ISO" $CDMNT || exitclean


trap exitclean SIGINT SIGTERM


# Does it look like an ISO?
if [ ! -d $CDMNT/isolinux -o ! -f $CDMNT/isolinux/initrd0.img ]; then
    echo "The ISO image doesn't look like a LiveCD ISO image to me."
    exitclean
fi


# Create a cpio archive of just the ISO and append it to the
# initrd image.  The Linux kernel will do the right thing,
# aggregating both cpio archives (initrd + ISO) into a single
# filesystem.
ISOBASENAME=`basename "$ISO"`
ISODIRNAME=`dirname "$ISO"`
( cd "$ISODIRNAME" && echo "$ISOBASENAME" | cpio -H newc --quiet -L -o ) |
  gzip -9 |
  cat $CDMNT/isolinux/initrd0.img - > tftpboot/initrd0.img


# Kernel image.
cp $CDMNT/isolinux/vmlinuz0 tftpboot/vmlinuz0


# pxelinux bootloader.
if [ -f /usr/share/syslinux/pxelinux.0 ]; then
    cp /usr/share/syslinux/pxelinux.0 tftpboot
elif [ -f /usr/lib/syslinux/pxelinux.0 ]; then
    cp /usr/lib/syslinux/pxelinux.0 tftpboot
else
    echo "Warning: You need to add pxelinux.0 to tftpboot/ subdirectory"
fi


# Get boot append line from original cd image.
if [ -f $CDMNT/isolinux/isolinux.cfg ]; then
    APPEND=$(grep -m1 append $CDMNT/isolinux/isolinux.cfg | sed -e "s#CDLABEL=[^ ]*#/$ISOBASENAME#" -e "s/ *append *//")
fi


# pxelinux configuration.
mkdir tftpboot/pxelinux.cfg
cat > tftpboot/pxelinux.cfg/default <<EOF
DEFAULT pxeboot
TIMEOUT 20
PROMPT 0
LABEL pxeboot
KERNEL vmlinuz0
APPEND rootflags=loop $APPEND
ONERROR LOCALBOOT 0
EOF


# All done, clean up.
umount $CDMNT
rmdir $CDMNT


echo "Your pxeboot image is complete."
echo
echo "Copy tftpboot/ subdirectory to /tftpboot or a subdirectory of /tftpboot."
echo "Set up your DHCP, TFTP and PXE server to serve /tftpboot/.../pxeboot.0"
echo
echo "Note: The initrd image contains the whole CD ISO and is consequently"
echo "very large.  You will notice when pxebooting that initrd can take a"
echo "long time to download.  This is normal behaviour."


exit 0


# PXE "default" file
-- /tftpboot/pxelinux.cfg/default

default 0
prompt 4
menu title PXE Boot Menu
menu INCLUDE pxelinux.cfg/graphics.conf
MENU AUTOBOOT Starting Local System in # seconds
display msgs/boot.menu


# Boot from Hard Disk
label 0
localboot 1


LABEL RESCUE 
KERNEL RESCUE/vmlinuz0
APPEND rootflags=loop initrd=RESCUE/initrd0.img root=live:/Fedora-16-i686-Live-Desktop.iso rootfstype=auto ro liveimg quiet  rhgb rd.luks=0 rd.md=0 rd.dm=0 


label RHEVH01
  kernel RHEVH/vmlinuz0
  IPAPPEND 2
  APPEND initrd=RHEVH/initrd0.img rootflags=loop root=live:/rhevh-6.2-20111108.0.iso rootfstype=auto ro liveimg nomodeset check rootflags=ro crashkernel=512M-2G:64M,2G-:128M elevator=deadline processor.max_cstate=1 install quiet rd_NO_LVM rhgb rd_NO_LUKS rd_NO_MD rd_NO_DM




label RHEVH02
  kernel RHEVH/vmlinuz0
  append initrd=RHEVH/initrd0.img ramdisk=5939 dhcpclass=RHEVH noipv6 ks=nfs:10.10.31.200:/export/kickstart/Profiles/RHEVH02.ks ksdevice=eth0


# RHEL-6.2-x86_64
label 621
  kernel RHEL-6.2-x86_64/vmlinuz
  append initrd=RHEL-6.2-x86_64/initrd.img ramdisk=5939 dhcpclass=RHEL-6.2-x86_64 noipv6
label 622
  kernel RHEL-6.2-x86_64/vmlinuz
  append initrd=RHEL-6.2-x86_64/initrd.img ramdisk=5939 dhcpclass=RHEL-6.2-x86_64 noipv6 rescue ks


# PXE boot menu
-- /tftpboot/msgs/boot.menu



 =================================================================
   WARNING: Most of these choices |  arch  |  Manual   | Rescue  |
    will do fresh installations!  |        |  Install  | Install |
 -----------------------------------------------------------------
  RHEL-6.2                        | x86_64 |    620    |   621   |
  Fedora LiveCD                   |   x86  |        RESCUE       |
 =================================================================
  Type in the hostname for automated install
  Hosts: RHEVH01, RHEVH02


  0. Boot from the Hard Drive



Comments

  1. Hi, did you ever find an answer for this?

    I'm looking for a way to load CentOS 7 liveCD over the network using PXE boot.
    So far using this script I accomplished to load initrd, but right after it shows: Probing EDD (edd=off to disable) ... ok and it freezes.

    ReplyDelete
  2. Pxe Boot A Livecd Image >>>>> Download Now

    >>>>> Download Full

    Pxe Boot A Livecd Image >>>>> Download LINK

    >>>>> Download Now

    Pxe Boot A Livecd Image >>>>> Download Full

    >>>>> Download LINK ed

    ReplyDelete

Post a Comment

Popular posts from this blog

RHN Satellite Server (spacewalk) repomd.xml not found

"repomd.xml not found" If you add a channel, or if your RHN cache gets corrupted, and one of your guests complains that it cannot find repomd.xml for jb-ews-2-x86_64-server-5-rpm (for example) - you need to rebuild your repodata cache. Normally this is an automated job - which is exemplified by the fact that you have obviously built out your entire Satellite environment and never had to do any of the steps you are about to do. So - some prep work: Open 3 terminals to your Satellite Server and run: # Term 1 cd /var/cache/rhn watch "ls -l | wc -l" # Term 2 pwd cd /var/log/rhn tail -f rhn_taskomatic_daemon.log # Term 3 satellite-sync --channel=jb-ews-2-x86_64-server-5-rpm Once the satellite-sync has completed, you >should< see the count increment by one.  If you are unlucky (like me) you will not. You then need to login to the Satellite WebUI as the satellite admin user. Click on the Admin tab (at the top) Task Schedules (on the left) fin

Install RHEL 7 on old HP DL380 g5

Someone at work had been running RHEL on an HP DL380 G5 and blew it up.  After several attempts at doing an installation that made me conclude the hardware was actually bad... I kept digging for the answer. Attempt install and Anaconda could not find any disks - try a Drivers Disk (dd.img) both cciss and hpsa.   -- once we did that, when the system would reboot it would say it could not find a disk. hmmm. Boot from your installation media and interrupt the startup at grub. Add hpsa.hpsa_allow_any=1 hpsa.hpsa_simple_mode=1 to the line starting with linuxefi press CTRL-X to boot. Once the system restarts after the install, you need to once again interrupt the startup and add the line from above. After the system starts, edit /etc/default/grub and add those 2 parameters to the end of the line starting with GRUB_CMDLINE_LINUX (which likely has quiet at the end of the line currently). then run # cp /boot/grub2/grub.cfg /boot/grub2/grub.cfg.orig # grub2-mkconfig -o /boot/grub2

MOTD with colors! (also applies to shell profiles)

I'm not sure why I had never looked into this before, but this evening I became obsessed with discovering how to present different colored text in the /etc/motd. A person had suggested creating a shell script (rather than using special editing modes in vi, or something) and I agree that is the simplest way of getting this accomplished quickly. This most noteworthy portion of this script is the following: RESET="\033[0m" that puts the users shell back to the original color. I typically like a green text on black background. Also - a great reference for the different colors and font-type (underscore, etc...) https://wiki.archlinux.org/index.php/Color_Bash_Prompt I found this example on the web and I wish I could recall where so that I could provide credit to that person. #!/bin/bash #define the filename to use as output motd="/etc/motd" # Collect useful information about your system # $USER is automatically defined HOSTNAME=`uname -n` KERNEL=`un