Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Handle root on LVM partitioning
Signed-off-by: Philippe Vanhaesendonck <philippe.vanhaesendonck@oracle.com>
  • Loading branch information
AmedeeBulle committed Mar 11, 2020
commit c07776475f20bb3d1ef60c40668f1817bd81faf6
42 changes: 39 additions & 3 deletions oracle-linux-image-tools/bin/mnt-img.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Mount VM images
#
# Copyright (c) 1982-2019 Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 1982-2020 Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at
# https://oss.oracle.com/licenses/upl.
#
Expand Down Expand Up @@ -181,6 +181,10 @@ fi
# lock
echo "MOUNTED IMAGE:$IMAGE_FILE $LPDEVICE" > $WORK_HOME/"$ID"

# Get host volume groups
host_vgs=$(vgs --noheadings -o vg_name)
guest_vg=0

# map device
if ! kpartx -a "$LPDEVICE" &>/dev/null; then
losetup -d "$LPDEVICE"
Expand All @@ -190,18 +194,50 @@ fi
mapped_devices=$(kpartx -l "$LPDEVICE" | grep "$LPDEVICE" | awk '{print $1}')
ct=1
for d in $mapped_devices; do
mkdir -p "$MOUNT_POINT"/$ct
file -sL /dev/mapper/"$d"
# mount ext3, ext4, btrfs, xfs partitions
if file -sL /dev/mapper/"$d" | egrep -q -i "ext3|ext4|btrfs|xfs"; then
mkdir -p "$MOUNT_POINT"/$ct
mount /dev/mapper/"$d" "$MOUNT_POINT"/$ct
echo "MOUNTED DIR:/dev/mapper/$d $MOUNT_POINT/$ct" |tee -a $WORK_HOME/"$ID"
ct=$((ct+1))
elif file -sL /dev/mapper/"$d" | egrep -q -i "lvm2"; then
echo "LVM detected"
guest_vg=1
pvscan --cache /dev/mapper/"$d"
else
echo "/dev/mapper/$d not mounted - Unknown filesystem."
fi

done

if [[ ${guest_vg} == 1 ]]; then
# Image has LVM
# This only works for simple setups (where the whole VG is on the device)
# Scan for Volume Groups
all_vgs=$(vgscan | grep "Found volume group" | sed -e 's/^[^"]*"\([^"]*\)".*$/\1/')
for vg in ${all_vgs}; do
# Only consider new VGs
if ! grep -w -q "${vg}" <<<${host_vgs}; then
# Ensure the VG is active and register it
vgchange -ay "${vg}"
echo "LVM GROUP:${vg}" | tee -a "${WORK_HOME}/${ID}"
lvscan >/dev/null
# Search for filesystems in the VG
for fs in "/dev/${vg}"/*; do
file -sL "${fs}"
if file -sL "${fs}" | egrep -q -i "ext3|ext4|btrfs|xfs"; then
mkdir -p "${MOUNT_POINT}/${ct}"
mount "${fs}" "${MOUNT_POINT}/${ct}"
echo "MOUNTED DIR:${fs} ${MOUNT_POINT}/${ct}" | tee -a "${WORK_HOME}/${ID}"
ct=$((ct+1))
else
echo "${fs} not mounted - Unknown filesystem."
fi
done
fi
done
fi

;;

############################################################################
Expand Down
12 changes: 10 additions & 2 deletions oracle-linux-image-tools/distr/ol7-slim/image-scripts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# image scripts for OL7
#
# Copyright (c) 1982-2019 Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 1982-2020 Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at
# https://oss.oracle.com/licenses/upl.
#
Expand All @@ -23,7 +23,7 @@
# None
#######################################
distr::validate() {
[[ "${ROOT_FS,,}" =~ ^(xfs)|(btrfs)$ ]] || error "ROOT_FS must be xfs or btrfs"
[[ "${ROOT_FS,,}" =~ ^(xfs)|(btrfs)|(lvm)$ ]] || error "ROOT_FS must be xfs, btrfs or lvm"
readonly ROOT_FS
}

Expand All @@ -42,11 +42,19 @@ distr::kickstart() {
part btrfs.01 --fstype="btrfs" --ondisk=sda --size=4096 --grow\n\
btrfs none --label=btr_pool --data=single btrfs.01\n\
btrfs / --subvol --name=root btr_pool\
"
local lvm="\
part pv.01 --ondisk=sda --size=4096 --grow\n\
volgroup vg_main pv.01\n\
logvol swap --fstype="swap" --vgname=vg_main --size=4096 --name=lv_swap\n\
logvol / --fstype="xfs" --vgname=vg_main --size=4096 --name=lv_root --grow\
"

# Kickstart file is populated for xfs
if [[ "${ROOT_FS,,}" = "btrfs" ]]; then
sed -i -e 's!^part / .*$!'"${btrfs}"'!' "${WORKSPACE}/${KS_FILE}"
elif [[ "${ROOT_FS,,}" = "lvm" ]]; then
sed -i -e '/^part swap/d' -e 's!^part / .*$!'"${lvm}"'!' "${WORKSPACE}/${KS_FILE}"
fi

# Pass kernel selection
Expand Down