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

P2V using dd for KVM-QEMU guest

Preface: I have certainly not exhaustively tested this process.  I had a specific need and found a specific solution that worked. Situation:  I was issued a shiny new laptop running Red Hat Enterprise Linux 7 (with Corp VPN, certs, Authentication configuration, etc...)  The image was great, but I needed more flexibility on my bare metal.  So, my goal was to P2V the corporate image so I could just run it as a VM. * Remove corporate drive and install new SSD * install corp drive in external USB-3 case * Install RHEL 7 on new SSD * dd old drive to a disk-image file in a temp location which will be an image which is the same size as your actual drive (unless you have enough space in your destination to contain a temp and converted image) * convert the raw disk-image to a qcow file while pushing it to the final location - this step should reduce the disk size - however, I believe it will only reduce/collapse zero-byte blocks (not just free space - i.e. if you de...

Extending SNMP to run arbitrary shell script

Why are we here... This is not likely something I would have pursued under normal circumstances.  I happen to be working for a customer/client who is not afforded a lot of flexibility to accomplish their goals.  In this case, the rigor is justified.  They have to sometimes be fairly creative with how they solve problems. In this case they would like to utilize an existing snmp implementation to execute a command (or shell script) on a remote system.  They came to me with the idea of using Net-SNMP extend. https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/sect-System_Monitoring_Tools-Net-SNMP-Extending.html NOTE:  This is NOT a good implementation strategy in the "real world"  it will simply allow you to test the functionality.  There are a TON of security implications which would need to be taken in to consideration. Implementation Steps: [root@rh7tst01 ~]# yum -y install net-snmp net-snmp-utils ...

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...