Fresh Install of Linux

PC bioses can make fresh installation or reinstallation a bit difficult.
There is no single way of doing this, other than pulling the hard disk out and reformatting.

Fortunately there are various methods that work on most PC's built after 1990 or so.

1/ UEFI shell script boot

2/ Partitioned and formatted USB stick with grub boot. This works for modern bioses (UEFI can be difficult!).

3/ Partitioned and formatted disk with MBR and syslinux on a DOS partition .

4/ ISO image on USB stick. This works for many earlier bioses.

5/ ISO image on CD or DVD rom. Fall back approach for even earlier bioses.



Boot Using UEFI shell script

Some later UEFI bioses do not easily enter a boot menu ("Bing seems to cling!"). In the later case the only way is to enter Bing (win8) and turn on the full power off shutdown mode to get access to the boot menu. The F2 key is commonly used to enter the bios (in some cases before reset and power on, in others after). Once the bios is entered , then boot from USB can be selected.
Uefi boses will often only accept amd64/ia64 programs (no legacy option) . A good way to boot is to partition a USB stick with a small (~100Mb) ef00 (EFI system) partition, and a partition for live 64 bit linux system spanning the rest of the disk using gdisk or parted. Booting can be done using rEFind. The rEFInd files are unzipped and copied to partition 1. "rEFind" is capable of loading and running the system installed on the second partition.It also makes a good boot manager when copied to a similar boot partition on an hdd or sdd.
An alternative is "Grub-efi".

Boot Using MBR and fdisk partitioned USB stick

Later and current PC's will mostly boot happily from a bootable usb stick formatted in the same way as a hard drive, apart from some that are deliberately designed to prevent linux being used (some Intel Atom soc's). Later PC bioses will usually accept an ISO image on a USB stick.

Most recent PC bioses will accept a syslinux boot load on a dos partition.

Somewhat earlier PC's will accept a USB stick with an ISO image or a CD/DVD rom with an ISO image, but not a normally partitioned and formatted USB stick.

Still earlier bioses will refuse USB sticks unless formatted in odd ways, but will still accept a DVD or CD with an ISO image. Once the system is booted from the CD, a USB stick can be used for the remaining OS files.

Boot Using Syslinux

Bioses which will accept partitioned drives with a dos formatted boot partition can be satisfied using syslinux. A typical sequence for user "root" is:

> fdisk /dev/sdb # partition drive as desired, but make partition 1 fat32 & bootable

> dd conv=notrunc bs=440 count=1 if=/usr/lib/syslinux/mbr.bin of=/dev/sdb # install MBR on sdb

> syslinux -i /dev/sdb1 # install syslinux

> mount /dev/sdb1 /mnt/sdb1

> cp -rv /boot /mnt/sdb1 # copy kernel and initrd

Generate syslinux.cfg:

DEFAULT linux
SAY Booting using SYSLINUX
LABEL linux
linux /boot/vmlinuz
initrd /boot/initrd.img
append root=/dev/ram0 rw

Boot using ISO image



An ISO image of less than ~ 650 M will span many different bioses. It can be copied to a USB stick or CD/DVD. If the system has a DVD rather than a CD, then an extra partion can hold a readonly os partition (generated either on a USB stick or a loop back mounted extended iso image).

Knoppix or distro releases provide iso images which are useful starting points, but do not always give an easy path to installing a live OS for a particular environment or tailored release.

A good way to generate such an ISO image is grub-mkrescue. It will generate an image which can be copied to a USB stick as follows:

cat grub.iso > /dev/sdb

or to a cd/dvd using brasero or k3b.

I have found that fdisk can create on extra partition on an iso image formatted usb stick. The iso image itself shows up as partition 1. A second partition can hold a complete normally formatted linux installation. This works because an ISO image includes an MSDOS style partition table, which can be altered by fdisk without damaging the ISO image.

This is a particularly useful approach that allows an entire live installation on a single usb stick (I use debootstrap to load a fresh debian SID distribution, and then install necessary extra packages (linux-image,ssh,iwconfig etc) under chroot). The chroot environment will also allow creation of an i486 disc in an amd64 environment or vive versa.

When Grub starts, and no configuration options have been started, a "c" command will enter the Grub interactive mode. The commands used in interactive mode can be included in a "/boot/grub/grub.cfg" file to fully automate the boot. It is instructive to run Grub manually to see the various possibilities before using an automatic boot.

NB:USB keyboards do not work with some older bioses, and consequently also the Grub menu, although they work fine once the kernel has booted.

In Grub interactive mode "ls" will show all available drives and partitions eg (hd0),(cd0),(hd0.1) etc, which can be used by "ls" , e.g/ "ls (hd0)/" to show files. The two commands "linux" and "initrd" can then be used to specify the start environment for linux ,eg:

"linux (hd0 or cd0)/vmlinuz root=/dev/ram0"

"initrd (hdo or cd0)/initrd.img"

"boot" will then start the linux kernel in ram
Extra files needed in this environment can either be included as files by grub-mkrescue, or in the initial ram disk "initrd.img" (using gunzip and cpio).

menuentry "Grub Iso Rescue USB and boot" { linux (hd0)/vmlinuz root=/dev/sdb2 ro fstype=ext3 initrd (hd0)/initrd.img }
An example of a boot/grub/grub.cfg file used for grub-mkrescue:


menuentry "Grub Iso Rescue USB" {
linux (hd0)/vmlinuz root=/dev/ram0
initrd (hd0)/initrd.img
}




menuentry "Grub Iso Rescue CD" {
linux (cd0)/vmlinuz root=/dev/ram0
initrd (cd0)/initrd.img
}


menuentry "Grub Iso Rescue CD, OS on sdb2" {
linux (cd0)/vmlinuz root=/dev/sdb2 ro fstype=ext3
initrd (cd0)/initrd.img
}

The full live environment can be started by using mounting the second partition on the boot device, passing on /proc, /dev, and /sys using commands like "mount -o bind /proc /mnt/sdb2/proc", then chroot "chroot /mnt/sdb2/"

While this means of producing a bootable os seems cumbersome, it is a number of straightforward and checkable scripted steps. These steps can all be chained easily to make a fully or partiall automated boot disk as needed.