Friday, September 8, 2017

A quick guide for Installing Arch Linux in virtualbox

Hello friends,

There are several guides for installing Arch linux (a very popular linux distribution) including Arch's own Guide.

So, why write another one ??

Reason is simple... none of them worked 100% for me. So, I thought why not share with you a process or method that worked for me.

Majority of what I have written below is taken from this blog . However, even this one was not full-proof and I have to install-remove-reinstall several time.

I just hope that my method will work 100% for you as well.

So, let's begin ..

1) Download the image file from Arch Linux website . You can use this link.

2) Create a virtual machine of your choice of configuration. Please remember to select the Arch Linux (64-bit) as the Operating system choice.

3) Attach the image file to the virtual-machine that you just created.

4) Start the machine and choose to boot the x86_64 version. This will take you to a shell console prompt instead of the usual graphical interface everyone is so familiar using with other linux distribution. But, my friends , this is "Arch Linux" . So, it does everything in "arch" way.

5) Start the Arch partition editor to create a file-system to install our OS.

           gdisk /dev/sda

6) Type ‘p’ at the prompt and hit ‘Return’ to see an initial summary of your system vitals. To create the partition, do the following

a. Type ‘n’ at the prompt and hit ‘Return’ to tell gdisk you want to create a new partition.
b. Then just go through and hit ‘Return’ repeatedly to accept the default partition number, first sector, last sector, partition size, and hex code. This will create a final partition with a Linux filetype that fills the remainder of our virtual hard drive.
Now type ‘p’ and hit ‘Return’ to see the finished partition scheme showing a single partition as you have entered. 
Please Note that :- here we are skipping several things to make things simpler. e.g. we have skipped swap for two reasons , one being arch is low on resource requirement and two now a days RAM is available in plenty to all users. Another thing that we skipped here is creating seperate boot / root / home partition because of simple reason that this is installation on a virtualbox. This is not going to be your primary OS. Anything goes wrong, just wipe clean and start-over. It is the most beneficial part of using a virtualbox .

7) Now that we’ve drafted our partition, type ‘w’ at the gdisk prompt and hit ‘Return’ to write the partition scheme to the disk. When gdisk asks whether you’re sure you want to do this, type ‘Y’ and hit ‘Return’ to say yes. Gdisk will implement your partition table and then quit, leaving you back at the shell console prompt.

8) Next, back at the command line, we’re going to format our new disk partition so that we can begin using them. This is not unlike formatting any other disk, except perhaps that you may be used to doing this with a mouse and a desktop GUI. We’ll be doing the same thing from the command line.

So, run the following commands :-

a. Create a file-system.

         mkfs -t ext4 /dev/sda1

b. Convert the filesystem to 32-bit .

         resize2fs -s /dev/sda1

This may sounds odd to you as we are installing here a 64-bit OS but syslinux website states this :-
As of Syslinux 6.03, "pure 64-bits", compression and/or encryption are not supported.
Quoting part of the release notes of version 1.43 of e2fsprogs (May 17, 2016):
        Mke2fs will now create file systems with the metadata_csum and 64bit features enabled by default.
Users should rather (manually) disable the 64bit feature in the mke2fs command when creating / formatting a boot volume with ext2/3/4; otherwise, the bootloader (as of version 6.03) will fail.
So, we have to apply the work-around. ( reference link ). This helps us to avoid "Syslinux Failed to load ldlinux.c32" error in post-installation boot.

9) Next we will mount our newly created file-system

               mount /dev/sda1 /mnt

10) Before we proceed further, we need to check our internet connection as the Arch linux installer need an active internet connection to install it properly.

Now, you all might be thinking

"oh God ! I just downloaded 500 MB odd stuff and that too for a shell prompt based installer and it again need internet connection !!! Why ?  Why ? Why ?".

So, let me be frank with you that I simply have no idea for why :D . But, it simply doesn't work without internet connection. You will be left with a totally unusable environment.

So, ping google's IP .

             ping 8.8.8.8

If you receive a response then very good . Else please check if the network icon iin virtualbox indicator is greyed or blue. Once you make it blue i.e. connected the network adopter , run the below command twice (it doesn't work for me at first go..running twice will do no harm anyways) then recheck the ping response.

            dhcpcd

11) Now we can start installing Arch Linux.

To install the ‘base’ and ‘base-devel’ packages to the root partition, run the following command:
    pacstrap /mnt base base-devel
Since we’re currently installing the whole operating system, this command may take a few minutes to download (approx. 300 MB) and execute. You can stick around and watch the progress bars if this sort of thing fascinates you, or you can go get a cup of coffee and come back when it’s finished.

12) Next we have to do some miscellaneous setup before rebooting. To generate your system’s fstab file, run the following command:
   genfstab -p /mnt >> /mnt/etc/fstab
Next, install syslinux :

            arch-chroot /mnt /bin/bash
            
            pacman -S syslinux

            exit 

            syslinux-install_update -i -a -m -c /mnt/

Next, edit the syslinux configuration file located at /boot/syslinux/syslinux.cfg using below two commands.

a.  cp -p /mnt/boot/syslinux/syslinux.cfg /mnt/boot/syslinux/syslinux.cfg.bak
b.  sed 's/sda3/sda1/g'  /mnt/boot/syslinux/syslinux.cfg.bak > /mnt/boot/syslinux/syslinux.cfg

This step is required as the automated installation script that we used above sets the configuration to sda3 whereas in our installation we have just one partition and that is sda1.

13) a . Next, chroot to the installation to setup it further.

              arch-chroot /mnt /bin/bash

b. Setup the locale setting:

          echo LANG="en_US.UTF-8" > /etc/locale.conf

c. Open the file /etc/locale.gen and uncomment these two lines :-

          #en_US.UTF-8 UTF-8
          #en_US ISO-8859-1

d. Implement the locale change :

          locale-gen

e. Set the time-zone (default setting is at UTC) :

         rm /etc/localtime

         ln -s /usr/share/zoneinfo/America/New_York /etc/localtime

f. Set the hostname :

         echo "Arch Linux" >  /etc/hostname

g. Create the initial RAM disk :

          mkinitcpio -p linux

h. Set the root password to avoid system unauthorized access :

          passwd

i. Create a user for your use (here foo is the user)

           useradd --home-dir /home/foo --create-home foo

j. set a password for new user

         passwd foo


k. install sudo package. (test your internet connection by ping to 8.8.8.8, if the command doesn't work. Also run dhcpcd command to establish internet connection as in step 10 stated above )

         pacman -S sudo

l. edit the file /etc/sudoers to add the new user. Add the "foo ALL=(ALL) ALL" below the line "root ALL=(ALL) ALL" in the file.

m. make the dhcp service a default at startup :

         systemctl enable dhcpcd@enp0s3.service


n. install the virtualbox related packages

           pacman -S virtualbox-guest-utils virtualbox-guest-modules-arch

o. instruct the system to load virtualbox modules at startup

           echo -e "vboxguest\nvboxsf\nvboxvideo" > /etc/modules-load.d/virtualbox.conf

p. Enable the virtualbox service

          systemctl enable vboxservice.service

q. install the xserver packages for basic GUI setup

          pacman -S xorg-server xorg-xinit xorg-twm xorg-xclock xterm

r. Next install GUI environment of your choice ( I will use mate as example )

          pacman -S mate mate-extra

s. enable the display manager

          systemctl enable gdm

That's it for installing our Arch linux environment. We can quit it by issuing exit command.

14) Next we have to unmount our partition

                        cd / && umount /mnt

Once this has been done, we’ve only one last command to run before rebooting into our new system. Before rebooting, run this command from the installer disk’s command prompt, which will set the our partition’s BIOS flag to “bootable”—basically, tell the computer’s lizard brain which partition to boot—and allow your new system to boot on restart:

                       sgdisk /dev/sda --attributes=1:set:2

That's it !! Now reboot by entering following command

                       reboot

Now, remove the iso disk from the virtual drive and power-it off. Next time when you start your virtual machine, you will be presented with the "Arch Linux" boot menu which you can use to boot into the OS.

Any issue !!! Simply, post in the comment and I will look it up for you !!

Enjoy !!!