Search code examples
linuxramdisk

Direct copy Ramdisk image to Ramdisk device


Right, so I've got a Ramdisk image on a mounted device at, say, /mnt/sda1/Ramdisk.img . I want to copy the raw data directly to a ramdisk device at /dev/ram0, in such a way that there will be no need to use mke2fs: I could mount the image and device and find that both are identical.

Ideally this would use only linux commands.

My ideas so far: Mounting the image on a loopback and using basic IO to put the data from one device into the other. I could probably do this with C. Also, somehow finding the physical address of the ramdisk device and using linux or C commands to put the file directly into the memory.

Thanks in advance.

P.S: I know that the kernel somehow flags memory which was used for ramdisks so the system does not reclaim it. Anyone know where these flags are?


Solution

  • Any kind of copy command is going to require a partition and filesystem at the destination. However, dd can work at the disk or partition level, by just specifying the disk (eg /dev/sda) or partition (eg (dev/sda1) level. So in theory, you could do

    dd if=ramdisk_image_file of=/dev/ram0