-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add scripts to enable rpool disk expansion
- Loading branch information
Prakash Surya
committed
Aug 29, 2023
1 parent
cea781e
commit cd49c33
Showing
4 changed files
with
128 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |