4

For some testings, I need to access something like /dev/sda in my program.

But I can't do this on my own hard disk drive. You know why :D

Is there a way to create /dev/sdb using RAM or a file on another disk? I just need it to be there, and act like a disk while I'm using it, no matter what.

I know I can use virtual machines for this, but that invloves installing a linux. That is time consuming and is not so elegant.

3 Answers 3

3

Something like /dev/sdX may be difficult to do, however you might be able to use a USB drive to fulfill the need (I do have a hack solution for you though)

In a more general sense you can create a block device by creating a partition (dd if=/dev/zero of=file.img count=102400), then mounting it as a loopback device (losetup /dev/loopX file.img). You can treat the loop device like a block device (eg use FDISK on it). If you then want to access partitions you can use partx -a /dev/loopX

After creating your loopback device, it appears you can create symlinks to it, so ln -s /dev/loop0 /dev/sdz ln -s /dev/loop0p1 /dev/sdz1

Which will give you /dev/sdz and /dev/sdz1 (which, of-course, refer ultimately to the loopback file you made).

1
  • Thanks a lot, it totally worked. I was going to use this in a C program with read/lseek/write/open/close calls, and it worked like a charm!
    – vfsoraki
    Feb 27, 2014 at 9:13
1

Yes you can create RAM disk, here are instructions how to do this:

How to create RAM disk in Linux

1
  • I read that link. I suppose it creates a filesystem, but I wanted something like a raw disk, e.g. /dev/sdz not /dev/sdz1. Anyway, It was also a good thing to read and learn. Thanks!
    – vfsoraki
    Feb 27, 2014 at 9:16
0

Use BUSE project for this. It implements a block device based on RAM disk in user space. https://github.com/acozzette/BUSE

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .