Emulate a hard drive in Linux
Asked Answered
C

2

10

I have developed a FUSE-based file system as part of a research project and now have to study the actual read/write requests that are received by the hard drive. In an attempt to do this, I am looking at the option of creating a virtual Hard Drive in linux, that will intercept the requests being generated by the file system and log them.

Are there any resources available on the internet that can help me write the emulator and/or develop the skill sets needed to write one? I am currently reading the Linux Device Drivers 3 book to get an idea of how Linux manages block devices.

Any help is appreciated.

Thanks

Calculable answered 6/8, 2011 at 16:49 Comment(0)
T
3

Well, there is a way to mount an image file as a partition:

mount -t <fs type> -o loop file.img /mnt

substitute with your file system type, file.img should be an image of the desired partition.

Yet another way, you can install virtualbox, install linux on the virtual machine, add a new virtual hard drive and from within the virtual machine, format the virtual hard drive with the desired filesystem and use it. An advantage of this approach is that it provides a safe sandbox so that you don't accidentally damage your existing system while experimenting.

Tutankhamen answered 6/8, 2011 at 17:25 Comment(1)
Thanks for your answer. But that solution does not really allow me to get into to actual nitty-gritty of the events. I want to be able to track the requests being sent from the device driver. The way I see this happening is to write a block device driver, which then routes the requests to the emulator. However, the emulator will be running in user-space as opposed to the block device driver, which will be running in kernel space. I also need a mechanism to transfer requests from the block device driver to the emulator. And that is the reason I am looking for literature to write an emulator.Calculable
D
3

Take a look at the SCSI debug driver. Quoting from the site

The scsi_debug adapter driver simulates a variable number of SCSI disks, each sharing a common amount of RAM allocated by the driver to act as (volatile) storage.

If it were me, I'd enable the debug logging already present in that driver and then enhance it to suit your needs.

Dissident answered 7/8, 2011 at 22:48 Comment(1)
I read the documentation at the link that you had mentioned in your post. I cannot use that because I need persistence and the scsi_debug module uses an in-memory solution. Also, I'm trying to avoid messing with the buses. I am looking to pass control from the block device driver (which I shall be writing myself) to the emulator. I checked out CDemu, which has somewhat of the same architecture (although it does have a Virtual Host Bus Adapter module) where a kernel space component passes control to a daemon running in user-space.Calculable

© 2022 - 2024 — McMap. All rights reserved.