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.

相关推荐
Ujimatsu5 小时前
虚拟机安装Debian 13.x及其常用软件(2026.4)
linux·运维·ubuntu
拾贰_C7 小时前
【Agent | openai | Streaming | 】流式输出Streaming
ubuntu·面试·prompt
刘延林.10 小时前
win11系统下通过 WSL2 安装Ubuntu 24.04 使用RTX 5080 GPU
linux·运维·ubuntu
用户342688776219612 小时前
Agent + Ollama 部署踩坑记录
ubuntu
宁波阿成13 小时前
在ubuntu22.04源码级安装sub2api
linux·运维·ubuntu·ai·api·token·中转站
为美好的生活献上中指14 小时前
本地虚拟机部署redis集群
前端·redis·ubuntu·bootstrap·html·redis集群
一叶龙洲15 小时前
Ubuntu开机无法用向日葵远程控制
linux·运维·ubuntu
我是谁??16 小时前
ubuntu22.04 + 驱动570.211.01 + cuda12.8
ubuntu·raid
半壶清水17 小时前
ubuntu中部署开源交换机模拟器bmv2详细步骤
linux·运维·网络·网络协议·tcp/ip·ubuntu
Will_Ye19 小时前
Ubuntu:系统断网后自动重连指定wifi脚本
linux·运维·ubuntu