How to install a Linux-based OS

Write tutorials for Linux Mint here
More tutorials on https://github.com/orgs/linuxmint/discu ... /tutorials and (archive) on https://community.linuxmint.com/tutorial
Forum rules
Don't add support questions to tutorials; start your own topic in the appropriate sub-forum instead. Before you post read forum rules
Post Reply
mpiter
Level 2
Level 2
Posts: 80
Joined: Tue Oct 25, 2011 3:24 pm

How to install a Linux-based OS

Post by mpiter »

1. Introduction

I have spent almost 25 years managing Unix-based systems. I feel I can share some tips to ease users' live when they have to install a new Linux-based OS (Operating System) on their computer.

I am not going to make the distinction here between Linux being the kernel, Gnu being the OS, and what you get being the distribution. I am going to misuse the word Linux to designate a full Gnu/Linux-based OS.

This tutorial was initially aimed at "advanced" users who might try several Linux versions during their computers' live. But keep in mind that a simple OS upgrade may in many cases be viewed as a new installation. As a consequence, even Linux beginners may be interested by this How To. My piece of advice is therefore to try to read it, no matter what is your experience with Linux. If you do not understand the concepts presented below, go for the simplest installation with your Live CD, enjoy and build experience with your new Linux distribution without fear. Conversely, if you understand this How To, I think you better follow its guidelines, even if it seems hard the first time. If you do not understand why it is so important to thoroughly prepare a computer for a multi-OS usage, believe me, you will understand the day you will upgrade your OS for a new version that finally is less satisfying than the previous one. :)

There are presently more than 300 maintained Linux distributions available. Even if you know today which version you want to use, you may wish to try another one later. Also, you may hesitate someday between upgrading your OS or keeping your current version. Because you never know in advance if the new OS version will be better than your current one, you should not erase your current version to install the new one. In other words, you must install the new distribution on its own partition. This way, it will be very easy to come back to your previous OS without relying your backups. As a consequence, never install a Linux system without having at least another system partition to test another OS, even if today you are sure you will never change your OS. So you MUST plan to have at least two system partitions to leave you the liberty to test other OS without destroying your current one. Installing a new OS or upgrade on a separate partition offers several other advantages as shown below. This means that if you want a non-Linux OS such as Windows along with Linux on your computer, you will need at least 3 system partitions: One for Windows and at least two for Linux.

Some Linux OS such as Ubuntu give you the option to upgrade an existing system by simply clicking an "Upgrade" button. This link http://community.linuxmint.com/tutorial/view/2 explains why this is usually a bad idea and why you better make a fresh installation of the new OS version. Carrying out a fresh installation of a new version of your current OS is the same thing as installing a different OS. That is why this tutorial is basically for everybody who understands the concepts described below. With the multi-OS scheme presented here, the operation is very easy. I have not upgraded a system for a long time, I always make a fresh installation.

I am going to cover these steps:
  • If it is a first Linux installation on your computer, you must partition the disk;
  • If you already have an OS on your computer, you must back up user and system data of all your OS versions;
  • Test the new distribution in a Live CD session to check whether the OS can manage all your hardware without too much hassle;
  • Install the OS on a free system partition;
  • Test and configure the installed OS;
  • If the new OS is not as good as your previous one, come back to your favorite one just by rebooting it. If you made no mistakes, you will not need backups.
2. Partitioning your hard disk

If this is your first multi-OS installation, you MUST read this Web page http://ubuntuguide.org/wiki/Lucid_Multi ... stallation to fully understand how to partition a hard disk and how to configure GRUB to prepare a multi-boot system. If you do not understand everything in the Web page, do not be afraid, you will just need to type in a terminal the instructions provided. Using thereafter your computer will make you to understand many things. The advantage of following their scheme is that installing subsequent OS will need no manipulations of your GRUB configuration beside editing the title of the new OS in an ASCII file. So, this is something to do only once during the lifetime of your computer when you do not change its system hard disk. That saves a lot of time and makes the test of new OS a piece of cake. Today, installing a new Ubuntu-based OS such as Linux Mint takes me around 15 to 30 minutes (backups and test phase not included of course). I am actually writing this tutorial in a temporary OS that I installed on my computer a couple of days ago. I will probably not keep the new OS because I still prefer Linux Mint 13. Fortunately I work with this multi-OS scheme, hence coming back to Linux Mint 13 will just request me to reboot my computer and to slightly edit my user account configuration to restore my Mate panel, i.e., just a few minutes of my time.

Disk partitioning can be debated at length. For your first installation, read a bit about this topic. The effort will save you from a lot of difficulties later. I do not fully agree with the howto found on this site about disk partitioning because the author advocates to have a single OS on your hard disk. As I wrote above and will show below, this is one of the biggest mistakes you can make when you install an OS on a computer. Go immediately for a multi-OS scheme.

I will consider here that hard disk space is not an issue for you. If you have a small hard disk, adapt all partition sizes to your constraints. Your first task before partitioning your hard disk is to decide how many OS you want on top of Linux. You must have one partition for each non-Linux OS plus at least 2 partitions for Linux. For example, if you just want Windows installed along with Linux, you will need 3 system partitions. In such a case, install Windows first because its installer will destroy all prior work. Then:
  • Create two 15- to 20-GB partitions for two Linux OS. In Linux world, 15 GB/"system partition" should be sufficient today, even for huge Linux OS such as Linux Ultimate Edition. If you fear needing more system space in a couple of years, reserve 20 GB/"system partition". That is what I usually do.
  • You also need a swap partition. To be safe, book 4 times your RAM for your swap partition. It is a bit over killing but with modern hard disks, who cares?
  • Create a 1- or 2-GB partition for /boot.
  • Some people also like to have /tmp on its own partition with special read/write access for security reasons. If you choose that option, consider that editing a Blue Ray movie may easily require more than 15 GB of temporary space.
  • It is highly recommended to leave /home on its own partition to protect the system from lacking disk space when the users fill their disk partition. This way, the users will not be able to fill the system partitions with their own data.
  • Usually the swap, /boot, /tmp, and /home partitions should be unique on a hard disk because you will only boot one OS at a time. So all OS can share those partitions. Do not replicate them for each OS.
3. Backing up data

If it is not the first OS installation on the computer, back up the user and the system data of each OS. If you are upgrading an existing OS carrying out a fresh installation of the new version, the system data must contain at least /etc and the list of packages that were installed after your current OS had been set up. Your OS should provide a simple tool to extract such a list. I want to stress here that it is the list of packages, not the packages themselves. This way, when the new OS version is installed, you will have an easy way to know which packages you may need to install besides those automatically provided by the new distribution. For /etc, check etckeeper to manage /etc on your future OS to keep track of the changes you will bring yourself to /etc (http://aymanh.com/version-control-linux ... -etckeeper). It simplifies a lot our life when we upgrade a system because it is easy to spot and replicate our own modifications to /etc. That will be detailed below.

A Ubuntu-based OS installer generally asks for a user name. The user ID 1000 will be assigned to that user name. Always keep this user as a testing user or you will get into trouble from time to time when you test a new Linux version. The reason is that if the home directory of the user with ID 1000 does not exist, the installer will create and configure a new one for the default desktop environment of the distribution. Conversely, if the home directory of that user exists, the installer will not overwrite it. This can create problems when an obsolete configuration of a desktop environment conflicts with a new version producing a broken user account. Hence if you leave the home directory of a user with ID 1000 when you install a new Linux version, you may find yourself with a broken account when you login for the first time in the new distribution. That may mislead you to believe that the new distribution is bugged or poorly designed. In conclusion, you must always move away the home directory of the user with ID 1000 before installing a new Linux version. This way, you can be sure that you will be able to login with a clean configuration the first time you login in your new OS.

If the home directory of a user with ID 1000 already exists, move it away like this:

Code: Select all

sudo mv /home/username /home/username.bak
If, unfortunately, you are the user with ID 1000, you must change your user ID. Run your favorite user management tool from someone's else account with administrative rights and change your user ID for something else above 1000. When this is done run in a terminal:

Code: Select all

sudo chown -R your_username /home/your_username
That will recursively give you back the ownership of all the files and subdirectories from your home directory. Once there are no more home directories with user ID 1000, you may think about installing the new OS.

4. Testing the new OS in a Live session

Now it is time to test the new OS with your Live CD. After downloading the new OS ISO image file, check the file validity with md5sum. To do that, type in a terminal:

Code: Select all

md5sum your_image.iso
and compare the result with the expected one provided by the OS provider. For example, if you downloaded Linux Mint Mate 13 edition 64 bits, go to the download page http://www.linuxmint.com/edition.php?id=104 and you will see that the MD5 result is 2d84f671ad77a8019dfa6e1d00572d82. So if you type in a terminal:

Code: Select all

md5sum linuxmint-13-mate-dvd-64bit.iso
the result must be 2d84f671ad77a8019dfa6e1d00572d82 linuxmint-13-mate-dvd-64bit.iso. Any other answer would mean an incomplete or corrupted ISO file, hence you would need to download it again. Too many people have struggled for days with their new installation just because the downloaded ISO image was corrupted.

Several Linux distributions offer the possibility to boot a Live session of their OS, i.e., a session that only runs in your RAM without modifying your hard disk content. This way, you can test a bit the distribution before installing it on your computer. Those preliminary tests are often sufficient to reject a distribution saving us a lot of time because they avoid us a full installation on our hard disk. If your distribution cannot open a Live session, go immediately to the next section "5. Install the OS on a free system partition". Otherwise, read the rest of this section.

Once you know that your ISO image is clean, you must either burn it on a CD/DVD or put it on a USB device. I prefer my USB key because I bring it everywhere with me. This way when I am away I can always boot my favorite Linux OS if I can access a computer nearby. For this, I created a 2-GB partition on my 8-GB USB key to place a Linux Live CD on it. When I want to test a new OS, I use UNetbootin to transform the 2-GB partition of my USB key into a bootable Live "CD/DVD" from the new OS ISO image. I then boot a Live session of the OS from my USB key. If I am satisfied with the distribution, I let it on the key. If I prefer my previous system, I put it back on my USB key from the old Live CD ISO image. Then I put my key back in my wallet to have it with me everywhere I go. That is handy. If you test a Ubuntu-based OS, it is likely that UNetbootin will be able to produce a persistent Live USB key that automatically saves your changes between sessions. That helps a lot over time. If you do not know UNetbootin, do not worry there are tons of howto guides about it.

Boot the Live device. Do not install the OS yet, start by checking the compatibility between the new distribution and your hardware. You will know within a few minutes if the OS can handle your whole hardware without a lot of tweaking. If some devices are not properly managed, search in the Internet whether a solution exists. In an hour you can sometimes see in forums that managing some of your hardware by the new OS may require a very long battle. Experienced Linux users know that they are likely to eventually reach their goal, but sometimes the cost does not worth the result. In such a case, keeping your current OS and waiting 6 months for the next release is often wiser. Using another distribution may also be an interesting option if you crave for the last release because it contains a very important feature for you.

If you plan to equip different computers with your new OS, test the Live version on each of them. For example, if you want to install the distribution on 3 computers, do the test on the 3 pieces of equipment before beginning the installation on the first one. Would you like to work with that OS if some important hardware of one of the computers cannot be managed by the OS? Of course, it is better to discover that the OS cannot run on one of the 3 computers before finishing the installation on the two other ones. :)


5. Install the OS on a free system partition

If you are convinced to install the OS, what to do depends on your situation.

If it is the first Linux installation on the computer, you are unlucky because you will need to configure GRUB for the subsequent OS installations. This is tedious. Follow accurately the aforementioned guide and you will end up with a bootable system managed by a great GRUB configuration (http://ubuntuguide.org/wiki/Lucid_Multi ... stallation). I will not copy the guide, so follow it from now before resuming your reading here.

In contrast, if you already have the multi-OS GRUB configuration described in the guide, you will see how your life will be simple from now. Let's assume that you have a nice running OS that have satisfied you but you want to test another one. It can be either a different distribution or an upgrade of your current one. You have already done every steps written above, you have noted somewhere the partition structure of your hard disk, so you are ready for the installation.

Because we are in a Linux Mint forum, I will describe the steps of most Ubuntu-based OS such as Ubuntu, Linux Mint, or Linux Ultimate Edition. Within the Live session, click on the terrifying "Install..." button. After you have answered a few questions, the installer will find out that you already have one or several OS on your hard disk. It will ask you whether you want to install the new distribution along the other ones, or to replace one of them by the new one, or to carry out a custom installation. It is very important that you choose a custom installation or you may break your GRUB configuration rendering your previous efforts to nothing.

In the custom installation, you will need to choose what to do with each partition.
  • Let the swap partition being your swap partition for this OS too.
  • Choose the system partition where the new OS must be installed, choose its format (I usually use EXT4), and request the partition to be formatted and mounted on /.
  • Do not format any other partition. For example, if /tmp is on its own partition, you may be tempted to format it to have a fresh /tmp. Do not do that because it will change its UUID, and your previous OS will not be bootable anymore till you edit its /etc/fstab file to take the new /tmp UUID into account. If you do not understand this, do not bother, just do not format anything but /.
  • Complete your tree structure by requesting to mount the home partition on /home without formatting it. Do the same if you have other partitions to be mounted on your new OS system such as /tmp.
  • Do not mount your separate boot partition. Leave it alone or the installer will break your GRUB configuration.
  • Finally select the new OS system partition to install the new GRUB configuration. By default, the installer will suggest you to install the new grub configuration on your hard disk MBR, i.e., /dev/sda in most cases (the choice is often at the bottom of the installation screen). If you accept, your GRUB configuration will be destroyed. You must choose the partition which will be mounted on /. For example, if you decided to install the new OS on /dev/sda6, request the new grub configuration to be installed on /dev/sda6. This way, the new OS will be properly chainloaded by GRUB when you will boot. Again, if you do not understand the exact meaning of this choice, do not bother, just follow the instructions and you will be fine.
You are done. If I did not forget anything, you can click on Next and run the installer. You may have to answer a couple of questions again about your time zone and keyboard layout. The installer will also ask you a user name that will be created for you to login when the OS is installed. As discussed above, do not give your own account or another account that already exists or you may have trouble to login. Give a user name that has no home directories yet and let the installer create a home directory with a clean user environment for the new OS.

About 10 to 15 minutes after, the installer will tell you that it has finished. If you are very impatient you may reboot. In the first GRUB screen, choose the line corresponding to the new OS and you will boot it. When you see the second GRUB screen, just strike the Enter key because the new OS is automatically chosen by default. But be careful, the first GRUB screen was not updated by the installer. So you will not see the new OS name. You must know which line corresponds to that OS. Actually, when the installer has finished its work it is easier BEFORE rebooting the computer to edit the boot/grub/menu.lst ASCII file of the small boot partition to correctly indicates which is the new OS. For example, if the small boot partition is /dev/sda2, and if your new OS is on /dev/sda6, open a terminal in your Live session before rebooting and type:

Code: Select all

sudo mount /dev/sda2 /mnt
sudo gedit /mnt/boot/grub/menu.lst &
If gedit is not in your distribution, use any other text editor distributed with your OS. Search the line containing rootnoverify (hd0,5) (the number 5 here means the 6th partition (/dev/sda6) because the first partition is numbered 0; I know this is silly but this ball and chain comes from the past :D ). Replace the line just above rootnoverify (hd0,5) which contains title... by title your new OS name. You can also change the order of presentation of the OS to place your main one at the top. This will be the OS automatically booted when you do not press a key at boot time.

I also always want a line to be able to boot an OS from the first USB drive that may be interpreted as a hard disk. For this purpose I added this code near the end of boot/grub/menu.lst:

Code: Select all

title		An OS from the first USB drive
rootnoverify (hd1)
chainloader +1
This adds the line "An OS from the first USB drive" to the first GRUB menu. When I want to boot from my USB key or from an external hard disk, I disconnect all the devices that might be interpreted as hard disks, I just connect the one to be booted from, I reboot or switch my computer on, and I choose the line "An OS from the first USB drive" to boot. No more need to play with the BIOS to boot from my USB key or any other USB device. No more need to burn a Live CD on blank CD or DVD to install a Linux distribution.

So, to summarize how to install a subsequent OS after the data was backed up, after the ISO image was checked, and after the test user home directory was moved away:
  • Boot your Live CD/DVD (I use my USB key with the aforementioned GRUB line);
  • Test the OS compatibility with your hardware (a few minutes if you are not unlucky);
  • Click on the "Install..." button;
  • Select a custom installation and choose wisely what to do with your partitions;
  • Tell the installer to proceed;
  • Optionally edit the boot/grub/menu.lst ASCII file of the boot partition to indicate which menu line correspond to the new OS;
  • Reboot.
All this being done, you can test your newly installed OS.


6. Test and configure the installed OS

Let's assume that you called your test user testy. Login as testy. Immediately update your system through the update manager according to your taste. Some people install all available updates while other prefer to stick to the security ones. If you install all available updates, go for a walk because it can take half an hour.

Now you have an up-to-date system. Before installing the new OS you had saved the list of packages that you had installed on your previous OS after its initial set up. Take the list and install everything you want. Then, update /etc. It is where etckeeper is handy, specially if you still have your previous OS on another partition. For example, if you use Git as your control version system for etckeeper, and if your previous OS is on /dev/sda5, type in a terminal:

Code: Select all

sudo mount /dev/sda5 /mnt
cd /mnt/etc
gitk &
Browse the /etc version tree. It is very easy to spot the modifications you brought yourself to /etc on your previous system. You can then import them in your new OS. Do you see now how handy can be etckeeper? Without it, most people cannot remember all the /etc files they modified on the previous OS, they just remember some of them producing an uncleanly configured system. A few days ago, I imported in a newly installed system ALL my /etc own modifications from the previous OS in less than an hour. I therefore had my mail services, printers, and other features fully set in one short session. Now you should have a new system functionally at least at the level of your previous one.

Before login in you own account, keep testing the main features you usually use but only with testy account until you know whether you will keep or reject the OS. This way, you will not damage regular user accounts by bringing modifications only valid for the new OS. Because you have not touched yet user data, you can come back to your previous OS without work at all. If you decide to give up your new OS now, just type in a terminal:

Code: Select all

sudo rm -rf /home/testy
sudo mv /home/testy.bak /home/testy
sudo reboot
and you are done. You will reboot your previous OS exactly where you left it before starting to install the new one. Nothing modified! Is not it incredibly easy?

If you did not work with the multi-OS scheme and if you installed the new OS over the old one, now you would need to recover the old OS from backups with all the hassle that comes with restoring a system from backups. This is not always an easy task because inexperienced Linux users do not know what to backup and to restore. For example, they usually do not know how to handle /dev and /proc. On top of this, the Linux installers usually reformat the system partition (the partition mounted on /). This changes its UUID. As a consequence after restoring your previous OS, you will end up with the old partition UUID instead of the new one in your GRUB configuration and in /etc/fstab rendering your system unbootable because the old UUID does not exist anymore. With the multi-OS scheme you just suffer the first time to create a good multi-OS GRUB configuration. But following line by line the tutorial cited above is not too difficult. Even if you do not fully understand what you are doing the first time, you would probably be able to follow the instructions. Once it is done your life becomes incredibly easy when you want to test new OS or just upgrade your current one. People who blindly jumped from Ubuntu 10.10 to 11.04 know exactly what I mean!

Let's go back to your new OS. If you decide to keep it after testing it with testy account, you must update the user configurations. Logout from testy and login in your own account. Your account might be a bit messy due to an old desktop environment configuration incompatible with the new one. Normally, it should not be a problem. Most of the time, I can set my account as I want in one or two hours.

The work you are doing now in your account is likely to create incompatibilities with your previous desktop environment. So if you decide later to go back to your old OS because you discover a deal-break failure in the new OS, you will need to reboot your previous distribution and to recreate your old desktop environment either manually or from backups. This is usually quickly done. The last time I came back from a different distribution to the previous one after working for a week with my account in the new distribution, it took me about half an hour. I do not know what time would have been necessary if I had replaced my old distribution by a new one in a mono-OS configuration. Certainly much more than half an hour. In my case, I just rebooted my old OS, and I edited my account configuration for about 30 minutes.

Of course, if you are happy with your new OS and with your new desktop environment your are done. Enjoy! :D

pit
mpiter
Level 2
Level 2
Posts: 80
Joined: Tue Oct 25, 2011 3:24 pm

Re: How to install a Linux-based OS

Post by mpiter »

By the way. I am not an English native speaker. Any suggestion about the concepts or the formulation would be welcome.

pit
JoeBingo
Level 4
Level 4
Posts: 290
Joined: Fri Jun 24, 2011 4:18 pm

Re: How to install a Linux-based OS

Post by JoeBingo »

Thank you Very Much for this tutorial mpiter !!! Awesome !!! :cool:
As I next attempt to transition my old desktop from Mint 11 to Mint 13 ... this tutorial will be invaluable. Thank you
mpiter
Level 2
Level 2
Posts: 80
Joined: Tue Oct 25, 2011 3:24 pm

Re: How to install a Linux-based OS

Post by mpiter »

You are welcome. Since you really want to test and learn things, I think you will will be able to take advantage of it. I know you are not used to terminal command lines, hence do not hesitate to answer questions when something is not clear.
Post Reply

Return to “Tutorials”