Skip to content

Commit

Permalink
Merge branch 'basvandijk/guestos-mount-fs-with-CONFIG-label' into 'ma…
Browse files Browse the repository at this point in the history
…ster'

feat: ic-os/guestos: mount filesystem with the label CONFIG

The guestos used to only consider only removable devices
and devices with the serial "config" as devices
containing the `ic-bootstrap.tar` configuration.

This is insufficient in Utopia (i.e. cloud environments like AWS) where you
can't mark an EBS volume as removable and where you can't set the
serial of an EBS volume.

Instead we additionally consider devices which contain a filesystem
with the label "CONFIG" and make sure to set this label 
when we create the FAT filesystem. 

See merge request dfinity-lab/public/ic!16623
  • Loading branch information
basvandijk committed Dec 11, 2023
2 parents 753dca6 + 2350fdd commit b934613
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
16 changes: 9 additions & 7 deletions ic-os/boundary-guestos/rootfs/opt/ic/bin/bootstrap-ic-node.sh
Expand Up @@ -13,13 +13,15 @@

set -eo pipefail

# List all block devices marked as "removable".
function find_removable_devices() {
# List all block devices that could potentially contain the ic-bootstrap.tar configuration,
# i.e. "removable" devices or devices containing a filesystem with the label "CONFIG".
function find_config_devices() {
for DEV in $(ls -C /sys/class/block); do
echo "Consider device $DEV" >&2
if [ -e /sys/class/block/"${DEV}"/removable ]; then
local IS_REMOVABLE=$(cat /sys/class/block/"${DEV}"/removable)
if [ "${IS_REMOVABLE}" == 1 ]; then
local FS_LABEL=$(lsblk --fs --noheadings --output LABEL /dev/"${DEV}")
if [ "${IS_REMOVABLE}" == 1 ] || [ "${FS_LABEL}" == "CONFIG" ]; then
# If this is a partitioned device (and it usually is), then
# the first partition is of relevance.
# return first partition for use instead.
Expand Down Expand Up @@ -105,17 +107,17 @@ if [ -f /boot/config/CONFIGURED ]; then
fi

while [ ! -f /boot/config/CONFIGURED ]; do
echo "Locating removable device"
DEV="$(find_removable_devices)"
echo "Locating CONFIG device"
DEV="$(find_config_devices)"

# Check whether we were provided with a removable device -- on "real"
# Check whether we were provided with a CONFIG device -- on "real"
# VM deployments this will be the method used to inject bootstrap information
# into the system.
# But even if nothing can be mounted, just try and see if something usable
# is there already -- this might be useful when operating this thing as a
# docker container instead of full-blown VM.
if [ "${DEV}" != "" ]; then
echo "Found removable device at ${DEV}"
echo "Found CONFIG device at ${DEV}"
mount -t vfat -o ro "${DEV}" /mnt
fi

Expand Down
17 changes: 10 additions & 7 deletions ic-os/guestos/rootfs/opt/ic/bin/bootstrap-ic-node.sh
Expand Up @@ -62,8 +62,10 @@ function get_guestos_version() {
"gauge"
}

# List all block devices marked as "removable".
function find_removable_devices() {
# List all block devices that could potentially contain the ic-bootstrap.tar configuration,
# i.e. "removable" devices, devices with the serial "config"
# or devices containing a filesystem with the label "CONFIG".
function find_config_devices() {
for DEV in $(ls -C /sys/class/block); do
echo "Consider device $DEV" >&2
if [ -e /sys/class/block/"${DEV}"/removable ]; then
Expand All @@ -73,7 +75,8 @@ function find_removable_devices() {
# configuration device is identified by the serial "config".
local IS_REMOVABLE=$(cat /sys/class/block/"${DEV}"/removable)
local CONFIG_SERIAL=$(udevadm info --name=/dev/"${DEV}" | grep "ID_SCSI_SERIAL=config")
if [ "${IS_REMOVABLE}" == 1 ] || [ "${CONFIG_SERIAL}" != "" ]; then
local FS_LABEL=$(lsblk --fs --noheadings --output LABEL /dev/"${DEV}")
if [ "${IS_REMOVABLE}" == 1 ] || [ "${CONFIG_SERIAL}" != "" ] || [ "${FS_LABEL}" == "CONFIG" ]; then
# If this is a partitioned device (and it usually is), then
# the first partition is of relevance.
# return first partition for use instead.
Expand Down Expand Up @@ -160,17 +163,17 @@ if [ -f /boot/config/CONFIGURED ]; then
fi

while [ ! -f /boot/config/CONFIGURED ]; do
echo "Locating removable device"
DEV="$(find_removable_devices)"
echo "Locating CONFIG device"
DEV="$(find_config_devices)"

# Check whether we were provided with a removable device -- on "real"
# Check whether we were provided with a CONFIG device -- on "real"
# VM deployments this will be the method used to inject bootstrap information
# into the system.
# But even if nothing can be mounted, just try and see if something usable
# is there already -- this might be useful when operating this thing as a
# docker container instead of full-blown VM.
if [ "${DEV}" != "" ]; then
echo "Found removable device at ${DEV}"
echo "Found CONFIG device at ${DEV}"
mount -t vfat -o ro "${DEV}" /mnt
fi

Expand Down
14 changes: 9 additions & 5 deletions ic-os/scripts/build-bootstrap-config-image.sh
Expand Up @@ -304,11 +304,15 @@ function build_ic_bootstrap_diskimage() {
shift

local TMPDIR=$(mktemp -d)
build_ic_bootstrap_tar "${TMPDIR}/ic-bootstrap.tar" "$@"

truncate -s 10M "${OUT_FILE}"
mkfs.vfat "${OUT_FILE}"
mcopy -i "${OUT_FILE}" -o "${TMPDIR}/ic-bootstrap.tar" ::
local TAR="${TMPDIR}/ic-bootstrap.tar"
build_ic_bootstrap_tar "${TAR}" "$@"

size=$(du --bytes "${TAR}" | awk '{print $1}')
size=$((2 * size + 1048576))
echo "image size: $size"
truncate -s $size "${OUT_FILE}"
mkfs.vfat -n CONFIG "${OUT_FILE}"
mcopy -i "${OUT_FILE}" -o "${TAR}" ::

rm -rf "${TMPDIR}"
}
Expand Down

0 comments on commit b934613

Please sign in to comment.