clearlinux / distribution

Placeholder repository to allow filing of general bugs/issues/etc against the Clear Linux OS for Intel Architecture linux distribution
522 stars 29 forks source link

please consider to have available 'growpart' (as pundle) #894

Closed AntonioMeireles closed 2 years ago

AntonioMeireles commented 5 years ago

(as handy on contexts where online resizing is possible)

suggested packaging bellow:

From 61cfc2afdaa185da9edde1e90b628c9f8d0c7591 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ant=C3=B3nio=20Meireles?= <antonio.meireles@reformi.st>
Date: Fri, 14 Jun 2019 20:33:28 +0100
Subject: [PATCH] growpart: Autospec creation for version 0.31

---
 .gitignore      |  14 ++++++
 ChangeLog       | 118 ++++++++++++++++++++++++++++++++++++++++++++++
 Makefile        |   5 ++
 buildreq_add    |   2 +
 buildreq_ban    |   2 +
 description     |   1 +
 excludes        |   2 +
 growpart.spec   | 122 ++++++++++++++++++++++++++++++++++++++++++++++++
 install_prepend |  70 +++++++++++++++++++++++++++
 options.conf    |  58 +++++++++++++++++++++++
 pkgconfig_add   |   2 +
 pkgconfig_ban   |   2 +
 release         |   1 +
 requires_add    |   2 +
 requires_ban    |   2 +
 testresults     |   5 ++
 upstream        |   1 +
 17 files changed, 409 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 ChangeLog
 create mode 100644 Makefile
 create mode 100644 buildreq_add
 create mode 100644 buildreq_ban
 create mode 100644 description
 create mode 100644 excludes
 create mode 100644 growpart.spec
 create mode 100644 install_prepend
 create mode 100644 options.conf
 create mode 100644 pkgconfig_add
 create mode 100644 pkgconfig_ban
 create mode 100644 release
 create mode 100644 requires_add
 create mode 100644 requires_ban
 create mode 100644 testresults
 create mode 100644 upstream

diff --git a/description b/description
new file mode 100644
index 0000000..2a0ab7f
--- /dev/null
+++ b/description
@@ -0,0 +1 @@
+Extends a partition to fill available space
\ No newline at end of file
diff --git a/growpart.spec b/growpart.spec
new file mode 100644
index 0000000..3e44eb4
--- /dev/null
+++ b/growpart.spec
@@ -0,0 +1,122 @@
+#
+# This file is auto-generated. DO NOT EDIT
+# Generated by: autospec.py
+#
+Name     : growpart
+License  : GPL-3.0
+Requires: growpart-bin = %{version}-%{release}
+Requires: growpart-license = %{version}-%{release}
+Requires: growpart-man = %{version}-%{release}
+
+%description
+Extends a partition to fill available space
+
+%package bin
+Requires: growpart-license = %{version}-%{release}
+
+
+
+%package license
+
+
+
+%package man
+
+%description man
+man components for the growpart package.
+
+
+%prep
+
+%build
+export GCC_IGNORE_WERROR=1
+export AR=gcc-ar
+export RANLIB=gcc-ranlib
+export NM=gcc-nm
+export CFLAGS="$CFLAGS -O3 -ffat-lto-objects -flto=4 "
+export FCFLAGS="$CFLAGS -O3 -ffat-lto-objects -flto=4 "
+export FFLAGS="$CFLAGS -O3 -ffat-lto-objects -flto=4 "
+export CXXFLAGS="$CXXFLAGS -O3 -ffat-lto-objects -flto=4 "
+make  %{?_smp_mflags}
+
+
+%install
+rm -rf %{buildroot}
+## install_prepend content
+rm -rf $(ls {bin,man}/*|grep -v growpart)
+install -D -m 0644 LICENSE %{buildroot}/usr/share/package-licenses/%{name}/LICENSE
+cat > growpartfs <<EOF
+[ $# -ne 1 ] && { echo "Usage: $0 device|mountpoint"; exit 1; }
+if [ -b "$1" ]; then
+dev="$1"
+else
+dev="$(findmnt -nfvo SOURCE -- "$1")"
+[ -b "$dev" ] || { echo "Cannot find device for '$1'"; exit 1; }
+fi
+if [ "$(lsblk -ndo TYPE -- "$dev")" = part ]; then
+disk="$(lsblk -ndpo PKNAME -- "$dev")"
+partnum="${dev##*[!0-9]}"
+growpart "$disk" "$partnum" || { [ $? -ne 1 ] && exit 1; }
+fi
+fs="$(lsblk -ndo FSTYPE -- "$dev")"
+mnt="$(lsblk -ndo MOUNTPOINT -- "$dev")"
+case "$fs" in
+btrfs) btrfs filesystem resize max "$mnt" || exit 1 ;;
+ext[2-4]) resize2fs -- "$dev" || exit 1 ;;
+xfs) xfs_growfs "$mnt"  || exit 1 ;;
+*) echo "Unsupported filesystem type '$fs'"; exit 1 ;;
+esac
+EOF
+install -D -m 0755 growpartfs %{buildroot}/%{_bindir}/growpartfs
+cat > growpartfs@.service <<EOF
+[Unit]
+Description=Grows the filesystem and partition at %I
+[Service]
+Type=oneshot
+ExecStart=/usr/bin/growpartfs %I
+[Install]
+WantedBy=multi-user.target
+EOF
+install -D -m 0644 growpartfs@.service %{buildroot}/%{_libdir}/systemd/system/growpartfs@.service
+## install_prepend end
+%make_install
+
+%files
+%defattr(-,root,root,-)
+/usr/lib64/systemd/system/growpartfs@.service
+
+%files bin
+%defattr(-,root,root,-)
+/usr/bin/growpart
+/usr/bin/growpartfs
+
+%files license
+%defattr(0644,root,root,0755)
+/usr/share/package-licenses/growpart/LICENSE
+
+%files man
+%defattr(0644,root,root,0755)
+/usr/share/man/man1/growpart.1
diff --git a/install_prepend b/install_prepend
new file mode 100644
index 0000000..8462d1a
--- /dev/null
+++ b/install_prepend
@@ -0,0 +1,70 @@
+
+rm -rf $(ls {bin,man}/*|grep -v growpart)
+
+install -D -m 0644 LICENSE %{buildroot}/usr/share/package-licenses/%{name}/LICENSE
+
+# the goodies bellow come from https://aur.archlinux.org/packages/growpart
+
+cat > growpartfs <<EOF
+#!/bin/sh
+# Copyright 2018 Google Inc. All Rights Reserved.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, version 3 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+# Expands a filesystem and its corresponding partition (if it exists) to fill
+# all available disk space.  Takes as an argument the mountpoint or device to
+# expand, with any specification supported by findmnt.
+[ $# -ne 1 ] && { echo "Usage: $0 device|mountpoint"; exit 1; }
+
+# Find the device to expand.
+if [ -b "$1" ]; then
+    dev="$1"
+else
+    dev="$(findmnt -nfvo SOURCE -- "$1")"
+    [ -b "$dev" ] || { echo "Cannot find device for '$1'"; exit 1; }
+fi
+
+# If it's a partition, expand that first using growpart.
+if [ "$(lsblk -ndo TYPE -- "$dev")" = part ]; then
+    disk="$(lsblk -ndpo PKNAME -- "$dev")"
+    partnum="${dev##*[!0-9]}"
+    growpart "$disk" "$partnum" || { [ $? -ne 1 ] && exit 1; }
+fi
+
+# Expand the filesystem.
+fs="$(lsblk -ndo FSTYPE -- "$dev")"
+mnt="$(lsblk -ndo MOUNTPOINT -- "$dev")"
+case "$fs" in
+    btrfs) btrfs filesystem resize max "$mnt" || exit 1 ;;
+    ext[2-4]) resize2fs -- "$dev" || exit 1 ;;
+    xfs) xfs_growfs "$mnt"  || exit 1 ;;
+    *) echo "Unsupported filesystem type '$fs'"; exit 1 ;;
+esac
+
+EOF
+
+install -D -m 0755 growpartfs %{buildroot}/%{_bindir}/growpartfs
+
+cat > growpartfs@.service <<EOF
+[Unit]
+Description=Grows the filesystem and partition at %I
+
+[Service]
+Type=oneshot
+ExecStart=/usr/bin/growpartfs %I
+
+[Install]
+WantedBy=multi-user.target
+
+EOF
+install -D -m 0644 growpartfs@.service %{buildroot}/%{_libdir}/systemd/system/growpartfs@.service
diff --git a/options.conf b/options.conf
new file mode 100644
index 0000000..8555c0c
--- /dev/null
+++ b/options.conf
@@ -0,0 +1,58 @@
+name = growpart
+url = https://launchpad.net/cloud-utils/trunk/0.31/+download/cloud-utils-0.31.tar.gz
+use_lto = true
+verify_required = false

Thanks in Advance!

All the best, and a great weekend

ahkok commented 5 years ago

Can we please not have here documents installing scripts (it's fine for a 3-liner, not 30+ lines). Instead, add them through a patch to the source tree, and add a single line in install_append that transfers them into the %{buildroot}

ahkok commented 5 years ago

Similarly, autospec can handle .service files already. Just add them directly to the folder. (fairly sure they would handle @ ok).

However, this unit makes very little sense to me tbh.

AntonioMeireles commented 5 years ago

revised patch per review comments bellow:

From 6d6959fc8231602859906fa27c6c41b5e010ad66 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ant=C3=B3nio=20Meireles?= <antonio.meireles@reformi.st>
Date: Sat, 15 Jun 2019 12:47:08 +0100
Subject: [PATCH] growpart: Autospec creation for version 0.31

---
 .gitignore          |  14 ++++++
 ChangeLog           | 118 ++++++++++++++++++++++++++++++++++++++++++++
 Makefile            |   5 ++
 buildreq_add        |   2 +
 buildreq_ban        |   2 +
 description         |   1 +
 excludes            |   2 +
 growpart.spec       | 107 +++++++++++++++++++++++++++++++++++++++
 growpartfs.patch    |  48 ++++++++++++++++++
 growpartfs@.service |   9 ++++
 install_prepend     |   3 ++
 options.conf        |  58 ++++++++++++++++++++++
 pkgconfig_add       |   2 +
 pkgconfig_ban       |   2 +
 release             |   1 +
 requires_add        |   2 +
 requires_ban        |   2 +
 series              |   1 +
 testresults         |   5 ++
 upstream            |   1 +
 20 files changed, 385 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 ChangeLog
 create mode 100644 Makefile
 create mode 100644 buildreq_add
 create mode 100644 buildreq_ban
 create mode 100644 description
 create mode 100644 excludes
 create mode 100644 growpart.spec
 create mode 100644 growpartfs.patch
 create mode 100644 growpartfs@.service
 create mode 100644 install_prepend
 create mode 100644 options.conf
 create mode 100644 pkgconfig_add
 create mode 100644 pkgconfig_ban
 create mode 100644 release
 create mode 100644 requires_add
 create mode 100644 requires_ban
 create mode 100644 series
 create mode 100644 testresults
 create mode 100644 upstream

diff --git a/description b/description
new file mode 100644
index 0000000..2a0ab7f
--- /dev/null
+++ b/description
@@ -0,0 +1 @@
+Extends a partition to fill available space
\ No newline at end of file
diff --git a/growpart.spec b/growpart.spec
new file mode 100644
index 0000000..517704f
--- /dev/null
+++ b/growpart.spec
@@ -0,0 +1,107 @@
+#
+# This file is auto-generated. DO NOT EDIT
+# Generated by: autospec.py
+#
+Name     : growpart
+Source1  : growpartfs@.service
+License  : GPL-3.0
+Requires: growpart-bin = %{version}-%{release}
+Requires: growpart-license = %{version}-%{release}
+Requires: growpart-man = %{version}-%{release}
+Requires: growpart-services = %{version}-%{release}
+Patch1: growpartfs.patch
+
+%description
+Extends a partition to fill available space
+
+%package bin
+Requires: growpart-license = %{version}-%{release}
+Requires: growpart-services = %{version}-%{release}
+
+
+
+%package license
+
+
+
+%package man
+
+%description man
+man components for the growpart package.
+
+
+%package services
+Group: Systemd services
+
+%description services
+services components for the growpart package.
+
+
+%prep
+%patch1 -p1
+
+%build
+export GCC_IGNORE_WERROR=1
+export AR=gcc-ar
+export RANLIB=gcc-ranlib
+export NM=gcc-nm
+export CFLAGS="$CFLAGS -O3 -ffat-lto-objects -flto=4 "
+export FCFLAGS="$CFLAGS -O3 -ffat-lto-objects -flto=4 "
+export FFLAGS="$CFLAGS -O3 -ffat-lto-objects -flto=4 "
+export CXXFLAGS="$CXXFLAGS -O3 -ffat-lto-objects -flto=4 "
+make  %{?_smp_mflags}
+
+
+%install
+rm -rf %{buildroot}
+## install_prepend content
+rm -rf $(ls {bin,man}/*|grep -v growpart)
+install -D -m 0644 LICENSE %{buildroot}/usr/share/package-licenses/%{name}/LICENSE
+## install_prepend end
+%make_install
+mkdir -p %{buildroot}/usr/lib/systemd/system
+install -m 0644 %{SOURCE1} %{buildroot}/usr/lib/systemd/system/growpartfs@.service
+
+%files
+%defattr(-,root,root,-)
+
+%files bin
+%defattr(-,root,root,-)
+/usr/bin/growpart
+/usr/bin/growpartfs
+
+%files license
+%defattr(0644,root,root,0755)
+/usr/share/package-licenses/growpart/LICENSE
+
+%files man
+%defattr(0644,root,root,0755)
+/usr/share/man/man1/growpart.1
+
+%files services
+%defattr(-,root,root,-)
+/usr/lib/systemd/system/growpartfs@.service
diff --git a/growpartfs.patch b/growpartfs.patch
new file mode 100644
index 0000000..7cfaebb
--- /dev/null
+++ b/growpartfs.patch
@@ -0,0 +1,48 @@
+diff -Naur cloud-utils-0.31/bin/growpartfs cloud-utils-0.31+growpartfs/bin/growpartfs
+--- cloud-utils-0.31/bin/growpartfs    1970-01-01 01:00:00.000000000 +0100
++++ cloud-utils-0.31+growpartfs/bin/growpartfs 2019-06-15 12:23:48.000000000 +0100
+@@ -0,0 +1,44 @@
++#!/bin/sh
++# Copyright 2018 Google Inc. All Rights Reserved.
++#
++# This program is free software: you can redistribute it and/or modify
++# it under the terms of the GNU General Public License as published by
++# the Free Software Foundation, version 3 of the License.
++#
++# This program is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++# GNU General Public License for more details.
++#
++# You should have received a copy of the GNU General Public License
++# along with this program.  If not, see <https://www.gnu.org/licenses/>.
++
++# Expands a filesystem and its corresponding partition (if it exists) to fill
++# all available disk space.  Takes as an argument the mountpoint or device to
++# expand, with any specification supported by findmnt.
++[ $# -ne 1 ] && { echo "Usage: $0 device|mountpoint"; exit 1; }
++
++# Find the device to expand.
++if [ -b "$1" ]; then
++  dev="$1"
++else
++  dev="$(findmnt -nfvo SOURCE -- "$1")"
++  [ -b "$dev" ] || { echo "Cannot find device for '$1'"; exit 1; }
++fi
++
++# If it's a partition, expand that first using growpart.
++if [ "$(lsblk -ndo TYPE -- "$dev")" = part ]; then
++  disk="$(lsblk -ndpo PKNAME -- "$dev")"
++  partnum="${dev##*[!0-9]}"
++  growpart "$disk" "$partnum" || { [ $? -ne 1 ] && exit 1; }
++fi
++
++# Expand the filesystem.
++fs="$(lsblk -ndo FSTYPE -- "$dev")"
++mnt="$(lsblk -ndo MOUNTPOINT -- "$dev")"
++case "$fs" in
++  btrfs) btrfs filesystem resize max "$mnt" || exit 1 ;;
++  ext[2-4]) resize2fs -- "$dev" || exit 1 ;;
++  xfs) xfs_growfs "$mnt"  || exit 1 ;;
++  *) echo "Unsupported filesystem type '$fs'"; exit 1 ;;
++esac
diff --git a/growpartfs@.service b/growpartfs@.service
new file mode 100644
index 0000000..df2fa0b
--- /dev/null
+++ b/growpartfs@.service
@@ -0,0 +1,9 @@
+[Unit]
+Description=Grows the filesystem and partition at %I
+
+[Service]
+Type=oneshot
+ExecStart=/usr/bin/growpartfs %I
+
+[Install]
+WantedBy=multi-user.target
diff --git a/install_prepend b/install_prepend
new file mode 100644
index 0000000..82ebcbf
--- /dev/null
+++ b/install_prepend
@@ -0,0 +1,3 @@
+rm -rf $(ls {bin,man}/*|grep -v growpart)
+
+install -D -m 0644 LICENSE %{buildroot}/usr/share/package-licenses/%{name}/LICENSE
diff --git a/options.conf b/options.conf
new file mode 100644
index 0000000..8555c0c
--- /dev/null
+++ b/options.conf
@@ -0,0 +1,58 @@
+name = growpart
+url = https://launchpad.net/cloud-utils/trunk/0.31/+download/cloud-utils-0.31.tar.gz
+use_lto = true
+verify_required = false
diff --git a/series b/series
new file mode 100644
index 0000000..7686d11
--- /dev/null
+++ b/series
@@ -0,0 +1 @@
+growpartfs.patch

the case for the unit file is pretty simple - if you have a cloud guest somewhere - say GCE already running and want, for one reason or another, to extend one of its partitions and do not want a full reinstall (via ucd - which may or may or may not be in use) then you just increase the partition size via whatever tooling the cloud provider gives you and then you just reboot the guest and the new size will be in effect. (the service file is instantiated to give the use the ability to fine grain whatever it wants resizable).

OTOH tbh having this kind of facilities available is also about reducing the drift off migrating to ClearLinux by giving the (new) users the ability to get their payloads running with minimal mods to whatever way they are already on. (and fwiw, unlike say the CLR statelessness, i frankly do not think this is an area where it may make sense to even try to tell ppl to be different)

Again, thanks for your patience and a great weekend

chriseomi commented 2 years ago

This is a great idea. Any idea why it was never added? growpart is super useful for increasing disks on cloud providers without downtime.

bryteise commented 2 years ago

Should be added to the next release.