Unable to mount files in Vagrant - permissions

Error description
I'm unable to mount files in Vagrant or Docker, so it seems like it's an issue caused by some kind of a permission error.
My OS is Ubuntu 18.04 LTS (Bionic Beaver), I'm not running any access control modules like SELinux as far as I'm aware.
The Docker-related discussion of the error is found in another question:
Unable to mount files in Docker
Troubleshooting Vagrant
As a result I'm unable to mount files into Vagrant boxes (even though I have vboxsf):
Vagrant was unable to mount VirtualBox shared folders. This is usually
because the filesystem "vboxsf" is not available. This filesystem is
made available via the VirtualBox Guest Additions and kernel module.
Please verify that these guest additions are properly installed in the
guest. This is not a bug in Vagrant and is usually caused by a faulty
Vagrant box. For context, the command attempted was:
mount -t vboxsf -o uid=1000,gid=1000 srv_salt /srv/salt
The error output from the command was:
/sbin/mount.vboxsf: mounting failed with the error: No such device
I have specified these statements in Vagrantfile and it works on my colleagues local builds, but in my build these files do not get mounted or copied into the boxes:
host.vm.synced_folder "salt/", "/srv/salt"
host.vm.synced_folder "pillar/", "/srv/pillar"
Conclusion
It seems something is very messed up on my local machine when it comes to copying over files, possibly has to do with how my user is configured and what access it has to mounting files into VMs and containers.
If anyone can shed some light on this I'd appreciate it.
Updates
1)
As user #BMitch suggested I went through my "Virtualbox Guest Additions" installation.
Whenever I do an update of my packages I log this into logfiles, found this from update-20180405_153850.txt, almost 2 months ago.
Preparing to unpack .../virtualbox-guest-additions-iso_5.1.34-0ubuntu1.16.04.2_all.deb ...
Unpacking virtualbox-guest-additions-iso (5.1.34-0ubuntu1.16.04.2) over (5.0.40-0ubuntu1.16.04.1) ...
But this doesn't make sense to me.. my bootstrapping script (vagrant up'ing the boxes) fails the first time I run it with this:
Vagrant was unable to mount VirtualBox shared folders. This is usually
because the filesystem "vboxsf" is not available. This filesystem is
made available via the VirtualBox Guest Additions and kernel module.
Please verify that these guest additions are properly installed in the
guest. This is not a bug in Vagrant and is usually caused by a faulty
Vagrant box. For context, the command attempted was:
mount -t vboxsf -o uid=1000,gid=1000 srv_salt /srv/salt
The error output from the command was:
/sbin/mount.vboxsf: mounting failed with the error: No such device
Traceback (most recent call last):
File "launch-vagrant.py", line 166, in <module>
main()
File "launch-vagrant.py", line 120, in main
vagrant()
File "launch-vagrant.py", line 95, in vagrant
main()
File "launch-vagrant.py", line 67, in main
start()
File "launch-vagrant.py", line 83, in start
_exec('vagrant', 'up')
File "launch-vagrant.py", line 129, in _exec
subprocess.check_call(list(args))
File "/usr/lib/python3.6/subprocess.py", line 291, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['vagrant', 'up']' returned non-zero exit status 1.
The second time I run it it succeeds but with the following warning message:
Copy iso file /usr/share/virtualbox/VBoxGuestAdditions.iso into the box /tmp/VBoxGuestAdditions.iso
Mounting Virtualbox Guest Additions ISO to: /mnt
mount: /dev/loop0 is write-protected, mounting read-only
Installing Virtualbox Guest Additions 5.2.11 - guest version is unknown
Verifying archive integrity... All good.
Uncompressing VirtualBox 5.2.11 Guest Additions for Linux........
VirtualBox Guest Additions installer
Removing installed version 5.2.11 of VirtualBox Guest Additions...
Copying additional installer modules ...
Installing additional modules ...
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel modules.
This system is currently not set up to build kernel modules.
Please install the Linux kernel "header" files matching the current kernel
for adding new hardware support to the system.
The distribution packages containing the headers are probably:
kernel-devel kernel-devel-3.10.0-693.21.1.el7.x86_64
VirtualBox Guest Additions: Starting.
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel modules.
This system is currently not set up to build kernel modules.
Please install the Linux kernel "header" files matching the current kernel
for adding new hardware support to the system.
The distribution packages containing the headers are probably:
kernel-devel kernel-devel-3.10.0-693.21.1.el7.x86_64
An error occurred during installation of VirtualBox Guest Additions 5.2.11. Some functionality may not work as intended.
In most cases it is OK that the "Window System drivers" installation failed.
Clearly, this is the VBox Guest Additions installed in the actual boxes and not on my local machine.
I did however change the file mode for /usr/share/virtualbox/VBoxGuestAdditions.iso so maybe that will fix the issue:
petrus#DD-XPS-15-9550:/usr/share/virtualbox$ ll
total 56656
drwxr-xr-x 3 root root 4096 maj 14 00:28 ./
drwxr-xr-x 384 root root 16384 maj 16 12:58 ../
drwxr-xr-x 2 root root 12288 maj 13 23:06 nls/
-rw-r--r-- 1 root root 57970688 apr 20 15:50 VBoxGuestAdditions.iso
-rwxr-xr-x 1 root root 2600 nov 29 2016 VBox.sh*
-rwxr-xr-x 1 root root 4163 apr 13 18:37 VBoxSysInfo.sh*
petrus#DD-XPS-15-9550:/usr/share/virtualbox$ sudo chmod ugo+w VBoxGuestAdditions.iso
[sudo] password for petrus:
petrus#DD-XPS-15-9550:/usr/share/virtualbox$ ll
total 56656
drwxr-xr-x 3 root root 4096 maj 14 00:28 ./
drwxr-xr-x 384 root root 16384 maj 16 12:58 ../
drwxr-xr-x 2 root root 12288 maj 13 23:06 nls/
-rw-rw-rw- 1 root root 57970688 apr 20 15:50 VBoxGuestAdditions.iso
-rwxr-xr-x 1 root root 2600 nov 29 2016 VBox.sh*
-rwxr-xr-x 1 root root 4163 apr 13 18:37 VBoxSysInfo.sh*

To the vagrant problem:
By default Vagrant mounted the folder of host Vagrant file to '/vagrant'. Test the output of 'ls -l /vagrant' if the basic file system mount works.
The 'ls' command should show your Vagrantfile as a minimum in '/vagrant'.
If the Vagrantfile is visible in the virtual machine basically the mount works with vagrant.
host.vm.synced_folder "salt/", "/srv/salt"
host.vm.synced_folder "pillar/", "/srv/pillar"
It seem you mount your additional folder relative to your Vagrantfile. In that case you can modify your VM internally to link them to the desired dest folder.
You can do that in the provision state of your VM for example.
# Vagrantfile snippet
config.vm.provision "shell", inline: <<-SHELL
ln -s /vagrant/salt /srv/salt
ln -s /vagrant/pillar /srv/pillar
SHELL
Maybe this file are not available at provision time then run them as one time task after your first login or put something similar to /etc/rc.local of your VM

Related

Q: E: Error reading the CPU table in ubuntu

I can not update or upgrade my computer by terminal.
Show the error message E: Error reading the CPU table.
how can I fix it ?
In my case some file system corruption caused files in the directory /usr/share/dpkg/ and the file /usr/share/dpkg/cputable wasn't found
to be deleted, concurrent access during some other operation?
rsync / copying ( in my case rsync'ing ) from a known good installation appears to have fixed this particular problem
possible alternative boot from a livecd and mount the target disk and copy
The command strace apt update showed the location of the missing file
In My case I have faced with corrupted dpkg installation and at the end it ended up with “E: Error reading the CPU table” even I enter sudo apt-get update
Step to fix it.
1) Create tempory location for dpkg and download relavent .deb file
sudo mkdir /tmp/dpkg then
cd tmp/dpkg
2) Downlod .deb file with relavent .deb file in http://archive.ubuntu.com/ubuntu/pool/main/d/dpkg/
sudo wget http://archive.ubuntu.com/ubuntu/pool/main/d/dpkg/dpkg_1.19.0.5ubuntu5.1_amd64.deb
3) Manually go to that downloaded directory and extract the .deb file(GDebi installation might not work as well)
Navigate to <Your_Extracted_Folder>/usr/share/dpkg and now you can
see the set of files with cputable file. We need to copy these files
to /usr/share/dpkg
4) Check /usr/share/ having dpkg folder if not create it with
sudo mkdir /usr/share/dpkg
5) cd <Your_Extracted_Folder>/usr/share/dpkg
6) sudo cp * /usr/share/dpkg
Now you can see all the files and it will fix the “E: Error reading the CPU table”
Check if you have (unintentionally) "overwritten" your /usr/share directory with a file..
ls -l /usr/
-rwxr-xr-x 1 root root 1254 Feb 4 19:08 share*
drwxr-xr-x 193 root root 4096 Dec 10 09:09 share~/
I solved it by moving the file share* to share_bak and then renaming the directory share~ (to share). Problem solved!

How do I properly configure glassfish 4 to work with gurobi's shared library?

Error:
java.lang.UnsatisfiedLinkError: /opt/gurobi600/linux64/lib/libGurobiJni60.so: libgurobi60.so: cannot open shared object
It is getting the path correct when I add it via JVM settings, for some reason it doesn't find it if only relying on LD_LIBRARY_PATH environment variable though. Either way it has trouble with the libgurobi60.so. I tried adding all of this to glassfish_home/domains/domain1/lib/applibs and ext to no avail.
Here are the permissions for /opt/gurobi600/linux64/lib
-rw-r--r-- gurobi.jar
lrwxrwxrwx libgurobi60.so -> ./libgurobi.so.6.0.0
lrwxrwxrwx libgurobi_c++.a -> ./libgurobi_g++4.2.a
-rw-r--r-- libgurobi_g++4.1.a
-rw-r--r-- libgurobi_g++4.2.a
-rwxr-xr-x libGurobiJni60.so
-rwxrwxrwx libgurobi.so.6.0.0
I had this working on my previous server running ubuntu 12.04, this is now on 14.04. Previously copying the .so file to /usr/local/bin seemed to fix the issue, but this does not work on the new server.
Running the following two commands fixed it:
echo "/opt/gurobi600/linux64/lib" | sudo tee /etc/ld.so.conf.d/gurobi.conf
sudo ldconfig

Linux mount NFS with specific user

I was searching hours on the Internet, but for this specific problem I could not find any solution.
1: I have a Xubuntu Linux on my PC. I use it in average way: browse the Internet, watch videos, etc. And also it gives home for my PHPStorm app but no the project files. This is the HOST. It has a host-only network: 192.168.56.1
2: I have a VirtualBox Debian Linux (no GUI) system. This meant to be represent a development version of my real webserver. It has all the project files. This VM is on an external drive, so I can take it everywhere (e.g.: to the office). 192.168.56.101. This is the GUEST.
3: on the HOST I use dnsmasq to force every *.dev domain to be redirected to the GUEST. So I can test my projects easily.
4: on the GUEST I exported the /var/www folder in the /etc/exports:
/var/www 192.168.56.1(rw,sync,no_root_squash,no_subtree_check)
The problem: I want to use the PHPStorm on the HOST to edit the files on the GUEST "locally". But I cannot mount the GUEST's /var/www folder into the HOST's /home/gabor/Projects folder with full permissions. I tried to use the following:
$> sudo mount 192.168.56.101:/var/www /home/gabor/Projects
This looks okay for the first time, but the folder is mounted with nobody:nogoup and I have no permissions to edit.
I want the /home/gabor/Projects has the owner gabor:gabor and everything I create in this folder must has the owner www-data:www-data on the Debian side. But for NFS mounting I cannot specify the user.
$> sudo mount -o umask=0022,gid=1000,uid=1000 192.168.56.101:/var/www /home/gabor/Projects
mount.nfs: an incorrect mount option was specified
I also failed to mount --bind the /var/www with different user (should be nobody:nogroup) on the Debian, so that I could export that one...
How can I solve this problem?
Please help me.
Thank you.
NFS v2 and v3 do not support uid/gid.
on Ubuntu man nfs
Adding this answer for posterity, as I ended up here with the same question.
Try this in /etc/export:
/var/www 192.168.56.1(rw,root_squash)
Then on the client, put this in /etc/fstab:
192.168.56.101:/var/www /home/gabor/Projects nfs defaults,user,noauto,relatime,rw 0 0
The user option will allow a non-root user to mount the volume. Adjust other options as needed.
Then on the client again, become the user you want to mount the volume as, and then mount the volume you added to /etc/fstab:
$ id
uid=1000(gabor) gid=1000(gabor) groups=1000(gabor)
$ mount /home/gabor/Projects
$
Make sure that the uid and/or gid are the same on the server. I'm not sure if the usernames can be different or not. Also make sure that the directory being exported on the server is writable by the user or group. See this blog post for additional info about setting up NFS in a similar manner.
Caution: This is an insecure configuration without authentication. Use NFS v4 with Kerberos for strong authentication.
Ok, I found a solution that exactly does what I want.
First, install the sshfs:
$> sudo apt-get install sshfs
Then mount the remote /var/www:
$> sshfs -o uid=33,gid=33 root#192.168.56.101:/var/www /home/gabor/Projects
And that is it!
$> ls -la /home/gabor | grep Projects
drwxr-xr-x 1 www-data www-data 4096 Okt 14 21:10 Projects

how to read shadow file in linux using python script

file = open('/etc/shadow', 'r')
print(file)
getting error like this
file = open('/etc/shadow', 'r')
IOError: [Errno 13] Permission denied: '/etc/shadow'
On most systems /etc/shadow is owned by root with rw permissions.
$ ls -la /etc/shadow
-rw------- 1 root root 692 Jun 10 19:24 /etc/shadow
You need to either:
Change the permissons (don't do this it is not safe)
but you could this by running 'chmod o+r /etc/shadow' as root. This will give the 'other' users read rights to
Run your program as root. Either by
a. Starting it as root
su -c 'python myPython.py' //you will be asked to provide the root password.
b. Starting it with sudo [1]
sudo python myPython.py this all depends on you sudo configuration but is your best bet other then just starting python as root.
Also an example to call sudo from within python[5].
c. Set setuid bit on the program [2]
This will most likely not work as Python is an interpreted language and most modern Unix systems will disallow (exception being Perl) setuid on interpreted programs as opposed to compiled/binaries.
chown root programName # Set owner to be root
chmod +s programName # This gives the program itself the right to run as root.
Regardless of whom starts it.
[1]http://en.wikipedia.org/wiki/Sudo
[2]http://en.wikipedia.org/wiki/Setuid
[3]Open a file as superuser in python
[4]Setuid bit on python script : Linux vs Solaris
[5]Using sudo with Python script
The problem is not with the source code or python. But with not having the correct file system rights to the '/etc/shadow' file.
In python 3 you can do:
import spwd
spwd.getspnam('username')
More information about the spwd module can be found here: https://docs.python.org/3/library/spwd.html#module-spwd

How can I mount an S3 volume with proper permissions using FUSE

I have an Amazon S3 bucket (let's call it static.example.com) that I need to mount on an EC2 instance (Ubuntu 12.04.2). I've installed s3fs. I'm able to mount the volume, but I can't write to the bucket. I have tried:
sudo s3fs static.example.com -o use_cache=/tmp,allow_other,uid=33,gid=33 /mnt/static.example.com
I can then cd /mnt and ls -la to see:
drwxr-xr-x 5 root root 4096 Mar 28 18:03 .
drwxr-xr-x 25 root root 4096 Feb 19 19:22 ..
lrwxrwxrwx 1 root root 7 Feb 21 19:19 httpd -> /httpd/
drwx------ 2 root root 16384 Oct 9 2012 lost+found
drwxr-xr-x 1 www-data www-data 0 Jan 1 1970 static.example.com
This all looks good, but when I cd static.example.com and mkdir test, I get:
mkdir: cannot create directory `test': Permission denied
The only way I can actually create a directory or touch a file is to force it with sudo. This is not a viable option, however, because I want to write files to the bucket from Apache. My Apache server runs as user:group www-data. Running mount yields:
s3fs on /mnt/static.example.com type fuse.s3fs (rw,nosuid,nodev,allow_other)
How can I mount this bucket in a manner that will allow me to write to the bucket?
I'm the lead developer and maintainer of Open source project RioFS: a userspace filesystem to mount Amazon S3 buckets.
Our project is an alternative to “s3fs” project, main advantages comparing to “s3fs” are: simplicity, the speed of operations and bugs-free code. Currently the project is in the “beta” state, but it's been running on several high-loaded fileservers for quite some time.
We are seeking for more people to join our project and help with the testing. From our side we offer quick bugs fix and will listen to your requests to add new features.
Regarding your issue:
if'd you use RioFS, you could mount a bucket and have a write access to it using the following command (assuming you have installed RioFS and have exported AWSACCESSKEYID and AWSSECRETACCESSKEY environment variables):
riofs -o allow_other http://s3.amazonaws.com bucket_name /mnt/static.example.com
(please refer to project description for command line arguments)
Please note that the project is still in the development, there are could be still a number of bugs left.
If you find that something doesn't work as expected: please fill a issue report on the project's GitHub page.
Hope it helps and we are looking forward to seeing you joined our community !
This works for me:
sudo s3fs bucketname /mnt/folder -o allow_other,nosuid,use_cache=/mnt/foldercache
If you need to debug, just add ,f2 -f -d:
sudo s3fs bucketname /mnt/folder -o allow_other,nosuid,use_cache=/mnt/foldercache,f2 -f -d
Try this method using S3Backer:
mountpoint/
file # (e.g., can be used as a virtual loopback)
stats # human readable statistics
Read more about it hurr:
http://www.turnkeylinux.org/blog/exploring-s3-based-filesystems-s3fs-and-s3backer