balena-io-modules / etcher-image-write

The cross-platform way to stream an OS image to a device
Apache License 2.0
28 stars 8 forks source link

Error: EACCES: permission denied, open '/dev/rdisk3' without sudo #44

Closed cedricve closed 8 years ago

cedricve commented 8 years ago

Really nice job :) I'll be using this library in the @kerberosio project. However when trying to flash an img to the SD-card I get a permission denied. I then started the nodejs app with sudo, and it looks like it's working.

However when I will package the project, do you know what will happen?

jviotti commented 8 years ago

Hi @cedricve ,

Thanks a lot for reaching and very sorry about the delay. I was not watching this repository for some reason :/

Sadly, most operating systems require elevated privileges to perform direct I/O to devices, so you really need to run this as sudo (or Administrator on Windows) for it to work.

However when I will package the project, do you know what will happen?

What we currently do in Etcher is that we check if the current process is running with enough permissions using the is-elevated module. If not, we use sudo-prompt (for OS X and GNU/Linux) and elevator (for Windows) to re-run the writer script with the necessary permissions.

This is currently a bit of a mess, since there are many edge cases. You can see the code that performs the elevation of the writer script for Etcher here: https://github.com/resin-io/etcher/tree/master/lib/src/child-writer.

We've been thinking about creating and maintaining a C++ NodeJS add-on module that interacts with each OSes native APIs directly and provides a drop in replacement for child_process.spawn that handles elevation automatically, however I'm not sure when this will take place.

For the time being, you can follow what we do on Etcher. I with you a lot of luck with Kerberosio, and don't hesitate in getting in touch at juan@resin.io if you need any further help.

cedricve commented 8 years ago

Thanks @jviotti for the fast response and explanation.

However I've decided to just fork the Etcher repository and stack my changes on top of it; I've send you guys an e-mail about the plan of action. I'll expand the libraries you (resin) created: the cli and visuals.

Are you guys active on gitter or something similar?

Cédric

jviotti commented 8 years ago

Hi @cedricve ,

Sounds good. Looking forward to the email. We're active in the following Gitter channel: https://gitter.im/resin-io/chat.

jviotti commented 8 years ago

I'm closing this thread since further discussion happened on Gitter.