Why is sshfs not shown in /proc/filesystems? - linux

One of the books on advanced linux programming states:
The /proc/filesystems entry displays the file system types known to the kernel. Note that this list isn't very useful because it is not complete: File systems can be loaded and unloaded dynamically as kernel modules.The contents of /proc/filesystems list only file system types that either are statically linked into the kernel or are currently loaded. Other file system types may be available on the system as modules but might not be loaded yet.
Now, I have:
➜ ~ ps -C sshfs
PID TTY TIME CMD
8123 ? 00:00:00 sshfs
➜ ~ mount | grep sshfs
root#ss1: on /home/wani/tmp type fuse.sshfs (rw,nosuid,nodev,relatime,user_id=0,group_id=0)
➜ ~
But ...
➜ ~ cat /proc/filesystems | grep sshfs
➜ ~

sshfs is implemented in userspace using the FUSE infrastructure. Userspace filesystems are not known to the kernel as a separate entity. The FUSE kernel-side infrastructure itself, however, is known to the kernel. On my system:
$ cat /proc/filesystems
nodev sysfs
nodev rootfs
nodev ramfs
...
ext4
cramfs
...
nodev fuse
nodev fusectl
...
Note the last two lines; the kernel is aware of a fuse filesystem, which is essentially an adapter interface that lets filesystem services to be provided by userspace processes.

Related

Programmatically obtaining USB file system format

I need to mount a USB drive to an embedded system, running Linux. The USB could be in FAT, NTFS or ExFAT format.
How can i handle this in code so that I pass proper type in mount command such as
mount -t vfat /dev/sda1 /mnt
So I have tried mount with:
mount -t vfat,ntfs /dev/sda1 /mnt
This command gives invalid argument, but it successfully mounts the USB if USB is in NTFS or VFAT format. However if i try to give
mount -t vfat,ntfs,exfat /dev/sda1 /mnt
The command fails.
Any pointers will be really helpful.
From the mount manual page:
If no -t option is given, or if the auto type is specified,
mount will try to guess the desired type. Mount uses the blkid
library for guessing the filesystem type...
Is libblkid available for your embedded system?
Try:
mount -t auto /dev/sda1 /mnt
or
mount /dev/sda1 /mnt
And as mentioned in the comments, make sure the kernel on your embedded system supports exfat.

How to get the list of clients connected to an NFS server within a local network? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 1 year ago.
The community reviewed whether to reopen this question last month and left it closed:
Original close reason(s) were not resolved
Improve this question
I have an NFS server with folder permissions as follows. There are 50 clients which need to connect to this server within the same network. I would like to know what's the command to lookup which are the clients accessing this server from the server.
NFS Server configuration file looks like this.
[root#server ~]# cat /etc/exports
/home/guests *(rw,sync)
/india *(rw,sync)
Below are the list of shared folders
[root#server ~]# showmount -e
Export list for server.sanith.com:
/india *
/home/guests *
For testing purpose I have now connected one client to the server. Below output is from the "client2" machine.
[root#client2 ~]# showmount -e 192.168.1.10
Export list for 192.168.1.10:
/india *
/home/guests *
[root#client2 ~]# mount -t nfs 192.168.1.10:/india /test
[root#client2 ~]# mount
/dev/sda2 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
/dev/sda3 on /home type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
gvfs-fuse-daemon on /root/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
192.168.1.10:/india on /test type nfs (rw,vers=4,addr=192.168.1.10,clientaddr=192.168.1.12)
I tried using showmount -a and showmount -d but not sure what am missing which's not list the client machines connected.
[root#server ~]# showmount -a
All mount points on server.sanith.com:
[root#server ~]# man showmount
[root#server ~]# showmount -d
Directories on server.sanith.com:
[root#server ~]# netstat -an | grep 192.168.1.10:2048
[root#server ~]# netstat -an | grep 192.168.1.10:2049
[root#server ~]# cat /var/lib/nfs/rmtab
[root#server ~]#
Note : The firewall is disabled on the server temporarily during this testing.
Please advise.
You can find connected NFS clients by running the following on the NFS server:
netstat | grep :nfs
Since Linux kernel 5.3 you can use special directory called /proc/fs/nfsd/clients.
You can check Kernel version by uname -r command
NFS works over both UDP and TCP, only open TCP connections will show in netstat or ss. Also, as a distributed filesystem, it has (historically) had its fair share of problemsPDF (state, cache, locking, notifications, security — some of which have solutions through extra RPC features, e.g. rpc.statd).
On a Linux NFS server (see man rpc.mountd) the client mount/unmount requests are recorded in /var/lib/nfs/rmtab, just like /etc/mtab, sothe answer should be:
cat /var/lib/nfs/rmtab
If it's empty, then you either have a problem with rpc.mountd (so you should check the RPC services running), or all the clients are NFSv4 which doesn't use this feature.
On versions I've checked rmtab is presented as:
10.1.2.0/24:/path/to/export1:0x000...flags
10.1.2.10:/path/to/export1:0x0000...flags
10.1.2.22:/path/to/export1:0x0000...flags
10.1.2.0/24:/path/to/export2:0x000...flags
10.1.2.22:/path/to/export2:0x0000...flags
10.1.2.99:/path/to/export2:0x0000...flags
i.e., each mount point is listed, followed by the clients using it.
Note the caveat in the man page:
However, this file is mostly ornamental. One, the client can continue to use the file handle even after calling rpc.mountd's UMOUNT procedure. And two, if a client reboots without notifying rpc.mountd, a stale entry will remain in rmtab.
The /proc/fs/nfsd/client approach (#Vsevolod Gromov's answer) in newer kernels should be better in this respect, but because it only supports NFSv4 clients which should be better behaved.
Since netstat is not always available for it is to be replaced by ss you also might use
ss -a|grep nfs
netstat -a | grep nfs
This worked for me on Ubuntu GNOME 16.04.

mount: you must specify the filesystem type

I was trying to execute qemu while following the qemu/linaro tutorial,
https://developer.mozilla.org/en-US/docs/Mozilla/Developer_guide/Virtual_ARM_Linux_environment
I was executing the command,
sudo mount -o loop,offset=106496 -t auto vexpress.img /mnt/tmp
mount: you must specify the filesystem type
so i did fdisk on the img file and got the following,
Device Boot Start End Blocks Id System
vexpress.img1 * 63 106494 53216 e W95 FAT16 (LBA)
vexpress.img2 106496 6291455 3092480 83 Linux
The filesystem is Linux according to the fdisk command. But I get error,
sudo mount -o loop,offset=106496 -t Linux vexpress.img /mnt/tmp
mount: unknown filesystem type 'Linux'
Kindly help.
You correctly decide to mount the particular partition by specifying its offset but the offset parameter is in bytes and fdisk shows the offset in blocks (the block size is shown before the partition list --- usually 512). For the block size 512 the command would be:
sudo mount -o loop,offset=$((106496*512)) -t auto vexpress.img /mnt/tmp
If the automatic file system type detection does not still work there is another problem. Linux is not really a file system type. In the partition table it is a collective type used for multiple possible particular file systems. For mount you must specify the particular file system. In Linux you can list the supported ones by cat /proc/filesystems.

Busybox SUID on NFS rootfs

I am building a Linux system from the bottom for a Beagle Bone board. I have compiled the vanilla kernel and built a basic root file system with busybox. The system is booted with U-boot, while the rootfs is located on a Linux PC and exported through NFS:
/path/to/rootfs 10.42.0.17(rw,wdelay,no_root_squash,no_subtree_check,sec=sys,rw,secure,no_root_squash,no_all_squash)
The U-boot bootargs are:
bootargs console=ttyO0,115200n8 root=/dev/nfs rw nfsroot=${serverip}:/path/to/rootfs,v3,tcp ip=dhcp
I've encountered a problem when trying to get su working for non-root users. In order to work around the problem people over internet are suggesting to set the suid bit for the busybox binary.
After doing so:
$ sudo chmod u+s busybox
and verifying:
$ ls -la
...
-rwsr-xr-x 1 myuser myuser 1882976 Jan 13 21:47 busybox
...
$ stat -c "%a %n" busybox
4755 busybox
Something went wrong. The kernel is booting and all of the usual messages are displayed, but it is getting stuck at the end, and no login line is displayed. Here are last few lines of the booting sequence:
[ 3.776185] IP-Config: Complete:
[ 3.779656] device=eth0, hwaddr=c8:a0:30:c5:80:e9, ipaddr=10.42.0.17, mask=255.255.255.0, gw=10.42.0.1
[ 3.789877] host=10.42.0.17, domain=, nis-domain=(none)
[ 3.795822] bootserver=10.42.0.1, rootserver=10.42.0.1, rootpath=
[ 3.802492] nameserver0=10.42.0.1
[ 3.871575] VFS: Mounted root (nfs filesystem) on device 0:15.
[ 3.879903] devtmpfs: mounted
[ 3.883713] Freeing unused kernel memory: 380K (c07ef000 - c084e000)
If removing the flag, the things are returning to normal:
....
[ 3.862291] Freeing unused kernel memory: 380K (c07ef000 - c084e000)
10.42.0.17 login:
If setting the flag from within the running shell on the Beagle Bone board itself, the shell is stopping responding right after the chmod is performed.
I suspect it is something to do with the way the NFS is exporting the rootfs, but it's only a guess, so qualified explanation and possible solution would be helpful.
After some research I will answer my question myself. The answer is very simple. In order the above to work, the busybox binary should be owned by root:root. The simplest solution is just to change the ownership.

UBIFS mount in busybox via fstab does not recognize relatime option

I am getting this error when I try to mount my UBIFS filesytem:
mount -o remount,rw /config
UBIFS error (pid 1265): ubifs_parse_options: unrecognized mount option "relatime" or
missing value
The content of my fstab is :
root#drgos:~# cat /etc/fstab
# WARNING: this is an auto generated file, please use uci to set static filesystems
/dev/ubi0_0 /config ubifs ro 0 0
And when I type mount the result is :
root#drgos:~# mount
rootfs on / type rootfs (rw)
none on /proc type proc (rw,relatime)
none on /sys type sysfs (rw,relatime)
tmpfs on /dev type tmpfs (rw,relatime,size=512k)
none on /dev/pts type devpts (rw,relatime,mode=600)
/dev/ubi0_0 on /config type ubifs (ro,relatime)
none on /proc/bus/usb type usbfs (rw,relatime)
I do not understand why I have the option relatime since that one is not present in my fstab!
I am using BusyBox v1.11.2 (2014-01-13 09:35:41 CET) multi-call binary.
These options are dependent on the Linux kernel version. relatime is a general mount options. relatime is the default for newer Linux kernels. Other filesystems may quietly ignore unknown options, whereas ubifs is failing. You can try mount -o remount,rw,noatime,norelatime /config. Your mount command shows the /config directory is mounted with relatime; this is information that busybox mount applet collected.
This information is collected with the getmntent_r() function. If busybox is dynamically linked, then the 'C' library may be giving this information as part of the *mnt_opts* string.
The idea with mount -o remount,rw,noatime,norelatime /config is to try and over-ride this information so that UbiFs will be happy with its mount options. The other way is to simply umount and then mount again manually.
umount /config
mount -t ubifs /dev/ubi0_0 /config
This way previous mount information will not be retrieved.

Resources