31

I'm following the steps in How to create a bootable USB stick on OS X to install Ubuntu on a USB stick, and I keep getting the error:

dd: /dev/disk4: Permission denied

when I try to run step 8, even if I use sudo and enter my password.

I know this is probably a silly little mistake, but I'm not familiar enough with the terminal to figure it out on my own. Anyone out there who could help? (I'm using OSX, by the way.)

Zanna
  • 70,465
Seth
  • 311
  • 1
  • 3
  • 4

11 Answers11

39

One common cause for this is a "locked" SD card. Unfortunately it seems that the sensor in the MacBook Pro and Air can get stuck. It can be fixed with a can of compressed air.

A lot of us ran into this trying to image SD cards for the Raspberry Pi. And with that device you have no option but to boot off of the SD.

This raises a fascinating fact. It seems that the lock switch is a purely mechanical "intent indicator" that must be sensed by the host device. This is analogous to the way the lock switch worked on 3.5" floppy drives, so it should be no shock to those of us old enough to have to punch a hole in our 5.25" floppies to make them writeable. (And cover the hole with tape to make them readonly!) However, because it is called Secure Digital and is solid state, you would expect the card to protect itself, not rely on the host.

  • really interesting! I had a sandisk microSD connected through a sandisk microSD adapter and I was getting Permission denied. I used a different adapter and it works fine. Also doing Raspberry Pi work. – Matthew Turner Apr 11 '15 at 05:36
  • 1
    @mtpain, Hmmm. Well, with microSD it's definitely a different issue because there is no write lock switch on it. I'm sure you have the ingenuity to devise a series of tests to see if you have a bad adapter or a just a fluke combination of devices that don't work well together. – Bruno Bronosky Apr 12 '15 at 02:44
  • 1
    You can also tape the lock switch into the unlocked position. – RyanGC Apr 24 '15 at 18:50
  • 1
    I can not believe this solution worked. Thank you. – Daniele Vrut Sep 11 '16 at 20:00
  • 1
    Thanks! I was using an SD and it was in fact in the locked status – Giacomo Pigani Feb 24 '17 at 23:34
  • 2
    I can't begin to express my surprise that blowing on my MBP's card slot was the solution to this problem. I haven't had to do that since the N64 days! – bloudermilk Feb 22 '18 at 05:07
  • 1
    @bloudermilk I KNOW RIGHT! Blows my mind even 5 years later. – Bruno Bronosky Feb 22 '18 at 06:27
  • 1
    There are SD card style adaptors for microSD cards, which even have the write lock switch on them. After reading this I just blew in the port and it then worked. – rich Mar 08 '18 at 11:09
  • 1
    I had the same issue flashing a Raspberry Pi, I'm astounded that this was the solution. – AmericanUmlaut May 30 '18 at 01:44
  • same as @bloudermilk! blew my mind that the solution was blowing air in the card slot of my mbp :) – Demetris Constantinou Jan 09 '20 at 13:10
  • 1
    Late to the party - I just found this. Some sellotape helped me :-) – Gaz Sep 23 '21 at 13:20
12

I came across this once too. Use 'diskutil' to check the device your SD card appears as:

diskutil list

Then unmount it (Don't unmount using 'Finder', it wont work):

diskutil unmountDisk /dev/disk_4

Now use the 'dd' command to load your image:

sudo bash -c 'gzip -dc the_image_file.img.gz | dd of=/dev/disk_4'

I hope this helps.

Josh
  • 121
  • 1
  • 2
3

Since it's silly that sudo (essentially 'root') can't access the device with dd it would seem that the error message "Permission denied" does not actually mean that root has a permissions problem. iow it's a red herring.

Double check that the device is not still mounted - run the unmount command again as per step 7 and double check that it really is unmounted but still accessible as a device.

A common problem I've had with making USB boot devices under linux is an inconsistent partition table. Delete the partition table completely and remake it, then create the new new partition as FAT and format it for good measure. The errors I get under Linux don't make any more sense than this one, so I'm hoping that this is what your problem is.

I'll have a shot at removing the partition table under OSX. Note that I am a linux user, so I'm relying on the fact that OSX is similar, and that the same thing seems to be found for OSX on a google search.

First we'll use dd to erase the partition table on the USB drive. In a terminal type:

sudo dd if=/dev/zero of=/dev/disk4 bs=512 count=1

This should overwrite the first 512 bytes of the device, thus destroying the partition table. Instructions I found here seem to suggest

sudo dd if=/dev/zero of=/dev/disk4 bs=1 count=1024

for OSX however the difference is minor and I believe the end result should be the same. As for any dd operation make sure you have the correct partition as there will be nothing left of the data on the device after you press enter.

Next I believe you should use disk utility to to recreate the partition table, and a new partition, and format it FAT. I'm a linux user, so I'm afraid I can't be more specific but I believe that the disk utility should complain that that there is no partition table and either make one for you, or prompt you to do so.

fabricator4
  • 8,375
  • Hmm.. I confirmed that it's unmounted. I tried running the step 8 command again with it mounted and it gave me the same error, so it hasn't even managed to get far enough to care. I have no idea how to work with partition tables or where to find them. Maybe you would be able to explain? – Seth Nov 10 '12 at 07:58
  • Well I've had go, though I don't use OSX so I'm shooting blind here. If this doesn't work you could try a different USB pendrive. – fabricator4 Nov 10 '12 at 09:20
2

Here was my solution:

Sudo wasn't asking for my password when I tried to use it. I thought that was odd.

So, I su'd to root and did it from there.

sudo su
<enter password>

Then I ran the commands and they worked.

1

Use sudo in front of the dd command

sudo dd if=/Users/JPurcell/Downloads/Fedora-18-x86_64-Live-Desktop.iso of=/dev/disk2

WARNING: Improper use of the sudo command could lead to data loss or the deletion of important system files. Please double-check your typing when using sudo. Type "man sudo" for more information.

that fixed the permission denied for me. it seems to be working now.

and I was root before hand. I also did the

sudo dd if=/dev/zero of=/dev/disk4 bs=1 count=1024 before sudo dd if=/Users/JPurcell/Downloads/Fedora-18-x86_64-Live-Desktop.iso of=/dev/disk2

I did it right after without reformatting the usb drive. I dont know if its been successful but lights blinking on the drive and terminal is not giving me errors.

Braiam
  • 67,791
  • 32
  • 179
  • 269
Joe
  • 11
1

Potentially try ejecting the usb drive and reformatting first, then retry all the steps. diskutil list, unmount, then write the iso to the disk. I ran into similar issues where dd was giving permission denied errors and I reformatted my usb and everything worked correctly.

Ben
  • 11
  • 1
    Reformatting the disk before running dd solve my problem. The reformatting must be done from Terminal with diskutil eraseDisk FAT32 BOOT /dev/disk2, because "Disk Utility" app didn't work well. – veladan Jul 29 '20 at 09:51
1

ls -l /dev/disk2 gave me this result:

brw-r-----  1 root  operator    1,   5 Dec 17 10:27 /dev/disk2

I solved the problem by changing the owner of the file:

sudo chown <myUser>:<myGroup> /dev/disk2

Then I was able to dd the files to the USB stick.

muru
  • 197,895
  • 55
  • 485
  • 740
Chris
  • 11
0

For me, simply restarting the Macbook solved the problem.

0

From this related question, a comment on the highest-voted answer seems to suggest you aren't the only one having troubles with dd.

The same answer recommends using optical media (a.k.a. a LiveDVD) instead of a USB drive if you can, as that seems more reliable.

*Note: I am not and never was a Mac user, so I'm afraid I can't help out much more than this.

0

Well, I struggle a lot with this but finally succeed...

server:~ myusername$ sudo dd if=/Users/myusername/Desktop/ubuntu1304.img of=/dev/disk1s1 bs=1m

WARNING: Improper use of the sudo command could lead to data loss or the deletion of important system files. Please double-check your typing when using sudo. Type "man sudo" for more information.

To proceed, enter your password, or type Ctrl-C to abort.

Password:******

DONE!

Points to check: USB formated for FAT usb disk should be unmounted. usb disk => 2Gb All this in iOSX Mavericks ver 10.9

Hope this helps!

Seth
  • 58,122
0

I ran into this problem because I was attempting to dd the wrong device. diskutil list showed /dev/disk0, /dev/disk1, and /dev/disk2 I was using /dev/disk2 should have been /dev/disk1