Skip to content

Commit

Permalink
Provide options to create a RAID on ROOT disk
Browse files Browse the repository at this point in the history
  • Loading branch information
rsevilla87 committed Jun 26, 2019
1 parent 3f26c45 commit ba54aa1
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 16 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ standalone script or during bootup via a dracut module.
## Kernel command line options for coreos-installer running in the initramfs

* coreos.inst=yes - Instruct the installer to run
* coreos.inst.install_dev - The block device on the system to install to
* coreos.inst.install_dev - The block device on the system to install to. In case of
using an RAID device it should be a comma separated list of block devices names
* coreos.inst.image_url - The url of the coreos image to install to this device
* coreos.inst.ignition_url - The url of the coreos ignition config (optional, enter
coreos.inst.ignition_url=skip to not load an ignition config)
* coreos.inst.raid_dev - The RAID device name (optional)
* coreos.inst.raid_level - The RAID level (optional)

## Using the installer on FCOS or RHCOS

Expand Down
82 changes: 67 additions & 15 deletions coreos-installer
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,17 @@ write_networking_opts() {
echo "set ignition_network_kcmdline=\"$(cat /tmp/networking_opts)\"" >> /mnt/boot_partition/ignition.firstboot
}

############################################################
# Helper to enable autoassembly of special devices on cmdline
############################################################
write_cmdline_opts() {
log "Appending rd.auto=1 to Kernel cmdline"
mkdir -p /mnt/boot_partition
mount_boot_partition /mnt/boot_partition
trap 'umount /mnt/boot_partition; trap - RETURN' RETURN
sed -i '/linux16/s/$/ rd.auto=1/' /mnt/boot_partition/grub2/grub.cfg
}

############################################################
# START HERE
############################################################
Expand Down Expand Up @@ -431,8 +442,14 @@ get_img_url() {
# Validate that selected device exists
############################################################
check_selected_device() {
if [ ! -b $DEST_DEV ]
then
if [ -f /tmp/raid_dev ]; then
for dev in $RAID_DEV; do
if [ ! -b $dev ]; then
log "${dev} does not exist."
exit 1
fi
done
elif [ ! -b $DEST_DEV ]; then
log "${DEST_DEV} does not exist."
exit 1
fi
Expand Down Expand Up @@ -599,8 +616,13 @@ validate_image() {
#Wipe any remaining disk labels
#########################################################
wipe_target_disk_labels() {
log "Wiping ${DEST_DEV}"
wipefs --all --force "${DEST_DEV}"
if [ -f /tmp/raid_dev ]; then
log "Wiping ${RAID_DEV}"
wipefs --all --force ${RAID_DEV}
else
log "Wiping ${DEST_DEV}"
wipefs --all --force "${DEST_DEV}"
fi
}

log() {
Expand All @@ -612,9 +634,13 @@ log() {
#And Write the image to disk
#########################################################
write_image_to_disk() {
log "Writing disk image"

set -o pipefail
if [ -f /tmp/raid_dev ]; then
log "Creating array device ${DEST_DEV}"
mdadm --create ${DEST_DEV} --level=$(cat /tmp/raid_level) --raid-devices=2 ${RAID_DEV} --metadata=1.0 --run
fi
log "Writing disk image"
zcat /mnt/dl/imagefile.gz |\
dd bs=1M iflag=fullblock oflag=direct conv=sparse of="${DEST_DEV}" status=none
RETCODE=$?
Expand All @@ -636,24 +662,32 @@ write_image_to_disk() {
parse_args() {
USAGE="Usage: $0 [options]
Options:
-d DEVICE Install to the given device, alternatively specify
coreos.inst.install_dev on the kcmdline.
-i IGNITION The URL (or path) to the given Ignition config,
alternatively specify coreos.inst.ignition_url on the
kcmdline.
-b BASEURL The URL to the image, alternatively specify
coreos.inst.image_url on the kcmdline.
-h This.
-d DEVICE Install to the given device(s), alternatively specify
coreos.inst.install_dev on the kcmdline.
Multiple devices separated by commas may be specified
in order to create a RAID device
-r RAID_DEV RAID device name, alternatively specify coreos.inst.raid_dev
on the kcmdline
-l RAID_LEVEL RAID level, alternatively specify coreos.inst.raid_level
on the kcmdline
-i IGNITION The URL (or path) to the given Ignition config,
alternatively specify coreos.inst.ignition_url on the
kcmdline.
-b BASEURL The URL to the image, alternatively specify
coreos.inst.image_url on the kcmdline.
-h This.
This tool installs CoreOS style disk images on a block device.
"

while getopts "d:i:b:h" OPTION
while getopts "d:i:b:r:l:h" OPTION
do
case $OPTION in
d) DEVICE="$OPTARG" ;;
i) IGNITION="$OPTARG" ;;
b) BASE_URL="${OPTARG%/}" ;;
r) RAID_DEV="${OPTARG%/}" ;;
l) RAID_LEVEL="${OPTARG%/}" ;;
h) echo "$USAGE"; exit;;
*) exit 1;;
esac
Expand All @@ -673,6 +707,14 @@ This tool installs CoreOS style disk images on a block device.
then
echo "${BASE_URL}" > /tmp/image_url
fi
if [[ ! -z "${RAID_DEV}" ]]
then
echo "${RAID_DEV}" > /tmp/raid_dev
fi
if [[ ! -z "${RAID_LEVEL}" ]]
then
echo "${RAID_LEVEL}" > /tmp/raid_level
fi
}

# Main function for running the installer
Expand All @@ -687,7 +729,12 @@ main() {

# set a global environment variable that can be used
# by a few of the functions below.
DEST_DEV=$(cat /tmp/selected_dev)
if [ -f /tmp/raid_dev ]; then
RAID_DEV=$(cat /tmp/selected_dev | sed 's/,/\n/' | sed 's/^/\/dev\//' | tr '\n' ' ')
DEST_DEV=$(cat /tmp/raid_dev)
else
DEST_DEV=$(cat /tmp/selected_dev)
fi
DEST_DEV=/dev/$DEST_DEV

#import_gpg_key
Expand All @@ -707,6 +754,11 @@ main() {
# If one was provided, install the ignition config
write_ignition_file

# If RAID creation is required
if [ -f /tmp/raid_dev ]; then
write_cmdline_opts
fi

# If networking options were present, persist to firstboot initramfs
write_networking_opts

Expand Down
13 changes: 13 additions & 0 deletions dracut/30coreos-installer/parse-coreos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ then
echo $IGNITION_URL >> /tmp/ignition_url
fi

local RAID_DEV=$(getarg coreos.inst.raid_dev=)
if [ ! -z "$RAID_DEV" ]
then
echo "preset RAID device to $RAID_DEV" >> /tmp/debug
echo $RAID_DEV >> /tmp/raid_dev
fi

local RAID_LEVEL=$(getarg coreos.inst.raid_level=)
if [ ! -z "$RAID_LEVEL" ]
then
echo "preset RAID level to ${RAID_LEVEL}" >> /tmp/debug
echo $RAID_LEVEL >> /tmp/raid_level
fi

# Kernel networking args
# Currently only persisting `ipv6.disable`, but additional options may be added
Expand Down

0 comments on commit ba54aa1

Please sign in to comment.