No loop device in Cygwin

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

No loop device in Cygwin

Post by qw »

Hi everybody,

It is a little disappointing that Cygwin does not support loop devices. ImDisk is a great tool, but it appears only as a mounted volume "/cygdrive/x" and not as a device "/dev/whatever". So we can't use "dd" to copy the boot sector to the virtual disk.

How do you guys handle virtual disks?

Roel
Rudster816
Member
Member
Posts: 141
Joined: Thu Jun 17, 2010 2:36 am

Re: No loop device in Cygwin

Post by Rudster816 »

As embarrassing\broken this code is, it's what I wrote really quickly to produce a FAT32 HDD image for Qemu on Windows. I couldn't find any tool for Windows that could edit a binary image from the command line so I decided to write my own.

http://pastebin.com/dEE7vgfX

If you want to use it, you can do whatever you want with it, just keep in mind it's super ghetto. If you improve upon it, it would be nice if you sent me the code for my own use though :).


Also, read this to know why Cygwin doesn't have loopback devices.

http://cygwin.com/ml/cygwin-developers/ ... 00005.html
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: No loop device in Cygwin

Post by Combuster »

MTools does everything and the kitchen sink on FAT images (And it looks like Rudster missed it because it seems to fit his bill).

I only touch physical storage as the last step to prevent incomplete builds. I always work with images because of that, and because pretty much all VMs and emulators prefer disk images. I have quite a few more tools in my arsenal, but they are all meant to deal with non-floppy or non-x86 platforms.
Last edited by Combuster on Mon Mar 19, 2012 11:58 am, edited 1 time in total.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Nable
Member
Member
Posts: 453
Joined: Tue Nov 08, 2011 11:35 am

Re: No loop device in Cygwin

Post by Nable »

I use mostly raw images, so it's obvious to access them.

I've never used ImDisk but if it mounts images, then may be you can access them using something like /proc/sys/Device/HarddiskX/Partition0
( 1to1 cygwin mapping of Windows NT native \\.\Device\HarddiskX\ ), X is a number, Partition0 means accessing to the whole disk starting from sector 0, not to a partition. Be careful, you may accidentally erase your harddrive.
Rudster816
Member
Member
Posts: 141
Joined: Thu Jun 17, 2010 2:36 am

Re: No loop device in Cygwin

Post by Rudster816 »

Combuster wrote:MTools does everything and the kitchen sink on FAT images (And it looks like Rudster missed it because it seems to fit his bill).

I only touch physical storage as the last step to prevent incomplete builds. I always work with images because of that, and because pretty much all VMs and emulators prefer disk images. I have quite a few more tools in my arsenal, but they are all meant to deal with non-floppy or non-x86 platforms.
Just compiled it on Cygwin (odd that Cygwin doesn't provide a package for it), it looks very promising, thanks!


To anyone who compiles it on Cygwin, I had to edit the Makefile to include the libiconv library.

I changed the line (line 61 on my generated Makefile)
LIBS =

to
LIBS = /lib/libiconv.a

obviously you'll need libiconv installed (Cygwin provides a package if you don't already have it).
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re: No loop device in Cygwin

Post by bubach »

I use ImDisk to create/mount the image file and partcopy for inserting the bootsector or direct copying of sectors. The kernel gets copied using Windows normal copy command since it's a FAT12 image.
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
User avatar
Nessphoro
Member
Member
Posts: 308
Joined: Sat Apr 30, 2011 12:50 am

Re: No loop device in Cygwin

Post by Nessphoro »

Please check out the extended article for diskpart
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: No loop device in Cygwin

Post by qw »

Nable, that would be "/proc/sys/Device/ImDisk0" in my case. It's ugly but it works. Thanks!

EDIT: I added this to my Makefile, so I can run "make mount boot unmount":

Code: Select all

IMAGE	= hobbes.img
UNIT	= 0
MOUNT	= h

DEVICE	= /proc/sys/Device/ImDisk$(UNIT)
DRIVE	= /cygdrive/$(MOUNT)

boot	: boot.bin
	dd if=$< of=$(DEVICE)

mount	:
	imdisk -a -m $(MOUNT): -o fd -o rem -f $(IMAGE) -u $(UNIT)

unmount	:
	imdisk -d -m $(MOUNT):
EDIT 2: Using device name "/proc/sys/DosDevices/Global/$(MOUNT):" is even better because it eliminates the need of UNIT, so ImDisk can pick the unit number itself. It also makes the code independent from ImDisk.
Post Reply