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

  • All

Requirements

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

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.

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

  2. Configure grub to boot the PXE Images

      Installing From the localhost

    1. For a LOCAL install, add the following example grub entry to your /etc/grub.conf

      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:
      “/boot/vmlinuz”, instead.

      SKIP TO STEP 3 IF DOING A LOCAL INSTALL

    2. Installing from a Remote Location using VNC

    3. 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):

      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:

      Another way to run with a static network config, using vncconnect
      instead, which tells the installer to connect back to our listening VNC
      client:

      You may also use DHCP, but you must make sure you will know the assigned IP address when the server reboots:

      Yet another way to use DHCP. This might be the best option if you do not know what the IP will be:

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

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

      1. 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.
      2. Your
        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
        time.

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

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

      First we need to initialize the “main fallback” saved default by
      telling grub to save the first (#0th) entry with the following command:

      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 once

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

      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:

      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:

      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

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

  5. Once installation is complete, reboot into the newly installed OS and continue with post-installation configuration as usual.

Troubleshooting

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

N/A

More Information

Disclaimer

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

Added Reading

Last Modified: 9 Oct, 2010 at 19:00:26