Create root filesystem snapshots with LVM

From ArchWiki
Revision as of 06:25, 27 April 2013 by Freejack (talk | contribs)
Jump to: navigation, search

This article will show you how to setup LVM snapshot creation during system start. Such snapshots can be used for full system backups with minimal downtime.


A system with LVM root and systemd.


During system start a clean snapshot of the root volume is created using a new service. Create /etc/systemd/system/mk-lvm-snapshots.service containing:

Description=make LVM snapshots


ExecStart=/usr/sbin/lvcreate -L10G -n snap-root -s lvmvolume/root

Adapt the lvcreate command to match your root volume group and volume name.

Create a new systemd target /etc/systemd/system/ with this service:

Description=Make Snapshots

Enable the new service with systemctl enable mk-lvm-snapshots.service.

If the system is started with the new target, LVM snapshot(s) are created just after mounting the local filesystems. To get a grub menu entry starting this target create /boot/grub/custom.cfg based on the grub.cfg entry for your normal startup. The kernel command line is extended to start the new

### make snapshots ###
menuentry 'Arch GNU/Linux, make snapshots' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-core repo kernel-true-...' {
        echo    'Loading Linux core repo kernel ...'
        linux   /boot/vmlinuz-linux root=/dev/mapper/lvmvolume-root ro
        echo    'Loading initial ramdisk ...'
        initrd  /boot/initramfs-linux.img

Remember to adjust custom.cfg if grub.cfg changes.

After restarting the system with this grub entry lvs should show up the newly created snapshot. To get the messages of the new service use journalctl -u mk-lvm-snapshots.service.