Friday, October 2, 2015

Isolate System with Linux Namespace

Hi,

I am sharing this new post from one of the famous blogs. This is quite informative post. You will enjoy it. Have a look at the post here http://www.toptal.com/linux/separation-anxiety-isolating-your-system-with-linux-namespaces

Thanks

Saturday, December 4, 2010

Backup Old Kernel While updating kernel

Hi Guys,


I am here again with a new post. Its cool out today here. Its 17 degree C temperature outside and i am enjoying it while writing this blog post.

So, today i am going to tell you how you can secure your old kernel while upgrading to the new Kernel. In my previous post, i have mentioned how to update a kernel and in this post we will see how to retain old kernel while installing new one so that we can choose at boot time to boot in either of the kernel version.

Prerequisites:-
- An installed linux box/machine of any distribution
- Kernel Source of the latest version to update kernel

I am using Fedora 13 for this practical.

Steps to go:-

1) Goto the directory '/boot':
# cd /boot

2) Copy the 2 kernel files i.e. vmlinuz & initramfs or initrd into the same directory with a slightly different name.
Names of the file might look like this "vmlinuz-2.6.34.7-61.fc13.i686" and "initramfs-2.6.34.7-61.fc13.i686.img" or similar to that.

NOTE: This operation needs super user privileges.
# cp vmlinuz-2.6.34.7-61.fc13.i686 vmlinuz-2.6.34.7-61.old
# cp initramfs-2.6.34.7-61.fc13.i686.img initramfs-2.6.34.7-61.old.img

3) Now, Install the new kernel from source as we did in my previous post.
or from yum, you can do as:
# yum update kernel

4) Now, edit /etc/grub.conf
# vim /etc/grub.conf
title Fedora Old Kernel
root (hd0,1) # provide your root partition here
kernel /boot/vmlinuz-2.6.34.7-61.old
initrd /boot/initramfs-2.6.34.7-61.old.img
:wq
save and exit

5) Now, reboot check by booting in the old kernel......DONE

Enjoy booting 2 kernels.....:)

Monday, November 29, 2010

Installing New Kernel from source

Hi Guys,

Today, i am going to discuss a very important aspect of the Operating System that is KERNEL. Kernel is the Core of any Operating System which interacts with the Hardware. Linux kernel is updated on a regular basis. Right now the latest kernel stable release is 2.6.36.1. I will be using this kernel only for this short tutorial.

You can download the kernel source files from http://kernel.org

So download a kernel source first according to your choice of version. I will be using stable kernel 2.6.36.1.

Prequisites:
- A ready Linux installed system (ANY LINUX)
- Kernel source tar balls

Steps to go:-

I will be building my kernel in my HOME directory since i am just trying it out.

1) Download Linux source first either from CLI or GUI as you wish. I will be using the CLI utility 'wget':
# wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.36.1.tar.bz2

2) Uncompress the source archive:
# tar jxvf linux-2.6.36.1.tar.bz2

3) cd into the directory linux-2.6.36.1. Now, we need to configure to select the features we want/need:

# make config

or
# make xconfig
(This is QT based X-Configurations)

or
# make menuconfig
(This is ncurses based)

or
# make gconfig
(This is GTK+ based X-Windows Configurations)

or
# make oldconfig
(This is used in case you want the previous kernel build configurations.)

4) Now building the kernel:
# make

NOTE: If you are using an old kernel like 2.4.x , then you need to build dependencies first using 'make dep'.

With the previous step it will have built both kernel (bzimage) and modules.
For Old Kernels like 2.4.x , you need to run 'make bzimage' and 'make modules'.

5) Now, Become root to install modules and kernel. Everything before can be done as a normal user. There is really no need to do above steps as a root user. Actually, root is a very powerful user. So a single mistake can ruin your system completely.

Install modules as:
# make modules_install

Install the new kernel as:
# make install

6) We are done here. But if in case, your new kernel entry doesn't appear in the GRUB MENU. Then, we have one more steps. Almost all linux distros, automatically edits the grub.conf file and makes the new entry for you. But if thats not a case then, you can do as follows to create a new grub entry:

# vim /etc/grub.conf
title Kernel-2.6.36.1
root (hd0,1)     # provide your root partition here
kernel /boot/vmlinuz-2.6.36.1
initrd /boot/initramfs-2.6.36.1.img
:wq
save and exit

7) DONE. Reboot and boot into the new kernel. Have fun......:)


NOTE:
If you're just trying out this procedure, do the unpacking and building in your home directory as discussed above. In a professional environment, though, the source would be stored in /usr/src or /usr/local/src, where compiling would also be done. To allow this, and at the same time avoid becoming root for the entire procedure, create a group "devel" (or whatever) and add yourself to that group. Then change the group owner of /usr/src to the new group and grant write privileges to the group.

That way you can unpack the kernel tarball into /usr/src (or whatever) and configure and build there without doing everything as root. Of course, you'll still need to sudo or become root when you install the new kernel and edit the grub configuration files.

Tuesday, November 23, 2010

Installing GRUB after Windows Installation

Hi guys,

I am here again with a new post. And this post is very demanding for any Linux home user because we use many OSes at home. These can be either Windows or Linux/Unix or any other. If a user installs Windows after Linux. Then, windows will write its boot-loader in MBR(Master Boot Record). So, now what the problem is, that you won't be able to boot in linux.

So, now to boot into linux you need the boot-loader. So, we will reinstall boot-loader grub in the MBR once again. This process is called "rescuing the broken system" or "Rescuing Grub".


I am using RHEL 5 in my case.

Prerequisites:

- Installation media CD/DVD containing Linux install image or USB or a server running DHCP server on network for PXE boot to start installation process
- A broken system (system without GRUB)

Steps to go:

1) Insert the boot media into the cd-rom (in case you have CD/DVD) else boot from USB or network. When the boot screen comes up, pass the parameter to boot in desired environment. Since we are trying to fix a broken system we will pass "linux rescue" as our parameter and press "enter".

# boot: linux rescue

2) Then, it will ask you for various things like keyboard layout and language, network interfaces to start or not etc and finally the rescue environment warning page will come up. Read that carefully.

Press "continue" it will start searching for your partition and mount it under "/mnt/sysimage" and drop you to a shell. Now do as:

# chroot /mnt/sysimage
-changing root environment to the broken system

3) Now, its time to run the command that fixes your system and installs grub:

# grub-install /dev/sda
- use "sda" for SATA disks and "hda" for IDE disks

or

Invoke Grub and use its command-line to fix as:
# grub
grub> find /etc/passwd
- this checks that on which partition this file exists, you will get the output something like "(hd0,1)" or may differ according to your partition scheme. So use yours. "hd0" means first harddisk and "1" means the second partition. If it is "0" in place of "1" then it will be first partition.

grub> root (hd0,1)

grub> setup (hd0)

grub> quit

# exit

4) Finished.....You are done....:)

Now boot into your linux and have fun......:)

Different Linux distros might have different ways to rescue. So read there help first. You can get key parameters to boot from the boot media help by pressing function keys(F1,F2,F3.......).

Wednesday, November 17, 2010

Implementing QUOTA (User quota and Group Quota)

Hi guys,

Today i am going to show you how to implement quota in LINUX. The quota is implemented for the two: users and groups.

I - IMPLEMENTING USER QUOTA

Steps to go:-

First of select a device where you want to set quota, i have created a device /dev/sda8 of 500MB for example:

1) Now, format the partition.
# mkfs.ext3 /dev/sda8

2) Create a mount point for the newly created device /dev/sda8
# mkdir /data

3) Now, checking mounting the device under /data. Can be done in 2 ways as we already discussed in previous posts. Mounting manually or making an entry in the file /etc/fstab for automounting.

# mount -t ext3 /dev/sda8 /data
 or make a an entry in the file /etc/fstab and do # mount -a

4) Now, finally start implementing quota for users. Edit the file "/etc/fstab" and make a new entry or edit the existing entry(if you made an entry for mounting device /dev/sda8) as follows:
# vim /etc/fstab
/dev/sda8     /data     defaults,usrquota     1 2
:wq
save and exit

5) Now, remount the device as:
# mount -o remount /data
# ls /data (just to check whether re-mounted correctly or not)

6) Now, check for existing user quota in the "/data".
# quotacheck -cu /data

7) Now, turning quota on, in the directory "/data"
# quotaon -vu /home

8) Setting quota now for a user "aman".
# setquota -u aman 100 200 0 0 /home

Here, 100 is the soft limit and 200 hard limit. The others 0s are the inode softlimit and inode hardlimit. You should read more about these limit by googling them.

9) Now, checking quota reports and see all existing quotas for the users.
# repquota -vu /data


NOTE: we have used the switch "-u" to represent that we are checking the for user quota.

10) DONE.....

Now, its time to check quota from the user for which quota is turned on.

Now, change to the other user "aman" as:
# su - aman

Now, run the following commands to check the quota:
# dd if=/dev/zero of=/data/quota1 bs=1k count=100
# dd if=/dev/zero of=/data/quota2 bs=1k count=150

NOTE: The first command will a warning but will make the file "quota1" in "/data" because soft limit is 100. But the second command will not make the file exceeding the hard limit 200.

II - IMPLEMENTING GROUP QUOTA

Group Quota is mostly similar to the User Quota. The thing is that its implemented for the users of a particular groups rather an individual user. For example: if we have some users as aman, gaurav, virender, pandey etc. belonging to a group named as "garv". Then, the quota we will set on this group, will be common for all these users belonging to the group "garv".

NOTE: I am using the same device for implementing group quota which i used for "user quota" i.e. /dev/sda8 or /data.

Steps to go:

1) Edit the file "/etc/fstab" and edit the line containing "/data":
# vim /etc/fstab
/dev/sda8     /data     defaults,usrquota,grpquota    1 2
:wq
save and exit

NOTE: That we have just added a new keyword "grpquota" to setup the group quota on the particular device.

2) Now, Remount the device once again.
# mount -o remount /data
# ls /data (just to check whether device successfully remounted or not)

3) Check for existing quota in "/data":
# quotacheck -cg /data

4) Turning on the group quota in "/data":
# quotaon -vg /data

5) Setting up the group quota for the group "garv":
# setquota -g garv 100 200 0 0 /data

NOTE: The limits are same as they were in user quota above. 100 is the soft limit and 200 is hard limit Rest 0s are inode softlimit and hardlimit.

6) Checking quota reports for groups:
# repquota -vg /data

NOTE: Here we used the switch "-g" to represent that we are checking for group quota not user quota.

7) DONE.......:)

Now, again we should check the quota from the user of the group for which quotas are being implemented. So switch to any user belonging to the group "garv".
# su - aman
or
# su - gaurav

Now, run the same commands as we did in user quota with the "dd"(disk dump) utility.

# dd if=/dev/zero of=/data/quota1 bs=1k count=100
# dd if=/dev/zero of=/data/quota2 bs=1k count=150


Enjoy....Implementing Quotas on your users.......:)

Sunday, November 14, 2010

Implementing RAID (Redundant Array Inexpensive Disk)

Hi Guys,

Today i am going to show you a very very important concept of the system administration called RAID. It is a very important thing for any system administrator.

RAID is actually used for fault tolerance. So, it has a very significant value for data because data is very important for any organisation whether it is big or small. RAID can be implemented in 2 ways: Hardware RAID and Software RAID.

Hardware RAID is implemented through the disk controller of the system. Instruction for configuring hardware RAID differs from controller to controller. So refer your disk controller manual for implementation.

We will be discussing the software RAID. Software RAID is implemented through the operating system and uses some processor and memory resources.

Different RAID levels are available with software RAID, so you can decide one is best for your needs. Software RAID allows for RAID levels 0, 1, 5 and 6.

RAID level 0, or striping, means that data is written across all hard drives in the array to accomplish the fast disk performance. No redundancy is used, so the size of the logical RAID drive is equal to the size of all the hard drives in the array. Because there is no redundancy, recovering data from a hard drive crash is not possible through RAID.

RAID level 1, or mirroring, means that all data is written to each disk in the array, accomplishing redundancy. The data is “mirrored” on a second drive. This allows for easy recovery should a disk fail. However, it does mean that, for example, if there are two disks in the array, the size for the logical disk is size of the smaller of the two disks because data must be mirrored to the second disk.

RAID level 5, combines striping and parity. Data is written across all disks as in RAID 0, but parity data is also written to one of the disks. Should a hard drive failure occur, this parity data can be used to recover the data from the failed drive, including while the data is being accessed and the drive is still missing from the array.

RAID level 6, RAID level 6 is RAID level 5 with dual parity. Data is written across all disks as in RAID 5, but two sets of parity data is calculated. Performance is slightly worse than RAID 5 because the extra parity data must be calculated and written to disk. RAID 5 allows for recovery using the parity data if only one drive in the array fails. Because of the dual parity, RAID 6 allows for recovery from the failure of up to two drives in the array.

SETTING UP THE RAID DEVICES:

Using Software RAID:

1) First, create partitions for the RAID, using fdisk same as we did for the LVM and set their partition type ID to "fd".

2) Now, creating RAID device, I have created 3 paritions sda5,sda6,sda7:

# mdadm --create /dev/md0 --level=5 --raid-devices=3 /dev/sda{5,6,7}
or
# mdadm --C /dev/md0 --l=5 -n=3 /dev/sda{5,6,7}

Here, the word "create" has a parameter "/dev/md0" which is a device name i am creating for RAID. Then, with "level", i am specifying the level of the RAID, I am trying to implement. And "raid-devices" is the number of devices or the number or parallel logical disks.

3) Now check the RAID status:
# cat /proc/mdstat
and
# mdadm --details /dev/md0

4) Formatting RAID device:
# mkfs.ext3 /dev/md0

5) Creating mount point for the RAID device:
# mkdir /tmp/RAID5

6) Mounting RAID:
# mount -t ext3 /dev/md0 /tmp/RAID0
or make a entry in the file "/etc/fstab" for automounting

7) DONE...:)

Enjoy....backing up of data with RAID.....:)

Friday, November 12, 2010

Implementing LVM (Logical Volume Management)

Hi Guys,

I am going to discuss a very very famous part of the LINUX called LVM (Logical Volume Management).

Before we start making LVM, lets learn some other basic things.
- To implement LVM we go step by step and make Physical Volume first.
- Then, we will make Volume Group.
- Then, finally the Logical Volume
- Logical Volume have the partition type ID "8e"

Similarly, swap has "82", raid has "fd", ntfs has "7", extended has "5", Linux has "83" etc etc.

Prerequistes:-

* A machine with a Linux Installation (In my case it is RHEL5)
* Free space on hard-disk to create the new partitions

Commands we will be using:
- pvcreate
- vgcreate
- lvcreate
- pvscan
- vgscan
- lvscan
- pvdisplay
- vgdisplay
- lvdisplay
- lvextend
- lvreduce
- resize2fs

So before reading further, please go through the manuals of these commands. So that you can be aware of the commands working.

I - ADD A LOGICAL PARTITION

Steps to go:-

1) Create new partition on the hard-disk with the command below:
# fdisk /dev/sda (in case if you have a SATA hard-disk)
or
# fdisk /dev/hda (in case if you have a IDE hard-disk)

press "m" now and read all the shortcuts now.

Now, press "n" to create a new partition. It will ask whether to create "primary partition" or "extended". If you already have 4 primary parition including 1 extended then it won't ask it and will directly create a logical partition in extended partition.

It will ask for first cylinder, keep it blank and press enter. Then, it will ask for last cylinder, put your partition size as "+1024M" (if specifying in MBs) or "+1G" (if specifying in GBs).

2) Now, change the partition ID. By default, every partition gets the partition ID as "83". So to change it press "t". "t" means toggle.

It will ask for the partition number of which ID has to be changed. Put the number of the newly created partition's number.

Then, it will ask the partition ID and put "8e" as the partition ID now.

3) Now, to write changes to the disk press "w". It will write changes to the disk and will automatically quit the program "fdisk".

4) Now, run the program "partprobe" to send information to the kernel about the newly added paritions.
# partprobe /dev/sda
or
# partprobe /dev/hda

NOTE:- I have created 3 logical paritions using the procedure above as SDA5, SDA6, SDA7. SDA4 is my extended partition. And i will be using this scheme only within the example.

5) Now, creating physical volume with the 3 new logical volume partitions (sda5,sda6,sda7)as:
# pvcreate /dev/sda{5,6,7}

Now, run the command "pvscan", "pvdisplay" and see results.

6) Now, creating volume group named as "vg1":
# vgcreate vg1 /dev/sda{5,6,7}

Now, run the command "vgscan", "vgdisplay" and see results.

7) Now, Finally creating the logical volume named as "lv1":
# lvcreate --size +500M --name lv1 vg1

Here, we are creating a logical volume "lv1" in the volume group "vg1" which we just created using the 3 new partitions. You can provide size either in MBs or GBs using M or G in the size parameter.

Now, run the command "lvscan", "lvdisplay" and see results.

8) Now, Format the new LVM as:
# mkfs.ext3 /dev/vg1/lv1
or
# mke2fs -j /dev/vg1/lv1

9) Now, Mounting LVM at a mount point "/lv1" as:
# mkdir /lv1
# mount -t ext3 /dev/vg1/lv1 /lv1

or you can add a new entry to the file "/etc/fstab". So that this partition is auto-mounted everytime on the mount point "/lv1".

# vim /etc/fstab
/dev/vg1/lv1     ext3     defaults     1 2
:wq
save and exit

10) Now, run "mount -a" and check the parition:
# mount -a
# cd /lv1
# df -h

II - EXTENDING A LOGICAL PARTITION

Resizng a LVM is very crucial task because there is a lot risk of "data corruption" if we didn't do it in right manner.

So for extending a LVM. First thing we need to remember is the sequence of it commands to be run.

1) First, umount the logical volume.
# umount /lv1

2) Now, extending the LVM:
# lvextend --size +50M /dev/vg1/lv1

Putting a + in front of 50M tells that LVM has to be extended by 50M. Means 50M has to added to the LVM.

3) Now, run file system check:
# e2fsck -f /dev/vg1/lv1

4) Finally, resizing the LVM:
# resize2fs /dev/vg1/lv1


III - REDUCING A LOGICAL PARTITION

Again, the sequence of commands is very important.

1)  Umount the LVM as we did above.

2) Run file system check to avoid data corruption.
# e2fsck -f /dev/vg1/lv1

3) Resizing partition, let we had a LVM partition of 500M and we extended that by 50M and now reducing it to 300M:


# resize2fs /dev/vg1/lv1 300M

NOTE:- Remember, we are not using + here before 300M since we are reducing the size.

4) Finally, reducing LVM:

# lvreduce --size 300M /dev/vg1/lv1

5) mount -a



Similarly, we can extend physical volumes and volume groups.

EXTENDING PHYSICAL VOLUME:-

Create a new partition on hard-disk same as we did in making LVM and run the command as:
# pvcreate /dev/sda8

EXTENDING VOLUME GROUP:-

# vgextend vg1 /dev/sda8


Finished.....enjoy deploying LVM....:)