-
Notifications
You must be signed in to change notification settings - Fork 20
Fix root UUID detection for device-mapper/LUKS systems #43
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,7 @@ | |
| terms. | ||
| """ | ||
|
|
||
| import os, logging, subprocess | ||
| import os, logging, subprocess, re | ||
|
|
||
| class NoBlockDevError(Exception): | ||
| pass | ||
|
|
@@ -104,12 +104,41 @@ def get_drive_dev(self, esp): | |
|
|
||
| def get_uuid(self, path): | ||
| self.log.debug('Looking for UUID for path %s' % path) | ||
|
|
||
| # 1. Try findmnt for UUID directly | ||
| try: | ||
| args = ['findmnt', '-n', '-o', 'UUID', '--mountpoint', path] | ||
| result = subprocess.run(args, stdout=subprocess.PIPE) | ||
| uuid = result.stdout.decode('ASCII') | ||
| uuid = uuid.strip() | ||
| return uuid | ||
| except OSError as e: | ||
| raise UUIDNotFoundError from e | ||
| uuid = result.stdout.decode('ASCII').strip() | ||
| if uuid: | ||
| return uuid | ||
| except OSError: | ||
| pass | ||
|
|
||
| # 2. Try findmnt SOURCE -> blkid | ||
| try: | ||
| args = ['findmnt', '-n', '-o', 'SOURCE', '--mountpoint', path] | ||
| result = subprocess.run(args, stdout=subprocess.PIPE) | ||
| src = result.stdout.decode('ASCII').strip() | ||
| if src: | ||
| args = ['blkid', '-s', 'UUID', '-o', 'value', src] | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On my machine, this command does not return anything regardless of what UUID I feed it. It just exits with status 2. |
||
| result = subprocess.run(args, stdout=subprocess.PIPE) | ||
| uuid = result.stdout.decode('ASCII').strip() | ||
| if uuid: | ||
| return uuid | ||
| except OSError: | ||
| pass | ||
|
|
||
| # 3. If path is root, try /proc/cmdline | ||
| if path == '/': | ||
| try: | ||
| with open("/proc/cmdline", "r") as f: | ||
| cmdline = f.read() | ||
| match = re.search(r"\broot=UUID=([0-9a-fA-F-]{36})\b", cmdline) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not a good method to determine the UUID required. If kernelstub is running on a live system, this method will always fail. |
||
| if match: | ||
| return match.group(1) | ||
| except Exception: | ||
| pass | ||
|
|
||
| raise UUIDNotFoundError('Could not determine UUID for %s' % path) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason this is being handled after the existing code? If we need to add the
-nflag, we should just add it instead of failing without it and falling back on nearly identical code.