canonical / canonical/cloud-utils

growpart: Specify partition without partition number

Open
#48 1 comment 5 reactions 0 assignees View on GitHub
Dominant language
Shell
Stars
124
Forks
36
PR merge metrics
No merged PRs in 30d

Description

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:

```bash
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:

```bash
SOURCE=$(findmnt -nr -o SOURCE -T /var)
growpart --device "$SOURCE"
```

```bash
UUID=$(findmnt -nr -o UUID -T /var)
growpart --uuid "$UUID"
```

```bash
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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.