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 https://qiita.com/takoyaki3/items/d1b2623c62aba5231f90

brd: Block device created in memory --Qiita https://qiita.com/satoru_takeuchi/items/6ea57ca74016d5d92425

Motivation

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.

environment

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 https://unix.stackexchange.com/questions/157041/how-linux-kernel-3-x-manage-ramdisk-as-block-device

Using the RAM disk block device with Linux — The Linux Kernel documentation https://www.kernel.org/doc/html/latest/admin-guide/blockdev/ramdisk.html

brd.c was 550 steps of code. https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/drivers/block/brd.c

VBoxManage internalcommands createrawvmdk

VBoxManage internalcommands createrawvmdk https://www.serverwatch.com/server-tutorials/using-a-physical-hard-drive-with-a-virtualbox-vm.html

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

https://www.virtualbox.org/manual/ch09.html#rawdisk

Creating a RAM Disk block device

  1. Parameters

2a) Kernel Command Line Parameters

ramdisk_size=N
    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).

Source: https://www.kernel.org/doc/html/latest/admin-guide/blockdev/ramdisk.html#parameters

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 https://ja.wikipedia.org/wiki/2 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.

Notes

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. https://www.freebsd.org/doc/handbook/disks-virtual.html

macOS host

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

mdconfig: command not found

orz

According to the following, `hdid``` and `hdiutil``` are likely to be used for this purpose. https://www.cnet.com/news/how-to-make-ram-disks-in-os-x/

~~ [Catarina](https://dic.nicovideo.jp/a/%E3%82%AB%E3%82%BF%E3%83%AA%E3%83%8A%28%E3%82% 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. https://en.wikipedia.org/wiki/List_of_RAM_drive_software#Microsoft_Windows

Recommended Posts

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