dracut/0007-Backup-and-restore-run-initramfs-via-systemd-service.patch

189 lines
7.0 KiB
Diff
Raw Normal View History

2012-02-13 06:11:06 +00:00
From 4cfd24d1799fafacf6624c9638454de93dd6f331 Mon Sep 17 00:00:00 2001
2012-02-10 09:01:59 +00:00
From: Harald Hoyer <harald@redhat.com>
Date: Fri, 10 Feb 2012 09:37:18 +0100
Subject: [PATCH] Backup and restore /run/initramfs via systemd services
This saves the space /run/initramfs is taking for the shutdown
---
Makefile | 16 ++++++++++++++--
dracut-backup.service | 15 +++++++++++++++
dracut-initramfs-backup.sh | 22 ++++++++++++++++++++++
dracut-restore.service | 18 ++++++++++++++++++
2012-02-13 06:11:06 +00:00
dracut.spec | 13 ++++++++++++-
5 files changed, 81 insertions(+), 3 deletions(-)
2012-02-10 09:01:59 +00:00
create mode 100644 dracut-backup.service
create mode 100644 dracut-initramfs-backup.sh
create mode 100644 dracut-restore.service
diff --git a/Makefile b/Makefile
index 8d7b7d6..09e87c8 100644
--- a/Makefile
+++ b/Makefile
@@ -40,6 +40,7 @@ install: doc
mkdir -p $(DESTDIR)$(sysconfdir)/dracut.conf.d
install -m 0755 dracut-functions $(DESTDIR)$(pkglibdir)/dracut-functions
install -m 0755 dracut-logger $(DESTDIR)$(pkglibdir)/dracut-logger
+ install -m 0755 dracut-initramfs-backup.sh $(DESTDIR)$(pkglibdir)/dracut-initramfs-backup
cp -arx modules.d $(DESTDIR)$(pkglibdir)
install -m 0644 dracut.8 $(DESTDIR)$(mandir)/man8/dracut.8
install -m 0644 dracut-catimages.8 $(DESTDIR)$(mandir)/man8/dracut-catimages.8
@@ -47,6 +48,15 @@ install: doc
install -m 0644 dracut.conf.5 $(DESTDIR)$(mandir)/man5/dracut.conf.5
install -m 0644 dracut.cmdline.7 $(DESTDIR)$(mandir)/man7/dracut.cmdline.7
ln -s dracut.cmdline.7 $(DESTDIR)$(mandir)/man7/dracut.kernel.7
+ if [ -n "$(systemdsystemunitdir)" ]; then \
+ mkdir -p $(DESTDIR)$(systemdsystemunitdir); \
+ install -m 0644 dracut-backup.service $(DESTDIR)$(systemdsystemunitdir); \
+ install -m 0644 dracut-restore.service $(DESTDIR)$(systemdsystemunitdir); \
+ mkdir -p $(DESTDIR)$(systemdsystemunitdir)/sysinit.target.wants; \
+ mkdir -p $(DESTDIR)$(systemdsystemunitdir)/reboot.target.wants; \
+ ln -s ../dracut-backup.service $(DESTDIR)$(systemdsystemunitdir)/sysinit.target.wants/dracut-backup.service; \
+ ln -s ../dracut-restore.service $(DESTDIR)$(systemdsystemunitdir)/reboot.target.wants/dracut-restore.service; \
+ fi
clean:
$(RM) *~
@@ -77,12 +87,14 @@ rpm: dracut-$(VERSION).tar.bz2
( mv "$$rpmbuild"/noarch/*.rpm .; mv "$$rpmbuild"/*.src.rpm .;rm -fr "$$rpmbuild"; ls *.rpm )
syncheck:
- @ret=0;for i in dracut-logger modules.d/99base/init modules.d/*/*.sh; do \
+ @ret=0;for i in dracut-initramfs-backup.sh dracut-logger \
+ modules.d/99base/init modules.d/*/*.sh; do \
[ "$${i##*/}" = "module-setup.sh" ] && continue; \
[ "$${i##*/}" = "caps.sh" ] && continue; \
dash -n "$$i" ; ret=$$(($$ret+$$?)); \
done;exit $$ret
- @ret=0;for i in dracut modules.d/02caps/caps.sh modules.d/*/module-setup.sh; do \
+ @ret=0;for i in mkinitrd-dracut.sh dracut modules.d/02caps/caps.sh \
+ modules.d/*/module-setup.sh; do \
bash -n "$$i" ; ret=$$(($$ret+$$?)); \
done;exit $$ret
diff --git a/dracut-backup.service b/dracut-backup.service
new file mode 100644
index 0000000..69110eb
--- /dev/null
+++ b/dracut-backup.service
2012-02-13 06:11:06 +00:00
@@ -0,0 +1,15 @@
2012-02-10 09:01:59 +00:00
+# This file is part of systemd.
+#
+# systemd 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; either version 2 of the License, or
+# (at your option) any later version.
+
+[Unit]
+Description=Save /run/initramfs
+ConditionPathExists=/run/initramfs
+
+[Service]
+ExecStart=/usr/lib/dracut/dracut-initramfs-backup backup
+Type=oneshot
+RemainAfterExit=yes
diff --git a/dracut-initramfs-backup.sh b/dracut-initramfs-backup.sh
new file mode 100644
index 0000000..7320d40
--- /dev/null
+++ b/dracut-initramfs-backup.sh
@@ -0,0 +1,22 @@
+#!/bin/sh
+# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
+# ex: ts=8 sw=4 sts=4 et filetype=sh
+
+set -e
+cd /run/initramfs
+
+if [ "x$1" = "xbackup" ]; then
+ compress="gzip"
+ command -v pigz > /dev/null 2>&1 && compress="pigz"
+ find . |cpio -H newc -o --quiet \
+ | pigz > /var/lib/initramfs/_run_initramfs-backup.cpio.gz
+ mv -f /var/lib/initramfs/_run_initramfs-backup.cpio.gz \
+ /var/lib/initramfs/run_initramfs-backup.cpio.gz
+ rm -fr etc bin lib lib64 sbin shutdown tmp usr var
+ > .backuped
+elif [ "x$1" = "xrestore" ]; then
+ [ -f .backuped -a -f /var/lib/initramfs/run_initramfs-backup.cpio.gz ] || exit 1
+ zcat /var/lib/initramfs/run_initramfs-backup.cpio.gz | cpio -id >/dev/null 2>&1
+ rm .backuped
+ rm -f /var/lib/initramfs/run_initramfs-backup.cpio.gz
+fi
diff --git a/dracut-restore.service b/dracut-restore.service
new file mode 100644
index 0000000..3a07efe
--- /dev/null
+++ b/dracut-restore.service
@@ -0,0 +1,18 @@
+# This file is part of systemd.
+#
+# systemd 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; either version 2 of the License, or
+# (at your option) any later version.
+
+[Unit]
+Description=Restore /run/initramfs
+After=getty@tty1.service prefdm.service
+Before=reboot.service
+DefaultDependencies=no
+ConditionPathExists=/run/initramfs/.backuped
+
+[Service]
+ExecStart=/usr/lib/dracut/dracut-initramfs-backup restore
+Type=oneshot
+RemainAfterExit=yes
\ No newline at end of file
diff --git a/dracut.spec b/dracut.spec
2012-02-13 06:11:06 +00:00
index 1b0b76b..6efd553 100644
2012-02-10 09:01:59 +00:00
--- a/dracut.spec
+++ b/dracut.spec
@@ -27,6 +27,7 @@ Source0: http://www.kernel.org/pub/linux/utils/boot/dracut/dracut-%{version}.tar
BuildArch: noarch
BuildRequires: dash bash git
+
%if 0%{?fedora} || 0%{?rhel} > 6
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
%endif
@@ -51,6 +52,10 @@ Obsoletes: nash <= 6.0.93
Obsoletes: libbdevid-python <= 6.0.93
%endif
+%if 0%{?fedora} > 16 || 0%{?rhel} > 6
+BuildRequires: systemd-units
+%endif
+
%if 0%{?suse_version} > 9999
Obsoletes: mkinitrd < 2.6.1
Provides: mkinitrd = 2.6.1
@@ -161,7 +166,8 @@ rm -rf $RPM_BUILD_ROOT
make install DESTDIR=$RPM_BUILD_ROOT \
libdir=%{_prefix}/lib \
bindir=%{_bindir} \
- sysconfdir=/etc mandir=%{_mandir}
+ sysconfdir=/etc mandir=%{_mandir} \
+ systemdsystemunitdir=%{_unitdir}
echo %{name}-%{version}-%{release} > $RPM_BUILD_ROOT/%{dracutlibdir}/modules.d/10rpmversion/dracut-version
2012-02-13 06:11:06 +00:00
@@ -217,6 +223,7 @@ rm -rf $RPM_BUILD_ROOT
%dir %{dracutlibdir}/modules.d
%{dracutlibdir}/dracut-functions
%{dracutlibdir}/dracut-logger
+%{dracutlibdir}/dracut-initramfs-backup
%config(noreplace) /etc/dracut.conf
%if 0%{?fedora} || 0%{?suse_version} || 0%{?rhel} > 6
%config /etc/dracut.conf.d/01-dist.conf
@@ -266,6 +273,10 @@ rm -rf $RPM_BUILD_ROOT
2012-02-10 09:01:59 +00:00
%config(noreplace) /etc/logrotate.d/dracut_log
%attr(0644,root,root) %ghost %config(missingok,noreplace) %{_localstatedir}/log/dracut.log
%dir %{_sharedstatedir}/initramfs
+%if 0%{?fedora} > 16 || 0%{?rhel} > 6
+%{_unitdir}/*.service
+%{_unitdir}/*/*.service
+%endif
%files network
%defattr(-,root,root,0755)