How to use Cygwin to copy an image from an SD memory card

30

7

Long story short, I'm working on a Windows 7 machine and I'd like to strip the image off an SD card (backing up the card from a Raspberry Pi). I'm trying to use Cygwin, but not having much success.

Examining the /dev directory, it looks like my SD card is showing up as sdd and sdd1. However, when I run the following command:

dd if=/dev/sdd of=RPi.img

I get the following:

dd: opening '/dev/sdd': Permission denied

I've used dd on a Mac and under Linux without any problem, using similar syntax. What am I missing with Cygwin?

GrandAdmiral

Posted 2013-04-10T15:58:18.333

Reputation: 435

With VirtualBox 5.x I have managed to format a USB drive completely to boot GRUB2. Thought I got it to work the first time, but I ended up probably not only needing to install their USB Extension Pack, but also when the VM started up I needed to select the USB drive under devices so the VM had a 'direct' connection to the drive to operate on 'completely'. I just saw you mention VirtualBox and wonder if this note could also help the situation. – Pysis – 2017-03-25T01:30:50.230

Have you tried dd if=/dev/sdd1 of RPi.img? – Kruug – 2013-04-10T16:30:14.543

If I do that, I only get a ~59 MB file from the 4 GB SD Memory Card. Basically I'm only getting the portion of the card that Windows "sees" when you insert the card in the reader. It's not the full image. – GrandAdmiral – 2013-04-10T16:35:54.023

Could you use a Linux machine, or Linux LiveCD instead of trying in Windows? – Kruug – 2013-04-10T16:40:32.753

Virtual Linux Machines don't seem to see the SD Memory Card (tried VMware Player and VirtualBox) because I'm using the internal reader on the laptop. Then to top it off.... I don't have a CD burner in the laptop either. :) I have a Mac at home that I can use, I was just trying to find something that would work with my current situation.... and figure out if it was even possible. Seemed like cygwin should have worked. – GrandAdmiral – 2013-04-10T16:42:58.023

For creating a Linux bootable device, check out http://unetbootin.sourceforge.net/. It will take a LiveCD and "burn" it to a USB device allowing you to boot from it.

– Kruug – 2013-04-10T16:45:55.187

4I found that I can also use 'cat /proc/partitions' to get the name of the attached SD Memory Card. – GrandAdmiral – 2013-05-16T15:18:27.047

Answers

28

You get the Permission denied error, because you are not root. That sounds strange in the context of Cygwin, but it hits home.

When you query your status (id) in a normally started Cygwin shell, you'll get something like that:

$ id
uid=1001(user) gid=545(Users) groups=545(Users),555(Remote Desktop Users),513(None)
$ dd if=/dev/sda bs=1000 count=1 | wc -c
dd: opening `/dev/sda': Permission denied
0

Under Windows 7 the trick to become root in Cygwin is to start the session elevated, that is, do a right click on your Cygwin icon and choose Run as Administrator. Now your are still not root itself, but at least in root's group:

$ id
uid=1001(user) gid=545(Users) groups=545(Users),0(root),544(Administrators),555(Remote Desktop Users),513(None)

And now, dd works as you are used to it from Un*x:

$ dd if=/dev/sda bs=1000 count=1 | wc -c
1+0 records in
1+0 records out
1000 bytes (1.0 kB) copied, 0.00104424 s, 958 kB/s
1000

mpy

Posted 2013-04-10T15:58:18.333

Reputation: 20 866

I'm not a member of root this way. Has anything changed? – Pysis – 2017-03-25T01:33:54.683

1

@Pysis: I'm still able to become root this way with the current cygwin version (CYGWIN_NT-6.1-WOW 2.7.0(0.306/5/3) 2017-02-12 13:13 i686 Cygwin) as of today's update. Maybe http://stackoverflow.com/q/4090301 on SO might be of help for you?!

– mpy – 2017-03-25T11:38:16.580

It seems I have 2.6.1 from cygwin1.dll (cygcheck). I don't get "0(root)", but I do get "114(Local account and member of Administrators group"), "544(Administrators)", and "405504(High Mandatory Level)" instead of "401408(Medium Mandatory Level)" on my Windows 10 Pro x64-bit system. The context is that I wanted to run fdisk, but that still seems to not help, although I may have been able to run other tools with privileged access just fine, such as dd on a block device stream file, only curious here. – Pysis – 2017-03-26T18:18:50.423

@Pysis: May this has to do with W10?! -- Unfortunately I can only speculate as I use W7 only. – mpy – 2017-03-26T19:02:21.713

this method works fine in W10: CYGWIN_NT-10.0 hostname 2.11.2(0.329/5/3) 2018-11-08 14:34 x86_64 Cygwin I was able to dd a bootable image to the thumbdrive from cygwin this way – cowbert – 2019-03-18T00:58:27.163

Very interesting, and that works. Thanks! While both this method and USB Image Tool provide a solution, I'll accept this answer because it's more directly related to my initial question. – GrandAdmiral – 2013-05-16T15:21:14.637

12

I recently had to clone one USB drive to another on windows. My drive is a multiboot with additional software so I didn't want to just copy all files on the FS. DD was a clear choice, but I wasn't on linux so there were a few things I had to do to get it working.

I had cygwin installed and did the following.

first I had to figure out what /dev/sdX device my f: volume was. To do so run this command in cygwin. (TIP: Make sure you start cygwin with admin privs.. *Right click on cygwin and "Run as Administrator")

    cat /proc/partitions
which should output:
   8 0 3813383838 sda
   8 1       4031 sda3 C:\
   8 15  30588303 sdb 
   8 15  30588303 sdb1 E:\
   8 21  30530020 sdc
   8 22  30530020 sdc1 F:\

etc... Here you can clearly see for me to clone my F: drive to my E: drive I'd issue the following command.

There is one more step actually, you have to find the root of your device. Look for an sd* that has a size of your device. This whould be easy as the size should be well known such as 8GB, 16GB, 32GB expanded as bytes as shown above.

dd if=/dev/sdc of=/dev/sdb bs=8M

My image was 32gb.. and I didn't want to just sit and wait with a blinking cursor.. I wanted to see progress so I installed "pv" in cygwin.

dd if=/dev/sdc | pv | dd of=/dev/sdb bs=8M

Now if you want to copy the thumbdrive to an image do the following.

dd if=/dev/sdX | pv | dd of=/cygdrive/c/Users/Myname/Desktop/mythumbdrive.img bs=8M

Hope this helps

Jaime

Posted 2013-04-10T15:58:18.333

Reputation: 121

2

Will something like USB Image Tool do?
Or, do you insist on using Cygwin? ...

nik

Posted 2013-04-10T15:58:18.333

Reputation: 50 788

No insistence on using Cygwin. That tool was a little strange when displaying the SD Memory Card (sometimes the info would disappear, but maybe that was Windows doing something) but it seemed to work and it was REALLY FAST. I have a 4 GB file sitting on my computer that is the size I expected. I think I'll diff it with a version from the actual 'dd' command just to make sure. IF that looks good, I'll accept your answer. Thanks! – GrandAdmiral – 2013-04-10T16:48:29.893

Well, the files didn't match but that could be my fault. I think I booted the RPi after grabbing the first image, not thinking about it. Well, at least I have the backup I wanted now and I have a tool to experiment with down the road that works under Windows. Worst case I'll just drive home and use a sane computer/OS. :) – GrandAdmiral – 2013-04-10T18:22:49.013

2

I've had success with dd for Windows, which I believe is a rewrite rather than a port. It's open-source and does not rely on Cygwin.

I particularly liked the dd --list command, which listed all the disk devices along with enough info to identify the one I wanted.

RomanSt

Posted 2013-04-10T15:58:18.333

Reputation: 7 830

1

HDD Raw Copy Tool can make copies of an SD card. If you select "Raw image (dd image)" in the save dialog then it will be identical to the ones made with dd. You can restore images too.

I know it's not done via cygwin, but I personally wouldn't trust it with accessing raw devices.

yuikonnu

Posted 2013-04-10T15:58:18.333

Reputation: 210

Where do you get the option to save a Raw Image? I saw where you could select the source (SD Memory Card) and the destination (HDD), but then there was just a Start button. Since it wasn't clear what was going to happen next, I exited the program. – GrandAdmiral – 2013-04-10T16:56:12.677

First you double-click your drive, then on the next screen you double click the "File" option where you can choose where to save the image. – yuikonnu – 2013-04-11T07:49:18.487

0

I see that RaspberryPi.org is now recommending Win32 Disk Imager for writing images to SD Memory Cards. It will also read images from the card, so I'm trying it out now.

GrandAdmiral

Posted 2013-04-10T15:58:18.333

Reputation: 435

I refuse to touch that one as there are reports of it trashing your system disc. Rare, but it depends on the hardware and I'm not going to risk it. – tjmoore – 2014-08-13T11:58:35.080