Labels

Sunday, June 7, 2015

Use Arch Linux

Why Arch Linux?


Arch Linux is all about freedom. It is like you build your own house. You choose your land, and you start building your own. Explains Arch philosophy, "KISS" stands for "Keep It Simple Stupid". Just use it once, I'm sure you won't leave it. I'll sort out my points here,

1. Simplicity and performance.
This is the major goal of Arch Linux. Since you build everything from the scratch, you can choose the best components for your needs which give the best desktop experience and simpleness. The lightweight core structure gives the best performance by lower system resource demands.

2. Packages.
Arch Linux has the biggest software repository. I still couldn't find any package that is available for any other distribution but Arch. AUR(Arch User Repository) almost has everything. Arch developers don't patch software that much. Because of that you always get the vanilla packages which are fresh, clean and almost up to date.

3. Package manager.
Arch Linux has a nice package manager, "pacman" for its official repositories, which makes much more easier package management than other distributions. In Ubuntu or other distributions if you are installing some software you have to follow these steps add the repository, update the package list cache and install it. But Arch AUR gives you the ability to do all those stuff in one command. Very easy to maintain packages.

4. Rolling release.
Arch Linux is just the GNU/Linux kernel itself plus the desktop environment. Once you installed Arch Linux you don't have to worry about updating your operating system to newer releases like other distributions, which gives you the ability to use the packages you installed, forever. With Arch Linux, you are always running the latest. You are on the edge.

5. Documentation and community.
Arch Linux is a community driven distribution. It's by the community, to the community. No one can affect its development, nothing commercial. It's all about the freedom. If you are attempting put your hands on Arch Linux, Wiki has a nice documentation. Almost everything is there. This documentation helps you to learn about GNU/Linux much better than all other documentations, all from the scratch.


A simple guide to install Arch Linux.


Step 1 - Make a bootable.
Download Arch Linux image from here and make a bootable drive or a disk using a suitable tool like YUMI or Universal-USB-Installer something like that. If you are using Linux use "dd" to make a bootable.

Step 2 - Boot.
Boot the Arch bootable media you created. Select the appropriate option from the boot menu, whether your system is 64 bit or 32 bit. After booting the installation media, what you get is a root shell.



Step 3 - Set up the network.
Arch Linux installation need a working internet connection to download and install packages. Check whether the network is working,

# ping -c3 www.google.com

If you get an error like "unknown host", you have to setup network manually. If you are using a wifi connection use,

# wifi-menu

Step 4 - Setup partitions.

# lsblk -l //get a list of drives
# cfdisk /dev/sdx //disk utility to configure partitions

In this case, I'm going to make the root partition and swap partition only. If your PC is UEFI possessed, you might need to make a boot partition too. See Arch Linux guide for more details.


Now set the file system types and format partitions. Replace x, a, b and c with appropriate drive letters and numbers.

# mkfs.ext4 /dev/sdxa
# mkswap /dev/sdxb

Step 5 - Mount the partitions.
Now you have to mount the partitions you created.

# mkdir -p /mnt
# mount /dev/sdxa /mnt
# mkdir -p /mnt/home

If you have a boot partition,

# mkdir -p /mnt/boot
# mount /dev/sdxc /mnt/boot

Set swap,

# swapon /dev/sdxb

Step 6 - Install Arch base system and configure file system table.
Now you can install Arch Linux core packages to your drive. If you are encountering problems with this step, try prioritizing mirrors in /etc/pacman.d/mirrorlist file. 

# pacstrap -i /mnt base

And generate the file system table for the system to decide how to use partitions and drives.

# genfstab -U -p /mnt >> /mnt/etc/fstab


Step 7 - Configuring system.

# arch-chroot /mnt

To add locale and language support,

# echo LANG=en_US.UTF-8 > /etc/locale.gen
# export LANG=en_US.UTF-8

or manually edit the file /etc/locale.gen.

# nano /etc/locale.gen

Set timezone,

# ls /usr/share/zoneinfo //to get a list of available time zones
# ls /usr/share/zoneinfo/Asia //to get a list of sub zones
# ln -s /usr/share/zoneinfo/Asia/Colombo /etc/localtime
# hwclock --systohc --utc //sync the clock with chosen settings


Step 8 - Configure network.
To use a wired connection, you have to enable the dhcpcd service,

# systemctl enable dhcpcd

For wireless connections install these packages,

# pacman -S wireless_tools wpa_supplicant wpa_actiond dialog

Step 9 - Configure package manager.
Add multilib repository support, which has 32-bit applications in case if you want,

# nano /etc/pacman.conf

Uncomment,

[multilib]
Include=/etc/pacman.d/mirrorlist

Update the system,

# pacman -Syu


Step 10 - Root and users.
Now you have to create a user. For more information, see Arch Linux guide to users and groups.
To set root password,

# passwd //set password

To create a new user,

# useradd -m -g users -G wheel,storage,power -s /bin/bash lahiru
# passwd lahiru //set user password

Set up user privileges, for later sudo accesses,

# pacman -S sudo
# EDITOR=nano visudo

and uncomment,

%wheel ALL=(ALL) ALL


Step 11 - Install some required packages.
Install display server and other packages related including sound. Choose the appropriate video driver when installing this,

# pacman -S xorg alsa-utils 

Step 12 - Install bootloader
Now we are almost done.Install a suitable bootloader like grub or syslinux,
Here I'm going to install syslinux,

# pacman -S syslinux gptfdisk mtools
# syslinux-install_update -i -a -m

See whether if the drive letters are correct in /mnt/boot/syslinux/syslinux.cfg, else manually edit them.

# nano /boot/systlinux/syslinux.cfg


Step 13 - Reboot
Exit from chroot, unmount drives and reboot.

# exit
# umount /dev/sdxa
# umount /dev/sdxb
# reboot

Step 14 - Boot and log in.
Now you can boot and login to your system.



Step 15 - Install a desktop environment.
Now you can install any window manager or desktop environment you like. There are plenty of window managers and desktop environments for Arch Linux. Almost every desktop environment you see in other distributions is there. Let's try installing KDE-5.

# pacman -S plasma kmix

Configure network manager and add USB modem support if you want,

# pacman -S usb_modeswitch modemmanger mobile-broadband-provider-info
# systemctl enable NetworkManager
# systemctl enable ModemManager

Step 16 - Set up a login manager.
It is better if you install a suitable display manager for the desktop environment you installed. There are plenty of display managers around. LXDM is a lightweight one. To install LXDM and enable it on system startup,

# pacman -S lxdm
# systemctl enable lxdm

Step 17 - Change system name.
To change the system hostname use,

# hostnamectl set-hostname --static archlinux

Step 18 - Reboot.
Reboot your system and enjoy. Configure it as you want.

Sunday, March 22, 2015

Busybox based Tiny Linux

This bash scripts download Linux and Busybox, compile, combine and make a Linux operating system, that runs a shell.

To run scripts,

$ git clone https://github.com/lpsandaruwan/BBTL.git && cd BBTL
$ sh bbtl.sh


kernel.sh 

This script downloads the Linux kernel and compiles it. The default option is to make a minimal Linux kernel. If you want more options, change line 13,  make tinyconfig

Follow this, http://www.tldp.org/HOWTO/SCSI-2.4-HOWTO/kconfig.html


busybox.sh

Here script is configured to build the busybox binaries as static with no shared libraries. You can also change the busybox configuration if you need more options.


GIT: https://github.com/lpsandaruwan/BBTL



Thursday, March 12, 2015

Analyze Linux kernel crashes using kdump

A kernel panic is an action taken by the operating system when fatal errors occur in the kernel. Hardware failures or software bugs are the main reasons cause that kind of errors. To see what happened inside the kernel and to debug or analyze those kernel panic issues and crashes, there are some tools and mechanisms, kdump is one of them.

kdump can dump and save the machine memory content on kernel crash to a specified location, to a disk or to a machine connected over a network. It is based on kexec which gives the facility to the boot another kernel without rebooting the computer or without going through bios. When a kernel panic or a crash occurs kernel crash handler boots the dump capture kernel using kexec and gives the ability to get access to memory image of the crashed system kernel through vmcore and to save it.

To use this,

1. Install kexec-tools
$ wget http://kernel.org/pub/linux/utils/kernel/kexec/kexec-tools.tar.gz
$ tar xvpzf kexec-tools.tar.gz
$ ls -d kexec-tools-* #to check the VERSION number 
$ cd kexec-tools-VERSION
$ ./configure
$ make
$ sudo make install

2. Dump-capture kernel
There are two methods of using kdump.
a) Build a separate custom dump-capture kernel
b) Use system kernel binary itself as dump-capture-kernel
Most operating systems has the kdump packages installed by default. However to build system/dump capture kernel, in the kernel config file, following options should be enabled.

CONFIG_KEXEC=y
CONFIG_CRASH_DUMP=y
CONFIG_PROC_VMCORE=y

3. Setup kdump kernel
For dump capture kernel, some memory should be reserved. To do that boot need to be edited. In boot loader configuration file, crashkernel=512M-2G:64M, 2G-:128M line to the system kernel. This means, if ram is below 512mb reserve no space, if ram is in range 512mb to 2gb reserve 64mb and ram is greater than 2gb reserve 128mb for the dump-capture kernel.

a) syslinux(/boot/syslinux/syslinux.cfg)
APPEND root=/dev/sdx crashkernel=512M-2G:64M, 2G-:128M

b) grub(/boot/grub/grub.conf)
linux /vmlinuz-3.x.x.x ro root=dev/sdx crashkernel=512M-2G:64M, 2G-:128M

4. Configure the kdump.conf file and enable the kdump service
There is a description in this /etc/kdump.conf file itself, kdump can be configured as per user's needs. Enable the kdump service and reboot the system.

$ sudo systemctl enable kdump.service

5. Test kdump
To check whether the kdump service is running,

$ systemctl status kdump.service

Linux kernel has a feature to crash the kernel immediately for testing purposes. To do this switch user to root and,

# echo 1 > /proc/sys/kernel/sysrq
# echo c > /proc/sysrq-trigger

After the kdump process, the crash can be analyzed using the captured dump file using a suitable tool.

Sunday, March 1, 2015

About me

I have been working at Mubasher Financial Services Development Center, Sri Lanka until 2016 as a software engineer and finished my studies from (BSc in Computer Science)University of Colombo School of Computing. I am a dedicated person who likes to work for my goals and stay independent. I am heavily interested in OpenSource and always looking forward to supporting the OpenSource community more and more.

Lahiru Sandaruwan Pathirage
lpsandaruwan@gmail.com github.com/lpsandaruwan

Please note that I am no longer a contributor to this blog and, I moved to GitHub pages<http://lahiru.site>.