Search This Blog

Sunday, February 7, 2016

Time with mr. LINUX ! PART02

 (If you have not installed and configured Arch linux yet, please check my previous post first) .

Linux filesystem 

A specific way in which files are stored on a disk is called file system: enables files to have names and attributes. It also enables them to be stored in a hierarchy of directories or folders arranged in a directory tree. The next figure shows how does linux organizes its directories. In linux everything is a file so there is no root directory (you won't find things like c: d: etc like in microsoft windows to represent storage devices and hard drive partitions).
Linux VFS (virtual file system) makes all the files on all the devices appear to exist in a single hierarchy.
Linux assigns a device name to each device but that is not how the files on that device are being accessed. to gain access to files on another device, the OS must first be informed where in the directory tree these files should appear (This process is called mounting a file system). The file system (device) includes a directory that is passed to the OS to be mounted (mount point). In part01 we learned about fstab configuration file provided by linux to facilitate mounting at boot time.
*Note: in the figure, jono, mako and cory are users of the systems.

Arch linux repositories and package Management

"A repository is a storage location from which software packages can be retrieved and installed on a computer." Arch linux official repositories include:
- basic: official binary repository
- core: Packages needed to, boot Arch linux, connect to the internet, building packages, and system setup processes.
- extra: desktop environment and programs. (packages that do not fit in core)
- community: Packages built by community (packages built by trusted AUR users: Archlinux User Repository)
- multilib: contains 32 bit software and libraries
Official packages are obtained by pacman (package tool/installer) from the Arch linux package tree and compiled either for IA-32 or x86-64 architectures. Binary packages use tar.xz format with .pkg placed before this (.pkg.tar.xz)
* There is also the Arch Build System (ABS) ( used in conjunction with AUR packages) which provides a directory tree of shell scripts called (PKGBuilds) that enable any and all official Arch packages to be customized and compiled. (more to ABS in future posts!)

Package Management (pacman)

Pacman is one of the major distinguishing features of Arch Linux and handles installation, upgrade, removal and downgrade of packages. It features an automatic dependencies resolution. pacman keeps the system up to date by synchronizing package lists with the master server. 
Here are the most important uses and options of pacman:

- Update the packages database: pacman -Syu
- Search for packages in the database: pacman -Ss string1 string2
- Search for already installed packages: pacman -Qs string1 string2 
- Display information about certain package: pacman -Si package_name
or  pacman -Qi package_name (installed package)
- Cleaning the package cache: pacman -Sc
- Install package/packages: pacman -S package1 package2 ..
- Remove a package/packages: pacman -R package1 package2 ..
or pacman -Rs package_name (remove package and dependencies)

More info and options: pacman !

Time with mr. LINUX ! PART01

In the next few posts, i will be introducing you and myself to the Arch linux (using command line interface only) and will try to make it a very compact tutorial that concentrates on the basics... however ..

Some necessary introduction

Linux is a beloved open-source OS that competes with both market monsters, Microsoft and Apple. There are 2 ways to operate a Linux OS; using a graphical user interface GUI (windows, icons, menus, etc ... the stuff you are familiar with in windows or osx) or using a command line interface CLI (shell). Due to its flexibility and configurability, linux variants include thousands of programs and applications and they are known as Distributions or distro (like Debian, Fedora, Ubuntu, ..etc ) to satisfy all kinds of needs and tastes.

Arch linux is one of these distributions (targets advanced users) that supports community involvement and consists predominantly of free and open-source software, and supports IA-32 and x86-64 architectures. 

x86-32 or IA-32 stands for Intel Architecture - 32 bit, sometimes called i386. This refers to the instruction set  architecture (ISA) that was first implemented in the intel 80386 microprocessors in the mid 80s.x86-64 on the other hand refers to the 64 bit version of the x86 architecture. By the way: an Instruction Set Architecture is a part of computer architecture that is related to the programing of a microprocessor (data types, registers, addressing modes, instructions , etc)

The 5 important steps:  get and install Arch linux

1- Lets go to the archlinux download page and download the latest release in a form of an iso image (about 701 MB in size) then create an Arch linux USB installer drive (LiveUSB) for booting in BIOS and UEFI (another firmware interface for PCs designed to replace the BIOS ). Here is how you create the LiveUSB:
Under Windows: Use a programs like Rufus to create a bootable USB drives (Rufus has an easy and multilingual interface, please check their website for details). 
Under OSX:  - Insert the USB key and then OSX will mount it automatically.- Go to terminal and type:  diskutil list to figure out the USB device name from a list of connected storage devices (usually appear as: disk1, disk2, ..)  - Unmount the USB key by typing:  diskutil unmountDisk /dev/disk#
- Navigate to the folder where you downloaded the iso image and then type: dd if=image.iso of=/dev/rdisk1 bs=1M
 - Finallydiskutil eject /dev/disk# before physical removal of USB key from computer. 
After booting the target computer from the USB key, you are automatically logged in as root.

LiveUSB Boot screen

2- Now it's time to partition and format the hard drive and we do that using fdisk and/or cfdisk partitioning tools:  fdisk -l  to list all available storage devices, then: cfdisk /dev/sda to use the partition tool. 

(note that cfdisk is similar to fdisk but has a different user interface. cfdisk has the advantage over fdisk in that it's possible to enlarge an extended partition when there is free space after it. )

I suggest that you delete all partitions on the target drive (To delete an existing partition, highlight it with the up and down keys, select the Delete command with the left and right arrow keys, and press Enter) then create a root partition (by selecting the new command.This partition will include most of the disk freespace) and make it of type bootable (by selecting the type command, and using the space bar to toggle between different types). Now create a second partition (a swap partition with 1/2 the size of installed RAM on the PC) and make it of type swap. Finally save/write (write command) and quit fdisk tool.
3- Create the file system on the root partition: mkfs.ext4 /dev/sda1 then mount: mount /dev/sda1 mnt  
4- Make a swap file on the swap partition: mkswap /dev/sda2 then utilize it: swapon /dev/sda2
5- Type pcstrap -i /mnt base base-devel to instal arch linux base system and development base system a on the mounted root partition.
*sda1 stands for root partition and sda2 for swap partition.
*The root partition is the disk partition that contains the root file system and on which the root directory is located.
*Swap space in Linux is used if the system needs more memory resources and the RAM is full, inactive pages in memory are moved to the swap space.

Configuring the installation

- Now to access the new installed system type: arch-chroot /mnt
- Create a password for the root account by typing: passwd then the actual password after being prompted to do so.

Important setup (locale)

locale in arch linux refere to regional monetary values, time and date formats and other regional standards.
- To setup the system locale, type: nano /etc/locale.gen (nano is the name of the text editor tool we use to edit the locale.gen file).
- Uncomment the line referring to your region or country then use CTRL + o to save/write changes, press Enter then CTRL + x to quit.
#en_SG ISO-8859-1
en_US.UTF-8 UTF-8
#en_US ISO-8859-1
- Type locale-gen to generate the locale
Type : cd /usr/share/zoneinfo to navigate to the time zone settings. Type ls to list the different time zones.
- To confirm the chosen time zone setting type: ln -s /usr/share/zoneinfo/Europe/Zurich /etc/localtime
- Now we would like to setup a hostname, we do that by typing: echo my_hostname> /etc/hostname

Here we need to have a wired internet connection (Ethernet cable) to our target computer.
Check internet connectivity by pinging for example..
ping -c 3

Installing the Bootloader (grub)

GRUB =  GRand Unified Bootloader, a very powerful newish BootLoader that can be used to boot most operating system on the intel platforms. Here think multiboot functionalities :-)

- First we download grub using the arch linux package manager (pacman)
  pacman -S grub-bios
then we install it by typing: grub-install /dev/sda
- Now generate the so called INIT files (Initialization files used by grub to load linux). 
do that by typing: mkinitcpio -p linux
- Create the grub configuration file: grub-mkconfig -o /boot/grub/grub.cfg
- Exit the current root session.
- Generate fstab file (a configuration file that controls with automating the mounting process of partitions): genfstab  /mnt >> /mnt/etc/fstab
- Unmount the Hard drive: umount /mnt
- Reboot (make sure to remove the installation LiveUSB before rebooting) 

Another necessary setup (Keyboard layout)

- Type localectl status to view the current keyboard configurations
   System Locale: LANG=en_GB.utf8
       VC Keymap: cz-qwertz
      X11 Layout: cz
- Type localectl list-keymaps | grep -i  keyword  ( the keyword here could be something like us for United states, ch for Switzerland or de for Germany)
- After finding the right keymap for your keyboard type: localectl set-keymap --no-convert your_keymap
- Finaly load the keymap: loadkeys keymap

Final step (user account)

To create a user account type: useradd -m -G wheel -s  /bin/bash user_name
( -m =  create a user home directory in /home, -G = introduce a list of groups a user is part of, -s = defines the path- and file-name of the login shell)
Finally secure the new account with a password: type passwd then create the actual password. 

Now we are ready to start -linuxing- !