question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug sfdisk parcer

See original GitHub issue

HI! I tried the parser on two operating systems : Debian 10 and CentOS 8.

If I specify sfdisk -l /dev/sda1 | jc --sfdisk , the output is : [{“disk”:“/dev/sda1”,“cylinders”:1,“units”:“sectors of 1 * 512 = 512 bytes”}]

But, if I want to get information on the entire sdc drive, I get a parser error :

 sfdisk -l /dev/sda | jc --sfdisk -dd :

Traceback (most recent call last):
  File "/usr/local/bin/jc", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.8/site-packages/jc/cli.py", line 618, in main
    result = parser.parse(data, raw=raw, quiet=quiet)
  File "/usr/local/lib/python3.8/site-packages/jc/parsers/sfdisk.py", line 296, in parse
    item['heads'] = line.split()[4]
IndexError: list index out of range

.... sfdisk.py in parse(data='Disk /dev/sda: 32 GiB, 34359738368 bytes, 671088...     2099200 67108863 65009664  31G 8e Linux LVM\n', raw=False, quiet=False)

If I comment out 2 lines ::

296 # item[‘heads’] = line.split()[4] 297 # item[‘sectors_per_track’] = line.split()[6]

I have this result : [{“disk”:“/dev/sda”,“cylinders”:32,“units”:“sectors of 1 * 512 = 512 bytes”},{“disk”:“identifier”,“cylinders”:57705}]

If my normal sfdisk output here:

# sfdisk -l /dev/sda
Disk /dev/sda: 32 GiB, 34359738368 bytes, 67108864 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x5fac7705

Device     Boot   Start      End  Sectors Size Id Type
/dev/sda1  *       2048  2099199  2097152   1G 83 Linux
/dev/sda2       2099200 67108863 65009664  31G 8e Linux LVM 

That is, all drive information is not displayed. I would also like to ask for support for the -F flag, I often use it to get information about disk resizing.

Thanx

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:14 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
kellyjonbrazilcommented, Aug 31, 2021

Oh, I forgot to mention - I noticed there is now a -J JSON output option in sfdisk, which is great! Unfortunately, though, it is quite limited at the moment.

1reaction
caisyewcommented, Aug 31, 2021

Thank you very match !!! Work is very well!!! Great job!

sfdisk -l /dev/sdc |jc --sfdisk -p
[
  {
    "disk": "/dev/sdc",
    "disk_size": "931.5 GiB",
    "bytes": 1000204886016,
    "sectors": 1953525168,
    "disk_model": "",
    "units": "sectors of 1 * 512 = 512 bytes",
    "logical_sector_size": 512,
    "physical_sector_size": 4096,
    "min_io_size": 4096,
    "optimal_io_size": 4096,
    "disk_label_type": "gpt",
    "disk_identifier": "00005954-4A70-0000-E60F-0000E3510000",
    "partitions": [
      {
        "device": "/dev/sdc1",
        "start": 40,
        "end": 409639,
        "sectors": 409600,
        "size": "200M",
        "type": "EFI System"
      },
      {
        "device": "/dev/sdc2",
        "start": 411648,
        "end": 1952255591,
        "sectors": 1951843944,
        "size": "930.7G",
        "type": "Microsoft basic data"
      },
      {
        "device": "/dev/sdc3",
        "start": 1952255592,
        "end": 1953525127,
        "sectors": 1269536,
        "size": "619.9M",
        "type": "Apple boot"
      }
    ]
  }
]

And with flag -F:

sfdisk -F /dev/sdc |jc --sfdisk -p
[
  {
    "disk": "/dev/sdc",
    "free_disk_size": "16 EiB",
    "free_bytes": 18446744073708523520,
    "free_sectors": 18446744073709549608,
    "units": "sectors of 1 * 512 = 512 bytes",
    "logical_sector_size": 512,
    "physical_sector_size": 4096,
    "partitions": [
      {
        "start": 2048,
        "end": 39,
        "sectors": 18446744073709549608,
        "size": "16E"
      }
    ]
  }
]
Read more comments on GitHub >

github_iconTop Results From Across the Web

Replication of libfdisk script parsing bug on stock Xubuntu ...
Created a new partition 1 of type 'EFI System' and of size 260 MiB. 3934: libfdisk: ASK: [0x6c8f20]: do_ask done [rc=0]. 3934 ...
Read more >
Fdisk Error Message - Unix & Linux Stack Exchange
After this i went to fdisk and created it again. I then went on to add a file system to this partition using...
Read more >
fdisk: -w / --wipe is no longer honoured in ver 2.36
Bug #1005101: fdisk: -w / --wipe is no longer honoured in ver 2.36 ... previously (deb 10) used fdisk with --wipe=never option, ......
Read more >
[PATCH/RFC] fdisk: read/parse/print GPT disklabels - BusyBox
Return an error if anything is out of place. + * Do not create an empty disklabel. This is used for the "list"...
Read more >
1119045 – vgscan 'Parse error at byte 1587 (line 101)
The tools are complaining that an illegal token (character, word or other element) appeared in the LVM metadata read from the device. An...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found