Linux: "fstab" with additional mount options? - linux

I'm using "GlusterFS" Client, to mount the GlusterFS Volume on my Web Server. Below is the MOUNT command when I manually mount from the command line:
# mount -t glusterfs -o aux-gfid-mount gluster1:/gv0 /var/www/html
I don't know how to put that -o aux-gfid-mount option inside the /etc/fstab. So my fstab is still, lacking that option:
gluster1:/gv0 /var/www/html/ glusterfs defaults,_netdev,fetch-attempts=5 0 0
How do I put that -o aux-gfid-mount option inside the fstab please?

As per my comment:
gluster1:/gv0 /var/www/html/ glusterfs defaults,_netdev,aux-gfid-mount,fetch-attempts=5 0 0

Related

Blob Storage Permament mounting in redhat linux

I have a linux server where i had mounted blog storage but it is temporary mount everytime i restart the machine i have to run this below command manually
sudo blobfuse /sfp/publicstorage134/blobstorage123 --tmp-path=/mnt/rec/mountpath --config-file=/user1/connection_sf.cfg -o attr_timeout=180 -o entry_timeout=120 -o negative_timeout=180 -o allow_other
How can i make this stoarge mount permanently instead of mounting with this command after every restart. Is it possible to put this in /etc/fstab?
The recommendation is to create a script, such as mount.sh or you can also add blobfuse directly to /etc/fstab
Add the following line to use mount.sh:
/<path_to_blobfuse>/mount.sh </path/to/desired/mountpoint> fuse _netdev
OR
Add the following line to run without mount.sh:
blobfuse /home/azureuser/mntblobfuse fuse delay_connect,defaults,_netdev,--tmp-path=/home/azureuser/tmppath,--config-file=/home/azureuser/connection.cfg,--log-level=LOG_DEBUG,allow_other 0 0

Azure File Share Owner/Group Permissions Revert On VM Reboot

I am mounting an Azure File Share to /elasticdata/azshare on my Ubuntu 16.04 LTS virtual machine. I mount the drive using the following script:
sudo mkdir /elasticdata/fileshare
if [ ! -d "/etc/smbcredentials" ]; then
sudo mkdir /etc/smbcredentials
fi
if [ ! -f "/etc/smbcredentials/fileshare.cred" ]; then
sudo bash -c 'echo "username=fileshare" >> /etc/smbcredentials/fileshare.cred'
sudo bash -c 'echo "password=password" >> /etc/smbcredentials/fileshare.cred'
fi
sudo chmod 600 /etc/smbcredentials/fileshare.cred
sudo bash -c 'echo "//fileshare.file.core.windows.net/analysis /elasticdata/fileshare cifs nofail,vers=3.0,credentials=/etc/smbcredentials/fileshare.cred,dir_mode=0777,file_mode=0777,serverino" >> /etc/fstab'
sudo mount -t cifs //fileshare.file.core.windows.net/analysis /elasticdata/fileshare -o vers=3.0,credentials=/etc/smbcredentials/fileshare.cred,dir_mode=0777,file_mode=0777,serverino,uid=$(id -u elasticsearch),gid=$(id -g elasticsearch)
In my last line, I set the owner and the group of the mount location to be that of the user elasticsearch. I can verify this is true after the drive is mounted.
I then make a symlink like so:
ln -s /elasticdata/fileshare/analysis /etc/elasticsearch
In /etc/elasticsearch/analysis, I can see the owner and group to be that of the elasticsearch user.
When I restart my VM, the owner and group permissions I set revert back to that of the root user and my elasticsearch cluster is unable to start due to the following error:
[HTTP/1.1 500 Internal Server Error]{"error":{"root_cause":[{"type":"access_control_exception","reason":"access denied (\"java.io.FilePermission\" \"/etc/elasticsearch/analysis/charmapping.txt\" \"read\")"}],"type":"access_control_exception","reason":"access denied (\"java.io.FilePermission\" \"/etc/elasticsearch/analysis/charmapping.txt\" \"read\")"},"status":500}`.
How can I prevent the permissions from reverting? Or, how can I let elasticsearch gain access to the files a different way?
Try using /etc/fstab to mount the cifs filesystem at boot time.
A basic /etc/fstab looks like this
/dev/hda2 / ext2 defaults 1 1
/dev/hdb1 /home ext2 defaults 1 2
/dev/cdrom /media/cdrom auto ro,noauto,user,exec 0 0
/dev/fd0 /media/floppy auto rw,noauto,user,sync 0 0
proc /proc proc defaults 0 0
/dev/hda1 swap swap pri=42 0 0
My guess is you want to add a line to the file for the cifs file system. It should look something like this.
//fileshare.file.core.windows.net/analysis /elasticdata/fileshare cifs defaults,uid=<user id you want>,gid=<group id you want> 0 0

Mount using offline file system (OFS+FUSE)

I am trying to explore OFS (Offline file system) built on the top of FUSE and still exploring it.
http://offlinefs.sourceforge.net/wiki/
I installed it on both Fedora and Ubuntu 14.04,however whenever I try to mount any local directory using mount utility, I get the “Transport endpoint not connected” for mount directory.
This is how I am running it :
mount –t ofs file:/home/user/Downloads/src /home/user/Downloads/mountdir
The above executes without error and if I run mount command on ../mountdir ,it correctly says
ofs on /mountdir type fuse.ofs.
However when I try to browse /mountdir I get “Transport endpoint not connected”.I even tried unmounting and restarting the machine,no use!
Can someone point me to a right direction.
You're using it incorrectly, you must have two forward slashes in the URI that is specified as the mount device i.e. file://.
As an e.g.
$ sudo mount -t ofs file://usr /tmp/mnt
$ ls /tmp/mnt
bin/ etc/ games/ include/ lib/ lib32/ libx32/ local/ sbin/ share/ src/
$ sudo umount /tmp/mnt
with a single file:/ we have:
$ sudo mount -t ofs file:/usr /tmp/mnt
$ ls /tmp/mnt
ls: cannot access /tmp/mnt: Transport endpoint is not connected
$ sudo umount /tmp/mnt
Now if you're intending to use a remote filesystem with OFS, which is the primary use-case, you have to first install the relevant remote filesystem packages on the OS you're using, then use, for example, if we've got cifs, which is the newer name for smb/samba:
sudo mount -t ofs cifs://127.0.0.1/Music /tmp/music
Now, if you need to pass options to cifs, such as the password/username/a config file, you can use the remoteoptions parameter, so for example for guest account access:
sudo mount -t ofs -o remoteoptions=guest cifs://127.0.0.1/Music /tmp/music
or, if you're using a credentials file (see mount.cifs manual page), you can use:
sudo mount -t ofs -o remoteoptions=credentials=/etc/remotecreds.conf cifs://127.0.0.1/Music /tmp/music
for remote options, you use a : as the separator (it gets swapped for a , when passed into the underlying mount command), so to mount as an explicit user/password:
sudo mount -t ofs -o remoteoptions=username=mike:password=mike1 cifs://127.0.0.1/Music /tmp/music
It only worked in my case (ubuntu 16) with the following command:
mount -t ofs -o remoteoptions=username=XXXXX:password=xxxx:guest:vers=3.0 cifs://HOST/dir /mountpoint

What happens if you mount to a non-empty mount point with fuse?

I am new to fuse. When I try to run a FUSE client program I get this error:
fuse: mountpoint is not empty
fuse: if you are sure this is safe, use the 'nonempty' mount option
I understand that a mountpoint is the directory where you will logically attach the FUSE filesystem. What will happen if I mount to this location? What are the dangers? Is it just that the directory will be overwritten? Basically: what will happen if you mount to a non empty directory?
You need to make sure that the files on the device mounted by fuse will not have the same paths and file names as files which already existing in the nonempty mountpoint. Otherwise this would lead to confusion. If you are sure, pass -o nonempty to the mount command.
You can try what is happening using the following commands.. (Linux rocks!) .. without destroying anything..
// create 10 MB file
dd if=/dev/zero of=partition bs=1024 count=10240
// create loopdevice from that file
sudo losetup /dev/loop0 ./partition
// create filesystem on it
sudo e2mkfs.ext3 /dev/loop0
// mount the partition to temporary folder and create a file
mkdir test
sudo mount -o loop /dev/loop0 test
echo "bar" | sudo tee test/foo
# unmount the device
sudo umount /dev/loop0
# create the file again
echo "bar2" > test/foo
# now mount the device (having file with same name on it)
# and see what happens
sudo mount -o loop /dev/loop0 test
Just add -o nonempty in command line, like this:
s3fs -o nonempty <bucket-name> </mount/point/>
Apparently nothing happens, it fails in a non-destructive way and gives you a warning.
I've had this happen as well very recently. One way you can solve this is by moving all the files in the non-empty mount point to somewhere else, e.g.:
mv /nonEmptyMountPoint/* ~/Desktop/mountPointDump/
This way your mount point is now empty, and your mount command will work.
For me the error message goes away if I unmount the old mount before mounting it again:
fusermount -u /mnt/point
If it's not already mounted you get a non-critical error:
$ fusermount -u /mnt/point
fusermount: entry for /mnt/point not found in /etc/mtab
So in my script I just put unmount it before mounting it.
Just set "nonempty" as an optional value in your /etc/fstab
For example:
## mount a bucket
/usr/local/bin/s3fs#{your_bucket_name} {local_mounted_dir} fuse _netdev,url={your_bucket_endpoint_url},allow_other,nonempty 0 0
## mount a sub-directory of bucket, Do like this:
/usr/local/bin/s3fs#{your_bucket_name}:{sub_dir} {local_mounted_dir} fuse _netdev,url={your_bucket_endpoint_url},allow_other,nonempty 0 0
force it with -l
sudo umount -l ${HOME}/mount_dir

How do you force a CIFS connection to unmount

I have a CIFS share mounted on a Linux machine. The CIFS server is down, or the internet connection is down, and anything that touches the CIFS mount now takes several minutes to timeout, and is unkillable while you wait. I can't even run ls in my home directory because there is a symlink pointing inside the CIFS mount and ls tries to follow it to decide what color it should be. If I try to umount it (even with -fl), the umount process hangs just like ls does. Not even sudo kill -9 can kill it. How can I force the kernel to unmount?
I use lazy unmount: umount -l (that's a lowercase L)
Lazy unmount. Detach the filesystem
from the filesystem hierarchy now, and
cleanup all references to the
filesystem as soon as it is not busy
anymore. (Requires kernel 2.4.11 or
later.)
umount -a -t cifs -l
worked like a charm for me on CentOS 6.3. It saved me a server reboot.
On RHEL 6 this worked:
umount -f -a -t cifs -l
This works for me (Ubuntu 13.10 Desktop to an Ubuntu 14.04 Server) :-
sudo umount -f /mnt/my_share
Mounted with
sudo mount -t cifs -o username=me,password=mine //192.168.0.111/serv_share /mnt/my_share
where serv_share is that set up and pointed to in the smb.conf file.
I had this issue for a day until I found the real resolution. Instead of trying to force unmount an smb share that is hung, mount the share with the "soft" option. If a process attempts to connect to the share that is not available it will stop trying after a certain amount of time.
soft Make the mount soft. Fail file system calls after a number of seconds.
mount -t smbfs -o soft //username#server/share /users/username/smb/share
stat /users/username/smb/share/file
stat: /users/username/smb/share/file: stat: Operation timed out
May not be a real answer to your question but it is a solution to the problem
There's a -f option to umount that you can try:
umount -f /mnt/fileshare
Are you specifying the '-t cifs' option to mount? Also make sure you're not specifying the 'hard' option to mount.
You may also want to consider fusesmb, since the filesystem will be running in userspace you can kill it just like any other process.
Try umount -f /mnt/share. Works OK with NFS, never tried with cifs.
Also, take a look at autofs, it will mount the share only when accessed, and will unmount it afterworlds.
There is a good tutorial at www.howtoforge.net
I had a very similar problem with davfs. In the man page of umount.davfs, I found that the -f -l -n -r -v options are ignored by umount.davfs. To force-unmount my davfs mount, I had to use umount -i -f -l /media/davmount.
umount -f -t cifs -l /mnt &
Be careful of &, let umount run in background.
umount will detach filesystem first, so you will find nothing abount /mnt. If you run df command, then it will umount /mnt forcibly.
Approaching this problem sideways:
If you can't unmount because the filesystem is busy, is your ssh/terminal session cd'd into the mount directory, therefore making the filesystem busy?
For me, the solution was to cd into my home, then sudo umount worked flawlessly.
cd ~
umount /path/to/my/share
I would post this as a comment, but I have insufficient reputation. Hoping to spare someone else the forehead slap.
I experienced very different results regarding unmounting a dead cifs mount and found several tricks to bypass the problem temporarily.
Let's start with the mountpoint command. It can be useful to analyze the status of a mount:
mountpoint /mnt/smb_share
Usually it returns is a mountpoint or / is not a mountpoint.
But it can even return:
No such device
Transport endpoint is not connected
<nothing / stale>
For every result expect of is not a mountpoint there is a chance of unmounting.
You could try the usual way:
umount /mnt/smb_share
or force mode:
umount /mnt/smb_share -f
But often the force does not help. It simply returns the same nasty device is busy message.
Then the only option is to use the lazy mode:
umount /mnt/smb_share -l
BUT: This does not unmount anything. It only "moves" the mount to the root of the system, which can be seen as follows:
# lsof | grep mount | grep cwd
mount.cif 3125 root cwd unknown / (stat: No such device)
mount.cif 3150 root cwd unknown / (stat: No such device)
It is even noted in the documentation:
Lazy unmount. Detach the filesystem from the file hierarchy
now, and clean up all references to this filesystem as soon
as it is not busy anymore.
Now if you are unlucky, it will stay there forever. Even killing the process probably does not help:
kill -9 $pid
But why is this a problem? Because mount /mnt/smb_share does not work until the lazy unmounted path is really cleaned up by the Linux Kernel. And this is even mentioned in the documentation of umount. "lazy" should only be used to avoid a long shutdown / reboot times:
A system reboot would be expected in near future if you’re
going to use this option for network filesystem or local
filesystem with submounts. The recommended use-case for
umount -l is to prevent hangs on shutdown due to an
unreachable network share where a normal umount will hang due
to a downed server or a network partition. Remounts of the
share will not be possible.
Workarounds
Use a different SMB version
If you still have hopes that the lazy unmounted path will ever be not busy anymore and cleaned up by the Linux Kernel or you can't reboot at the moment, then you are maybe lucky and your SMB server supports different protocol versions. By that we can use the following trick:
Lets say you mounted your share as follows:
mount.cifs //smb.server/share /mnt/smb_share -o username=smb_user,password=smb_pw
By that Linux automatically tries the maximum support SMB protocol version. Maybe 3.1. Now, you can force this version and it won't mount as expected:
mount.cifs //smb.server/share /mnt/smb_share -o username=smb_user,password=smb_pw,vers=3.1
But then simply try a different version:
mount.cifs //smb.server/share /mnt/smb_share -o username=smb_user,password=smb_pw,vers=3.0
or maybe 2.1:
mount.cifs //smb.server/share /mnt/smb_share -o username=smb_user,password=smb_pw,vers=2.1
Change the IP of the SMB server
If you are able to change the IP address or add a second IP to your SMB server, you can use this to mount the same server.
Dirty: Forward the traffic
Lets say the SMB server has the IP address 10.0.0.1 and the mount is really dead. Then create this iptables rule:
iptables -t nat -A OUTPUT -d 10.0.0.250 -j DNAT --to-destination 10.0.0.1
Now change your mount rule accordingly, so it mounts the samba server through IP 10.0.0.250 instead of 10.0.0.1 and voila, its mounted without server reboot. Dirty, but it works. PS This rule does not survive a reboot, so you should mount the SMB server manually and leave the /etc/fstab as usual.
More debugging
If you want to check if samba connection itself is theoretically working, you could try to list all SMB shares of the server through SMB3 as follows:
smbclient //smb.server -U "smb_user" -m SMB3 -L
or to view the content of a share with SMB1:
smbclient //smb.server -U "smb_user" -m NT1 -c ls
On RHEL 6 this worked for me also:
umount -f -a -t cifs -l FOLDER_NAME
A lazy unmount will do the job for you.
umount -l <mount path>

Resources