From 739b3f2e99e9af663734787c807de7a85750d0b87d60b3484fcb5211d7bf4851 Mon Sep 17 00:00:00 2001 From: Robert Schweikert Date: Tue, 14 Mar 2017 19:05:20 +0000 Subject: [PATCH 1/4] - SUpport single spec builds OBS-URL: https://build.opensuse.org/package/show/Cloud:Tools/growpart?expand=0&rev=6 --- growpart.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/growpart.spec b/growpart.spec index e89e1f9..5e14263 100644 --- a/growpart.spec +++ b/growpart.spec @@ -1,7 +1,7 @@ # # spec file for package growpart # -# Copyright (c) 2016 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed From b71ffcb7760e6ba823a581a742c014d0598c6c2478133b5a1476cc88ec27356f Mon Sep 17 00:00:00 2001 From: Robert Schweikert Date: Tue, 23 Jan 2018 13:48:13 +0000 Subject: [PATCH 2/4] - Update to version 0.30 (bsc#1064755) + improved error messages on failure. + ignore sfdisk failure in 2.28.1 when due to reread failing (LP: #1619285) + Add service file to start growpart via systemd + Add rootgrow script to wrap growpart OBS-URL: https://build.opensuse.org/package/show/Cloud:Tools/growpart?expand=0&rev=7 --- cloud-utils-0.29.tar.gz | 3 --- cloud-utils-0.30.tar.gz | 3 +++ growpart.changes | 10 ++++++++ growpart.spec | 24 ++++++++++++++--- rootgrow | 57 +++++++++++++++++++++++++++++++++++++++++ rootgrow.service | 11 ++++++++ 6 files changed, 101 insertions(+), 7 deletions(-) delete mode 100644 cloud-utils-0.29.tar.gz create mode 100644 cloud-utils-0.30.tar.gz create mode 100644 rootgrow create mode 100644 rootgrow.service diff --git a/cloud-utils-0.29.tar.gz b/cloud-utils-0.29.tar.gz deleted file mode 100644 index b2abc96..0000000 --- a/cloud-utils-0.29.tar.gz +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:9ea1b66f5a4798c8d6eeca48d908e11169a38e943efa433b7ec5dffa907e257c -size 419396 diff --git a/cloud-utils-0.30.tar.gz b/cloud-utils-0.30.tar.gz new file mode 100644 index 0000000..8156bab --- /dev/null +++ b/cloud-utils-0.30.tar.gz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7360dd3d56aca48945a4a1943315f1633f82f3486ca5f065c6746bce274b8aa5 +size 58526 diff --git a/growpart.changes b/growpart.changes index 7db99c9..5858182 100644 --- a/growpart.changes +++ b/growpart.changes @@ -1,3 +1,13 @@ +------------------------------------------------------------------- +Mon Jan 22 21:12:33 UTC 2018 - rjschwei@suse.com + +- Update to version 0.30 (bsc#1064755) + + improved error messages on failure. + + ignore sfdisk failure in 2.28.1 when due to reread failing + (LP: #1619285) + + Add service file to start growpart via systemd + + Add rootgrow script to wrap growpart + ------------------------------------------------------------------- Tue Sep 13 20:53:26 UTC 2016 - rjschwei@suse.com diff --git a/growpart.spec b/growpart.spec index 5e14263..5939e79 100644 --- a/growpart.spec +++ b/growpart.spec @@ -1,7 +1,7 @@ # # spec file for package growpart # -# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -17,17 +17,24 @@ Name: growpart -Version: 0.29 +Version: 0.30 Release: 0 Summary: Grow a partition License: GPL-3.0 Group: System/Management Url: http://launchpad.net/cloud-utils Source0: cloud-utils-%{version}.tar.gz +Source1: rootgrow +Source2: rootgrow.service Patch: licenseGPLv3.patch Requires: util-linux -%if 0%{?suse_version} && 0%{?suse_version} >= 1220 +%if 0%{?suse_version} && 0%{?suse_version} > 1220 Requires: gptfdisk +Requires: python3 +Requires: systemd +# pkg-config is needed to find correct systemd unit dir +BuildRequires: pkg-config +BuildRequires: systemd %endif BuildRoot: %{_tmppath}/%{name}-%{version}-build BuildArch: noarch @@ -44,10 +51,15 @@ partition can be expanded to take up the additional size. %build %install -mkdir -p %{buildroot}/%{_sbindir} mkdir -p %{buildroot}/%{_mandir}/man1 +mkdir -p %{buildroot}/%{_sbindir} cp bin/growpart %{buildroot}/%{_sbindir} cp man/growpart.1 %{buildroot}/%{_mandir}/man1 +%if 0%{?suse_version} && 0%{?suse_version} > 1220 +mkdir -p %{buildroot}/usr/lib/systemd/system +cp %SOURCE1 %{buildroot}/%{_sbindir} +cp %SOURCE2 %{buildroot}/usr/lib/systemd/system +%endif %clean rm -rf $RPM_BUILD_ROOT @@ -57,5 +69,9 @@ rm -rf $RPM_BUILD_ROOT %doc LICENSE-GPLv3 %{_sbindir}/growpart %{_mandir}/man1/* +%if 0%{?suse_version} && 0%{?suse_version} > 1220 +%{_sbindir}/rootgrow +/usr/lib/systemd/system/rootgrow.service +%endif %changelog diff --git a/rootgrow b/rootgrow new file mode 100644 index 0000000..5497c9e --- /dev/null +++ b/rootgrow @@ -0,0 +1,57 @@ +#!/usr/bin/python3 +import os +import re +import syslog + +split_dev = re.compile('([a-z/]*)(\d*)') +mounts = open('/proc/mounts' ,'r').readlines() + +def get_mount_point(device): + for mount in mounts: + if mount.startswith(device): + return mount.split(' ')[1] + +def resize_fs(fs_type, device): + if fs_type.startswith('ext'): + cmd = 'resize2fs %s' % device + syslog.syslog( + syslog.LOG_INFO, + 'Resizing: "%s"' %cmd + ) + os.system(cmd) + elif fs_type == 'xfs': + mnt_point = get_mount_point(device) + cmd = 'xfs_growfs %s' % mnt_point + syslog.syslog( + syslog.LOG_INFO, + 'Resizing: "%s"' %cmd + ) + os.system(cmd) + + +for mount in mounts: + if ' / ' in mount: + mount_dev = mount.split(' ')[0] + fs = mount.split(' ')[2] + try: + dev, partition = split_dev.match(mount_dev).groups() + except: + syslog.syslog( + syslog.LOG_ERR, + 'match exception for "%s"' % mount + ) + break + if dev and partition: + cmd = '/usr/sbin/growpart %s %s' %(dev, partition) + syslog.syslog( + syslog.LOG_INFO, + 'Executing: "%s"' % cmd + ) + os.system(cmd) + resize_fs(fs, mount_dev) + else: + syslog.syslog( + syslog.LOG_ERR, + 'could not match device and partition in "%s"' % mount + ) + diff --git a/rootgrow.service b/rootgrow.service new file mode 100644 index 0000000..23c62f9 --- /dev/null +++ b/rootgrow.service @@ -0,0 +1,11 @@ +[Unit] +Description=Grow the root partition +After=local-fs.target +Wants=local-fs.target + +[Service] +ExecStart=/usr/sbin/rootgrow +Type=oneshot + +[Install] +WantedBy=multi-user.target From 61cd2ed9873096070033c4fd3330d3b132a693db87d94a866d21b0b9c341156e Mon Sep 17 00:00:00 2001 From: Robert Schweikert Date: Tue, 23 Jan 2018 14:40:21 +0000 Subject: [PATCH 3/4] - Fix permissions OBS-URL: https://build.opensuse.org/package/show/Cloud:Tools/growpart?expand=0&rev=8 --- growpart.spec | 1 + 1 file changed, 1 insertion(+) diff --git a/growpart.spec b/growpart.spec index 5939e79..e917233 100644 --- a/growpart.spec +++ b/growpart.spec @@ -59,6 +59,7 @@ cp man/growpart.1 %{buildroot}/%{_mandir}/man1 mkdir -p %{buildroot}/usr/lib/systemd/system cp %SOURCE1 %{buildroot}/%{_sbindir} cp %SOURCE2 %{buildroot}/usr/lib/systemd/system +chmod 755 %{buildroot}/%{_sbindir}/rootgrow %endif %clean From eac27c0ffc3a997c6be6a0d285ef6a4d5c7bb6d504e83d1916a037fbb07cc006 Mon Sep 17 00:00:00 2001 From: Robert Schweikert Date: Wed, 24 Jan 2018 17:16:59 +0000 Subject: [PATCH 4/4] - Split rootgrow and script and service into subpackage to retain dependency chain for growpart OBS-URL: https://build.opensuse.org/package/show/Cloud:Tools/growpart?expand=0&rev=9 --- growpart.changes | 6 ++++++ growpart.spec | 32 ++++++++++++++++++++++++-------- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/growpart.changes b/growpart.changes index 5858182..5c311dd 100644 --- a/growpart.changes +++ b/growpart.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Wed Jan 24 17:15:46 UTC 2018 - rjschwei@suse.com + +- Split rootgrow and script and service into subpackage to retain + dependency chain for growpart + ------------------------------------------------------------------- Mon Jan 22 21:12:33 UTC 2018 - rjschwei@suse.com diff --git a/growpart.spec b/growpart.spec index e917233..552f75b 100644 --- a/growpart.spec +++ b/growpart.spec @@ -16,25 +16,21 @@ # +%define base_version 0.30 Name: growpart -Version: 0.30 +Version: %{base_version} Release: 0 Summary: Grow a partition License: GPL-3.0 Group: System/Management Url: http://launchpad.net/cloud-utils -Source0: cloud-utils-%{version}.tar.gz +Source0: cloud-utils-%{base_version}.tar.gz Source1: rootgrow Source2: rootgrow.service Patch: licenseGPLv3.patch Requires: util-linux %if 0%{?suse_version} && 0%{?suse_version} > 1220 Requires: gptfdisk -Requires: python3 -Requires: systemd -# pkg-config is needed to find correct systemd unit dir -BuildRequires: pkg-config -BuildRequires: systemd %endif BuildRoot: %{_tmppath}/%{name}-%{version}-build BuildArch: noarch @@ -44,8 +40,25 @@ Grow a partition. This is predominantly useful in the cloud when an instance is started with a larger root partition than the image size. The root partition can be expanded to take up the additional size. +%if 0%{?suse_version} && 0%{?suse_version} > 1220 +%package rootgrow +Version: 1.0.0 +Release: 0 +Summary: Resize root partition +Group: System/Management +Requires: growpart +Requires: python3 +Requires: systemd +# pkg-config is needed to find correct systemd unit dir +BuildRequires: pkg-config +BuildRequires: systemd + +%description rootgrow +Provides as script and service togrow the root partition +%endif + %prep -%setup -q -n cloud-utils-%{version} +%setup -q -n cloud-utils-%{base_version} %patch -p1 %build @@ -70,7 +83,10 @@ rm -rf $RPM_BUILD_ROOT %doc LICENSE-GPLv3 %{_sbindir}/growpart %{_mandir}/man1/* + %if 0%{?suse_version} && 0%{?suse_version} > 1220 +%files rootgrow +%defattr(-,root,root,-) %{_sbindir}/rootgrow /usr/lib/systemd/system/rootgrow.service %endif