Skip to content

growpart: Specify partition without partition number #48

@robbiemcmichael

Description

@robbiemcmichael

Instead of taking an argument for the device and partition number, growpart should have an option to specify the partition without the partition number (e.g via the full partition device name, label or UUID).

We're currently making use of growpart to resize the /var partition on a fleet of heterogeneous bare metal servers. Some partitions are on hard drives while others are on NVMe drives, so we currently need to carry around a script that determines the device name and partition number for the /var partition before running growpart.

The complexity stems from there seemingly being no standard command that will give you the partition number for a device. Since this can be messy to implement, it seems as though others might benefit from this being made simpler.

The scenario is roughly this:

  • Machine boots up
  • The script has no idea what the naming format of the device will be
  • The script does know the partition label and the mount point that it needs to resize

Currently we have to do something like this:

SOURCE=$(findmnt -nr -o SOURCE -T /var)
DEVICE=/dev/$(lsblk -nr -o PKNAME "$SOURCE")
PARTNUM=${SOURCE#$DEVICE}
PARTNUM=${PARTNUM#p}
growpart "$DEVICE" "$PARTNUM"

Though it's actually worse in reality because we don't have lsblk available, so it's a bunch of brittle string manipulation instead.

The improvement would be to be able to resize using one of the following options:

SOURCE=$(findmnt -nr -o SOURCE -T /var)
growpart --device "$SOURCE"
UUID=$(findmnt -nr -o UUID -T /var)
growpart --uuid "$UUID"
growpart --label VAR

The reason to throw in the label and UUID options is that blkid (which is already a dependency of growpart) can get the device name of the partition with blkid --label and blkid --uid. I think this would be enough to implement any of the above options in growpart.

I'm open to other approaches to solving this, I'm mostly just after a way to avoid specifying the partition number in a separate argument because it doesn't lend itself to use in scripts where the partition needs to be discovered first. Determining the partition number has a few catches around device naming formats and is just generally a bit error prone.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions