Skip to content

Commit

Permalink
build: Add support for XFS DATA Partition
Browse files Browse the repository at this point in the history
Add the ability to specify XFS for a variant's DATA partition. The
variants now allow xfs-data-partition to be set to enable this feature.
If not specified, the DATA partition defaults to ext4.

Signed-off-by: Matthew Yeazel <yeazelm@amazon.com>
  • Loading branch information
yeazelm committed Jul 11, 2023
1 parent e5813f1 commit 43f52f2
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 5 deletions.
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ ARG REPO
ARG GRUB_SET_PRIVATE_VAR
ARG SYSTEMD_NETWORKD
ARG UNIFIED_CGROUP_HIERARCHY
ARG XFS_DATA_PARTITION
ENV SYSTEMD_NETWORKD=${SYSTEMD_NETWORKD}
ENV VARIANT=${VARIANT}
WORKDIR /home/builder
Expand Down Expand Up @@ -102,6 +103,7 @@ RUN rpmdev-setuptree \
&& echo -e -n "${GRUB_SET_PRIVATE_VAR:+%bcond_without grub_set_private_var\n}" >> .bconds \
&& echo -e -n "${SYSTEMD_NETWORKD:+%bcond_without systemd_networkd\n}" >> .bconds \
&& echo -e -n "${UNIFIED_CGROUP_HIERARCHY:+%bcond_without unified_cgroup_hierarchy\n}" >> .bconds \
&& echo -e -n "${XFS_DATA_PARTITION:+%bcond_without xfs_data_partition\n}" >> .bconds \
&& cat .bconds ${PACKAGE}.spec >> rpmbuild/SPECS/${PACKAGE}.spec \
&& find . -maxdepth 1 -not -path '*/\.*' -type f -exec mv {} rpmbuild/SOURCES/ \; \
&& echo ${NOCACHE}
Expand Down Expand Up @@ -197,6 +199,7 @@ ARG OS_IMAGE_PUBLISH_SIZE_GIB
ARG DATA_IMAGE_PUBLISH_SIZE_GIB
ARG KERNEL_PARAMETERS
ARG GRUB_SET_PRIVATE_VAR
ARG XFS_DATA_PARTITION
ENV VARIANT=${VARIANT} VERSION_ID=${VERSION_ID} BUILD_ID=${BUILD_ID} \
PRETTY_NAME=${PRETTY_NAME} IMAGE_NAME=${IMAGE_NAME} \
KERNEL_PARAMETERS=${KERNEL_PARAMETERS}
Expand All @@ -214,6 +217,7 @@ RUN --mount=target=/host \
--data-image-publish-size-gib="${DATA_IMAGE_PUBLISH_SIZE_GIB}" \
--partition-plan="${PARTITION_PLAN}" \
--ovf-template="/host/variants/${VARIANT}/template.ovf" \
${XFS_DATA_PARTITION:+--xfs-data-partition=yes} \
${GRUB_SET_PRIVATE_VAR:+--with-grub-set-private-var=yes} \
&& echo ${NOCACHE}

Expand Down
1 change: 1 addition & 0 deletions packages/release/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ selinux-policy = { path = "../selinux-policy" }
systemd = { path = "../systemd" }
util-linux = { path = "../util-linux" }
wicked = { path = "../wicked" }
xfsprogs = { path = "../xfsprogs" }
3 changes: 2 additions & 1 deletion packages/release/local.mount
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ After=prepare-local-fs.service
Requires=prepare-local-fs.service

[Mount]
EnvironmentFile=/usr/share/bottlerocket/image-features.env
What=/dev/disk/by-partlabel/BOTTLEROCKET-DATA
Where=/local
Type=ext4
Type=${DATA_PARTITION_FILESYSTEM}
# "noexec" omitted to allow containers and migrations to run
Options=defaults,nosuid,nodev,noatime,private

Expand Down
3 changes: 2 additions & 1 deletion packages/release/prepare-local-fs.service
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ RefuseManualStop=true
[Service]
Type=oneshot

EnvironmentFile=/usr/share/bottlerocket/image-features.env
# Create the filesystem on the partition, if it doesn't exist.
ExecStart=/usr/lib/systemd/systemd-makefs ext4 /dev/disk/by-partlabel/BOTTLEROCKET-DATA
ExecStart=/usr/lib/systemd/systemd-makefs ${DATA_PARTITION_FILESYSTEM} /dev/disk/by-partlabel/BOTTLEROCKET-DATA

# Stop and mask the repart-data-* oneshots in case they're waiting on non-existent data partitions.
# 'BOTTLEROCKET-DATA' already exists so we can move on.
Expand Down
2 changes: 1 addition & 1 deletion packages/xfsprogs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ util-linux = { path = "../util-linux" }

# RPM Requires
[dependencies]
# none - will likely change
# none
10 changes: 10 additions & 0 deletions tools/buildsys/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@ line arguments set in the boot configuration.
[package.metadata.build-variant.image-features]
unified-cgroup-hierarchy = true
```
`xfs-data-partition` changes the filesystem for the data partition from ext4 to xfs. The
default will remain ext4 and xfs is opt-in.
```ignore
[package.metadata.build-variant.image-features]
xfs-data-partition = true
*/

mod error;
Expand Down Expand Up @@ -505,6 +512,7 @@ pub enum ImageFeature {
GrubSetPrivateVar,
SystemdNetworkd,
UnifiedCgroupHierarchy,
XfsDataPartition,
}

impl TryFrom<String> for ImageFeature {
Expand All @@ -514,6 +522,7 @@ impl TryFrom<String> for ImageFeature {
"grub-set-private-var" => Ok(ImageFeature::GrubSetPrivateVar),
"systemd-networkd" => Ok(ImageFeature::SystemdNetworkd),
"unified-cgroup-hierarchy" => Ok(ImageFeature::UnifiedCgroupHierarchy),
"xfs-data-partition" => Ok(ImageFeature::XfsDataPartition),
_ => error::ParseImageFeatureSnafu { what: s }.fail()?,
}
}
Expand All @@ -525,6 +534,7 @@ impl fmt::Display for ImageFeature {
ImageFeature::GrubSetPrivateVar => write!(f, "GRUB_SET_PRIVATE_VAR"),
ImageFeature::SystemdNetworkd => write!(f, "SYSTEMD_NETWORKD"),
ImageFeature::UnifiedCgroupHierarchy => write!(f, "UNIFIED_CGROUP_HIERARCHY"),
ImageFeature::XfsDataPartition => write!(f, "XFS_DATA_PARTITION"),
}
}
}
Expand Down
33 changes: 31 additions & 2 deletions tools/rpm2img
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ BUILDER_ARCH="$(uname -m)"
OVF_TEMPLATE=""

GRUB_SET_PRIVATE_VAR="no"
XFS_DATA_PARTITION="no"

for opt in "$@"; do
optarg="$(expr "${opt}" : '[^=]*=\(.*\)')"
Expand All @@ -27,6 +28,7 @@ for opt in "$@"; do
--partition-plan=*) PARTITION_PLAN="${optarg}" ;;
--ovf-template=*) OVF_TEMPLATE="${optarg}" ;;
--with-grub-set-private-var=*) GRUB_SET_PRIVATE_VAR="${optarg}" ;;
--xfs-data-partition=*) XFS_DATA_PARTITION="${optarg}" ;;
esac
done

Expand Down Expand Up @@ -277,6 +279,13 @@ SUPPORT_URL="https://github.com/bottlerocket-os/bottlerocket/discussions"
BUG_REPORT_URL="https://github.com/bottlerocket-os/bottlerocket/issues"
EOF

# Set the BOTTLEROCKET-DATA Filesystem for creating/mounting
if [ "${XFS_DATA_PARTITION}" == "yes" ] ; then
printf "%s\n" "DATA_PARTITION_FILESYSTEM=xfs" >> "${ROOT_MOUNT}/${SYS_ROOT}/usr/share/bottlerocket/image-features.env"
else
printf "%s\n" "DATA_PARTITION_FILESYSTEM=ext4" >> "${ROOT_MOUNT}/${SYS_ROOT}/usr/share/bottlerocket/image-features.env"
fi

# BOTTLEROCKET-ROOT-A
mkdir -p "${ROOT_MOUNT}/lost+found"
ROOT_LABELS=$(setfiles -n -d -F -m -r "${ROOT_MOUNT}" \
Expand Down Expand Up @@ -408,8 +417,28 @@ mkfs_data() {
target="${1:?}"
size="${2:?}"
offset="${3:?}"
mkfs.ext4 -m 0 -d "${DATA_MOUNT}" "${BOTTLEROCKET_DATA}" "${size}"
echo "${UNLABELED}" | debugfs -w -f - "${BOTTLEROCKET_DATA}"
# Create an XFS filesystem if requested
if [ "${XFS_DATA_PARTITION}" == "yes" ] ; then
echo "writing XFS filesystem for DATA"
# Create a file to write the filesystem to first
dd if=/dev/zero of="${BOTTLEROCKET_DATA}" bs=1M count=${size%?}
# block size of 4096, directory block size of 16384
# enable inotbtcount, bigtime, and reflink
# use an internal log with starting size of 64m
# use the minimal 2 Allocation groups, this still overprovisions when expanded
# set strip units of 512k and sectsize to make EBS volumes align
mkfs.xfs \
-b size=4096 -n size=16384 \
-m inobtcount=1,bigtime=1,reflink=1 \
-l internal,size=64m \
-d agcount=2,su=512k,sw=1,sectsize=4096 \
-f "${BOTTLEROCKET_DATA}"
else
# default to ext4
echo "writing ext4 filesystem for DATA"
mkfs.ext4 -m 0 -d "${DATA_MOUNT}" "${BOTTLEROCKET_DATA}" "${size}"
echo "${UNLABELED}" | debugfs -w -f - "${BOTTLEROCKET_DATA}"
fi
dd if="${BOTTLEROCKET_DATA}" of="${target}" conv=notrunc bs=1M seek="${offset}"
}

Expand Down
1 change: 1 addition & 0 deletions variants/aws-dev/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ exclude = ["README.md"]
[package.metadata.build-variant.image-features]
grub-set-private-var = true
unified-cgroup-hierarchy = true
xfs-data-partition = true

[package.metadata.build-variant]
kernel-parameters = [
Expand Down
1 change: 1 addition & 0 deletions variants/metal-dev/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ partition-plan = "unified"
[package.metadata.build-variant.image-features]
grub-set-private-var = true
unified-cgroup-hierarchy = true
xfs-data-partition = true

[package.metadata.build-variant]
image-format = "raw"
Expand Down
1 change: 1 addition & 0 deletions variants/vmware-dev/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ partition-plan = "unified"
[package.metadata.build-variant.image-features]
grub-set-private-var = true
unified-cgroup-hierarchy = true
xfs-data-partition = true

[package.metadata.build-variant]
image-format = "vmdk"
Expand Down

0 comments on commit 43f52f2

Please sign in to comment.