2

Often people take an image of a hard dive with dd, for example, and then mount the partitions within using kpartx or losetup. It's a common way to make the partitions on an image file mountable and look like a filesystem.

I'm wondering if it's possible to do the reverse; that is make a device like /dev/sda look like a file. Note: my purpose in asking this is in relation to a raid0 data recovery.

In my case, I could dd the two 2TB drives I'm working on to some other storage container and operate on the image files. But that is painful, so I'm trying to avoid taking images.

Any ideas how to make a drive like /dev/sda look like a file?

Edit to add more info.

The tool I'm trying to use for recovery is FUSE based, http://pyraid.googlecode.com If I run it against image files it works fine. If I run it against block devices (/dev/sdx) it does not work.

file /dev/sda
/dev/sda: block special

file sda.img
sda.img: data

So to ask my question another way, how can I make a block special device look like data?

qwopper
  • 21
  • 2
  • 7
    It already "looks like a file." And if you're really trying to recover data from those disks, you should be taking images. – Michael Hampton Sep 01 '13 at 05:26
  • 3
    `/dev/sda` is a file and you can treat it like a file. – replay Sep 01 '13 at 05:32
  • 4
    I don't know where in the world you are but I'm guessing it's really late and you're tired. Go to bed and come back refreshed tomorrow and marvel at how stupid being tired can make you. – user9517 Sep 01 '13 at 05:45
  • "It does not work" is not useful. You should have received (and posted here) an error message. – Michael Hampton Sep 01 '13 at 14:43
  • There is no error message. Pyraid appears to work but it just creates a zero byte raid device when you feed it block devices. – qwopper Sep 01 '13 at 15:28
  • Hm, sounds like a bug. Then again, you really should be working on images anyway. – Michael Hampton Sep 01 '13 at 15:42
  • This question has an answer here: https://unix.stackexchange.com/questions/561877/mount-a-block-device-as-a-regular-file: use the fuse "passthrough" demo, as well as here: https://superuser.com/questions/543492/the-opposite-of-mount-o-loop-can-i-read-a-block-device-as-a-regular-file the "diskfile" utility – remram Jun 05 '23 at 04:14

1 Answers1

2

Sure you can. In linux, everything acts like a file. The point of imaging isn't to make something into a file - its to ensure you do not mess things up and damage things further. You could do recovery directly from a drive, using the exact same tools, but if you have physical damage, or you wrote to the drive,... boom.

So, if you wanted to work directly off the whole drive - run your tools on /dev/sdX and on /sdXn if you wanted to work off a partition. Just that you risk more data loss. Making an image is the smart thing, since if you work off an image of an image, and you make a mistake you can just delete it, start over from a fresh copy and not lose anything.

Imaging is just due diligence. Do it. Its much more hassle to be working to recover things from part of a disk that you just accidentally dded over. It also is very useful if you suspect hardware failure. Its worth the 2-3 hours or so (and the temporary disk space you will need) for the peace of mind.

Journeyman Geek
  • 6,977
  • 3
  • 32
  • 50