166b0 [Solved] Working with symlink and learning unlink = rm the hard way - The FreeBSD Forums
The FreeBSD Forums  

Go Back   The FreeBSD Forums > Base System > General

General General questions about the FreeBSD operating system. Ask here if your question does not fit elsewhere.

Reply
 
Thread Tools Display Modes
  #1  
Old August 21st, 2009, 18:12
tekkon tekkon is offline
Junior Member
 
Join Date: Nov 2008
Posts: 17
Thanks: 6
Thanked 0 Times in 0 Posts
Default Working with symlink and learning unlink = rm the hard way

I was following this thread to mount ntfs-3g at boot time. The solution involves creating a symlink from ntfs-3g to mount_ntfs which I'm not familiar with.

I'm on FreeBSD 7.1-RELEASE. I'll describe what i did to my system.

I tried creating a symlink by putting
Code:
ln -s /sbin/mount_ntfs /usr/local/bin/ntfs-3g
in '/etc/rc.local'. I gotten this error:
Code:
ln: /usr/local/bin/ntfs-3g: File exists
at boot.

I read the ln man page some more and tried:
Code:
ln -sf /sbin/mount_ntfs /usr/local/bin/ntfs-3g
It worked. Now I learn I've gotten the order of the source and target of the linking wrong. I then issued:
Code:
ln -sf /usr/local/bin/ntfs-3g /sbin/mount_ntfs
which is the correct order I needed.

I issued the following to check the symlink. I got:
Code:
file /sbin/mount_ntfs
/sbin/mount_ntfs: broken symbolic link to `/usr/local/bin/ntfs-3g'
Then I checked /usr/local/bin/ntfs-3g and gotten the same error:
Code:
file /usr/local/bin/ntfs-3g
/usr/local/bin/ntfs-3g: broken symbolic link to `/sbin/mount_ntfs'
It seems I've now linked both files in a circle to each other. So I looked for a tool to unlink them. I issued:
Code:
unlink /sbin/mount_ntfs
and now it appears I had deleted /sbin/mount_ntfs with unlink.

Figuring that until I find a way to replace the deleted /sbin/mount_ntfs, I should just remove the broken symlink of /usr/local/bin/ntfs-3g from /sbin/mount_ntfs at this time. I made a backup this time with:
Code:
cp -RP /usr/local/bin/ntfs-3g /usr/local/bin/ntfs-3g_bak
this time in case the symlink remove procedure goes wrong again.

After issuing:
Code:
rm /usr/local/bin/ntfs-3g
surely not only the symlink but the file 'ntfs-3g' was also gone. I recovered 'ntfs-3g' from the backup to find that the broken symlink from '/sbin/mount_ntfs' has also been restored.

That was what happened. Please teach me how to safely remove symlinks between 2 binary files without removing the file itself and how to replace /sbin/mount_ntfs that I've deleted.

Last edited by tekkon; August 22nd, 2009 at 23:54. Reason: [code]
Reply With Quote
  #2  
Old August 21st, 2009, 19:29
Alt's Avatar
Alt Alt is offline
Member
 
Join Date: Nov 2008
Location: Mother Russia
Posts: 726
Thanks: 32
Thanked 77 Times in 71 Posts
Default

1. Do not use `-f` flag unless you need to FORCE action. That why you overwrited ur real binary..
2. If you do `ln -s /usr/local/bin/ntfs-3g /sbin/mount_ntfs` one time, this will create symlink "/sbin/mount_ntfs" pointing to your binary. It is *no need* to do it every boot. (If your /sbin/ is not a ramdisk lol))
3. Do not put any stuff to /etc/rc.local or /etc/rc.d or /etc anyway =) Its not linux, user startup scripts must live in /usr/local/etc/rc.d/
4. If you do `rm /sbin/mount_ntfs` it will remove object "/sbin/mount_ntfs" - no matter symlink or file. Real file not affected. (Caution if you symlink a directory and then `rm -rf` it can destroy real files)
Reply With Quote
The Following User Says Thank You to Alt For This Useful Post:
tekkon (August 21st, 2009)
  #3  
Old August 21st, 2009, 20:32
tekkon tekkon is offline
Junior Member
 
Join Date: Nov 2008
Posts: 17
Thanks: 6
Thanked 0 Times in 0 Posts
Default

Thank you for your advices.

I used -f with ln because using -s only returned the error: 'ln: /usr/local/bin/ntfs-3g: File exists'

As symlinks are created one time, how do I get a list of the symlinks created besides having to check the individual linked files?

Since I had symlinked one binary to another, removing the symlink will remove the symlink will remove the linking binary too. Is there a way to remove the symlink only without touching the binary?
Reply With Quote
  #4  
Old August 21st, 2009, 20:47
Alt's Avatar
Alt Alt is offline
Member
 
Join Date: Nov 2008
Location: Mother Russia
Posts: 726
Thanks: 32
Thanked 77 Times in 71 Posts
Default

Quote:
Originally Posted by tekkon View Post
I used -f with ln because using -s only returned the error: 'ln: /usr/local/bin/ntfs-3g: File exists'
It protected you, but you forced =)

Quote:
Originally Posted by tekkon View Post
As symlinks are created one time, how do I get a list of the symlinks created besides having to check the individual linked files?
dont understood =)

Quote:
Originally Posted by tekkon View Post
Since I had symlinked one binary to another, removing the symlink will remove the symlink will remove the linking binary too. Is there a way to remove the symlink only without touching the binary?
Read part 4 above =)
Reply With Quote
  #5  
Old August 21st, 2009, 20:49
jb_fvwm2 jb_fvwm2 is offline
Senior Member
 
Join Date: Nov 2008
Posts: 1,386
Thanks: 60
Thanked 145 Times in 130 Posts
Default

I've put a working example of symlink creation in /etc/motd (along
with other commands) so that I can grep the proper usage instantly...
(Sorry to not answer the question(s)...)
(ignoring the post immediately above, it was posted as I wrote)
Reply With Quote
  #6  
Old August 22nd, 2009, 02:12
tekkon tekkon is offline
Junior Member
 
Join Date: Nov 2008
Posts: 17
Thanks: 6
Thanked 0 Times in 0 Posts
Default

Alt:
Okay, I think I learn something new about symlinks. A symlinks is an object and cannot exist together with another object of the same name along the same path.

Since I had already issued 'ln -sf' on both '/sbin/mount_ntfs' and '/usr/local/bin/ntfs-3g' as targets, that means both mount_ntfs and ntfs-3g now is a symlink instead of the original binary.

I think reinstalling ntfs-3g can get the ntfs-3g binary back but how do I restore mount_ntfs ?

From what I had seen, the correct way to symlink the source 'ntfs-3g' to target 'mount_ntfs' is to issue:
Code:
mv /sbin/mount_ntfs /sbin/mount_ntfs.bak
before running
Code:
ln -s /usr/local/bin/ntfs-3g /sbin/mount_ntfs
am I right?

Quote:
Originally Posted by Alt View Post
dont understood =)
I thought the system had a list somewhere keeping track of all the symlinks that exist throughout the system.

jb_fvwm2:
Thanks for the good tip.

Last edited by tekkon; August 22nd, 2009 at 23:59. Reason: [code]
Reply With Quote
  #7  
Old August 22nd, 2009, 02:45
phoenix's Avatar
phoenix phoenix is offline
Moderator
 
Join Date: Nov 2008
Location: Kamloops, BC, Canada
Posts: 3,141
Thanks: 43
Thanked 703 Times in 579 Posts
Default

The argument order for ln is the same as for cp or for mv. In other words, you link from an existing file to the name of the link.

The correct ln command is # ln -s /usr/local/bin/ntfs-3g /usr/bin/mount_ntfs.

To remove a symlink is as simple as removing a file, just rm it: # rm /usr/bin/mount_ntfs After all, a symlink is just a file.

What happened, in your case, is that you wrote the arguments backwards. And it gave an error. Which you then ignored, and forced the link from a non-existent file overtop of an existing file (which wiped out the contents of ntfs-3g). Then you deleted the non-existent symlink, leaving an empty file behind.

You'll need to re-install the ntfs-3g port to get things working again. And then re-do the symlink, with the arguments in the right order.
__________________
Freddie

Help for FreeBSD: Handbook, FAQ, man pages, mailing lists.
Reply With Quote
  #8  
Old August 22nd, 2009, 06:22
Alt's Avatar
Alt Alt is offline
Member
 
Join Date: Nov 2008
Location: Mother Russia
Posts: 726
Thanks: 32
Thanked 77 Times in 71 Posts
Default

Quote:
Originally Posted by tekkon View Post
From what I had seen, the correct way to symlink the source 'ntfs-3g' to target 'mount_ntfs' is to issue 'mv /sbin/mount_ntfs /sbin/mount_ntfs.bak' before running 'ln -s /usr/local/bin/ntfs-3g /sbin/mount_ntfs' am I right?
Yes.

Quote:
Originally Posted by tekkon View Post
I thought the system had a list somewhere keeping track of all the symlinks that exist throughout the system.
Technically, a symlink is just a file. So, it lives in your filesystem =) Difference is that it have attribute saying it is symlink. In this case file content is just a path to original file which it point to.
Look this:
Code:
> ls -la s.tgz
lrwxr-xr-x  1 alt  wheel  14 22 авг 09:20 s.tgz -> sitemap.xml.gz
We do an ls and see "lrwxr-xr-x". 'l' says its symlink. Filesize is 14 cus this file is a symlink and content only path to "sitemap.xml.gz"
Reply With Quote
  #9  
Old August 22nd, 2009, 16:36
tekkon tekkon is offline
Junior Member
 
Join Date: Nov 2008
Posts: 17
Thanks: 6
Thanked 0 Times in 0 Posts
Default

Alt, phoenix:

Thanks for further explaining. I now have a better understanding of how to work with symlinks.


One last thing though, how do I replace the '/sbin/mount_ntfs' binary that I had destroyed? Since 'mount_ntfs' is part of the base system, do I need to rebuild my FreeBSD 7.1-RELEASE to get mount_ntfs back?
Reply With Quote
  #10  
Old August 22nd, 2009, 17:17
Beastie Beastie is offline
Senior Member
 
Join Date: Mar 2009
Location: /dev/earth0
Posts: 1,701
Thanks: 0
Thanked 301 Times in 245 Posts
Default

If you still have the ISO/CD, why don't you just get it back from there? It's in the /7.x-RELEASE/base directory. You'll have to merge the chunks and untar the merged file. Check install.sh for more information. You'll find mount_ntfs in /sbin obviously.

EDIT: if you don't have the ISO anymore, you can also get the base from the ftp: ftp://ftp.freebsd.org/pub/FreeBSD/re...-RELEASE/base/ (change the x to your release minor version)
__________________
May the source be with you!

Last edited by Beastie; August 22nd, 2009 at 17:30.
Reply With Quote
The Following User Says Thank You to Beastie For This Useful Post:
tekkon (August 22nd, 2009)
  #11  
Old August 22nd, 2009, 18:10
phoenix's Avatar
phoenix phoenix is offline
Moderator
 
Join Date: Nov 2008
Location: Kamloops, BC, Canada
Posts: 3,141
Thanks: 43
Thanked 703 Times in 579 Posts
Default

If you have the source tree installed, you should be able to go into /usr/src/sbin/mount_ntfs and run # make; make install to re-install it.
__________________
Freddie

Help for FreeBSD: Handbook, FAQ, man pages, mailing lists.
Reply With Quote
The Following User Says Thank You to phoenix For This Useful Post:
tekkon (August 22nd, 2009)
Reply

Tags
ntfs-3g, symlink, unlink

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Learning C programming, C99 or not marius Userland Programming & Scripting 15 December 14th, 2012 15:47
Learning FreeBSD lha General 12 January 26th, 2009 09:40
How to undo unlink operation mukembo General 4 January 4th, 2009 06:35
simple question, just learning pk7 Firewalls 7 December 31st, 2008 00:31
Simple? PF question. Just learning neurosis Firewalls 11 November 20th, 2008 12:38


All times are GMT +1. The time now is 08:05.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
The mark FreeBSD is a registered trademark of The FreeBSD Foundation and is used by The FreeBSD Project with the permission of The FreeBSD Foundation.
Web protection and acceleration provided by CloudFlare
0