Dominique Leuenberger 2022-02-18 22:03:04 +00:00 committed by Git OBS Bridge
parent bf34621d12
commit 09279c3488
3 changed files with 17 additions and 7 deletions

View File

@ -1,3 +1,10 @@
-------------------------------------------------------------------
Wed Feb 16 15:27:38 UTC 2022 - Fabian Vogt <fvogt@suse.com>
- Get the parent device with lsblk
- Improve the partition number extraction to work with device names
containing multiple numbers (bsc#1196101)
-------------------------------------------------------------------
Mon Nov 11 08:29:53 UTC 2019 - Fabian Vogt <fvogt@suse.com>

View File

@ -1,5 +1,4 @@
#!/bin/sh
set -euo pipefail
UNIT_DIR="${1:-/tmp}"
@ -13,6 +12,11 @@ for mnt in $(findmnt --fstab --options x-growpart.grow --output TARGET --noheadi
mnt_esc="$(systemd-escape --path "${mnt}")"
dev_esc="$(systemd-escape --path "${dev}")"
# /dev/sda3 -> /dev/sda, /dev/nvme0n1p3 -> /dev/nvme0n1
parent_dev="/dev/$(lsblk --nodeps -rno PKNAME "${dev}")"
# Last number in the device name: /dev/nvme0n1p42 -> 42
partnum="$(echo "${dev}" | sed 's/^.*[^0-9]\([0-9]\+\)$/\1/')"
mkdir -p "${UNIT_DIR}/${mnt_esc}.mount.wants"
cat > "${UNIT_DIR}/growpart@${dev_esc}.service" <<EOF
[Unit]
@ -35,8 +39,7 @@ Type=oneshot
RemainAfterExit=yes
# Exit code 1 means "NOCHANGE"
SuccessExitStatus=1
# Use sed to split /dev/foo42 into /dev/foo 42
ExecStart=/bin/sh -c "/usr/sbin/growpart $(echo ${dev} | sed 's/\([a-z/]*\)\(\d*\)/\1 \2/')"
ExecStart=/bin/sh -c "/usr/sbin/growpart ${parent_dev} ${partnum}"
TimeoutSec=0
EOF
ln -sf "${UNIT_DIR}/growpart@${dev_esc}.service" "${UNIT_DIR}/${mnt_esc}.mount.wants/"

View File

@ -1,7 +1,7 @@
#
# spec file for package growpart-generator
#
# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany.
# Copyright (c) 2022 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
@ -12,17 +12,17 @@
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.
# Please submit bugfixes or comments via http://bugs.opensuse.org/
# Please submit bugfixes or comments via https://bugs.opensuse.org/
#
Name: growpart-generator
Version: 0.8
Release: 0
Summary: Grow a partition automatically
Summary: Grow a partition automatically
License: GPL-3.0-only
Group: System/Management
Url: https://build.opensuse.org/package/show/devel:kubic/growpart-generator
URL: https://build.opensuse.org/package/show/devel:kubic/growpart-generator
Source1: growpart-generator.sh
Source2: gpl-3.0.txt
BuildRequires: systemd-rpm-macros