Files
my-rook-config/tests/scripts/create-bluestore-partitions.sh
T

124 lines
2.8 KiB
Bash
Raw Normal View History

2021-03-01 16:54:54 +01:00
#!/usr/bin/env bash
# Copyright 2021 The Rook Authors. All rights reserved.
#
# 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.
2020-10-27 14:25:08 +01:00
set -ex
#############
# VARIABLES #
#############
SIZE=2048M
#############
# FUNCTIONS #
#############
2021-03-01 16:54:54 +01:00
function usage {
echo "Use me like this to create bluestore partitions:"
echo "$0 --disk /dev/sda --bluestore-type block.db"
echo ""
echo "Use me like this to create multiple OSDs:"
echo "$0 --disk /dev/sda --osd-count 2"
echo ""
}
2020-10-27 14:25:08 +01:00
function wipe_disk {
2021-03-01 16:54:54 +01:00
sudo sgdisk --zap-all --clear --mbrtogpt -g -- "$DISK"
sudo dd if=/dev/zero of="$DISK" bs=1M count=10
sudo parted -s "$DISK" mklabel gpt
sudo partprobe "$DISK"
sudo udevadm settle
sudo parted "$DISK" -s print
2020-10-27 14:25:08 +01:00
}
function create_partition {
2021-03-01 16:54:54 +01:00
sudo sgdisk --new=0:0:+"$SIZE" --change-name=0:"$1" --mbrtogpt -- "$DISK"
2020-10-27 14:25:08 +01:00
}
function create_block_partition {
2021-03-01 16:54:54 +01:00
local osd_count=$1
if [ "$osd_count" -eq 1 ]; then
2020-10-27 14:25:08 +01:00
sudo sgdisk --largest-new=0 --change-name=0:'block' --mbrtogpt -- "$DISK"
2021-03-01 16:54:54 +01:00
elif [ "$osd_count" -gt 1 ]; then
SIZE=6144M
for osd in $(seq 1 "$osd_count"); do
echo "$osd"
create_partition osd-"$osd"
2021-10-11 16:47:49 +02:00
echo "SUBSYSTEM==\"block\", ATTR{size}==\"12582912\", ATTR{partition}==\"$osd\", ACTION==\"add\", RUN+=\"/bin/chown 167:167 ${DISK}${osd}\"" | sudo tee -a /etc/udev/rules.d/01-rook-"$osd".rules
2021-03-01 16:54:54 +01:00
done
fi
2020-10-27 14:25:08 +01:00
}
########
# MAIN #
########
2021-03-01 16:54:54 +01:00
if [ ! "$#" -ge 1 ]; then
exit 1
fi
while [ "$1" != "" ]; do
case $1 in
--disk)
shift
DISK="$1"
;;
--bluestore-type)
shift
BLUESTORE_TYPE="$1"
;;
--osd-count)
shift
OSD_COUNT="$1"
;;
-h | --help)
usage
exit
;;
*)
usage
exit 1
esac
shift
done
2020-10-27 14:25:08 +01:00
# First wipe the disk
wipe_disk
2021-03-01 16:54:54 +01:00
if [ -n "$BLUESTORE_TYPE" ]; then
case "$BLUESTORE_TYPE" in
block.db)
create_partition block.db
2020-10-27 14:25:08 +01:00
;;
2021-03-01 16:54:54 +01:00
block.wal)
create_partition block.db
create_partition block.wal
2020-10-27 14:25:08 +01:00
;;
2021-03-01 16:54:54 +01:00
*)
printf "invalid bluestore configuration %q" "$BLUESTORE_TYPE" >&2
exit 1
2020-10-27 14:25:08 +01:00
esac
2021-03-01 16:54:54 +01:00
fi
2020-10-27 14:25:08 +01:00
# Create final block partitions
2021-03-01 16:54:54 +01:00
create_block_partition "$OSD_COUNT"
2020-10-27 14:25:08 +01:00
# Inform the kernel of partition table changes
2020-11-18 12:14:58 +01:00
sudo partprobe "$DISK"
# Wait the udev event queue, and exits if all current events are handled.
sudo udevadm settle
2020-10-27 14:25:08 +01:00
# Print drives
sudo lsblk
2021-10-11 16:47:49 +02:00
sudo parted "$DISK" -s print