Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add support for early boot #2

Merged
merged 20 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

root = true

[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = space
indent_size = 2

[Makefile]
indent_style = tab

[*.{diff,md}]
trim_trailing_whitespace = false
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.rpm
*.tar
*.tar.gz
12 changes: 9 additions & 3 deletions 70-ec2-nvme-devices.rules
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ KERNEL=="nvme[0-9]*n[0-9]*", ENV{DEVTYPE}=="disk", ATTRS{serial}=="?*", ATTRS{mo
KERNEL=="nvme[0-9]*n[0-9]*p[0-9]*", ENV{DEVTYPE}=="partition", ATTRS{serial}=="?*", ATTRS{model}=="?*", IMPORT{program}="/usr/sbin/ec2nvme-nsid %k"
KERNEL=="nvme[0-9]*n[0-9]*p[0-9]*", ENV{DEVTYPE}=="partition", ATTRS{serial}=="?*", ATTRS{model}=="?*", ENV{_NS_ID}=="?*", SYMLINK+="disk/by-id/nvme-$attr{model}_$attr{serial}-ns-$env{_NS_ID}-part%n", OPTIONS+="string_escape=replace"

# ebs nvme devices
KERNEL=="nvme[0-9]*n[0-9]*", ENV{DEVTYPE}=="disk", ATTRS{model}=="Amazon Elastic Block Store", PROGRAM="/usr/sbin/ebsnvme-id -u /dev/%k", SYMLINK+="%c"
KERNEL=="nvme[0-9]*n[0-9]*p[0-9]*", ENV{DEVTYPE}=="partition", ATTRS{model}=="Amazon Elastic Block Store", PROGRAM="/usr/sbin/ebsnvme-id -u /dev/%k", SYMLINK+="%c%n"
# Import variables for EBS volumes
KERNEL=="nvme[0-9]*n[0-9]*", ENV{DEVTYPE}=="disk", ATTRS{model}=="Amazon Elastic Block Store", IMPORT{program}+="/usr/sbin/ebsnvme-id -U %k"
KERNEL=="nvme[0-9]*n[0-9]*p[0-9]*", ENV{DEVTYPE}=="partition", ATTRS{model}=="Amazon Elastic Block Store", IMPORT{program}+="/usr/sbin/ebsnvme-id -U %k"

# Assign symlinks
KERNEL=="nvme[0-9]*n[0-9]*", ENV{DEVTYPE}=="disk", ATTRS{model}=="Amazon Elastic Block Store", ENV{_EC2_BLOCK_DEVICE_MAPPING}=="?*", SYMLINK+="$env{_EC2_BLOCK_DEVICE_MAPPING}"
KERNEL=="nvme[0-9]*n[0-9]*", ENV{DEVTYPE}=="disk", ATTRS{model}=="Amazon Elastic Block Store", ENV{_EBS_VOLUME_ID}=="?*", SYMLINK+="disk/by-id/ebs-$env{_EBS_VOLUME_ID}"
KERNEL=="nvme[0-9]*n[0-9]*p[0-9]*", ENV{DEVTYPE}=="partition", ATTRS{model}=="Amazon Elastic Block Store", ENV{_EC2_BLOCK_DEVICE_MAPPING}=="?*", SYMLINK+="$env{_EC2_BLOCK_DEVICE_MAPPING}$env{ID_PART_ENTRY_NUMBER}"
KERNEL=="nvme[0-9]*n[0-9]*p[0-9]*", ENV{DEVTYPE}=="partition", ATTRS{model}=="Amazon Elastic Block Store", ENV{_EBS_VOLUME_ID}=="?*", SYMLINK+="disk/by-id/ebs-$env{_EBS_VOLUME_ID}-part$env{ID_PART_ENTRY_NUMBER}"

# Do not timeout I/O operations on EBS volumes.
KERNEL=="nvme[0-9]*n[0-9]*", ENV{DEVTYPE}=="disk", ATTRS{model}=="Amazon Elastic Block Store", ATTR{queue/io_timeout}="4294967295"
Expand Down
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the MIT License. See the LICENSE accompanying this file
# for the specific language governing permissions and limitations under
# the License.

RPM_BUILD_DIR := $(shell mktemp -d /tmp/amazon-linux-utils.rpm-XXXXXXXX)

.PHONY: rpm
rpm:
git archive --format=tar HEAD > amazon-ec2-utils.tar
gzip -f -9 amazon-ec2-utils.tar
rpmbuild --define "%_topdir $(RPM_BUILD_DIR)" -ta amazon-ec2-utils.tar.gz -v
cp -fv $(RPM_BUILD_DIR)/RPMS/**/*.rpm $(RPM_BUILD_DIR)/SRPMS/*.rpm .
110 changes: 66 additions & 44 deletions amazon-ec2-utils.spec
Original file line number Diff line number Diff line change
@@ -1,84 +1,106 @@
%define dracutlibdir %{_prefix}/lib/dracut

Name: amazon-ec2-utils
Summary: A set of tools for running in EC2
Version: 2.2.0
Release: 1%{?dist}
License: MIT
Group: System Tools

Source0: ec2-metadata
Source1: ec2udev-vbd
Source2: 51-ec2-hvm-devices.rules
Source16: 60-cdrom_id.rules
Source22: 70-ec2-nvme-devices.rules
Source23: ec2nvme-nsid
Source24: ebsnvme-id
Source25: 51-ec2-xen-vbd-devices.rules
Source26: 53-ec2-read-ahead-kb.rules

Source: amazon-ec2-utils.tar.gz
URL: https://github.com/aws/amazon-ec2-utils
BuildArch: noarch
Provides: ec2-utils = %{version}-%{release}
Obsoletes: ec2-utils < 2.1
Provides: ec2-metadata = %{version}-%{release}
Obsoletes: ec2-metadata <= 0.1
Requires: curl
Requires: python3
BuildRequires: python3-devel
BuildRequires: systemd-rpm-macros
BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
Requires: nvme-cli >= 1.13
BuildRequires: gzip systemd-rpm-macros
BuildRoot: %{_tmppath}/%{name}-root

%description
amazon-ec2-utils contains a set of utilities for running in ec2.
amazon-ec2-utils contains a set of utilities for running in EC2.

%prep
%autosetup -c

%build
# compress manpages
gzip -f -9 doc/*.8

%install
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT%{_bindir}
mkdir -p $RPM_BUILD_ROOT%{_udevrulesdir}
mkdir -p $RPM_BUILD_ROOT/%{_sbindir}
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/udev/rules.d/
mkdir -p $RPM_BUILD_ROOT%{_mandir}/man8/

install -m755 %{SOURCE0} $RPM_BUILD_ROOT%{_bindir}
install -m755 %{SOURCE1} $RPM_BUILD_ROOT/%{_sbindir}
install -m644 %{SOURCE2} $RPM_BUILD_ROOT%{_udevrulesdir}
install -m644 %{SOURCE25} $RPM_BUILD_ROOT%{_udevrulesdir}
install -m644 %{SOURCE26} $RPM_BUILD_ROOT%{_udevrulesdir}
# Directories
%{__install} -d -pm 755 %{buildroot}%{_bindir}
%{__install} -d -pm 755 %{buildroot}%{_mandir}/man8
%{__install} -d -pm 755 %{buildroot}%{_sbindir}
%{__install} -d -pm 755 %{buildroot}%{_sysconfdir}/dracut.conf.d
%{__install} -d -pm 755 %{buildroot}%{_sysconfdir}/udev/rules.d
%{__install} -d -pm 755 %{buildroot}%{_udevrulesdir}
%{__install} -d -pm 755 %{buildroot}%{dracutlibdir}/modules.d/96ec2-utils

# Scripts
%{__install} -pm 755 ebsnvme-id %{buildroot}%{_sbindir}/ebsnvme-id
%{__install} -pm 755 ec2-metadata %{buildroot}%{_bindir}/ec2-metadata
%{__install} -pm 755 ec2nvme-nsid %{buildroot}%{_sbindir}/ec2nvme-nsid
%{__install} -pm 755 ec2udev-vbd %{buildroot}%{_sbindir}/ec2udev-vbd

# man pages
%{__install} -pm 644 doc/ebsnvme-id.8.gz %{buildroot}%{_mandir}/man8/ebsnvme-id.8.gz
%{__install} -pm 644 doc/ec2-metadata.8.gz %{buildroot}%{_mandir}/man8/ec2-metadata.8.gz

# udev rules
%{__install} -pm 644 51-ec2-hvm-devices.rules %{buildroot}%{_udevrulesdir}/51-ec2-hvm-devices.rules
%{__install} -pm 644 51-ec2-xen-vbd-devices.rules %{buildroot}%{_udevrulesdir}/51-ec2-xen-vbd-devices.rules
%{__install} -pm 644 53-ec2-read-ahead-kb.rules %{buildroot}%{_udevrulesdir}/53-ec2-read-ahead-kb.rules
%{__install} -pm 644 70-ec2-nvme-devices.rules %{buildroot}%{_udevrulesdir}/70-ec2-nvme-devices.rules

# Install 60-cdrom_id.rules to /etc rather than %{_udevrulesdir}
# because it is intended as an override of a systemd-provided rules
# file:
install -m644 %{SOURCE16} $RPM_BUILD_ROOT%{_sysconfdir}/udev/rules.d/

#udev rules for nvme block devices and supporting scripts
install -m644 %{SOURCE22} $RPM_BUILD_ROOT%{_udevrulesdir}
install -m755 %{SOURCE23} $RPM_BUILD_ROOT%{_sbindir}/ec2nvme-nsid
install -m755 %{SOURCE24} $RPM_BUILD_ROOT/%{_sbindir}

%check
%{python3} -m py_compile %{SOURCE24}
%{__install} -pm 644 60-cdrom_id.rules %{buildroot}%{_sysconfdir}/udev/rules.d/60-cdrom_id.rules

%clean
rm -rf $RPM_BUILD_ROOT
# Dracut module
%{__install} -pm 644 dracut/dracut.conf %{buildroot}%{_sysconfdir}/dracut.conf.d/ec2-utils.conf
%{__install} -pm 755 dracut/module-setup.sh %{buildroot}%{dracutlibdir}/modules.d/96ec2-utils/module-setup.sh

%files
%license LICENSE
%doc README.md
%{_bindir}/ec2-metadata
%{_mandir}/man8/ebsnvme-id.8.gz
%{_mandir}/man8/ec2-metadata.8.gz
%{_sbindir}/ec2nvme-nsid
%{_sbindir}/ebsnvme-id
%{_sbindir}/ec2udev-vbd
/usr/lib/udev/rules.d/51-ec2-hvm-devices.rules
/usr/lib/udev/rules.d/51-ec2-xen-vbd-devices.rules
/usr/lib/udev/rules.d/53-ec2-read-ahead-kb.rules
/usr/lib/udev/rules.d/70-ec2-nvme-devices.rules
/etc/udev/rules.d/60-cdrom_id.rules
%{_udevrulesdir}/51-ec2-hvm-devices.rules
%{_udevrulesdir}/51-ec2-xen-vbd-devices.rules
%{_udevrulesdir}/53-ec2-read-ahead-kb.rules
%{_udevrulesdir}/70-ec2-nvme-devices.rules
%{_sysconfdir}/udev/rules.d/60-cdrom_id.rules

%package dracut
Summary: Dracut module providing early boot support for EC2 devices
Requires: amazon-ec2-utils = %{version}-%{release}
Requires: dracut

%description dracut
This subpackage contains the Dracut module that provides early boot support for EC2
devices, like making EBS NVMe devices have names in /dev that match their EC2 block
device mapping names.

%files dracut
%license LICENSE
%doc README.md
%{_sysconfdir}/dracut.conf.d/ec2-utils.conf
%{dracutlibdir}/modules.d/96ec2-utils/module-setup.sh

%changelog
* Thu Jan 18 2024 Keith Gable <gablk@amazon.com> - 2.2.0-1
- Corrected issue where an ec2-metadata error was written to stdout
- Change ec2nvme-nsid to use Bash string manipulation to improve
performance and reliability
- Rewrite ebsnvme-id in Bash so it is usable in early boot
- Add Dracut module to support block device naming in early boot

* Mon Jun 5 2023 Guillaume Delacour <delacoug@amazon.com> - 2.2.0-1
- Add `--quiet` option to `ec2-metadata --help` output
Expand Down
23 changes: 13 additions & 10 deletions doc/ebsnvme-id.8
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,35 @@
\" of this license, visit
\" http://creativecommons.org/licenses/by-sa/4.0/.
\" SPDX-License-Identifier: CC-BY-SA-4.0
.TH EBSNVME-ID 8 "May 4 2020"
.TH EBSNVME-ID 8 "Jan 19 2024"
.SH NAME
ebsnvme-id \- Reads and prints EBS information from NVMe devices
.SH SYNOPSIS
.B ebsnvme-id
.RI [ options ] " DEVICE"
.RI [ options ]
.br
.SH DESCRIPTION
.B ebsnvme-id
uses the NVME Management Interface to read various metadata about
NVME-attached EBS storage volumes. It can be used to retrive the EBS
uses the NVMe Management Interface to read various metadata about
NVMe-attached EBS storage volumes. It can be used to retrive the EBS
Volume ID or EC2 API device mapping value given the local block device
name.

.SH OPTIONS
.TP
.B \-v, \-\-volume
.B \-v <device>
ziggythehamster marked this conversation as resolved.
Show resolved Hide resolved
Return volume-id
.TP
.B \-b, \-\-block-dev
Return block device mapping
.B \-b <device>, \-u <device>
Return block device mapping (\-u is a deprecated alias)
.TP
.B \-u, \-\-udev
Output data in format suitable for udev rules
.B \-U <device>
Output data for the device as udev environment environment variables
suitable for use with
.B IMPORT{program}
in a udev rule
.TP
.B \-h, \-\-help
.B \-h
Show summary of options.
.SH SEE ALSO
.BR nvme (1),
Expand Down
7 changes: 7 additions & 0 deletions dracut/dracut.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the MIT License. See the LICENSE accompanying this file
# for the specific language governing permissions and limitations under
# the License.

add_dracutmodules+=" ec2-utils "
35 changes: 35 additions & 0 deletions dracut/module-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the MIT License. See the LICENSE accompanying this file
# for the specific language governing permissions and limitations under
# the License.

# called by dracut
check() {
# don't install this module unless the configuration explicitly requests it
return 255
}

# called by dracut
depends() {
echo bash udev-rules
return 0
}

# called by dracut
install() {
# Install udev rules
inst_rules \
51-ec2-hvm-devices.rules \
51-ec2-xen-vbd-devices.rules \
53-ec2-read-ahead-kb.rules \
70-ec2-nvme-devices.rules

# Install scripts
inst_multiple \
ebsnvme-id \
ec2nvme-nsid \
ec2udev-vbd
}
Loading