Live as if you were to die tomorrow. Learn as if you were to live forever.

Friday, 23 January 2015

What is the difference between soft and hard links ?

Soft Link:

1. Soft link having different inode number.
2. Soft link can cross file system boundaries.
3. In soft link we can link to files as well as directories.
4. Soft link will break if original file is moved or deleted.
5. Size of the soft link file is the length of the original file.

[root@localhost vinod]# ln -s new.pl softlink.pl
[root@localhost vinod]# ll new.pl softlink.pl
-rw-r--r--. 1 root root 610 Jan  4 23:24 new.pl
lrwxrwxrwx. 1 root root   6 Jan 23 03:44 softlink.pl -> new.pl
[root@localhost vinod]#


Hard Link:

1. Hard link having same inode number.
2. Hard link can not cross file system boundaries.
3. In Hard link we can only link to files but we cannot link to directories.
4. Hard link cannot break even if you delete or move the original file.
5. Size of hard link file is equal to the length of the original file.


[root@server vinod]# ln pass.sh hardlink.sh
[root@server vinod]# ll pass.sh hardlink.sh
-rw-r--r--. 2 root root 36 Dec 31 22:40 hardlink.sh
-rw-r--r--. 2 root root 36 Dec 31 22:40 pass.sh
[root@server vinod]#



Tuesday, 6 January 2015

How to check Linux Distribution, Architecture and Kernel ?

How to check the Linux Distribution ?

To check which Linux Distribution we can see the file /etc/issue or /etc/redhat-release

[root@localhost ~]# cat /etc/issue
Red Hat Enterprise Linux Server release 6.0 (Santiago)
Kernel \r on an \m

[root@localhost ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.0 (Santiago)
[root@localhost ~]#

Here, we can say that we are using the RedHat Linux 6

Find out the system architecture ?

Use the below commands to find out the system architecture.
  
[root@localhost ~]# arch
x86_64

[root@localhost ~]# uname -m
x86_64

[root@localhost ~]# getconf LONG_BIT
64

Here, x86_64 means the system is 64-bit. If you will get i386 or i686 then the system is 32-bit. If you are confused in x86_64 and i386 simply type the command  "getconf LONG_BIT", You will come to know the archiecture.

Check the Linux Kernel

To check the linux kernel use the below command

[root@localhost ~]# uname
Linux

[root@localhost ~]# uname -s
Linux

It only print the name of  the kernel. Here, linux is the name of kernel.

Check the kernel version

There are various commands in linux to check the kernel version. You can use any one of the below command to check the kernel version.

[root@localhost ~]# uname -r
2.6.32-71.el6.x86_64

[root@localhost ~]# cat /proc/version
Linux version 2.6.32-71.el6.x86_64 (mockbuild@x86-007.build.bos.redhat.com) (gcc version 4.4.4 20100726 (Red Hat 4.4.4-13) (GCC) ) #1 SMP Wed Sep 1 01:33:01 EDT 2010
[root@localhost ~]# 

[root@localhost ~]# rpm -q kernel
kernel-2.6.32-71.el6.x86_64

[root@localhost ~]# dmesg | grep Manufacturer | grep Linux
usb usb1: Manufacturer: Linux 2.6.32-71.el6.x86_64 ehci_hcd
usb usb2: Manufacturer: Linux 2.6.32-71.el6.x86_64 uhci_hcd


Here, 2.6.32-71.el6.x86_64 is the kernel version. 
2   ------>  Kernel version
6   ------>  Major release
32 ------> Minor release
71.el6 --> Fix  
x86_64 -> Architecture, x86_64 means the system is 64-bit


Note: Interview point of view all above information is very important. :)

Tuesday, 30 December 2014

Mount your own iso image on redhat linux


First create the mount point where you want to mount the iso image.

#mkdir /mntimg

Now, To mount iso image temporarily use following step


#mount -o loop -t iso9660 /image/data.iso /mntimg

Now, you have mounted the data.iso file on /mntimg directory.
You can check the entry of iso file in mtab file.


vi /etc/mtab

Now, You have mounted the iso file temporarily.

When you restart the system the iso image will unmount automatically for that you need to mount the iso permanently.

To mount iso permanently use following steps:

You need to add the entry in the fstab file


vi /etc/fstab

add the following entry



/image/data.iso /mntimg iso9660 loop,ro 0 0
wq!



You can crosscheck using the command


#mount -a

Cheers !!!! Now, You have permanently mount the iso image on /mntimg directory.

Monday, 29 December 2014

Configure your own yum repository using iso image

If you have installed the RedHat/CentOS on your Desktop and you are not having the Internet connectivity. In this case you cannot install the packages using the YUM but if you wants to install the packages for that you will need to configure the YUM as follows

First of all mount iso image on the directory.

Now configure the YUM repository

Create the file under the yum.repos.d directory which is having the .repo extension.

#vi /etc/yum.repos.d/rpm.repo

add the following lines under rpm.repo file


[Repository]
name="Yum Repository"
baseurl=file:///mntimg/
enabled=1
gpgcheck=0

:wq!

Now, Try to install the package.

#yum install vsftpd

Cheers !! You have successfully configured your own yum repository.

Wednesday, 24 December 2014

What is GNU ?

GNU means GNU not Unix. The important part of any O.S. is kernel. In GNU the Linux is the kernel. Linux alone cannot form O.S. but with the help of other programs “GNU” we refer as Linux.

Linux is same as like of Unix. Linux is free, multitasking, multi-user O.S. but its not user friendly, You will need some training to handle the Linux O.S.

We can say, free Unix like O.S. known as GNU.

Most of the people uses Linux as Server O.S.


Saturday, 20 December 2014

Runlevels in Linux

Run-level defines the state in which O.S. and its services are running.

There are total 7 run-levels in linux and system can be booted in any of these run-levels.

Run-level
                              Description
        0
Halt / Shutdown
        1
Single User Mode
        2
Multi User without NFS
        3
Full Multiuser
        4
Unused
        5
X11 (Graphical Mode)
        6
Reboot

By default linux boots in either run-level 3 or 5
                       
The init program is used to handle all the run-levels and its process id is 1.

You can also check the process id of init using below command

[root@server]$ ps -aux | grep init
root         1  0.0  0.1  31032  1880 ?        Ss   Sep30   0:19 /sbin/init  

The /etc/inittab file contains the information regarding the run-levels.
Issue the command cat /etc/inittab
                       
            # Default runlevel. The runlevels used are:
#   0 - halt (Do NOT set initdefault to this)
#   1 - Single user mode
#   2 - Multiuser, without NFS (The same as 3, if you do not have networking)
#   3 - Full multiuser mode
#   4 - unused
#   5 - X11
#   6 - reboot (Do NOT set initdefault to this)
#
id:5:initdefault:                      

Here, see the last line in file “id:5:initdefault:” which states that the run-level of the system is 5. You can also change the run-level to 3 or 1 as per your convenience but keep in mind that these changes are permanent.

To change the run-level temporarily simply you can type the command “init run-level” i.e. init 3.

How to  check the current run-level ?

runlevel command is used to check the current run-level.

[root@server]$ runlevel
N 3

Here, N means previous run-level and 3 is the current run-level.

You can also use the command who –r


[root@server]$ who -r
         run-level 3  2014-09-30 04:23

MBR (Master Boot Loader)


MBR is the Master Boot Loader which is located at first sector of the hard disk used to find the operating system and load it into the memory.

The MBR can be created automatically when you create the partitions.

The size of MBR is 512 bytes which contains:

(i)                 Primary Boot Loader (446 Bytes)
(ii)               Partition table (64 Bytes)
(iii)             MBR Validation Check/Magic Number (2 Bytes)

(i)  Primary Boot Loader:

Primary boot loader contains partition and that partition contains the code (software program) to boot the system. The size of primary boot loader is 446 Bytes.

(ii) Partition Table:

The partition table is used to store all the information of the created partitions. In linux we can create only 4 primary partitions because the size of partition table is 64 bytes and each primary partition requires 16 byes so 16 x 4 = 64 bytes. Now size of partition size is over, that’s the reason we cannot create more than 4 partitions in linux.

(iii) MBR Validation Check/Magic Number:

If the MBR gets corrupted in this situation Magic Number restore MBR. Its size is 2 Bytes.