Skip to content

Instantly share code, notes, and snippets.

@abrasive
Last active April 3, 2024 01:58
Show Gist options
  • Save abrasive/ac5b9c9f6727201774c41f5a3078be1d to your computer and use it in GitHub Desktop.
Save abrasive/ac5b9c9f6727201774c41f5a3078be1d to your computer and use it in GitHub Desktop.
Set up a laptop as NVMe-over-fabric target in initramfs
#!/bin/sh
# This imports the nvme device exported by the nvme-target-mode.sh script
set -e
sudo modprobe nvme-fabrics
sudo ifconfig thunderbolt0 10.99.1.1 netmask 255.255.255.0 up
sudo nvme connect -t tcp -a 10.99.1.2 -n mylaptopname -s 4420
#!/bin/sh
# This script configures the Thunderbolt interface with a static IP and exports nvme0 over TCP to all comers.
# Your kernel config needs:
# CONFIG_NVME_FABRICS
# CONFIG_NVME_TARGET
# CONFIG_NVME_TARGET_TCP
# The client additionally needs CONFIG_NVME_TCP
set -e
IP=10.99.1.2
# my initrd has already imported my ZFS pool before this point, YMMV
zpool export mypool
ip addr add $IP/24 dev thunderbolt0
ifconfig thunderbolt0 up
mount -t configfs none /sys/kernel/config
cd /sys/kernel/config/nvmet
SUB=subsystems/mylaptopname
mkdir $SUB
echo 1 > $SUB/attr_allow_any_host
NS=$SUB/namespaces/1
mkdir $NS
echo /dev/nvme0n1 > $NS/device_path
echo 1 > $NS/enable
PORT=ports/1
mkdir $PORT
echo $IP > $PORT/addr_traddr
echo tcp > $PORT/addr_trtype
echo 4420 > $PORT/addr_trsvcid
echo ipv4 > $PORT/addr_adrfam
ln -s $SUB $PORT/subsystems/
echo NVMe target ready
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment