https://wiki.archlinux.org/api.php?action=feedcontributions&user=Freejack&feedformat=atomArchWiki - User contributions [en]2024-03-29T05:39:04ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=NFS&diff=292404NFS2014-01-11T11:39:56Z<p>Freejack: /* using /etc/fstab */ typo</p>
<hr />
<div>[[Category:File systems]]<br />
[[Category:Networking]]<br />
[[ar:NFS]]<br />
[[de:Network File System]]<br />
[[es:NFS]]<br />
[[fr:NFS]]<br />
[[it:NFSv4]]<br />
[[zh-CN:NFS]]<br />
{{Related articles start}}<br />
{{Related|NFS Troubleshooting}}<br />
{{Related articles end}}<br />
From [[Wikipedia: Network File System|Wikipedia]]: <br />
: ''Network File System (NFS) is a distributed file system protocol originally developed by Sun Microsystems in 1984, allowing a user on a client computer to access files over a network in a manner similar to how local storage is accessed.''<br />
<br />
== Installation ==<br />
<br />
Both client and server only require the [[pacman|installation]] of the {{Pkg|nfs-utils}} package.<br />
<br />
{{Note|It is HIGHLY recommended to use a time sync daemon on ALL nodes of your network to keep client/server clocks in sync. Without accurate clocks on all nodes, NFS can introduce unwanted delays! The [[NTP]] system is recommended to sync both the server and the clients to the highly accurate NTP servers available on the Internet.}}<br />
<br />
==Configuration==<br />
<br />
===Server===<br />
<br />
==== ID mapping ====<br />
<br />
Edit {{ic|/etc/idmapd.conf}} and set the {{ic|Domain}} field to your domain name.<br />
<br />
{{hc|/etc/idmapd.conf|<nowiki><br />
[General]<br />
<br />
Verbosity = 1<br />
Pipefs-Directory = /var/lib/nfs/rpc_pipefs<br />
Domain = atomic<br />
<br />
[Mapping]<br />
<br />
Nobody-User = nobody<br />
Nobody-Group = nobody<br />
</nowiki>}}<br />
<br />
==== File system ====<br />
<br />
{{Note|For security reasons, it is recommended to use an NFS export root which will keep users limited to that mount point only. The following example illustrates this concept.}}<br />
<br />
Define any NFS shares in {{ic|/etc/exports}} which are relative to the NFS root. In this example, the NFS root will be {{ic|/srv/nfs4}} and we will be sharing {{ic|/mnt/music}}.<br />
<br />
# mkdir -p /srv/nfs4/music<br />
<br />
Read/Write permissions must be set on the music directory so clients may write to it. <br />
<br />
Now mount the actual target share, {{ic|/mnt/music}} to the NFS share via the mount command:<br />
<br />
# mount --bind /mnt/music /srv/nfs4/music<br />
<br />
To make it stick across server reboots, add the bind mount to {{ic|fstab}}:<br />
{{hc|/etc/fstab|<br />
/mnt/music /srv/nfs4/music none bind 0 0<br />
}}<br />
<br />
==== Exports ====<br />
<br />
Add directories to be shared and an ip address or hostname(s) of client machines that will be allowed to mount them in {{ic|exports}}:<br />
{{hc|/etc/exports|<nowiki><br />
/srv/nfs4/ 192.168.0.1/24(rw,fsid=root,no_subtree_check)<br />
/srv/nfs4/music 192.168.0.1/24(rw,no_subtree_check,nohide) # note the nohide option which is applied to mounted directories on the file system.<br />
</nowiki>}}<br />
<br />
Users need-not open the share to the entire subnet; one can specify a single IP address or hostname as well.<br />
<br />
For more information about all available options see {{ic|man 5 exports}}.<br />
<br />
If you modify {{ic|/etc/exports}} while the server is running, you must re-export them for changes to take effect:<br />
# exportfs -rav<br />
<br />
==== Starting the server ====<br />
<br />
Start {{ic|rpc-idmapd.service}} and {{ic|rpc-mountd.service}} [[systemd#Using units|using systemd]]. If you want them running at boot time, enable them. Note that these units require other services, which are launched automatically by [[systemd]].<br />
<br />
==== Firewall configuration ====<br />
<br />
To enable access through a firewall, tcp and udp ports 111, 2049, and 20048 need to be opened. To configure this for [[iptables]], edit {{ic|/etc/iptables/iptables.rules}} to include the following lines:<br />
<br />
{{hc|/etc/iptables/iptables.rules|<nowiki><br />
-A INPUT -p tcp -m tcp --dport 111 -j ACCEPT<br />
-A INPUT -p tcp -m tcp --dport 2049 -j ACCEPT<br />
-A INPUT -p tcp -m tcp --dport 20048 -j ACCEPT<br />
-A INPUT -p udp -m udp --dport 111 -j ACCEPT<br />
-A INPUT -p udp -m udp --dport 2049 -j ACCEPT<br />
-A INPUT -p udp -m udp --dport 20048 -j ACCEPT<br />
</nowiki>}}<br />
<br />
To apply changes, restart {{ic|iptables}} service.<br />
<br />
=== Client ===<br />
<br />
Clients need to start {{ic|rpc-gssd.service}} to avoid an approx 15 seconds delay with an accompanying error in dmsg that reads, "RPC: AUTH_GSS upcall timed out".<br />
<br />
{{Note|The server does not need to run this service.}}<br />
<br />
==== Mounting from Linux ====<br />
<br />
Show the server's exported filesystems:<br />
$ showmount -e servername<br />
<br />
Then mount omitting the server's NFS export root: <br />
# mount -t nfs4 servername:/music /mountpoint/on/client<br />
<br />
{{Note|Server name needs to be a valid hostname (not just IP address). Otherwise mounting of remote share will hang.}}<br />
<br />
===== using /etc/fstab =====<br />
<br />
Using [[fstab]] is useful for a server which is always on, and the NFS shares are available whenever the client boots up. Edit {{ic|/etc/fstab}} file, and add an appropriate line reflecting the setup. Again, the server's NFS export root is omitted.<br />
<br />
{{hc|/etc/fstab|<nowiki><br />
servername:/music /mountpoint/on/client nfs4 rsize=8192,wsize=8192,timeo=14,intr,_netdev 0 0<br />
</nowiki>}}<br />
<br />
{{Note|Consult the NFS and mount man pages for more mount options.}}<br />
<br />
Some additional mount options to consider are include:<br />
<br />
; rsize and wsize: The {{ic|rsize}} value is the number of bytes used when reading from the server. The {{ic|wsize}} value is the number of bytes used when writing to the server. The default for both is 1024, but using higher values such as 8192 can improve throughput. This is not universal. It is recommended to test after making this change, see [[#Performance tuning]].<br />
<br />
; timeo: The {{ic|timeo}} value is the amount of time, in tenths of a second, to wait before resending a transmission after an RPC timeout. After the first timeout, the timeout value is doubled for each retry for a maximum of 60 seconds or until a major timeout occurs. If connecting to a slow server or over a busy network, better performance can be achieved by increasing this timeout value. <br />
<br />
; intr: The {{ic|intr}} option allows signals to interrupt the file operation if a major timeout occurs for a hard-mounted share.<br />
<br />
; _netdev: The {{ic|_netdev}} option tells the system to wait until the network is up before trying to mount the share. systemd assumes this for NFS, but anyway it is good practice to use it for all types of networked filesystems<br />
<br />
{{Note|Setting the sixth field (fs_passno) to a nonzero value may lead to unexpected behaviour, e.g. hangs when the systemd automount waits for a check which will never happen.}}<br />
<br />
===== Using autofs =====<br />
<br />
Using [[autofs]] is useful when multiple machines want to connect via NFS; they could both be clients as well as servers. The reason this method is preferable over the earlier one is that if the server is switched off, the client will not throw errors about being unable to find NFS shares. See [[autofs#NFS network mounts]] for details.<br />
<br />
==== Mounting from Windows ====<br />
<br />
{{Note|Only the Ultimate and Enterprise editions of Windows 7 and the Enterprise edition of Windows 8 include "Client for NFS".}}<br />
NFS shares can be mounted from Windows if the "Client for NFS" service is activated (which it is not by default).<br />
To install the service go to "Programs and features" in the Control Panel and click on "Turn Windows features on or off". Locate "Services for NFS" and activate it as well as both subservices ("Administrative tools" and "Client for NFS").<br />
<br />
Some global options can be set by opening the "Services for Network File System" (locate it with the search box) and right click on ''client > properties''.<br />
<br />
{{Warning|Serious performance issues may occur (it randomly takes 30-60 seconds to display a folder, 2 MB/s file copy speed on gigabit LAN, ...) to which Microsoft does not have a solution yet.[https://social.technet.microsoft.com/Forums/en-CA/w7itpronetworking/thread/40cc01e3-65e4-4bb6-855e-cef1364a60ac]}}<br />
<br />
To mount a share using Explorer:<br />
<br />
{{ic|Computer}} > {{ic|Map network drive}} > {{ic|servername:/srv/nfs4/music}}<br />
<br />
==== Mounting from OS X ====<br />
<br />
{{Note|OS X by default uses an insecure (>1024) port to mount a share.}}<br />
Either export the share with the {{ic|insecure}} flag, and mount using Finder:<br />
<br />
{{ic|Go}} > {{ic|Connect to Server}} > {{ic|nfs://servername/}}<br />
<br />
Or, mount the share using a secure port using the terminal:<br />
# mount -t nfs -o resvport servername:/srv/nfs4 /Volumes/servername<br />
<br />
== Tips and tricks ==<br />
<br />
=== Performance tuning ===<br />
<br />
In order to get the most out of NFS, it is necessary to tune the {{ic|rsize}} and {{ic|wsize}} mount options to meet the requirements of the network configuration.<br />
<br />
=== Automatic mount handling ===<br />
<br />
This trick is useful for laptops that require nfs shares from a local wireless network. If the nfs host becomes unreachable, the nfs share will be unmounted to hopefully prevent system hangs when using the hard mount option. See https://bbs.archlinux.org/viewtopic.php?pid=1260240#p1260240<br />
<br />
Make sure that the NFS mount points are correctly indicated in {{ic|/etc/fstab}}:<br />
<br />
{{hc|$ cat /etc/fstab|<nowiki><br />
lithium:/mnt/data /mnt/data nfs noauto,noatime,rsize=32768,wsize=32768,intr,hard 0 0<br />
lithium:/var/cache/pacman /var/cache/pacman nfs noauto,noatime,rsize=32768,wsize=32768,intr,hard 0 0</nowiki><br />
}}<br />
<br />
The {{ic|noauto}} mount option tells systemd not to automatically mount the shares at boot. systemd would otherwise attempt to mount the nfs shares that may or may not exist on the network causing the boot process to appear to stall on a blank screen.<br />
<br />
In order to mount NFS share by non-root user {{ic|user}} may be required to be added to fstab entry. Also enable rpc-statd.service.<br />
<br />
Create the {{ic|auto_share}} script that will be used by ''cron'' to check if the NFS host is reachable,<br />
<br />
{{hc|/root/bin/auto_share|<nowiki><br />
#!/bin/bash<br />
<br />
SERVER="YOUR_NFS_HOST"<br />
<br />
MOUNT_POINTS=$(sed -e '/^.*#/d' -e '/^.*:/!d' -e 's/\t/ /g' /etc/fstab | tr -s " " | cut -f2 -d" ")<br />
<br />
ping -c 1 "${SERVER}" &>/dev/null<br />
<br />
if [ $? -ne 0 ]; then<br />
# The server could not be reached, unmount the shares<br />
for umntpnt in ${MOUNT_POINTS}; do<br />
umount -l -f $umntpnt &>/dev/null<br />
done<br />
else<br />
# The server is up, make sure the shares are mounted<br />
for mntpnt in ${MOUNT_POINTS}; do<br />
mountpoint -q $mntpnt || mount $mntpnt<br />
done<br />
fi<br />
</nowiki>}}<br />
<br />
# chmod +x /root/bin/auto_share<br />
<br />
Create the root cron entry to run {{ic|auto_share}} every minute:<br />
<br />
{{hc|# crontab -e|<nowiki><br />
* * * * * /root/bin/auto_share<br />
</nowiki>}}<br />
<br />
A systemd unit file can also be used to mount the NFS shares at startup. The unit file is not necessary if NetworkManager is installed and configured on the client system. See [[#NetworkManager dispatcher]].<br />
<br />
{{hc|/etc/systemd/system/auto_share.service|<nowiki><br />
[Unit]<br />
Description=NFS automount<br />
<br />
[Service]<br />
Type=oneshot<br />
RemainAfterExit=yes<br />
ExecStart=/root/bin/auto_share<br />
<br />
[Install]<br />
WantedBy=multi-user.target<br />
</nowiki>}}<br />
<br />
Now enable {{ic|auto_share}}.<br />
<br />
==== NetworkManager dispatcher ====<br />
<br />
In addition to the method described previously, NetworkManager can also be configured to run a script on network status change.<br />
<br />
Enable and start the {{ic|NetworkManager-dispatcher}} service.<br />
<br />
The easiest method for mount shares on network status change is to just symlink to the {{ic|auto_share}} script:<br />
<br />
# ln -s /root/bin/auto_share /etc/NetworkManager/dispatcher.d/30_nfs.sh<br />
<br />
Or use the following mounting script that checks for network availability:<br />
<br />
{{hc|/etc/NetworkManager/dispatcher.d/30_nfs.sh|<nowiki><br />
#!/bin/bash<br />
<br />
SSID="CHANGE_ME"<br />
<br />
MOUNT_POINTS=$(sed -e '/^.*#/d' -e '/^.*:/!d' -e 's/\t/ /g' /etc/fstab | tr -s " " | cut -f2 -d" ")<br />
<br />
ISNETUP=$(nmcli dev wifi | \grep $SSID | tr -s ' ' | cut -f 10 -d ' ') 2>/dev/null<br />
<br />
# echo "$ISNETUP" >> /tmp/nm_dispatch_log<br />
<br />
if [[ "$ISNETUP" == "yes" ]]; then<br />
for mntpnt in ${MOUNT_POINTS}; do<br />
mountpoint -q $mntpnt || mount $mntpnt<br />
done<br />
else<br />
for srvexp in ${MOUNT_POINTS}; do<br />
umount -l -f $srvexp &>/dev/null<br />
done<br />
fi<br />
</nowiki>}}<br />
<br />
Now when the wireless SSID "CHANGE_ME" goes up or down, the {{ic|nfs.sh}} script will be called to mount or unmount the shares as soon as possible.<br />
<br />
=== Configure NFS fixed ports ===<br />
<br />
{{Out of date|This section was originally refered to NFS version 3.}}<br />
If you have a port-based [[firewall]], you might want to set up a fixed ports. For rpc.statd and rpc.mountd you should set following settings in {{ic|/etc/conf.d/nfs-common}} and {{ic|/etc/conf.d/nfs-server}} (ports can be different):<br />
<br />
{{hc|/etc/conf.d/nfs-common|2=STATD_OPTS="-p 4000 -o 4003"}}<br />
{{hc|/etc/conf.d/nfs-server|2=MOUNTD_OPTS="--no-nfs-version 2 -p 4002"}}<br />
{{hc|/etc/modprobe.d/lockd.conf|2=# Static ports for NFS lockd<br />
options lockd nlm_udpport=4001 nlm_tcpport=4001}}<br />
<br />
After restart {{ic|nfs-common}} {{ic|nfs-server}} daemons and reload {{ic|lockd}} modules you can check used ports with following command:<br />
{{hc|$ rpcinfo -p|<br />
program vers proto port service<br />
100000 4 tcp 111 portmapper<br />
100000 3 tcp 111 portmapper<br />
100000 2 tcp 111 portmapper<br />
100000 4 udp 111 portmapper<br />
100000 3 udp 111 portmapper<br />
100000 2 udp 111 portmapper<br />
100024 1 udp 4000 status<br />
100024 1 tcp 4000 status<br />
100021 1 udp 4001 nlockmgr<br />
100021 3 udp 4001 nlockmgr<br />
100021 4 udp 4001 nlockmgr<br />
100021 1 tcp 4001 nlockmgr<br />
100021 3 tcp 4001 nlockmgr<br />
100021 4 tcp 4001 nlockmgr<br />
100003 2 tcp 2049 nfs<br />
100003 3 tcp 2049 nfs<br />
100003 4 tcp 2049 nfs<br />
100003 2 udp 2049 nfs<br />
100003 3 udp 2049 nfs<br />
100003 4 udp 2049 nfs<br />
100005 3 udp 4002 mountd<br />
100005 3 tcp 4002 mountd<br />
}}<br />
<br />
Then, you need to open the ports 111-2049-4000-4001-4002-4003 TCP and UDP.<br />
<br />
== Troubleshooting ==<br />
<br />
There is a dedicated article [[NFS Troubleshooting]].<br />
<br />
== See also ==<br />
<br />
* See also [[Avahi]], a Zeroconf implementation which allows automatic discovery of NFS shares.<br />
* HOWTO: [[Diskless network boot NFS root]]<br />
* [http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?topic=/com.ibm.aix.prftungd/doc/prftungd/nfs_perf.htm NFS Performance Management]<br />
* If you are setting up the Arch Linux NFS server for use by Windows clients through Microsoft's SFU, you will save a lot of time and hair-scratching by looking at [https://bbs.archlinux.org/viewtopic.php?pid=523934#p523934 this forum post] first !<br />
* [http://blogs.msdn.com/sfu/archive/2008/04/14/all-well-almost-about-client-for-nfs-configuration-and-performance.aspx Microsoft Services for Unix NFS Client info]<br />
* [http://blogs.msdn.com/sfu/archive/2007/05/01/unix-interoperability-and-windows-vista.aspx Unix interoperability and Windows Vista] Prerequisites to connect to NFS with Vista</div>Freejackhttps://wiki.archlinux.org/index.php?title=NFS&diff=292403NFS2014-01-11T11:39:09Z<p>Freejack: note regarding fs_passno</p>
<hr />
<div>[[Category:File systems]]<br />
[[Category:Networking]]<br />
[[ar:NFS]]<br />
[[de:Network File System]]<br />
[[es:NFS]]<br />
[[fr:NFS]]<br />
[[it:NFSv4]]<br />
[[zh-CN:NFS]]<br />
{{Related articles start}}<br />
{{Related|NFS Troubleshooting}}<br />
{{Related articles end}}<br />
From [[Wikipedia: Network File System|Wikipedia]]: <br />
: ''Network File System (NFS) is a distributed file system protocol originally developed by Sun Microsystems in 1984, allowing a user on a client computer to access files over a network in a manner similar to how local storage is accessed.''<br />
<br />
== Installation ==<br />
<br />
Both client and server only require the [[pacman|installation]] of the {{Pkg|nfs-utils}} package.<br />
<br />
{{Note|It is HIGHLY recommended to use a time sync daemon on ALL nodes of your network to keep client/server clocks in sync. Without accurate clocks on all nodes, NFS can introduce unwanted delays! The [[NTP]] system is recommended to sync both the server and the clients to the highly accurate NTP servers available on the Internet.}}<br />
<br />
==Configuration==<br />
<br />
===Server===<br />
<br />
==== ID mapping ====<br />
<br />
Edit {{ic|/etc/idmapd.conf}} and set the {{ic|Domain}} field to your domain name.<br />
<br />
{{hc|/etc/idmapd.conf|<nowiki><br />
[General]<br />
<br />
Verbosity = 1<br />
Pipefs-Directory = /var/lib/nfs/rpc_pipefs<br />
Domain = atomic<br />
<br />
[Mapping]<br />
<br />
Nobody-User = nobody<br />
Nobody-Group = nobody<br />
</nowiki>}}<br />
<br />
==== File system ====<br />
<br />
{{Note|For security reasons, it is recommended to use an NFS export root which will keep users limited to that mount point only. The following example illustrates this concept.}}<br />
<br />
Define any NFS shares in {{ic|/etc/exports}} which are relative to the NFS root. In this example, the NFS root will be {{ic|/srv/nfs4}} and we will be sharing {{ic|/mnt/music}}.<br />
<br />
# mkdir -p /srv/nfs4/music<br />
<br />
Read/Write permissions must be set on the music directory so clients may write to it. <br />
<br />
Now mount the actual target share, {{ic|/mnt/music}} to the NFS share via the mount command:<br />
<br />
# mount --bind /mnt/music /srv/nfs4/music<br />
<br />
To make it stick across server reboots, add the bind mount to {{ic|fstab}}:<br />
{{hc|/etc/fstab|<br />
/mnt/music /srv/nfs4/music none bind 0 0<br />
}}<br />
<br />
==== Exports ====<br />
<br />
Add directories to be shared and an ip address or hostname(s) of client machines that will be allowed to mount them in {{ic|exports}}:<br />
{{hc|/etc/exports|<nowiki><br />
/srv/nfs4/ 192.168.0.1/24(rw,fsid=root,no_subtree_check)<br />
/srv/nfs4/music 192.168.0.1/24(rw,no_subtree_check,nohide) # note the nohide option which is applied to mounted directories on the file system.<br />
</nowiki>}}<br />
<br />
Users need-not open the share to the entire subnet; one can specify a single IP address or hostname as well.<br />
<br />
For more information about all available options see {{ic|man 5 exports}}.<br />
<br />
If you modify {{ic|/etc/exports}} while the server is running, you must re-export them for changes to take effect:<br />
# exportfs -rav<br />
<br />
==== Starting the server ====<br />
<br />
Start {{ic|rpc-idmapd.service}} and {{ic|rpc-mountd.service}} [[systemd#Using units|using systemd]]. If you want them running at boot time, enable them. Note that these units require other services, which are launched automatically by [[systemd]].<br />
<br />
==== Firewall configuration ====<br />
<br />
To enable access through a firewall, tcp and udp ports 111, 2049, and 20048 need to be opened. To configure this for [[iptables]], edit {{ic|/etc/iptables/iptables.rules}} to include the following lines:<br />
<br />
{{hc|/etc/iptables/iptables.rules|<nowiki><br />
-A INPUT -p tcp -m tcp --dport 111 -j ACCEPT<br />
-A INPUT -p tcp -m tcp --dport 2049 -j ACCEPT<br />
-A INPUT -p tcp -m tcp --dport 20048 -j ACCEPT<br />
-A INPUT -p udp -m udp --dport 111 -j ACCEPT<br />
-A INPUT -p udp -m udp --dport 2049 -j ACCEPT<br />
-A INPUT -p udp -m udp --dport 20048 -j ACCEPT<br />
</nowiki>}}<br />
<br />
To apply changes, restart {{ic|iptables}} service.<br />
<br />
=== Client ===<br />
<br />
Clients need to start {{ic|rpc-gssd.service}} to avoid an approx 15 seconds delay with an accompanying error in dmsg that reads, "RPC: AUTH_GSS upcall timed out".<br />
<br />
{{Note|The server does not need to run this service.}}<br />
<br />
==== Mounting from Linux ====<br />
<br />
Show the server's exported filesystems:<br />
$ showmount -e servername<br />
<br />
Then mount omitting the server's NFS export root: <br />
# mount -t nfs4 servername:/music /mountpoint/on/client<br />
<br />
{{Note|Server name needs to be a valid hostname (not just IP address). Otherwise mounting of remote share will hang.}}<br />
<br />
===== using /etc/fstab =====<br />
<br />
Using [[fstab]] is useful for a server which is always on, and the NFS shares are available whenever the client boots up. Edit {{ic|/etc/fstab}} file, and add an appropriate line reflecting the setup. Again, the server's NFS export root is omitted.<br />
<br />
{{hc|/etc/fstab|<nowiki><br />
servername:/music /mountpoint/on/client nfs4 rsize=8192,wsize=8192,timeo=14,intr,_netdev 0 0<br />
</nowiki>}}<br />
<br />
{{Note|Consult the NFS and mount man pages for more mount options.}}<br />
<br />
Some additional mount options to consider are include:<br />
<br />
; rsize and wsize: The {{ic|rsize}} value is the number of bytes used when reading from the server. The {{ic|wsize}} value is the number of bytes used when writing to the server. The default for both is 1024, but using higher values such as 8192 can improve throughput. This is not universal. It is recommended to test after making this change, see [[#Performance tuning]].<br />
<br />
; timeo: The {{ic|timeo}} value is the amount of time, in tenths of a second, to wait before resending a transmission after an RPC timeout. After the first timeout, the timeout value is doubled for each retry for a maximum of 60 seconds or until a major timeout occurs. If connecting to a slow server or over a busy network, better performance can be achieved by increasing this timeout value. <br />
<br />
; intr: The {{ic|intr}} option allows signals to interrupt the file operation if a major timeout occurs for a hard-mounted share.<br />
<br />
; _netdev: The {{ic|_netdev}} option tells the system to wait until the network is up before trying to mount the share. systemd assumes this for NFS, but anyway it is good practice to use it for all types of networked filesystems<br />
<br />
{{Note|Setting the sixt field (fs_passno) to a nonzero value may lead to unexpected behaviour, e.g. hangs when the systemd automount waits for a check which will never happen.}}<br />
<br />
===== Using autofs =====<br />
<br />
Using [[autofs]] is useful when multiple machines want to connect via NFS; they could both be clients as well as servers. The reason this method is preferable over the earlier one is that if the server is switched off, the client will not throw errors about being unable to find NFS shares. See [[autofs#NFS network mounts]] for details.<br />
<br />
==== Mounting from Windows ====<br />
<br />
{{Note|Only the Ultimate and Enterprise editions of Windows 7 and the Enterprise edition of Windows 8 include "Client for NFS".}}<br />
NFS shares can be mounted from Windows if the "Client for NFS" service is activated (which it is not by default).<br />
To install the service go to "Programs and features" in the Control Panel and click on "Turn Windows features on or off". Locate "Services for NFS" and activate it as well as both subservices ("Administrative tools" and "Client for NFS").<br />
<br />
Some global options can be set by opening the "Services for Network File System" (locate it with the search box) and right click on ''client > properties''.<br />
<br />
{{Warning|Serious performance issues may occur (it randomly takes 30-60 seconds to display a folder, 2 MB/s file copy speed on gigabit LAN, ...) to which Microsoft does not have a solution yet.[https://social.technet.microsoft.com/Forums/en-CA/w7itpronetworking/thread/40cc01e3-65e4-4bb6-855e-cef1364a60ac]}}<br />
<br />
To mount a share using Explorer:<br />
<br />
{{ic|Computer}} > {{ic|Map network drive}} > {{ic|servername:/srv/nfs4/music}}<br />
<br />
==== Mounting from OS X ====<br />
<br />
{{Note|OS X by default uses an insecure (>1024) port to mount a share.}}<br />
Either export the share with the {{ic|insecure}} flag, and mount using Finder:<br />
<br />
{{ic|Go}} > {{ic|Connect to Server}} > {{ic|nfs://servername/}}<br />
<br />
Or, mount the share using a secure port using the terminal:<br />
# mount -t nfs -o resvport servername:/srv/nfs4 /Volumes/servername<br />
<br />
== Tips and tricks ==<br />
<br />
=== Performance tuning ===<br />
<br />
In order to get the most out of NFS, it is necessary to tune the {{ic|rsize}} and {{ic|wsize}} mount options to meet the requirements of the network configuration.<br />
<br />
=== Automatic mount handling ===<br />
<br />
This trick is useful for laptops that require nfs shares from a local wireless network. If the nfs host becomes unreachable, the nfs share will be unmounted to hopefully prevent system hangs when using the hard mount option. See https://bbs.archlinux.org/viewtopic.php?pid=1260240#p1260240<br />
<br />
Make sure that the NFS mount points are correctly indicated in {{ic|/etc/fstab}}:<br />
<br />
{{hc|$ cat /etc/fstab|<nowiki><br />
lithium:/mnt/data /mnt/data nfs noauto,noatime,rsize=32768,wsize=32768,intr,hard 0 0<br />
lithium:/var/cache/pacman /var/cache/pacman nfs noauto,noatime,rsize=32768,wsize=32768,intr,hard 0 0</nowiki><br />
}}<br />
<br />
The {{ic|noauto}} mount option tells systemd not to automatically mount the shares at boot. systemd would otherwise attempt to mount the nfs shares that may or may not exist on the network causing the boot process to appear to stall on a blank screen.<br />
<br />
In order to mount NFS share by non-root user {{ic|user}} may be required to be added to fstab entry. Also enable rpc-statd.service.<br />
<br />
Create the {{ic|auto_share}} script that will be used by ''cron'' to check if the NFS host is reachable,<br />
<br />
{{hc|/root/bin/auto_share|<nowiki><br />
#!/bin/bash<br />
<br />
SERVER="YOUR_NFS_HOST"<br />
<br />
MOUNT_POINTS=$(sed -e '/^.*#/d' -e '/^.*:/!d' -e 's/\t/ /g' /etc/fstab | tr -s " " | cut -f2 -d" ")<br />
<br />
ping -c 1 "${SERVER}" &>/dev/null<br />
<br />
if [ $? -ne 0 ]; then<br />
# The server could not be reached, unmount the shares<br />
for umntpnt in ${MOUNT_POINTS}; do<br />
umount -l -f $umntpnt &>/dev/null<br />
done<br />
else<br />
# The server is up, make sure the shares are mounted<br />
for mntpnt in ${MOUNT_POINTS}; do<br />
mountpoint -q $mntpnt || mount $mntpnt<br />
done<br />
fi<br />
</nowiki>}}<br />
<br />
# chmod +x /root/bin/auto_share<br />
<br />
Create the root cron entry to run {{ic|auto_share}} every minute:<br />
<br />
{{hc|# crontab -e|<nowiki><br />
* * * * * /root/bin/auto_share<br />
</nowiki>}}<br />
<br />
A systemd unit file can also be used to mount the NFS shares at startup. The unit file is not necessary if NetworkManager is installed and configured on the client system. See [[#NetworkManager dispatcher]].<br />
<br />
{{hc|/etc/systemd/system/auto_share.service|<nowiki><br />
[Unit]<br />
Description=NFS automount<br />
<br />
[Service]<br />
Type=oneshot<br />
RemainAfterExit=yes<br />
ExecStart=/root/bin/auto_share<br />
<br />
[Install]<br />
WantedBy=multi-user.target<br />
</nowiki>}}<br />
<br />
Now enable {{ic|auto_share}}.<br />
<br />
==== NetworkManager dispatcher ====<br />
<br />
In addition to the method described previously, NetworkManager can also be configured to run a script on network status change.<br />
<br />
Enable and start the {{ic|NetworkManager-dispatcher}} service.<br />
<br />
The easiest method for mount shares on network status change is to just symlink to the {{ic|auto_share}} script:<br />
<br />
# ln -s /root/bin/auto_share /etc/NetworkManager/dispatcher.d/30_nfs.sh<br />
<br />
Or use the following mounting script that checks for network availability:<br />
<br />
{{hc|/etc/NetworkManager/dispatcher.d/30_nfs.sh|<nowiki><br />
#!/bin/bash<br />
<br />
SSID="CHANGE_ME"<br />
<br />
MOUNT_POINTS=$(sed -e '/^.*#/d' -e '/^.*:/!d' -e 's/\t/ /g' /etc/fstab | tr -s " " | cut -f2 -d" ")<br />
<br />
ISNETUP=$(nmcli dev wifi | \grep $SSID | tr -s ' ' | cut -f 10 -d ' ') 2>/dev/null<br />
<br />
# echo "$ISNETUP" >> /tmp/nm_dispatch_log<br />
<br />
if [[ "$ISNETUP" == "yes" ]]; then<br />
for mntpnt in ${MOUNT_POINTS}; do<br />
mountpoint -q $mntpnt || mount $mntpnt<br />
done<br />
else<br />
for srvexp in ${MOUNT_POINTS}; do<br />
umount -l -f $srvexp &>/dev/null<br />
done<br />
fi<br />
</nowiki>}}<br />
<br />
Now when the wireless SSID "CHANGE_ME" goes up or down, the {{ic|nfs.sh}} script will be called to mount or unmount the shares as soon as possible.<br />
<br />
=== Configure NFS fixed ports ===<br />
<br />
{{Out of date|This section was originally refered to NFS version 3.}}<br />
If you have a port-based [[firewall]], you might want to set up a fixed ports. For rpc.statd and rpc.mountd you should set following settings in {{ic|/etc/conf.d/nfs-common}} and {{ic|/etc/conf.d/nfs-server}} (ports can be different):<br />
<br />
{{hc|/etc/conf.d/nfs-common|2=STATD_OPTS="-p 4000 -o 4003"}}<br />
{{hc|/etc/conf.d/nfs-server|2=MOUNTD_OPTS="--no-nfs-version 2 -p 4002"}}<br />
{{hc|/etc/modprobe.d/lockd.conf|2=# Static ports for NFS lockd<br />
options lockd nlm_udpport=4001 nlm_tcpport=4001}}<br />
<br />
After restart {{ic|nfs-common}} {{ic|nfs-server}} daemons and reload {{ic|lockd}} modules you can check used ports with following command:<br />
{{hc|$ rpcinfo -p|<br />
program vers proto port service<br />
100000 4 tcp 111 portmapper<br />
100000 3 tcp 111 portmapper<br />
100000 2 tcp 111 portmapper<br />
100000 4 udp 111 portmapper<br />
100000 3 udp 111 portmapper<br />
100000 2 udp 111 portmapper<br />
100024 1 udp 4000 status<br />
100024 1 tcp 4000 status<br />
100021 1 udp 4001 nlockmgr<br />
100021 3 udp 4001 nlockmgr<br />
100021 4 udp 4001 nlockmgr<br />
100021 1 tcp 4001 nlockmgr<br />
100021 3 tcp 4001 nlockmgr<br />
100021 4 tcp 4001 nlockmgr<br />
100003 2 tcp 2049 nfs<br />
100003 3 tcp 2049 nfs<br />
100003 4 tcp 2049 nfs<br />
100003 2 udp 2049 nfs<br />
100003 3 udp 2049 nfs<br />
100003 4 udp 2049 nfs<br />
100005 3 udp 4002 mountd<br />
100005 3 tcp 4002 mountd<br />
}}<br />
<br />
Then, you need to open the ports 111-2049-4000-4001-4002-4003 TCP and UDP.<br />
<br />
== Troubleshooting ==<br />
<br />
There is a dedicated article [[NFS Troubleshooting]].<br />
<br />
== See also ==<br />
<br />
* See also [[Avahi]], a Zeroconf implementation which allows automatic discovery of NFS shares.<br />
* HOWTO: [[Diskless network boot NFS root]]<br />
* [http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?topic=/com.ibm.aix.prftungd/doc/prftungd/nfs_perf.htm NFS Performance Management]<br />
* If you are setting up the Arch Linux NFS server for use by Windows clients through Microsoft's SFU, you will save a lot of time and hair-scratching by looking at [https://bbs.archlinux.org/viewtopic.php?pid=523934#p523934 this forum post] first !<br />
* [http://blogs.msdn.com/sfu/archive/2008/04/14/all-well-almost-about-client-for-nfs-configuration-and-performance.aspx Microsoft Services for Unix NFS Client info]<br />
* [http://blogs.msdn.com/sfu/archive/2007/05/01/unix-interoperability-and-windows-vista.aspx Unix interoperability and Windows Vista] Prerequisites to connect to NFS with Vista</div>Freejackhttps://wiki.archlinux.org/index.php?title=Create_root_filesystem_snapshots_with_LVM&diff=255793Create root filesystem snapshots with LVM2013-05-01T07:38:11Z<p>Freejack: /* Setup */ markup</p>
<hr />
<div>[[Category:System recovery]]<br />
{{Article summary start}}<br />
{{Article summary text|Setup root filesystem LVM snapshot creation during system start.<br />
Such snapshots can be used for [[Full System Backup with tar|full system backups]]<br />
with minimal downtime or testing system updates with the option to revert<br />
them.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary text|{{pkg|lvm2}}, {{pkg|systemd}}}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|LVM}}<br />
{{Article summary wiki|Full System Backup with tar}}<br />
{{Article summary end}}<br />
<br />
<br />
== Prerequisites ==<br />
<br />
You need a system with [[LVM]] root filesystem and [[systemd]].<br />
Ensure that [[Lvm#Snapshots|LVM snapshots]] prerequisites are correctly setup.<br />
<br />
== Setup ==<br />
<br />
During system start a clean snapshot of the root volume is<br />
created using a new systemd service. Create<br />
{{ic|/etc/systemd/system/mk-lvm-snapshots.service}} containing:<br />
{{bc|[Unit]<br />
Description&#61;make LVM snapshots<br />
Requires&#61;local-fs-pre.target<br />
DefaultDependencies&#61;no<br />
Conflicts&#61;shutdown.target<br />
After&#61;local-fs-pre.target<br />
Before&#61;local-fs.target<br />
<br />
[Install]<br />
WantedBy&#61;make-snapshots.target<br />
<br />
[Service]<br />
Type&#61;oneshot<br />
ExecStart&#61;/usr/sbin/lvcreate -L10G -n snap-root -s lvmvolume/root}}<br />
<br />
Adapt the {{ic|lvcreate}} command to match your root volume group and volume name.<br />
Adjust the snapshot size if necessary. If additional filesystems should be snapshotted<br />
during startup you may extend the {{ic|ExecStart}} property with addtional lvcreate commands,<br />
separated with {{ic| ; }}.<br />
<br />
{{Note|You should test the {{ic|# lvcreate}} command in the running system until it works as desired.<br />
Remove the test snapshots with {{ic|# lvremove}}. The snapshots taken from a running system are<br />
not as consistent as snapshots taken in single user mode or during startup.}}<br />
<br />
Create a new systemd target {{ic|/etc/systemd/system/make-snapshots.target}}:<br />
{{bc|[Unit]<br />
Description&#61;Make Snapshots<br />
Requires&#61;multi-user.target}}<br />
Adapt the base target, if {{ic|multi-user.target}} is not your default target.<br />
<br />
Enable the new service with {{ic|# systemctl enable mk-lvm-snapshots.service}}.<br />
<br />
If the system is started with the new target, LVM snapshot(s) are created just after mounting the local filesystems.<br />
To get a [[grub]] menu entry starting this target create {{ic|/boot/grub/custom.cfg}} based on the<br />
{{ic|grub.cfg}} entry for your normal startup. The kernel command line is extended to start the new<br />
{{ic|make-snapshots.target}}:<br />
{{bc|### make snapshots ###<br />
menuentry 'Arch GNU/Linux, make snapshots' --class arch --class gnu-linux --class gnu --class os {<br />
...<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root&#61;/dev/mapper/lvmvolume-root ro '''systemd.unit&#61;make-snapshots.target'''<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
} }}<br />
<br />
Remember to adjust {{ic|custom.cfg}} if {{ic|grub.cfg}} changes.<br />
<br />
After restarting the system with this grub entry {{ic|# lvs}} should show up the newly created snapshot.<br />
<br />
{{Tip|To get the messages of the new service use<br />
{{ic|# journalctl -u mk-lvm-snapshots.service}}.}}<br />
<br />
== Usage ==<br />
<br />
=== Backup ===<br />
To use this functionality for a full system backup, restart your system with the snapshot creation target.<br />
Mount the snapshot volume (and further volumes, if required), preferably using the read only (<tt>-o</tt>) option.<br />
Then backup your system, for example with tar as described in [[Full_System_Backup_with_tar]].<br />
<br />
During backup you can continue to use your system normally, since all changes to your regular volumes are invisible in<br />
the snapshots. Do not forget to delete the snapshot volume after the backup &ndash; changes to your regular volume will<br />
use up space in the snapshot due to the copy-on-write operations. If the snapshot space becomes fully used, and LVM<br />
is not able to automatically grow the snapshot, LVM will deny further writes to your regular volumes or drop the<br />
snapshot, which should be avoided.<br />
<br />
=== Revert updates ===<br />
An other use for LVM snapshots is testing and reverting of updates. In this case create a snapshot for the system<br />
in a known good state and perform updates or changes afterwards.<br />
<br />
If you want to permantly stick to the updates just drop the snapshot with {{ic|# lvremove}}. If you want to revert to the snapshotted<br />
state issue a {{ic|# lvchange --merge}} for the snapshot. During the next restart of the system (use the default target) the snapshot<br />
is merged back into your regular volume. All changes to the volume happened after the snapshot are undone.<br />
{{Note|After merging the snapshot no longer exists. Recreate a new snapshot if further testing with rollback<br />
option is desired.}}<br />
<br />
== Known issues ==<br />
Due to [https://bugzilla.redhat.com/show_bug.cgi?id=681582 bug 681582] shutting down the system with active<br />
snapshots may hang for some time (currently 1...3 minutes). As a workaround a shorter job timeout can be set.<br />
Create a copy of {{ic|/usr/lib/systemd/system/dmeventd.service}} in {{ic|/etc/systemd/system}} and insert<br />
{{ic|JobTimeoutSec&#61;10}}:<br />
{{bc|[Unit]<br />
Description&#61;Device-mapper event daemon<br />
Documentation&#61;man:dmeventd(8)<br />
Requires&#61;dmeventd.socket<br />
After&#61;dmeventd.socket<br />
DefaultDependencies&#61;no<br />
'''JobTimeoutSec&#61;10'''<br />
<br />
[Service]<br />
Type&#61;forking<br />
ExecStart&#61;/usr/sbin/dmeventd<br />
ExecReload&#61;/usr/sbin/dmeventd -R<br />
Environment&#61;SD_ACTIVATION&#61;1<br />
PIDFile&#61;/run/dmeventd.pid<br />
OOMScoreAdjust&#61;-1000}}</div>Freejackhttps://wiki.archlinux.org/index.php?title=Create_root_filesystem_snapshots_with_LVM&diff=255792Create root filesystem snapshots with LVM2013-05-01T07:37:00Z<p>Freejack: /* Known issues */ dmeventd timeout</p>
<hr />
<div>[[Category:System recovery]]<br />
{{Article summary start}}<br />
{{Article summary text|Setup root filesystem LVM snapshot creation during system start.<br />
Such snapshots can be used for [[Full System Backup with tar|full system backups]]<br />
with minimal downtime or testing system updates with the option to revert<br />
them.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary text|{{pkg|lvm2}}, {{pkg|systemd}}}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|LVM}}<br />
{{Article summary wiki|Full System Backup with tar}}<br />
{{Article summary end}}<br />
<br />
<br />
== Prerequisites ==<br />
<br />
You need a system with [[LVM]] root filesystem and [[systemd]].<br />
Ensure that [[Lvm#Snapshots|LVM snapshots]] prerequisites are correctly setup.<br />
<br />
== Setup ==<br />
<br />
During system start a clean snapshot of the root volume is<br />
created using a new systemd service. Create<br />
{{ic|/etc/systemd/system/mk-lvm-snapshots.service}} containing:<br />
{{bc|[Unit]<br />
Description&#61;make LVM snapshots<br />
Requires&#61;local-fs-pre.target<br />
DefaultDependencies&#61;no<br />
Conflicts&#61;shutdown.target<br />
After&#61;local-fs-pre.target<br />
Before&#61;local-fs.target<br />
<br />
[Install]<br />
WantedBy&#61;make-snapshots.target<br />
<br />
[Service]<br />
Type&#61;oneshot<br />
ExecStart&#61;/usr/sbin/lvcreate -L10G -n snap-root -s lvmvolume/root}}<br />
<br />
Adapt the {{ic|lvcreate}} command to match your root volume group and volume name.<br />
Adjust the snapshot size if necessary. If additional filesystems should be snapshotted<br />
during startup you may extend the {{ic|ExecStart}} property with addtional lvcreate commands,<br />
separated with {{ic| ; }}.<br />
<br />
{{Note|You should test the {{ic|# lvcreate}} command in the running system until it works as desired.<br />
Remove the test snapshots with {{ic|# lvremove}}. The snapshots taken from a running system are<br />
not as consistent as snapshots taken in single user mode or during startup.}}<br />
<br />
Create a new systemd target {{ic|/etc/systemd/system/make-snapshots.target}}:<br />
{{bc|[Unit]<br />
Description&#61;Make Snapshots<br />
Requires&#61;multi-user.target}}<br />
Adapt the base target, if {{ic|multi-user.target}} is not your default target.<br />
<br />
Enable the new service with {{ic|# systemctl enable mk-lvm-snapshots.service}}.<br />
<br />
If the system is started with the new target, LVM snapshot(s) are created just after mounting the local filesystems.<br />
To get a [[grub]] menu entry starting this target create {{ic|/boot/grub/custom.cfg}} based on the<br />
{{ic|grub.cfg}} entry for your normal startup. The kernel command line is extended to start the new<br />
{{ic|make-snapshots.target}}:<br />
{{bc|### make snapshots ###<br />
menuentry 'Arch GNU/Linux, make snapshots' --class arch --class gnu-linux --class gnu --class os {<br />
...<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root&#61;/dev/mapper/lvmvolume-root ro systemd.unit&#61;make-snapshots.target<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
} }}<br />
<br />
Remember to adjust {{ic|custom.cfg}} if {{ic|grub.cfg}} changes.<br />
<br />
After restarting the system with this grub entry {{ic|# lvs}} should show up the newly created snapshot.<br />
<br />
{{Tip|To get the messages of the new service use<br />
{{ic|# journalctl -u mk-lvm-snapshots.service}}.}}<br />
<br />
== Usage ==<br />
<br />
=== Backup ===<br />
To use this functionality for a full system backup, restart your system with the snapshot creation target.<br />
Mount the snapshot volume (and further volumes, if required), preferably using the read only (<tt>-o</tt>) option.<br />
Then backup your system, for example with tar as described in [[Full_System_Backup_with_tar]].<br />
<br />
During backup you can continue to use your system normally, since all changes to your regular volumes are invisible in<br />
the snapshots. Do not forget to delete the snapshot volume after the backup &ndash; changes to your regular volume will<br />
use up space in the snapshot due to the copy-on-write operations. If the snapshot space becomes fully used, and LVM<br />
is not able to automatically grow the snapshot, LVM will deny further writes to your regular volumes or drop the<br />
snapshot, which should be avoided.<br />
<br />
=== Revert updates ===<br />
An other use for LVM snapshots is testing and reverting of updates. In this case create a snapshot for the system<br />
in a known good state and perform updates or changes afterwards.<br />
<br />
If you want to permantly stick to the updates just drop the snapshot with {{ic|# lvremove}}. If you want to revert to the snapshotted<br />
state issue a {{ic|# lvchange --merge}} for the snapshot. During the next restart of the system (use the default target) the snapshot<br />
is merged back into your regular volume. All changes to the volume happened after the snapshot are undone.<br />
{{Note|After merging the snapshot no longer exists. Recreate a new snapshot if further testing with rollback<br />
option is desired.}}<br />
<br />
== Known issues ==<br />
Due to [https://bugzilla.redhat.com/show_bug.cgi?id=681582 bug 681582] shutting down the system with active<br />
snapshots may hang for some time (currently 1...3 minutes). As a workaround a shorter job timeout can be set.<br />
Create a copy of {{ic|/usr/lib/systemd/system/dmeventd.service}} in {{ic|/etc/systemd/system}} and insert<br />
{{ic|JobTimeoutSec&#61;10}}:<br />
{{bc|[Unit]<br />
Description&#61;Device-mapper event daemon<br />
Documentation&#61;man:dmeventd(8)<br />
Requires&#61;dmeventd.socket<br />
After&#61;dmeventd.socket<br />
DefaultDependencies&#61;no<br />
'''JobTimeoutSec&#61;10'''<br />
<br />
[Service]<br />
Type&#61;forking<br />
ExecStart&#61;/usr/sbin/dmeventd<br />
ExecReload&#61;/usr/sbin/dmeventd -R<br />
Environment&#61;SD_ACTIVATION&#61;1<br />
PIDFile&#61;/run/dmeventd.pid<br />
OOMScoreAdjust&#61;-1000}}</div>Freejackhttps://wiki.archlinux.org/index.php?title=User:Freejack/Create_LVM_Snapshots_for_Full_System_Backup&diff=255745User:Freejack/Create LVM Snapshots for Full System Backup2013-04-30T16:04:44Z<p>Freejack: Redirected page to Create root filesystem snapshots with LVM</p>
<hr />
<div>#REDIRECT [[Create root filesystem snapshots with LVM]]</div>Freejackhttps://wiki.archlinux.org/index.php?title=Create_root_filesystem_snapshots_with_LVM&diff=255382Create root filesystem snapshots with LVM2013-04-27T18:13:10Z<p>Freejack: /* Revert updates */ clarify start target for snp merge</p>
<hr />
<div>[[Category:System recovery]]<br />
{{Article summary start}}<br />
{{Article summary text|Setup root filesystem LVM snapshot creation during system start.<br />
Such snapshots can be used for [[Full System Backup with tar|full system backups]]<br />
with minimal downtime or testing system updates with the option to revert<br />
them.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary text|{{pkg|lvm2}}, {{pkg|systemd}}}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|LVM}}<br />
{{Article summary wiki|Full System Backup with tar}}<br />
{{Article summary end}}<br />
<br />
<br />
== Prerequisites ==<br />
<br />
You need a system with [[LVM]] root filesystem and [[systemd]].<br />
Ensure that [[Lvm#Snapshots|LVM snapshots]] prerequisites are correctly setup.<br />
<br />
== Setup ==<br />
<br />
During system start a clean snapshot of the root volume is<br />
created using a new systemd service. Create<br />
{{ic|/etc/systemd/system/mk-lvm-snapshots.service}} containing:<br />
{{bc|[Unit]<br />
Description&#61;make LVM snapshots<br />
Requires&#61;local-fs-pre.target<br />
DefaultDependencies&#61;no<br />
Conflicts&#61;shutdown.target<br />
After&#61;local-fs-pre.target<br />
Before&#61;local-fs.target<br />
<br />
[Install]<br />
WantedBy&#61;make-snapshots.target<br />
<br />
[Service]<br />
Type&#61;oneshot<br />
ExecStart&#61;/usr/sbin/lvcreate -L10G -n snap-root -s lvmvolume/root}}<br />
<br />
Adapt the {{ic|lvcreate}} command to match your root volume group and volume name.<br />
Adjust the snapshot size if necessary. If additional filesystems should be snapshotted<br />
during startup you may extend the {{ic|ExecStart}} property with addtional lvcreate commands,<br />
separated with {{ic| ; }}.<br />
<br />
{{Note|You should test the {{ic|# lvcreate}} command in the running system until it works as desired.<br />
Remove the test snapshots with {{ic|# lvremove}}. The snapshots taken from a running system are<br />
not as consistent as snapshots taken in single user mode or during startup.}}<br />
<br />
Create a new systemd target {{ic|/etc/systemd/system/make-snapshots.target}}:<br />
{{bc|[Unit]<br />
Description&#61;Make Snapshots<br />
Requires&#61;multi-user.target}}<br />
Adapt the base target, if {{ic|multi-user.target}} is not your default target.<br />
<br />
Enable the new service with {{ic|# systemctl enable mk-lvm-snapshots.service}}.<br />
<br />
If the system is started with the new target, LVM snapshot(s) are created just after mounting the local filesystems.<br />
To get a [[grub]] menu entry starting this target create {{ic|/boot/grub/custom.cfg}} based on the<br />
{{ic|grub.cfg}} entry for your normal startup. The kernel command line is extended to start the new<br />
{{ic|make-snapshots.target}}:<br />
{{bc|### make snapshots ###<br />
menuentry 'Arch GNU/Linux, make snapshots' --class arch --class gnu-linux --class gnu --class os {<br />
...<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root&#61;/dev/mapper/lvmvolume-root ro systemd.unit&#61;make-snapshots.target<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
} }}<br />
<br />
Remember to adjust {{ic|custom.cfg}} if {{ic|grub.cfg}} changes.<br />
<br />
After restarting the system with this grub entry {{ic|# lvs}} should show up the newly created snapshot.<br />
<br />
{{Tip|To get the messages of the new service use<br />
{{ic|# journalctl -u mk-lvm-snapshots.service}}.}}<br />
<br />
== Usage ==<br />
<br />
=== Backup ===<br />
To use this functionality for a full system backup, restart your system with the snapshot creation target.<br />
Mount the snapshot volume (and further volumes, if required), preferably using the read only (<tt>-o</tt>) option.<br />
Then backup your system, for example with tar as described in [[Full_System_Backup_with_tar]].<br />
<br />
During backup you can continue to use your system normally, since all changes to your regular volumes are invisible in<br />
the snapshots. Do not forget to delete the snapshot volume after the backup &ndash; changes to your regular volume will<br />
use up space in the snapshot due to the copy-on-write operations. If the snapshot space becomes fully used, and LVM<br />
is not able to automatically grow the snapshot, LVM will deny further writes to your regular volumes or drop the<br />
snapshot, which should be avoided.<br />
<br />
=== Revert updates ===<br />
An other use for LVM snapshots is testing and reverting of updates. In this case create a snapshot for the system<br />
in a known good state and perform updates or changes afterwards.<br />
<br />
If you want to permantly stick to the updates just drop the snapshot with {{ic|# lvremove}}. If you want to revert to the snapshotted<br />
state issue a {{ic|# lvchange --merge}} for the snapshot. During the next restart of the system (use the default target) the snapshot<br />
is merged back into your regular volume. All changes to the volume happened after the snapshot are undone.<br />
{{Note|After merging the snapshot no longer exists. Recreate a new snapshot if further testing with rollback<br />
option is desired.}}<br />
<br />
== Known issues ==<br />
Due to [https://bugzilla.redhat.com/show_bug.cgi?id=681582 bug 681582] shutting down the system with active<br />
snapshots may hang for some time (currently 1...3 minutes).</div>Freejackhttps://wiki.archlinux.org/index.php?title=Full_system_backup_with_tar&diff=255380Full system backup with tar2013-04-27T18:04:12Z<p>Freejack: /* Overview */ link to LVM Snapshots</p>
<hr />
<div>[[Category:System recovery]]<br />
This article will show you how to do a full system backup with tar.<br />
<br />
== Overview ==<br />
<br />
Backing up with tar has the advantages of using compression that can help save disk space, and simplicity. The process only requires several steps, they are:<br />
<br />
# Boot from a LiveCD<br />
# Change root to the Linux install<br />
# Mount additional (if any) partitions/drives<br />
# Add exclusions<br />
# Use the backup script to backup<br />
<br />
To minimize downtime the backup can alternatively be performed on a running system using [[Lvm#Snapshots|LVM snapshots]],<br />
if all filesystems reside on LVM volumes.<br />
<br />
== Boot with LiveCD ==<br />
<br />
Many Linux bootable CDs, USBs... have the ability to let you change root to your install. While changing root isn't necessary to do a backup, it provides the ability to just run the script without need to transfer it to a temporary drive or having to locate it on the filesystem. The Live medium must be of the same architecture that your Linux install currently is (i.e. i686 or x86_64).<br />
<br />
== Changing Root ==<br />
<br />
First you should have a scripting environment set up on your current Linux install. If you do not know what that is, it means that you are able to execute any scripts that you may have as if they are regular programs. If you do not, see this [http://linuxtidbits.wordpress.com/2009/12/03/setting-up-a-scripting-environment/ article] on how to do that. What you'll need to do next is change root, to learn more about what changing root is, read [[Change Root|this]]. When you change root, you do not need to mount any temporary file systems (<tt>/proc</tt>, <tt>/sys</tt>, and <tt>/dev</tt>). These temporary file systems get populated on boot and you actually do not want to backup them up because they can interfere with the normal (and necessary) population process which can change on any upgrade. To change root, you'll need to mount your current Linux installs root partition. For example:<br />
<br />
mkdir /mnt/arch<br />
mount /dev/<your-partition-or-drive><br />
<br />
Use {{Ic|fdisk -l}} to discover you partitions and drives. Now {{Ic|chroot}}:<br />
<br />
cd /mnt/arch<br />
chroot . /bin/bash<br />
<br />
This example obviously uses bash but you can use other shells if available. Now you will be in your scripted environment (this is provided that you have your {{ic|~/.bashrc}} sourced on entry):<br />
<br />
<pre><br />
cat ~/.bash_profile<br />
# If using bash, source the local .bashrc<br />
source ~/.bashrc<br />
</pre><br />
<br />
== Mount Other Partitions ==<br />
<br />
Other partitions that you use (if any) will need to be mounted in their proper places (e.g. if you have a separate <tt>/home</tt> partition).<br />
<br />
== Exclude File ==<br />
<br />
{{Ic|tar}} has the ability to ignore specified files and directories. The syntax is one definition per line. {{Ic|tar}} also has the capability to understand regular expressions (regexps). For example:<br />
<br />
<pre><br />
# Not old backups <br />
/opt/backup/arch-full* <br />
<br />
# Not temporary files <br />
/tmp/*<br />
<br />
# Not the cache for pacman<br />
/var/cache/pacman/pkg/<br />
...<br />
</pre><br />
<br />
== Backup Script ==<br />
<br />
Backing up with tar is straight-forward process. Here is a basic script that can do it and provides a couple checks. You'll need to modify this script to define your backup location, and exclude file (if you have one), and then just run this command after you've {{Ic|chroot}}ed and mounted all your partitions.<br />
<br />
<pre><br />
#!/bin/bash<br />
# full system backup<br />
<br />
# Backup destination<br />
backdest=/opt/backup<br />
<br />
# Labels for backup name<br />
#PC=${HOSTNAME}<br />
pc=pavilion<br />
distro=arch<br />
type=full<br />
date=$(date "+%F")<br />
backupfile="$backdest/$distro-$type-$date.tar.gz"<br />
<br />
# Exclude file location<br />
prog=${0##*/} # Program name from filename<br />
excdir="/home/<user>/.bin/root/backup"<br />
exclude_file="$excdir/$prog-exc.txt"<br />
<br />
# Check if chrooted prompt.<br />
echo -n "First chroot from a LiveCD. Are you ready to backup? (y/n): "<br />
read executeback<br />
<br />
# Check if exclude file exists<br />
if [ ! -f $exclude_file ]; then<br />
echo -n "No exclude file exists, continue? (y/n): "<br />
read continue<br />
if [ $continue == "n" ]; then exit; fi<br />
fi<br />
<br />
if [ $executeback = "y" ]; then<br />
tar --exclude-from=$exclude_file -czpvf $backupfile /<br />
fi<br />
</pre></div>Freejackhttps://wiki.archlinux.org/index.php?title=LVM&diff=255378LVM2013-04-27T17:50:51Z<p>Freejack: /* Configuration */ link to root fs LVM snapshot article</p>
<hr />
<div>[[Category:Getting and installing Arch]]<br />
[[Category:File systems]]<br />
[[cs:LVM]]<br />
[[de:LVM]]<br />
[[es:LVM]]<br />
[[fr:LVM]]<br />
[[it:LVM]]<br />
[[ru:LVM]]<br />
[[tr:LVM]]<br />
[[zh-CN:LVM]]<br />
{{Article summary start}}<br />
{{Article summary text|This article will provide an example of how to install and configure Arch Linux with Logical Volume Manager (LVM).}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary text|{{pkg|lvm2}}}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|Software RAID and LVM}}<br />
{{Article summary wiki|System Encryption with LUKS}}<br />
{{Article summary wiki|Encrypted LVM}}<br />
{{Article summary end}}<br />
<br />
==Introduction==<br />
{{Wikipedia|Logical Volume Manager (Linux)}}<br />
===LVM Building Blocks===<br />
Logical Volume Management makes use of the [http://sources.redhat.com/dm/ device-mapper] feature of the Linux kernel to provide a system of partitions that is independent of the underlying disk's layout. With LVM you can abstract your storage space and have "virtual partitions" which makes it easier to extend and shrink partitions (subject to the filesystem you use allowing this) and add/remove partitions without worrying about whether you have enough contiguous space on a particular disk, without getting caught up in the problems of fdisking a disk that is in use (and wondering whether the kernel is using the old or new partition table) and without having to move other partition out of the way. This is strictly an ease-of-management issue: it does not provide any additional security. However, it sits nicely with the other two technologies we are using.<br />
<br />
The basic building blocks of LVM are:<br />
<br />
* '''Physical volume (PV)''': Partition on hard disk (or even hard disk itself or loopback file) on which you can have volume groups. It has a special header and is divided into physical extents. Think of physical volumes as big building blocks which can be used to build your hard drive.<br />
* '''Volume group (VG)''': Group of physical volumes that are used as storage volume (as one disk). They contain logical volumes. Think of volume groups as hard drives.<br />
* '''Logical volume (LV)''': A "virtual/logical partition" that resides in a volume group and is composed of physical extents. Think of logical volumes as normal partitions.<br />
* '''Physical extent (PE)''': A small part of a disk (usually 4MB) that can be assigned to a logical Volume. Think of physical extents as parts of disks that can be allocated to any partition.<br />
<br />
Example: <br />
'''Physical disks'''<br />
<br />
Disk1 (/dev/sda):<br />
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _<br />
|Partition1 50GB (Physical volume) |Partition2 80GB (Physical volume) |<br />
|/dev/sda1 |/dev/sda2 |<br />
|_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |<br />
<br />
Disk2 (/dev/sdb):<br />
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _<br />
|Partition1 120GB (Physical volume) |<br />
|/dev/sdb1 |<br />
| _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ __ _ _|<br />
<br />
'''LVM logical volumes'''<br />
<br />
Volume Group1 (/dev/MyStorage/ = /dev/sda1 + /dev/sda2 + /dev/sdb1):<br />
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ <br />
|Logical volume1 15GB |Logical volume2 35GB |Logical volume3 200GB |<br />
|/dev/MyStorage/rootvol|/dev/MyStorage/homevol |/dev/MyStorage/mediavol |<br />
|_ _ _ _ _ _ _ _ _ _ _ |_ _ _ _ _ _ _ _ _ _ _ _ _ |_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |<br />
<br />
<br />
===Advantages===<br />
<br />
LVM gives you more flexibility than just using normal hard drive partitions:<br />
* Use any number of disks as one big disk.<br />
* Have logical volumes stretched over several disks.<br />
* Create small logical volumes and resize them "dynamically" as they get more filled.<br />
* Resize logical volumes regardless of their order on disk. It does not depend on the position of the LV within VG, there is no need to ensure surrounding available space.<br />
* Resize/create/delete logical and physical volumes online. Filesystems on them still need to be resized, but some support online resizing.<br />
* Online/live migration of LV being used by services to different disks without having to restart services.<br />
* Snapshots allow you to backup a frozen copy of the filesystem, while keeping service downtime to a minimum.<br />
<br />
These can be very helpful in a server situation, desktop less so, but you must decide if the features are worth the abstraction.<br />
<br />
===Disadvantages===<br />
<br />
* Linux exclusive (almost). There is no official support in most other OS (FreeBSD, Windows..).<br />
* Additional steps in setting up the system, more complicated.<br />
* If you use the [[btrfs]] filesystem, its Subvolume feature will also give you the benefit of having a flexible layout. In that case, using the additional Abstraction layer of LVM may be unnecessary.<br />
<br />
==Installing Arch Linux on LVM==<br />
You should create your LVM Volumes between the [[Partitioning]] and [[File_Systems#Step_2:_create_the_new_file_system|mkfs]] steps of the Installation Procedure. Instead of directly formating a partition to be you root file file-system, it will be created inside a logical volume (LV). <br />
<br />
Quick overview: <br />
* Create partition(s) where your PV will reside. Set the partition type to 'Linux LVM', which is 8e if you use MBR, 8e00 for GPT.<br />
* Create your physical volumes (PV). If you have one disk it is best to just create one PV in one large partition. If you have multiple disks you can create partitions on each of them and create a PV on each partition.<br />
* Create your volume group (VG) and add all the PV to it.<br />
* Create logical volumes (LV) inside your VG.<br />
* Continue with “Format the partitions” step of Beginners Guide.<br />
* When you reach the “Create initial ramdisk environment” step in the Beginners Guide, add the lvm hook to mkinitcpio.conf (see below for details).<br />
<br />
{{Warning|/boot cannot reside in LVM when using [[GRUB Legacy]], which does not support LVM. [[GRUB]] users do not have this limitation. If you need to use GRUB Legacy, you must create a separate /boot partition and format it directly. }}<br />
<br />
===Create physical volumes===<br />
Make sure you target the right partitions! To find the partitions with type 'Linux LVM':<br />
* MBR system: {{Ic|fdisk -l}}<br />
* GPT system: {{Ic|lsblk}} and then {{Ic|gdisk -l <disk-device>}}<br />
<br />
Create a physical volume on them:<br />
# pvcreate <disk-device> (e.g.: pvcreate /dev/sda2)<br />
This command creates a header on each partition so it can be used for LVM.<br />
You can track created physical volumes with:<br />
# pvdisplay<br />
<br />
{{Note|If using a SSD use {{ic|pvcreate --dataalignment 1m /dev/sda2}} (for erase block size < 1MiB), see e.g. [http://serverfault.com/questions/356534/ssd-erase-block-size-lvm-pv-on-raw-device-alignment here]}}<br />
<br />
===Create volume group===<br />
Next step is to create a volume group on this physical volume. First you need to create a volume group on one of the new partitions and then add to it all other physical volumes you want to have in it:<br />
# vgcreate VolGroup00 /dev/sda2<br />
# vgextend VolGroup00 /dev/sdb1<br />
Also you can use any other name you like instead of VolGroup00 for a volume group when creating it. You can track how your volume group grows with:<br />
# vgdisplay<br />
<br />
{{Note|You can create more than one volume group if you need to, but then you will not have all your storage presented as one disk.}}<br />
<br />
===Create logical volumes===<br />
Now we need to create logical volumes on this volume group. You create a logical volume with the next command by giving the name of a new logical volume, its size, and the volume group it will live on:<br />
# lvcreate -L 10G VolGroup00 -n lvolhome<br />
This will create a logical volume that you can access later with {{ic|/dev/mapper/Volgroup00-lvolhome}} or {{ic|/dev/VolGroup00/lvolhome}}. Same as with the volume groups, you can use any name you want for your logical volume when creating it.<br />
<br />
To create swap on a logical volume, an additional argument is needed:<br />
# lvcreate -C y -L 10G VolGroup00 -n lvolswap<br />
The {{Ic|-C y}} is used to create a contiguous partition, which means that your swap space does not get partitioned over one or more disks nor over non-contiguous physical extents.<br />
<br />
If you want to fill all the free space left on a volume group, use the next command:<br />
# lvcreate -l +100%FREE VolGroup00 -n lvolmedia<br />
<br />
You can track created logical volumes with:<br />
# lvdisplay<br />
<br />
{{Note|You may need to load the ''device-mapper'' kernel module ('''modprobe dm-mod''') for the above commands to succeed:}}<br />
<br />
{{Tip|You can start out with relatively small logical volumes and expand them later if needed. For simplicity, leave some free space in the volume group so there is room for expansion.}}<br />
<br />
===Create filesystems and mount logical volumes===<br />
Your logical volumes should now be located in {{ic|/dev/mapper/}} and {{ic|/dev/YourVolumeGroupName}}. If you cannot find them, use the next commands to bring up the module for creating device nodes and to make volume groups available:<br />
# modprobe dm-mod<br />
# vgscan<br />
# vgchange -ay<br />
Now you can create filesystems on logical volumes and mount them as normal partitions (if you are installing Arch linux, refer to [[Beginners' Guide#Mount the partitions|mounting the partitions]] for additional details):<br />
# mkfs.ext4 /dev/mapper/VolGroup00-lvolhome<br />
# mount /dev/mapper/VolGroup00-lvolhome /home<br />
<br />
{{Warning|When choosing mountpoints, just select your newly created logical volumes (use: {{ic|/dev/mapper/Volgroup00-lvolhome}}). Do NOT select the actual partitions on which logical volumes were created (do not use: {{ic|/dev/sda2}}).}}<br />
<br />
=== Add lvm hook to mkinitcpio.conf ===<br />
<br />
You'll need to make sure the {{Ic|udev}} and {{Ic|lvm2}} [[mkinitcpio]] hooks are enabled.<br />
<br />
{{Ic|udev}} is there by default. Edit the file and insert {{Ic|lvm2}} between {{Ic|block}} and {{Ic|filesystem}} like so:<br />
<br />
{{hc|/etc/mkinitcpio.conf:|<nowiki>HOOKS="base udev ... block lvm2 filesystems"</nowiki>}}<br />
<br />
Afterwards, you can continue in normal installation instructions with the [[Mkinitcpio#Image_creation_and_activation|create an initial ramdisk]] step.<br />
<br />
== Configuration ==<br />
=== Advanced options ===<br />
If you need monitoring (needed for snapshots) you can enable lvmetad. <br />
For this set {{ic|1=use_lvmetad = 1}} in {{ic|/etc/lvm/lvm.conf}}.<br />
This is the default by now. <br />
<br />
You can restrict the volumes that are activated automatically by setting the {{Ic|auto_activation_volume_list}} in {{Ic|/etc/lvm/lvm.conf}}. If in doubt, leave this option commented out.<br />
<br />
=== Grow logical volume ===<br />
To grow a logical volume you first need to grow the logical volume and then the filesystem to use the newly created free space. Let us say we have a logical volume of 15GB with ext3 on it and we want to grow it to 20G. We need to do the following steps: <br />
# lvextend -L 20G VolGroup00/lvolhome (or lvresize -L +5G VolGroup00/lvolhome)<br />
# resize2fs /dev/VolGroup00/lvolhome<br />
You may use {{Ic|lvresize}} instead of {{Ic|lvextend}}.<br />
<br />
If you want to fill all the free space on a volume group, use the next command:<br />
# lvextend -l +100%FREE VolGroup00/lvolhome<br />
<br />
{{Warning|Not all filesystems support growing without loss of data and/or growing online.}}<br />
<br />
{{Note|If you do not resize your filesystem, you will still have a volume with the same size as before (volume will be bigger but partly unused).}}<br />
<br />
=== Shrink logical volume ===<br />
Because your filesystem is probably as big as the logical volume it resides on, you need to shrink the filesystem first and then shrink the logical volume. Depending on your filesystem, you may need to unmount it first. Let us say we have a logical volume of 15GB with ext3 on it and we want to shrink it to 10G. We need to do the following steps: <br />
# resize2fs /dev/VolGroup00/lvolhome 9G<br />
# lvreduce -L 10G VolGroup00/lvolhome (or lvresize -L -5G VolGroup00/lvolhome)<br />
# resize2fs /dev/VolGroup00/lvolhome<br />
Here we shrunk the filesystem more than needed so that when we shrunk the logical volume we did not accidentally cut off the end of the filesystem. After that we normally grow the filesystem to fill all free space left on logical volume. You may use {{Ic|lvresize}} instead of {{Ic|lvreduce}}.<br />
<br />
{{Warning|<br />
*Do not reduce the filesystem size to less than the amount of space occupied by data or you risk data loss.<br />
*Not all filesystems support shrinking without loss of data and/or shrinking online.}}<br />
<br />
{{Note|It is better to reduce the filesystem to a smaller size than the logical volume, so that after resizing the logical volume, we do not accidentally cut off some data from the end of the filesystem.}}<br />
<br />
=== Remove logical volume ===<br />
{{Warning|Before you remove a logical volume, make sure to move all data that you want to keep somewhere else, otherwise it will be lost!}}<br />
<br />
First, find out the name of the logical volume you want to remove. You can get a list of all logical volumes installed on the system with:<br />
<br />
{{bc|# lvs}}<br />
<br />
Next, look up the mountpoint for your chosen logical volume...:<br />
<br />
{{bc|$ df -h}}<br />
<br />
... and unmount it:<br />
<br />
{{bc|# umount /your_mountpoint}}<br />
<br />
Finally, remove the logical volume:<br />
<br />
{{bc|# lvremove /dev/yourVG/yourLV}}<br />
<br />
Confirm by typing {{keypress|y}} and you are done.<br />
<br />
Do not forget, to update {{ic|/etc/fstab}}!<br />
<br />
You can verify the removal of your logical volume by typing "lvs" as root again (see first step of this section).<br />
<br />
=== Add physical volume to a volume group ===<br />
<br />
You first create a new physical volume on the block device you wish to use, then extend your volume group<br />
<br />
{{bc|1=<br />
# pvcreate /dev/sdb1<br />
# vgextend VolGroup00 /dev/sdb1}}<br />
<br />
This of course will increase the total number of physical extents on your volume group, which can be allocated by logical volumes as you see fit.<br />
<br />
{{Note|It is considered good form to a partition table on your storage medium below LVM, and use the appropriate type code: {{ic|8e}} for MBR, and {{ic|8e00}} for GPT partitions.}}<br />
<br />
=== Remove partition from a volume group ===<br />
All of the data on that partition needs to be moved to another partition. Fortunately, LVM makes this easy:<br />
# pvmove /dev/sdb1<br />
If you want to have the data on a specific physical volume, specify that as the second argument to {{Ic|pvmove}}:<br />
# pvmove /dev/sdb1 /dev/sdf1<br />
Then the physical volume needs to be removed from the volume group:<br />
# vgreduce myVg /dev/sdb1<br />
Or remove all empty physical volumes:<br />
# vgreduce --all vg0<br />
<br />
And lastly, if you want to use the partition for something else, and want to avoid LVM thinking that the partition is a physical volume:<br />
# pvremove /dev/sdb1<br />
<br />
=== Snapshots ===<br />
====Introduction====<br />
LVM allows you to take a snapshot of your system in a much more efficient way than a traditional backup. It does this efficiently by using a COW (copy-on-write) policy. The initial snapshot you take simply contains hard-links to the inodes of your actual data. So long as your data remains unchanged, the snapshot merely contains its inode pointers and not the data itself. Whenever you modify a file or directory that the snapshot points to, LVM automatically clones the data, the old copy referenced by the snapshot, and the new copy referenced by your active system. Thus, you can snapshot a system with 35GB of data using just 2GB of free space so long as you modify less than 2GB (on both the original and snapshot).<br />
<br />
====Configuration====<br />
You create snapshot logical volumes just like normal ones.<br />
<br />
# lvcreate --size 100M --snapshot --name snap01 /dev/mapper/vg0-pv<br />
With that volume, you may modify less than 100M of data, before the snapshot volume fills up.<br />
<br />
It is important to have the ''dm-snapshot'' module listed in the MODULES variable of {{ic|/etc/mkinitcpio.conf}}, otherwise the system will not boot. If you do this on an already installed system, make sure to rebuild the image with<br />
# mkinitcpio -g /boot/initramfs-linux.img<br />
<br />
Todo: scripts to automate snapshots of root before updates, to rollback... updating {{ic|menu.lst}} to boot snapshots (separate article?)<br />
<br />
snapshots are primarily used to provide a frozen copy of a filesystem to make backups; a backup taking two hours provides a more consistent image of the filesystem than directly backing up the partition.<br />
<br />
See [[Create root filesystem snapshots with LVM]] for automating the creation of clean root filesystem snapshots during system startup<br />
for backup and rollback.<br />
<br />
[[Encrypted_LVM]]<br />
<br />
== Troubleshooting ==<br />
===Changes that could be required due to changes in the Arch-Linux defaults===<br />
The {{ic|1=use_lvmetad = 1}} must be set in {{ic|/etc/lvm/lvm.conf}}. This is the default now - if you have a {{ic|lvm.conf.pacnew}} file, you must merge this change.<br />
<br />
===LVM commands do not work===<br />
*Load proper module:<br />
# modprobe dm_mod<br />
<br />
The {{ic|dm_mod}} module should be automatically loaded. In case it does not, you can try:<br />
<br />
{{hc|/etc/mkinitcpio.conf:|<nowiki>MODULES="dm_mod ..."</nowiki>}}<br />
<br />
You will need to [[Mkinitcpio#Image_creation_and_activation|rebuild]] the initramfs to commit any changes you made.<br />
<br />
<br />
*Try preceding commands with ''lvm'' like this:<br />
# lvm pvdisplay<br />
<br />
=== Logical Volumes do not show up ===<br />
If you are trying to mount existing logical volumes, but they do not show up in {{ic|lvscan}}, you can use the following commands to activate them:<br />
<br />
# vgscan<br />
# vgchange -ay<br />
<br />
===LVM on removable media===<br />
Symptoms:<br />
~$ sudo vgscan<br />
Reading all physical volumes. This may take a while...<br />
/dev/backupdrive1/backup: read failed after 0 of 4096 at 319836585984: Input/output error<br />
/dev/backupdrive1/backup: read failed after 0 of 4096 at 319836643328: Input/output error<br />
/dev/backupdrive1/backup: read failed after 0 of 4096 at 0: Input/output error<br />
/dev/backupdrive1/backup: read failed after 0 of 4096 at 4096: Input/output error<br />
Found volume group "backupdrive1" using metadata type lvm2<br />
Found volume group "networkdrive" using metadata type lvm2<br />
<br />
Cause:<br />
:Removing an external LVM drive without deactivating the volume group(s) first. Before you disconnect, make sure to:<br />
# vgchange -an <volume group name><br />
<br />
Fix: (assuming you already tried to activate the volume group with vgchange -ay <vg>, and are receiving the Input/output errors<br />
# vgchange -an <volume group name><br />
:Unplug the external drive and wait a few minutes<br />
# vgscan<br />
# vgchange -ay <volume group name><br />
<br />
===kernel options===<br />
In kernel options, you may need {{ic|dolvm}}. {{ic|<nowiki>root=</nowiki>}} should be set to the logical volume, e.g {{ic|<nowiki>/dev/mapper/{vg-name}-{lv-name}</nowiki>}}<br />
<br />
<br />
===obsolete stuff===<br />
If you still use sysvinit, modify {{ic|USELVM}} appropriately:<br />
<br />
{{hc|/etc/rc.conf:|<nowiki>USELVM="yes"</nowiki>}}<br />
<br />
<br />
== Additional resources ==<br />
* [http://sourceware.org/lvm2/ LVM2 Resource Page] on SourceWare.org<br />
* [http://tldp.org/HOWTO/LVM-HOWTO/ LVM HOWTO] article at The Linux Documentation Project<br />
* [http://www.gentoo.org/doc/en/lvm2.xml Gentoo LVM2 installation] guide at Gentoo Documentation<br />
* [http://en.gentoo-wiki.com/wiki/LVM LVM] article at Gentoo Wiki<br />
* [http://www.joshbryan.com/blog/2008/01/02/lvm2-mirrors-vs-md-raid-1/ LVM2 Mirrors vs. MD Raid 1] post by Josh Bryan</div>Freejackhttps://wiki.archlinux.org/index.php?title=Create_root_filesystem_snapshots_with_LVM&diff=255377Create root filesystem snapshots with LVM2013-04-27T17:44:49Z<p>Freejack: first version -- moved from user namespace</p>
<hr />
<div>[[Category:System recovery]]<br />
{{Article summary start}}<br />
{{Article summary text|Setup root filesystem LVM snapshot creation during system start.<br />
Such snapshots can be used for [[Full System Backup with tar|full system backups]]<br />
with minimal downtime or testing system updates with the option to revert<br />
them.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary text|{{pkg|lvm2}}, {{pkg|systemd}}}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|LVM}}<br />
{{Article summary wiki|Full System Backup with tar}}<br />
{{Article summary end}}<br />
<br />
<br />
== Prerequisites ==<br />
<br />
You need a system with [[LVM]] root filesystem and [[systemd]].<br />
Ensure that [[Lvm#Snapshots|LVM snapshots]] prerequisites are correctly setup.<br />
<br />
== Setup ==<br />
<br />
During system start a clean snapshot of the root volume is<br />
created using a new systemd service. Create<br />
{{ic|/etc/systemd/system/mk-lvm-snapshots.service}} containing:<br />
{{bc|[Unit]<br />
Description&#61;make LVM snapshots<br />
Requires&#61;local-fs-pre.target<br />
DefaultDependencies&#61;no<br />
Conflicts&#61;shutdown.target<br />
After&#61;local-fs-pre.target<br />
Before&#61;local-fs.target<br />
<br />
[Install]<br />
WantedBy&#61;make-snapshots.target<br />
<br />
[Service]<br />
Type&#61;oneshot<br />
ExecStart&#61;/usr/sbin/lvcreate -L10G -n snap-root -s lvmvolume/root}}<br />
<br />
Adapt the {{ic|lvcreate}} command to match your root volume group and volume name.<br />
Adjust the snapshot size if necessary. If additional filesystems should be snapshotted<br />
during startup you may extend the {{ic|ExecStart}} property with addtional lvcreate commands,<br />
separated with {{ic| ; }}.<br />
<br />
{{Note|You should test the {{ic|# lvcreate}} command in the running system until it works as desired.<br />
Remove the test snapshots with {{ic|# lvremove}}. The snapshots taken from a running system are<br />
not as consistent as snapshots taken in single user mode or during startup.}}<br />
<br />
Create a new systemd target {{ic|/etc/systemd/system/make-snapshots.target}}:<br />
{{bc|[Unit]<br />
Description&#61;Make Snapshots<br />
Requires&#61;multi-user.target}}<br />
Adapt the base target, if {{ic|multi-user.target}} is not your default target.<br />
<br />
Enable the new service with {{ic|# systemctl enable mk-lvm-snapshots.service}}.<br />
<br />
If the system is started with the new target, LVM snapshot(s) are created just after mounting the local filesystems.<br />
To get a [[grub]] menu entry starting this target create {{ic|/boot/grub/custom.cfg}} based on the<br />
{{ic|grub.cfg}} entry for your normal startup. The kernel command line is extended to start the new<br />
{{ic|make-snapshots.target}}:<br />
{{bc|### make snapshots ###<br />
menuentry 'Arch GNU/Linux, make snapshots' --class arch --class gnu-linux --class gnu --class os {<br />
...<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root&#61;/dev/mapper/lvmvolume-root ro systemd.unit&#61;make-snapshots.target<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
} }}<br />
<br />
Remember to adjust {{ic|custom.cfg}} if {{ic|grub.cfg}} changes.<br />
<br />
After restarting the system with this grub entry {{ic|# lvs}} should show up the newly created snapshot.<br />
<br />
{{Tip|To get the messages of the new service use<br />
{{ic|# journalctl -u mk-lvm-snapshots.service}}.}}<br />
<br />
== Usage ==<br />
<br />
=== Backup ===<br />
To use this functionality for a full system backup, restart your system with the snapshot creation target.<br />
Mount the snapshot volume (and further volumes, if required), preferably using the read only (<tt>-o</tt>) option.<br />
Then backup your system, for example with tar as described in [[Full_System_Backup_with_tar]].<br />
<br />
During backup you can continue to use your system normally, since all changes to your regular volumes are invisible in<br />
the snapshots. Do not forget to delete the snapshot volume after the backup &ndash; changes to your regular volume will<br />
use up space in the snapshot due to the copy-on-write operations. If the snapshot space becomes fully used, and LVM<br />
is not able to automatically grow the snapshot, LVM will deny further writes to your regular volumes or drop the<br />
snapshot, which should be avoided.<br />
<br />
=== Revert updates ===<br />
An other use for LVM snapshots is testing and reverting of updates. In this case create a snapshot for the system<br />
in a known good state and perform updates or changes afterwards.<br />
<br />
If you want to permantly stick to the updates just drop the snapshot with {{ic|# lvremove}}. If you want to revert to the snapshotted<br />
state issue a {{ic|# lvchange --merge}} for the snapshot. During the next restart of the system the snapshot<br />
is merged back into your regular volume. All changes to the volume happened after the snapshot are undone.<br />
{{Note|After merging the snapshot no longer exists. Recreate a new snapshot if further testing with rollback<br />
option is desired.}}<br />
<br />
== Known issues ==<br />
Due to [https://bugzilla.redhat.com/show_bug.cgi?id=681582 bug 681582] shutting down the system with active<br />
snapshots may hang for some time (currently 1...3 minutes).</div>Freejackhttps://wiki.archlinux.org/index.php?title=User:Freejack/Create_LVM_root_snapshots&diff=255376User:Freejack/Create LVM root snapshots2013-04-27T17:43:52Z<p>Freejack: Freejack moved page User:Freejack/Create LVM root snapshots to Create root filesystem snapshots with LVM</p>
<hr />
<div>#REDIRECT [[Create root filesystem snapshots with LVM]]</div>Freejackhttps://wiki.archlinux.org/index.php?title=Create_root_filesystem_snapshots_with_LVM&diff=255375Create root filesystem snapshots with LVM2013-04-27T17:43:52Z<p>Freejack: Freejack moved page User:Freejack/Create LVM root snapshots to Create root filesystem snapshots with LVM</p>
<hr />
<div><!-- [[Category:System recovery]] --><br />
{{Article summary start}}<br />
{{Article summary text|Setup root filesystem LVM snapshot creation during system start.<br />
Such snapshots can be used for [[Full System Backup with tar|full system backups]]<br />
with minimal downtime or testing system updates with the option to revert<br />
them.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary text|{{pkg|lvm2}}, {{pkg|systemd}}}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|LVM}}<br />
{{Article summary wiki|Full System Backup with tar}}<br />
{{Article summary end}}<br />
<br />
<br />
== Prerequisites ==<br />
<br />
You need a system with [[LVM]] root filesystem and [[systemd]].<br />
Ensure that [[Lvm#Snapshots|LVM snapshots]] prerequisites are correctly setup.<br />
<br />
== Setup ==<br />
<br />
During system start a clean snapshot of the root volume is<br />
created using a new systemd service. Create<br />
{{ic|/etc/systemd/system/mk-lvm-snapshots.service}} containing:<br />
{{bc|[Unit]<br />
Description&#61;make LVM snapshots<br />
Requires&#61;local-fs-pre.target<br />
DefaultDependencies&#61;no<br />
Conflicts&#61;shutdown.target<br />
After&#61;local-fs-pre.target<br />
Before&#61;local-fs.target<br />
<br />
[Install]<br />
WantedBy&#61;make-snapshots.target<br />
<br />
[Service]<br />
Type&#61;oneshot<br />
ExecStart&#61;/usr/sbin/lvcreate -L10G -n snap-root -s lvmvolume/root}}<br />
<br />
Adapt the {{ic|lvcreate}} command to match your root volume group and volume name.<br />
Adjust the snapshot size if necessary. If additional filesystems should be snapshotted<br />
during startup you may extend the {{ic|ExecStart}} property with addtional lvcreate commands,<br />
separated with {{ic| ; }}.<br />
<br />
{{Note|You should test the {{ic|# lvcreate}} command in the running system until it works as desired.<br />
Remove the test snapshots with {{ic|# lvremove}}. The snapshots taken from a running system are<br />
not as consistent as snapshots taken in single user mode or during startup.}}<br />
<br />
Create a new systemd target {{ic|/etc/systemd/system/make-snapshots.target}}:<br />
{{bc|[Unit]<br />
Description&#61;Make Snapshots<br />
Requires&#61;multi-user.target}}<br />
Adapt the base target, if {{ic|multi-user.target}} is not your default target.<br />
<br />
Enable the new service with {{ic|# systemctl enable mk-lvm-snapshots.service}}.<br />
<br />
If the system is started with the new target, LVM snapshot(s) are created just after mounting the local filesystems.<br />
To get a [[grub]] menu entry starting this target create {{ic|/boot/grub/custom.cfg}} based on the<br />
{{ic|grub.cfg}} entry for your normal startup. The kernel command line is extended to start the new<br />
{{ic|make-snapshots.target}}:<br />
{{bc|### make snapshots ###<br />
menuentry 'Arch GNU/Linux, make snapshots' --class arch --class gnu-linux --class gnu --class os {<br />
...<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root&#61;/dev/mapper/lvmvolume-root ro systemd.unit&#61;make-snapshots.target<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
} }}<br />
<br />
Remember to adjust {{ic|custom.cfg}} if {{ic|grub.cfg}} changes.<br />
<br />
After restarting the system with this grub entry {{ic|# lvs}} should show up the newly created snapshot.<br />
<br />
{{Tip|To get the messages of the new service use<br />
{{ic|# journalctl -u mk-lvm-snapshots.service}}.}}<br />
<br />
== Usage ==<br />
<br />
=== Backup ===<br />
To use this functionality for a full system backup, restart your system with the snapshot creation target.<br />
Mount the snapshot volume (and further volumes, if required), preferably using the read only (<tt>-o</tt>) option.<br />
Then backup your system, for example with tar as described in [[Full_System_Backup_with_tar]].<br />
<br />
During backup you can continue to use your system normally, since all changes to your regular volumes are invisible in<br />
the snapshots. Do not forget to delete the snapshot volume after the backup &ndash; changes to your regular volume will<br />
use up space in the snapshot due to the copy-on-write operations. If the snapshot space becomes fully used, and LVM<br />
is not able to automatically grow the snapshot, LVM will deny further writes to your regular volumes or drop the<br />
snapshot, which should be avoided.<br />
<br />
=== Revert updates ===<br />
An other use for LVM snapshots is testing and reverting of updates. In this case create a snapshot for the system<br />
in a known good state and perform updates or changes afterwards.<br />
<br />
If you want to permantly stick to the updates just drop the snapshot with {{ic|# lvremove}}. If you want to revert to the snapshotted<br />
state issue a {{ic|# lvchange --merge}} for the snapshot. During the next restart of the system the snapshot<br />
is merged back into your regular volume. All changes to the volume happened after the snapshot are undone.<br />
{{Note|After merging the snapshot no longer exists. Recreate a new snapshot if further testing with rollback<br />
option is desired.}}<br />
<br />
== Known issues ==<br />
Due to [https://bugzilla.redhat.com/show_bug.cgi?id=681582 bug 681582] shutting down the system with active<br />
snapshots may hang for some time (currently 1...3 minutes).</div>Freejackhttps://wiki.archlinux.org/index.php?title=Create_root_filesystem_snapshots_with_LVM&diff=255374Create root filesystem snapshots with LVM2013-04-27T17:42:48Z<p>Freejack: /* Known issues */</p>
<hr />
<div><!-- [[Category:System recovery]] --><br />
{{Article summary start}}<br />
{{Article summary text|Setup root filesystem LVM snapshot creation during system start.<br />
Such snapshots can be used for [[Full System Backup with tar|full system backups]]<br />
with minimal downtime or testing system updates with the option to revert<br />
them.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary text|{{pkg|lvm2}}, {{pkg|systemd}}}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|LVM}}<br />
{{Article summary wiki|Full System Backup with tar}}<br />
{{Article summary end}}<br />
<br />
<br />
== Prerequisites ==<br />
<br />
You need a system with [[LVM]] root filesystem and [[systemd]].<br />
Ensure that [[Lvm#Snapshots|LVM snapshots]] prerequisites are correctly setup.<br />
<br />
== Setup ==<br />
<br />
During system start a clean snapshot of the root volume is<br />
created using a new systemd service. Create<br />
{{ic|/etc/systemd/system/mk-lvm-snapshots.service}} containing:<br />
{{bc|[Unit]<br />
Description&#61;make LVM snapshots<br />
Requires&#61;local-fs-pre.target<br />
DefaultDependencies&#61;no<br />
Conflicts&#61;shutdown.target<br />
After&#61;local-fs-pre.target<br />
Before&#61;local-fs.target<br />
<br />
[Install]<br />
WantedBy&#61;make-snapshots.target<br />
<br />
[Service]<br />
Type&#61;oneshot<br />
ExecStart&#61;/usr/sbin/lvcreate -L10G -n snap-root -s lvmvolume/root}}<br />
<br />
Adapt the {{ic|lvcreate}} command to match your root volume group and volume name.<br />
Adjust the snapshot size if necessary. If additional filesystems should be snapshotted<br />
during startup you may extend the {{ic|ExecStart}} property with addtional lvcreate commands,<br />
separated with {{ic| ; }}.<br />
<br />
{{Note|You should test the {{ic|# lvcreate}} command in the running system until it works as desired.<br />
Remove the test snapshots with {{ic|# lvremove}}. The snapshots taken from a running system are<br />
not as consistent as snapshots taken in single user mode or during startup.}}<br />
<br />
Create a new systemd target {{ic|/etc/systemd/system/make-snapshots.target}}:<br />
{{bc|[Unit]<br />
Description&#61;Make Snapshots<br />
Requires&#61;multi-user.target}}<br />
Adapt the base target, if {{ic|multi-user.target}} is not your default target.<br />
<br />
Enable the new service with {{ic|# systemctl enable mk-lvm-snapshots.service}}.<br />
<br />
If the system is started with the new target, LVM snapshot(s) are created just after mounting the local filesystems.<br />
To get a [[grub]] menu entry starting this target create {{ic|/boot/grub/custom.cfg}} based on the<br />
{{ic|grub.cfg}} entry for your normal startup. The kernel command line is extended to start the new<br />
{{ic|make-snapshots.target}}:<br />
{{bc|### make snapshots ###<br />
menuentry 'Arch GNU/Linux, make snapshots' --class arch --class gnu-linux --class gnu --class os {<br />
...<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root&#61;/dev/mapper/lvmvolume-root ro systemd.unit&#61;make-snapshots.target<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
} }}<br />
<br />
Remember to adjust {{ic|custom.cfg}} if {{ic|grub.cfg}} changes.<br />
<br />
After restarting the system with this grub entry {{ic|# lvs}} should show up the newly created snapshot.<br />
<br />
{{Tip|To get the messages of the new service use<br />
{{ic|# journalctl -u mk-lvm-snapshots.service}}.}}<br />
<br />
== Usage ==<br />
<br />
=== Backup ===<br />
To use this functionality for a full system backup, restart your system with the snapshot creation target.<br />
Mount the snapshot volume (and further volumes, if required), preferably using the read only (<tt>-o</tt>) option.<br />
Then backup your system, for example with tar as described in [[Full_System_Backup_with_tar]].<br />
<br />
During backup you can continue to use your system normally, since all changes to your regular volumes are invisible in<br />
the snapshots. Do not forget to delete the snapshot volume after the backup &ndash; changes to your regular volume will<br />
use up space in the snapshot due to the copy-on-write operations. If the snapshot space becomes fully used, and LVM<br />
is not able to automatically grow the snapshot, LVM will deny further writes to your regular volumes or drop the<br />
snapshot, which should be avoided.<br />
<br />
=== Revert updates ===<br />
An other use for LVM snapshots is testing and reverting of updates. In this case create a snapshot for the system<br />
in a known good state and perform updates or changes afterwards.<br />
<br />
If you want to permantly stick to the updates just drop the snapshot with {{ic|# lvremove}}. If you want to revert to the snapshotted<br />
state issue a {{ic|# lvchange --merge}} for the snapshot. During the next restart of the system the snapshot<br />
is merged back into your regular volume. All changes to the volume happened after the snapshot are undone.<br />
{{Note|After merging the snapshot no longer exists. Recreate a new snapshot if further testing with rollback<br />
option is desired.}}<br />
<br />
== Known issues ==<br />
Due to [https://bugzilla.redhat.com/show_bug.cgi?id=681582 bug 681582] shutting down the system with active<br />
snapshots may hang for some time (currently 1...3 minutes).</div>Freejackhttps://wiki.archlinux.org/index.php?title=Create_root_filesystem_snapshots_with_LVM&diff=255373Create root filesystem snapshots with LVM2013-04-27T17:40:27Z<p>Freejack: /* Revert updates */</p>
<hr />
<div><!-- [[Category:System recovery]] --><br />
{{Article summary start}}<br />
{{Article summary text|Setup root filesystem LVM snapshot creation during system start.<br />
Such snapshots can be used for [[Full System Backup with tar|full system backups]]<br />
with minimal downtime or testing system updates with the option to revert<br />
them.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary text|{{pkg|lvm2}}, {{pkg|systemd}}}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|LVM}}<br />
{{Article summary wiki|Full System Backup with tar}}<br />
{{Article summary end}}<br />
<br />
<br />
== Prerequisites ==<br />
<br />
You need a system with [[LVM]] root filesystem and [[systemd]].<br />
Ensure that [[Lvm#Snapshots|LVM snapshots]] prerequisites are correctly setup.<br />
<br />
== Setup ==<br />
<br />
During system start a clean snapshot of the root volume is<br />
created using a new systemd service. Create<br />
{{ic|/etc/systemd/system/mk-lvm-snapshots.service}} containing:<br />
{{bc|[Unit]<br />
Description&#61;make LVM snapshots<br />
Requires&#61;local-fs-pre.target<br />
DefaultDependencies&#61;no<br />
Conflicts&#61;shutdown.target<br />
After&#61;local-fs-pre.target<br />
Before&#61;local-fs.target<br />
<br />
[Install]<br />
WantedBy&#61;make-snapshots.target<br />
<br />
[Service]<br />
Type&#61;oneshot<br />
ExecStart&#61;/usr/sbin/lvcreate -L10G -n snap-root -s lvmvolume/root}}<br />
<br />
Adapt the {{ic|lvcreate}} command to match your root volume group and volume name.<br />
Adjust the snapshot size if necessary. If additional filesystems should be snapshotted<br />
during startup you may extend the {{ic|ExecStart}} property with addtional lvcreate commands,<br />
separated with {{ic| ; }}.<br />
<br />
{{Note|You should test the {{ic|# lvcreate}} command in the running system until it works as desired.<br />
Remove the test snapshots with {{ic|# lvremove}}. The snapshots taken from a running system are<br />
not as consistent as snapshots taken in single user mode or during startup.}}<br />
<br />
Create a new systemd target {{ic|/etc/systemd/system/make-snapshots.target}}:<br />
{{bc|[Unit]<br />
Description&#61;Make Snapshots<br />
Requires&#61;multi-user.target}}<br />
Adapt the base target, if {{ic|multi-user.target}} is not your default target.<br />
<br />
Enable the new service with {{ic|# systemctl enable mk-lvm-snapshots.service}}.<br />
<br />
If the system is started with the new target, LVM snapshot(s) are created just after mounting the local filesystems.<br />
To get a [[grub]] menu entry starting this target create {{ic|/boot/grub/custom.cfg}} based on the<br />
{{ic|grub.cfg}} entry for your normal startup. The kernel command line is extended to start the new<br />
{{ic|make-snapshots.target}}:<br />
{{bc|### make snapshots ###<br />
menuentry 'Arch GNU/Linux, make snapshots' --class arch --class gnu-linux --class gnu --class os {<br />
...<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root&#61;/dev/mapper/lvmvolume-root ro systemd.unit&#61;make-snapshots.target<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
} }}<br />
<br />
Remember to adjust {{ic|custom.cfg}} if {{ic|grub.cfg}} changes.<br />
<br />
After restarting the system with this grub entry {{ic|# lvs}} should show up the newly created snapshot.<br />
<br />
{{Tip|To get the messages of the new service use<br />
{{ic|# journalctl -u mk-lvm-snapshots.service}}.}}<br />
<br />
== Usage ==<br />
<br />
=== Backup ===<br />
To use this functionality for a full system backup, restart your system with the snapshot creation target.<br />
Mount the snapshot volume (and further volumes, if required), preferably using the read only (<tt>-o</tt>) option.<br />
Then backup your system, for example with tar as described in [[Full_System_Backup_with_tar]].<br />
<br />
During backup you can continue to use your system normally, since all changes to your regular volumes are invisible in<br />
the snapshots. Do not forget to delete the snapshot volume after the backup &ndash; changes to your regular volume will<br />
use up space in the snapshot due to the copy-on-write operations. If the snapshot space becomes fully used, and LVM<br />
is not able to automatically grow the snapshot, LVM will deny further writes to your regular volumes or drop the<br />
snapshot, which should be avoided.<br />
<br />
=== Revert updates ===<br />
An other use for LVM snapshots is testing and reverting of updates. In this case create a snapshot for the system<br />
in a known good state and perform updates or changes afterwards.<br />
<br />
If you want to permantly stick to the updates just drop the snapshot with {{ic|# lvremove}}. If you want to revert to the snapshotted<br />
state issue a {{ic|# lvchange --merge}} for the snapshot. During the next restart of the system the snapshot<br />
is merged back into your regular volume. All changes to the volume happened after the snapshot are undone.<br />
{{Note|After merging the snapshot no longer exists. Recreate a new snapshot if further testing with rollback<br />
option is desired.}}<br />
<br />
== Known issues ==<br />
Due to [https://bugzilla.redhat.com/show_bug.cgi?id=681582 bug 681582] shutting down the system with active<br />
snapshots may hang for some time.</div>Freejackhttps://wiki.archlinux.org/index.php?title=Create_root_filesystem_snapshots_with_LVM&diff=255372Create root filesystem snapshots with LVM2013-04-27T17:36:35Z<p>Freejack: /* Setup */</p>
<hr />
<div><!-- [[Category:System recovery]] --><br />
{{Article summary start}}<br />
{{Article summary text|Setup root filesystem LVM snapshot creation during system start.<br />
Such snapshots can be used for [[Full System Backup with tar|full system backups]]<br />
with minimal downtime or testing system updates with the option to revert<br />
them.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary text|{{pkg|lvm2}}, {{pkg|systemd}}}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|LVM}}<br />
{{Article summary wiki|Full System Backup with tar}}<br />
{{Article summary end}}<br />
<br />
<br />
== Prerequisites ==<br />
<br />
You need a system with [[LVM]] root filesystem and [[systemd]].<br />
Ensure that [[Lvm#Snapshots|LVM snapshots]] prerequisites are correctly setup.<br />
<br />
== Setup ==<br />
<br />
During system start a clean snapshot of the root volume is<br />
created using a new systemd service. Create<br />
{{ic|/etc/systemd/system/mk-lvm-snapshots.service}} containing:<br />
{{bc|[Unit]<br />
Description&#61;make LVM snapshots<br />
Requires&#61;local-fs-pre.target<br />
DefaultDependencies&#61;no<br />
Conflicts&#61;shutdown.target<br />
After&#61;local-fs-pre.target<br />
Before&#61;local-fs.target<br />
<br />
[Install]<br />
WantedBy&#61;make-snapshots.target<br />
<br />
[Service]<br />
Type&#61;oneshot<br />
ExecStart&#61;/usr/sbin/lvcreate -L10G -n snap-root -s lvmvolume/root}}<br />
<br />
Adapt the {{ic|lvcreate}} command to match your root volume group and volume name.<br />
Adjust the snapshot size if necessary. If additional filesystems should be snapshotted<br />
during startup you may extend the {{ic|ExecStart}} property with addtional lvcreate commands,<br />
separated with {{ic| ; }}.<br />
<br />
{{Note|You should test the {{ic|# lvcreate}} command in the running system until it works as desired.<br />
Remove the test snapshots with {{ic|# lvremove}}. The snapshots taken from a running system are<br />
not as consistent as snapshots taken in single user mode or during startup.}}<br />
<br />
Create a new systemd target {{ic|/etc/systemd/system/make-snapshots.target}}:<br />
{{bc|[Unit]<br />
Description&#61;Make Snapshots<br />
Requires&#61;multi-user.target}}<br />
Adapt the base target, if {{ic|multi-user.target}} is not your default target.<br />
<br />
Enable the new service with {{ic|# systemctl enable mk-lvm-snapshots.service}}.<br />
<br />
If the system is started with the new target, LVM snapshot(s) are created just after mounting the local filesystems.<br />
To get a [[grub]] menu entry starting this target create {{ic|/boot/grub/custom.cfg}} based on the<br />
{{ic|grub.cfg}} entry for your normal startup. The kernel command line is extended to start the new<br />
{{ic|make-snapshots.target}}:<br />
{{bc|### make snapshots ###<br />
menuentry 'Arch GNU/Linux, make snapshots' --class arch --class gnu-linux --class gnu --class os {<br />
...<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root&#61;/dev/mapper/lvmvolume-root ro systemd.unit&#61;make-snapshots.target<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
} }}<br />
<br />
Remember to adjust {{ic|custom.cfg}} if {{ic|grub.cfg}} changes.<br />
<br />
After restarting the system with this grub entry {{ic|# lvs}} should show up the newly created snapshot.<br />
<br />
{{Tip|To get the messages of the new service use<br />
{{ic|# journalctl -u mk-lvm-snapshots.service}}.}}<br />
<br />
== Usage ==<br />
<br />
=== Backup ===<br />
To use this functionality for a full system backup, restart your system with the snapshot creation target.<br />
Mount the snapshot volume (and further volumes, if required), preferably using the read only (<tt>-o</tt>) option.<br />
Then backup your system, for example with tar as described in [[Full_System_Backup_with_tar]].<br />
<br />
During backup you can continue to use your system normally, since all changes to your regular volumes are invisible in<br />
the snapshots. Do not forget to delete the snapshot volume after the backup &ndash; changes to your regular volume will<br />
use up space in the snapshot due to the copy-on-write operations. If the snapshot space becomes fully used, and LVM<br />
is not able to automatically grow the snapshot, LVM will deny further writes to your regular volumes or drop the<br />
snapshot, which should be avoided.<br />
<br />
=== Revert updates ===<br />
An other use for LVM snapshots is testing and reverting of updates. In this case create a snapshot for the system<br />
in a known good state and perform updates or changes afterwards.<br />
<br />
If you want to permantly stick to the updates just drop the snapshot with {{ic|# lvremove}}. If you want to revert to the snapshotted<br />
state issue a {{ic|# lvchange --merge}} for the snapshot. During the next restart of the system the snapshot<br />
is merged back into your regular volume. All changes to the volume happened after the snapshot are undone.<br />
<br />
== Known issues ==<br />
Due to [https://bugzilla.redhat.com/show_bug.cgi?id=681582 bug 681582] shutting down the system with active<br />
snapshots may hang for some time.</div>Freejackhttps://wiki.archlinux.org/index.php?title=Create_root_filesystem_snapshots_with_LVM&diff=255371Create root filesystem snapshots with LVM2013-04-27T17:34:41Z<p>Freejack: /* Setup */</p>
<hr />
<div><!-- [[Category:System recovery]] --><br />
{{Article summary start}}<br />
{{Article summary text|Setup root filesystem LVM snapshot creation during system start.<br />
Such snapshots can be used for [[Full System Backup with tar|full system backups]]<br />
with minimal downtime or testing system updates with the option to revert<br />
them.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary text|{{pkg|lvm2}}, {{pkg|systemd}}}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|LVM}}<br />
{{Article summary wiki|Full System Backup with tar}}<br />
{{Article summary end}}<br />
<br />
<br />
== Prerequisites ==<br />
<br />
You need a system with [[LVM]] root filesystem and [[systemd]].<br />
Ensure that [[Lvm#Snapshots|LVM snapshots]] prerequisites are correctly setup.<br />
<br />
== Setup ==<br />
<br />
During system start a clean snapshot of the root volume is<br />
created using a new systemd service. Create<br />
{{ic|/etc/systemd/system/mk-lvm-snapshots.service}} containing:<br />
{{bc|[Unit]<br />
Description&#61;make LVM snapshots<br />
Requires&#61;local-fs-pre.target<br />
DefaultDependencies&#61;no<br />
Conflicts&#61;shutdown.target<br />
After&#61;local-fs-pre.target<br />
Before&#61;local-fs.target<br />
<br />
[Install]<br />
WantedBy&#61;make-snapshots.target<br />
<br />
[Service]<br />
Type&#61;oneshot<br />
ExecStart&#61;/usr/sbin/lvcreate -L10G -n snap-root -s lvmvolume/root}}<br />
<br />
Adapt the {{ic|lvcreate}} command to match your root volume group and volume name.<br />
Adjust the snapshot size if necessary. If additional filesystems should be snapshotted<br />
during startup you may extend the {{ic|ExecStart}} property with addtional lvcreate commands,<br />
separated with {{ic| ; }}.<br />
<br />
{{Note|You should test the {{ic|# lvcreate}} command in the running system until it works as desired.<br />
Remove the test snapshots with {{ic|# lvremove}}.}}<br />
<br />
Create a new systemd target {{ic|/etc/systemd/system/make-snapshots.target}}:<br />
{{bc|[Unit]<br />
Description&#61;Make Snapshots<br />
Requires&#61;multi-user.target}}<br />
Adapt the base target, if {{ic|multi-user.target}} is not your default target.<br />
<br />
Enable the new service with {{ic|# systemctl enable mk-lvm-snapshots.service}}.<br />
<br />
If the system is started with the new target, LVM snapshot(s) are created just after mounting the local filesystems.<br />
To get a [[grub]] menu entry starting this target create {{ic|/boot/grub/custom.cfg}} based on the<br />
{{ic|grub.cfg}} entry for your normal startup. The kernel command line is extended to start the new<br />
{{ic|make-snapshots.target}}:<br />
{{bc|### make snapshots ###<br />
menuentry 'Arch GNU/Linux, make snapshots' --class arch --class gnu-linux --class gnu --class os {<br />
...<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root&#61;/dev/mapper/lvmvolume-root ro systemd.unit&#61;make-snapshots.target<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
} }}<br />
<br />
Remember to adjust {{ic|custom.cfg}} if {{ic|grub.cfg}} changes.<br />
<br />
After restarting the system with this grub entry {{ic|# lvs}} should show up the newly created snapshot.<br />
<br />
{{Tip|To get the messages of the new service use<br />
{{ic|# journalctl -u mk-lvm-snapshots.service}}.}}<br />
<br />
== Usage ==<br />
<br />
=== Backup ===<br />
To use this functionality for a full system backup, restart your system with the snapshot creation target.<br />
Mount the snapshot volume (and further volumes, if required), preferably using the read only (<tt>-o</tt>) option.<br />
Then backup your system, for example with tar as described in [[Full_System_Backup_with_tar]].<br />
<br />
During backup you can continue to use your system normally, since all changes to your regular volumes are invisible in<br />
the snapshots. Do not forget to delete the snapshot volume after the backup &ndash; changes to your regular volume will<br />
use up space in the snapshot due to the copy-on-write operations. If the snapshot space becomes fully used, and LVM<br />
is not able to automatically grow the snapshot, LVM will deny further writes to your regular volumes or drop the<br />
snapshot, which should be avoided.<br />
<br />
=== Revert updates ===<br />
An other use for LVM snapshots is testing and reverting of updates. In this case create a snapshot for the system<br />
in a known good state and perform updates or changes afterwards.<br />
<br />
If you want to permantly stick to the updates just drop the snapshot with {{ic|# lvremove}}. If you want to revert to the snapshotted<br />
state issue a {{ic|# lvchange --merge}} for the snapshot. During the next restart of the system the snapshot<br />
is merged back into your regular volume. All changes to the volume happened after the snapshot are undone.<br />
<br />
== Known issues ==<br />
Due to [https://bugzilla.redhat.com/show_bug.cgi?id=681582 bug 681582] shutting down the system with active<br />
snapshots may hang for some time.</div>Freejackhttps://wiki.archlinux.org/index.php?title=Create_root_filesystem_snapshots_with_LVM&diff=255370Create root filesystem snapshots with LVM2013-04-27T17:33:58Z<p>Freejack: /* Revert updates */</p>
<hr />
<div><!-- [[Category:System recovery]] --><br />
{{Article summary start}}<br />
{{Article summary text|Setup root filesystem LVM snapshot creation during system start.<br />
Such snapshots can be used for [[Full System Backup with tar|full system backups]]<br />
with minimal downtime or testing system updates with the option to revert<br />
them.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary text|{{pkg|lvm2}}, {{pkg|systemd}}}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|LVM}}<br />
{{Article summary wiki|Full System Backup with tar}}<br />
{{Article summary end}}<br />
<br />
<br />
== Prerequisites ==<br />
<br />
You need a system with [[LVM]] root filesystem and [[systemd]].<br />
Ensure that [[Lvm#Snapshots|LVM snapshots]] prerequisites are correctly setup.<br />
<br />
== Setup ==<br />
<br />
During system start a clean snapshot of the root volume is<br />
created using a new systemd service. Create<br />
{{ic|/etc/systemd/system/mk-lvm-snapshots.service}} containing:<br />
{{bc|[Unit]<br />
Description&#61;make LVM snapshots<br />
Requires&#61;local-fs-pre.target<br />
DefaultDependencies&#61;no<br />
Conflicts&#61;shutdown.target<br />
After&#61;local-fs-pre.target<br />
Before&#61;local-fs.target<br />
<br />
[Install]<br />
WantedBy&#61;make-snapshots.target<br />
<br />
[Service]<br />
Type&#61;oneshot<br />
ExecStart&#61;/usr/sbin/lvcreate -L10G -n snap-root -s lvmvolume/root}}<br />
<br />
Adapt the {{ic|lvcreate}} command to match your root volume group and volume name.<br />
Adjust the snapshot size if necessary. If additional filesystems should be snapshotted<br />
during startup you may extend the {{ic|ExecStart}} property with addtional lvcreate commands,<br />
separated with {{ic| ; }}.<br />
<br />
{{Note|You should test the {{ic|lvcreate}} command in the running system until it works as desired.<br />
Remove the test snapshots with {{ic|lvremove}}.}}<br />
<br />
Create a new systemd target {{ic|/etc/systemd/system/make-snapshots.target}}:<br />
{{bc|[Unit]<br />
Description&#61;Make Snapshots<br />
Requires&#61;multi-user.target}}<br />
Adapt the base target, if {{ic|multi-user.target}} is not your default target.<br />
<br />
Enable the new service with {{ic|# systemctl enable mk-lvm-snapshots.service}}.<br />
<br />
If the system is started with the new target, LVM snapshot(s) are created just after mounting the local filesystems.<br />
To get a [[grub]] menu entry starting this target create {{ic|/boot/grub/custom.cfg}} based on the<br />
{{ic|grub.cfg}} entry for your normal startup. The kernel command line is extended to start the new<br />
{{ic|make-snapshots.target}}:<br />
{{bc|### make snapshots ###<br />
menuentry 'Arch GNU/Linux, make snapshots' --class arch --class gnu-linux --class gnu --class os {<br />
...<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root&#61;/dev/mapper/lvmvolume-root ro systemd.unit&#61;make-snapshots.target<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
} }}<br />
<br />
Remember to adjust {{ic|custom.cfg}} if {{ic|grub.cfg}} changes.<br />
<br />
After restarting the system with this grub entry {{ic|# lvs}} should show up the newly created snapshot.<br />
<br />
{{Tip|To get the messages of the new service use<br />
{{ic|# journalctl -u mk-lvm-snapshots.service}}.}}<br />
<br />
== Usage ==<br />
<br />
=== Backup ===<br />
To use this functionality for a full system backup, restart your system with the snapshot creation target.<br />
Mount the snapshot volume (and further volumes, if required), preferably using the read only (<tt>-o</tt>) option.<br />
Then backup your system, for example with tar as described in [[Full_System_Backup_with_tar]].<br />
<br />
During backup you can continue to use your system normally, since all changes to your regular volumes are invisible in<br />
the snapshots. Do not forget to delete the snapshot volume after the backup &ndash; changes to your regular volume will<br />
use up space in the snapshot due to the copy-on-write operations. If the snapshot space becomes fully used, and LVM<br />
is not able to automatically grow the snapshot, LVM will deny further writes to your regular volumes or drop the<br />
snapshot, which should be avoided.<br />
<br />
=== Revert updates ===<br />
An other use for LVM snapshots is testing and reverting of updates. In this case create a snapshot for the system<br />
in a known good state and perform updates or changes afterwards.<br />
<br />
If you want to permantly stick to the updates just drop the snapshot with {{ic|# lvremove}}. If you want to revert to the snapshotted<br />
state issue a {{ic|# lvchange --merge}} for the snapshot. During the next restart of the system the snapshot<br />
is merged back into your regular volume. All changes to the volume happened after the snapshot are undone.<br />
<br />
== Known issues ==<br />
Due to [https://bugzilla.redhat.com/show_bug.cgi?id=681582 bug 681582] shutting down the system with active<br />
snapshots may hang for some time.</div>Freejackhttps://wiki.archlinux.org/index.php?title=Create_root_filesystem_snapshots_with_LVM&diff=255369Create root filesystem snapshots with LVM2013-04-27T17:32:42Z<p>Freejack: /* Backup */</p>
<hr />
<div><!-- [[Category:System recovery]] --><br />
{{Article summary start}}<br />
{{Article summary text|Setup root filesystem LVM snapshot creation during system start.<br />
Such snapshots can be used for [[Full System Backup with tar|full system backups]]<br />
with minimal downtime or testing system updates with the option to revert<br />
them.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary text|{{pkg|lvm2}}, {{pkg|systemd}}}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|LVM}}<br />
{{Article summary wiki|Full System Backup with tar}}<br />
{{Article summary end}}<br />
<br />
<br />
== Prerequisites ==<br />
<br />
You need a system with [[LVM]] root filesystem and [[systemd]].<br />
Ensure that [[Lvm#Snapshots|LVM snapshots]] prerequisites are correctly setup.<br />
<br />
== Setup ==<br />
<br />
During system start a clean snapshot of the root volume is<br />
created using a new systemd service. Create<br />
{{ic|/etc/systemd/system/mk-lvm-snapshots.service}} containing:<br />
{{bc|[Unit]<br />
Description&#61;make LVM snapshots<br />
Requires&#61;local-fs-pre.target<br />
DefaultDependencies&#61;no<br />
Conflicts&#61;shutdown.target<br />
After&#61;local-fs-pre.target<br />
Before&#61;local-fs.target<br />
<br />
[Install]<br />
WantedBy&#61;make-snapshots.target<br />
<br />
[Service]<br />
Type&#61;oneshot<br />
ExecStart&#61;/usr/sbin/lvcreate -L10G -n snap-root -s lvmvolume/root}}<br />
<br />
Adapt the {{ic|lvcreate}} command to match your root volume group and volume name.<br />
Adjust the snapshot size if necessary. If additional filesystems should be snapshotted<br />
during startup you may extend the {{ic|ExecStart}} property with addtional lvcreate commands,<br />
separated with {{ic| ; }}.<br />
<br />
{{Note|You should test the {{ic|lvcreate}} command in the running system until it works as desired.<br />
Remove the test snapshots with {{ic|lvremove}}.}}<br />
<br />
Create a new systemd target {{ic|/etc/systemd/system/make-snapshots.target}}:<br />
{{bc|[Unit]<br />
Description&#61;Make Snapshots<br />
Requires&#61;multi-user.target}}<br />
Adapt the base target, if {{ic|multi-user.target}} is not your default target.<br />
<br />
Enable the new service with {{ic|# systemctl enable mk-lvm-snapshots.service}}.<br />
<br />
If the system is started with the new target, LVM snapshot(s) are created just after mounting the local filesystems.<br />
To get a [[grub]] menu entry starting this target create {{ic|/boot/grub/custom.cfg}} based on the<br />
{{ic|grub.cfg}} entry for your normal startup. The kernel command line is extended to start the new<br />
{{ic|make-snapshots.target}}:<br />
{{bc|### make snapshots ###<br />
menuentry 'Arch GNU/Linux, make snapshots' --class arch --class gnu-linux --class gnu --class os {<br />
...<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root&#61;/dev/mapper/lvmvolume-root ro systemd.unit&#61;make-snapshots.target<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
} }}<br />
<br />
Remember to adjust {{ic|custom.cfg}} if {{ic|grub.cfg}} changes.<br />
<br />
After restarting the system with this grub entry {{ic|# lvs}} should show up the newly created snapshot.<br />
<br />
{{Tip|To get the messages of the new service use<br />
{{ic|# journalctl -u mk-lvm-snapshots.service}}.}}<br />
<br />
== Usage ==<br />
<br />
=== Backup ===<br />
To use this functionality for a full system backup, restart your system with the snapshot creation target.<br />
Mount the snapshot volume (and further volumes, if required), preferably using the read only (<tt>-o</tt>) option.<br />
Then backup your system, for example with tar as described in [[Full_System_Backup_with_tar]].<br />
<br />
During backup you can continue to use your system normally, since all changes to your regular volumes are invisible in<br />
the snapshots. Do not forget to delete the snapshot volume after the backup &ndash; changes to your regular volume will<br />
use up space in the snapshot due to the copy-on-write operations. If the snapshot space becomes fully used, and LVM<br />
is not able to automatically grow the snapshot, LVM will deny further writes to your regular volumes or drop the<br />
snapshot, which should be avoided.<br />
<br />
=== Revert updates ===<br />
An other use for LVM snapshots is testing and reverting of updates. In this case create a snapshot for the system<br />
in a known good state and perform updates or changes afterwards.<br />
<br />
If you want to permantly stick to the updates just drop the snapshot. If you want to revert to the snapshotted<br />
state issue a {{ic|# lvchange --merge}} for the snapshot. During the next restart of the system the snapshot<br />
is merged back into your regular volume. All changes to the volume happened after the snapshot are undone.<br />
<br />
== Known issues ==<br />
Due to [https://bugzilla.redhat.com/show_bug.cgi?id=681582 bug 681582] shutting down the system with active<br />
snapshots may hang for some time.</div>Freejackhttps://wiki.archlinux.org/index.php?title=Create_root_filesystem_snapshots_with_LVM&diff=255368Create root filesystem snapshots with LVM2013-04-27T17:28:22Z<p>Freejack: /* Setup */</p>
<hr />
<div><!-- [[Category:System recovery]] --><br />
{{Article summary start}}<br />
{{Article summary text|Setup root filesystem LVM snapshot creation during system start.<br />
Such snapshots can be used for [[Full System Backup with tar|full system backups]]<br />
with minimal downtime or testing system updates with the option to revert<br />
them.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary text|{{pkg|lvm2}}, {{pkg|systemd}}}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|LVM}}<br />
{{Article summary wiki|Full System Backup with tar}}<br />
{{Article summary end}}<br />
<br />
<br />
== Prerequisites ==<br />
<br />
You need a system with [[LVM]] root filesystem and [[systemd]].<br />
Ensure that [[Lvm#Snapshots|LVM snapshots]] prerequisites are correctly setup.<br />
<br />
== Setup ==<br />
<br />
During system start a clean snapshot of the root volume is<br />
created using a new systemd service. Create<br />
{{ic|/etc/systemd/system/mk-lvm-snapshots.service}} containing:<br />
{{bc|[Unit]<br />
Description&#61;make LVM snapshots<br />
Requires&#61;local-fs-pre.target<br />
DefaultDependencies&#61;no<br />
Conflicts&#61;shutdown.target<br />
After&#61;local-fs-pre.target<br />
Before&#61;local-fs.target<br />
<br />
[Install]<br />
WantedBy&#61;make-snapshots.target<br />
<br />
[Service]<br />
Type&#61;oneshot<br />
ExecStart&#61;/usr/sbin/lvcreate -L10G -n snap-root -s lvmvolume/root}}<br />
<br />
Adapt the {{ic|lvcreate}} command to match your root volume group and volume name.<br />
Adjust the snapshot size if necessary. If additional filesystems should be snapshotted<br />
during startup you may extend the {{ic|ExecStart}} property with addtional lvcreate commands,<br />
separated with {{ic| ; }}.<br />
<br />
{{Note|You should test the {{ic|lvcreate}} command in the running system until it works as desired.<br />
Remove the test snapshots with {{ic|lvremove}}.}}<br />
<br />
Create a new systemd target {{ic|/etc/systemd/system/make-snapshots.target}}:<br />
{{bc|[Unit]<br />
Description&#61;Make Snapshots<br />
Requires&#61;multi-user.target}}<br />
Adapt the base target, if {{ic|multi-user.target}} is not your default target.<br />
<br />
Enable the new service with {{ic|# systemctl enable mk-lvm-snapshots.service}}.<br />
<br />
If the system is started with the new target, LVM snapshot(s) are created just after mounting the local filesystems.<br />
To get a [[grub]] menu entry starting this target create {{ic|/boot/grub/custom.cfg}} based on the<br />
{{ic|grub.cfg}} entry for your normal startup. The kernel command line is extended to start the new<br />
{{ic|make-snapshots.target}}:<br />
{{bc|### make snapshots ###<br />
menuentry 'Arch GNU/Linux, make snapshots' --class arch --class gnu-linux --class gnu --class os {<br />
...<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root&#61;/dev/mapper/lvmvolume-root ro systemd.unit&#61;make-snapshots.target<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
} }}<br />
<br />
Remember to adjust {{ic|custom.cfg}} if {{ic|grub.cfg}} changes.<br />
<br />
After restarting the system with this grub entry {{ic|# lvs}} should show up the newly created snapshot.<br />
<br />
{{Tip|To get the messages of the new service use<br />
{{ic|# journalctl -u mk-lvm-snapshots.service}}.}}<br />
<br />
== Usage ==<br />
<br />
=== Backup ===<br />
To use this functionality for a full system backup, restart your system with the snapshot creation target.<br />
Mount the snapshot volume (and further volumes, if required), preferably using the read only (<tt>-o</tt>) option.<br />
Then backup your system, for example with tar as described in [[Full_System_Backup_with_tar]].<br />
<br />
During backup you can continue to use your system normally, since all changes to your regular volumes are invisible in<br />
the snapshots. Do not forget to delete the snapshot volume after the backup &ndash; changes to your regular volume will<br />
use up space in the snapshot due to the copy-on-write operations. If the snapshot space becomes fully used LVM<br />
will deny further writes to your regular volumes, which should be avoided.<br />
<br />
=== Revert updates ===<br />
An other use for LVM snapshots is testing and reverting of updates. In this case create a snapshot for the system<br />
in a known good state and perform updates or changes afterwards.<br />
<br />
If you want to permantly stick to the updates just drop the snapshot. If you want to revert to the snapshotted<br />
state issue a {{ic|# lvchange --merge}} for the snapshot. During the next restart of the system the snapshot<br />
is merged back into your regular volume. All changes to the volume happened after the snapshot are undone.<br />
<br />
== Known issues ==<br />
Due to [https://bugzilla.redhat.com/show_bug.cgi?id=681582 bug 681582] shutting down the system with active<br />
snapshots may hang for some time.</div>Freejackhttps://wiki.archlinux.org/index.php?title=Create_root_filesystem_snapshots_with_LVM&diff=255367Create root filesystem snapshots with LVM2013-04-27T17:27:41Z<p>Freejack: /* Setup */</p>
<hr />
<div><!-- [[Category:System recovery]] --><br />
{{Article summary start}}<br />
{{Article summary text|Setup root filesystem LVM snapshot creation during system start.<br />
Such snapshots can be used for [[Full System Backup with tar|full system backups]]<br />
with minimal downtime or testing system updates with the option to revert<br />
them.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary text|{{pkg|lvm2}}, {{pkg|systemd}}}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|LVM}}<br />
{{Article summary wiki|Full System Backup with tar}}<br />
{{Article summary end}}<br />
<br />
<br />
== Prerequisites ==<br />
<br />
You need a system with [[LVM]] root filesystem and [[systemd]].<br />
Ensure that [[Lvm#Snapshots|LVM snapshots]] prerequisites are correctly setup.<br />
<br />
== Setup ==<br />
<br />
During system start a clean snapshot of the root volume is<br />
created using a new systemd service. Create<br />
{{ic|/etc/systemd/system/mk-lvm-snapshots.service}} containing:<br />
{{bc|[Unit]<br />
Description&#61;make LVM snapshots<br />
Requires&#61;local-fs-pre.target<br />
DefaultDependencies&#61;no<br />
Conflicts&#61;shutdown.target<br />
After&#61;local-fs-pre.target<br />
Before&#61;local-fs.target<br />
<br />
[Install]<br />
WantedBy&#61;make-snapshots.target<br />
<br />
[Service]<br />
Type&#61;oneshot<br />
ExecStart&#61;/usr/sbin/lvcreate -L10G -n snap-root -s lvmvolume/root}}<br />
<br />
Adapt the {{ic|lvcreate}} command to match your root volume group and volume name.<br />
Adjust the snapshot size if necessary. If additional filesystems should be snapshotted<br />
during startup you may extend the {{ic|ExecStart}} property with addtional lvcreate commands,<br />
separated with {{ic| ; }}.<br />
<br />
{{Note|You should test the {{ic|lvcreate}} command in the running system until it works as desired.<br />
Remove the test snapshots with {{ic|lvremove}}.}}<br />
<br />
Create a new systemd target {{ic|/etc/systemd/system/make-snapshots.target}} with this service:<br />
{{bc|[Unit]<br />
Description&#61;Make Snapshots<br />
Requires&#61;multi-user.target}}<br />
Adapt the base target, if {{ic|multi-user.target}} is not your default target.<br />
<br />
Enable the new service with {{ic|# systemctl enable mk-lvm-snapshots.service}}.<br />
<br />
If the system is started with the new target, LVM snapshot(s) are created just after mounting the local filesystems.<br />
To get a [[grub]] menu entry starting this target create {{ic|/boot/grub/custom.cfg}} based on the<br />
{{ic|grub.cfg}} entry for your normal startup. The kernel command line is extended to start the new<br />
{{ic|make-snapshots.target}}:<br />
{{bc|### make snapshots ###<br />
menuentry 'Arch GNU/Linux, make snapshots' --class arch --class gnu-linux --class gnu --class os {<br />
...<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root&#61;/dev/mapper/lvmvolume-root ro systemd.unit&#61;make-snapshots.target<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
} }}<br />
<br />
Remember to adjust {{ic|custom.cfg}} if {{ic|grub.cfg}} changes.<br />
<br />
After restarting the system with this grub entry {{ic|# lvs}} should show up the newly created snapshot.<br />
<br />
{{Tip|To get the messages of the new service use<br />
{{ic|# journalctl -u mk-lvm-snapshots.service}}.}}<br />
<br />
== Usage ==<br />
<br />
=== Backup ===<br />
To use this functionality for a full system backup, restart your system with the snapshot creation target.<br />
Mount the snapshot volume (and further volumes, if required), preferably using the read only (<tt>-o</tt>) option.<br />
Then backup your system, for example with tar as described in [[Full_System_Backup_with_tar]].<br />
<br />
During backup you can continue to use your system normally, since all changes to your regular volumes are invisible in<br />
the snapshots. Do not forget to delete the snapshot volume after the backup &ndash; changes to your regular volume will<br />
use up space in the snapshot due to the copy-on-write operations. If the snapshot space becomes fully used LVM<br />
will deny further writes to your regular volumes, which should be avoided.<br />
<br />
=== Revert updates ===<br />
An other use for LVM snapshots is testing and reverting of updates. In this case create a snapshot for the system<br />
in a known good state and perform updates or changes afterwards.<br />
<br />
If you want to permantly stick to the updates just drop the snapshot. If you want to revert to the snapshotted<br />
state issue a {{ic|# lvchange --merge}} for the snapshot. During the next restart of the system the snapshot<br />
is merged back into your regular volume. All changes to the volume happened after the snapshot are undone.<br />
<br />
== Known issues ==<br />
Due to [https://bugzilla.redhat.com/show_bug.cgi?id=681582 bug 681582] shutting down the system with active<br />
snapshots may hang for some time.</div>Freejackhttps://wiki.archlinux.org/index.php?title=Create_root_filesystem_snapshots_with_LVM&diff=255366Create root filesystem snapshots with LVM2013-04-27T17:21:39Z<p>Freejack: /* Setup */</p>
<hr />
<div><!-- [[Category:System recovery]] --><br />
{{Article summary start}}<br />
{{Article summary text|Setup root filesystem LVM snapshot creation during system start.<br />
Such snapshots can be used for [[Full System Backup with tar|full system backups]]<br />
with minimal downtime or testing system updates with the option to revert<br />
them.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary text|{{pkg|lvm2}}, {{pkg|systemd}}}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|LVM}}<br />
{{Article summary wiki|Full System Backup with tar}}<br />
{{Article summary end}}<br />
<br />
<br />
== Prerequisites ==<br />
<br />
You need a system with [[LVM]] root filesystem and [[systemd]].<br />
Ensure that [[Lvm#Snapshots|LVM snapshots]] prerequisites are correctly setup.<br />
<br />
== Setup ==<br />
<br />
During system start a clean snapshot of the root volume is<br />
created using a new systemd service. Create<br />
{{ic|/etc/systemd/system/mk-lvm-snapshots.service}} containing:<br />
{{bc|[Unit]<br />
Description&#61;make LVM snapshots<br />
Requires&#61;local-fs-pre.target<br />
DefaultDependencies&#61;no<br />
Conflicts&#61;shutdown.target<br />
After&#61;local-fs-pre.target<br />
Before&#61;local-fs.target<br />
<br />
[Install]<br />
WantedBy&#61;make-snapshots.target<br />
<br />
[Service]<br />
Type&#61;oneshot<br />
ExecStart&#61;/usr/sbin/lvcreate -L10G -n snap-root -s lvmvolume/root}}<br />
<br />
Adapt the {{ic|lvcreate}} command to match your root volume group and volume name.<br />
Adjust the snapshot size if necessary. If additional filesystems should be snapshotted<br />
during startup you may extend the {{ic|ExecStart}} property with addtional lvcreate commands,<br />
separated with {{ic| ; }}.<br />
<br />
Create a new systemd target {{ic|/etc/systemd/system/make-snapshots.target}} with this service:<br />
{{bc|[Unit]<br />
Description&#61;Make Snapshots<br />
Requires&#61;multi-user.target}}<br />
Adapt the base target, if {{ic|multi-user.target}} is not your default target.<br />
<br />
Enable the new service with {{ic|# systemctl enable mk-lvm-snapshots.service}}.<br />
<br />
If the system is started with the new target, LVM snapshot(s) are created just after mounting the local filesystems.<br />
To get a [[grub]] menu entry starting this target create {{ic|/boot/grub/custom.cfg}} based on the<br />
{{ic|grub.cfg}} entry for your normal startup. The kernel command line is extended to start the new<br />
{{ic|make-snapshots.target}}:<br />
{{bc|### make snapshots ###<br />
menuentry 'Arch GNU/Linux, make snapshots' --class arch --class gnu-linux --class gnu --class os {<br />
...<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root&#61;/dev/mapper/lvmvolume-root ro systemd.unit&#61;make-snapshots.target<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
} }}<br />
<br />
Remember to adjust {{ic|custom.cfg}} if {{ic|grub.cfg}} changes.<br />
<br />
After restarting the system with this grub entry {{ic|# lvs}} should show up the newly created snapshot.<br />
<br />
{{Tip|To get the messages of the new service use<br />
{{ic|# journalctl -u mk-lvm-snapshots.service}}.}}<br />
<br />
== Usage ==<br />
<br />
=== Backup ===<br />
To use this functionality for a full system backup, restart your system with the snapshot creation target.<br />
Mount the snapshot volume (and further volumes, if required), preferably using the read only (<tt>-o</tt>) option.<br />
Then backup your system, for example with tar as described in [[Full_System_Backup_with_tar]].<br />
<br />
During backup you can continue to use your system normally, since all changes to your regular volumes are invisible in<br />
the snapshots. Do not forget to delete the snapshot volume after the backup &ndash; changes to your regular volume will<br />
use up space in the snapshot due to the copy-on-write operations. If the snapshot space becomes fully used LVM<br />
will deny further writes to your regular volumes, which should be avoided.<br />
<br />
=== Revert updates ===<br />
An other use for LVM snapshots is testing and reverting of updates. In this case create a snapshot for the system<br />
in a known good state and perform updates or changes afterwards.<br />
<br />
If you want to permantly stick to the updates just drop the snapshot. If you want to revert to the snapshotted<br />
state issue a {{ic|# lvchange --merge}} for the snapshot. During the next restart of the system the snapshot<br />
is merged back into your regular volume. All changes to the volume happened after the snapshot are undone.<br />
<br />
== Known issues ==<br />
Due to [https://bugzilla.redhat.com/show_bug.cgi?id=681582 bug 681582] shutting down the system with active<br />
snapshots may hang for some time.</div>Freejackhttps://wiki.archlinux.org/index.php?title=Create_root_filesystem_snapshots_with_LVM&diff=255365Create root filesystem snapshots with LVM2013-04-27T17:20:55Z<p>Freejack: /* Prerequisites */</p>
<hr />
<div><!-- [[Category:System recovery]] --><br />
{{Article summary start}}<br />
{{Article summary text|Setup root filesystem LVM snapshot creation during system start.<br />
Such snapshots can be used for [[Full System Backup with tar|full system backups]]<br />
with minimal downtime or testing system updates with the option to revert<br />
them.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary text|{{pkg|lvm2}}, {{pkg|systemd}}}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|LVM}}<br />
{{Article summary wiki|Full System Backup with tar}}<br />
{{Article summary end}}<br />
<br />
<br />
== Prerequisites ==<br />
<br />
You need a system with [[LVM]] root filesystem and [[systemd]].<br />
Ensure that [[Lvm#Snapshots|LVM snapshots]] prerequisites are correctly setup.<br />
<br />
== Setup ==<br />
<br />
During system start a clean snapshot of the root volume is<br />
created using a new service. Create<br />
{{ic|/etc/systemd/system/mk-lvm-snapshots.service}} containing:<br />
{{bc|[Unit]<br />
Description&#61;make LVM snapshots<br />
Requires&#61;local-fs-pre.target<br />
DefaultDependencies&#61;no<br />
Conflicts&#61;shutdown.target<br />
After&#61;local-fs-pre.target<br />
Before&#61;local-fs.target<br />
<br />
[Install]<br />
WantedBy&#61;make-snapshots.target<br />
<br />
[Service]<br />
Type&#61;oneshot<br />
ExecStart&#61;/usr/sbin/lvcreate -L10G -n snap-root -s lvmvolume/root}}<br />
<br />
Adapt the {{ic|lvcreate}} command to match your root volume group and volume name.<br />
Adjust the snapshot size if necessary. If additional filesystems should be snapshotted<br />
during startup you may extend the {{ic|ExecStart}} property with addtional lvcreate commands,<br />
separated with {{ic| ; }}.<br />
<br />
Create a new systemd target {{ic|/etc/systemd/system/make-snapshots.target}} with this service:<br />
{{bc|[Unit]<br />
Description&#61;Make Snapshots<br />
Requires&#61;multi-user.target}}<br />
Adapt the base target, if {{ic|multi-user.target}} is not your default target.<br />
<br />
Enable the new service with {{ic|# systemctl enable mk-lvm-snapshots.service}}.<br />
<br />
If the system is started with the new target, LVM snapshot(s) are created just after mounting the local filesystems.<br />
To get a [[grub]] menu entry starting this target create {{ic|/boot/grub/custom.cfg}} based on the<br />
{{ic|grub.cfg}} entry for your normal startup. The kernel command line is extended to start the new<br />
{{ic|make-snapshots.target}}:<br />
{{bc|### make snapshots ###<br />
menuentry 'Arch GNU/Linux, make snapshots' --class arch --class gnu-linux --class gnu --class os {<br />
...<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root&#61;/dev/mapper/lvmvolume-root ro systemd.unit&#61;make-snapshots.target<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
} }}<br />
<br />
Remember to adjust {{ic|custom.cfg}} if {{ic|grub.cfg}} changes.<br />
<br />
After restarting the system with this grub entry {{ic|# lvs}} should show up the newly created snapshot.<br />
<br />
{{Tip|To get the messages of the new service use<br />
{{ic|# journalctl -u mk-lvm-snapshots.service}}.}}<br />
<br />
<br />
== Usage ==<br />
<br />
=== Backup ===<br />
To use this functionality for a full system backup, restart your system with the snapshot creation target.<br />
Mount the snapshot volume (and further volumes, if required), preferably using the read only (<tt>-o</tt>) option.<br />
Then backup your system, for example with tar as described in [[Full_System_Backup_with_tar]].<br />
<br />
During backup you can continue to use your system normally, since all changes to your regular volumes are invisible in<br />
the snapshots. Do not forget to delete the snapshot volume after the backup &ndash; changes to your regular volume will<br />
use up space in the snapshot due to the copy-on-write operations. If the snapshot space becomes fully used LVM<br />
will deny further writes to your regular volumes, which should be avoided.<br />
<br />
=== Revert updates ===<br />
An other use for LVM snapshots is testing and reverting of updates. In this case create a snapshot for the system<br />
in a known good state and perform updates or changes afterwards.<br />
<br />
If you want to permantly stick to the updates just drop the snapshot. If you want to revert to the snapshotted<br />
state issue a {{ic|# lvchange --merge}} for the snapshot. During the next restart of the system the snapshot<br />
is merged back into your regular volume. All changes to the volume happened after the snapshot are undone.<br />
<br />
== Known issues ==<br />
Due to [https://bugzilla.redhat.com/show_bug.cgi?id=681582 bug 681582] shutting down the system with active<br />
snapshots may hang for some time.</div>Freejackhttps://wiki.archlinux.org/index.php?title=Create_root_filesystem_snapshots_with_LVM&diff=255364Create root filesystem snapshots with LVM2013-04-27T17:19:32Z<p>Freejack: </p>
<hr />
<div><!-- [[Category:System recovery]] --><br />
{{Article summary start}}<br />
{{Article summary text|Setup root filesystem LVM snapshot creation during system start.<br />
Such snapshots can be used for [[Full System Backup with tar|full system backups]]<br />
with minimal downtime or testing system updates with the option to revert<br />
them.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary text|{{pkg|lvm2}}, {{pkg|systemd}}}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|LVM}}<br />
{{Article summary wiki|Full System Backup with tar}}<br />
{{Article summary end}}<br />
<br />
<br />
== Prerequisites ==<br />
<br />
You need a system with [[LVM]] root filesystem and [[systemd]].<br />
Check if [[Lvm#Snapshots|LVM snapshots]] are correctly setup.<br />
<br />
<br />
== Setup ==<br />
<br />
During system start a clean snapshot of the root volume is<br />
created using a new service. Create<br />
{{ic|/etc/systemd/system/mk-lvm-snapshots.service}} containing:<br />
{{bc|[Unit]<br />
Description&#61;make LVM snapshots<br />
Requires&#61;local-fs-pre.target<br />
DefaultDependencies&#61;no<br />
Conflicts&#61;shutdown.target<br />
After&#61;local-fs-pre.target<br />
Before&#61;local-fs.target<br />
<br />
[Install]<br />
WantedBy&#61;make-snapshots.target<br />
<br />
[Service]<br />
Type&#61;oneshot<br />
ExecStart&#61;/usr/sbin/lvcreate -L10G -n snap-root -s lvmvolume/root}}<br />
<br />
Adapt the {{ic|lvcreate}} command to match your root volume group and volume name.<br />
Adjust the snapshot size if necessary. If additional filesystems should be snapshotted<br />
during startup you may extend the {{ic|ExecStart}} property with addtional lvcreate commands,<br />
separated with {{ic| ; }}.<br />
<br />
Create a new systemd target {{ic|/etc/systemd/system/make-snapshots.target}} with this service:<br />
{{bc|[Unit]<br />
Description&#61;Make Snapshots<br />
Requires&#61;multi-user.target}}<br />
Adapt the base target, if {{ic|multi-user.target}} is not your default target.<br />
<br />
Enable the new service with {{ic|# systemctl enable mk-lvm-snapshots.service}}.<br />
<br />
If the system is started with the new target, LVM snapshot(s) are created just after mounting the local filesystems.<br />
To get a [[grub]] menu entry starting this target create {{ic|/boot/grub/custom.cfg}} based on the<br />
{{ic|grub.cfg}} entry for your normal startup. The kernel command line is extended to start the new<br />
{{ic|make-snapshots.target}}:<br />
{{bc|### make snapshots ###<br />
menuentry 'Arch GNU/Linux, make snapshots' --class arch --class gnu-linux --class gnu --class os {<br />
...<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root&#61;/dev/mapper/lvmvolume-root ro systemd.unit&#61;make-snapshots.target<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
} }}<br />
<br />
Remember to adjust {{ic|custom.cfg}} if {{ic|grub.cfg}} changes.<br />
<br />
After restarting the system with this grub entry {{ic|# lvs}} should show up the newly created snapshot.<br />
<br />
{{Tip|To get the messages of the new service use<br />
{{ic|# journalctl -u mk-lvm-snapshots.service}}.}}<br />
<br />
<br />
== Usage ==<br />
<br />
=== Backup ===<br />
To use this functionality for a full system backup, restart your system with the snapshot creation target.<br />
Mount the snapshot volume (and further volumes, if required), preferably using the read only (<tt>-o</tt>) option.<br />
Then backup your system, for example with tar as described in [[Full_System_Backup_with_tar]].<br />
<br />
During backup you can continue to use your system normally, since all changes to your regular volumes are invisible in<br />
the snapshots. Do not forget to delete the snapshot volume after the backup &ndash; changes to your regular volume will<br />
use up space in the snapshot due to the copy-on-write operations. If the snapshot space becomes fully used LVM<br />
will deny further writes to your regular volumes, which should be avoided.<br />
<br />
=== Revert updates ===<br />
An other use for LVM snapshots is testing and reverting of updates. In this case create a snapshot for the system<br />
in a known good state and perform updates or changes afterwards.<br />
<br />
If you want to permantly stick to the updates just drop the snapshot. If you want to revert to the snapshotted<br />
state issue a {{ic|# lvchange --merge}} for the snapshot. During the next restart of the system the snapshot<br />
is merged back into your regular volume. All changes to the volume happened after the snapshot are undone.<br />
<br />
== Known issues ==<br />
Due to [https://bugzilla.redhat.com/show_bug.cgi?id=681582 bug 681582] shutting down the system with active<br />
snapshots may hang for some time.</div>Freejackhttps://wiki.archlinux.org/index.php?title=Create_root_filesystem_snapshots_with_LVM&diff=255350Create root filesystem snapshots with LVM2013-04-27T15:05:13Z<p>Freejack: </p>
<hr />
<div><!-- [[Category:System recovery]] --><br />
{{Article summary start}}<br />
{{Article summary text|This article will show you how to setup LVM snapshot creation during system start.<br />
Such snapshots can be used for [[Full System Backup with tar|full system backups]]<br />
with minimal downtime or testing system updates with the option to revert<br />
them (restore point).}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary text|{{pkg|lvm2}}, {{pkg|systemd}}}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|LVM}}<br />
{{Article summary wiki|Full System Backup with tar}}<br />
{{Article summary end}}<br />
<br />
<br />
== Prerequisites ==<br />
<br />
You need a system with [[LVM]] root filesystem and [[systemd]].<br />
Check if [[Lvm#Snapshots|LVM snapshots]] are correctly setup.<br />
<br />
<br />
== Setup ==<br />
<br />
During system start a clean snapshot of the root volume is<br />
created using a new service. Create<br />
{{ic|/etc/systemd/system/mk-lvm-snapshots.service}} containing:<br />
{{bc|[Unit]<br />
Description&#61;make LVM snapshots<br />
Requires&#61;local-fs-pre.target<br />
DefaultDependencies&#61;no<br />
Conflicts&#61;shutdown.target<br />
After&#61;local-fs-pre.target<br />
Before&#61;local-fs.target<br />
<br />
[Install]<br />
WantedBy&#61;make-snapshots.target<br />
<br />
[Service]<br />
Type&#61;oneshot<br />
ExecStart&#61;/usr/sbin/lvcreate -L10G -n snap-root -s lvmvolume/root}}<br />
<br />
Adapt the {{ic|lvcreate}} command to match your root volume group and volume name.<br />
Adjust the snapshot size if necessary. If additional filesystems should be snapshotted<br />
during startup you may extend the {{ic|ExecStart}} property with addtional lvcreate commands,<br />
separated with {{ic| ; }}.<br />
<br />
Create a new systemd target {{ic|/etc/systemd/system/make-snapshots.target}} with this service:<br />
{{bc|[Unit]<br />
Description&#61;Make Snapshots<br />
Requires&#61;multi-user.target}}<br />
Adapt the base target, if {{ic|multi-user.target}} is not your default target.<br />
<br />
Enable the new service with {{ic|# systemctl enable mk-lvm-snapshots.service}}.<br />
<br />
If the system is started with the new target, LVM snapshot(s) are created just after mounting the local filesystems.<br />
To get a [[grub]] menu entry starting this target create {{ic|/boot/grub/custom.cfg}} based on the<br />
{{ic|grub.cfg}} entry for your normal startup. The kernel command line is extended to start the new<br />
{{ic|make-snapshots.target}}:<br />
{{bc|### make snapshots ###<br />
menuentry 'Arch GNU/Linux, make snapshots' --class arch --class gnu-linux --class gnu --class os {<br />
...<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root&#61;/dev/mapper/lvmvolume-root ro systemd.unit&#61;make-snapshots.target<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
} }}<br />
<br />
Remember to adjust {{ic|custom.cfg}} if {{ic|grub.cfg}} changes.<br />
<br />
After restarting the system with this grub entry {{ic|# lvs}} should show up the newly created snapshot.<br />
<br />
{{Tip|To get the messages of the new service use<br />
{{ic|# journalctl -u mk-lvm-snapshots.service}}.}}<br />
<br />
<br />
== Usage ==<br />
<br />
=== Backup ===<br />
To use this functionality for a full system backup, restart your system with the snapshot creation target.<br />
Mount the snapshot volume (and further volumes, if required), preferably using the read only (<tt>-o</tt>) option.<br />
Then backup your system, for example with tar as described in [[Full_System_Backup_with_tar]].<br />
<br />
During backup you can continue to use your system normally, since all changes to your regular volumes are invisible in<br />
the snapshots. Do not forget to delete the snapshot volume after the backup &ndash; changes to your regular volume will<br />
use up space in the snapshot due to the copy-on-write operations. If the snapshot space becomes fully used LVM<br />
will deny further writes to your regular volumes, which should be avoided.<br />
<br />
=== Revert updates ===<br />
An other use for LVM snapshots is testing and reverting of updates. In this case create a snapshot for the system<br />
in a known good state and perform updates or changes afterwards.<br />
<br />
If you want to permantly stick to the updates just drop the snapshot. If you want to revert to the snapshotted<br />
state issue a {{ic|# lvchange --merge}} for the snapshot. During the next restart of the system the snapshot<br />
is merged back into your regular volume. All changes to the volume happened after the snapshot are undone.<br />
<br />
== Known issues ==<br />
Due to [https://bugzilla.redhat.com/show_bug.cgi?id=681582 bug 681582] shutting down the system with active<br />
snapshots may hang for some time.</div>Freejackhttps://wiki.archlinux.org/index.php?title=Create_root_filesystem_snapshots_with_LVM&diff=255347Create root filesystem snapshots with LVM2013-04-27T14:13:04Z<p>Freejack: </p>
<hr />
<div><!-- [[Category:System recovery]] --><br />
{{Article summary start}}<br />
{{Article summary text|This article will show you how to setup LVM snapshot creation during system start.<br />
Such snapshots can be used for [[Full System Backup with tar|full system backups]]<br />
with minimal downtime or testing system updates with the option to revert<br />
them (restore point).}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary text|{{pkg|lvm2}}, {{pkg|systemd}}}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|LVM}}<br />
{{Article summary wiki|Full System Backup with tar}}<br />
{{Article summary end}}<br />
<br />
<br />
== Prerequisites ==<br />
<br />
You need a system with [[LVM]] root filesystem and [[systemd]].<br />
Check if [[Lvm#Snapshots|LVM snapshots]] are correctly setup.<br />
<br />
<br />
== Setup ==<br />
<br />
During system start a clean snapshot of the root volume is<br />
created using a new service. Create<br />
{{ic|/etc/systemd/system/mk-lvm-snapshots.service}} containing:<br />
{{bc|[Unit]<br />
Descriptionm&#61;ake LVM snapshots<br />
Requires&#61;local-fs-pre.target<br />
DefaultDependencies&#61;no<br />
Conflicts&#61;shutdown.target<br />
After&#61;local-fs-pre.target<br />
Before&#61;local-fs.target<br />
<br />
[Install]<br />
WantedBy&#61;make-snapshots.target<br />
<br />
[Service]<br />
Type&#61;oneshot<br />
ExecStart&#61;/usr/sbin/lvcreate -L10G -n snap-root -s lvmvolume/root}}<br />
<br />
Adapt the {{ic|lvcreate}} command to match your root volume group and volume name.<br />
Adjust the snapshot size if necessary.<br />
<br />
Create a new systemd target {{ic|/etc/systemd/system/make-snapshots.target}} with this service:<br />
{{bc|[Unit]<br />
Description&#61;Make Snapshots<br />
Requires&#61;multi-user.target}}<br />
Adapt the base target, if {{ic|multi-user.target}} is not your default target.<br />
<br />
Enable the new service with {{ic|systemctl enable mk-lvm-snapshots.service}}.<br />
<br />
If the system is started with the new target, LVM snapshot(s) are created just after mounting the local filesystems.<br />
To get a [[grub]] menu entry starting this target create {{ic|/boot/grub/custom.cfg}} based on the<br />
{{ic|grub.cfg}} entry for your normal startup. The kernel command line is extended to start the new<br />
{{ic|make-snapshots.target}}:<br />
{{bc|### make snapshots ###<br />
menuentry 'Arch GNU/Linux, make snapshots' --class arch --class gnu-linux --class gnu --class os {<br />
...<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root&#61;/dev/mapper/lvmvolume-root ro systemd.unit&#61;make-snapshots.target<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
} }}<br />
<br />
Remember to adjust {{ic|custom.cfg}} if {{ic|grub.cfg}} changes.<br />
<br />
After restarting the system with this grub entry {{ic|lvs}} should show up the newly created snapshot.<br />
<br />
{{Tip|To get the messages of the new service use<br />
{{ic|journalctl -u mk-lvm-snapshots.service}}.}}<br />
<br />
<br />
== Usage ==<br />
<br />
=== Backup ===<br />
To use this functionality for a full system backup, restart your system with the snapshot creation target.<br />
Mount the snapshot volume (and further volumes, if required), preferably using the read only (<tt>-o</tt>) option.<br />
Then backup your system, for example with tar as described in [[Full_System_Backup_with_tar]].<br />
<br />
During backup you can continue to use your system normally, since all changes to your regular volumes are invisible in<br />
the snapshots. Do not forget to delete the snapshot volume after the backup -- changes to your regular volume will<br />
use up space in the snapshot due to the copy-on-write operations. If the snapshot space becomes fully used LVM<br />
will deny further writes to your regular volumes, which should be avoided.<br />
<br />
=== Revert updates ===<br />
An other use for LVM snapshots is testing and reverting of updates. In this case create a snapshot for the system<br />
in a known good state and perform updates or changes afterwards.<br />
<br />
If you want to permantly stick to the updates just drop the snapshot. If you want to revert to the snapshotted<br />
state issue a {{ic|lvchange --merge}} for the snapshot. During the next restart of the system the snapshot<br />
is merged back into your regular volume. All changes to the volume happened after the snapshot are undone.<br />
<br />
== Known issues ==<br />
Due to [https://bugzilla.redhat.com/show_bug.cgi?id=681582 bug 681582] shutting down the system with active<br />
snapshots may hang for some time.</div>Freejackhttps://wiki.archlinux.org/index.php?title=Create_root_filesystem_snapshots_with_LVM&diff=255346Create root filesystem snapshots with LVM2013-04-27T14:09:01Z<p>Freejack: </p>
<hr />
<div><!-- [[Category:System recovery]] --><br />
{{Article summary start}}<br />
{{Article summary text|This article will show you how to setup LVM snapshot creation during system start.<br />
Such snapshots can be used for [[Full System Backup with tar|full system backups]]<br />
with minimal downtime or testing system updates or changes with the option to revert<br />
them.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary text|{{pkg|lvm2}}, {{pkg|systemd}}}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|LVM}}<br />
{{Article summary wiki|Full System Backup with tar}}<br />
{{Article summary end}}<br />
<br />
<br />
== Prerequisites ==<br />
<br />
You need a system with [[LVM]] root filesystem and [[systemd]].<br />
Check if [[Lvm#Snapshots|LVM snapshots]] are correctly setup.<br />
<br />
<br />
== Setup ==<br />
<br />
During system start a clean snapshot of the root volume is<br />
created using a new service. Create<br />
{{ic|/etc/systemd/system/mk-lvm-snapshots.service}} containing:<br />
{{bc|[Unit]<br />
Descriptionm&#61;ake LVM snapshots<br />
Requires&#61;local-fs-pre.target<br />
DefaultDependencies&#61;no<br />
Conflicts&#61;shutdown.target<br />
After&#61;local-fs-pre.target<br />
Before&#61;local-fs.target<br />
<br />
[Install]<br />
WantedBy&#61;make-snapshots.target<br />
<br />
[Service]<br />
Type&#61;oneshot<br />
ExecStart&#61;/usr/sbin/lvcreate -L10G -n snap-root -s lvmvolume/root}}<br />
<br />
Adapt the {{ic|lvcreate}} command to match your root volume group and volume name.<br />
Adjust the snapshot size if necessary.<br />
<br />
Create a new systemd target {{ic|/etc/systemd/system/make-snapshots.target}} with this service:<br />
{{bc|[Unit]<br />
Description&#61;Make Snapshots<br />
Requires&#61;multi-user.target}}<br />
Adapt the base target, if {{ic|multi-user.target}} is not your default target.<br />
<br />
Enable the new service with {{ic|systemctl enable mk-lvm-snapshots.service}}.<br />
<br />
If the system is started with the new target, LVM snapshot(s) are created just after mounting the local filesystems.<br />
To get a [[grub]] menu entry starting this target create {{ic|/boot/grub/custom.cfg}} based on the<br />
{{ic|grub.cfg}} entry for your normal startup. The kernel command line is extended to start the new<br />
{{ic|make-snapshots.target}}:<br />
{{bc|### make snapshots ###<br />
menuentry 'Arch GNU/Linux, make snapshots' --class arch --class gnu-linux --class gnu --class os {<br />
...<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root&#61;/dev/mapper/lvmvolume-root ro systemd.unit&#61;make-snapshots.target<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
} }}<br />
<br />
Remember to adjust {{ic|custom.cfg}} if {{ic|grub.cfg}} changes.<br />
<br />
After restarting the system with this grub entry {{ic|lvs}} should show up the newly created snapshot.<br />
<br />
{{Tip|To get the messages of the new service use<br />
{{ic|journalctl -u mk-lvm-snapshots.service}}.}}<br />
<br />
<br />
== Usage ==<br />
<br />
=== Backup ===<br />
To use this functionality for a full system backup, restart your system with the snapshot creation target.<br />
Mount the snapshot volume (and further volumes, if required), preferably using the read only (<tt>-o</tt>) option.<br />
Then backup your system, for example with tar as described in [[Full_System_Backup_with_tar]].<br />
<br />
During backup you can continue to use your system normally, since all changes to your regular volumes are invisible in<br />
the snapshots. Do not forget to delete the snapshot volume after the backup -- changes to your regular volume will<br />
use up space in the snapshot due to the copy-on-write operations. If the snapshot space becomes fully used LVM<br />
will deny further writes to your regular volumes, which should be avoided.<br />
<br />
=== Revert updates ===<br />
An other use for LVM snapshots is testing and reverting of updates. In this case create a snapshot for the system<br />
in a known good state and perform updates or changes afterwards.<br />
<br />
If you want to permantly stick to the updates just drop the snapshot. If you want to revert to the snapshotted<br />
state issue a {{ic|lvchange --merge}} for the snapshot. During the next restart of the system the snapshot<br />
is merged back into your regular volume. All changes to the volume happened after the snapshot are undone.<br />
<br />
== Known issues ==<br />
Due to [https://bugzilla.redhat.com/show_bug.cgi?id=681582 bug 681582] shutting down the system with active<br />
snapshots may hang for some time.</div>Freejackhttps://wiki.archlinux.org/index.php?title=Create_root_filesystem_snapshots_with_LVM&diff=255345Create root filesystem snapshots with LVM2013-04-27T14:07:05Z<p>Freejack: /* Backup */</p>
<hr />
<div>[[Category:System recovery]]<br />
{{Article summary start}}<br />
{{Article summary text|This article will show you how to setup LVM snapshot creation during system start.<br />
Such snapshots can be used for [[Full System Backup with tar|full system backups]]<br />
with minimal downtime or testing system updates or changes with the option to revert<br />
them.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary text|{{pkg|lvm2}}, {{pkg|systemd}}}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|LVM}}<br />
{{Article summary wiki|Full System Backup with tar}}<br />
{{Article summary end}}<br />
<br />
<br />
== Prerequisites ==<br />
<br />
You need a system with [[LVM]] root filesystem and [[systemd]].<br />
Check if [[Lvm#Snapshots|LVM snapshots]] are correctly setup.<br />
<br />
<br />
== Setup ==<br />
<br />
During system start a clean snapshot of the root volume is<br />
created using a new service. Create<br />
{{ic|/etc/systemd/system/mk-lvm-snapshots.service}} containing:<br />
{{bc|[Unit]<br />
Descriptionm&#61;ake LVM snapshots<br />
Requires&#61;local-fs-pre.target<br />
DefaultDependencies&#61;no<br />
Conflicts&#61;shutdown.target<br />
After&#61;local-fs-pre.target<br />
Before&#61;local-fs.target<br />
<br />
[Install]<br />
WantedBy&#61;make-snapshots.target<br />
<br />
[Service]<br />
Type&#61;oneshot<br />
ExecStart&#61;/usr/sbin/lvcreate -L10G -n snap-root -s lvmvolume/root}}<br />
<br />
Adapt the {{ic|lvcreate}} command to match your root volume group and volume name.<br />
Adjust the snapshot size if necessary.<br />
<br />
Create a new systemd target {{ic|/etc/systemd/system/make-snapshots.target}} with this service:<br />
{{bc|[Unit]<br />
Description&#61;Make Snapshots<br />
Requires&#61;multi-user.target}}<br />
Adapt the base target, if {{ic|multi-user.target}} is not your default target.<br />
<br />
Enable the new service with {{ic|systemctl enable mk-lvm-snapshots.service}}.<br />
<br />
If the system is started with the new target, LVM snapshot(s) are created just after mounting the local filesystems.<br />
To get a [[grub]] menu entry starting this target create {{ic|/boot/grub/custom.cfg}} based on the<br />
{{ic|grub.cfg}} entry for your normal startup. The kernel command line is extended to start the new<br />
{{ic|make-snapshots.target}}:<br />
{{bc|### make snapshots ###<br />
menuentry 'Arch GNU/Linux, make snapshots' --class arch --class gnu-linux --class gnu --class os {<br />
...<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root&#61;/dev/mapper/lvmvolume-root ro systemd.unit&#61;make-snapshots.target<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
} }}<br />
<br />
Remember to adjust {{ic|custom.cfg}} if {{ic|grub.cfg}} changes.<br />
<br />
After restarting the system with this grub entry {{ic|lvs}} should show up the newly created snapshot.<br />
<br />
{{Tip|To get the messages of the new service use<br />
{{ic|journalctl -u mk-lvm-snapshots.service}}.}}<br />
<br />
<br />
== Usage ==<br />
<br />
=== Backup ===<br />
To use this functionality for a full system backup, restart your system with the snapshot creation target.<br />
Mount the snapshot volume (and further volumes, if required), preferably using the read only (<tt>-o</tt>) option.<br />
Then backup your system, for example with tar as described in [[Full_System_Backup_with_tar]].<br />
<br />
During backup you can continue to use your system normally, since all changes to your regular volumes are invisible in<br />
the snapshots. Do not forget to delete the snapshot volume after the backup -- changes to your regular volume will<br />
use up space in the snapshot due to the copy-on-write operations. If the snapshot space becomes fully used LVM<br />
will deny further writes to your regular volumes, which should be avoided.<br />
<br />
=== Revert updates ===<br />
An other use for LVM snapshots is testing and reverting of updates. In this case create a snapshot for the system<br />
in a known good state and perform updates or changes afterwards.<br />
<br />
If you want to permantly stick to the updates just drop the snapshot. If you want to revert to the snapshotted<br />
state issue a {{ic|lvchange --merge}} for the snapshot. During the next restart of the system the snapshot<br />
is merged back into your regular volume. All changes to the volume happened after the snapshot are undone.<br />
<br />
== Known issues ==<br />
Due to [https://bugzilla.redhat.com/show_bug.cgi?id=681582 bug 681582] shutting down the system with active<br />
snapshots may hang for some time.</div>Freejackhttps://wiki.archlinux.org/index.php?title=User:Freejack&diff=255344User:Freejack2013-04-27T14:05:58Z<p>Freejack: </p>
<hr />
<div>Use my [[User talk:freejack|talk]] page for public comments. Use my [[Special:EmailUser/freejack|email]] for private comments.<br />
<br />
----<br />
<br />
* [[User:freejack/Create LVM root snapshots]]<br />
<br />
__NOTOC__ {{DISPLAYTITLE:User:freejack}}</div>Freejackhttps://wiki.archlinux.org/index.php?title=User:Freejack/Create_LVM_Snapshots_for_Full_System_Backup&diff=255343User:Freejack/Create LVM Snapshots for Full System Backup2013-04-27T14:05:27Z<p>Freejack: Freejack moved page User:Freejack/Create LVM Snapshots for Full System Backup to User:Freejack/Create LVM root snapshots</p>
<hr />
<div>#REDIRECT [[User:Freejack/Create LVM root snapshots]]</div>Freejackhttps://wiki.archlinux.org/index.php?title=Create_root_filesystem_snapshots_with_LVM&diff=255342Create root filesystem snapshots with LVM2013-04-27T14:05:27Z<p>Freejack: Freejack moved page User:Freejack/Create LVM Snapshots for Full System Backup to User:Freejack/Create LVM root snapshots</p>
<hr />
<div>[[Category:System recovery]]<br />
{{Article summary start}}<br />
{{Article summary text|This article will show you how to setup LVM snapshot creation during system start.<br />
Such snapshots can be used for [[Full System Backup with tar|full system backups]]<br />
with minimal downtime or testing system updates or changes with the option to revert<br />
them.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary text|{{pkg|lvm2}}, {{pkg|systemd}}}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|LVM}}<br />
{{Article summary wiki|Full System Backup with tar}}<br />
{{Article summary end}}<br />
<br />
<br />
== Prerequisites ==<br />
<br />
You need a system with [[LVM]] root filesystem and [[systemd]].<br />
Check if [[Lvm#Snapshots|LVM snapshots]] are correctly setup.<br />
<br />
<br />
== Setup ==<br />
<br />
During system start a clean snapshot of the root volume is<br />
created using a new service. Create<br />
{{ic|/etc/systemd/system/mk-lvm-snapshots.service}} containing:<br />
{{bc|[Unit]<br />
Descriptionm&#61;ake LVM snapshots<br />
Requires&#61;local-fs-pre.target<br />
DefaultDependencies&#61;no<br />
Conflicts&#61;shutdown.target<br />
After&#61;local-fs-pre.target<br />
Before&#61;local-fs.target<br />
<br />
[Install]<br />
WantedBy&#61;make-snapshots.target<br />
<br />
[Service]<br />
Type&#61;oneshot<br />
ExecStart&#61;/usr/sbin/lvcreate -L10G -n snap-root -s lvmvolume/root}}<br />
<br />
Adapt the {{ic|lvcreate}} command to match your root volume group and volume name.<br />
Adjust the snapshot size if necessary.<br />
<br />
Create a new systemd target {{ic|/etc/systemd/system/make-snapshots.target}} with this service:<br />
{{bc|[Unit]<br />
Description&#61;Make Snapshots<br />
Requires&#61;multi-user.target}}<br />
Adapt the base target, if {{ic|multi-user.target}} is not your default target.<br />
<br />
Enable the new service with {{ic|systemctl enable mk-lvm-snapshots.service}}.<br />
<br />
If the system is started with the new target, LVM snapshot(s) are created just after mounting the local filesystems.<br />
To get a [[grub]] menu entry starting this target create {{ic|/boot/grub/custom.cfg}} based on the<br />
{{ic|grub.cfg}} entry for your normal startup. The kernel command line is extended to start the new<br />
{{ic|make-snapshots.target}}:<br />
{{bc|### make snapshots ###<br />
menuentry 'Arch GNU/Linux, make snapshots' --class arch --class gnu-linux --class gnu --class os {<br />
...<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root&#61;/dev/mapper/lvmvolume-root ro systemd.unit&#61;make-snapshots.target<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
} }}<br />
<br />
Remember to adjust {{ic|custom.cfg}} if {{ic|grub.cfg}} changes.<br />
<br />
After restarting the system with this grub entry {{ic|lvs}} should show up the newly created snapshot.<br />
<br />
{{Tip|To get the messages of the new service use<br />
{{ic|journalctl -u mk-lvm-snapshots.service}}.}}<br />
<br />
<br />
== Usage ==<br />
<br />
=== Backup ===<br />
To use this functionality for a full system backup, restart your system with the snapshot creation target.<br />
Mount the snapshot volume (and further volumes, if required), preferably using the read only (<tt>-o</tt>) option.<br />
Then backup your system, for example with tar as described in [[Full_System_Backup_with_tar]].<br />
<br />
During backup you can continue your system normally, since all changes to your regular volumes are invisible in<br />
the snapshots. Do not forget to delete the snapshot volume after the backup -- changes to your regular volume will<br />
use up space in the snapshot due to the copy-on-write operations. If the snapshot space becomes fully used LVM<br />
will deny further writes to your regular volumes, which should be avoided.<br />
<br />
=== Revert updates ===<br />
An other use for LVM snapshots is testing and reverting of updates. In this case create a snapshot for the system<br />
in a known good state and perform updates or changes afterwards.<br />
<br />
If you want to permantly stick to the updates just drop the snapshot. If you want to revert to the snapshotted<br />
state issue a {{ic|lvchange --merge}} for the snapshot. During the next restart of the system the snapshot<br />
is merged back into your regular volume. All changes to the volume happened after the snapshot are undone.<br />
<br />
== Known issues ==<br />
Due to [https://bugzilla.redhat.com/show_bug.cgi?id=681582 bug 681582] shutting down the system with active<br />
snapshots may hang for some time.</div>Freejackhttps://wiki.archlinux.org/index.php?title=Create_root_filesystem_snapshots_with_LVM&diff=255341Create root filesystem snapshots with LVM2013-04-27T14:02:16Z<p>Freejack: </p>
<hr />
<div>[[Category:System recovery]]<br />
{{Article summary start}}<br />
{{Article summary text|This article will show you how to setup LVM snapshot creation during system start.<br />
Such snapshots can be used for [[Full System Backup with tar|full system backups]]<br />
with minimal downtime or testing system updates or changes with the option to revert<br />
them.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary text|{{pkg|lvm2}}, {{pkg|systemd}}}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|LVM}}<br />
{{Article summary wiki|Full System Backup with tar}}<br />
{{Article summary end}}<br />
<br />
<br />
== Prerequisites ==<br />
<br />
You need a system with [[LVM]] root filesystem and [[systemd]].<br />
Check if [[Lvm#Snapshots|LVM snapshots]] are correctly setup.<br />
<br />
<br />
== Setup ==<br />
<br />
During system start a clean snapshot of the root volume is<br />
created using a new service. Create<br />
{{ic|/etc/systemd/system/mk-lvm-snapshots.service}} containing:<br />
{{bc|[Unit]<br />
Descriptionm&#61;ake LVM snapshots<br />
Requires&#61;local-fs-pre.target<br />
DefaultDependencies&#61;no<br />
Conflicts&#61;shutdown.target<br />
After&#61;local-fs-pre.target<br />
Before&#61;local-fs.target<br />
<br />
[Install]<br />
WantedBy&#61;make-snapshots.target<br />
<br />
[Service]<br />
Type&#61;oneshot<br />
ExecStart&#61;/usr/sbin/lvcreate -L10G -n snap-root -s lvmvolume/root}}<br />
<br />
Adapt the {{ic|lvcreate}} command to match your root volume group and volume name.<br />
Adjust the snapshot size if necessary.<br />
<br />
Create a new systemd target {{ic|/etc/systemd/system/make-snapshots.target}} with this service:<br />
{{bc|[Unit]<br />
Description&#61;Make Snapshots<br />
Requires&#61;multi-user.target}}<br />
Adapt the base target, if {{ic|multi-user.target}} is not your default target.<br />
<br />
Enable the new service with {{ic|systemctl enable mk-lvm-snapshots.service}}.<br />
<br />
If the system is started with the new target, LVM snapshot(s) are created just after mounting the local filesystems.<br />
To get a [[grub]] menu entry starting this target create {{ic|/boot/grub/custom.cfg}} based on the<br />
{{ic|grub.cfg}} entry for your normal startup. The kernel command line is extended to start the new<br />
{{ic|make-snapshots.target}}:<br />
{{bc|### make snapshots ###<br />
menuentry 'Arch GNU/Linux, make snapshots' --class arch --class gnu-linux --class gnu --class os {<br />
...<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root&#61;/dev/mapper/lvmvolume-root ro systemd.unit&#61;make-snapshots.target<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
} }}<br />
<br />
Remember to adjust {{ic|custom.cfg}} if {{ic|grub.cfg}} changes.<br />
<br />
After restarting the system with this grub entry {{ic|lvs}} should show up the newly created snapshot.<br />
<br />
{{Tip|To get the messages of the new service use<br />
{{ic|journalctl -u mk-lvm-snapshots.service}}.}}<br />
<br />
<br />
== Usage ==<br />
<br />
=== Backup ===<br />
To use this functionality for a full system backup, restart your system with the snapshot creation target.<br />
Mount the snapshot volume (and further volumes, if required), preferably using the read only (<tt>-o</tt>) option.<br />
Then backup your system, for example with tar as described in [[Full_System_Backup_with_tar]].<br />
<br />
During backup you can continue your system normally, since all changes to your regular volumes are invisible in<br />
the snapshots. Do not forget to delete the snapshot volume after the backup -- changes to your regular volume will<br />
use up space in the snapshot due to the copy-on-write operations. If the snapshot space becomes fully used LVM<br />
will deny further writes to your regular volumes, which should be avoided.<br />
<br />
=== Revert updates ===<br />
An other use for LVM snapshots is testing and reverting of updates. In this case create a snapshot for the system<br />
in a known good state and perform updates or changes afterwards.<br />
<br />
If you want to permantly stick to the updates just drop the snapshot. If you want to revert to the snapshotted<br />
state issue a {{ic|lvchange --merge}} for the snapshot. During the next restart of the system the snapshot<br />
is merged back into your regular volume. All changes to the volume happened after the snapshot are undone.<br />
<br />
== Known issues ==<br />
Due to [https://bugzilla.redhat.com/show_bug.cgi?id=681582 bug 681582] shutting down the system with active<br />
snapshots may hang for some time.</div>Freejackhttps://wiki.archlinux.org/index.php?title=Create_root_filesystem_snapshots_with_LVM&diff=255340Create root filesystem snapshots with LVM2013-04-27T13:56:29Z<p>Freejack: </p>
<hr />
<div>[[Category:System recovery]]<br />
{{Article summary start}}<br />
{{Article summary text|This article will show you how to setup LVM snapshot creation during system start.<br />
Such snapshots can be used for [[Full System Backup with tar|full system backups]]<br />
with minimal downtime or testing system updates or changes with the option to revert<br />
them.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary text|{{pkg|lvm2}}, {{pkg|systemd}}}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|LVM}}<br />
{{Article summary wiki|Full System Backup with tar}}<br />
{{Article summary end}}<br />
<br />
<br />
== Prerequisites ==<br />
<br />
A system with [[LVM]] root filesystem and [[systemd]].<br />
Check if [[Lvm#Snapshots|LVM snapshots]] are correctly setup.<br />
<br />
<br />
== Setup ==<br />
<br />
During system start a clean snapshot of the root volume is<br />
created using a new service. Create<br />
{{ic|/etc/systemd/system/mk-lvm-snapshots.service}} containing:<br />
{{bc|[Unit]<br />
Descriptionm&#61;ake LVM snapshots<br />
Requires&#61;local-fs-pre.target<br />
DefaultDependencies&#61;no<br />
Conflicts&#61;shutdown.target<br />
After&#61;local-fs-pre.target<br />
Before&#61;local-fs.target<br />
<br />
[Install]<br />
WantedBy&#61;make-snapshots.target<br />
<br />
[Service]<br />
Type&#61;oneshot<br />
ExecStart&#61;/usr/sbin/lvcreate -L10G -n snap-root -s lvmvolume/root}}<br />
<br />
Adapt the {{ic|lvcreate}} command to match your root volume group and volume name.<br />
<br />
Create a new systemd target {{ic|/etc/systemd/system/make-snapshots.target}} with this service:<br />
{{bc|[Unit]<br />
Description&#61;Make Snapshots<br />
Requires&#61;multi-user.target}}<br />
Adapt the base target, if {{ic|multi-user.target}} is not your default target.<br />
<br />
Enable the new service with {{ic|systemctl enable mk-lvm-snapshots.service}}.<br />
<br />
If the system is started with the new target, LVM snapshot(s) are created just after mounting the local filesystems.<br />
To get a [[grub]] menu entry starting this target create {{ic|/boot/grub/custom.cfg}} based on the<br />
{{ic|grub.cfg}} entry for your normal startup. The kernel command line is extended to start the new<br />
{{ic|make-snapshots.target}}:<br />
{{bc|### make snapshots ###<br />
menuentry 'Arch GNU/Linux, make snapshots' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-core repo kernel-true-...' {<br />
...<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root&#61;/dev/mapper/lvmvolume-root ro systemd.unit&#61;make-snapshots.target<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
} }}<br />
<br />
Remember to adjust {{ic|custom.cfg}} if {{ic|grub.cfg}} changes.<br />
<br />
After restarting the system with this grub entry {{ic|lvs}} should show up the newly created snapshot.<br />
To get the messages of the new service use<br />
{{ic|journalctl -u mk-lvm-snapshots.service}}.<br />
<br />
== Usage ==<br />
<br />
=== Backup ===<br />
To use this functionality for a full system backup, restart your system with the snapshot creation target.<br />
Mount the snapshot volume (and further volumes, if required), preferably using the read only (<tt>-o</tt>) option.<br />
Then backup your system, for example with tar as described in [[Full_System_Backup_with_tar]].<br />
<br />
During backup you can continue your system normally, since all changes to your regular volumes are invisible in<br />
the snapshots. Do not forget to delete the snapshot volume after the backup -- changes to your regular volume will<br />
use up space in the snapshot due to the copy-on-write operations. If the snapshot space becomes fully used LVM<br />
will deny further writes to your regular volumes, which should be avoided.<br />
<br />
=== Revert updates ===<br />
An other use for LVM snapshots is testing and reverting of updates. In this case create a snapshot for the system<br />
in a known good state and perform updates or changes afterwards.<br />
<br />
If you want to permantly stick to the updates just drop the snapshot. If you want to revert to the snapshotted<br />
state issue a {{ic|lvchange --merge}} for the snapshot. During the next restart of the system the snapshot<br />
is merged back into your regular volume. All changes to the volume happened after the snapshot are undone.<br />
<br />
== Known issues ==<br />
Due to [https://bugzilla.redhat.com/show_bug.cgi?id=681582 bug 681582] shutting down the system with active<br />
snapshots may hang for some time.</div>Freejackhttps://wiki.archlinux.org/index.php?title=Create_root_filesystem_snapshots_with_LVM&diff=255338Create root filesystem snapshots with LVM2013-04-27T13:19:52Z<p>Freejack: /* Known issues */</p>
<hr />
<div>This article will show you how to setup LVM snapshot creation during system start.<br />
Such snapshots can be used for [[Full System Backup with tar|full system backups]]<br />
with minimal downtime or testing system updates or changes with the option to revert<br />
them.<br />
<br />
<br />
== Prerequisites ==<br />
<br />
A system with [[LVM]] root and [[systemd]].<br />
<br />
<br />
== Setup ==<br />
<br />
Check if [[Lvm#Snapshots|LVM snapshots]] are correctly setup.<br />
<br />
During system start a clean snapshot of the root volume is<br />
created using a new service. Create<br />
{{ic|/etc/systemd/system/mk-lvm-snapshots.service}} containing:<br />
{{bc|[Unit]<br />
Descriptionm&#61;ake LVM snapshots<br />
Requires&#61;local-fs-pre.target<br />
DefaultDependencies&#61;no<br />
Conflicts&#61;shutdown.target<br />
After&#61;local-fs-pre.target<br />
Before&#61;local-fs.target<br />
<br />
[Install]<br />
WantedBy&#61;make-snapshots.target<br />
<br />
[Service]<br />
Type&#61;oneshot<br />
ExecStart&#61;/usr/sbin/lvcreate -L10G -n snap-root -s lvmvolume/root}}<br />
<br />
Adapt the {{ic|lvcreate}} command to match your root volume group and volume name.<br />
<br />
Create a new systemd target {{ic|/etc/systemd/system/make-snapshots.target}} with this service:<br />
{{bc|[Unit]<br />
Description&#61;Make Snapshots<br />
Requires&#61;multi-user.target}}<br />
Adapt the base target, if {{ic|multi-user.target}} is not your default target.<br />
<br />
Enable the new service with {{ic|systemctl enable mk-lvm-snapshots.service}}.<br />
<br />
If the system is started with the new target, LVM snapshot(s) are created just after mounting the local filesystems.<br />
To get a [[grub]] menu entry starting this target create {{ic|/boot/grub/custom.cfg}} based on the<br />
{{ic|grub.cfg}} entry for your normal startup. The kernel command line is extended to start the new<br />
{{ic|make-snapshots.target}}:<br />
{{bc|### make snapshots ###<br />
menuentry 'Arch GNU/Linux, make snapshots' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-core repo kernel-true-...' {<br />
...<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root&#61;/dev/mapper/lvmvolume-root ro systemd.unit&#61;make-snapshots.target<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
} }}<br />
<br />
Remember to adjust {{ic|custom.cfg}} if {{ic|grub.cfg}} changes.<br />
<br />
After restarting the system with this grub entry {{ic|lvs}} should show up the newly created snapshot.<br />
To get the messages of the new service use<br />
{{ic|journalctl -u mk-lvm-snapshots.service}}.<br />
<br />
== Usage ==<br />
<br />
=== Backup ===<br />
To use this functionality for a full system backup, restart your system with the snapshot creation target.<br />
Mount the snapshot volume (and further volumes, if required), preferably using the read only (<tt>-o</tt>) option.<br />
Then backup your system, for example with tar as described in [[Full_System_Backup_with_tar]].<br />
<br />
During backup you can continue your system normally, since all changes to your regular volumes are invisible in<br />
the snapshots. Do not forget to delete the snapshot volume after the backup -- changes to your regular volume will<br />
use up space in the snapshot due to the copy-on-write operations. If the snapshot space becomes fully used LVM<br />
will deny further writes to your regular volumes, which should be avoided.<br />
<br />
=== Revert updates ===<br />
An other use for LVM snapshots is testing and reverting of updates. In this case create a snapshot for the system<br />
in a known good state and perform updates or changes afterwards.<br />
<br />
If you want to permantly stick to the updates just drop the snapshot. If you want to revert to the snapshotted<br />
state issue a {{ic|lvchange --merge}} for the snapshot. During the next restart of the system the snapshot<br />
is merged back into your regular volume. All changes to the volume happened after the snapshot are undone.<br />
<br />
== Known issues ==<br />
Due to [https://bugzilla.redhat.com/show_bug.cgi?id=681582 bug 681582] shutting down the system with active<br />
snapshots may hang for some time.</div>Freejackhttps://wiki.archlinux.org/index.php?title=Create_root_filesystem_snapshots_with_LVM&diff=255336Create root filesystem snapshots with LVM2013-04-27T12:53:46Z<p>Freejack: /* Known issues */</p>
<hr />
<div>This article will show you how to setup LVM snapshot creation during system start.<br />
Such snapshots can be used for [[Full System Backup with tar|full system backups]]<br />
with minimal downtime or testing system updates or changes with the option to revert<br />
them.<br />
<br />
<br />
== Prerequisites ==<br />
<br />
A system with [[LVM]] root and [[systemd]].<br />
<br />
<br />
== Setup ==<br />
<br />
Check if [[Lvm#Snapshots|LVM snapshots]] are correctly setup.<br />
<br />
During system start a clean snapshot of the root volume is<br />
created using a new service. Create<br />
{{ic|/etc/systemd/system/mk-lvm-snapshots.service}} containing:<br />
{{bc|[Unit]<br />
Descriptionm&#61;ake LVM snapshots<br />
Requires&#61;local-fs-pre.target<br />
DefaultDependencies&#61;no<br />
Conflicts&#61;shutdown.target<br />
After&#61;local-fs-pre.target<br />
Before&#61;local-fs.target<br />
<br />
[Install]<br />
WantedBy&#61;make-snapshots.target<br />
<br />
[Service]<br />
Type&#61;oneshot<br />
ExecStart&#61;/usr/sbin/lvcreate -L10G -n snap-root -s lvmvolume/root}}<br />
<br />
Adapt the {{ic|lvcreate}} command to match your root volume group and volume name.<br />
<br />
Create a new systemd target {{ic|/etc/systemd/system/make-snapshots.target}} with this service:<br />
{{bc|[Unit]<br />
Description&#61;Make Snapshots<br />
Requires&#61;multi-user.target}}<br />
Adapt the base target, if {{ic|multi-user.target}} is not your default target.<br />
<br />
Enable the new service with {{ic|systemctl enable mk-lvm-snapshots.service}}.<br />
<br />
If the system is started with the new target, LVM snapshot(s) are created just after mounting the local filesystems.<br />
To get a [[grub]] menu entry starting this target create {{ic|/boot/grub/custom.cfg}} based on the<br />
{{ic|grub.cfg}} entry for your normal startup. The kernel command line is extended to start the new<br />
{{ic|make-snapshots.target}}:<br />
{{bc|### make snapshots ###<br />
menuentry 'Arch GNU/Linux, make snapshots' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-core repo kernel-true-...' {<br />
...<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root&#61;/dev/mapper/lvmvolume-root ro systemd.unit&#61;make-snapshots.target<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
} }}<br />
<br />
Remember to adjust {{ic|custom.cfg}} if {{ic|grub.cfg}} changes.<br />
<br />
After restarting the system with this grub entry {{ic|lvs}} should show up the newly created snapshot.<br />
To get the messages of the new service use<br />
{{ic|journalctl -u mk-lvm-snapshots.service}}.<br />
<br />
== Usage ==<br />
<br />
=== Backup ===<br />
To use this functionality for a full system backup, restart your system with the snapshot creation target.<br />
Mount the snapshot volume (and further volumes, if required), preferably using the read only (<tt>-o</tt>) option.<br />
Then backup your system, for example with tar as described in [[Full_System_Backup_with_tar]].<br />
<br />
During backup you can continue your system normally, since all changes to your regular volumes are invisible in<br />
the snapshots. Do not forget to delete the snapshot volume after the backup -- changes to your regular volume will<br />
use up space in the snapshot due to the copy-on-write operations. If the snapshot space becomes fully used LVM<br />
will deny further writes to your regular volumes, which should be avoided.<br />
<br />
=== Revert updates ===<br />
An other use for LVM snapshots is testing and reverting of updates. In this case create a snapshot for the system<br />
in a known good state and perform updates or changes afterwards.<br />
<br />
If you want to permantly stick to the updates just drop the snapshot. If you want to revert to the snapshotted<br />
state issue a {{ic|lvchange --merge}} for the snapshot. During the next restart of the system the snapshot<br />
is merged back into your regular volume. All changes to the volume happened after the snapshot are undone.<br />
<br />
== Known issues ==<br />
Due to [https://bugzilla.redhat.com/show_bug.cgi?id=681582 bug 681582] shutting down the system with active<br />
snapshots may hang for some minutes. As a workaround you can reduce the timeout for stopping the LVM monitoring<br />
by making a copy of {{ic|/usr/lib/systemd/system/lvm-monitoring.service}} to<br />
{{ic|/etc/systemd/system}} and add {{ic|1=TimeoutStopSec=5s}} to the {{ic|[Service]]}} section.</div>Freejackhttps://wiki.archlinux.org/index.php?title=Create_root_filesystem_snapshots_with_LVM&diff=255334Create root filesystem snapshots with LVM2013-04-27T12:52:40Z<p>Freejack: </p>
<hr />
<div>This article will show you how to setup LVM snapshot creation during system start.<br />
Such snapshots can be used for [[Full System Backup with tar|full system backups]]<br />
with minimal downtime or testing system updates or changes with the option to revert<br />
them.<br />
<br />
<br />
== Prerequisites ==<br />
<br />
A system with [[LVM]] root and [[systemd]].<br />
<br />
<br />
== Setup ==<br />
<br />
Check if [[Lvm#Snapshots|LVM snapshots]] are correctly setup.<br />
<br />
During system start a clean snapshot of the root volume is<br />
created using a new service. Create<br />
{{ic|/etc/systemd/system/mk-lvm-snapshots.service}} containing:<br />
{{bc|[Unit]<br />
Descriptionm&#61;ake LVM snapshots<br />
Requires&#61;local-fs-pre.target<br />
DefaultDependencies&#61;no<br />
Conflicts&#61;shutdown.target<br />
After&#61;local-fs-pre.target<br />
Before&#61;local-fs.target<br />
<br />
[Install]<br />
WantedBy&#61;make-snapshots.target<br />
<br />
[Service]<br />
Type&#61;oneshot<br />
ExecStart&#61;/usr/sbin/lvcreate -L10G -n snap-root -s lvmvolume/root}}<br />
<br />
Adapt the {{ic|lvcreate}} command to match your root volume group and volume name.<br />
<br />
Create a new systemd target {{ic|/etc/systemd/system/make-snapshots.target}} with this service:<br />
{{bc|[Unit]<br />
Description&#61;Make Snapshots<br />
Requires&#61;multi-user.target}}<br />
Adapt the base target, if {{ic|multi-user.target}} is not your default target.<br />
<br />
Enable the new service with {{ic|systemctl enable mk-lvm-snapshots.service}}.<br />
<br />
If the system is started with the new target, LVM snapshot(s) are created just after mounting the local filesystems.<br />
To get a [[grub]] menu entry starting this target create {{ic|/boot/grub/custom.cfg}} based on the<br />
{{ic|grub.cfg}} entry for your normal startup. The kernel command line is extended to start the new<br />
{{ic|make-snapshots.target}}:<br />
{{bc|### make snapshots ###<br />
menuentry 'Arch GNU/Linux, make snapshots' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-core repo kernel-true-...' {<br />
...<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root&#61;/dev/mapper/lvmvolume-root ro systemd.unit&#61;make-snapshots.target<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
} }}<br />
<br />
Remember to adjust {{ic|custom.cfg}} if {{ic|grub.cfg}} changes.<br />
<br />
After restarting the system with this grub entry {{ic|lvs}} should show up the newly created snapshot.<br />
To get the messages of the new service use<br />
{{ic|journalctl -u mk-lvm-snapshots.service}}.<br />
<br />
== Usage ==<br />
<br />
=== Backup ===<br />
To use this functionality for a full system backup, restart your system with the snapshot creation target.<br />
Mount the snapshot volume (and further volumes, if required), preferably using the read only (<tt>-o</tt>) option.<br />
Then backup your system, for example with tar as described in [[Full_System_Backup_with_tar]].<br />
<br />
During backup you can continue your system normally, since all changes to your regular volumes are invisible in<br />
the snapshots. Do not forget to delete the snapshot volume after the backup -- changes to your regular volume will<br />
use up space in the snapshot due to the copy-on-write operations. If the snapshot space becomes fully used LVM<br />
will deny further writes to your regular volumes, which should be avoided.<br />
<br />
=== Revert updates ===<br />
An other use for LVM snapshots is testing and reverting of updates. In this case create a snapshot for the system<br />
in a known good state and perform updates or changes afterwards.<br />
<br />
If you want to permantly stick to the updates just drop the snapshot. If you want to revert to the snapshotted<br />
state issue a {{ic|lvchange --merge}} for the snapshot. During the next restart of the system the snapshot<br />
is merged back into your regular volume. All changes to the volume happened after the snapshot are undone.<br />
<br />
== Known issues ==<br />
Due to [[https://bugzilla.redhat.com/show_bug.cgi?id=681582|bug 681582]] shutting down the system with active<br />
snapshots may hang for some minutes. As a workaround you can reduce the timeout for stopping the LVM monitoring<br />
by making a copy of {{ic|/usr/lib/systemd/system/lvm-monitoring.service}} to<br />
{{ic|/etc/systemd/system}} and add {{ic|1=TimeoutStopSec=5s}} to the {{ic|[Service]]}} section.</div>Freejackhttps://wiki.archlinux.org/index.php?title=Create_root_filesystem_snapshots_with_LVM&diff=255332Create root filesystem snapshots with LVM2013-04-27T12:35:30Z<p>Freejack: </p>
<hr />
<div>This article will show you how to setup LVM snapshot creation during system start.<br />
Such snapshots can be used for [[Full System Backup with tar|full system backups]]<br />
with minimal downtime or testing system updates or changes with the option to revert<br />
them.<br />
<br />
<br />
== Prerequisites ==<br />
<br />
A system with [[LVM]] root and [[systemd]].<br />
<br />
<br />
== Setup ==<br />
<br />
Check if [[Lvm#Snapshots|LVM snapshots]] are correctly setup.<br />
<br />
During system start a clean snapshot of the root volume is<br />
created using a new service. Create<br />
{{ic|/etc/systemd/system/mk-lvm-snapshots.service}} containing:<br />
{{bc|[Unit]<br />
Descriptionm&#61;ake LVM snapshots<br />
Requires&#61;local-fs-pre.target<br />
DefaultDependencies&#61;no<br />
Conflicts&#61;shutdown.target<br />
After&#61;local-fs-pre.target<br />
Before&#61;local-fs.target<br />
<br />
[Install]<br />
WantedBy&#61;make-snapshots.target<br />
<br />
[Service]<br />
Type&#61;oneshot<br />
ExecStart&#61;/usr/sbin/lvcreate -L10G -n snap-root -s lvmvolume/root}}<br />
<br />
Adapt the {{ic|lvcreate}} command to match your root volume group and volume name.<br />
<br />
Create a new systemd target {{ic|/etc/systemd/system/make-snapshots.target}} with this service:<br />
{{bc|[Unit]<br />
Description&#61;Make Snapshots<br />
Requires&#61;multi-user.target}}<br />
Adapt the base target, if {{ic|multi-user.target}} is not your default target.<br />
<br />
Enable the new service with {{ic|systemctl enable mk-lvm-snapshots.service}}.<br />
<br />
If the system is started with the new target, LVM snapshot(s) are created just after mounting the local filesystems.<br />
To get a [[grub]] menu entry starting this target create {{ic|/boot/grub/custom.cfg}} based on the<br />
{{ic|grub.cfg}} entry for your normal startup. The kernel command line is extended to start the new<br />
{{ic|make-snapshots.target}}:<br />
{{bc|### make snapshots ###<br />
menuentry 'Arch GNU/Linux, make snapshots' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-core repo kernel-true-...' {<br />
...<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root&#61;/dev/mapper/lvmvolume-root ro systemd.unit&#61;make-snapshots.target<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
} }}<br />
<br />
Remember to adjust {{ic|custom.cfg}} if {{ic|grub.cfg}} changes.<br />
<br />
After restarting the system with this grub entry {{ic|lvs}} should show up the newly created snapshot.<br />
To get the messages of the new service use<br />
{{ic|journalctl -u mk-lvm-snapshots.service}}.<br />
<br />
== Usage ==<br />
<br />
=== Backup ===<br />
To use this functionality for a full system backup, restart your system with the snapshot creation target.<br />
Mount the snapshot volume (and further volumes, if required), preferably using the read only (<tt>-o</tt>) option.<br />
Then backup your system, for example with tar as described in [[Full_System_Backup_with_tar]].<br />
<br />
During backup you can continue your system normally, since all changes to your regular volumes are invisible in<br />
the snapshots. Do not forget to delete the snapshot volume after the backup -- changes to your regular volume will<br />
use up space in the snapshot due to the copy-on-write operations. If the snapshot space becomes fully used LVM<br />
will deny further writes to your regular volumes, which should be avoided.<br />
<br />
=== Revert updates ===<br />
An other use for LVM snapshots is testing and reverting of updates. In this case create a snapshot for the system<br />
in a known good state and perform updates or changes afterwards.<br />
<br />
If you want to permantly stick to the updates just drop the snapshot. If you want to revert to the snapshotted<br />
state issue a {{ic|lvchange --merge}} for the snapshot. During the next restart of the system the snapshot<br />
is merged back into your regular volume. All changes to the volume happened after the snapshot are undone.</div>Freejackhttps://wiki.archlinux.org/index.php?title=Create_root_filesystem_snapshots_with_LVM&diff=255331Create root filesystem snapshots with LVM2013-04-27T12:34:29Z<p>Freejack: /* Usage */</p>
<hr />
<div>This article will show you how to setup LVM snapshot creation during system start.<br />
Such snapshots can be used for [[Full System Backup with tar|full system backups]]<br />
with minimal downtime.<br />
<br />
<br />
== Prerequisites ==<br />
<br />
A system with [[LVM]] root and [[systemd]].<br />
<br />
<br />
== Setup ==<br />
<br />
Check if [[Lvm#Snapshots|LVM snapshots]] are correctly setup.<br />
<br />
During system start a clean snapshot of the root volume is<br />
created using a new service. Create<br />
{{ic|/etc/systemd/system/mk-lvm-snapshots.service}} containing:<br />
{{bc|[Unit]<br />
Descriptionm&#61;ake LVM snapshots<br />
Requires&#61;local-fs-pre.target<br />
DefaultDependencies&#61;no<br />
Conflicts&#61;shutdown.target<br />
After&#61;local-fs-pre.target<br />
Before&#61;local-fs.target<br />
<br />
[Install]<br />
WantedBy&#61;make-snapshots.target<br />
<br />
[Service]<br />
Type&#61;oneshot<br />
ExecStart&#61;/usr/sbin/lvcreate -L10G -n snap-root -s lvmvolume/root}}<br />
<br />
Adapt the {{ic|lvcreate}} command to match your root volume group and volume name.<br />
<br />
Create a new systemd target {{ic|/etc/systemd/system/make-snapshots.target}} with this service:<br />
{{bc|[Unit]<br />
Description&#61;Make Snapshots<br />
Requires&#61;multi-user.target}}<br />
Adapt the base target, if {{ic|multi-user.target}} is not your default target.<br />
<br />
Enable the new service with {{ic|systemctl enable mk-lvm-snapshots.service}}.<br />
<br />
If the system is started with the new target, LVM snapshot(s) are created just after mounting the local filesystems.<br />
To get a [[grub]] menu entry starting this target create {{ic|/boot/grub/custom.cfg}} based on the<br />
{{ic|grub.cfg}} entry for your normal startup. The kernel command line is extended to start the new<br />
{{ic|make-snapshots.target}}:<br />
{{bc|### make snapshots ###<br />
menuentry 'Arch GNU/Linux, make snapshots' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-core repo kernel-true-...' {<br />
...<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root&#61;/dev/mapper/lvmvolume-root ro systemd.unit&#61;make-snapshots.target<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
} }}<br />
<br />
Remember to adjust {{ic|custom.cfg}} if {{ic|grub.cfg}} changes.<br />
<br />
After restarting the system with this grub entry {{ic|lvs}} should show up the newly created snapshot.<br />
To get the messages of the new service use<br />
{{ic|journalctl -u mk-lvm-snapshots.service}}.<br />
<br />
== Usage ==<br />
<br />
=== Backup ===<br />
To use this functionality for a full system backup, restart your system with the snapshot creation target.<br />
Mount the snapshot volume (and further volumes, if required), preferably using the read only (<tt>-o</tt>) option.<br />
Then backup your system, for example with tar as described in [[Full_System_Backup_with_tar]].<br />
<br />
During backup you can continue your system normally, since all changes to your regular volumes are invisible in<br />
the snapshots. Do not forget to delete the snapshot volume after the backup -- changes to your regular volume will<br />
use up space in the snapshot due to the copy-on-write operations. If the snapshot space becomes fully used LVM<br />
will deny further writes to your regular volumes, which should be avoided.<br />
<br />
=== Revert updates ===<br />
An other use for LVM snapshots is testing and reverting of updates. In this case create a snapshot for the system<br />
in a known good state and perform updates or changes afterwards.<br />
<br />
If you want to permantly stick to the updates just drop the snapshot. If you want to revert to the snapshotted<br />
state issue a {{ic|lvchange --merge}} for the snapshot. During the next restart of the system the snapshot<br />
is merged back into your regular volume. All changes to the volume happened after the snapshot are undone.</div>Freejackhttps://wiki.archlinux.org/index.php?title=Create_root_filesystem_snapshots_with_LVM&diff=255307Create root filesystem snapshots with LVM2013-04-27T08:56:44Z<p>Freejack: </p>
<hr />
<div>This article will show you how to setup LVM snapshot creation during system start.<br />
Such snapshots can be used for [[Full System Backup with tar|full system backups]]<br />
with minimal downtime.<br />
<br />
<br />
== Prerequisites ==<br />
<br />
A system with [[LVM]] root and [[systemd]].<br />
<br />
<br />
== Setup ==<br />
<br />
Check if [[Lvm#Snapshots|LVM snapshots]] are correctly setup.<br />
<br />
During system start a clean snapshot of the root volume is<br />
created using a new service. Create<br />
{{ic|/etc/systemd/system/mk-lvm-snapshots.service}} containing:<br />
{{bc|[Unit]<br />
Descriptionm&#61;ake LVM snapshots<br />
Requires&#61;local-fs-pre.target<br />
DefaultDependencies&#61;no<br />
Conflicts&#61;shutdown.target<br />
After&#61;local-fs-pre.target<br />
Before&#61;local-fs.target<br />
<br />
[Install]<br />
WantedBy&#61;make-snapshots.target<br />
<br />
[Service]<br />
Type&#61;oneshot<br />
ExecStart&#61;/usr/sbin/lvcreate -L10G -n snap-root -s lvmvolume/root}}<br />
<br />
Adapt the {{ic|lvcreate}} command to match your root volume group and volume name.<br />
<br />
Create a new systemd target {{ic|/etc/systemd/system/make-snapshots.target}} with this service:<br />
{{bc|[Unit]<br />
Description&#61;Make Snapshots<br />
Requires&#61;multi-user.target}}<br />
Adapt the base target, if {{ic|multi-user.target}} is not your default target.<br />
<br />
Enable the new service with {{ic|systemctl enable mk-lvm-snapshots.service}}.<br />
<br />
If the system is started with the new target, LVM snapshot(s) are created just after mounting the local filesystems.<br />
To get a [[grub]] menu entry starting this target create {{ic|/boot/grub/custom.cfg}} based on the<br />
{{ic|grub.cfg}} entry for your normal startup. The kernel command line is extended to start the new<br />
{{ic|make-snapshots.target}}:<br />
{{bc|### make snapshots ###<br />
menuentry 'Arch GNU/Linux, make snapshots' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-core repo kernel-true-...' {<br />
...<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root&#61;/dev/mapper/lvmvolume-root ro systemd.unit&#61;make-snapshots.target<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
} }}<br />
<br />
Remember to adjust {{ic|custom.cfg}} if {{ic|grub.cfg}} changes.<br />
<br />
After restarting the system with this grub entry {{ic|lvs}} should show up the newly created snapshot.<br />
To get the messages of the new service use<br />
{{ic|journalctl -u mk-lvm-snapshots.service}}.<br />
<br />
== Usage ==<br />
To use this functionality for a full system backup, restart your system with the snapshot creation target.<br />
Mount the snapshot volume (and further volumes, if required), preferably using the read only (<tt>-o</tt>) option.<br />
Then backup your system, for example with tar as described in [[Full_System_Backup_with_tar]].<br />
<br />
During backup you can continue your system normally, since all changes to your regular volumes are invisible in<br />
the snapshots. Do not forget to delete the snapshot volume after the backup -- changes to your regular volume will<br />
use up space in the snapshot due to the copy-on-write operations. If the snapshot space becomes fully used LVM<br />
will deny further writes to your regular volumes, which should be avoided.</div>Freejackhttps://wiki.archlinux.org/index.php?title=Create_root_filesystem_snapshots_with_LVM&diff=255283Create root filesystem snapshots with LVM2013-04-27T06:52:31Z<p>Freejack: /* Usage */</p>
<hr />
<div>This article will show you how to setup LVM snapshot creation during system start.<br />
Such snapshots can be used for [[Full System Backup with tar|full system backups]]<br />
with minimal downtime.<br />
<br />
<br />
== Prerequisites ==<br />
<br />
A system with [[LVM]] root and [[systemd]].<br />
<br />
<br />
== Setup ==<br />
<br />
During system start a clean snapshot of the root volume is<br />
created using a new service. Create<br />
<tt>/etc/systemd/system/mk-lvm-snapshots.service</tt> containing:<br />
<pre><br />
[Unit]<br />
Description=make LVM snapshots<br />
Requires=local-fs-pre.target<br />
DefaultDependencies=no<br />
Conflicts=shutdown.target<br />
After=local-fs-pre.target<br />
Before=local-fs.target<br />
<br />
[Install]<br />
WantedBy=make-snapshots.target<br />
<br />
[Service]<br />
Type=oneshot<br />
ExecStart=/usr/sbin/lvcreate -L10G -n snap-root -s lvmvolume/root<br />
</pre><br />
<br />
Adapt the <tt>lvcreate</tt> command to match your root volume group and volume name.<br />
<br />
Create a new systemd target <tt>/etc/systemd/system/make-snapshots.target</tt> with this service:<br />
<pre><br />
[Unit]<br />
Description=Make Snapshots<br />
Requires=multi-user.target<br />
</pre><br />
Adapt the base target, if <tt>multi-user.target</tt> is not your default target.<br />
<br />
Enable the new service with <tt>systemctl enable mk-lvm-snapshots.service</tt>.<br />
<br />
If the system is started with the new target, LVM snapshot(s) are created just after mounting the local filesystems.<br />
To get a [[grub]] menu entry starting this target create <tt>/boot/grub/custom.cfg</tt> based on the<br />
<tt>grub.cfg</tt> entry for your normal startup. The kernel command line is extended to start the new <tt>make-snapshots.target</tt>:<br />
<pre><br />
### make snapshots ###<br />
menuentry 'Arch GNU/Linux, make snapshots' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-core repo kernel-true-...' {<br />
...<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root=/dev/mapper/lvmvolume-root ro systemd.unit=make-snapshots.target<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
}<br />
</pre><br />
<br />
Remember to adjust <tt>custom.cfg</tt> if <tt>grub.cfg</tt> changes.<br />
<br />
After restarting the system with this grub entry <tt>lvs</tt> should show up the newly created snapshot.<br />
To get the messages of the new service use<br />
<tt>journalctl -u mk-lvm-snapshots.service</tt>.<br />
<br />
== Usage ==<br />
To use this functionality for a full system backup, restart your system with the snapshot creation target.<br />
Mount the snapshot volume (and further volumes, if required), preferably using the read only (<tt>-o</tt>) option.<br />
Then backup your system, for example with tar as described in [[Full_System_Backup_with_tar]].<br />
<br />
During backup you can continue your system normally, since all changes to your regular volumes are invisible in<br />
the snapshots. Do not forget to delete the snapshot volume after the backup -- changes to your regular volume will<br />
use up space in the snapshot due to the copy-on-write operations. If the snapshot space becomes fully used LVM<br />
will deny further writes to your regular volumes, which should be avoided.</div>Freejackhttps://wiki.archlinux.org/index.php?title=Create_root_filesystem_snapshots_with_LVM&diff=255282Create root filesystem snapshots with LVM2013-04-27T06:41:38Z<p>Freejack: </p>
<hr />
<div>This article will show you how to setup LVM snapshot creation during system start.<br />
Such snapshots can be used for [[Full System Backup with tar|full system backups]]<br />
with minimal downtime.<br />
<br />
<br />
== Prerequisites ==<br />
<br />
A system with [[LVM]] root and [[systemd]].<br />
<br />
<br />
== Setup ==<br />
<br />
During system start a clean snapshot of the root volume is<br />
created using a new service. Create<br />
<tt>/etc/systemd/system/mk-lvm-snapshots.service</tt> containing:<br />
<pre><br />
[Unit]<br />
Description=make LVM snapshots<br />
Requires=local-fs-pre.target<br />
DefaultDependencies=no<br />
Conflicts=shutdown.target<br />
After=local-fs-pre.target<br />
Before=local-fs.target<br />
<br />
[Install]<br />
WantedBy=make-snapshots.target<br />
<br />
[Service]<br />
Type=oneshot<br />
ExecStart=/usr/sbin/lvcreate -L10G -n snap-root -s lvmvolume/root<br />
</pre><br />
<br />
Adapt the <tt>lvcreate</tt> command to match your root volume group and volume name.<br />
<br />
Create a new systemd target <tt>/etc/systemd/system/make-snapshots.target</tt> with this service:<br />
<pre><br />
[Unit]<br />
Description=Make Snapshots<br />
Requires=multi-user.target<br />
</pre><br />
Adapt the base target, if <tt>multi-user.target</tt> is not your default target.<br />
<br />
Enable the new service with <tt>systemctl enable mk-lvm-snapshots.service</tt>.<br />
<br />
If the system is started with the new target, LVM snapshot(s) are created just after mounting the local filesystems.<br />
To get a [[grub]] menu entry starting this target create <tt>/boot/grub/custom.cfg</tt> based on the<br />
<tt>grub.cfg</tt> entry for your normal startup. The kernel command line is extended to start the new <tt>make-snapshots.target</tt>:<br />
<pre><br />
### make snapshots ###<br />
menuentry 'Arch GNU/Linux, make snapshots' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-core repo kernel-true-...' {<br />
...<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root=/dev/mapper/lvmvolume-root ro systemd.unit=make-snapshots.target<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
}<br />
</pre><br />
<br />
Remember to adjust <tt>custom.cfg</tt> if <tt>grub.cfg</tt> changes.<br />
<br />
After restarting the system with this grub entry <tt>lvs</tt> should show up the newly created snapshot.<br />
To get the messages of the new service use<br />
<tt>journalctl -u mk-lvm-snapshots.service</tt>.<br />
<br />
== Usage ==<br />
To use this functionality for a full system backup restart your system with the snapshot creation target. Mount the<br />
snapshot volume (and further volumes, if required), preferably using the read only (<tt>-o</tt>) option.<br />
Then backup your system, for example with tar as described in [[Full_System_Backup_with_tar]].</div>Freejackhttps://wiki.archlinux.org/index.php?title=Create_root_filesystem_snapshots_with_LVM&diff=255281Create root filesystem snapshots with LVM2013-04-27T06:25:58Z<p>Freejack: </p>
<hr />
<div>This article will show you how to setup LVM snapshot creation during system start.<br />
Such snapshots can be used for [[Full System Backup with tar|full system backups]]<br />
with minimal downtime.<br />
<br />
<br />
== Prerequisites ==<br />
<br />
A system with [[LVM]] root and [[systemd]].<br />
<br />
<br />
== Setup ==<br />
<br />
During system start a clean snapshot of the root volume is<br />
created using a new service. Create<br />
<tt>/etc/systemd/system/mk-lvm-snapshots.service</tt> containing:<br />
<pre><br />
[Unit]<br />
Description=make LVM snapshots<br />
Requires=local-fs-pre.target<br />
DefaultDependencies=no<br />
Conflicts=shutdown.target<br />
After=local-fs-pre.target<br />
Before=local-fs.target<br />
<br />
[Install]<br />
WantedBy=make-snapshots.target<br />
<br />
[Service]<br />
Type=oneshot<br />
ExecStart=/usr/sbin/lvcreate -L10G -n snap-root -s lvmvolume/root<br />
</pre><br />
<br />
Adapt the <tt>lvcreate</tt> command to match your root volume group and volume name.<br />
<br />
Create a new systemd target <tt>/etc/systemd/system/make-snapshots.target</tt> with this service:<br />
<pre><br />
[Unit]<br />
Description=Make Snapshots<br />
Requires=multi-user.target<br />
</pre><br />
<br />
Enable the new service with <tt>systemctl enable mk-lvm-snapshots.service</tt>.<br />
<br />
If the system is started with the new target, LVM snapshot(s) are created just after mounting the local filesystems.<br />
To get a [[grub]] menu entry starting this target create <tt>/boot/grub/custom.cfg</tt> based on the<br />
<tt>grub.cfg</tt> entry for your normal startup. The kernel command line is extended to start the new <tt>make-snapshots.target</tt>:<br />
<pre><br />
### make snapshots ###<br />
menuentry 'Arch GNU/Linux, make snapshots' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-core repo kernel-true-...' {<br />
...<br />
echo 'Loading Linux core repo kernel ...'<br />
linux /boot/vmlinuz-linux root=/dev/mapper/lvmvolume-root ro systemd.unit=make-snapshots.target<br />
echo 'Loading initial ramdisk ...'<br />
initrd /boot/initramfs-linux.img<br />
}<br />
</pre><br />
<br />
Remember to adjust <tt>custom.cfg</tt> if <tt>grub.cfg</tt> changes.<br />
<br />
After restarting the system with this grub entry <tt>lvs</tt> should show up the newly created snapshot.<br />
To get the messages of the new service use<br />
<tt>journalctl -u mk-lvm-snapshots.service</tt>.</div>Freejackhttps://wiki.archlinux.org/index.php?title=Create_root_filesystem_snapshots_with_LVM&diff=255280Create root filesystem snapshots with LVM2013-04-27T06:05:41Z<p>Freejack: Created page with "This article will show you how to setup LVM snapshot creation during system start. Such snapshots can be used for full system backups with mini..."</p>
<hr />
<div>This article will show you how to setup LVM snapshot creation during system start.<br />
Such snapshots can be used for [[Full System Backup with tar|full system backups]]<br />
with minimal downtime.<br />
<br />
<br />
== Prerequisites ==<br />
<br />
A system with [[LVM]] root and [[systemd]].<br />
<br />
<br />
== Setup ==<br />
<br />
During system start a clean snapshot of the root volume is<br />
created using a new service. Create<br />
<tt>/etc/systemd/system/mk-lvm-snapshots.service</tt> containing:<br />
<pre><br />
[Unit]<br />
Description=make LVM snapshots<br />
Requires=local-fs-pre.target<br />
DefaultDependencies=no<br />
Conflicts=shutdown.target<br />
After=local-fs-pre.target<br />
Before=local-fs.target<br />
<br />
[Install]<br />
WantedBy=make-snapshots.target<br />
<br />
[Service]<br />
Type=oneshot<br />
ExecStart=/usr/sbin/lvcreate -L10G -n snap-root -s lvmvolume/root<br />
</pre><br />
<br />
Adapt the <tt>lvcreate</tt> command to match your root volume group and volume name.</div>Freejackhttps://wiki.archlinux.org/index.php?title=User:Freejack&diff=255278User:Freejack2013-04-27T05:52:44Z<p>Freejack: </p>
<hr />
<div>Use my [[User talk:freejack|talk]] page for public comments. Use my [[Special:EmailUser/freejack|email]] for private comments.<br />
<br />
----<br />
<br />
* [[User:freejack/Create LVM Snapshots for Full System Backup]]<br />
<br />
__NOTOC__ {{DISPLAYTITLE:User:freejack}}</div>Freejackhttps://wiki.archlinux.org/index.php?title=User_talk:Freejack&diff=255277User talk:Freejack2013-04-27T05:49:32Z<p>Freejack: Created page with " ----"</p>
<hr />
<div><br />
----</div>Freejackhttps://wiki.archlinux.org/index.php?title=User:Freejack&diff=255276User:Freejack2013-04-27T05:48:00Z<p>Freejack: Created page with "Use my talk page for public comments. Use my email for private comments. ---- * User:freejack/Main Page __NOTOC__ ..."</p>
<hr />
<div>Use my [[User talk:freejack|talk]] page for public comments. Use my [[Special:EmailUser/freejack|email]] for private comments.<br />
<br />
----<br />
<br />
* [[User:freejack/Main Page]]<br />
<br />
__NOTOC__ {{DISPLAYTITLE:User:freejack}}</div>Freejack