26 January 2012

HOWTO: Boot Linux from an USB device and install it using NFS

This tutorial is for RedHat compatible operating systems (ie: CentOS) but once you have syslinux it should be the similar for other Linux variants.

We need a computer running Linux (RedHat or CentOS) and the ISO of the target Linux we want to install.

In this tutorial, this computer will serve the installation files using NFS and should be in the same network as the computer we want to install.

Install syslinux

sudo yum install syslinux

Mount the ISO to a folder

sudo mkdir -p /mnt/mylinux
sudo mount -o loop /path/to/iso/mylinux.iso /mnt/mylinux


Configure NFS and export the content of the ISO

Edit /etc/exports and add a line containing the network address where your computers are located:

/mnt/mylinux 192.168.1.0/24(ro,insecure)

Publish the new share and (re)start the service

sudo exportfs -a
sudo service nfs restart

Install syslinux on the USB device

Be sure to identify what is your USB partition using then install syslinux on the mounted partition:

sudo fdisk -l
sudo mount -l
sudo syslinux -i /dev/sdX1

Install the boot loader mbr

This time the boot loader must be installed on the device itself, not on the mounted partition.

Unmount the device first:

sudo umount /media/usbdevice
sudo dd conv=notrunc bs=440 count=1 if=/usr/share/syslinux/mbr.bin of=/dev/sdX
sudo parted /dev/sdX set 1 boot on

Copy vmlinuz and initrd.img from the ISO

cp /mnt/mylinux/images/pxeboot/vmlinuz /media/usbdevice
cp /mnt/mylinux/images/pxeboot/initrd.img /media/usbdevice

Add a menu:

cp /usr/share/syslinux/vesamenu.c32 /media/usbdevice

Create the minimum syslinux.cfg configuration

This configuration assumes that the machine containing the files (the one we used to create the USB) has the IP 192.168.1.100.

If your network doesn't have a router with DHCP enabled then remove the option ip=dhcp.

Change this according to your needs.

ui vesamenu.c32
prompt 0
timeout 300

menu title PXE boot menu

label mylinux
 menu label mylinux
 kernel vmlinuz
 append initrd=initrd.img method=nfs:192.168.1.100:/mnt/mylinux lang=us keymap=us ip=dhcp noipv6

Install Linux on the target machine

Select the boot menu on the target computer then choose your USB device.

A menu should popup with our option to install Linux.

No comments:

Post a Comment