Apply Ramdisk block device, allocate RAM Disk to VirtualBox virtual drive and try installing Linux

Happy New Year </ font>

No insurance certificate

Licenses, disclaimers, and prohibitions regarding technical information written by us

Previous research

Copy speed comparison when a virtual machine is set up on Ram Disk (Ram Disk, NvMe SSD, SSD, HDD, external HDD) --Qiita

brd: Block device created in memory --Qiita


I wanted to build an on-memory virtual machine with VirtualBox, so I'm sorry.

  • Any virtual environment that can read and write block devices as virtual HDDs should be usable for the same purpose.


Host OS: `` `modprobe brd``` possible, VirtualBox installed Linux Guest OS: OS that makes it easy to build a minimal environment such as Slackware Linux

  • Other than Slackware, Debian, Arch, or FreeBSD is easy to create a minimal environment. If you're doing it on Gentoo, it's better to have some extra memory to allocate.

Referenced literature

RAM disk block device How Linux kernel 3.x manage ramdisk as block device? - Unix & Linux Stack Exchange

Using the RAM disk block device with Linux — The Linux Kernel documentation

brd.c was 550 steps of code.

VBoxManage internalcommands createrawvmdk

VBoxManage internalcommands createrawvmdk

Chapter 9. Advanced Topics - Oracle® VM VirtualBox® User Manual

  • 9.7. Advanced Storage Configuration
  • 9.7.1. Using a Raw Host Hard Disk From a Guest

Creating a RAM Disk block device

  1. Parameters

2a) Kernel Command Line Parameters

    Size of the ramdisk.

This parameter tells the RAM disk driver to set up RAM disks of N k size. The default is 4096 (4 MB).


I wanted to allocate about 8G, so I set it to `1024 (KiB) x8 × 2 ^ 10 = 8388608 (KiB)` (the allocation is [~~ m × {(2 ^ 10) × n } ``` ~~ m × (2 ^ 10n)` `` unit system](assuming prefix)).

The command line on the host OS is as follows

sudo modprobe brd rd_size=8388608

This will bring up / dev / ramX (where X is a number).

Release the ramdisk after umount etc. in / dev / ramX

sudo modprobe --remove brd

I feel good.


The owner of the block device of the host OS, for example

$ ls -l /dev/ram0
brw-rw---- 1 root disk 1,0 January 1 11:08 /dev/ram0

If the current user belongs to the group "disk", the block device can be read and written without being promoted to root. It's a little easier, but be careful not to inadvertently say `` `dd if = / dev / zero of = / dev / sdX```.

Allocate RAM Disk by diverting the function of allocating a physical drive to the virtual HDD of VirtualBox

The following is an example of a command line that generates a vmdk that reads / writes / dev / ram0 under `$ HOME /'VirtualBox VMs' /`.

VBoxManage internalcommands createrawvmdk -filename $HOME/'VirtualBox VMs'/ramdisk.vmdk -rawdisk /dev/ram0

If you specify this $ HOME /'VirtualBox VMs' / ramdisk.vmdk as the HDD of the virtual machine on the VirtualBox side, it is OK.

  • If an error occurs when installing the OS or operating the virtual machine, it may be better to switch ON / OFF of "Use HOST IO cache" on the drive controller.

OS installation on virtual machine

There was no problem with the normal OS installation procedure. With this method, the capacity that can be allocated to the virtual HDD is small, so I think that a lightweight OS is suitable.

The part that I felt troublesome

Since / dev / ram0 is regenerated every time the host is restarted, the UUID of the device changes each time. ↓ Each time you need to recreate vmdk and re-register it in the virtual media manager or virtual machine.

It seems that this area should be made into a shell script and automated.

  • If you back up and restore / dev / ram0 with dd, it seems that you can go with the same UUID all the time.

FreeBSD, macOS, Windows, etc.

I searched for commands / apps that could be used for the same purpose when hosting an OS other than Linux.

FreeBSD host

According to the following, the same can be done using the mdconfig (md probably stands for memory disk) command.

macOS host

It's a BSD system, and is it included in mdconfig?

mdconfig: command not found


According to the following, `hdid``` and `hdiutil``` are likely to be used for this purpose.

~~ [Catarina]( B0% E3% 83% A9% E3% 83% B3% E3% 83% 96% E3% 83% AB% E3% 83% BC% E3% 83% 95% E3% 82% A1% E3% 83% B3% E3% 82% BF% E3% 82% B8% E3% 83% BC% 29) ~~ OS 10.15 Catalina also had hdid and hdiutil, so it should be okay.

Windows10 host

According to the following, ImDisk seems to be usable for this purpose.

Recommended Posts

Apply Ramdisk block device, allocate RAM Disk to VirtualBox virtual drive and try installing Linux
Block device RAM Disk Creating a device