loop设备模拟nvme设备

加载 nvme-loop内核模块(需要内核支持,或者自己编译 nvme-loop 相关模块)

sudo modprobe nvme-loop

生成 loop 文件

dd if=/dev/zero of=/path/to/nvme_fs bs=1M count=100
losetup -f /path/to/nvme_fs
#可用 losetup -a 查看 生成的 loop 设备
losetup -a

安装 configshell-fb

pip install configshell-fb
#如果是python3,则改为pip3

下载 NVME Target CLI

git clone git://git.infradead.org/users/hch/nvmetcli.git
cd nvmetcli

修改 nvmetcli 下的 examples/loop.json,将"path"改为生成的loop设备路径

diff examples/loop.json examples/loop-modified.json 
35c35
<             "path": "/dev/nvme0n1"
---
>             "path": "/dev/loop0"

生成 nvme target

./nvmetcli restore examples/loop.json
#如果是用的python3,不存在/usr/bin/python,可以在nvmetcli里将/usr/bin/python改为/usr/bin/python3
#dmesg 里可以看到
dmesg | tail
...
[ 2014.964638] nvmet: adding nsid 1 to subsystem testnqn

连接到 target

#安装nvme-cli
yum install nvme-cli
#连接到 target
nvme connect -t loop -n testnqn -q hostnqn
##dmesg 里可以看到
...
[ 2103.771075] nvmet: creating controller 1 for subsystem testnqn for NQN hostnqn.
[ 2103.773174] nvme nvme0: Please enable CONFIG_NVME_MULTIPATH for full support of multi-port devices.
[ 2103.773193] nvme nvme0: creating 4 I/O queues.
[ 2103.773562] nvme nvme0: new ctrl: "testnqn"

nvme list 查看

nvme list
Node                  SN                   Model                                    Namespace Usage                      Format           FW Rev
--------------------- -------------------- ---------------------------------------- --------- -------------------------- ---------------- --------
/dev/nvme0n1          4fe879af5fcdf13f     Linux                                    1          20.97  GB /  20.97  GB    512   B +  0 B   4.19.91-

参考

https://blog.csdn.net/Hello_NB1/article/details/93142900

你可能感兴趣的:(Linux,linux)