Skip to content

Commit

Permalink
Add scripts to enable rpool disk expansion
Browse files Browse the repository at this point in the history
  • Loading branch information
Prakash Surya committed Aug 29, 2023
1 parent cea781e commit cd49c33
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 1 deletion.
5 changes: 4 additions & 1 deletion debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ DEPENDS += ansible, \
debootstrap, \
debsums, \
dmidecode, \
gdisk, \
init, \
iproute2, \
iputils-ping, \
jq, \
kbd, \
kmod, \
less, \
Expand All @@ -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.
Expand Down
54 changes: 54 additions & 0 deletions files/common/usr/bin/rpool-disk-attach
Original file line number Diff line number Diff line change
@@ -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"
36 changes: 36 additions & 0 deletions files/common/usr/bin/rpool-disk-detach
Original file line number Diff line number Diff line change
@@ -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"
34 changes: 34 additions & 0 deletions files/common/usr/bin/rpool-disk-format
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit cd49c33

Please sign in to comment.