1

latest kernels have made ramdisk modules:

CONFIG_BLK_DEV_RAM=m

Which is the module and where to find it.

Is loadable during boot from initramfs ?

I had root on software RAID1 with SSD and Ramdisk (/dev/ram1)

with write-mostly on SSD.

CONFIG_BLK_DEV_RAM in original kernel is boolean, now is module ?!?!

Any rationale for this change ?

Thank You

user683323
  • 13
  • 1
  • 4

2 Answers2

3

The block ramdisk module is called brd and can be loaded as follows:

sudo modprobe brd rd_size=100000

where rd_size is the number of blocks. After this step you have a device /dev/ram0 that you can put a filesystem on:

sudo mkfs /dev/ram0

and mount.

Jos
  • 28,156
  • 8
  • 82
  • 88
  • Thank You ! I've added "brd rd_size=16777216" to /etc/initramfs/modules . Run update-initramfs -u after and everything is ok ! – user683323 Apr 28 '17 at 20:57
  • Good. If you are satisfied with my answer, please tick the check mark next to it to mark your question as answered. – Jos Apr 28 '17 at 21:05
  • I read in the `mkfs` man page that if you don't specify `--type` ext2 is used by default. When comes to a RAM disk, I wonder if ext4 would be better or not. – Lonnie Best Jul 13 '20 at 13:50
1

Another option for a RAM Disks is zram. When you place a file onto a zram RAM disk, the file gets quickly compressed during the transfer and it is transparently decompress during the retrieval. This can be helpful in circumstances where your system doesn't quite have the amount of RAM you desire for your RAM disk.

Here's how to create a zram RAM disk:

Make a folder to which you will mount your RAM disk:

sudo mkdir /tmp/ramdisk 

Change the ownership of that folder, so your user will have full access to the RAM disk when we later mount it:

sudo chown -R yourUserName:yourGroupName /tmp/ramdisk

Make the folder immutable so you don't ever accidentally fill up your OS partition with data intended for the RAM disk:

sudo chattr +i /tmp/ramdisk

Load the zram module:

sudo modprobe zram

Create a 1GB ram disk:

sudo zramctl --find --size 1G

The command above will output the device path of the RAM disk you've created. It will most likely be /dev/zram0, and that's what we'll assume going forward.

Format the RAM disk to EXT4:

sudo mke2fs -t ext4 -O ^has_journal -L "zram device" /dev/zram0

Mount the RAM disk to the immutable mount point folder we created:

sudo mount /dev/zram0 /tmp/ramdisk

Now you should be able to move files to and from the RAM disk located at /tmp/ramdisk/.

If you're done playing with it, unmount it:

sudo umount /tmp/ramdisk/

Lastly, lets destroy the RAM disk and free up any memory it was using:

sudo zramctl --reset /dev/zram0

If you also want to remove the the folder /tmp/ramdisk, first make it mutable:

sudo chattr -i /tmp/ramdisk

Now you can delete the folder:

rm -rf /tmp/ramdisk
Lonnie Best
  • 2,174
  • 2
  • 32
  • 42