Recreating a deleted hardlink to a file if I know the inode number


 
Thread Tools Search this Thread
Special Forums Hardware Filesystems, Disks and Memory Recreating a deleted hardlink to a file if I know the inode number
# 1  
Old 08-11-2008
Recreating a deleted hardlink to a file if I know the inode number

At risk of twisting the rules to nearly the point of breaking (if you think this goes too far mods, I apologise and accept that this should be deleted), I'm hoping someone might be able to cast a little light on the following problem regarding hard links to files.

Creating a hardlink to a file
Quote:
I'm trying to relink a file someone tried to delete while a process (that we don't want to shutdown) also had a filehandle open to it.
Consequently, we've got an inode entry but no directory entry (aka 'file') for it.

I've tracked the inode number down via lsof, as well as the particular filehandle the process has within the /proc filesystem.

This filehandle is presented as a standard "file"/directory entry in /proc/<pid>/fd and I can read from it ok as I would any other file.

I was hoping to create a link to it back where it used to be but I keep getting a 'No such file or directory' error. I know I've got my ln syntax correct as I've tested it out on plain files elsewhere.
Code:
ln /proc/<pid>/fd/<handle> /path/to/application/logs/access

Is ln the tool to use here? Surely if I know the inode number, filehandle and what it used to be called, I can recreate it?
# 2  
Old 08-11-2008
I don't think that you're breaking the rules with a 2 week bump. Hard links are only possible within a file system. You can't can't make a hard link from one file system into another file system. /proc is a separate file system and you can't create links there at all. An extra link in /proc won't help you anyway. Forget /proc. It goes nowhere.

The only tool with a shot at this is fsdb, but I don't know fsdb well enough to tell you the precise steps. Call this plan A. The general steps I would try are:

1 create some file
2 create an extra link to the file with very bizarre name (more easily found and easy to sure you have the right one)
3 hit the power switch to drop power to the box
4 come up in single user mode and run fsdb
5 edit the directory entry to point to my file
6 edit the inodes to increment and decrement the usuage counts
7 run fsck

And I would practice on a test system before I tried it for real.

If I couldn't get it to work, plan B:

1 drop power
2 ship the disk to a data recovery specialist with experts who can implement plan A.
# 3  
Old 08-11-2008
Yoicks! Probably a little bit extreme for what I need (as I can recover the data from the proc filesystem's filehandle list). Good point about the cross-filesystem thing, that explains why ln isn't going to play ball.

What I guess I'm really looking for is a way to take an inode number (something that still has at least one link to it) and create a 'file' (aka directory entry) on the same filesystem that links to it.

fsdb sounds like something to take a look at, but it also sounds like a great way for me to really fubar a filesystem. Methinks I'll play with it on a lab server Smilie
# 4  
Old 08-19-2008
As an aside, some kernels - BSD is one - have an fhopen call that will open a file based on inode number.

I don't see how that helps since you can read the file via /proc/<pid>/fd. If the filesystem still has the data out there somewhere, can you read the file onto media to rescue it?
# 5  
Old 01-14-2009
Just in case someone else sees this...

I stumbled onto this thread while experiencing a similar problem. A file had been deleted while a process still had it opened.

Use lsof to determine the inode number of the file

install icat (Google icat-sleuthtools)... for ubuntu it's apt-get install sleuthtools

then use icat to copy the file to the new location:

icat -hf ext /dev/xxx <inode> > /path/to/copy.file

-h tells it to skip over any holes in the file (sparse data)
-f ext tells it to use ext2/3

/dev/xxx is the device (NOT THE MOUNTED DIRECTORY!!!)

<inode> is the node returned from lsof

Hope this helps!

-Ecifer
# 6  
Old 01-20-2009
MySQL Cool!

That's rather cool, will bookmark Smilie In my case it very similar to the abilities granted via the /proc/<pid>/fd/<filehandle> but being able to refer to inode number directly is a trick I'll be pleased to have in my toolbox! Smilie
# 7  
Old 01-21-2009
For the record... that only worked on 2 out of 3 attempts for me... it really depends on whether or not the open process is actively using the file at the time.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Linux

Inode number changes for a file in Redhat Linux

Hi, I have created a file a.txt in Redhat Linux. Inode number for a file changes every time i update the file using vi editor , gedit etc. Is there any setting that can be made , such that inode number never changes as that is supposed to be the expected behavior? Or if we cannot... (13 Replies)
Discussion started by: srirammanohar
13 Replies

2. Shell Programming and Scripting

Changing inode value of a hardlink

is it possible to change the inode value/ file path of a hard link? (2 Replies)
Discussion started by: fhill2
2 Replies

3. Solaris

Retreive deleted file name if you having inode number

Some one please help me to find deleted file name, if I am having inode number in Solaris without using any 3rd party tool. Thanks :) (3 Replies)
Discussion started by: aksijain
3 Replies

4. Red Hat

Inode number changes for a file in Redhat Linux

Hi, I have created a file abc.log in Redhat Linux. Inode number for a file get changes every time i update the file using vi editor. Is there any setting that can be made , such that inode number never gets changed? Or if we cannot restrict from inode number getting changed , is... (9 Replies)
Discussion started by: raghu.amilineni
9 Replies

5. Shell Programming and Scripting

Modifying a file without changing inode number

Hi all, I am struggling to change the content of a file without changing the inode number. The exact issue is as below. I have a file name test.bak which has 100 lines of text. I am trying to to delete the first 90 lines of the text in the file. I know that using sed/awk/head/tail I can... (3 Replies)
Discussion started by: sathishkmrv
3 Replies

6. AIX

How to get the filename of which has been deleted if I know the inode number?

How to get the filename of which has been deleted if I know the inode number. i can use the command "istat" to get the inode number of the file. # istat /proc//fd/x If this file has been deleted,but the process of this file has not been closed and handle has not been released ,so this... (3 Replies)
Discussion started by: JoyOnLine
3 Replies

7. Solaris

Recreating .xml file in /etc/zones

Folks, just wondering if there is a way to recreate this file if inadvertantly removed ?? (8 Replies)
Discussion started by: trevagreene
8 Replies

8. UNIX for Dummies Questions & Answers

Number of Inode on a disk

How we can know number of inode present in my Disk including free and occupied. Is there any tool or program to know how much free inode are there in inode free list . (2 Replies)
Discussion started by: mr_deb
2 Replies

9. Solaris

Creating a hardlink to a file

I'm trying to relink a file someone tried to delete while a process (that we don't want to shutdown) also had a filehandle open to it. Consequently, we've got an inode entry but no directory entry (aka 'file') for it. I've tracked the inode number down via lsof, as well as the particular... (0 Replies)
Discussion started by: Smiling Dragon
0 Replies

10. Filesystems, Disks and Memory

Inode number

as kernel keeps track of user activities on a file by its INODE number and I node table . what is the structure of Inode table. and where does this Inode table mapped into?user space or kernel space? is the Inode Number is fixed for a file till its deletion? thanks (1 Reply)
Discussion started by: compbug
1 Replies
Login or Register to Ask a Question