Skip to content

Instantly share code, notes, and snippets.

@jalaziz
Last active September 20, 2024 09:18
Show Gist options
  • Save jalaziz/bcfe2f71e3f7e8fe42a9c294c1e9279f to your computer and use it in GitHub Desktop.
Save jalaziz/bcfe2f71e3f7e8fe42a9c294c1e9279f to your computer and use it in GitHub Desktop.
CoreOS AWS EBS NVMe udev rules
# Copyright (C) 2018 Jameel Al-Aziz
# Modified for simplicification and use within CoreOS.
#
# Copyright (C) 2006-2016 Amazon.com, Inc. or its affiliates.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# A copy of the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
# OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the
# License.
# ebs nvme devices
KERNEL=="nvme[0-9]*n[0-9]*", ENV{DEVTYPE}=="disk", ATTRS{model}=="Amazon Elastic Block Store", PROGRAM="/opt/bin/ebs-nvme-mapping /dev/%k", SYMLINK+="%c"
#!/bin/bash
# This file has been modified from
# https://github.com/oogali/ebs-automatic-nvme-mapping/blob/master/ebs-nvme-mapping.sh
#
# Copyright (c) 2018 Omachonu Ogali
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
vol=$(nvme id-ctrl --raw-binary "$1" | cut -c3073-3104 | tr -s ' ' | sed 's/ $//g')
vol=${vol#/dev/}
if [[ -n "$vol" ]]; then
echo ${vol/xvd/sd} ${vol/sd/xvd}
fi
[Unit]
Description=Reload AWS EBS NVMe rules
Before=user-config.target
DefaultDependencies=no
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/udevadm control --reload-rules
ExecStart=/usr/bin/udevadm trigger -y "nvme[0-9]*n[0-9]*"
ExecStart=/usr/bin/udevadm settle
[Unit]
Description=Formats /dev/xvdb
Before=dbus.service docker.service
After=ebs-nvme-udev-trigger.service dev-xvdb.device
Wants=ebs-nvme-udev-trigger.service dev-xvdb.device
DefaultDependencies=no
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/bash -c '(blkid -t TYPE=ext4 /dev/xvdb) || (/usr/sbin/mkfs.ext4 -F /dev/xvdb)'
@r7vme
Copy link

r7vme commented Jun 7, 2018

Helped us too! thanks @jalaziz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment