Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
The script is from Container Linux: coreos/fedora-coreos-tracker#104 (comment), I changed it and tested to make sure it works on fcos.
  • Loading branch information
bh7cw committed Jun 17, 2020
1 parent a6fbe03 commit 5cf37e3
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
47 changes: 47 additions & 0 deletions overlay.d/05core/usr/lib/udev/bin/aws-ebs-nvme-id
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash

# Copyright (c) 2020 The CoreOS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

usage() {
echo "Usage: $0 [-d|-p|-h] <device>" 1>&2
}

# Get partition ID from device name, e.g. '/dev/nvme0n1p2' -> '1'
namespace_id() {
NSID=$(echo -n "$1" | cut -f 3 -d 'n' | cut -f 1 -d 'p')
echo "_NS_ID=${NSID}"
}

# Get device name from raw metadata,
devname() {
RAWVOL=$(nvme id-ctrl --raw-binary "$1" | cut -c3073-3104 | tr -s ' ' | sed 's/ $//g')
VOL="${RAWVOL#/dev/}"
if [[ -n "$VOL" ]]; then
echo "${VOL}"
else
exit 1
fi
}

while getopts "hd:n:" o; do
case "${o}" in
d)
devname "${OPTARG}"
exit 0
;;
n)
namespace_id "${OPTARG}"
exit 0
;;
h)
usage
exit 0
;;
*)
usage
exit 1
;;
esac
done
14 changes: 14 additions & 0 deletions overlay.d/05core/usr/lib/udev/rules.d/70-aws-ebs-nvme-id.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#AWS EBS NVMe
ACTION!="add|change", GOTO="aws_ebs_nvme_end"
SUBSYSTEM!="block", GOTO="aws_ebs_nvme_end"

# NVMe devices
KERNEL=="nvme[0-9]*n[0-9]*", ENV{DEVTYPE}=="disk", ATTRS{model}=="Amazon Elastic Block Store", ATTRS{serial}=="?*", SYMLINK+="disk/by-id/nvme-$attr{model}_$attr{serial}-ns-%n", OPTIONS+="string_escape=replace"
KERNEL=="nvme[0-9]*n[0-9]*", ENV{DEVTYPE}=="disk", ATTRS{model}=="Amazon Elastic Block Store", ATTRS{serial}=="?*", PROGRAM="/usr/lib/udev/bin/aws-ebs-nvme-id -d /dev/%k", SYMLINK+="%c"

# NVMe partitions
KERNEL=="nvme[0-9]*n[0-9]*p[0-9]*", ENV{DEVTYPE}=="partition", ATTRS{model}=="Amazon Elastic Block Store", ATTRS{serial}=="?*", IMPORT{program}="/usr/lib/udev/bin/aws-ebs-nvme-id -d /dev/%k"
KERNEL=="nvme[0-9]*n[0-9]*p[0-9]*", ENV{DEVTYPE}=="partition", ATTRS{model}=="Amazon Elastic Block Store", ATTRS{serial}=="?*", ENV{_NS_ID}=="?*", SYMLINK+="disk/by-id/nvme-$attr{model}_$attr{serial}-ns-$env{_NS_ID}-part%n", OPTIONS+="string_escape=replace"
KERNEL=="nvme[0-9]*n[0-9]*p[0-9]*", ENV{DEVTYPE}=="partition", ATTRS{model}=="Amazon Elastic Block Store", ATTRS{serial}=="?*", ENV{_NS_ID}=="?*", PROGRAM="/usr/lib/udev/bin/aws-ebs-nvme-id -d /dev/%k", SYMLINK+="%c%n"

LABEL="aws_ebs_nvme_end"

0 comments on commit 5cf37e3

Please sign in to comment.