30

I installed Debian in VirtualBox (for various experiments which usually broke my system) and tried to launch the VirtualBox guest addon script. I logged in as root and tried to launch autorun.sh, but I got «Permission denied». ls -l shows that the script have an executable rights.

Sorry, that I can't copy the output -- VirtualBox absolutely have no use without the addon, as neither a shared directory, nor a shared clipboard works. But just for you to be sure, I copied the rights by hands:

#ls -l ./autorun.sh
-r-xr-xr-x 1 root root 6966 Mar 26 13:56 ./autorun.sh

At first I thought that it may be that the script executes something that gave the error. I tried to replace /bin/sh with something like #/pathtorealsh/sh -xv, but I got no output — it seems the script can't even be executed.

I have not even an idea what could cause it.

4
  • 2
    Looks like it should work. Try running it with bash explicitly: `bash -x ./autorun.sh". Maybe this will give an additional clue. Commented Aug 24, 2014 at 6:08
  • 3
    What is output of mount | grep noexec?
    – cuonglm
    Commented Aug 24, 2014 at 6:12
  • 1
    @Gnouc, you're right, the mounted «cdrom» have the noexec set. Probably you may post it as an answer; meanwhile I am trying to remount it with an exec rights. Hm, I didn't even knew that the filesystem could have such an attribute.
    – Hi-Angel
    Commented Aug 24, 2014 at 6:16
  • 1
    And if you try to run it via going sh ./autorun.sh what happens?
    – infixed
    Commented Apr 5, 2016 at 17:34

6 Answers 6

47

Maybe your file system is mounted with noexec option set, so you can not run any executable files. From mount documentation:

noexec

Do not allow direct execution of any binaries on the mounted filesystem. (Until recently it was possible to run binaries anyway using a command like /lib/ld*.so /mnt/binary. This trick fails since Linux 2.4.25 / 2.6.0.)

Try:

mount | grep noexec

Then check if your file system is listed in output.

If yes, you can solve this problem, by re-mounting file system with exec option:

mount -o remount,exec filesystem
7
  • That didn't work for me. I had to unmount and then remount normally. Then it worked fine.
    – datakid
    Commented Jun 23, 2016 at 4:01
  • @datakid: What is your fs?
    – cuonglm
    Commented Jun 23, 2016 at 4:14
  • I am having this issue with debian 9, some files are permission denied if the scripts is running as root, but it identify as root... like a windows behavior, if i remove & the script worked! =[ Commented Dec 14, 2017 at 13:07
  • I was getting a very strange message, which turned out to be because of noexec: "sh: 75: script.sh: Permission denied"
    – tmm1
    Commented Oct 3, 2018 at 21:03
  • 1
    Also, if it complains about not being able to remount /dev/whatever because it's write protected, you will need to make sure your remount command tells it to mount RO (e.g. mount -o remount,exec,ro)
    – tanantish
    Commented Jan 19, 2020 at 15:29
4

bash -x ./filename.filetype should work. It worked for me when I got permission denied as a root user.

2
  • No, as in the end the problem turned out to be the noexec mount option, this won't work, because there could be more files that have to be executed; i.e. the filename.filetype would gasp trying to execute other files from the same filesystem. You can easily check it with a simplified test: create a two line script which prints "hello", then just calls himself again, but do not set executable rights. If you execute it with -x, it would print "hello", but then the recursive call line would trigger an error.
    – Hi-Angel
    Commented Apr 6, 2016 at 4:33
  • This worked perfectly for me when I edited a bash file in my Google Collab workspace and tried to run it. Thanks!
    – Pe Dro
    Commented Feb 25, 2020 at 11:53
2

My solution to this problem is to use source. I was on a storage volume of very important data. This volume is mounted as noexec. I have a simple shell script that is executable but got permission problem.

./fixsamplesheet.sh # this guy is executable
-bash: ./fixsamplesheet.sh: Permission denied

source fixsamplesheet.sh # worked fine

Only tested on my Ubuntu.

2
  • This doesn't solve the problem, you are still not able to run it as an executable. You are running bash as an executable which reads the information from the .sh file.
    – youpilat13
    Commented Feb 9, 2021 at 8:06
  • The mechanism is to execute the commands in the current shell, not using the *.sh as if it is executable. Agree, not the true solution.
    – Kemin Zhou
    Commented Feb 9, 2021 at 21:08
0

Just mount the extensions ISO file as a "virtual" CD.

In the guest I run, I cd to the appropriate mount point, such as cd '/media/some_username/VBox_GAs_6.1.18' (name is dependent on version number)

Then run sudo sh ./VBoxLinuxAdditions.run

Restart the VM to make it work properly.

0

I had exactly the same problem installing Guest Additions on my copy of Debian Buster in Virtual Box.

As a work-around I simply copied the file VBoxLinuxEditions.run to the home directory of Debian and ran it from there using sudo. This not the solution as to why the script could not be run, but at least I was able to install Guest Additions.

Interestingly, I had no problem installing Guest Additions on my version of MX Linux which I have installed in Virtual Box, despite the fact that MX Linux is based on Debian.

0

The workaround that worked for me in a Debian 12 VM was to copy the VBoxLinuxAdditions.run file from the CD to my home folder, change permissions to add execution, then run it as root.

BUT, I forgot that guest additions compiles itself so if the prerequisites are not installed it will complain and halt.

So do this first before trying to run the guest additions:

sudo apt install build-essential dkms linux-headers-$(uname -r)

Once that's done, run the guest additions run file in your home folder. After that's completed you'll want to reboot.

After reboot, confirm the guest additions are working. The quick test I use is to resize the VM window and see if the desktop resizes too. If it does they are working.

Don't forget to delete the VBoxLinuxAdditions.run file from your home folder.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .