To create a RAM-based block device in Ubuntu.

To create a RAM-based block device in Ubuntu, use the

brd (RAM block device) kernel module to create a fast, memory-backed device (/dev/ram* ), or use tmpfs for simpler, file-based RAM storage. The brd method offers higher IOPS and mimics a real physical block device, ideal for performance testing or secure, temporary storage.

Method 1: Using brd (Kernel RAM Block Device)

This creates an actual block device in RAM, allowing for partitioning and file systems.

  1. Load the brd module and create a 1GB RAM disk (size is in KiB):

    bash

    复制代码
    sudo modprobe brd rd_nr=1 rd_size=1048576 max_part=1
    • rd_nr=1 : Creates one device (/dev/ram0 ).

    • rd_size=1048576 : Size in KiB (

      1024×1024=1GB1024 cross 1024 equals 1 GB
      1024×1024=1GB ).

  2. Format the RAM disk (e.g., ext4):

    bash

    复制代码
    sudo mkfs.ext4 /dev/ram0
  3. Mount the device :

    bash

    复制代码
    sudo mkdir /mnt/ramdisk
    sudo mount /dev/ram0 /mnt/ramdisk
  4. Clean up (unmount and remove module):

    bash

    复制代码
    sudo umount /mnt/ramdisk
    sudo rmmod brd

Method 2: Using tmpfs (Temporary File System)

tmpfs is generally easier, acts like a ramdisk, and can swap to disk if RAM runs out.

  1. Create mount point :

    bash

    复制代码
    sudo mkdir /mnt/ramdisk
  2. Mount as tmpfs (e.g., 1GB):

    bash

    复制代码
    sudo mount -t tmpfs -o size=1G tmpfs /mnt/ramdisk

Summary Table

Feature brd (Method 1) tmpfs (Method 2)
Type Actual Block Device Filesystem in RAM
Performance Highest IOPS High
Swap No Yes (may swap to disk)
Setup modprobe + mkfs mount -t tmpfs

Note: Any data on a RAM disk is lost upon reboot or when the module is removed.

相关推荐
The️4 小时前
Linux驱动开发之Open_Close函数
linux·运维·驱动开发·mcu·ubuntu
weixin_444579307 小时前
Ubuntu 22.04 服务器安装教程(二)——桌面版系统
linux·服务器·ubuntu
YQ_011 天前
Ubuntu下安装WPS
linux·ubuntu·wps
小志biubiu1 天前
Linux_进程概念(A)-进程部分【Ubuntu】
linux·运维·服务器·ubuntu·操作系统·进程
普通网友1 天前
Ubuntu 入门及安装全指南
linux·运维·ubuntu
花间相见1 天前
【Ubuntu实用工具】—— Gnome拓展管理器及实用拓展
linux·运维·ubuntu
adnyting1 天前
【牙牙学语(一)】Ubuntu配置宝塔面板、Cloudflare Tunnel、免费域名访问 完整搭建指南
ubuntu·妙点
花间相见1 天前
【Ubuntu实用工具】—— Fcitx5 输入法安装与完整配置指南(新手友好+避坑版)
linux·数据库·ubuntu
鸠摩智首席音效师1 天前
如何在 Ubuntu 上安装 phpMyAdmin ?
linux·运维·ubuntu
_OP_CHEN2 天前
【MySQL数据库基础】(一)保姆级 MySQL 环境配置教程!CentOS 7+Ubuntu 双系统全覆盖
linux·数据库·sql·mysql·ubuntu·centos·环境配置