sfdisk crash when pc-boot.img is too big

Bug #1666580 reported by Barry Warsaw
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Ubuntu Image
Fix Released
High
Barry Warsaw

Bug Description

In response to LP: #1666173 the real problem is caused when pc-boot.img is too big for the mbr.

Steps to reproduce (from repo or deb, adjust to not use /tmp for snaps):

$ mkdir /tmp/uiwork
$ ubuntu-image -w /tmp/uiwork -d -t load_gadget_yaml pc-amd64-model.assertion
$ truncate -s 512 /tmp/uiwork/unpack/gadget/pc-boot.img
$ ubuntu-image -w /tmp/uiwork -d -r
DEBUG:ubuntu-image:-> [ 3] populate_rootfs_contents
DEBUG:ubuntu-image:-> [ 4] calculate_rootfs_size
DEBUG:ubuntu-image:-> [ 5] pre_populate_bootfs_contents
DEBUG:ubuntu-image:-> [ 6] populate_bootfs_contents
DEBUG:ubuntu-image:-> [ 7] prepare_filesystems
DEBUG:ubuntu-image:-> [ 8] populate_filesystems
DEBUG:ubuntu-image:-> [ 9] make_disk
ERROR:ubuntu-image:COMMAND FAILED: ['sfdisk', '--part-type', '/tmp/uiwork/pc.img', '1', '21686148-6449-6e6f-744e-656564454649']
ERROR:ubuntu-image:
ERROR:ubuntu-image:sfdisk: /tmp/uiwork/pc.img: no partition table found

ERROR:ubuntu-image:uncaught exception in state machine step: [9] make_disk
Traceback (most recent call last):
  File "/home/barry/projects/ubuntu/allsnappy/ubuntu-image/ubuntu_image/state.py", line 73, in __next__
    step()
  File "/home/barry/projects/ubuntu/allsnappy/ubuntu-image/ubuntu_image/builder.py", line 508, in make_disk
    self._make_one_disk(image_path, name, volume)
  File "/home/barry/projects/ubuntu/allsnappy/ubuntu-image/ubuntu_image/builder.py", line 462, in _make_one_disk
    image.set_parition_type(part_id, part.type)
  File "/home/barry/projects/ubuntu/allsnappy/ubuntu-image/ubuntu_image/image.py", line 148, in set_parition_type
    str(partnum), str(typecode)])
  File "/home/barry/projects/ubuntu/allsnappy/ubuntu-image/ubuntu_image/helpers.py", line 98, in run
    proc.check_returncode()
  File "/usr/lib/python3.5/subprocess.py", line 349, in check_returncode
    self.stderr)
subprocess.CalledProcessError: Command '['sfdisk', '--part-type', '/tmp/uiwork/pc.img', '1', '21686148-6449-6e6f-744e-656564454649']' returned non-zero exit status 1
ERROR:ubuntu-image:Crash in state machine
Traceback (most recent call last):
  File "/home/barry/projects/ubuntu/allsnappy/ubuntu-image/ubuntu_image/__main__.py", line 204, in main
    list(state_machine)
  File "/home/barry/projects/ubuntu/allsnappy/ubuntu-image/ubuntu_image/state.py", line 73, in __next__
    step()
  File "/home/barry/projects/ubuntu/allsnappy/ubuntu-image/ubuntu_image/builder.py", line 508, in make_disk
    self._make_one_disk(image_path, name, volume)
  File "/home/barry/projects/ubuntu/allsnappy/ubuntu-image/ubuntu_image/builder.py", line 462, in _make_one_disk
    image.set_parition_type(part_id, part.type)
  File "/home/barry/projects/ubuntu/allsnappy/ubuntu-image/ubuntu_image/image.py", line 148, in set_parition_type
    str(partnum), str(typecode)])
  File "/home/barry/projects/ubuntu/allsnappy/ubuntu-image/ubuntu_image/helpers.py", line 98, in run
    proc.check_returncode()
  File "/usr/lib/python3.5/subprocess.py", line 349, in check_returncode
    self.stderr)
subprocess.CalledProcessError: Command '['sfdisk', '--part-type', '/tmp/uiwork/pc.img', '1', '21686148-6449-6e6f-744e-656564454649']' returned non-zero exit status 1

Note that pc-boot.img is properly 440 before the truncate call (that's why LP: #1666173 is invalid).

To investigate:

1) We did early on get this warning:

WARNING:ubuntu-image:Partition size/offset need to be a multiple of sector size (512). The size/offset will be rounded up to the nearest sector.

Is that warning about the size:440 of the mbr structure? That would be wrong. Since the other sizes/offsets (not offset-write) are in units of MiB, I'm not sure what else could be triggering that. The warning should include a message about which structure it's complaining about.

2) Why did we not get a warning that pc-boot.img is too big for the mbr?

3) Instead of blinding making the partition fit the image, we should probably stop with an error if the contents of the mbr is bigger than 440 bytes. Clearly that's a fatal error condition.

Barry Warsaw (barry)
Changed in ubuntu-image:
milestone: none → 1.0
assignee: nobody → Barry Warsaw (barry)
importance: Undecided → High
status: New → Confirmed
Revision history for this message
Barry Warsaw (barry) wrote :

So yes, the sector size/offset warning is issued for the mbr partition. That at least seems wrong since the mbr must be <= 446 bytes.

Revision history for this message
Barry Warsaw (barry) wrote :

volumes:
  pc:
    bootloader: grub
    structure:
      - name: mbr
        type: mbr
        size: 440
        content:
          - image: pc-boot.img
      - name: BIOS Boot
        type: DA,21686148-6449-6E6F-744E-656564454649
        size: 1M
        offset: 1M
        offset-write: mbr+92
        content:
          - image: pc-core.img
      - name: EFI System
        type: EF,C12A7328-F81F-11D2-BA4B-00A0C93EC93B
        filesystem: vfat
        filesystem-label: system-boot
        size: 50M
        content:
          - source: grubx64.efi
            target: EFI/boot/grubx64.efi
          - source: shim.efi.signed
            target: EFI/boot/bootx64.efi
          - source: grub.cfg
            target: EFI/ubuntu/grub.cfg

Barry Warsaw (barry)
Changed in ubuntu-image:
status: Confirmed → In Progress
Barry Warsaw (barry)
Changed in ubuntu-image:
status: In Progress → Fix Committed
Barry Warsaw (barry)
Changed in ubuntu-image:
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.