Booting grub with the Centos PXE vmlinuz/initrd images allows you to perform a network installation of Centos over any existing Linux distro, should you not be able to write to or boot from the conventional CD/DVD install media. A PXE netinstall can both be done locally, and with extra care, remotely using VNC. Both methods are explained in this HOWTO.
Applicable to Centos Versions
In order to use this installation method you must already have a
linux distro installed which successfully boots using the grub
bootloader. A network connection and a network device that anaconda can
configure is also required (which rules out some wireless-only
Doing the Work
NOTE: the grub “PXE” image installation method described here is not the same as a conventional PXE installation where the network card supports PXE
netbooting of the images on a remotely configured tftp/dhcp server. In
this case we’re taking advantage of a system with a pre-existing
bootloader by telling it to bootstrap the images directly on disk.
Summary of steps below: 1) put the pxe
images in /boot; 2) configure grub.conf for a local or (advanced)
remote vnc install; 3) point of no return: double-check & backup,
backup, backup. 4) reboot and start the netinstall from a known mirror.
- Download the vmlinuz and initrd.img PXE
images for the OS version and architecture you want to install, into
your /boot directory. If you already have image filenames by those
generic names in your /boot directory, download them to a temp
directory instead, rename them to something unique and identifiable
(such as vmlinuz.f7.pxe and initrd.img.f7.pxe), and then copy or move them to /boot/. (note: grub doesn’t care about selinux or file permissions)
1cd /boot/<br />wget 'http://download.Centos.redhat.com/pub/Centos/linux/releases/8/Centos/i386/os/images/pxeboot/vmlinuz'<br />wget 'http://download.Centos.redhat.com/pub/Centos/linux/releases/8/Centos/i386/os/images/pxeboot/initrd.img'<br />
- Centos 8 i386 (32bit): http://download.Centos.redhat.com/pub/Centos/linux/releases/8/Centos/i386/os/images/pxeboot/
- Centos 8 x86_64 (64bit): http://download.Centos.redhat.com/pub/Centos/linux/releases/8/Centos/x86_64/os/images/pxeboot/
- Centos 7 i386 (32bit): http://download.Centos.redhat.com/pub/Centos/linux/releases/7/Centos/i386/os/images/pxeboot/
- Centos 7 x86_64 (64bit): http://download.Centos.redhat.com/pub/Centos/linux/releases/7/Centos/x86_64/os/images/pxeboot/
- Configure grub to boot the PXE Images
- For a LOCAL install, add the following example grub entry to your /etc/grub.conf1title Install Centos (PXE)<br /> root (hd0,0)<br /> kernel /vmlinuz<br /> initrd /initrd.img<br />
NOTE: The above assumes you have your /boot on a separate partition
from the root partition, which is the default. If /boot was on the same
device as your ‘/’ root partition you would use, for example:
SKIP TO STEP 3 IF DOING A LOCAL INSTALL
- For a REMOTE install, the grub.conf and VNC setup is more involved.
You will need to configure your boot loader for the new PXE
images. At this point you will need information about the existing
server and network. This is key to the success of the reboot. You must know that the PXE
images will boot your hardware. Specifically hard disk drives and
network interface cards are needed to do the install. The best way to
check this is read (TODO:missing link) about it or test it. You must
also know what your network adapter will show up as it is passed to the
kernel at boot. Again, you have been warned. Also, it is good to make
backups of your boot loader configs. As another note, please ‘append’
this information into your configs. Do not replace what you have, just
add to it.
For this example we will use the following network settings. You must adjust them to your own network (or rely upon DHCP instead – see further below):1IP: 192.168.1.2<br />Netmask: 255.255.255.0<br />Gateway: 192.168.1.1<br />DNS: 192.168.1.1<br />Server Network Interface: eth0<br /><br />Workstation Machine: 192.168.1.23<br />Hostname: test.mydomain.com<br />VNC Password: yourPass<br />
Note: Make sure your password is between 6-11 characters in length.
The following are example kernel configs for grub:
This is an example grub config section with our example static IP config:1title Install Centos (PXE) - <strong>static. we connect to vnc server.</strong><br /> root (hd0,0)<br /> kernel /vmlinuz vnc vncpassword=yourPass headless ip=192.168.1.2 noipv6 netmask=255.255.255.0 gateway=192.168.1.1 dns=192.168.1.1 hostname=test.mydomain.com ksdevice=eth0 method=http://download.Centos.redhat.com/pub/Centos/linux/releases/8/Centos/i386/os/ lang=en_US keymap=us<br /> initrd /initrd.img
Another way to run with a static network config, using vncconnect
instead, which tells the installer to connect back to our listening VNC
client:1title Install Centos (PXE) - <strong>static. vnc server connects to us.</strong><br /> root (hd0,0)<br /> kernel /vmlinuz vnc vncconnect=192.168.1.23 headless ip=192.168.1.2 noipv6 netmask=255.255.255.0 gateway=192.168.1.1 dns=192.168.1.1 hostname=test.mydomain.com ksdevice=eth0 method=http://download.Centos.redhat.com/pub/Centos/linux/releases/8/Centos/i386/os/ lang=en_US keymap=us<br /> initrd /initrd.img
You may also use DHCP, but you must make sure you will know the assigned IP address when the server reboots:1title Install Centos (PXE) - <strong>dhcp. we connect to the vnc server.</strong><br /> root (hd0,0)<br /> kernel /vmlinuz vnc vncpassword=yourPass headless ip=dhcp noipv6 ksdevice=eth0 method=http://download.Centos.redhat.com/pub/Centos/linux/releases/8/Centos/i386/os/ lang=en_US keymap=us<br /> initrd /initrd.img
Yet another way to use DHCP. This might be the best option if you do not know what the IP will be:1title Install Centos (PXE) - <strong>dhcp. vnc server connects to us.</strong><br /> root (hd0,0)<br /> kernel /vmlinuz vnc vncconnect=192.168.1.23 headless ip=dhcp noipv6 ksdevice=eth0 method=http://download.Centos.redhat.com/pub/Centos/linux/releases/8/Centos/i386/os/ lang=en_US keymap=us<br /> initrd /initrd.img
Adapt one of the above examples to your environment, add it to your
grub.conf, and change the “default=N” line to refer to it, where N
equals the position of the new entry, counting from the top, starting
at zero (e.g. if it was the 3rd entry, use “default=2”).
- Configure Grub to boot once-only, then Fallback, in case Bootup Fails
If your new PXE grub config fails to boot and start the installation correctly the very first time, you are stuck, unless you have some way to recover. There are two ways to do so:
- Your server has an emergency IP KVM, or virtual ssh
console of some kind. If you’ve got this kind of access you can fix the
grub problem as if you were physically in front of the server. Even in
this case, you can save time with a fallback setup as described below.
server has a simple remote “reboot” facility provided via a web control
panel of some sort. If you can AT LEAST reboot your server, or call a
remote tech to do it manually, then you can setup grub to boot the PXE kernel once, and on the next boot fallback to the last used working kernel. If you can’t
reboot your server, then you probably shouldn’t be attempting a remote
install unless you have the experience to KNOW it will work the first
To configure grub to only boot an entry once, then fallback, you
need to switch grub.conf from using the fixed “default=N” index number,
to using “default=saved”. You must then to tell grub which entry will
be the saved default by putting “savedefault” in the good grub.conf
entry, and by immediately saving it on the command line (see below).
Finally, you tell grub to save a default entry that it will only boot
once, afterwhich it will boot the previous savedefault until told
See the example grub.conf below. The WORKING kernel entry is (#0) the one at the very top (yours should be as well), and the PXE VNC grub entry we want to boot next is the 3rd one down (#2).1<strong>default=saved</strong><br />timeout=5<br />splashimage=(hd0,0)/boot/grub/splash.xpm.gz<br />hiddenmenu<br />title <em>#0</em> - Centos (2.6.21-1.3228.fc7)<br /> root (hd0,0)<br /> kernel /vmlinuz-2.6.21-1.3228.fc7 ro root=/dev/VolGroup00/LogVol00<br /> initrd /initrd-2.6.21-1.3228.fc7.img<br /> <strong>savedefault</strong><br /><br />title <em>#1</em> - Centos (2.6.21-1.3194.fc7)<br /> root (hd0,0)<br /> kernel /vmlinuz-2.6.21-1.3194.fc7 ro root=/dev/VolGroup00/LogVol00<br /> initrd /initrd-2.6.21-1.3194.fc7.img<br /><br />title <em>#2</em> - Install Centos (PXE) - dhcp. vnc server connects to us.<br /> root (hd0,0)<br /> kernel /vmlinuz vnc vncconnect=192.168.1.23 headless ip=dhcp noipv6 ksdevice=eth0 method=http://download.Centos.redhat.com/pub/Centos/linux/releases/8/Centos/i386/os/ lang=en_US keymap=us<br /> initrd /initrd.img<br />
First we need to initialize the “main fallback” saved default by
telling grub to save the first (#0th) entry with the following command:1echo 'savedefault --default=<strong>0</strong>' | grub --batch<br />
And finally, we need to tell grub which entry to attempt booting only once before rebooting to the saved fallback entry above. In this example, we want to boot #2 once1echo 'savedefault --default=<strong>2 <em>--once</em></strong>' | grub --batch<br />
- Your server has an emergency IP KVM, or virtual ssh
- Setup your Workstation to Listen for the VNC Install to Start
This step is only needed if you choose to use vncconnect to
tell the installer to connect back to your waiting VNC viewer, rather
than you initiating a connection with the waiting VNC server. Having
the installer connect back to your VNC client is very convenient,
especially if its DHCP IP is dynamic, or in the case where it’s easier
to open a hole for VNC on your side of the firewall, or if you would
just rather have the VNC install start when it’s ready rather than you
having to poll the server to see if it’s ready yet. If you choose not
to use this method, be sure to set a vncpassword so that no random hacker can connect to the VNC server before you do.
To be able to use vncconnect you must setup a vncviewer to listen and wait for the server to boot. Run the following on your workstation:1vncviewer --listen<br />
This will setup vncviewer to listen on port 5500 by default. Other
VNC clients may use a different port; see their documentation. Use
netstat on your workstation to check to see if it is listening:1# netstat -panl | grep 5500<br />tcp 0 0 0.0.0.0:5500 0.0.0.0:* LISTEN 28370/vncviewer<br />
Finally, and most importantly, you must make sure that the server can connect to your client. You can do this from the server with the following netcat command:1# nc -vz 192.168.1.23 5500<br />Connection to 192.168.1.23 5500 port [tcp/fcp-addr-srvr1] succeeded!<br />
If you don’t see “succeeded”, and instead see “No route to host” or
“Connection refused”, then a firewall is mostly likely blocking the
connection and you need to do one or both of the following: 1) open port 5500 on your workstation’s firewall. 2) if you have a NAT router, and you’re remotely installing to a server that’s outside your local LAN, then you’ll need to setup a port forward mapping from the external port 5500, to your workstation’s internal 192.168.1.21:5500
Installing From the localhost
Installing from a Remote Location using VNC
- For a LOCAL install, add the following example grub entry to your /etc/grub.conf
- Double-check your grub.conf to make sure that it is set to load the correct PXE image files (no typos) upon reboot. Nearing the point of no return here, so make sure you have a backup of all your important data in case installation fails.
- Reboot to Begin the Network Installation.
IMPORTANT NOTE ABOUT NETWORK MIRROR PATHS: During the installation
you will be prompted for the “site name” and the “Centos directory” of
the network mirror you want to install from – you need to know this
before-hand, so write a few down. You can either setup and use your own
local mirror, or use one of the many geographically close public
mirrors that are listed here: http://mirrors.Centosproject.org/publiclist
When using a public mirror, you need to make sure to use the full, correct directory path, or it won’t be found – the directory should end with “/os/”. Using the example mirror of “http://mirror.cc.vt.edu/pub/Centos/linux“,
the “Web site name” part would be “mirror.cc.vt.edu”, but the directory
would *not* only be “/pub/Centos/linux”. You have to drill down the
mirror directories to find the correct full path with “/os/” at the
end, and in this example it happens to be
“pub/Centos/linux/releases/8/Centos/i386/os”. Note also that the mirror
arch path you install from needs to match the PXE image arch that you’re booting from: i386 or x86_64.
- Once installation is complete, reboot into the newly installed OS and continue with post-installation configuration as usual.
How to test
For local installations: if you added the PXE
images correctly, you should still be able to boot back to the old
kernel by simply selecting it from the grub menu. Do this and try
again. You must know if your boot loader expects /boot or not, which
should be easy to infer from the pre-existing entries in grub.conf.
For remote installations: if the PXE
images failed to boot and connect to your VNC client in a reasonable
amount of time, something probably went wrong and you’ll need a way to
reboot the server. If you setup grub correctly to only boot the PXE entry –once,
it will automatically fallback to the previously saved default after
you reboot. If it doesn’t, you may be in trouble, unless you have an
emergency IP KVM, virtual console, or onsite tech support.
Common problems and fixes
We test this stuff on our own machines, really we do. But you may
run into problems, if you do, come to #Centos on irc.freenode.net