You have a computer that is running windows and you want to install one or more copies of Linux. How do you do that?

Learn how to partition and install Linux.
How to configure the boot loader for multiple OSs.
How to load more than one Linux Version without clobbering /boot
How to use one version of Linux to rescue another OS.
How to backup your Master Boot Record and partition table.

Finally we will use part of the meeting to install Linux on machines people bring to the meeting.

Dual Booting Windows and Linux
Dual Booting Windows and Linux

How to plan a dual boot computer

Before we start installing Linux on a computer which is already running Windows we need to make a few decision. Here is a quick list of decisions and suggested solutions.

What Partitions do we need?

You will need at least 2 partitions to install Linux. But normally I would suggest 4 partitions.

1. You need a root partition.

The root is the base of the Linux system. In Windows you always need a C:\ as the root of your system. In Linux you need a / as the root. I usually recommend a 30 Gig partition for your root partition.

If you are going to install a lot of applications you can make this root partition bigger. If you want more control you could create multiple partition, one for root, one for usr, one for opt, etc. This is a more advanced option which we will not discuss today.

2. You need a swap partition.

Linux uses the swap partition to store memory pages which are not currently active. The swap partition is used for Hibernation, (suspend-to-disk). Additionally the swap partition is used for disk buffering for files. For more information about swap have a look at SwapFaq

The usual sized of the swap partition is twice the sized of your ram. So if you have a machine with 4 gig of ram, your swap partition should be 8 gig.

3. I usually suggest a separate partition for boot.

The reason for this is to locate the boot images to be in a primary partition on the first drive. It also isolates the boot loader from the install partition.

For this partition I usually make it the first partition on the first hard disk. I normally only reserve about 1/2 to 1 gig for this partition.

4. I usually make a separate partition for home.

As a Linux user, most of your data will live in or below the directory /home/user. So by having this on a separate partition it makes it easier to backup your data. It also means that you can install a new version of Linux without rewriting your home folder.

Grub Boot Loader
Grub Boot Loader

What is a boot loader

When a modern computer is turned off, software, including operating systems, application code, and data, is stored on nonvolatile data storage devices such as hard drives, CDs, DVDs, flash memory cards (like SD cards), USB flash drives, and floppy disks. When the computer is powered on, it typically does not have an operating system in random access memory (RAM). The computer first executes a relatively small program stored in read-only memory (ROM) along with a small amount of needed data, to access the nonvolatile device or devices from which the operating system programs and data can be loaded into RAM.

The small program that starts this sequence is known as a bootstrap loader, bootstrap or boot loader. This small program’s only job is to load other data and programs which are then executed from RAM. Often, multiple-stage boot loaders are used, during which several programs of increasing complexity load one after the other in a process of chain loading. Modern boot loaders

The typical boot loader for Ubuntu is Grub2. This is a newer version of Grub.

GNU GRUB (short for GNU GRand Unified Bootloader) is a boot loader package from the GNU Project. GRUB is the reference implementation of the Multiboot Specification, which provides a user the choice to boot one of multiple operating systems installed on a computer or select a specific kernel configuration available on a particular operating system’s partitions.

GNU GRUB was developed from a package called the Grand Unified Bootloader (a play on Grand Unified Theory[4]). It is predominantly used for Unix-like systems. The GNU operating system uses GNU GRUB as its boot loader, as do most Linux distributions. The Solaris operating system has used GRUB as its boot loader on x86 systems, starting with the Solaris 10 1/06 release. GNU GRUB

For most of you Grub2 will be installed as part of the Ubuntu installation and never need modification. But if you are going to be modifying Grub manually or booting more than just Ubuntu and Windows, you should review the section How to plan for multiple Operating Systems.

How to backup the MBR and partition table

A Master Boot Record (MBR) is a special type of boot sector at the very beginning of partitioned computer mass storage devices like fixed disks or removable drives intended for use with IBM PC-compatible systems and beyond. The MBR holds the information on how the logical partitions, containing file systems, are organized on that medium. Besides that, the MBR functions as an operating system-independent chain boot loader in conjunction with each partition’s Volume Boot Record (VBR).

MBRs are not present on non-partitioned media like floppies, superfloppies or other storage devices configured to behave as such.

The concept of MBRs was introduced in 1983. With storage volumes now commonly exceeding 2 TB, it has become a limiting factor in the 2010s. The MBR partitioning scheme is therefore in the process of being superseded by the GUID Partition Table (GPT) scheme in new computers. A GPT can coexist with a MBR in order to provide some limited form of backward compatibility for older systems. Master boot record

Backing up the MBR is important because it contains 2 records we are interested in. The first is the partition table. The second is the start of the boot loader. It can happen, especially when installing windows, that the MBR is overwritten. When this happens it is easy to restore the MBR from a backup.

Lets start by looking at the structure of the MBR.

The MBR comprises the first 512 bytes of a hard drive.

This 512-byte space then is split up into two smaller sections. The first 446 bytes of the MBR contain the boot code—code like the first stage of GRUB that allows you to load an operating system. The final 66 bytes contain a 64-byte partition table and a 2-byte signature at the very end. Hack and / - When Disaster Strikes: Restoring a Master Boot Record

So we can see now that the first 512 bytes of the hard disk contain the MBR and the partition table. We can backup this part of the hard disk using the dd to grab the data and write it to a file. So the backup for the MBR plus the partition table is:

dd if=/dev/sda of=/path/mbr-backup bs=512 count=1

Explanation: if is input file, in this case the hard disk sda. of is the output file, in this case /path/mbr-backup. bs is block size, here 512 bytes. count the number of blocks to backup.

Now that we have it written to a file we could restore the MBR and partition table using the command.

dd if=/path/mbr-backup of=/dev/sda bs=512 count=1

Warning: Restoring the MBR with a mismatching partition table will make your data unreadable and nearly impossible to recover. If you simply need to reinstall the bootloader see GRUB Master Boot Record

Another little trick is to remove the MBR without removing the partition table you can use the command:

dd if=/dev/zero of=/dev/sda bs=446 count=1

Juggling Multiple Operating Systems
Juggling Multiple Operating Systems

How to plan for multiple Operating Systems

If you want to install multiple versions of Linux, or multiple operating systems on your machine I recommend you switch from Grub2, the default boot loader to legacy grub, just known as grub. The reason I recommend this is because you can edit the grub menu with a text editor, and you can control when you update your boot loader as opposed to allowing the updater do it.

Here are instructions on how to roll back Grub HowTo: Revert from grub2 to Legacy Grub.

You will now need a separate partition to hold your boot images which is not updated by the updater. So lets assume you have a first primary partition /dev/sda1.

You install your system the first time with /dev/sda1 as /boot. Then update grub to legacy grub. Next after booting into Linux. Unmount /boot, and create a folder like /mnt/boot. Now remount /dev/sda1 to /mnt/boot. Create a /boot folder and copy all the files from /mnt/boot to /boot. Remember to update fstab.

This gives you a boot loader which lives in /mnt/boot/grub, but your software updater only updates /boot. So after any kernel update, you copy the new kernel files from /boot to /mnt/boot, and update /mnt/boot/grub/menu.lst.

Planned Future Talk on Multiple OS installs

At a future talk we will go into the advanced details about maintaining a multi-OS computer.

So I am postponing talking about:

  • How to load more than one Linux Version without clobbering /boot

  • How to use one version of Linux to rescue another OS.

What about Users?

When you install Ubuntu it asks you to create a user. I generally create a dummy user like: Tony the Temp which uses the default User ID values. Once I have the system configured the way I want I create another user john and give john a specific UID and GID.

What is ID and GID?

Each user on a Linux system is assigned a User ID and one Group IDs. These are used by the system to identify the permission on all the files in the system.

A user ID (UID) is a unique positive integer assigned by a Unix-like operating system to each user. Each user is identified to the system by its UID, and user names are generally used only as an interface for humans.User ID Definition

But where this becomes interesting is suppose you have three Linux systems. If you UID was different on each system you would need to modify the UID on every file you copied from one system to the other. Or suppose you access the files on the first system from the second system. If the UID does not match, you might not be able to copy/read/write your own files..You can view your UID with the command:

id -a

So what I have learned to do is create my own user after the system is working. Lets assume my UID = 1050 and my primary GID = 100.

adduser --uid 1050 --gid 100 john

This creates the user john with the UID of 1050 and the GID of 100. .

Lastly if you want to modify your UID or GID here is some help with Linux How to change user UID and GID

So now it is time to install

Ubuntu Logo
Ubuntu Logo

Install Ubuntu 12.04.2 LTS

Written by John F. Moore

Last Revised: Tue Nov 1 18:14:04 EDT 2016

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
HTML5 Powered with CSS3 / Styling, and Semantics