Curtin fails if a partition with bootable flag is present

Bug #1875903 reported by seahawk1986
34
This bug affects 6 people
Affects Status Importance Assigned to Milestone
curtin
Fix Released
High
Unassigned

Bug Description

I became aware of this problem by reading this forum post: https://www.vdr-portal.de/forum/index.php?thread/133200-yavdr-experimental-f%C3%BCr-ubuntu-20-04-yavdr-ansible-focal/&postID=1325428#post1325428 so I am not able to do an explicit debug run.

curtain parses the output of a subprocess call like "sfdisk --dump /dev/sdb", which can look like this:

label: dos
label-id: 0x0007ca9c
device: /dev/sdb
unit: sectors
/dev/sdb1 : start= 2048, size= 29294592, type=83, bootable
/dev/sdb2 : start= 29296640, size= 28682240, type=83
/dev/sdb3 : start= 57985022, size= 2872291330, type=5
/dev/sdb5 : start= 2927134720, size= 3141632, type=82
/dev/sdb6 : start= 57985024, size= 29294592, type=83
/dev/sdb7 : start= 87281664, size= 2839851008, type=83

The method _sfdisk_parse_lines(lines) (https://github.com/canonical/curtin/blob/master/curtin/block/__init__.py#L251 ff.) expects key-value pairs in the style key=value, which isn't the case for any partition flags.

As a side node: The output of sfdisk for gpt-formatted disks can contain partition names, so splitting the right hand side string of the colon by ',' (https://github.com/canonical/curtin/blob/master/curtin/block/__init__.py#L259 ff.) without proper parsing of quotes (e.g. using shlex.split() https://docs.python.org/3/library/shlex.html) could cause additional issues if the partition name contains one or more commata.

Related branches

Revision history for this message
seahawk1986 (seahawk1986-hotmail) wrote :
Revision history for this message
Ryan Harper (raharper) wrote :

Thanks for filing the bug and including the sfdisk table.

Changed in curtin:
importance: Undecided → High
status: New → Triaged
Revision history for this message
Paride Legovini (paride) wrote :

Hi Ryan,

sfdisk has a --json option that makes it output the partitions in json format. Do you think we could use it to make the parsing more solid?

Revision history for this message
seahawk1986 (seahawk1986-hotmail) wrote :

This seems to be a bug with the same cause: https://bugs.launchpad.net/ubuntu/+source/subiquity/+bug/1875560

Using json output sounds good, flags are represented as boolean values:
{
   "partitiontable": {
      "label":"dos",
      "id":"0x27690b00",
      "device":"/dev/sda",
      "unit":"sectors",
      "partitions": [
         {"node":"/dev/sda1", "start":2048, "size":116660224, "type":"83", "bootable":true},
         {"node":"/dev/sda2", "start":116664318, "size":8380418, "type":"5"},
         {"node":"/dev/sda5", "start":116664320, "size":8380416, "type":"82"}
      ]
   }
}

Revision history for this message
Paride Legovini (paride) wrote :

sfdisk in <= Trusty does not have --json, but the version in Xenial has it already.

Revision history for this message
Ryan Harper (raharper) wrote :

Yes; already implementing that.

Revision history for this message
Server Team CI bot (server-team-bot) wrote :

This bug is fixed with commit 8ab48f64 to curtin on branch master.
To view that commit see the following URL:
https://git.launchpad.net/curtin/commit/?id=8ab48f64

Changed in curtin:
status: Triaged → Fix Committed
Revision history for this message
Michael Wesley (electr0) wrote :

Has this bug been confirmed as fixed?

I'm still experiencing this error, even when using the new installer as prompted during the update.

https://bugs.launchpad.net/subiquity/+bug/1878890

Unless something else is going on in with my installation...?

Revision history for this message
Ryan Harper (raharper) wrote :

@electr0

This bug is fixed, your crash file, we can see sfdisk --json being used:

Verifying /dev/sda2 exists
 Running command ['sfdisk', '--json', '/dev/sda'] with allowed return codes [0] (capture=True)
 Verifying /dev/sda2 size, expecting 86564143104 bytes, found 86564143104 bytes
 Device /dev/sda2 ptable entry: {
  "node": "/dev/sda2",
  "size": 169070592,
  "start": 61442048,
  "type": "83"
 }
 Verifying /dev/sda2 partition flag, expecting linux, found None
 An error occured handling 'partition-sda2': RuntimeError - Verifying /dev/sda2 partition flag, expecting linux, found None

This path is a new, we'll fix this in https://bugs.launchpad.net/ubuntu/+source/curtin/+bug/1878890

Revision history for this message
Kai Harrekilde-Petersen (kaihp) wrote :

@raharper

I can confirm that this fixes the original problem I reported under https://bugs.launchpad.net/ubuntu/+source/subiquity/+bug/1875560

Unfortunately other bugs werre hiding behind this for me: curtin now barfs on /dev/sda2 (if it's Type=0x83) or on /dev/sda3 (if /dev/sda2 type=0x00). Seems like that curtin is very sensitive (too sensitive!)to how preexisting partition layouts look like.

I added the bugs to my subiquity bug report including logs.

Revision history for this message
Ryan Harper (raharper) wrote :

@Kai

Thanks for the confirmation and following up in the other bug reports. In my comment #9, I believe LP: #1878890 will resolve your current issue.

Revision history for this message
Kai Harrekilde-Petersen (kaihp) wrote :

@Ryan

Agreed, LP: #1878890 definititely smells like fish.

Revision history for this message
Ryan Harper (raharper) wrote : Fixed in curtin version 20.1.

This bug is believed to be fixed in curtin in version 20.1. If this is still a problem for you, please make a comment and set the state back to New

Thank you.

Changed in curtin:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.