Backup and restore /run/initramfs via systemd services

This saves the space /run/initramfs is taking for the shutdown
master
Harald Hoyer 2012-02-10 09:37:18 +01:00
parent 81dcf7c90a
commit 4cfd24d179
5 changed files with 81 additions and 3 deletions

View File

@ -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


15
dracut-backup.service Normal file
View File

@ -0,0 +1,15 @@
# 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

View File

@ -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

18
dracut-restore.service Normal file
View File

@ -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

View File

@ -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

@ -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
%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)