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

install: Fail early if image sector size doesn't match destination #167

Merged
merged 4 commits into from
Feb 25, 2020
Merged

install: Fail early if image sector size doesn't match destination #167

merged 4 commits into from
Feb 25, 2020

Conversation

bgilbert
Copy link
Contributor

Otherwise we'd copy the whole image, then complain that we couldn't find any partitions. Detect the image sector size by checking both possible offsets for a GPT, detect the destination sector size by ioctl, and fail if they don't match.

If we don't detect any GPT, continue without error. In the future, detection could be expanded to cover additional partition table types.

In addition, if no partitions are detected after writing the image, complain about it rather than saying couldn't find boot device for /dev/sda. That should make it easier to track down non-sector-size issues with similar symptoms.

Closes #161.

@bgilbert
Copy link
Contributor Author

Updated.

@lucab
Copy link
Contributor

lucab commented Feb 25, 2020

CI is red due to a clippy warning. Other than that, PR looks fine and good to go.

@bgilbert
Copy link
Contributor Author

Updated for 📎.

Copy link
Contributor

@lucab lucab left a comment

Choose a reason for hiding this comment

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

LGTM

src/blockdev.rs Outdated
.iter()
.filter(|d| d.label.as_ref().unwrap_or(&"".to_string()) == "boot")
.collect::<Vec<&BlkDev>>();
if boot_partitions.is_empty() {
Copy link
Member

Choose a reason for hiding this comment

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

Minor: since what we really care about here is getting the boot device, would make sense to compress as e.g.:

let dev = match boot_partitions.len() {
  0 => bail!(...),
  1 => boot_partitions[0],
  _ => bail!(...),
};

src/blockdev.rs Outdated
source: BufReader<R>,
}

impl<R: Read> DiskSectorSizeReader<R> {
Copy link
Member

Choose a reason for hiding this comment

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

We're already reading and keeping the first 1M of the source image, right? Couldn't we just check that buffer? Doing it in a wrapping reader is fine, though it seems like unnecessary cognitive load/architecturing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call. That's much, much better.

We were complaining:

   Error: couldn't find boot device for /dev/sda

but the problem isn't really the boot device, it's that the partition
table isn't being read by the kernel.
Otherwise we'd copy the whole image, then complain that we couldn't
find any partitions.  Detect the image sector size by checking both
possible offsets for a GPT, detect the destination sector size by ioctl,
and fail if they don't match.

If we don't detect any GPT, continue without error.  In the future,
detection could be expanded to cover additional partition table types.
Test fixtures are 10 MB disk images containing a single empty partition.
@bgilbert
Copy link
Contributor Author

Updated.

// Were we asked to check sector size?
if let Some(expected) = expected_sector_size {
// Can we derive one from source data?
if let Some(actual) = detect_formatted_sector_size(&first_mb) {
Copy link
Member

Choose a reason for hiding this comment

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

If we're asked to expect a sector size, shouldn't we fail if we can't query the sector size from the image?

Copy link
Contributor Author

@bgilbert bgilbert Feb 25, 2020

Choose a reason for hiding this comment

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

It's a best-effort check to improve UX. We don't currently detect sector size on non-EFI CPU architectures.

Copy link
Member

@jlebon jlebon left a comment

Choose a reason for hiding this comment

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

LGTM!

@bgilbert
Copy link
Contributor Author

Thanks all!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider checking that disk sector size matches image
3 participants