Operating System - HP-UX
1827894 Members
1647 Online
109969 Solutions
New Discussion

creating a link file for lvm commands

 
223848
Frequent Advisor

creating a link file for lvm commands

Hi All,

              In my Unix box i created a link file which is pointing to /usr/sbin/lvdisplay

 

# ln -s /usr/sbin/lvdisplay /tmp/test

# ll | grep -i test
lrwxrwxrwx   1 root       sys             19 Sep  5 06:32 test -> /usr/sbin/lvdisplay


# ./test
test: Error, "test" is not a valid LVM command.

 

I created a hard link also, but then also i got the same error.

 

Then i tried to linka file to the path of hostname...

 

# ln -s /usr/bin/hostname /tmp/new
[rx260-01]/tmp

 

After this when i executed /tmp/new i got the hostname

 

# /tmp/new
rx260-01

 

The Unix verision is 11.23.

 

Can  you please tell me why its behaving like this..


10 REPLIES 10
Dennis Handly
Acclaimed Contributor

Re: creating a link file for LVM commands

>In my HP-UX box I created a link file which is pointing to /usr/sbin/lvdisplay

 

Why do that?  Don't.  What does "ll -i /usr/sbin/lvdisplay" show?

 

>Can you please tell me why its behaving like this?

 

Only the obvious, most likely there are multiple commands all hardlinked to one executable and the wrong name falls off the switch to the error case.

223848
Frequent Advisor

Re: creating a link file for LVM commands

Hi,

     Thanks for the reply

 

# ll -i /usr/sbin/lvdisplay
   518 -r-sr-xr-x  33 root       sys        1329404 Mar 17  2008 /usr/sbin/lvdisplay
[rx260-01]/tmp
#

Dennis Handly
Acclaimed Contributor

Re: creating a link file for LVM commands

># ll -i /usr/sbin/lvdisplay
>   518 -r-sr-xr-x  33 root  /usr/sbin/lvdisplay

 

As I suspected, there are 33 different commands in that one executable.

James R. Ferguson
Acclaimed Contributor

Re: creating a link file for LVM commands

Hi:

 

There are 33 different hard links to the executable.  As Dennis said, this is a classic way of offering one executable that when it runs, evaluates the *name* by which it was called to decide what functionality to invoke.  The LVM commands have long used this paradigm.

 

Regards!

 

...JRF...

223848
Frequent Advisor

Re: creating a link file for LVM commands

Hi All,

     Thank for the update, but sorry i  didn t understand by   "There are 33 different hard links to the executable"...

 

Can you please  explain me ......

 

Thanks

Laiju

James R. Ferguson
Acclaimed Contributor

Re: creating a link file for LVM commands


@223848 wrote:

     Thank for the update, but sorry i  didn t understand by   "There are 33 different hard links to the executable"...

 


Review the manpages for 'ls(1)' to appreciate what it is that the output you posted says.

 

Do you understand what a hard-link is?  The LVM binaries are hard-links to a common piece of code.

 

http://en.wikipedia.org/wiki/Hard_link

 

Hard links differ from soft (symbolic links) so be sure to understand what they are:

 

http://en.wikipedia.org/wiki/Symbolic_link

 

Regards!

 

...JRF...

Dennis Handly
Acclaimed Contributor

Re: creating a link file for LVM commands

>"There are 33 different hard links to the executable".

>>   518 -r-sr-xr-x  33 root  /usr/sbin/lvdisplay

 

33 is the (hard) link count.  If you look for inode with value of 518, you should find them all:

find /usr/sbin -inum 518 -exec ll -i +

223848
Frequent Advisor

Re: creating a link file for LVM commands

Hi All,

      Thanks a lot for the information

What i understood is..

 

I checked and found that all lv and vg related commands have same inode that means,, eventhough we are using the diffenret commands  its executing a common script..

As we can wee 33 hardlinks are there ,

 

Eventhough if im creating an additional soft link or hard link with a new name ( in our scenario /tmp/test)  then also when im executing with the new link (/tmp/test) , it will cehck whether i used any of the above 33 names ..

 

Whether my concept is clear .....

 

Regards

Laiju.

Dennis Handly
Acclaimed Contributor

Re: creating a link file for LVM commands

>even though we are using the different commands, it's executing a common script.

 

This isn't a script, it's a binary executable.

(Though the same trick can be used for scripts.)

223848
Frequent Advisor

Re: creating a link file for LVM commands

Hi Dennis and James,

 

                     Thanks a lot for your kind time for teaching  me :)

 

Regards

Laiju