Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Can't delete a directory

32 views
Skip to first unread message

Riley J. McIntire

unread,
Sep 11, 2002, 8:52:33 PM9/11/02
to FreeBSD Questions
Hi all,


Prior to a buildworld (adding sasl support to sendmail by installing
cyrus-sasl2 and modifying /etc/make.conf on 4.6.2-RELEASE) when removing
the old /usr/obj/usr this happened:

root@wimp:obj# chflags -R noschg * && \rm -r usr/
rm: usr/src/fsck_msdosfs: Directory not empty
rm: usr/src: Directory not empty
rm: usr/: Directory not empty

root@wimp:obj# ls -ilaFo usr/src/fsck_msdosfs/
total 4
155993 drwxr-xr-x 2 root wheel - 512 Sep 11 17:14 ./
133634 drwxr-xr-x 3 root wheel - 512 Sep 11 17:14 ../
root@wimp:obj# ls -ilaFo usr/src/
total 6
133634 drwxr-xr-x 3 root wheel - 512 Sep 11 17:14 ./
133633 drwxr-xr-x 3 root wheel - 512 Sep 1 13:58 ../
155993 drwxr-xr-x 2 root wheel - 512 Sep 11 17:14 fsck_msdosfs/

It will move within the fs, but not across:

root@wimp:src# mv fsck_msdosfs/ /usr
root@wimp:src# ll
total 4
drwxr-xr-x 2 root wheel - 512 Sep 11 17:45 ./
drwxr-xr-x 3 root wheel - 512 Sep 1 13:58 ../

root@wimp:src# mv /usr/fsck_msdosfs/ /tmp
mv: /usr/fsck_msdosfs/: Directory not empty
mv: /bin/rm: terminated with 1 (non-zero) status: Cross-device link
root@wimp:src#

Any ideas?

Thanks,

Riley


Warning: this .sig is umop ap!sdn Oh, I'm sorry...did I break your
concentration?


To Unsubscribe: send mail to majo...@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message

Beech Rintoul

unread,
Sep 11, 2002, 9:04:54 PM9/11/02
to Riley J. McIntire, FreeBSD Questions

Try doing

rm -R /usr/obj/usr

Beech
-------------------------------------------------------------------
Beech Rintoul - SysAdmin - akb...@sinbad.net
/"\ ASCII Ribbon Campaign | Sinbad Network Communications
\ / - NO HTML/RTF in e-mail | 3101 Penland Parkway #K-38
X - NO Word docs in e-mail | Anchorage, AK 99508-1957
/ \ -----------------------------------------------------------------

Daniel Bye

unread,
Sep 11, 2002, 9:21:42 PM9/11/02
to FreeBSD Questions

This is no different than rm -r /usr/obj/usr

Do this:

rm -rf /usr/obj/usr

The -f flag tells rm to "Force" the removal of the file/directory,
suppresses warnings about non-existant files, and causes rm not to alter
its exit status to reflect an error in cases where a file doesn't exist,
or its permissions would ordinarily prevent you from removing it.

HTH

Dan

--
Daniel Bye

PGP Key: ftp://ftp.slightlystrange.org/pgpkey/dan.asc
PGP Key fingerprint: 3D73 AF47 D448 C5CA 88B4 0DCF 849C 1C33 3C48 2CDC
_
ASCII ribbon campaign ( )
- against HTML, vCards and X
- proprietary attachments in e-mail / \

Riley J. McIntire

unread,
Sep 11, 2002, 9:40:07 PM9/11/02
to Beech Rintoul, FreeBSD Questions
> > root@wimp:obj# chflags -R noschg * && \rm -r usr/

> Try doing
>
> rm -R /usr/obj/usr
>
> Beech

root@wimp:/# \rm -R /usr/obj/usr/
rm: /usr/obj/usr/fsck_msdosfs: Directory not empty
rm: /usr/obj/usr/: Directory not empty
root@wimp:/#


from man rm:

-r Equivalent to -R

Riley

John Mills

unread,
Sep 11, 2002, 9:49:46 PM9/11/02
to Riley J. McIntire, Beech Rintoul, FreeBSD Questions
All -

On Wed, 11 Sep 2002, Riley J. McIntire wrote:

> > > root@wimp:obj# chflags -R noschg * && \rm -r usr/
>

How about:
[ ]$ rm -rf <root_of_destruction>

Naturally you will need appropriate permissions. Check your aim!

- John Mills

Riley J. McIntire

unread,
Sep 11, 2002, 11:39:36 PM9/11/02
to John Mills, Riley J. McIntire, Beech Rintoul, FreeBSD Questions
> How about:
> [ ]$ rm -rf <root_of_destruction>
> - John Mills
>

root@wimp:obj# rm -rf usr/
rm: usr/fsck_msdosfs: Directory not empty


rm: usr/: Directory not empty
root@wimp:obj#

Thanks,

Riley

Tony Landells

unread,
Sep 12, 2002, 12:02:08 AM9/12/02
to Riley J. McIntire, FreeBSD Questions
rile...@pacbell.net said:
> root@wimp:obj# rm -rf usr/
> rm: usr/fsck_msdosfs: Directory not empty
> rm: usr/: Directory not empty
> root@wimp:obj#

You aren't somehow using using usr/fsck_msdosfs in some file system
operation, like using it as a mount point?

If you had something mounted you wouldn't be able to delete the
directory.

Just a guess...

Tony
--
Tony Landells <a...@austclear.com.au>
Principal Networks, Security & IT Systems Engineer Ph: +61 3 9677 9319
Australian Clearing Services Pty Ltd Fax: +61 3 9677 9355
Level 4, Rialto North Tower
525 Collins Street
Melbourne VIC 3000
Australia

Matthew Seaman

unread,
Sep 12, 2002, 3:57:59 AM9/12/02
to Riley J. McIntire, John Mills, Beech Rintoul, FreeBSD Questions
On Wed, Sep 11, 2002 at 08:39:01PM -0700, Riley J. McIntire wrote:
> > How about:
> > [ ]$ rm -rf <root_of_destruction>
> > - John Mills
> >
>
> root@wimp:obj# rm -rf usr/
> rm: usr/fsck_msdosfs: Directory not empty
> rm: usr/: Directory not empty
> root@wimp:obj#

If you've exhausted all other avenues then there is an extreme but
dangerous action you could take to get rid of your rogue directory.
You should understand that this procedure will deliberately corrupt
part of your filesystem and relies then on running fsck(8) to sort the
whole mess out.

First, make a note of the device your /usr filesystem resides on, and
of the inode number of the rogue directory:

df /usr | sed -e 1d -e 's/ .*$//'
ls -id /usr/obj/usr/fsck_msdosfs | sed -e 's/ .*$//'

Also, take a backup of your system before you do anything else. Now,
reboot the system and bring it up into single user mode, exactly as
you would for doing a 'make installworld'. At this point it's worth
trying one last time to get rid of the directory by ordinary means:

fsck -f %device% (ie. the device you noted above)
mount -o rw -u / (having / read-write makes mount a
lot friendlier...)
mount /usr
cd /usr/obj/usr
rm -rf fsck_msdosfs

If that set of commands didn't succeed in getting rid of the
directory, then it's time to get nasty with the file system. (If, on
the other hand, it did work then breath a huge sigh of relief and just
reboot and ignore the rest of this.)

umount /usr
clri %device% %inode%
fsck -f %device% -y (fingers crossed...)

This final fsck will come up with and hopefully fix a bunch of errors
you've deliberately introduced with clri(8). However, the directory
will definitely be destroyed.

As ever, make sure you have good backups. This procedure involves a
significant risk of trashing your system. Did I mention that you need
good backups?

Cheers,

Matthew

--
Dr Matthew J Seaman MA, D.Phil. 26 The Paddocks
Savill Way
Marlow
Tel: +44 1628 476614 Bucks., SL7 1TH UK

John Mills

unread,
Sep 12, 2002, 10:42:08 AM9/12/02
to Riley J. McIntire, John Mills, Beech Rintoul, FreeBSD Questions
Riley, All-

Here's another suicidal approach:

On Wed, 11 Sep 2002, Riley J. McIntire wrote:

after I babbled:


> > How about:
> > [ ]$ rm -rf <root_of_destruction>

> root@wimp:obj# rm -rf usr/


> rm: usr/fsck_msdosfs: Directory not empty
> rm: usr/: Directory not empty
> root@wimp:obj#

Sorry - I came in late on this. Even as root! Is this behavior limited to
DOS directories?

You could try a script or alias to the general effect of:

-+-+-+-+-+-+-+-+-+-+-+-+- slashwrist -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#!/bin/sh
# sorry - I'm a bash weenie.
if [ $# -lt 1 ]
then
echo "usage: slashwrist <root_of_destruction>"
echo " and be _really_ careful, Boss!"
exit

else
for FILENAME in `find $1 ! -type d -print`
do
# consider interactive use here: 'rm -i $FILENAME'
echo "Removing "$FILENAME
rm -f $FILENAME
done
echo "Removing directories below "$1
rm -rf $1
fi
-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

You may have to run that as root, too, depending on permissions associated
with DOS directories.

DISCLAIMERS:

1) There is pretty much no limit to the damage you could do
your system with this script.

2) I just typed that out by way of example, and tried it only once in
FreeBSD. It may well contain errors, or constructs that work differently
than I expected. If you try it, _first_ comment out the 'rm' lines, then
run it and carefully read the list of files which would have gone to the
bit-bucket before you fire off a 'killer' version!

If you get the idea I'm a bit cautious about this, you get full credit on
the quiz. I would almost prefer to do it manually.

I once wiped out my Linux box's '/var' in a moment of emotion with a
simple 'rm' at the wrong spot - the emotions which followed were _much_
stronger!! Recovery took quite a while and ultimately a lot of rebuilding.

YMMdefinitelyV!
- John Mills

Riley J. McIntire

unread,
Sep 12, 2002, 2:34:46 PM9/12/02
to John Mills, Riley J. McIntire, Beech Rintoul, FreeBSD Questions
>
> > root@wimp:obj# rm -rf usr/
> > rm: usr/fsck_msdosfs: Directory not empty
> > rm: usr/: Directory not empty
> > root@wimp:obj#
>
> Sorry - I came in late on this. Even as root! Is this behavior limited to
> DOS directories?

This isn't a DOS directory, it's the remnants of the last buildworld (this
machine is "Build Master" for the other servers on the network).

As such, /usr/obj is an NFS export. However, /usr/obj/usr/fsck_msdosfs
isn't mounted. And after "umount -at nfs" on the other servers just to make
sure the error still occurs.

It's not convenient to take this down to single user, and I'm concerned this
might be a symptom of a more serious problem, although the logs show
nothing.

> # consider interactive use here: 'rm -i $FILENAME'
> echo "Removing "$FILENAME
> rm -f $FILENAME
> done
> echo "Removing directories below "$1
> rm -rf $1
> fi

Seems to me running rm -rf in a script wouldn't do any more than cli.

Thanks for the help!

Riley

John Mills

unread,
Sep 12, 2002, 2:46:17 PM9/12/02
to Riley J. McIntire, John Mills, Beech Rintoul, FreeBSD Questions
Riley -

On Thu, 12 Sep 2002, Riley J. McIntire wrote:

> > # consider interactive use here: 'rm -i $FILENAME'
> > echo "Removing "$FILENAME
> > rm -f $FILENAME
> > done
> > echo "Removing directories below "$1
> > rm -rf $1
> > fi

> Seems to me running rm -rf in a script wouldn't do any more than cli.

At that point the script has emptied the directories of files, but not
directories. The script doesn't remove directories from the bottom
upwards, so you're probably right that it wouldn't work.

Can you manually go to a leaf directory, empty it, then backup one and
remove it?

Can you turn off the exportation, then try the simple 'rm -rf'?

How about 'umount' this partition (slice?), re'mount' it on a generic
mount-point, then removing what you need to? Afterward you would
presumably reverse the process and export the new branch.

DISCLAIMER: I'm only guessing here.

- John Mills

Riley J. McIntire

unread,
Sep 12, 2002, 3:35:54 PM9/12/02
to John Mills, Beech Rintoul, FreeBSD Questions

>
> > Seems to me running rm -rf in a script wouldn't do any more than cli.
>
> At that point the script has emptied the directories of files, but not
> directories. The script doesn't remove directories from the bottom
> upwards, so you're probably right that it wouldn't work.
>
> Can you manually go to a leaf directory, empty it, then backup one and
> remove it?

I've renamed it, can mv it to any point on its (local) filesystem, including
above the export point, but can't delete it. The /usr/ and usr/ are a
little confusing below, note that usr/ == /usr/obj/usr.

root@wimp:obj# pwd
/usr/obj
root@wimp:obj# ls -ilaFo usr/fsck_msdosfs/
total 4
155993 drwxr-xr-x 2 root wheel - 512 Sep 12 12:26 ./
133633 drwxr-xr-x 3 root wheel - 512 Sep 12 12:26 ../


root@wimp:obj# ls -ilaFo usr/

total 6
133633 drwxr-xr-x 3 root wheel - 512 Sep 12 12:26 ./
133632 drwxr-xr-x 3 root wheel - 512 Sep 12 12:26 ../
155993 drwxr-xr-x 2 root wheel - 512 Sep 12 12:26 fsck_msdosfs/
root@wimp:obj# mv usr/fsck_msdosfs/ /usr
root@wimp:obj# cd /usr
root@wimp:usr# rm -rf fsck_msdosfs/
rm: fsck_msdosfs/: Directory not empty
root@wimp:usr# cd fsck_msdosfs/
/usr/fsck_msdosfs
root@wimp:fsck_msdosfs# ls -ilaFo
total 4
155993 drwxr-xr-x 2 root wheel - 512 Sep 12 12:27 ./
2 drwxr-xr-x 19 root wheel - 512 Sep 12 12:27 ../
root@wimp:fsck_msdosfs# cd ..
root@wimp:usr# ls -ilaFo fsck_msdosfs/
total 4
155993 drwxr-xr-x 2 root wheel - 512 Sep 12 12:27 ./
2 drwxr-xr-x 19 root wheel - 512 Sep 12 12:27 ../
root@wimp:usr#
root@wimp:usr# mv fsck_msdosfs/ /tmp
mv: fsck_msdosfs/: Directory not empty


mv: /bin/rm: terminated with 1 (non-zero) status: Cross-device link

root@wimp:usr#

This does create a /tmp/fsck_msdosfs, which is empty and easily removed.
However, /usr/fsck_msdosfs remains unremovable.

Thanks,

Riley

John Bleichert

unread,
Sep 12, 2002, 3:59:28 PM9/12/02
to Riley J. McIntire, FreeBSD Questions
On Thu, 12 Sep 2002, Riley J. McIntire wrote:
> Date: Thu, 12 Sep 2002 12:35:25 -0700
> From: Riley J. McIntire <rile...@pacbell.net>
<big-time snippage>

> mv: /bin/rm: terminated with 1 (non-zero) status: Cross-device link
> root@wimp:usr#
>

What is this "Cross-device link" that is causing rm to fail? Do you have a
link to another filesystem buried in there? I've had links across
filesystems and devices do this before. Try to find out what/where this
link is, manually unlink it, and then 'rm -rf' the darn directory.

Have you tried a thorough, manual fsck on this partition yet? Perhaps it's
a physical disk error.

# John Bleichert
# http://vonbek.dhs.org/latest.jpg

Riley J. McIntire

unread,
Sep 12, 2002, 4:21:17 PM9/12/02
to John Bleichert, FreeBSD Questions, john.m...@alum.mit.edu
>
> Have you tried a thorough, manual fsck on this partition yet?
> Perhaps it's
> a physical disk error.
> # John Bleichert

Should have thought of that, but like I said can't bring it down single user
at the moment. Looks like the problem is here. Any ideas what would cause
this?

(note that I moved it to /usr)

root@wimp:/# ls -ialFo /usr/fsck_msdosfs/


total 4
155993 drwxr-xr-x 2 root wheel - 512 Sep 12 12:27 ./
2 drwxr-xr-x 19 root wheel - 512 Sep 12 12:27 ../

root@wimp:/#

root@wimp:/# fsck /usr
** /dev/da0s1e (NO WRITE)
** Last Mounted on /usr
** Phase 1 - Check Blocks and Sizes
** Phase 2 - Check Pathnames
BAD INODE NUMBER FOR '.' I=155993 OWNER=root MODE=40755
SIZE=512 MTIME=Sep 12 12:27 2002
DIR=/fsck_msdosfs

UNEXPECTED SOFT UPDATE INCONSISTENCY

FIX? no

Thanks!

0 new messages