How does one mount UNC root? (SMB / CIFS)
Solution 1
I found it...
It's called smbnetfs.
It does everything I asked for in the question, although for listing and some other operations it's really slow.
Solution 2
Just as a side note: Every time someone on earth creates a smb / samba share of the root directory of a machine a Network Administrator in heaven loses his wings.
I've tried mount -t cifs "//"
Your syntax is wrong, it's incomplete, and you can't designate a share on the server as "/".
[1] Go to the server and create a share of "/" if that is what you truly want to do but name the share ... I don't know ... how about "root"
[2] Create a mount point on the client to mount the share - let's say /home/agnes/servername
[3] Then mount with a command that looks something like this:
sudo mount -t cifs //servername/root /home/agnes/servername -o some-list-of-options
Will it do everything you want it to do in your original post? I have no idea.
You can also go old school I guess and use smbclient:
smbclient //servername/root
You will end up with the prompt:
smb: >
If you enter help you will see the list of commands at your disposal:
? allinfo altname archive backup
blocksize cancel case_sensitive cd chmod
chown close del deltree dir
du echo exit get getfacl
geteas hardlink help history iosize
lcd link lock lowercase ls
l mask md mget mkdir
more mput newer notify open
posix posix_encrypt posix_open posix_mkdir
posix_rmdir posix_unlink posix_whoami print prompt
put pwd q queue quit
readlink rd recurse reget rename
reput rm rmdir showacls setea
setmode scopy stat symlink tar
tarmode timeout translate unlock volume
vuid wdel logon listconnect
showconnect tcon tdis tid logoff
..
Related videos on Youtube
BurninateSE
Updated on September 18, 2022Comments
-
BurninateSE over 1 year
I'm in a situation where I need to mount the UNC root, i.e. "\" or "smb://". I can open up nautilus and go to "smb://" but I need to actually do things with that, such as: readdir, mkdir, unlink, rmdir, open, read, write, etc. from the standard POSIX filesystem APIs. Is there existing software that lets me do that?
I've tried
mount -t cifs "//"
but it gives memount error: UNC name too short
I've also tried
mount -t cifs "smb://"
but that gives me aMounting cifs URL not implemented yet. Attempt to mount smb://
I've tried all those smb commands of old, but they're no longer present - I believe which have moved to cifs instead. I've also tried these fancy new gvfs / gio things, which I suppose is a gobject based userland mounting system, but
gio mount smb://
gives me...gio: smb:///: Location is already mounted
... Mounted where? I can go to it in nautilus, but again I can't do anything with that. I thought it might be mounted at /run/user/1000/gvfs but that program-fuse-folder-thing doesn't seem to do much on it's own unless I specifically mount things using the command.
I don't even really require to be able to list smb:// or even smb://server/, but I need ALL smb://server/shares/ to be available, which the same functionality as if I had mounted them using smb or gvfs (e.g. listing, making folders, deleting things, opening files, and also authentication).
To further clarify, any and all applications need to be able to basic perform filesystem API functions on any and all unc paths, at least to the extent provided by gvfs or cifs. For example, I should be able to:
cd /some/path/server1/share1/folder1 cat file1 mkdir newfolder2 cd ../existingfolder3 touch file2 cd /some/path/server2/share2 rmdir existingfolder4
... etc. Bonus points if I could
ls /some/path/server1
There are plenty of fuse libraries out there, so I was considering writing a little script that automatically mounted the shares when requested, and then just passing through the commands to the mount points, but I certainly don't want to reinvent the wheel, and I'd also love for something much for portable than anything I would have the time to develop. But if this is the easiest way then I can start writing some code and either post it here or start a new question when I need help with it.
Thank you!
-
BurninateSE over 5 yearsHey, this is a spectacular tool, thank you! Especially for answering so quickly. But I should probably clarify in my question that I need to be able to: readdir, mkdir, unlink, rmdir, open, read, etc. from the standard POSIX filesystem API with the smb monts.
-
N0rbert over 5 yearsI recommend to read Samba documentation and determine how they do all these things. From my experience we have two stages - share discovery and share mount. Discovery is done by
smbtree
andsmbclient -L host
. Then mounted share may be manipulated bycifs-utils
,smbmount
, GVFS and so on. Also see ArchLinux wiki for brief information about Samba. -
BurninateSE over 5 yearsSo then I would need the share share discovery and share mount stages to happen without any interaction at all. I'll take a look through the documentation links and report back, thanks!
-
BurninateSE over 5 yearsFantastic reply, thank you. I like the remark at the beginning too, but I am working with a windows-related thing so that's to be expected of course xD But this still doesn't solve my problem unfortunately - I have something that expects the exact same api for browsing the UNC root as it does the files inside of a samba share. Modifying the thing is not an option for both the reasons that it's not the simplest and more direct thing to do, but also another reason which I will not list. I would prefer to use the same API everything else in Linux is using, because that seems most correct.
-
BurninateSE over 5 yearsAnd also,
Your syntax is wrong, it's incomplete, and you can't designate a share on the server as "/"
It is wrong and incomplete which is why I'm asking for help, but I'm not trying to designate a share on a server as "/", I'm asking for something that will automatically translate that for me.