Python Tired of parsing geom and gpart

Wrote 100 lines of Python to dump sysctl -n kern.geom.confxml into something more manageable like this

Code:
cd0    -
da0    -
da1    MBR
    da1s1    fat16        msdosfs/DOSDIAG
    da1s2    ntfs        ntfs/WINDOWS7
    da1s3    freebsd        None
    da1s4    ebr            None
da2    GPT
    da2p1    freebsd-zfs    HoogeData
da3    GPT
    da3p1    efi            EFI System Partition
    da3p2    apple-hfs    MacStuff
da4    MBR
    nvd0s1    ntfs        ntfs/System%20Reserved
    nvd0s2    ntfs        None
    nvd0s3    freebsd        None
nvd0    GPT
    nvd0p1    efi                gptid/338bca2f-2047-11ea-8189-7085c2f370a8
    nvd0p2    freebsd-ufs        None
    nvd0p3    freebsd-swap    None

Did I waste my time or is there a simpler way of doing this?
 
Did I waste my time or is there a simpler way of doing this?
Doing stuff is rarely wasting time! At least I find myself learning something almost every time I do something.

Personally, when I need this kind of output I usually used sysctl -n kern.geom.conftxt:
Code:
0 DISK nvd1 512110190592 512 hd 0 sc 0
1 PART nvd1p3 494656290816 512 i 3 o 17453547520 ty freebsd-zfs xs GPT xt 516e7cba-6ecf-11d6-8ff8-00022d09712b
1 PART nvd1p2 17179869184 512 i 2 o 273678336 ty freebsd-swap xs GPT xt 516e7cb5-6ecf-11d6-8ff8-00022d09712b
2 ELI nvd1p2.eli 17179869184 4096
1 PART nvd1p1 272629760 512 i 1 o 20480 ty efi xs GPT xt c12a7328-f81f-11d2-ba4b-00a0c93ec93b
0 DISK nvd0 1024209543168 512 hd 0 sc 0
1 PART nvd0s3 580911104 512 i 3 o 1023626182656 ty !39 xs MBR xt 39
1 PART nvd0s2 1023048607744 512 i 2 o 576716800 ty ntfs xs MBR xt 7
1 PART nvd0s1 575668224 512 i 1 o 1048576 ty ntfs xs MBR xt 7
2 LABEL ntfs/System%20Reserved 575668224 512 i 0 o 0
However, I'm a true sucker for XML so... :p

There is also a version of this available producing dot files that can be visualized with graphics/graphviz:
Code:
sysctl -n kern.geom.confdot | dot -Tsvg -o geom_conf.svg

output.png
 
I knew about conftxt but it's still a bit more messy than I like with all the disks I have attached. The XML to graphviz is pretty impressive, though!

Also about conftxt:
Code:
$ sysctl -n kern.geom.conftxt | wc -l
      80
$ ./bsddisks.py | wc -l
      36

Cuts out diskids for better human identification.
 
Ok, now it's done, pokes into labels and EBRs that they say you shouldn't use

Code:
cd0    -
da0    -
da1    MBR
    da1s1    fat16        msdosfs/MINIBOOT
    da1s2    ntfs        ntfs/WINDOWSXP
    da1s3    freebsd        -
    da1s3*    BSD
        da1s3a    freebsd-ufs    ufsid/some-stuff
        da1s3b    freebsd-swap    -
    da1s4    ebr        -
    da1s4*    EBR
        da1s5    linux-data    ext2fs/LINUX
        da1s5*    MBR
        da1s6    linux-swap    -
da3    GPT
    da3p1    efi        gpt/EFI%20System%20Partition, msdosfs/EFI
    da3p2    apple-hfs    gpt/AppleJunk
da6    GPT
    da6p1    freebsd-zfs    gpt/TonsOfStuff
da7    GPT
    da7p1    efi        gptid/bla-bla-bla
    da7p2    apple-hfs    gpt/MoreAppleJunk
nvd0    MBR
    nvd0s1    ntfs        ntfs/System%20Reserved
    nvd0s2    ntfs        -
    nvd0s3    freebsd        -
    nvd0s3*    BSD
        nvd0s3a    freebsd-swap    -
        nvd0s3b    freebsd-ufs    -
 
Doing stuff is rarely wasting time! At least I find myself learning something almost every time I do something.
Even if the "stuff" is getting out of bed and having a cup of coffee in the morning. It tells me I learned "Yep, still above ground today". :)
Smart-a** aside, I agree with this. I could go Yoda and say something about do or do not, but every good engineer I've worked with has to "do" in order to learn/prove.
The output from #2 is awesome and getting there is Unix at it's core: linking commands together and modifying stdout along the way.
grahamperrin@ start at the bottom of the picture and go up. Think about how the kernel layers things, physical device, geom classes, partitions, GELI.
In the end it may not make sense, but you may get a glimpse of understanding (forest, trees, oh I think that one is an ash)
 
Not a waste :)



geom_conf.png

I'm slightly thrown by the arrows (all in one direction), and I'd probably find it easier to digest if transposed, for things to run from left to right.

I get the gist of it :)

Code:
% lsblk
DEVICE         MAJ:MIN SIZE TYPE                                          LABEL MOUNT
ada0             0:119 932G GPT                                               - -
  ada0p1         0:121 260M efi                                    gpt/efiboot0 -
  <FREE>         -:-   1.0M -                                                 - -
  ada0p2         0:123  16G freebsd-swap                              gpt/swap0 SWAP
  ada0p2.eli     2:53   16G freebsd-swap                                      - SWAP
  ada0p3         0:125 915G freebsd-zfs                                gpt/zfs0 <ZFS>
  ada0p3.eli     0:131 915G -                                                 - -
  <FREE>         -:-   708K -                                                 - -
da0              2:103  14G GPT                                               - -
  <FREE>         -:-   1.0M -                                                 - -
  da0p1          2:104  14G freebsd-zfs                       gpt/cache2-august <ZFS>
  <FREE>         -:-   1.0M -                                                 - -
da1              2:111  29G GPT                                               - -
  <FREE>         -:-   1.0M -                                                 - -
  da1p1          2:112  29G freebsd-zfs                        gpt/cache-august <ZFS>
% zpool list -v
NAME                  SIZE  ALLOC   FREE  CKPOINT  EXPANDSZ   FRAG    CAP  DEDUP    HEALTH  ALTROOT
august                912G   761G   151G        -         -    59%    83%  1.00x    ONLINE  -
  ada0p3.eli          915G   761G   151G        -         -    59%  83.4%      -    ONLINE
cache                    -      -      -        -         -      -      -      -         -
  gpt/cache-august   28.8G  28.6G   184M        -         -     0%  99.4%      -    ONLINE
  gpt/cache2-august  14.4G  6.94G  7.50G        -         -     0%  48.0%      -    ONLINE
%
 
The internet never forgets :),
 
This is way better because it doesn't use Python, I can not be bothered to write in something like shell, and it's in ports.
 
It's not perfect, however I can't complain about the imperfection that I see, because it's a side effect of an enhancement that I requested!
 
Back
Top