From cd49c3307ea88a32d80cad9a416d90481380998a Mon Sep 17 00:00:00 2001 From: Prakash Surya Date: Tue, 29 Aug 2023 10:23:39 -0700 Subject: [PATCH] Add scripts to enable rpool disk expansion PR URL: https://www.github.com/delphix/delphix-platform/pull/463 --- debian/rules | 5 ++- files/common/usr/bin/rpool-disk-attach | 54 ++++++++++++++++++++++++++ files/common/usr/bin/rpool-disk-detach | 36 +++++++++++++++++ files/common/usr/bin/rpool-disk-format | 34 ++++++++++++++++ 4 files changed, 128 insertions(+), 1 deletion(-) create mode 100755 files/common/usr/bin/rpool-disk-attach create mode 100755 files/common/usr/bin/rpool-disk-detach create mode 100755 files/common/usr/bin/rpool-disk-format diff --git a/debian/rules b/debian/rules index 9f352c7a..4b86ce5c 100755 --- a/debian/rules +++ b/debian/rules @@ -59,9 +59,11 @@ DEPENDS += ansible, \ debootstrap, \ debsums, \ dmidecode, \ + gdisk, \ init, \ iproute2, \ iputils-ping, \ + jq, \ kbd, \ kmod, \ less, \ @@ -85,7 +87,8 @@ DEPENDS += ansible, \ sudo, \ systemd-container, \ tzdata, \ - udev, + udev, \ + util-linux, # # The CRA PAM module provides an authentication method for the delphix user. diff --git a/files/common/usr/bin/rpool-disk-attach b/files/common/usr/bin/rpool-disk-attach new file mode 100755 index 00000000..bf21b6d8 --- /dev/null +++ b/files/common/usr/bin/rpool-disk-attach @@ -0,0 +1,54 @@ +#!/bin/bash -e +# +# Copyright 2023 Delphix +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License 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. +# + +function die() { + echo "$(basename "$0"): $*" >&2 + exit 1 +} + +function cleanup() { + # shellcheck disable=SC2317 + ([[ -z "$GRUB_DIR" ]] || [[ ! -d "$GRUB_DIR" ]]) && return + + umount "$GRUB_DIR" + rm -rf "$GRUB_DIR" +} + +function get_partition_path() { + lsblk -p "$1" --json | jq -Mr '.[][]["children"][0]["name"]' +} + +[[ $# -gt 2 ]] && usage "too many arguments specified" +[[ $# -eq 1 ]] && usage "too few arguments specified" + +[[ "$EUID" -ne 0 ]] && die "must be run as root" + +trap cleanup EXIT + +OLD_DISK_PATH="$(readlink -f "$1")" +NEW_DISK_PATH="$(readlink -f "$2")" + +OLD_DISK_PART="$(get_partition_path "$OLD_DISK_PATH")" +NEW_DISK_PART="$(get_partition_path "$NEW_DISK_PATH")" + +GRUB_DIR=$(mktemp -d -p /tmp -t unpack.XXXXXXX) + +set -o xtrace +zpool attach rpool "$OLD_DISK_PART" "$NEW_DISK_PART" +mount -t zfs "rpool/grub" "$GRUB_DIR" +grub-install --root-directory="$GRUB_DIR" "$NEW_DISK_PATH" +grub-mkconfig -o "/mnt/boot/grub/grub.cfg" diff --git a/files/common/usr/bin/rpool-disk-detach b/files/common/usr/bin/rpool-disk-detach new file mode 100755 index 00000000..aee996ea --- /dev/null +++ b/files/common/usr/bin/rpool-disk-detach @@ -0,0 +1,36 @@ +#!/bin/bash -e +# +# Copyright 2023 Delphix +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License 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. +# + +function die() { + echo "$(basename "$0"): $*" >&2 + exit 1 +} + +function get_partition_path() { + lsblk -p "$1" --json | jq -Mr '.[][]["children"][0]["name"]' +} + +[[ $# -gt 1 ]] && usage "too many arguments specified" +[[ $# -eq 0 ]] && usage "too few arguments specified" + +[[ "$EUID" -ne 0 ]] && die "must be run as root" + +DISK_PATH="$(readlink -f "$1")" +DISK_PART="$(get_partition_path "$DISK_PATH")" + +set -o xtrace +zpool attach rpool "$DISK_PART" diff --git a/files/common/usr/bin/rpool-disk-format b/files/common/usr/bin/rpool-disk-format new file mode 100755 index 00000000..54d2685d --- /dev/null +++ b/files/common/usr/bin/rpool-disk-format @@ -0,0 +1,34 @@ +#!/bin/bash -e +# +# Copyright 2023 Delphix +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License 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. +# + +function die() { + echo "$(basename "$0"): $*" >&2 + exit 1 +} + +[[ $# -gt 1 ]] && usage "too many arguments specified" +[[ $# -eq 0 ]] && usage "too few arguments specified" + +[[ "$EUID" -ne 0 ]] && die "must be run as root" + +DISK_PATH="$(readlink -f "$1")" + +set -o xtrace +sgdisk --zap-all "$DISK_PATH" +sgdisk "$DISK_PATH" --set-alignment=1 --new=2:1m:+1m --typecode=2:EF02 +sgdisk "$DISK_PATH" --new=1:: --typecode=1:8300 +sgdisk "$DISK_PATH" --print