Tag Archive : linux

/ linux

PostgreSQL, often simply “Postgres”, is an object-relational database management system (ORDBMS) with an emphasis on extensibility and standards-compliance. With more than 15 years of development history, it is quickly becoming the de facto database for enterprise level open source solutions.

In this article we will discuss about how to install PostgreSQL from source on Slackware64. Our objective is to make PostgreSQL installed and running on our machine.

The PostgreSQL we will use is the PostgreSQL 9.3.5

Obtain Material

The PostgreSQL is freely distributed under open source flag. You can go to PostgreSQL download page to obtain the source code. For version 9.3.5, we can download directly from here.

Installation

Extract the source code and go to that directory.

tar -jxf postgresql-9.3.5.tar.bz2
cd postgresql-9.3.5

Installation is using usual procedure in unix family: configure, make, install. Note that we are using /usr/local as our installation directory (where the PostgreSQL will reside). You can change it to anything you like. Root privileges is not necessary for compilation process, however it is need to install it to our directory /usr/local. If you choose to install it to non-root privileged area, you can drop the “su -c” thing.

./configure --prefix=/usr/local
make -j4
su -c "make install"

At this point, PostgreSQL is installed, but can’t yet be operational. Let’s do configuration.

Configuration

PostgreSQL User Account

We need a “postgres” user and group prior to building PostgreSQL. Do this using root privilege.

groupadd postgres
useradd -d /var/lib/pgsql postgres
passwd postgres

PostgreSQL Data Directory

Now we need to create PostgreSQL data directory if not exist. The data directory should be owned by postgres user.

mkdir /var/lib/pgsql/data
chown -Rf postgres:postgres /var/lib/pgsql

Initialize the directory. Before we can start creating any PostgreSQL database, the empty directory created above should be initialized.

su - postgres
/usr/bin/initdb -D /var/lib/pgsql/data

Next, validate the PostgreSQL data directory. Make sure all Postgres DB configuration file are created under the data directory.

Start PostgreSQL database. There are two ways to do it: using postmaster to do it, or invoking script.

/usr/bin/postmaster -D /var/lib/pgsql/data

or

/etc/rc.d/rc/postgres start

PostgreSQL Service

To make PostgreSQL run as service, we should make the init script executable.

chmod +x /etc/rc.d/rc.postgres

First Login

Let’s try our fresh build PostgreSQL.

psql -U postgres

where postgres is user account we have created before.

Installing OpenMPI from Source for Slackware64

December 11, 2015 | Article | No Comments

The Open MPI Project is an open source Message Passing Interface (MPI) implementation that is developed and maintained by a consortium of academic, research, and industry partners.

Message Passing Interface itself is a system designed by a group of researchers from academica and industry to function on a wide variety in parallel computers.The standard defines the syntax and semantics of a core routines useful to a wide range of users writing protable message-passing programs in Fortran77 or the C programming language.

This article will cover about compiling and installing latest OpenMPI for Linux Slackware64.

Obtain the Materials

The latest version (per May 23th, 2014) is 1.8.1. To build the program we need the source code. Download it from OpenMPI site or direct download from here.

Installation

Assuming we have downloaded the source code, we then extract and do compilation process:

tar -xvfj openmpi-1.8.1.tar.bz2
cd openmpi-1.8.1
./configure CFLAGS=-m64 CXXFLAGS=-m64 --with-wrapper-cflags=-m64 --with-wrapper-cxxflags=-m64
make

The flags we passed to configure script is used to ensure the -m64 flag to gcc and g++ during the build phase and also that mpicc wrapper knows to use -m64 when it compiles our code later.

Next we install it once the compilation process is successful.

make install

To check whether you have successfully install openmpi, invoke this command on terminal:

mpicc --version

Testing

Now let’s make a simple MPI application. Copy this source code and name it as mpi.c:

#include <mpi.h>
#include <stdio.h>

int main(int argc, char** argv) {
   int size, rank;
   MPI_Init(&argc, &argv);
   MPI_Comm_size(MPI_COMM_WORLD, &size);
   MPI_Comm_rank(MPI_COMM_WORLD, &rank);

   printf("Hello world from %d of %d\n", rank, size);

   MPI_Finalize();
}

Compile it using:

mpicc -o my_mpi mpi.c

There is a special way to run MPI program. In general, we do like this:

mpirun <program name> <list of arguments>

Thus, to run our program we invoke:

mpirun my_mpi

Watch it and note the result 😉

One of the problem with Windows Operating System is the narrow-range variety of available filesystem. When using Windows, you are limited to FAT and NTFS family file system. Now, suppose you want to access ext3, reiserfs, or XFS partition on Windows there is no way Windows facilitate this unless you do something. This article will describe the step for doing it using coLinux as tool.

In this article I use following:

  1. Windows 7 32-bit
  2. coLinux 0.7.9
  3. Ubuntu Image 9.04

Note: when this article written (18 January 2014) coLinux can only be used on 32-bit Windows!!

You can try any 32-bit Windows (Vista, 7, 8) but the system tested here is Windows 7 32-bit.

There are some alternative to Ubuntu: Alpine,Debian, Fedora, Gentoo, ArchLinux, Slackware. All of them use kernel 2.6. As the reason for using 9.04 is personal, you can use higher version available.

The Idea Behind

coLinux or cooperative Linux, is a free and open source Linux kernel running on Windows natively. We can say the linux kernel is run alongside Windows on single machine, like a virtual machine does. However the difference is we don’t emulate a machine to do this instead we run the linux kernel itself. Thus it is theoretically much more optimal than using any general purpose PC virtualization software.

So in general, we will do following scenario:

  1. install coLinux on Windows machine
  2. Assure access to disk partition
  3. Export all the mounted file system using samba

Much of the process will use command line interface (cmd.exe) which you should open using administration privilege.

Installation Step

coLinux can be obtained freely from their official site, or go to sourceforge site to download it. The version used here is 0.7.9-linux2.6.33.7. Download the installer and install it in C:\coLinux directory.

Edit the connection settings of the virtual ethernet card installed by the coLinux (It should be listed as “TAP Win32 Adapter V8 (coLinux)”). In the TCP/IP settings, set: IP address to 192.168.37.10 and Subnet Mask to 255.255.255.0

Download Ubuntu 9.04 disk image from sourceforge (listed as Ubuntu-9.04-1gb.7z). Extract the image file (Ubuntu-9.04.ext3.1gb.fs) to C:\coLinux. Note that you should have 7zip to extract this file. Now create a swap (for example 128MB swap) using following command on coLinux:

fsutil file createnew c:\coLinux\swap128.fs 134217728

You should know where the magic number comes 😉

Also make sure you run mkswap in Linux and make sure there is corresponding line in fstab.

Rename the file Ubuntu-9.04.ext3.1gb.fs to ubuntu.fs so we have two files: ubuntu.fs and swap128.fs.

Copy the example.conf to ubuntu.conf and edit it. Alternatively you can copy this text and save it as ubuntu.conf.

#
# This is an example for a configuration file that can
# be passed to colinux-daemon in this manner:
#
#    colinux-daemon @example.conf
#
# Note that you can still prepend or append configuration and 
# boot parameters before and after '@', or you can use more 
# that one '@ to load several settings one after another.
# 
#    colinux-daemon @example.conf @overrider.conf mem=32
#
# Full list of config params is listed in colinux-daemon.txt.

# The default kernel
kernel=vmlinux

# File contains the root file system.
# Download and extract preconfigured file from SF "Images for 2.6".
cobd0="c:\coLinux\ubuntu.fs"

# Swap device, should be an empty file with 128..512MB.
cobd1="c:\coLinux\swap128.fs"

# Tell kernel the name of root device (mostly /dev/cobd0,
# /dev/cobd/0 on Gentoo)
# This parameter will be forward to Linux kernel.
root=/dev/cobd0

# Additional kernel parameters (ro = rootfs mount read only)
ro

# Initrd installs modules into the root file system.
# Need only on first boot.
initrd=initrd.gz

# Maximal memory for linux guest
mem=32

# Select console size, default is 80x25
#cocon=120x40

# Slirp for internet connection (outgoing)
# Inside running coLinux configure eth0 with this static settings:
# ipaddress 10.0.2.15   broadcast  10.0.2.255   netmask 255.255.255.0
# gateway   10.0.2.2    nameserver 10.0.2.3
eth0=slirp

# Tuntap as private network between guest and host on second linux device
eth1=tuntap

# Setup for serial device
#ttys0=COM1,"BAUD=115200 PARITY=n DATA=8 STOP=1 dtr=on rts=on"

# Run an application on colinux start (Sample Xming, a Xserver)
#exec0=C:\Programs\Xming\Xming.exe,":0 -clipboard -multiwindow -ac"

If you copy and edit from example.conf, there are lines you need to change. In the end you should make sure following entries exist:

cobd0=C:\coLinux\ubuntu.fs
cobd1=C:\coLinux\swap128.fs
mem=32
eth0=slirp
eth1=tuntap

Now create ubuntu-start.cmd with following content:

set COLINUX_CONSOLE_FONT=Lucida Console:12
set COLINUX_CONSOLE_EXIT_ON_DETACH=1
colinux-daemon.exe -t nt @ubuntu.conf

Then run ubuntu-start.cmd.

Next we do some configuration. Login as root with default password “root”. You can change the root password if you want.

Run the editor and edit /etc/network/interfaces. Add following:

auto eth1
iface eth1 inet static
address 192.168.37.20
network 192.168.37.0
netmask 255.255.255.0
broadcast 192.168.37.255

Bringing up the eth1 by

ifup eth1

Test the network by pinging from our Linux to Windows. It should work now.

ping 192.168.37.10

Next we do update to install necessary package.

aptitude update
aptitude safe-upgrade
aptitude install samba openssh-server mc
apt-get clean

Open /etc/fuse.conf and remove # at the beginning of the line user_allow_other

Open /etc/ssh/sshd_config and change PermitRootLogin to “no”

Add new user named user1 (or any name you wish) and next we can login to this account via ssh:

adduser user1

But first, we need to reload the SSH server:

/et/init.d/ssh reload

At this point, use SSH client such as putty to check whether you can login to Linux via SSH.

Mount File System

First, search for the partition you want to mount. Let’ say it is \Device\Harddisk1\Partition4

If you have ran ubuntu-start.cmd (the system is running) then halt it before going further.

Edit ubuntu.conf and insert following:

cobd2="\Device\Harddisk1\Partition4"

Then run ubuntu-start.cmd (or halt the previous machine and restart it). Then login as root.

Do following to create a mount point:

mkdir /media/codb2

Then edit /etc/fstab and add following line (assuming my partition is xfs):

/dev/codb2 /media/codb2 xfs defaults 0 0

Then mount it like usual.

mount /media/cobd2

Share via Samba

Give user1 the appropriate privilege. If you want to share a whole file system with user1, you must give read and write permissions.

After setting permission, add the following at the very end of /etc/samba/smb.conf

[my data]
path = /media/cobd2
valid users = user1
read only = no

Next add the user to the password’s database of samba:

smbpasswd -a user1

Then reload the samba

/etc/init.d/samba reload

On Windows, type \\192.168.37.20 and login as user1 using the password generated by smbpasswd.

File Transfer Protocol (FTP) is a standard network protocol used for transferring files from one host to another host over a TCP-based network. The party involving two side: server and client, in other words it use client-server architecture. One famous FTP server is VSFTPD (Very Secure FTP Daemon).

In this article we will discuss about how to install VSFTPD to Arch Linux ARM, one of Linux distribution for ARM processor. Specifically, I use:

  1. Raspberry Pi model B, for machine
  2. Arch Linux ARM release 2013-07-22

Before we started, make sure you have installed Arch Linux ARM on your device.

Update the Repository

It is a good choice to update the repository as Arch Linux release new package periodically without save the old package. Arch Linux ARM use the very same package manager system like its parent uses. Therefore the command should be similar.

Make sure you have setup the Arch Linux ARM Repository.

To update the repository, do following:

pacman -Syy

Make sure your device can access the internet.

Installation

Installing vsftpd is really straightforward. We can install vsftpd from the Official Repositories by:

pacman -S vsftpd

Package manager will download the required package, depends on your connection. It will also install it automatically once the package are downloaded.

Start / Enable Server

We can enable server, which means the server started everytime we boot the device. Arch Linux use systemd, so to make it run automatically at boot time, do following:

systemctl enable vsftpd.service

While you can make it disabled / not run automatically by:

systemctl disable vsftpd.service

To start it manually, do:

systemctl start vsftpd.service

We can stop the service by:

systemctl stop vsftpd.service

Mounting Partition from Raw Disk Image on Linux

December 11, 2015 | Article | No Comments

In Linux/Unix or perhaps in every computer system, a term mounting is defined as attaching additional filesystem to the currently accessible filesystem of a computer. As we know, a filesystem is hierarchy of directories (also referred to as a directory tree) that is used to organize files on a computer or storage media.

We might familiar or maybe remember how to mount a partition well. But that’s when the partition is inside a storage media or physical medium. What if the partition we want to access is in form of disk image? Here, we will discuss it.

In this article I use:

  1. Slackware64 14.0
  2. dumped image from 4GB SD-card, using dd

The Theory

Disk Image

A disk image is a single file or storage device containing the complete contents and structure representing a data storage medium or device, such as hard drive, tape drive, floppy disk, optical disc, or USB flash drive. A disk image is usually created by creating a complete sector-by-sector copy of the source medium and thereby perfect replicating the structure and contents of a storage device.

In Linux, we can create disk image using dd utility. Assuming we want to create disk image of a SD-card which is recognized as /dev/sdb as MyDiskImage.img:

dd if=/dev/sdb of=MyDiskImage.img

Partition and Partition Table

As said, disk image is perfect copy of a storage media. Therefore we got very same bit of partition and partition table. Nothing is modified, unless you alter it. Therefore, we can still read the partition table like what we do on physical storage medium.

We can use fdisk to see the partition table of a disk image:

fdisk MyDiskImage.img

Loopback Device

We know that Linux and Unix list all recognized device as device nodes. They are treated like ordinary file and stored on /dev, like /dev/sda for first SCSI storage device we have. However, not many of us know some pseudo-devices on this directory. One of them is loop device /dev/loop*.

This is special node that we will use for mounting an image.

How to Mount

There are some steps we have to do so we can mount a partition inside of disk image.

Know the Offset

We have to know where is the offset of partition. Clearly we need to know where the partition start and where the partition end. Although, we only need the offset of beginning of the partition. To do that, we can use fdisk to peek on partition table. For example:

fdisk MyDiskImage.img

Here’s how my partition looks like.

Disk MyDiskImage.img: 691 MB, 691798016 bytes
255 heads, 63 sectors/track, 84 cylinders, total 1351168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0002c262

                         Device Boot      Start         End      Blocks   Id  System
2013-09-25-wheezy-raspbian.img1            8192      122879       57344    c  W95 FAT32 (LBA)
2013-09-25-wheezy-raspbian.img2          122880     5785599     2831360   83  Linux

What we want to know is the offset, which is in byte-level. However fdisk tell us about sectors. Fortunately we can convert the offset in sector to bytes by multiplying it with the size of sector. In our case, one sector is 512 bytes.

Let say we want to mount partition 2, which is ext4. We calculate the offset for this partition.

122880 * 512 = 62914560

Save this value.

Mount It!

The actual mounting. Mounting process is similar when we mount normal partition. However, this time we use loopback device and use one argument we never use before, “offset”. Basically, offset tell mount utility to skip the data on particular to offset.

Here how we do:

mount -o loop,offset=62914560 MyDiskImage.img /mnt/mount_point

Here we mount partition 2, which is located on 62914560 bytes after the beginning of the file. The partition should be mounted to our mount point (/mnt/mount_point). Unless you have an unknown filesystem, this command shouldn’t be fail.

This is short notes on how I create a dual boot machine with Windows 8 and Slackware64. Both are 64-bit operating system and will be installed on UEFI-based computer with GPT disk layout.

Actually I do this around in earlier year 2013, so this article might not up to date. However it should work because we use general method.

In this article, i use:

  1. Microsoft Windows 8 64-bit, installation disc
  2. Slackware64 14.0, installation disc
  3. Lenovo Ideapad Z480
  4. USB disk

Note that I do the scenario (would be) mentioned because my machine is fresh and I will do it from scratch.

About Machine

Lenovo Ideapad Z480 has following specification (main):

  1. Intel Core i7-3632QM
  2. RAM 4 GB
  3. HDD 1TB
  4. Video RAM NVidia GeForce GT640

However, I also give addition to RAM so in result I have 8GB RAM.

At default, it is not using UEFI so I activated UEFI capability.

I also convert the disk format from MBR to GPT, however I do this later.

General Overview

The problem arise before me is the fact that the Windows 8 installation DVD not support UEFI yet. Therefore I cannot boot the DVD in UEFI.And also, Windows 8 cannot be installed on GPT disk, yet. At that time Slackware also does not support UEFI, yet. But, it can be installed in GPT partition, good thing to know. Therefore I need a bootable USB disk to boot Slackware then create everything I need for installing Linux.

The scenario in this article:

  1. Create partition
  2. Install Windows 8 while the disk still use MBR layout.
  3. Install Slackware64 14.0 with GPT disk
  4. Finalizing, installing and configuring bootloader

Preparation

I use a companion Linux in bootable USB stick. I create a USB stick with UEFI capable. You can download it from here.

Make a partition for USB stick with FAT32 partition and boot flag enabled. You can use either gparted or gdisk (in Linux) to accomplish it.

Just extract what inside the archive to USB stick. Make sure there are two folders: EFI and Slackware64.

Step 1: Create Partition

Boot the machine using Windows installer DVD. I need to create a partition for MBR disk. In my case I create these primary partitions:

  1. boot partition, located on partition 1 with FAT32 file system, takes about 100MB.
  2. Reserved partition, used by Windows, create it for 350MB capacity.
  3. Windows partition, NTFS, I use 100GB
  4. Linux Partition, unallocated, I use 100GB

Those are the partition I need at the moment. The rest will be create at finalizing stage.

Here, once the Windows 8 installation DVD is booted, do normal installation routine. Once we got on media selection (where we install Windows), press [Shift] + F10. This will bring command prompt. Invoke following command:

diskpart

Now we will do partitioning. I’m using only one disk, so the disk should be recognized as disk 0. Also, I don’t use GPT at this section, it would be after installation of Windows 8.

select disk 0
clean

create partition primary size=100
format quick fs=fat32 label="System"

create partition msr size=350
format quick fs=ntfs

create partition primary size=100000
format quick fs=ntfs

create partition primary size=100000

Step 2: Installing Windows 8

Still using Windows 8 installation DVD, exit the command prompt. Now I’m refreshing the list so we will know all of the partition available.

I continue installing Windows like usual on partition 3.

Once the installation finish, go to step 3.

Step 3: Installing Slackware64

I need to do some preparation first. Therefore, there would be some subsections for this.

Convert MBR to GPT

Boot the USB stick.

Conversion is inherently risky. For safety, I backup the original configuration before converting the disk. The MBR itself is stored on the first sector of the disk and can be backed up with dd by:

dd if=/dev/sda of=backup.mbr bs=512 count=1

Then I run gdisk for disk on /dev/sda

gdisk /dev/sda

Follow the option menu for conversion MBR to GPT, and I done.

Prepare the Installation Environment

Mount the USB stick. I accomplish this by invoking following command:

mkdir /src
mount /dev/sdb1 /src

Invoke setup and adjust the setting like normal installation until you reach installation media stage.

Press ALT+F2 to switch to another screen (or another tty).

Install temporary system using USB stick. Invoke these commands:

cd /src/slackware64
installpkg -root /mnt [az]*/* cd

Installation

Now, back to our main setup and choose install from CD/DVD. Also, I won’t use LILO, instead I use ELILO. So I don’t install LILO.

After installation is finished, I don’t restart the machine immediately. Instead, I go to last step: Finalizing.

Step 4: Finalizing

First, make sure we are still boot the machine using USB stick, then load following command:

modprobe efivars

Also, I need to mount the boot partition

mount /dev/sda1 /mnt/boot/efi

Add Bootstrap to Slackware

I invoke following command. Note that these commands should be invoked as is, even a dot matters. If you remember, the Slackware is installed on 4th partition.

mount /dev/sda4 /mnt/root
cd /mnt/boot/efi
cp -rvf /src/EFI /mnt/boot/efi
cd /mnt/boot/efi/EFI
mv BOOT Slackware
cd Slackware
mv bootx64.efi elilo.efi
cp /mnt/root/boot/vmlinuz-huge-3.2.29 .
vi elilo.conf

And I configure the elilo.conf:

prompt
image = vmlinuz-huge-3.2.29
label = Slackware
root = /dev/sda4

And register boot so that machine can boot Slackware.

cd /mnt
usr/bin/efibootmgr -c -L "XathryaSlackBoot" -l "\\EFI\\Slackware\\elilo.efi"

Add Bootstrap to Windows

Eject the Slackware installation disc and insert Windows 8 installation disc. I need to copy all files needed to boot EFI from Windows 8 disc.

cd /mnt/boot/efi
mkdir /mnt/disc
mount /dev/sd1 /mnt/disc
cp -R /mnt/disc/efi/microsoft /mnt/boot/efi

That will copy “microsoft” folder and whole of it’s content to /mnt/boot/efi (which is my mounted efi boot partition).

Now, to create a bootstrap we first need to restart the machine and boot with Windows 8 installation DVD. What we will do is repair the Windows 8 EFI bootloader.

I do normal installation sequence method until I was prompted with list of volumes / partitions. Now press [Shift] + F10. A new command prompt appear.

Now invoke following command, which will bring me to diskpart (disk partition) program:

diskpart

My disk is only one, so I will use disk 0.

sel disk 0

Because the EFI partition is the very first partition (/dev/sda1), it should be registered as earlier volume. However, it doesn’t have drive letter, so I will give it one.

diskpart

sel vol 1
assign letter b:

The attempt is successful and I’m prompted by a message which tell me that the volume has been assign to letter B. Now leave the diskpart with exit command. Go to the EFI partition and add the EFI bootstrap.

cd /d b:\EFI\Microsoft\Boot\
bootrec /fixboot
ren BCD BCD.bak
bcdboot C:\Windows /l en-us /s B: /f ALL

bootrec (boot recover) will fix the UEFI bootloader.

bcdboot will be used to recreate BCD store. The C:\Windows is path where Windows is installed and B: is drive of my EFI partition. The “/f ALL” parameter updates the BIOS settings including UEFI firmware/NVRAM while /l en-us is to localize for US locale (US English).

Add More Partitions

I need more partitions so I create them. I use gdisk for this.

How to Set Up Repoforge Repository

December 9, 2015 | Article | 2 Comments

Repoforge, previously known as RPMforge, maintains a repository of RPM packages for Red Hat Enterprise Linux (RHEL), CentOS and Scientific Linux. If you are a RHEL or CentOS user, it is strongly recommended to set up Repoforge repository on your system, as it contains many useful software packages that are not available in existing stock repositories.

The configuration of Repoforge is not so difficult. Here in this article we will try to do it.

In this article, we will use CentOS 6.3 as example machine.

Installation

In order to enable Repoforge repository on your CentOS system, you need to check CentOS version. Though we said earlier that we use CentOS 6.3, you can also check your CentOS version by running the following command.

cat /etc/redhat-release

You should also check your architecture, whether 32-bit (i.e., i686) or 64-bit (i.e., x86_64) based:

uname -a

The configuration would depend on your version.

For 32-bit CentOS 6.*:

sudo rpm -Uvh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.i686.rpm

For 64-bit CentOS 6.*:

sudo rpm -Uvh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm

For 32-bit CentOS 5.*:

sudo rpm -Uvh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el5.rf.i386.rpm

For 64-bit CentOS 5.*:

sudo rpm -Uvh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el5.rf.x86_64.rpm

Verification

Once repoforge ins installed, you can use yum to install all available packages from the repoforge repo.

How to Set Up EPEL Repository

December 9, 2015 | Article | 1 Comment

EPEL, Extra Packages for Enterprise Linux, a Fedora Special Interest Group that creates, maintains, and manages a high quality set of additional packages for Enterprise Linux, including, but not limited to, Red Hat Enterprise Linux (RHEL), CentOS and Scientific Linux (SL). The project was started because many Fedora contributors wanted to use the Fedora packages they maintain on Red Hat Enterprise Linux (RHEL) and its compatible derivatives.

The configuration of EPEL is not so difficult. Here in this article we will try to do it.

Configuring EPEL is strongly recommended if you are using RHEL or its derivatives (CentOS, Fedora, Scientific Linux, etc). Once you set up EPEL repository, you can use yum command to install any of close to 7,000 EPEL packages.

In this article, we will use CentOS 6.3 as example machine.

Installation

In order to enable EPEL repository on your CentOS system, you need to check CentOS version. Though we said earlier that we use CentOS 6.3, you can also check your CentOS version by running the following command.

cat /etc/redhat-release

The configuration would depend on your version.

For CentOS 6.*:

sudo rpm -Uvh http://mirrors.kernel.org/fedora-epel/6/i386/epel-release-6-8.noarch.rpm

For CentOS 5.*:

sudo rpm -Uvh http://mirrors.kernel.org/fedora-epel/5/i386/epel-release-5-4.noarch.rpm

Verification

To verify that EPEL yum repository has been set up successfully, run the following command to list all available repositories on your system.

yum repolist

And you should see the list like this:

repo id            repo name                                              status
base               CentOS-6 - Base                                        4,776
epel               Extra Packages for Enterprise Linux 6 - i386           6,913
extras             CentOS-6 - Extras                                         17
updates            CentOS-6 - Updates                                       960
repolist: 12,666

And you have done it.

Introduction to User-Mode Linux

December 9, 2015 | Article | No Comments

If you are practicing for network engineering, there are many options to setup your own virtual network lab. GNS3, Netkit, Marionnet, VNUML, just name a few. All of those tools are great way to setup network lab. They are great for learning how to build network and practice various network topology in easier way. Yes, they are not low level. They keep us from customizing our linux node used in network lab. If we want true network with various setting and configuration, then we need dive deeper.

So imagine I want some nodes with different configuration. All configuration files (including the ones for the virtual hosts) are kept into one subdirectory and able to be modified while the lab was running. The node should start in few seconds. Is it possible? Well, let’s discuss User-Mode Linux. Well, it’s not fancy solution like other tools are. More like a home-made solution to match some of things you need.

User-Mode Linux, as hinted by the name, is a linux kernel that run as a process on another GNU/Linux operating system. It is a secure way of running Linux as a process. We can call it as type of virtualization but has different approach compared to VirtualBox or VMWare. It is closed to containerization but not the same. We run buggy software, experiments with new Linux kernels or distributions, and poke around in the inernals of Linux, all without risking main Linux.

User-Mode Linux and Virtualization Technology

Technology-wised, there are two types of virtualization technologies. They are full-virtualization and containerization, both offers some advantages over the other. The full virtualization, as in VirtualBox, VMWare, Xen, create a virtual resources or emulate physical platforms from CPU to the peripherals in which Linux will run. The containers, as in chroot, jail, docker, rkt, are sharing the same OS kernel as the hosts and run in some kind of isolation.

UML is closely related to the containers. However, UML itself is a fully functional Linux running as a process, make it different to containers. In the perspective of host, UML is like another process, running and ask for resources. From the perspective of UML, it is a kernel and give services to its processes. The UML itself is a modified copy of Linux kernel. Therefore, we can say that UML is a kernel as well as a userspace program in the same time.

Grab the Materials

There are two components of UML: the kernel and the filesystem. The kernel is the vital part. You can obtain the kernel here: http://uml.devloop.org.uk/

That links provide a kernel up to certain version. All are available in 32-bit and 64-bit architecture.

You can download a filesystem on here: http://fs.devloop.org.uk/

For this article, I will use Kernel version 3.11.2 64-bit and file system Slackware 12.x 64-bit.

We can create our own UML and filesystem, but that’s for another time.

Extract the kernel and filesystem. Here I have:

  1. kernel64-3.11.2
  2. Slamd64-12.1-root_fs

For the sake of simplicity, I will refer the kernel64 for the kernel we use and slamd64 for the filesystem.

First Boot

Let’s head to kernel first. Check and run the kernel:

chmod +x kernel64
./kernel64 mem=512M

It is quite straightforward. I run kernel and having virtual RAM about 512MB. Don’t worry if you encounter a kernel panic. It’s fair to assume that we didn’t specify any root filesystem (and that’s right). Now, let’s boot UML in proper way. This time, we will boot kernel and specify a filesystem.

./kernel64 ubda=Slamd64 mem=512M

Now you can see the familiar login prompt on your terminal.

Add a Network Support

To add network capability to UML node, we have to create a new TAP interface. We should allocate the TAP device to UML instance. Here, on you host Linux:

tunctl -t tap0

tap0 is the device name of our new interface.

Next, assign an IP address to it, assuming the IP address is 192.168.135.1 and on 192.168.135.0/24 network. Of course you need to adjust it to your network.

ifconfig tap0 192.168.1.1

Then modify the kernel invocation, by:

./kernel64 ubda=Slamd64 mem=512M eth0=tuntap,tap0,MAC_ADDR,IP_ADDR con0=fd:0,fd:1

There is also an option to utilizing DHCP daemon on the host to gives IP automatically to UML nodes. For example we use dhcpd for DHCP daemon. Create a DHCP configuration file in ~/dhcp.conf. Let’s say we want to create network 192.168.135.0/24

default-lease-time 6000;
max-lease-time 72000;
option domain-name-servers 192.168.135.1;
option routers 192.168.135.1;
server-name "192.168.135.1";
ddns-update-style none;
subnet  192.168.135.0  netmask  255.255.255.0  {
   range 192.168.135.2 192.168.135.254;
}

Our DNS might not be 192.168.135.1 so we should make it to the real DNS server.

Start the DHCP server on tap interface.

dhcpd -cf ~/dhcpd.conf tap0

and then modify kernel command line to give UML access to this new network interface.

Add Routing

The previous section should allow communication between the host and the guest (UML node). In order for the guest to reach the outside world we must configure the routing table. It means we need to tell the host to route the packets coming to/from the guest. It can be achieved by modifying firewall rules. However the very first thing to do is to make sure host is allowed to forward packets.

Execute following command.

echo 1 > /proc/sys/net/ipv4/ip_forward

Then add firewall rules.

iptables -t nat -I POSTROUTING -o eth0 -j MASQUERADE
iptables -I FORWARD -i tap0 -j ACCEPT
iptables -I FORWARD -o tap0 -j ACCEPT

In the next occasion, we will discussing some labs for UML.

Linux Kernel Installation

December 9, 2015 | Article | No Comments

Installation of Linux Kernel image is divided into two step. First step deals with the installation of kernel modules and static vmlinuz (kernel image). The way to do it is copying the static vmlinuz and all loadable kernel modules to their appropriate locations. The second step deals with the modification of the boot loader configuration file (GRUB, LILO, etc).

Installing Image and Modules

The ‘make’ command builds all the loadable kernel modules in some temporary directory. All we need to do is copying all those modules to the correct location. The location would be same whether you are in 32-bit system or 64-bit system (at least for now). In our case, it would be /lib/modules/<kernel version>/.

However, one can ignore copying these manually and use a command to do it. The process can be automated by simply calling a command from make. Of course you need to do it in the end of compilation on certain kernel (on the root directory tree).

make modules_install

For installing the static kernel (i.e. vmlinuz), the image should be placed to a location where bootloader program can find and boot it. Usually it is /boot.

The process is also can be automated by giving command:

make install

The static image vmlinuz is copied from certain directory to /boot directory. To make it clear, compilation will compile kernel based on your processor architecture (or if you specify other processor) and store it on the corresponding root directory. For x86 and x86_64, the image will be created as $KERNELDIR/arch/i386/boot/vmlinuz.

Boot Loader Configuration

Remember the process of booting: BIOS -> Boot Loader -> Kernel -> Init.

Boot Loader is in the second step which will search the kernel images and boot it. Some boot loader will search for the kernel images in the /boot directory.

There are two popular bootloaders we use: GRUB (Grand Unified Bootloader) and LILO (Linux Loader).

Configuring Grub

The version we use is Grub2. To use grub2 to boot our new linux kernel, we need to edit grub configuration. However you are not necessary to edit the file manually. Just run the command to make grub update the list, with root privilege of course:

update-grub

Configuring LILO

Linux Loader is considered old but still used on several distribution.

To add new kernel image to LILO entry, you can use following template and modify it to your need. You should append it to LILO configuration file, which is /etc/lilo.conf:

image=/boot/vmlinuz
  label=linux
  read-only
  root=/dev/hda3
  initrd=/boot/initrd-2.4.2-2.img
  append=" resume=/dev/sda2"

So here is the explanation:

The image is vmlinuz which located on /boot directory.

The entry would be labeled as “linux”. You should make this unique.

The root file system is /dev/hda3. Make sure you have a kernel which can read the file system. Especially if your root file system is not usual such as XFS, ZFS, ReiserFS, etc.

The initial ramdisk is initrd-2.4.2-2.img which is located on /boot. You can ignore this if your kernel doesn’t need initial ramdisk.

Append is used to add several argument to kernel. On that entry, we add capability to hibernate and sleep. For that capability kernel need a swap partition to read and write a temporary data. Therefore we specify /dev/sda2 which is a swap partition.

Practical Sample

  1. Install Kernel on Ubuntu
  2. Step by Step of Linux Kernel Compilation

Social media & sharing icons powered by UltimatelySocial