Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[copy_to_esp] Limit search to target disk only #110

Merged
merged 1 commit into from Jul 10, 2019

Conversation

tsirakisn
Copy link
Contributor

@tsirakisn tsirakisn commented Jul 2, 2019

@dpsmith tagging for visibility

OXT-1632

Signed-off-by: Nicholas Tsirakis tsirakisn@ainfosec.com

@eric-ch
Copy link
Contributor

eric-ch commented Jul 2, 2019

Build $6636

@@ -17,6 +17,9 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#

. ${DISK_CONF}
# ^^^ defines TARGET_DISK
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: please put your comments above the code you are explaining.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally I would...but there are a number of files in installer.git that have this same "^^^ defines" structure, so I went with that for consistency.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it is used in 17 places where as the more traditional style is used more often. With that said, regardless if I disagree with that format, you are correct there is precedent for its usage.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well it's used specifically where configuration files are sourced. I'm not sure where that originated but I'm not a fan of it either. Just going with what I see.

@@ -591,7 +594,7 @@ create_efi_boot_entries()

copy_to_esp()
{
local ESP=$(sfdisk -l -q | grep "EFI System" | awk '{ print $1 }')
local ESP=$(sfdisk -l -q "/dev/${TARGET_DISK}" | grep "EFI System" | awk '{ print $1 }')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is TARGET_DISK defined during an OTA/upgrade?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it's not, good point. Working on a fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

Copy link
Contributor

@jandryuk jandryuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating. I made some suggestions, but it's okay without them.

# TARGET_DISK not defined in upgrades; locate our
# installation disk manually.
if [ -z "${TARGET_DISK}" ]; then
local part="$(vgs xenclient --noheadings -o pv_name | sed 's/\s*//g' | sed 's|^/dev/||g')"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A since sed instance can run multiple commands like this: sed -e 's/\s*//g' -e 's|^/dev/||'

local TARGET_DISK="$(readlink /sys/class/block/$part | awk -F/ '{ print $(NF-1) }')"
fi

local ESP=$(sfdisk -l -q "/dev/${TARGET_DISK}" | grep "EFI System" | awk '{ print $1 }')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could elminate grep with sfdisk -l -q "/dev/${TARGET_DISK}" | awk '/EFI System/{ print $1 }'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to leave the grep call in there for the sole reason of the operation being much clearer to someone who doesn't fully know the awk language (like myself).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good.


# get disk from partition (e.g. sda2 --> sda). using
# readlink instead of simply stripping off trailing
# numbers to cover other disk formats (e.g. nvme)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment makes it sound like it's readlink resolving to the disk, but it's really the sysfs directory hierarchy. Maybe say "Use readlink to get the /sys/device entry and then use the parent directory as the disk name"

@crogers1
Copy link
Contributor

crogers1 commented Jul 3, 2019

Need this in stable-9 too, please submit a PR when the changes are approved for master.

@jean-edouard
Copy link
Member

@jean-edouard
Copy link
Member

Install failed with:
stages/Find-existing-install: .: line 20: can't open '/install/part2/data/disk.conf'

# work for other disk formats (e.g. nvme). this method
# will get the /sys/device entry and use the parent dir
# as the disk name.
local TARGET_DISK="$(readlink /sys/class/block/$part | awk -F/ '{ print $(NF-1) }')"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The installer already has helpers to handle this kind of things:

local devnode="$(vgs xenclient --noheadings -o pv_name)"
local disk=$(get_devnode_disk "${devnode}")
local part=$(get_devnode_part "${devnode}")

@tsirakisn
Copy link
Contributor Author

@jean-edouard ah I see what happened here...when I tested this I modified the installer while it was live, and I believe I waited until the installation was found before doing so. Let me do another round of testing on this.

OXT-1632

Signed-off-by: Nicholas Tsirakis <tsirakisn@ainfosec.com>
@tsirakisn
Copy link
Contributor Author

Ready for test again.

@eric-ch
Copy link
Contributor

eric-ch commented Jul 9, 2019

Build $6645

@jean-edouard
Copy link
Member

LGTM, merging soon.

@jean-edouard jean-edouard merged commit 38f5ee4 into OpenXT:master Jul 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants