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.

相关推荐
sxstj3 小时前
Ubuntu 完整安装并启用 Flatpak 教程
linux·运维·ubuntu
天疆说3 小时前
Ubuntu 26.04 下 Intel Meteor Lake 核显 + NPU 驱动配置与 PyTorch NPU 推理实测
linux·pytorch·ubuntu
meilindehuzi_a4 小时前
TypeScript面试题:interface 与 type:相同点、核心区别与选择指南
java·ubuntu·typescript
铁锚5 小时前
解决Ubuntu执行sudo时 unable to resolve host 报错问题
linux·数据库·ubuntu
Delta-delta6 小时前
win+ubuntu24.04双系统安装
ubuntu
淮北4949 小时前
ubuntu22 默认输入法调整频率
运维·服务器·git·ubuntu·elasticsearch
燐妤9 小时前
腾讯云 Ubuntu 24.04 + Docker 同时部署多个 Python Web 项目:没有域名也能用 IP 访问
ubuntu·docker·腾讯云
十年磨一剑~11 小时前
CAAM不落盘存储密钥方式处理
linux·ubuntu
zhangrelay11 小时前
ROS 2 Lyrical 第2章 ROS 2系统架构与核心概念
linux·笔记·学习·ubuntu·ros2
数智工坊19 小时前
Zotero自建Ubuntu WebDAV附件同步方案(完美解决存储空间不足)
linux·运维·ubuntu