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

Use PARTN or a fallback if not available #130

Open
lvps opened this issue Nov 14, 2024 · 2 comments
Open

Use PARTN or a fallback if not available #130

lvps opened this issue Nov 14, 2024 · 2 comments
Assignees
Labels
bug Something isn't working enhancement New feature or request server

Comments

@lvps
Copy link
Member

lvps commented Nov 14, 2024

Restore PARTN that was removed in 24f2e0b, then do one or more of the following when PARTN is not available:

  1. Use the last character (not recommended)
  2. Count how many elements with parttype != null are there and use that as the number
@lvps lvps added bug Something isn't working enhancement New feature or request server labels Nov 14, 2024
@parmigggiana
Copy link
Member

  1. Count how many elements with parttype != null are there and use that as the number

Could that be a problem with unallocated/borked partitions? Sometimes partition numbers can get skipped in /dev/xxx

@lvps
Copy link
Member Author

lvps commented Nov 14, 2024

Ideally we shouldn't have borked partitions on the golden image that has been just written (if there are any, we have much bigger problems). Unallocated shouldn't be a problem either, parttype is part of GPT or MBR table, it's not read from the filesystem or similar.

Here's a test with an unformatted partition:

dd if=/dev/zero of=test.img bs=4M count=1
cgdisk test.img  # Create a some GPT partitions with empty space and random types
sudo losetup -fP test.img
lsblk -J -o PATH,PARTN,PARTTYPE /dev/loop0
{
   "blockdevices": [
      {
         "path": "/dev/loop0",
         "partn": null,
         "parttype": null
      },{
         "path": "/dev/loop0p1",
         "partn": 1,
         "parttype": "0fc63daf-8483-4772-8e79-3d69d8477de4"
      },{
         "path": "/dev/loop0p2",
         "partn": 2,
         "parttype": "0fc63daf-8483-4772-8e79-3d69d8477de4"
      },{
         "path": "/dev/loop0p3",
         "partn": 3,
         "parttype": "0fc63daf-8483-4772-8e79-3d69d8477de4"
      },{
         "path": "/dev/loop0p4",
         "partn": 4,
         "parttype": "0657fd6d-a4ab-43c4-84e5-0933c84b4f4f"
      }
   ]
}

4 partitions with parttype != null, last partition is number 4

Let's try with MBR:

sudo losetup -d /dev/loop0
dd if=/dev/zero of=test.img bs=4M count=1
fdisk test.img  # Create some partitions
sudo losetup -fP test.img
lsblk -J -o PATH,PARTN,PARTTYPE /dev/loop0
{
   "blockdevices": [
      {
         "path": "/dev/loop0",
         "partn": null,
         "parttype": null
      },{
         "path": "/dev/loop0p1",
         "partn": 1,
         "parttype": "0x83"
      },{
         "path": "/dev/loop0p2",
         "partn": 2,
         "parttype": "0x6"
      },{
         "path": "/dev/loop0p3",
         "partn": 3,
         "parttype": "0x8e"
      }
   ]
}

3 partitions with parttype != null, last partition is number 3

There's nothing out of the ordinary in the output. I also tested MBR logical & extended partitions and that requires some special care when handling... but we don't use them, nobody uses them anymore, there's no point in supporting that.

So it should be safe to fall back to counting partitions. If you want to be super mega ultra hyper extra safe, you can add PTTYPE to the output and if it's "dos" (MBR) try to handle logical partitions, but it's not worth the effort.

@lvps lvps added this to the Short term things 2.0 milestone Nov 14, 2024
parmigggiana added a commit that referenced this issue Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request server
Projects
None yet
Development

No branches or pull requests

2 participants