23

I am working on writing a graphical application that uses the Pi's GPU, and I constantly get * failed to open vchiq instance errors when running my programs. This is usually fixed by a sudo chmod 777 /dev/vchiq, but (1) this is a very insecure fix that is definitely not suited to deployment to user-owned devices, and (2) it gets reset after each reboot.

How can I fix my /dev/vchiq problems "the right way", persistently, without introducing security issues?

5 Answers 5

32

I was able to solve a similar problem by adding myself to the video group (I was not using the default user). Maybe this can help.

The command is:

sudo usermod -a -G video $(whoami)

You will need to log out and in again for the change to take effect.

6
  • 2
    This worked for me (sudo usermod -a -G video $(whoami)), I would also recommend (for security purposes) adding a dedicated user for whatever process will need access to the camera and adding only that user to the video group.
    – n8henrie
    Commented May 14, 2016 at 15:53
  • 3
    After rebooting, this permanent solution works fine and is relatively safe. Commented May 16, 2016 at 18:55
  • Reboot required.... Commented Nov 12, 2017 at 21:23
  • 2
    This worked for me too! Thanks. Reboot is not necessary, logging out and logging in again is enough.
    – tuvokki
    Commented Mar 28, 2018 at 16:00
  • 1
    This is the proper, secure way to do it. If you have a dedicated user for this function, you can add them by replacing $(whoami) with that username.
    – IceMage
    Commented Feb 1, 2019 at 15:06
9

You can create a udev rule to set specific permissions on the device. As root, you could:

echo 'SUBSYSTEM=="vchiq",GROUP="video",MODE="0660"' > /etc/udev/rules.d/10-vchiq-permissions.rules
usermod -a -G video YourUnprivilegedUser
4
  • This does not fix the problem. After running that, I still get the error.
    – Cerin
    Commented Oct 17, 2015 at 6:49
  • I suspect the permissions are done in a higher (thus later in the running order) udev rule which undos this change. On my (Debian) PC the system supplied file is /lib/udev/rules.d/91-permissions.rules so I'd try writing this to an even higher one (and perhaps include local in the name to identify it as a local modification), i.e.: echo `SUBSYSTEM=="vchiq",GROUP="video",MODE="0660"\' > /etc/udev/rules.d/92-local-vchiq-permissions.rules
    – SlySven
    Commented Jan 19, 2016 at 7:50
  • I get permission denied, what might be wrong?
    – dmigo
    Commented Sep 22, 2016 at 18:08
  • Works perfectly for me. Elegant solution if usermod isn't enough Commented Aug 1, 2018 at 13:15
5

You could set SUID permission

sudo chmod u+s /dev/vchiq
3
  • What does this do?
    – fouric
    Commented Jun 13, 2014 at 5:00
  • 1
    When an executable file has been given the setuid attribute, normal users on the system who have permission to execute this file gain the privileges of the user who owns the file (commonly root). You could set this on your program (assuming it is owned by root). As /dev/vchiq belongs to group video another option is to set setgid and the group on your program to video.
    – Milliways
    Commented Jun 13, 2014 at 6:17
  • 1
    That didn't help, albeit user www-data is in video group, but I succeeded with chmod a+rw /dev/vchiq on Raspbian Stretch.
    – Jan Turoň
    Commented Dec 21, 2017 at 10:23
3

If you are running raspistill from a php script accessed via a browser then you need to enter: sudo usermod -a -G video www-data to give Apache the necessary permissions.

1
  • as said above, reboot required, but thanks a bunch.
    – Rusty
    Commented Jan 21, 2021 at 21:22
0

add

start_x=1 
gpu_mem=256

to boot/config.txt then run sudo raspistill -o cam.jpg

Of course I added the path for the raspistill. It worked for me in Ubuntu.

1
  • I do not see how this answers the OP's question - could you expand your answer to explain how it works on the Raspberry Pi?
    – SlySven
    Commented Jan 19, 2016 at 7:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.