Linux 内核 3.x 如何将 ramdisk 作为块设备进行管理?

Mos*_*afa 5 block-device ramdisk

我需要 RAM 中的块设备。我构建了一个 3.x 内核并添加了 RAM 块设备驱动程序。RAM块设备驱动器的数目为16(默认),但是当在内核引导代码中没有ramx/sys/block也不/dev。这是怎么回事?

小智 8

我想你的意思是这样的:

加载块 ramdisk 模块,使用rd_size=...参数以块为单位设置所需的大小。

# modprobe brd rd_size=123456
Run Code Online (Sandbox Code Playgroud)

...在此步骤/dev/ram0存在之后。

您现在可以在其上放置文件系统。

# mkfs /dev/ram0
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
30976 inodes, 123456 blocks
6172 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
16 block groups
8192 blocks per group, 8192 fragments per group
1936 inodes per group
Superblock backups stored on blocks: 
        8193, 24577, 40961, 57345, 73729

Writing inode tables: done                            
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 38 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
Run Code Online (Sandbox Code Playgroud)

安装它并检查已使用的空间并释放...

# mount /dev/ram0 /mnt 
# df /mnt 
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/ram0               119539      1550    111817   2% /mnt
Run Code Online (Sandbox Code Playgroud)