Operating System - HP-UX
1820879 Members
5101 Online
109628 Solutions
New Discussion юеВ

How to assign a particular inode number to a file?

 
SOLVED
Go to solution
Mary Rice
Frequent Advisor

How to assign a particular inode number to a file?

Hello Experts,

This may not be possible but I really need some help. I am upgrading 3 HPUX 10.20 systems to 11.11 this weekend. These will really be cold installs. My problem is some license files. Licensing this package is very involved. We have to run a utility and send the vendor a data file and they send back a file that is used as input for the licensing program. My problem is that the Licensing Center is not open over the weekend, but they will gladly have someone available if we agree to pay them $250 for each hour that they must remain on duty. Licensing normally takes several attempts and many hours during the normal week so I have no idea how many "extra" hours will be required. My boss is very unhappy.

After talking to the vendor's support staff, I found out that if my hostname is the same, the IP address is the same, the value returned by uname -i is the same, and the inode numbers of the license file and directory are the same then the license server will start. I also have to make sure the file modification times match the old times but that's easy.

The really bad news is that the license directory and files are in the / filesystem. If a 10.20 to 11.11 upgrade works then that would be my answer, but after reading many threads, I don't think that is a real option.

Does anybody know a way to copy a file and assign it a particular inode number?

Any ideas will be greatly appreciated.

TIA,
Mary Rice
9 REPLIES 9
Steven E. Protter
Exalted Contributor

Re: How to assign a particular inode number to a file?

1) Very good idea to avoid the upgrade, it will probably move and optimize filesystems anyway changing the inode the license file sits on.

2) Since you are doing a cold install, its probably a bad idea to try and put file a on inode b. You should lay out your system in a way thats optimal for your hardware software combination.

If you really want to explore this, try the dd command(look to others for help with that).

Best idea is to go through the process from the vendor of installing the license after install.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Wodisch
Honored Contributor

Re: How to assign a particular inode number to a file?

Hi Mary,

the tool you need is called "fsdb" and it is *VERY* dangerous!
So, in case you dare using it, do it with the freshly mounted, empty file system.
Then "touch" a file, look for its inode-number (ls -i) and then use "fsdb":
mount /dev/vgXX/lvolYY /mnt
touch /mnt/dummy
ls -i /mnt/dummy
umount /mnt
fsdb -F vxfs /dev/vgXX/lvolYY
2i
...
q

The commands to be used in place of the "..." are:
1) display the inode of your known file "dummy" by referencing its inode, e.g. 2i displays the inode of the root-directory of that filesystem
2) edit the inode you need to contain the values of the "dummy" files
3) edit the inode of the "dummy" file to become "unused"
4) "quit" from fsdb.
5) now mount your filesystem again, rename the "dummy" to your license file, and then copy the contents of the backed up license file to the new one.
6) restore all the other files needed

Read the man-pages about "fsdb_vxfs" as it is pretty complex and your are not permitted to make even typos :-(

FWIW,
Wodisch
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: How to assign a particular inode number to a file?

Hi Mary:

This is a tricky one! Have a look at fsdb_vxfs and see if you feel brave/lucky. I concur that your 10.20 to 11.11 upgrade is doomed.

Actually I do have a plan. A mv (in the same filesystem) operation preserves the inode - so that's one option but also a cp filea fileb preserves fileb's inode number if fileb is a pre-existing file.

The main trick will be to "reserve" the inode numbers.

On your existing box, you need to make a tar or cpio of your existing licence file directory and its contents. That will preserve the time metadata and the actual data.
You also need to do an ls -lai to get the existing inode numbers and note them.


I'll craft some simple scripts and get back to you.
If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: How to assign a particular inode number to a file?

Okay Mary:

Because this is the / filesystem, using fsdb is almost certainly doomed - unless you can transfer the disk(s) to another box temporarily.


I think this will work and should be perfectly safe:

On your existing 10.20 box:

I.) ls -lai licensedir | lp
cd licensedir
ls -lai | lp
(what ever your "licensedir" is)

Note the inode numbers reported.

2) cd /
find licensedir -print | cpio -ocv > /tmp/license.cpio

Save the license.cpio file on another machine using ftp. This will preserve your times and the data itself but not the inodes.

On your new 11.11 system:


c) Immediately after the base OS is installed (before anymore patches/applications are installed), you need to "reserve" the inodes found with the ls -lai commands above.

mkdir /marytmp

First, you need to make sure that the inodes are not already used by the OS load itself.


cd /
find / -xdev -inum 1200

With any luck, 1200 is not in use, so find will display nothing. Repeat the command to look for all the inodes that you need. Let's assume that the file itself needs inode 1300 and the directory needs 1200.

If the inodes are already in use then cp those files to new temporary files, rm the originals, and mv the temporary files to the original names. You will then have freed the original inode.

IV.) cd /marytmp
reservedir.sh 1200
(attached below)

This will create temporary dir's under /marytmp until inode 1200 is used. The last directory created (and displayed) will become your license directory. Let's say it's D001098.

mv D001098 /D1200

/D1200 now used inode 1200.
You can now remove all the temp dirs under /marytmp.
rmdir D*

5) Now, we need to reserve inode 1300. (Still in /marytmp)

reservefile.sh 1300
Again, the last file displayed will be your boy and use inode 1300. Let's pretend that's it's F001157.

mv F001157 /F1300.

/F1300 now uses inode 1300.


f) /marytmp has done it's job, so we can delete it.
cd /
rm -r /marytmp



VII.) At this point, we have D1200 and F1300 in /. Restore your license.cpio to ANOTHER filesystem, e.g. /tmp.

cd /tmp
cpio -icvdum < license.cpio

Your license directory and file are now under /tmp.


8) mv /D1200 licensedir
mv /F1300 licensedir/
(F1300 is now under "licensedir" but contains bogus data.
cp -p /tmp/licensedir/licensefile /licensedir/F1300
cd /licensedir
mv F1300 licensefile

i) Using chmod and chown, change the file/directory permissions to whatever values you need. Now everything is done except the modification times.

X.) touch -m -r /tmp/licensedir/licensefile licensefile

touch -m -r /tmp/licensedir /licensedir

At this point, you are done.

Here's reservedir.sh



If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: How to assign a particular inode number to a file?

Oops, the Forums are a slug today. I don't know if it was me or ... anyway, HERE's reservedir.sh.

If it ain't broke, I can fix that.
Mary Rice
Frequent Advisor

Re: How to assign a particular inode number to a file?

Thanks guys for the ideas. Keep 'em coming. Steven, I should have mentioned that I really, really need to have the systems back in operation by 8:00 AM Monday so that waiting hours to get licensed is not an option.

After reading the man pages, fsdb scares me to death. Clay, I did try your mv and cp commands and they do keep the inode numbers. I'll work with that for a bit and see where that leads me.

Thanks for your help,
Mary Rice
A. Clay Stephenson
Acclaimed Contributor

Re: How to assign a particular inode number to a file?

Hi Mary:

And here's reservefile.sh.

Read over my "cookbook" carefully. You should, of course, substitute the appropriate filenames and inode numbers but this scheme should work like a champ - with none of the risks associated with fsdb.


I hope that I have been at least semi-clear in these steps.

Regards, Clay
If it ain't broke, I can fix that.
Mary Rice
Frequent Advisor

Re: How to assign a particular inode number to a file?

Hello Gang,

I edited a copy of Clay's "cookbook", changing inode numbers and filenames to match my actual values. I tried it on a test filesystem and the inode numbers and modification times are all perfect.

I sent a copy of the "cookbook" to the vendor and asked for comments. They were impressed with how clever "I" was.

Clay, one minor point and please don't get mad: the I.), 2), c)'s were very confusing (if slightly amusing) and hard to follow.

Thanks everybody for all the help,
Mary Rice
A. Clay Stephenson
Acclaimed Contributor

Re: How to assign a particular inode number to a file?

Okay Mary, I confess, the Roman numerals, digits, and letters are a Cartalk convention. I'm a big fan of Click and Clack. I won't do it no more.

I am glad the method worked for you.

Regards (and no points for this), Clay
If it ain't broke, I can fix that.