Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting a recursive hard link

Status
Not open for further replies.

bombcan

Technical User
Jun 8, 2004
49
CA
I have a problem with one of my filesystems in AIX 4.33
In /usr1/log I have a directory called .KSQmEa which points back to /usr1. If I do a rm -R it will delete all of my /usr1
I need to just remove it without affecting /usr1.

Any help would be great!
 
Directories cannot be hardlinked. A simple "rm" with the -R should suffice to delete it.
 
You may try this

cd /usr1/log
unlink .KSQmEa

But first I'd like to see you answer to Rod's post.

HTH,

p5wizard
 
ls -al /usr1/log/.KSQmEa

shows me the output of /usr1

so I can cd into this directory and can go on and on

/usr1/log/.KSQmEa/log/.KSQmEa/log

 
It shows

2 drwxr-sr-x 62 root system 1536 Sep 06 14:03 /usr1
2 drwxr-sr-x 62 root system 1536 Sep 06 14:03 /usr1/log/.KSQmEa
 
Interesting, that's definately a real hard link on a directory.

I suspect some "unlink" delicate surgery, wait for the CATE :)

I tried building a filesystem to replicate the problem, but the link command refuses to do the job.
 
That's why I called it a hard link...Not sure how this came up on the system. But I tried to do a rm -R on .KSQmEa and it
was deleting my /usr1/ directory
That was fun!!!
 
Wow. That's one broken filesystem. Sorry to disappoint, but a CATE doesn't give me any magical insight into the manner in which it's broken, or if this symptom is the only damage.

If /usr1 is a filesystem, unmount it and see if fsck can fix it.

If not, or if fsck can't fix it, you can try the following at your own risk:

back up /usr1
back up /usr1 again
pull tables of contents off of both backups to verify
cross fingers
[tt]unlink /usr1/log/.KSQmEa[/tt]

Typing with crossed fingers is the most difficult part. :)

Per documentation, that should do it (but per documentation the problem shouldn't exist in the first place). Sorry I can't give you a more solid answer.

Let us know how it goes.

- Rod


IBM Certified Advanced Technical Expert pSeries and AIX 5L
CompTIA Linux+
CompTIA Security+

A Simple Code for Posting on the Web
 
Give me a minute, writing up a long post, it can be done safely.
 
The problem he's going to have running a simple backup is when it walks the filesystem to build a file & directory list - any backup software is going to process that hardlink as a normal directory and go into a perpetual loop. That should be true for both inode and filename type backups.

Here's the way I would deal with it, assuming there is sufficient disk space to equal to a full copy of the filesystem.

First, build a list of all files in the filesystem, excluding the offending directory.

not 100% tested since I can't replicate the fault, but should suffice as pseudocode:
Code:
#!/bin/ksh

FILELIST=/a/directory/and/a/file
rm ${FILELIST} 2>/dev/null

# first process the top level of the /usr1 directory, excluding the logs subdir
cd /usr1
ls | grep -v "^log$" while read FDNAME
do
	find /usr1/${FDNAME} -type f >> ${FILELIST}
done

# second process the log directory, skipping the offending directory
cd /usr1/log
ls | grep -v "^\.KSQmEa$" | while read FDNAME
do
	find /usr1/log/${FDNAME} -type f >> ${FILELIST}
done

At this point, you can go a couple of different ways.

1) if you have enough space for 2 copies of /usr1:
a) Create a tarball using -L and the filelist that you just created to create a backup of /usr1 that excludes the problem directory.
b) Remount the broken filesystem as /usr1broken
c) Create a new /usr1
d) untar the tarball

2) if you have enough space for only 1 copy of /usr1
a) Create a second filesystem /usr1copy, and iterate through that filelist copying each file, maintaining permissions.
b) Remount the broken filesystem as /usr1broken
c) Remount the copied filesystem as /usr1
d) Repair any missing permissions (theoretically parse the entire file *and* directory tree, then pull the owner/group/perms for the same file from the original)

Both of these methods are intended simply to keep the broken filesystem around untouched, so there is always a recovery point if something goes badly wrong.

A third method would be to make a copy of the broken LV, perform a splitlvcopy on it, then perform the unlink as Rod mentioned. I don't favor doing this as if you've got a filesystem with a seriously weird problem (as you do), I would be concerned that it could have other problems. Copying the data to a newly created filesystem should ensure that you have a filesystem structure without hidden problems.
 
What if you do this

cd /usr1/log
ls -a | grep "^\."

Apart from the .KSQmEa entry do you see both . and .. ?

If you just have the . and .KSQmEa, then it is possible that the .. entry was somehow renamed. Not sure if that can be renamed to .. again. I'd go with the backup and restore strategy.

If you have . , .. and .KSQmEa, then backup, backup and try the unlink. But if this is the case, I'd also look for more of the same at least:

find /usr1 -type d ! -name ".KSQmEa" -ls

Of course this will go into a recursive pathname explosion if it finds any other offending dir hardlink, but then just ctrl-C the find command and run it again, including another '! -name "Whatever"' until you have found all the problem hardlinks...

As to the origin of this problem, I'm guessing a leftover NFS deleted file - I've seen filenames like that on NFS server filesystems when NFS client doesn't clean up like it should or after broken NFS links... Just a hunch.

And yes Rod, you are right: a CATE doesn't provide any magic spells for this one, not even for a wizard... ;-)


HTH,

p5wizard
 
You guys are great. I too had in mind to do option 1 of Chapter11's suggestion ...I was just wondering if there was an easier/faster way!

Thanks and I'll keep you posted in the progress!

 
lol. I looked at the manpages for link and unlink. Those commands look like very good ways to seriously screw up a filesystem, so I was going to leave those to people who know them better than I do.

+1 to p5wizard's suggestion for checking for other brokenness before running a backup.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top