linux installation

Linux installation:

Before we get into Linux installation, let's talk a little about Windows. It's a pity that you have to get your system to dual boot with both Linux and Windows present on the same machine. The reason you can't remove Windows OS is because many of the websites don't work on Linux browsers. Now with that info, let's try to get rid of as much as junk as possible.

Windows Changes:

The very first nuisance is that you can't use your laptop unless you have an account with microsoft, and they force you to sign in with that account. With Windows 10, you were able to avoid all of this by turning off internet, before setting up the laptop for the first time. Now, with Windows 11, it doesn't allow you to set up the computer if you are not connected to internet. I looked up tons of articles, but couldn't find anything reliable that works. So, I created my cheatsheet below based on what worked for me.

  • Switch to local account: Windows requires you to sign in with a microsoft account, basically how it's on all phones now. This is such a nonsense. We need to switch to local account. To remove online user account as your sign in option, search for settings. Go to settings->Accounts->Your info. Under there, you will see "Microsoft account" followed by a link to "Sign in with a local account instead". Click on that, enter minimal info (I think "user name" is required"), click next->next until done, and now your microsoft account will be switched with a local account. All of this is buried deep down on purpose
  • Remove Sign in option: Get rid of all PIN and any other sign in info. Some of should already be removed once you switch to local account. Go to settings->Accounts->sign-in options. Click on "PIN", click on "Remove PIN". Then under "Additional Settings", "choose "Never" for "When should Windows require you to sign in again". For account password removal, click on Password. It will ask for your current password and new password. Keep "New password" field blank. Now click ok, nd no more password required to login.
  • BitLocker Encryption: From Windows 10, there's this extra non-sense of BitLocker encrypting your hard drive to keep it safe. There's a recovery key associated with that, which is associated with your "Microsoft account" that was used for logging into your computer. Above, we switched to local account, but our online microsoft account is always associated with this laptop. This encryption causes a lot of grief during Linux installation, so disable it. Search for "encryption" in search box. It will show  "Device Encryption settings" which can also be accessed via settings->Privacy&Security->Device_Encryption. There you will need to turn it "off", if it's already "on". There's also an option to print or save "BitLocker Recovery Key" which is essential to have, if you ever do any BIOS changes. It's wise to keep a printed copy of this recovery key just in case something bad happens.
    • NOTE: There's a "Device Encryption" option  via Control panel->System&Security->Device_Encryption. This won't have anything in it to change, so don't end up here. This is NOT the right one.
  • Secure Boot: This is your last hurdle to getting Linux installed. You have UEFI in Windows 10, which has "secure boot" enabled. This prevents Linux OS from installing and will give error "Image could not be authenticated". To resolve this, you will need to change BIOS/UEFI settings. 2 ways to do this:
    • BIOS: You can directly get into BIOS settings. Press F2 (or some other function key depending on your laptop model) to boot into BIOS setup screen, while the laptop is just starting up (before it goes into the OS). Once the "boot window" comes, go to appr screen, and you will see "secure boot" option. Disable that.Then save changes and restart.
    • UEFI: Use this method when the BIOS method above doesn't work. Goto "change advanced startup options" in windows 10, From there, choose "Troubleshoot" -> Advanced options -> UEFI Firmware settings. The laptop will restart and will take you into "BIOS settings". Read through the list of options. There should be an option for "secure boot". Disable that.Then save changes and restart.
  • IMPORTANT: You need to do both steps: Disable "Bitlocker" first and then disable "Secure Boot". If you disable "Secure boot" first, the BIOS will keep asking for "Bitlocker" Key, and won't allow you to proceed. The only option will be to power down forcefully, and then powerup, go into BIOS and change "secure boot" to "on", and then it will allow you to log into Windows OS. So, the sequence of steps is very imp.

Now you are good to start with Linux installation process.

First need to find out a linux distribution that you like: https://www.howtogeek.com/313423/the-best-linux-distributions-for-beginners/

There are 3 basic steps in installing linux on a laptop, which already has windows 7, 8, 10, 11 installed.

  1. Dwnload linux iso, and burn it on a usb device or a dvd.
  2. Create an empty partition on windows with appr size on which we will install windows.
  3. Then from windows, choose the option to "restart and boot from usb efi device". Now on restart, laptop boots from usb. Follow the onscreen instructions for linux  from here on. Finally, you will have dual install with both linux and windows insalled.

Below are the 3 steps in more detail. I've explained specific steps for each OS later, but these are common ones for all OS.

1. Download and burn linux iso:

You need to download iso file from corresponding linux website (see choice of Linux OS in the section below), and have at least 16gb usb (you can get these 16gb usb for $2.99 on bestbuy very often). You need to follow the instructions in links below.

There are various ways to burn linux iso on a dvd or usb device. Many laptops do not have dvd drive anymore, so usb device is the only option available. However, installing via dvd can be life saver in cases where, linux fails to install via usb drives. In such cases, installing via dvd works just fine (one such example is ubuntu mate which installs via dvd only in my case).

There are 2 ways to burn linux iso files on usb. Both methods are detailed below:

NOTE: you will have to format your usb drive, before you burn iso files on it. On windows, you can do it by right clicking on that usb drive and clicking "format". Only FAT32 and NTFS are supported formats. If your usb drive is > 32GB, it will format it in exFAT instead of FAT32, which is not supported. If you burn iso files without formatting, the drive may not be bootable. In that case, reformat the drive with correct format, and then reburn the iso files. If your device already had something stored on it before, then there's no need to format it as it's already formatted.

Option 1: For WINDOW USERS: UUI installer, install on windows 10. => NOT RECOMMENDED.

This is needed for window users who don't have linux machine. Because of issues with this, I would recommend to go with option 2 below. Use this option at your risk.

Burn iso file on usb from within windows using UUI. We can't just copy and paste iso file from windows to usb drive, as the file doesn't get copied from start sector, so it won't be identified at all by the bootloader as having a valid OS. You need some 3rd party software, which in our case is UUI. UUI works flawlessly with most linux distro. However it does cause issues with some Linux distro which specifically ask not to use this UUI installator, We may also use the inbuilt burn option in windows that burns files to usb device. If you have a linux machine already, option 2 below will work flawlessly, so use that instead..

For people who can't use option 2 below and want to use UUI, here's the link for download:  https://www.pendrivelinux.com/universal-usb-installer-easy-as-1-2-3/.

On UUI installer, you will also see an option for formatting drive. I've never chosen any of those options (leave them unchecked). There are other ways to format device as I've mentioned above.

Option 2: ForLINUX USERS: using linux cp or dd cmd on Linux machine:

This option is the recommended one. However, this option does require access to a linux machine.If you don't have a linux machine, go with option 1 above.

There are lot of cmds in Linux to copy files from one source to other destination.

 Below are the steps:

A. STEP 1: From within linux, open a terminal and run "lsblk" to get device name for usb. First do it w/o usb inserted and then do it with usb inserted. You will see new "usb device" when doing it with usb inserted, It should be something like /dev/sdb (not using /dev/sdb1). part below means partition.

aarav@aarav-HP-Laptop-15-bw0xx:~$ lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 931.5G  0 disk
├─sda1   8:1    0   260M  0 part /boot/efi
├─sda2   8:2    0    16M  0 part
├─sda3   8:3    0 471.5G  0 part /media/aarav/Windows
├─sda4   8:4    0   980M  0 part
├─sda5   8:5    0  13.9G  0 part
├─sda6   8:6    0  18.6G  0 part /
└─sda7   8:7    0  93.1G  0 part /home
sdb      8:16   1  14.5G  0 disk
└─sdb1   8:17   1  14.5G  0 part /media/aarav/UUI
sr0     11:0    1  1024M  0 rom  

B. STEP 2: This step to unmount device is NOT needed. It may be needed for "dd" cmd below, but NOT for "cp" cmd.

Ignore all steps below and proceed to step 3.

We need to unmount sdb1, so run cmd (NOT needed anymore):

sudo umount /dev/sdb1

Now, when we run lsblk, it will show sdb1 as "part", with nothing mounted on it.

sdb      8:16   1  14.5G  0 disk
└─sdb1   8:17   1  14.5G  0 part

C. STEP 3: Now run any of Linux cp cmds. i used to think dd was the program that copies and maintains the image integrity. From the link below, looks like any cmd will do. Infact, plain "cp" cmd will work just fine.

https://unix.stackexchange.com/questions/224277/is-it-better-to-use-cat-dd-pv-or-another-procedure-to-copy-a-cd-dvd/224314#224314

Some Linux distro do not work with UUI installer at all as I mentioned above. CentOS and Arch Linux are the ones that gave me errors when trying to boot with image copied on USB drive. When I used Linux "cp" cmd to copy image, they worked flawlessly. UUI is not the preferred method for any Linux distro. Even if you have Windows machine, try to find someone with a linux machine to copy iso image. It'll save you few headaches :)

cp cmd: Plain old vailla "cp" cmd works.

sudo cp /home/aarav/Downloads/CentOS-7-x86_64-Everything-1804.iso /dev/sdb => This copies from src iso file to destination drive (here /dev/sdb. Do NOT use /dev/sdb1). This is fast and only takes less than a minute. Note that no . is needed in dest (i.e /dev/sdb/. is not needed, though may be used)

dd cmd: dd cmd is not really needed, but I'm putting it here, since I already used it multiple times, got it into my notes, and feel wasted deleting it.

Ignore all steps below for dd cmd and go to step 2 below.

sudo dd if=/home/aarav/Downloads/CentOS-7-x86_64-Everything-1804.iso of=/dev/sdb status=progress oflag=sync

18354176+0 records in
18354176+0 records out
9397338112 bytes (9.4 GB, 8.8 GiB) copied, 3529.5 s, 2.7 MB/s

It will take couple of hours to burn the usb device, and progess will show on progress bar. Once done, run lsblk cmd. It will show 2 partitions under sdb: sdb1 and sdb2

sdb      8:16   1  14.5G  0 disk
└─sdb1   8:17   1  4.3G  0 part

└─sdb2   8:17   1  8.5M  0 part

Congratulations. Now, this usb device is ready to be used to install linux.

2. Create empty partition on windows:

search for "partition" on windows 8/10/11. In windows 8, you can search by taking your mouse to top right corner, and then search option will show up on right side. search for "format", and choose "create and format hard disk partition". In windows 10/11,  search for "format" in windows search bar (Windows 10 has it in bottom left of screen, while windows 11 has it in center), it will bring an option for "create and format hard disk partition", choose that. It will bring a "disk management" window. Under C drive, it will show the largest hard drive on which windows is installed. Right click, and select "shrink volume". Choose amount of space to shrink by, and it will create a new, unallocated partition with that size (choose any size greater than 20GB). When we say shrink by 50GB, it creates a new "unallocated" partition of 50Gb. This "unallocated" partition is what we will use to install Linux. This "unallocated partition" will have nothing in it, and is unreadable by windows.

3. boot from usb device:

Once partition is created, then from within windows 8/10/11, you can ask the OS to restart and boot from USB drive. This is the easiest way. Search for "startup" in windows 8/10 search bar as explained above. It will bring an option for startup under settings (usually called "change advanced startup options" in windows 10/11) , Choose that, click on advanced startup, and then from within there, goto boot from "efi usb" drive. Make sure you have your usb drive (with Linux iso file burnt on it) inserted in laptop. You will see your usb drive name, or linux distro name or something similar. Now laptop will start and it will boot from usb drive. It will show you various options when it's booting from usb drive, just choose the "Linux OS boot" option (do not choose OEM, advanced, repair or any such option). Once you are inside Linux OS, you will see "Install Linux Mint" or similar icon. Just click on it, and it will guide you through instructions. For some linux distro as "CentOS", installation starts right away, when you select "install CentOS". 

Troubleshoot Issues before Linux Installs:

There are multiple issues when you can run into when installing Linux distro in step 3 USB drive not showing up. Windows 11 has even more stringent requirements before it can dual boot, compared to windows 8/10.

1. USB drive isn't showing: Sometimes, usb drive is not recognized at all during powerup, (even after you have clicked on "boot from efi usb device" from within windows). Your laptop will boot into windows as it normally does, without showing the boot menu from usb drive. If that happens, then you will need to use some combination of Function key (F1, F2, ctrl + F1, etc) to get into BIOS, and from there ask it to boot from usb drive. This just depends on brand of your laptop. For dell laptops, F2 or F12 work (without the "fn" key, just keep hitting the F2 or F12 key repeatedly). It will work eventually, you will have to patiently search on internet for key combination to enter BIOS. This is usually not required on windows 8/10, as "booting from EFI USB device" works on most laptops with windows 8/10. Windows 11 is  different story.

2. Disable BitLocker Encryption: This needs to be turned off, as explained above.

3. Disable Secure boot mode: This needs to be turned off, as explained above. Now, on restarting and starting with step 3 again (as shown above), you shouldn't get that error message.

 

Linux Power up OS selection:

Once you have Linux installed alongisde windows, you can now now turn off your computer and restart. Now a new menu will come up right after powerup. This menu is from Linux GRUB, and it allows you to choose which OS you want to boot into. Sometimes, this GRUB menu doesn't show at all, and machine boots right into windows. This GRUB menu is there along with Linux OS, but for some reason, Windows OS still retains control. There are many ways to fix this. You will have to search on internet. One of the options that has worked for me all the times in the past is here:

https://www.partitionwizard.com/clone-disk/dual-boot-option-not-showing.html

Here, option 2 is what worked. You have to type this line exactly on the cmd prompt of windows machine (open command prompt as admin), and GRUB menu comes back during startup. On windows 10, it shows "windows Powershell" in menu. you do NOT want to use that. You have to search for "command prompt" in search field, and then you will see option for "Run as administartor" on right side. you have to click on that and that will open "Administartor: Command Prompt". If you see "Administrator: Windows power shell", you are in wrong place. It may mess up your system. Also note the spaces and slashes in the cmd below. It should say "operation completed successfully" on entering the cmd below.

bcdedit /set {bootmgr} path \EFI\ubuntu\grubx64.efi

NOTE: There are lot of articles on how to fix this issue in windows 10. None of them may work for you. The fix depends on the brand of laptop you have. If you are not able to find anything that works, you can manually boot into Linux everytime by getting into the boot option (when computer power up). You have to find right sequence of keys to press to bring up bootup option (again search on the internet to find the sequence of keys for your particular brand of laptop). You may not be able to get the boot menu, but atleast you'll be able to login to Linux. I always had a hard time with HP laptop into getting dual boot :(

Linux distro:

I've installed Linux Mint, Ubuntu, OpenSuse and CentOS successfully on different laptops. I'll go over the instructions for each of these below.  If there is any error during installation process, then it's best to remove the installation, start fresh with new installation. Some files may get corrupted if there is any error during installation process. Trying to get that installation to work next time w/o deleting it is a sure wastage of time. However, deleting a linux distro is nt staright forward, look in below section.

These are couple of inux distro that I installed personally, and would recommend. I've detailed section for each.

  • Linux Mint
  • CentOS
  • Ubuntu
  • Arch Linux
  • Opensuse
  • MX

 

Uninstall/delete Linux distro: 

Some times, the Linux distro will run into issues halfway thru installation. in such cases, it's best to uninstall Linux OS, GRUB and then reinstall fresh. To uninstall Linux, steps to be done in below sequence are: 

  1. remove grub boot loader
  2. remove linux partition by logging into windows OS => NOTE:don't do this step before removing GRUB, as that may make GRUB not see Linux partition, and will give pain trying to delete GRUB.

Link => https://itsfoss.com/uninstall-ubuntu-linux-windows-dual-boot/

 

DeskTop Environment (DE):

Display manager (dm), aka login manager is responsible for bringing up this graphical login screen, and sets up graphical environment once logged in. Window manager (wm) is responsible for windows once logged in. It controls the placement and appearance of windows within a windowing system. Both dm and wm together along with file manager, terminal, etc comprise a desktop environment (DE). many dm can automatically dtect isntalled DE, and can give a choice as to which DE we want to start once logged in. Variuos DE come with a default dm and wm. These are the DE for various distro:

Remember, KDE and GNOME were the only 2 DE in Linux in 1995. corresponding dm were kdm, gdm, xdm (x display manager), lightdm (light display manager). wm were twm (most common on gnome).

GNOME:  dm=gdm (GNOME display manager), /etc/gdm has all configuration files. latest GNOME is GNOME3. It has 2 options: GNOME shell, and GNOME classic. GNOME classic is what is favoured by most distributions, as GNOME shell is major departure from earlier GNOME DE. Earlier version is GNOME2, which was very popular. A branch is forked off GNOME2 and that DE is known as MATE. Another such branch of GNOME2 is Cinnamon. Cinnamon is default DE for LinuxMint, while GNOME classic is the default for CentOS. Although GNOME classic looks similar to GNOME2, and is advertised as GNOME2 compatible, it's very different than GNOME2 in how it can be configured. Many of the options are locked down in GNOME3 classic (i.e number of workspaces is fixed to 1, no way to get a panel menu by right clicking on top menu bar, etc). Best thing to do is to just switch to MATE (which looks very similar to GNOME2) or Cinnamon (which looks very similar to windows and is the most user friendly linux gui for any user).

KDE: dm=kdm (KDE display manager). But on latest KDE Plasma 5, kdm has been replaced by sddm. It's default DE for OpenSuse.

Xfce: This is very light weight DE. It started as common desktop environment (CDE). wm=xfwm

 

Which of these DE gets called at powerup is decided by /etc/X11/xinit/xinitrc (or other files for sysctl). The binaries for these DE are put in /usr/bin/ (As *session*, or as *mate*, *kde*, etc). We can put an optional .xinitrc file in user dir with cmd "exec mate-session" in it. Then at startup, when that user logs in, MATE would be started as GUI. "exec gnome-session" in  .xinitrc will start GNOME at startup. Other way would be by putting a .Xclients file in your home dir, with name of session you want to start. i.e to start "MATE", type "mate-session" in .Xclients, change permission to +x (executable), However, this may not work for distro that have switched to sysctl (i.e it doesn't work on CentOS 7). Most fool proof way to achieve the same result is by removing all *.desktop file from /usr/share/xsessions/ except the one that we want to be there by default. Then system will boot into that GUI session for which the desktop file exists (since there's no other desktop file to look for). You can move those unneeded *.desktop files to some temp dir, and then move it back when needed. That way we can change to whatever DE we want to.

 NOTE: Remember all of these changes above with regard to .xinitrc, .Xclients, etc may still work for "startx" as startx does call xinit, which eventually looks in xinitrc file. You can look thru the code of xinitrc to figure out what file to change to get a particular wm, when running startxx from CLI in any of the virtual terminal. For ex, from tty2, we may type "startx" and that will start a wm. 

systemctl:

Once you install these different DE in any linux distro, you will see these in /usr/share/xsessions/*.desktop. Each of these DE have a dm and a wm. We can change which dm to power up with by using systemctl cmd (with sudo preceeding the cmd, as it requires root privileges)

sudo systemctl enable gdm.service => Tells systemd to start gdm automatically at boot. "disable" disables this. "enable" creates symbolic links, while disable dremoves these links. "start" will start an application's systemd service, while "stop" will stop it in current session. /etc/systemd/system/display-manager.service decides what dm gets started at boot. If gdm is to be started at boot, then there will be a soft link to /usr/lib/systemd/system/gdm.service .

systemctl get-default => This shows us the default run level of system. Earlier, /etc/inittab file used to have runlevel info since we used "init" system, but now since we use systemd, it uses targets instead of run-level. multi-user.target is analogus to runlevel 3, while graphical.target is analogous to runlevel 5. Runlevel 3 is text based login, while 5 is gui (X11) based login. Target is determined by /etc/systemd/system/default.target which is a softlink to /lib/systemd/system/grahical.target (for GUI based login mode). This link can be changed by using "systemctl set-default multi-user.target". target determines what services will be run, as each target is dependent on services or other targets, which in turn are dependent on services

sudo systemctl list-dpendencies graphical.target => This list all dependencies for graphical target. One of the dependencies listed here will be gdm.service which shows that dm used is gdm. "ps -ef | grep gdm" will also show /usr/sbin/gdm as one of the processes if gdm was used as dm.

 

Install desktop environment (DE):

Each OS has it's own way to install DE. We talk about installing these in the respective "OS installtion" sections.
 


 

Desktop Icons:

Sometimes, we install a software, but it doesn't automatically put a desktop icon, that we can click on. Making aDesktop Icon in Linux is easy. Make a file with .Desktop, and inside it, provide the icon image (Icon=), the executable to run (Exec=), and the dir, where it should be run (Path=). That's it.

NOTE: putting a .Desktop extension is necessary, else the script won't run. Let's create a file in Desktop dir: Desktop/Vivado\ 2023.1.Desktop and put in the belw contents(\ is there since I have a space in the name of the Desktop entry. If I had Vivado_2023.1.Desktop, then no \ needed). This name is not what appears below the dsktop icon, it's the name provided below (Name=). All other options may be omitted.

[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Icon=/tools/Xilinx/Vivado/2023.1/doc/images/vivado_logo.ico
Name[en_US]=Vivado 2023.1
Exec=/usr/local/bin/run-vivado
Path=/home/rajesh/Vivado_training
Name=Vivado 2023.1
StartupNotify=true

Now an icon will appear, as soon as the above file is saved. Now we can click on the icon and see if it runs our executable. Put a small script that prints "Hello World" in a file and check that the file appears in the dir indicated.