1

I learned that I can do modprobe brd rd_nr=1 rd_size=4585760 max_part=1 if I want to create a ram block device at /dev/ram0 but lets say I want to flush the device (to free the ram), then delete it and create another. How would I do this running modprobe brd rd_nr=1 rd_size=4585760 max_part=1 again doesn't seem to create another ram device in /dev

Recreate steps:

1) create disk: modprobe brd rd_nr=1 rd_size=4585760 max_part=1

2) use the ram disk for some arbitrary task: ex: dd if=/dev/zero of=/dev/ram0 count=1000

3) free up the memory blockdev --flushbufs /dev/ram0

4) delete device file: rm /dev/ram0

5) try to create another one: modprobe brd rd_nr=1 rd_size=4585760 max_part=1

6) ls /dev/ram* gives me an error

I know that I can change the rd_nr to be whatever number I desire but I want to be able to create these on the fly.

Edit: I don't want to create a tmpfs, my use case requires a block device

2

You should not delete /dev/ram0 yourself. It will be deleted when you do sudo rmmod brd, which frees the space and removes the module. You can then start again from modprobe.

2

I am not familiar with /dev/ram but you can do something similar with tmpfs and loop devices:

mkdir /ramdisks
mount -t tmpfs tmpfs /ramdisks
dd if=/dev/zero of=/ramdisks/disk0 bs=1M count=100
losetup /dev/loop0 /ramdisks/disk0
mke2fs /dev/loop0
...
losetup -d /dev/loop0
rm /ramdisks/disk0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.