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.

相关推荐
zhangrelay17 小时前
《机器人控制器设计与编程》课程习题资料-2026
linux·笔记·学习·ubuntu
Linux-lucky17 小时前
39-41-Linux学习之旅之redis缓存基础与NFS基础
linux·运维·mysql·ubuntu
QQ142207844919 小时前
2012 年的老 ThinkPad E430 改装 Ubuntu 24.04全程翻车排查实录
ubuntu·项目复盘
阿钱真强道19 小时前
06 嵌入式操作系统 | vim 与软件管理:apt / 源码编译
ubuntu·vim·嵌入式·apt·源码编译
牢姐与蒯19 小时前
Linux进程间通信(三).基于匿名管道的进程池的实现
linux·运维·服务器·ubuntu
Linux-lucky1 天前
32-38-Linux学习之旅之MySQL综合
linux·运维·学习·mysql·ubuntu
士訫2 天前
【Linux 踩坑】HP Victus RTX4050 Ubuntu 系统双屏无法同时点亮解决方案(完美适配 Advanced Optimus 机型)
ubuntu
指尖的爷2 天前
ARM 架构 Ubuntu(RK3588/aarch64)go开发环境安装手册
ubuntu·架构·golang
虚无的纽扣2 天前
【Linux】将进程知识与基础IO融会贯通——简单自定义Shell的实现
linux·ubuntu
问简3 天前
Ubuntu 26 + Windows 10 双系统 NTFS 共享盘笔记
ubuntu