Sunday, February 3, 2013

Logical Volume Management In Ubuntu



Logical Volume Management (LVM) is a disk management option that every major Linux distribution includes. Whether you need to set up storage pools or just need to dynamically create partitions, LVM is probably what you are looking for.

                      
                                         Fig1: Logical Volume Management
 What is LVM?

Logical Volume Manager allows for a layer of abstraction between your operating system and the disks/partitions it uses. In traditional disk management your operating system looks for what disks are available (/dev/sda, /dev/sdb, etc.) and then looks at what partitions are available on those disks (/dev/sda1, /dev/sda2, etc.).



Fig2: LV  Manager

With LVM, disks and partitions can be abstracted to contain multiple disks and partitions into one device. Your operating systems will never know the difference because LVM will only show the OS the volume groups (disks) and logical volumes (partitions) that you have set up.
Because volume groups and logical volumes aren’t physically tied to a hard drive, it makes it easy to dynamically resize and create new disks and partitions. In addition, LVM can give you features that your file system is not capable of doing. For example, Ext3 does not have support for live snapshots, but if you’re using LVM you have the ability to take a snapshot of your logical volumes without unmounting the disk.

When To Use LVM?

The first thing your should consider before setting up LVM is what you want to accomplish with your disks and partitions. Some distributions, like Fedora, install with LVM by default.
If you are using Ubuntu on a laptop with only one internal hard drive and you don’t need extended features like live snapshots, then you may not need LVM. If you need easy expansion or want to combine multiple hard drives into a single pool of storage then LVM may be what you have been looking for.

Setting up LVM in Ubuntu

First thing to know about using LVM is there is no easy way to convert your existing traditional partitions to logical volumes. It is possible to move to a new partition that uses LVM, but that won’t be something that we will cover in this article; instead we are going to take the approach of setting up LVM on a fresh installation of Ubuntu 11.10.To install Ubuntu using LVM you need to use the alternate install CD. Download it from the link below and burn a CD or use unetbootin to create a USB drive.

 Fig3: Ubuntu Edition Screen

Boot your computer from the alternate install disk and select your options up until the partition disks screen and select guided – use entire disk and set up LVM.

 Fig4: Partition Disks 

Select the main disk you want to use, typically your largest drive, and then go to the next step.

 Fig5: Disk to Partition

You will immediately need to write the changes to disk so make sure you selected the right disk and then write the changes.

 Fig6: Changes Screen

Select the size you want the first logical volume to be and then continue.

 Fig7: Partitioning Disks

Confirm your disk partitions and continue with the installation.
 Fig8: Changes Screen

The final step will write the GRUB boot loader to the hard drive. It is important to note that GRUB cannot be on an LVM partition because computer BIOS’s cannot directly read from a logical volume. Ubuntu will automatically create a 255 MB ext2 partition for your boot loader.

  Fig9: GBL Installation Permission Screen

After the installation is complete, reboot the machine and boot into Ubuntu as normal. There should be no perceivable difference between using LVM or traditional disk management with this type of installation.


Fig10: Final Completion Screen

This is how the LVM is installed on UBUNTU Linux.

Friday, February 1, 2013

CREATE AND RUN YOUR OWN COMMAND ON LINUX

Linux operating system allows users to create commands and execute them over the command line. To create a command in Linux, the first step is to create a bash script for the command. The second step is to make the command executable. The script can be run only after file permissions have been changed to executable mode. Once changed, copy it to the binary path of Linux so that it can be run just like system-defined commands of operating systems. Sometimes we need multiple commands to fulfill our desire task but it’s not flexible for user to execute all bunches of commands every time, so we can combine them together   and after that we can form our own command. Follow these easy steps to create a command in Linux.

Step 1:- First step to create bash file which will run your command on command line. Open GEDIT, and type following code on file,

   #!/bin/bash         
   echo "this is my first chance to create my own command'"     
   #then the rest of the files     
   echo "files of current directory are"
   ls

Give the file name as same as Command name you want to create, save this file.

Step2:- Now, you have to make this file executable. To make it executable use chmod command with option +x. CHMOD command is basically used to give access permission of files to user accounts. For more information about chmod command, open your terminal and type man chmod, you will get all information about chmod.
(Example for making file executable)

    chmod +x filelist  ( filelist is name of file )

Step3:- Now you have to copy this executable file to binary path of Linux that is “/usr/bin/”.

Sometimes for sudo (super user do) account user, it will not give you permission to copy this file to binary path of Linux. So to solve this we have to switch our account to root account, for this just type su command on terminal, it will asked you the current account password (only if you don’t created root account else you have to give root account password). After switching to root account copy your file into binary path that is “/usr/bin/”.

Now, try to execute your command, you can modify bash scripting file as per your requirement but you should have some basic knowledge of shell scripting to make perfect command that you want to create.