https://wiki.archlinux.org/api.php?action=feedcontributions&user=Pezcurrel&feedformat=atomArchWiki - User contributions [en]2024-03-28T21:31:51ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=Rxvt-unicode&diff=569377Rxvt-unicode2019-03-21T17:09:57Z<p>Pezcurrel: Removed "See the answer to the previous question, and please report if that helped." since it refers to a question and an answer which are not reported here (here they are: https://github.com/exg/rxvt-unicode/blob/master/README.FAQ)</p>
<hr />
<div>{{DISPLAYTITLE:rxvt-unicode}}<br />
[[Category:Terminal emulators]]<br />
[[de:urxvt]]<br />
[[es:Rxvt-unicode]]<br />
[[fr:urxvt]]<br />
[[ja:Rxvt-unicode]]<br />
[[ru:Rxvt-unicode]]<br />
[[sr:Rxvt-unicode]]<br />
{{Related articles start}}<br />
{{Related|rxvt-unicode/Tips and tricks}}<br />
{{Related articles end}}<br />
[http://software.schmorp.de/pkg/rxvt-unicode.html rxvt-unicode] is a customizable terminal emulator forked from [[Wikipedia:Rxvt|rxvt]]. Features of rxvt-unicode include international language support through [[Wikipedia:Unicode|Unicode]], transparency, the ability to display multiple font types and support for [[Perl]] extensions.<br />
<br />
== Installation ==<br />
<br />
[[Install]] the {{Pkg|rxvt-unicode}} package.<br />
<br />
== Configuration ==<br />
<br />
See {{man|1|urxvt}} and {{man|7|urxvt}} for available settings and values.<br />
<br />
=== Xresources ===<br />
<br />
Rxvt-unicode is controlled by command-line arguments or [[Xresources]]. Command-line arguments override, and take precedence over resource settings, see the [[X resources]] article for details.<br />
<br />
{{ic|urxvt --help}} prints all available ''rxvt'' resources to standard error. The man page has full explanations of each resource.<br />
<br />
=== Scrollback position ===<br />
<br />
By default, when shell output appears the scrollback view will automatically jump to the bottom of the buffer to display new output. If in cases where you want to see previous output (e.g., compiler messages), set the following options in {{ic|~/.Xresources}}:<br />
<br />
! do not scroll with output<br />
URxvt*scrollTtyOutput: false<br />
<br />
! scroll in relation to buffer (with mouse scroll or Shift+Page Up)<br />
URxvt*scrollWithBuffer: true<br />
<br />
! scroll back to the bottom on keypress<br />
URxvt*scrollTtyKeypress: true<br />
<br />
=== Scrollback buffer in secondary screen ===<br />
<br />
When you scroll a pager in a ''secondary screen'' (e.g. {{ic|less}} without the {{ic|'''-X'''}} option), it may be a good idea to disable the scrollback buffer to be able to scroll in the pager ''itself'', instead of the terminal's buffer: this is default and unchangeable behaviour in konsole and vte-based terminals.<br />
<br />
In urxvt, to disable the scrollback buffer for the ''secondary screen'':<br />
<br />
URxvt.secondaryScreen: 1<br />
URxvt.secondaryScroll: 0<br />
<br />
The above configuration works as expected except when scrolling with a mouse wheel. When you scroll a pager in the ''secondary screen'' with the mouse wheel - and there has been something in the scrollback buffer, instead of the pager itself - the scrollback buffer will be scrolled by the mouse wheel. To solve this issue, it is necessary to introduce a new option into rxvt-unicode [https://bbs.archlinux.org/viewtopic.php?id=132150]. A patched rxvt-unicode is available in AUR as {{aur|rxvt-unicode-better-wheel-scrolling}}. After installing it, add the following to the configuration file:<br />
<br />
URxvt.secondaryWheel: 1<br />
<br />
{{Note|Avoid using this option with the {{AUR|urxvt-vtwheel}} perl extension, as it will conflict.}}<br />
<br />
=== Font declaration methods ===<br />
<br />
URxvt.font: 9x15<br />
is the same as:<br />
URxvt.font: -misc-fixed-medium-r-normal--15-140-75-75-c-90-iso8859-1<br />
<br />
And, for the same font in bold:<br />
<br />
URxvt.font: 9x15bold<br />
<br />
is the same as:<br />
<br />
URxvt.font: -misc-fixed-bold-r-normal--15-140-75-75-c-90-iso8859-1<br />
<br />
The complete list of short names for X core fonts can be found in {{ic|/usr/share/fonts/misc/fonts.alias}} (there is also some fonts.alias files in some of the other subdirectories of {{ic|/usr/share/fonts/}}, but as they are packaged separately from the actual fonts, they may list fonts you do not actually have installed). It is worth noting that these short aliases select for ISO-8859-1 versions of the fonts rather than ISO-10646-1 (Unicode) versions, and 75 DPI rather than 100 DPI versions, so you are probably better off avoiding them and choosing fonts by their full long names instead.<br />
<br />
{{Note|The above paragraph is only for bitmap fonts. Other fonts can be used through Xft using the following format:}}<br />
URxvt.font: xft:monaco:size=10<br />
<br />
Or<br />
<br />
URxvt.font: xft:monaco:bold:size=10<br />
<br />
{{Note|If there is a hyphen(-) in an Xft font name, it must be escaped with backslash(\) twice. It's different from the usage of urxvt -fn option and the result that fc-list returns, where backslash present only once}}<br />
<br />
A nice method for testing out fonts in a live terminal before committing to the config is by printing escape codes in the terminal, for example:<br />
<br />
$ printf '\e]710;%s\007' "xft:Terminus:pixelsize=12"<br />
<br />
=== Font spacing ===<br />
<br />
By default the distance between characters can feel too wide. The spacing can be reduced by one pixel as such:<br />
<br />
{{hc|~/.Xresources|<nowiki><br />
URxvt.letterSpace: -1<br />
</nowiki>}}<br />
<br />
There is some debate [http://lists.schmorp.de/pipermail/rxvt-unicode/2007q4/000511.html][http://lists.schmorp.de/pipermail/rxvt-unicode/2007q4/000512.html] over how ''urxvt'' calculates character widths. {{AUR|rxvt-unicode-patched}} changes this calculation, usually resulting in tighter character spacing.<br />
<br />
=== Colors ===<br />
<br />
By default, rxvt-unicode is compiled with color support. In addition to the default foreground and background colors, rxvt can display up to 256 colors (plus high-intensity bold/blinking/underlined and any mix of these).<br />
<br />
It is also possible to specify the color values of foreground, background, cursorColor, cursorColor2, colorBD, colorUL as a number 0-15, as a convenient shorthand to reference the color name of color0-color15. See [[#Xresources]] for details.<br />
<br />
{{Note|By default {{ic|urxvt}} uses the same colors as [[Xterm]], except one. Add {{ic|URxvt.color12: rgb:5c/5c/ff}} to Xresources to change this.}}<br />
<br />
=== Printing ===<br />
<br />
By default, rxvt-unicode will print out a screen dump, via lpr, when {{ic|PrintScreen}} is pressed. Using {{ic|Ctrl+PrintScreen}} or {{ic|Shift-PrintScreen}} will include the terminal's scroll back in the printout as well. This behavior can be changed, or disabled entirely, based on personal preference and need.<br />
<br />
{{hc|~/.Xresources|<nowiki><br />
! Disable printing the terminal contents when pressing PrintScreen.<br />
URxvt.print-pipe: "cat > /dev/null"<br />
</nowiki>}}<br />
<br />
== Cut and paste ==<br />
<br />
Rxvt-unicode uses cut buffers which are loaded into the current {{Ic|PRIMARY}} selection by default. See [http://pod.tst.eu/http://cvs.schmorp.de/rxvt-unicode/doc/rxvt.1.pod#THE_SELECTION_SELECTING_AND_PASTING_ Selecting and pasting text] for details. <br />
<br />
It is possible to access the {{ic|CLIPBOARD}} selection with the bindings {{ic|ALT-CTRL-c}} and {{ic|ALT-CTRL-v}} for copy and paste respectively.<br />
<br />
{{Note|Selected text is automatically copied to {{ic|PRIMARY}} selection. The {{ic|selection-to-clipboard}} [[#Perl extensions|perl extension]], available since {{Pkg|rxvt-unicode}} 9.20, copies to {{ic|CLIPBOARD}} selection as well. }}<br />
<br />
See also [[Clipboard#Managers]].<br />
<br />
== Perl extensions ==<br />
<br />
{{Style|Bias towards url-select while matcher and url-select are mostly equivalent, as well as man page duplication}}<br />
<br />
We can enable URxvt perl extensions by including the following line:<br />
<br />
URxvt.perl-ext-common: extension_name_1,extension_name_2,...<br />
<br />
Please take note that there '''should not''' be any spacing between extension names.<br />
<br />
=== Clickable URLs ===<br />
<br />
You can make URLs in the terminal clickable using the matcher extension. For example, to open links in the default web browser with the left mouse button, add the following to {{ic|.Xresources}}:<br />
<br />
URxvt.perl-ext-common: default,matcher<br />
URxvt.url-launcher: /usr/bin/xdg-open<br />
URxvt.matcher.button: 1<br />
<br />
Since rxvt-unicode 9.14, it's also possible to use matcher to open and list recent (currently limited to 10) URLs via keyboard:<br />
<br />
URxvt.keysym.C-Delete: perl:matcher:last<br />
URxvt.keysym.M-Delete: perl:matcher:list<br />
<br />
Matching links can be colored with a chosen foreground or background [[#Colors|color]], for example blue:<br />
<br />
URxvt.matcher.rend.0: Uline Bold fg5<br />
<br />
Alternatively, use {{ic|colorUL}} for a #RRGGBB color. This will however color all underlined text, instead of only link matches:<br />
<br />
URxvt.colorUL: #4682B4<br />
<br />
=== Yankable URLs (no mouse) ===<br />
In addition, you can select and open URLs in your web browser without using the mouse.<br />
Install the {{Pkg|urxvt-perls}} package from the [[official repositories]] and adjust your {{ic|.Xresources}} as necessary. An example is shown below:<br />
URxvt.perl-ext: default,url-select<br />
URxvt.keysym.M-u: perl:url-select:select_next<br />
URxvt.url-select.launcher: /usr/bin/xdg-open<br />
URxvt.url-select.underline: true<br />
<br />
{{Note|This extension replaces the Clickable URLs extension mentioned above, so {{Ic|matcher}} can be removed from the {{Ic|URxvt.perl-ext}} list.}}<br />
<br />
'''Key commands:'''<br />
<br />
{| class="wikitable"<br />
! Key !! Description<br />
|-<br />
| Alt+u || Enter selection mode. The last URL on your screen will be selected. You can repeat {{ic|Alt+u}} to select the next upward URL.<br />
|-<br />
| k || Select next upward URL<br />
|-<br />
| j || Select next downward URL<br />
|-<br />
| Return || Open selected URL in browser and quit selection mode<br />
|-<br />
| o || Open selected URL in browser without quitting selection mode<br />
|-<br />
| y || Copy (yank) selected URL and quit selection mode<br />
|-<br />
| Esc || Cancel URL selection mode<br />
|}<br />
<br />
=== Simple tabs ===<br />
<br />
To add tabs to urxvt, add the following to your {{ic|~/.Xresources}}:<br />
URxvt.perl-ext-common: ...,tabbed,...<br />
<br />
To control tabs use:<br />
<br />
{| class="wikitable"<br />
! Key !! Description<br />
|-<br />
| Shift+Down || New tab<br />
|-<br />
| Shift+Left || Go to left tab<br />
|-<br />
| Shift+Right || Go to right tab<br />
|-<br />
| Ctrl+Left || Move tab to the left<br />
|-<br />
| Ctrl+Right || Move tab to the right<br />
|-<br />
| Ctrl+d || Close tab<br />
|}<br />
<br />
You can change the colors of tabs with the following:<br />
<br />
URxvt.tabbed.tabbar-fg: 2<br />
URxvt.tabbed.tabbar-bg: 0<br />
URxvt.tabbed.tab-fg: 3<br />
URxvt.tabbed.tab-bg: 0<br />
<br />
=== Fullscreen ===<br />
<br />
You can install the [[AUR]] package {{AUR|urxvt-fullscreen}}, and then set a key binding to put urxvt fullscreen.<br />
<br />
{{hc|~/.Xresources|<br />
...<br />
URxvt.perl-ext-common: ...,fullscreen,...<br />
URxvt.keysym.F11: perl:fullscreen:switch<br />
...<br />
}}<br />
<br />
=== Changing font size on the fly ===<br />
<br />
Install {{AUR|urxvt-resize-font-git}} from the [[AUR]], add it to your Perl extensions within {{ic|~/.Xresources}}<br />
<br />
URxvt.perl-ext-common: ...,resize-font,...<br />
<br />
The default keybindings are<br />
* {{ic|Ctrl++}} (or {{ic|1=Ctrl+Shift+=}}) to increase size<br />
* {{ic|Ctrl+-}} to decrease size<br />
* {{ic|1=Ctrl+=}} to reset size<br />
* {{ic|Ctrl+?}} to see current size<br />
<br />
You can also change key bindings, for example like this:<br />
<br />
URxvt.keysym.C-Down: resize-font:smaller<br />
URxvt.keysym.C-Up: resize-font:bigger<br />
<br />
For the Ctrl+Shift bindings to work, a default binding needs to be disabled (see discussion [http://wilmer.gaa.st/blog/archives/36-rxvt-unicode-and-ISO-14755-mode.html here]):<br />
<br />
URxvt.iso14755: false<br />
URxvt.iso14755_52: false<br />
<br />
=== Disabling Perl extensions ===<br />
<br />
If you do not use the Perl extension features, you can improve the security and speed by disabling Perl extensions completely.<br />
URxvt.perl-ext:<br />
URxvt.perl-ext-common:<br />
<br />
{{Note|If you use multiple Perl extension features, you can list them in succession, comma-separated: {{ic|URxvt.perl-ext-common:default,matcher,tabbed}}}}<br />
<br />
== Troubleshooting ==<br />
<br />
=== Transparency not working after upgrade to v9.09 ===<br />
<br />
The rxvt-unicode developers removed compatibility code for a lot of non standard wallpaper setters with this update. Using a non compatible wallpaper setter will break transparency support. Recommended wallpaper setters:<br />
<br />
* [[feh]]<br />
* hsetroot<br />
* esetroot<br />
<br />
To make true transparency work, make sure to comment URxvt.tintColor and URxvt.inheritPixmap.<br />
<br />
=== Remote hosts ===<br />
<br />
If you are logging into a remote host, you may encounter problems when running text-mode programs under rxvt-unicode. This can be fixed by installing {{Pkg|rxvt-unicode-terminfo}} on the remote host or by copying {{ic|/usr/share/terminfo/r/rxvt-unicode}} from your local machine to your host at {{ic|~/.terminfo/r/rxvt-unicode}}; same for rxvt-unicode-256color.<br />
<br />
Some remote systems do not change title automatically unless you specify TERM=xterm. To fix the issue add this line to .bashrc on the remote machine:<br />
<br />
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}:${PWD}\007"'<br />
<br />
=== Using rxvt-unicode as gmrun terminal ===<br />
<br />
Unlike some other terminals, urxvt expects the arguments to {{Ic|-e}} to be given separately, rather than grouped together with quotes. This causes trouble with gmrun, which assumes the opposite behavior. This can be worked around by putting an "eval" in front of gmrun's "Terminal" variable in {{ic|.gmrunrc}}:<br />
<br />
Terminal = eval urxvt<br />
TermExec = ${Terminal} -e<br />
<br />
(gmrun uses {{ic|/bin/sh}} to execute commands, so the "eval" is understood here.) The "eval" has the side-effect of "breaking up" the argument to {{Ic|-e}} in the same way that {{Ic|$@}} does in [[Bash]], making the command intelligible to urxvt.<br />
<br />
=== My numerical keypad acts weird and generates differing output? (e.g. in vim) ===<br />
<br />
Some Debian GNU/Linux users seem to have this problem, although no specific details were reported so far. It is possible that this is caused by the wrong TERM setting, although the details of whether and how this can happen are unknown, as TERM=rxvt should offer a compatible keymap.<br />
<br />
However, using the ''xmodmap'' program ({{Pkg|xorg-xmodmap}}), you can re-map your number pad keys back.<br />
<br />
1. Check the keycode that your numerical keypad (numpad) generates using {{ic|xev}} program.<br />
<br />
* Start the {{ic|xev}} program<br />
* Press your number pad keys and look for ''... keycode xxx ...'' in {{ic|xev}}'s output. For example, numpad 1 in some keyboards is also "End" key, that have a ''''keycode 87''''.<br />
<br />
2. Create or modify your xmodmap file, usually {{ic|~/.Xmodmap}}, with the content representing your keycode.<br />
<br />
Example of xmodmap file with number pad keycode:<br />
<br />
{{bc|1=<br />
keycode 63 = KP_Multiply<br />
keycode 79 = Home KP_7<br />
keycode 80 = Up KP_8<br />
keycode 81 = Prior KP_9<br />
keycode 82 = KP_Subtract<br />
keycode 83 = Left KP_4<br />
keycode 84 = KP_5<br />
keycode 85 = Right KP_6<br />
keycode 86 = KP_Add<br />
keycode 87 = End KP_1<br />
keycode 88 = Down KP_2<br />
keycode 89 = Next KP_3<br />
keycode 90 = Insert KP_0<br />
keycode 91 = Delete KP_Decimal<br />
keycode 112 = Prior<br />
keycode 117 = Next<br />
}}<br />
<br />
3. Load your xmodmap file at X session start-up.<br />
<br />
For example, in {{ic|~/.xinitrc}} file add:<br />
<br />
...<br />
xmodmap ~/.Xmodmap<br />
...<br />
<br />
=== Key combinations do not work ===<br />
<br />
See [http://vim.wikia.com/wiki/Get_Alt_key_to_work_in_terminal?useskin=monobook Get Alt key to work in terminal].<br />
<br />
=== Slow performance when drawing glyphs ===<br />
<br />
Some programs like alsamixer and xprop do not perform well with some graphics drivers and in consequence redraw very slowly. The option "skipBuiltinGlyphs" for {{ic|~/.Xresources}} or the command line option {{ic|-sbg}} may fix this. One possible solution is to add the following to {{ic|~/.Xresources}}:<br />
<br />
URxvt*skipBuiltinGlyphs: true<br />
<br />
=== Very long lines cause slowdown ===<br />
<br />
The {{ic|matcher}} plugin may be the culprit here. It must match a regex against a line every time the line updates, and if you have a large {{ic|saveLines}} value this can exacerbate the problem by allowing a very large maximum line length.<br />
<br />
There are some simple workarounds:<br />
<br />
* Reduce {{ic|saveLines}}<br />
* Disable the {{ic|matcher}} plugin<br />
<br />
If neither of those are palatable options, you can compromise by disabling URL matching past a certain cutoff point:<br />
<br />
# Copy {{ic|/usr/lib/urxvt/perl/matcher}} to {{ic|~/.urxvt/ext/}} (creating the directory if necessary)<br />
# Edit {{ic|~/.urxvt/ext/matcher}}, and find the {{ic|<nowiki>my ($self, $row) = @_;</nowiki>}} line in the {{ic|on_line_update}} sub. It should be line 270.<br />
# After that line, insert the line {{ic|return () if $row < -100;}}. This disables URL matching on any line that starts more than 100 rows behind the top of the terminal.<br />
<br />
== See also ==<br />
<br />
* [http://software.schmorp.de/pkg/rxvt-unicode.html rxvt-unicode] - Official site<br />
* [http://cvs.schmorp.de/rxvt-unicode/ Source Code] - Browseable CVS<br />
* [http://pod.tst.eu/http://cvs.schmorp.de/rxvt-unicode/doc/rxvt.7.pod rxvt-unicode FAQ] - Official FAQ<br />
* [http://pod.tst.eu/http://cvs.schmorp.de/rxvt-unicode/doc/rxvt.1.pod rxvt-unicode Reference] - Official manual page<br />
* [http://pod.tst.eu/http://cvs.schmorp.de/rxvt-unicode/src/urxvt.pm urxvtperl] - Official Perl extension reference</div>Pezcurrelhttps://wiki.archlinux.org/index.php?title=HiDPI&diff=541385HiDPI2018-09-15T11:48:08Z<p>Pezcurrel: /* Xfce */ Added one line about how to set gtk2 icon sizes; think it could be useful</p>
<hr />
<div>[[Category:Graphics]]<br />
[[ja:HiDPI]]<br />
[[zh-hans:HiDPI]]<br />
{{Related articles start}}<br />
{{Related|Font configuration}}<br />
{{Related articles end}}<br />
HiDPI (High Dots Per Inch) displays, also known by Apple's "[[wikipedia:Retina Display|Retina Display]]" marketing name, are screens with a high resolution in a relatively small format. They are mostly found in high-end laptops and monitors.<br />
<br />
Not all software behaves well in high-resolution mode yet. Here are listed most common tweaks which make work on a HiDPI screen more pleasant.<br />
<br />
== Desktop environments ==<br />
<br />
=== GNOME ===<br />
To enable HiDPI, Settings > Devices > Displays,or use gsettings:<br />
<br />
$ gsettings set org.gnome.desktop.interface scaling-factor 2<br />
<br />
{{Note|1={{ic|scaling-factor}} only allows whole numbers to be set. 1 = 100%, 2 = 200%, etc...}}<br />
<br />
==== Fractional Scaling ====<br />
<br />
A setting of {{ic|2, 3, etc}}, which is all you can do with {{ic|scaling-factor}}, may not be ideal for certain HiDPI displays and smaller screens (e.g. small tablets). <br />
<br />
*wayland<br />
Enable fractional Scaling experimental-feature:<br />
<br />
$ gsettings set org.gnome.mutter experimental-features "['scale-monitor-framebuffer']"<br />
<br />
then open Settings > Devices > Displays<br />
<br />
*xorg<br />
<br />
You can achieve any non-integer scale factor by using a combination of GNOME's {{ic|scaling-factor}} and [[xrandr]]. This combination keeps the TTF fonts properly scaled so that they do not become blurry if using {{ic|xrandr}} alone. You specify zoom-in factor with {{ic|gsettings}} and zoom-out factor with [[xrandr]].<br />
<br />
First scale GNOME up to the minimum size which is too big. Usually "2" is already too big, otherwise try "3" etc. Then start scaling down by setting zoom-out factor with [[xrandr]]. First get the relevant output name, the examples below use {{ic|eDP1}}. Start e.g. with zoom-out 1.25 times. If the UI is still too big, increase the scale factor; if it is too small decrease the scale factor.<br />
$ xrandr --output eDP1 --scale 1.25x1.25<br />
<br />
{{Note|To allow the mouse to reach the whole screen, you may need to use the {{ic|--panning}} option as explained in [[#Side display]].}}<br />
<br />
{{Accuracy|The following was initially added under [[#X Resources]]. Clarify how it integrates with the info there or that above for GNOME.|section=GNOME ignores X settings}}<br />
<br />
GNOME ignores X settings due to its xsettings Plugin in Gnome Settings Daemon, where DPI setting is hard coded.<br />
There is blog entry for [http://blog.drtebi.com/2012/12/changing-dpi-setting-on-gnome-34.html recompiling Gnome Settings Daemon].<br />
In the source documentation there is another way mentioned to set X settings DPI:<br />
<br />
You can use the dconf Editor and navigate to key <br />
<br />
/org/gnome/settings-daemon/plugins/xsettings/overrides<br />
<br />
and complement the entry with the value<br />
<br />
'Xft/DPI': <153600><br />
<br />
From README.xsettings<br />
<br />
Noting that variants must be specified in the usual way (wrapped in <>).<br />
<br />
Note also that DPI in the above example is expressed in 1024ths of an inch.<br />
<br />
=== KDE ===<br />
<br />
You can use KDE's settings to fine tune font, icon, and widget scaling. This solution affects both Qt and Gtk+ applications.<br />
<br />
To adjust font, widget, and icon scaling together:<br />
<br />
# System Settings → Display and Monitor → Display Configuration → Scale Display <br />
# Drag the slider to the desired size<br />
# Restart for the settings to take effect<br />
<br />
To adjust only font scaling:<br />
<br />
# System Settings → Fonts<br />
# Check "Force fonts DPI" and adjust the DPI level to the desired value. This setting should take effect immediately for newly started applications. You will have to logout and login for it to take effect on Plasma desktop.<br />
<br />
To adjust only icon scaling:<br />
<br />
# System Settings → Icons → Advanced<br />
# Choose the desired icon size for each category listed. This should take effect immediately.<br />
<br />
'''Display Scale not integer bug :'''<br />
<br />
When you use not integer values for Display Scale it causes font render issue in some QT application ( ex. okular ).<br />
<br />
A workaround for this is to:<br />
# Set the scale value to 1<br />
# Adjust your font and icons and use the "Force fonts DPI" ( this affects all apps, also GTK but not create issue with the fonts )<br />
# Restart KDE<br />
# If required tune the GTK apps using the variables GDK_SCALE/GDK_DPI_SCALE (as described above)<br />
<br />
==== Tray icons with fixed size ====<br />
<br />
The tray icons are not scaled with the rest of the desktop, since Plasma ignores the Qt scaling settings by default. To make Plasma respect the Qt settings, set {{ic|PLASMA_USE_QT_SCALING}} to {{ic|1}}.<br />
<br />
=== Xfce ===<br />
<br />
Go to Settings Manager → Appearance → Fonts, and change the DPI parameter. The value of 180 or 192 seems to work well on Retina screens. To get a more precise number, you can use {{ic|<nowiki>xdpyinfo | grep resolution</nowiki>}}, and then double it.<br />
<br />
To enlarge icons in system tray, right-click on it (aim for empty space / top pixels / bottom pixels, so that you will not activate icons themselves) → “Properties” → set “Maximum icon size” to 32, 48 or 64.<br />
<br />
Xfwm comes with two hidpi themes: Default-hdpi and Default-xhdpi. You can set them under Settings Manager → Window Manager → Style → Theme.<br />
<br />
You can set the default icon sizes of gtk2 menus, buttons and so on under Settings Manager → Settings Editor → xsettings → Gtk → IconSizes, with a line like this: {{ic|<nowiki>gtk-large-toolbar=96,96:gtk-small-toolbar=64,64:gtk-menu=64,64:gtk-dialog=96,96:gtk-button=64,64:gtk-dnd=64,64</nowiki>}}. "gtk-dnd" is for the icons during drag'n'drop, the others are quite self-explanatory. You can use any value your icon theme supports.<br />
<br />
=== Cinnamon ===<br />
<br />
Has good support out of the box.<br />
<br />
=== Enlightenment ===<br />
<br />
For E18, go to the E Setting panel. In Look → Scaling, you can control the UI scaling ratios. A ratio of 1.2 seems to work well for the native resolution of the MBPr 15" screen.<br />
<br />
== X Server ==<br />
<br />
Some programs use the DPI given by the X server. Examples are i3 ([https://github.com/i3/i3/blob/next/libi3/dpi.c source]) and Chromium ([https://code.google.com/p/chromium/codesearch#chromium/src/ui/views/widget/desktop_aura/desktop_screen_x11.cc source]).<br />
<br />
To verify that the X Server has properly detected the physical dimensions of your monitor, use the ''xdpyinfo'' utility from the {{Pkg|xorg-xdpyinfo}} package:<br />
<br />
$ xdpyinfo | grep -B 2 resolution<br />
screen #0:<br />
dimensions: 3200x1800 pixels (423x238 millimeters)<br />
resolution: 192x192 dots per inch<br />
<br />
This example uses inaccurate dimensions (423mm x 328mm, even though the Dell XPS 9530 has 346mm x 194mm) to have a clean multiple of 96 dpi, in this case 192 dpi. This tends to work better than using the correct DPI — Pango renders fonts crisper in i3 for example.<br />
<br />
If the DPI displayed by xdpyinfo is not correct, see [[Xorg#Display size and DPI]] for how to fix it.<br />
<br />
== X Resources ==<br />
<br />
If you are not using a desktop environment such as KDE, Xfce, or other that manipulates the X settings for you, you can set the desired DPI setting manually via the {{ic|Xft.dpi}} variable in [[Xresources]]:<br />
<br />
{{hc|~/.Xresources|<nowiki><br />
Xft.dpi: 180<br />
Xft.autohint: 0<br />
Xft.lcdfilter: lcddefault<br />
Xft.hintstyle: hintfull<br />
Xft.hinting: 1<br />
Xft.antialias: 1<br />
Xft.rgba: rgb<br />
</nowiki>}}<br />
<br />
Make sure the settings are loaded properly when X starts, for instance in your {{ic|~/.xinitrc}} with {{ic|xrdb -merge ~/.Xresources}} (see [[Xresources]] for more information).<br />
<br />
This will make the font render properly in most toolkits and applications, it will however not affect things such as icon size!<br />
Setting {{ic|Xft.dpi}} at the same time as toolkit scale (e.g. {{ic|GDK_SCALE}}) may cause interface elements to be much larger than intended in some programs like firefox.<br />
<br />
== GUI toolkits ==<br />
<br />
=== Qt 5 ===<br />
<br />
Since Qt 5.6, Qt 5 applications can be instructed to honor screen DPI by setting the {{ic|QT_AUTO_SCREEN_SCALE_FACTOR}} environment variable:<br />
<br />
export QT_AUTO_SCREEN_SCALE_FACTOR=1<br />
<br />
If automatic detection of DPI does not produce the desired effect, scaling can be set manually per-screen ({{ic|QT_SCREEN_SCALE_FACTORS}}) or globally ({{ic|QT_SCALE_FACTOR}}). For more details see the [https://blog.qt.io/blog/2016/01/26/high-dpi-support-in-qt-5-6/ Qt blog post].<br />
<br />
{{Note|<br />
* If you manually set the screen factor, it is important to set {{ic|1=QT_AUTO_SCREEN_SCALE_FACTOR=0}} otherwise some applications which explicitly force high DPI enabling get scaled twice.<br />
* {{ic|QT_SCALE_FACTOR}} scales fonts, but {{ic|QT_SCREEN_SCALE_FACTORS}} does not scale fonts.<br />
* If you also set the font DPI manually in ''xrdb'' to support other toolkits, {{ic|QT_SCALE_FACTORS}} will give you huge fonts.<br />
* If you have multiple screens of differing DPI ie: [[#Side display]] you may need to do {{ic|1=QT_SCREEN_SCALE_FACTORS="2;2"}}<br />
}}<br />
<br />
=== GDK 3 (GTK+ 3) ===<br />
<br />
To scale UI elements by a factor of two:<br />
<br />
export GDK_SCALE=2<br />
<br />
To undo scaling of text:<br />
<br />
export GDK_DPI_SCALE=0.5<br />
<br />
=== GTK+ 2 ===<br />
<br />
Scaling of UI elements is not supported by the toolkit itself, however it's possible to generate a theme with elements pre-scaled for HiDPI display using {{AUR|oomox-git}}.<br />
<br />
=== Elementary (EFL) ===<br />
<br />
To scale UI elements by a factor of 1.5:<br />
<br />
export ELM_SCALE=1.5<br />
<br />
For more details see https://phab.enlightenment.org/w/elementary/<br />
<br />
== Boot managers ==<br />
<br />
=== GRUB ===<br />
<br />
==== Lower the framebuffer resolution ====<br />
Set a lower resolution for the framebuffer as explained in [[GRUB/Tips and tricks#Setting the framebuffer resolution]].<br />
<br />
==== Change GRUB font size ====<br />
Find a ttf font that you like in {{ic|/usr/share/fonts/}}.<br />
<br />
Convert the font to a format that GRUB can utilize:<br />
<br />
# grub-mkfont -s 30 -o /boot/grubfont.pf2 /usr/share/fonts/FontFamily/FontName.ttf<br />
<br />
{{Note|Change the {{ic|-s 30}} parameter to modify the font size}}<br />
<br />
Edit {{ic|/etc/default/grub}} to set the new font as shown in [[GRUB/Tips and tricks#Background image and bitmap fonts]]:<br />
<br />
GRUB_FONT="/boot/grubfont.pf2"<br />
<br />
Update GRUB configuration by running {{ic|grub-mkconfig -o /boot/grub/grub.cfg}}<br />
<br />
== Applications ==<br />
<br />
=== Browsers ===<br />
<br />
==== Firefox ====<br />
<br />
Firefox should use the [[#GDK 3 (GTK+ 3)]] settings. However, the suggested {{ic|GDK_SCALE}} suggestion doesn't consistently scale the entirety of Firefox, and doesn't work for fractional values (e.g., a factor of 158DPI/96DPI = 1.65 for a 1080p 14" laptop). You may want to use {{ic|GDK_DPI_SCALE}} instead.<br />
<br />
To override those, open Firefox advanced preferences page ({{ic|about:config}}) and set parameter {{ic|layout.css.devPixelsPerPx}} to {{ic|2}} (or find the one that suits you better; {{ic|2}} is a good choice for Retina screens), but it also doesn't consistently scale the entirety of Firefox. If Firefox is not scaling fonts, you may want to create {{ic|userChrome.css}} and add appropriate styles to it. More information about {{ic|userChrome.css}} at [http://kb.mozillazine.org/index.php?title=UserChrome.css mozillaZine].<br />
<br />
{{hc|~/.mozilla/firefox/<em><profile></em>/chrome/userChrome.css|@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");<br />
<br />
/* #tabbrowser-tabs, #navigator-toolbox, menuitem, menu, ... */<br />
* {<br />
font-size: 15px !important;<br />
}<br />
<br />
/* exception for badge on adblocker */<br />
.toolbarbutton-badge {<br />
font-size: 8px !important;<br />
}<br />
}}<br />
<br />
{{Warning|The following extension is not compatible with Firefox Quantum (version 57 and above).}}<br />
<br />
If you use a HiDPI monitor such as Retina display together with another monitor, you can use [https://addons.mozilla.org/en-US/firefox/addon/autohidpi/ AutoHiDPI] add-on in order to automatically adjust {{ic|layout.css.devPixelsPerPx}} setting for the active screen. Also, since Firefox version 49, it auto-scales based on your screen resolution, making it easier to deal with 2 or more screens.<br />
<br />
==== Chromium / Google Chrome ====<br />
<br />
Chromium should use the [[#GDK 3 (GTK+ 3)]] settings.<br />
<br />
To override those, use the {{ic|1=--force-device-scale-factor}} flag with a scaling value. This will scale all content and ui, including tab and font size. For example {{ic|1=chromium --force-device-scale-factor=2}}.<br />
<br />
Using this option, a scaling factor of 1 would be normal scaling. Floating point values can be used. To make the change permanent, for Chromium, you can add it to {{ic|~/.config/chromium-flags.conf}}:<br />
<br />
{{hc|~/.config/chromium-flags.conf|2=--force-device-scale-factor=2}}<br />
<br />
To make this work for Chrome, add the same option to {{ic|~/.config/chrome-flags.conf}} instead.<br />
<br />
If you use a HiDPI monitor such as Retina display together with another monitor, you can use the [https://chrome.google.com/webstore/detail/resolution-zoom/enjjhajnmggdgofagbokhmifgnaophmh reszoom] extension in order to automatically adjust the zoom level for the active screen.<br />
<br />
==== Opera ====<br />
<br />
Opera should use the [[#GDK 3 (GTK+ 3)]] settings.<br />
<br />
To override those, use the {{ic|1=--alt-high-dpi-setting=X}} command line option, where X is the desired DPI. For example, with {{ic|1=--alt-high-dpi-setting=144}} Opera will assume that DPI is 144. Newer versions of opera will auto detect the DPI using the font DPI setting (in KDE: the force font DPI setting.)<br />
<br />
=== Thunderbird ===<br />
<br />
See [[#Firefox]]. To access {{ic|about:config}}, go to Edit → Preferences → Advanced → Config editor.<br />
<br />
=== Wine applications ===<br />
<br />
Run<br />
$ winecfg<br />
and change the "dpi" setting found in the "Graphics" tab. This only affects the font size.<br />
<br />
=== Skype ===<br />
<br />
Skype for Linux ({{AUR|skypeforlinux-stable-bin}} package) uses [[#GDK 3 (GTK+ 3)]].<br />
<br />
=== Spotify ===<br />
<br />
You can change scale factor by simple {{ic|Ctrl++}} for zoom in, {{ic|Ctrl+-}} for zoom out and {{ic|Ctrl+0}} for default scale. Scaling setting will be saved in {{ic|~/.config/spotify/Users/YOUR-SPOTIFY-USER-NAME/prefs}}:<br />
<br />
{{hc|~/.config/spotify/Users/YOUR-SPOTIFY-USER-NAME/prefs|<nowiki><br />
app.browser.zoom-level=100<br />
</nowiki>}}<br />
<br />
Also Spotify can be launched with a custom scaling factor which will be multiplied with setting specified in {{ic|~/.config/spotify/Users/YOUR-SPOTIFY-USER-NAME/prefs}}, for example<br />
$ spotify --force-device-scale-factor=1.5<br />
<br />
=== Zathura document viewer ===<br />
<br />
No modifications required for document viewing.<br />
<br />
UI text scaling is specified via [https://pwmt.org/projects/zathura/documentation/ configuration file] (note that "font" is a [https://pwmt.org/projects/girara/options/ girara option]):<br />
<br />
set font "monospace normal 20"<br />
<br />
=== Sublime Text 3 ===<br />
Sublime Text 3 has full support for display scaling. Go to Preferences > Settings > User Settings and add {{ic|"dpi_scale": 2.0}} to your settings [http://blog.wxm.be/2014/08/30/sublime-text-3-and-high-dpi-on-linux.html (source)].<br />
<br />
=== IntelliJ IDEA ===<br />
<br />
IntelliJ IDEA 15 and above should include HiDPI support.[http://blog.jetbrains.com/idea/2015/07/intellij-idea-15-eap-comes-with-true-hidpi-support-for-windows-and-linux/] If it does not work, the most convenient way to fix the problem in this case seems to be changing the Override Default Fonts setting:<br />
<br />
:''File -> Settings -> Behaviour & Appearance -> Appearance''<br />
<br />
The addition of {{ic|1=-Dhidpi=true}} to the vmoptions file in either {{ic|$HOME/.IdeaC14/}} or {{ic|/usr/share/intelligj-idea-ultimate-edition/bin/}} of [https://youtrack.jetbrains.com/issue/IDEA-114944 release 14] should not be required anymore.<br />
<br />
=== NetBeans ===<br />
<br />
NetBeans allows the font size of its interface to be controlled using the {{ic|1=--fontsize}} parameter during startup. To make this change permanent edit the {{ic|1=/usr/share/netbeans/etc/netbeans.conf}} file and append the {{ic|1=--fontsize}} parameter to the {{ic|1=netbeans_default_options}} property.[http://wiki.netbeans.org/FaqFontSize]<br />
<br />
The editor fontsize can be controlled from Tools → Option → Fonts & Colors.<br />
<br />
The output window fontsize can be controlled from Tools → Options → Miscelaneous → Output<br />
<br />
=== Gimp 2.8 ===<br />
<br />
Use a high DPI theme, or adjust {{ic|1=gtkrc}} of an existing theme. (Change all occurrences of the size {{ic|1=button}} to {{ic|1=dialog}}, for example {{ic|1=GimpToolPalette::tool-icon-size}}.)<br />
<br />
There is also the [https://github.com/jedireza/gimp-hidpi gimp-hidpi].<br />
<br />
=== Steam ===<br />
<br />
==== Official HiDPI support ====<br />
* Starting on 25 of January 2018 in the beta program there is actual support for HiDPI and it should be automatically detected.<br />
* Steam -> Settings -> Interface -> check "Enlarge text and icons based on monitor size" (restart required)<br />
* If it not automatically detected use {{ic|1=GDK_SCALE=2}} to set the desired scale factor.<br />
<br />
==== Unofficial ====<br />
The [https://github.com/MoriTanosuke/HiDPI-Steam-Skin HiDPI-Steam-Skin] can be installed to increase the font size of the interface. While not perfect, it does improve usability. <br />
<br />
{{Note|The README for the HiDPI skin lists several possible locations for where to place the skin. The correct folder out of these can be identified by the presence of a file named {{ic|1=skins_readme.txt}}.}}<br />
<br />
[http://steamcommunity.com/groups/metroskin/discussions/0/517142253861033946/ MetroSkin Unofficial Patch] also helps with HiDPI on Steam with Linux.<br />
<br />
=== Java applications ===<br />
<br />
Java applications using the AWT/Swing framework can be scaled by defining the sun.java2d.uiScale variable when invoking java. For example,<br />
<br />
java -Dsun.java2d.uiScale=2 -jar some_application.jar<br />
<br />
Since Java 9 the GDK_SCALE environment variable is used to scale Swing applications accordingly.<br />
<br />
=== Mono applications ===<br />
<br />
According to [https://bugzilla.xamarin.com/show_bug.cgi?id=35870], Mono applications should be scalable like [[#GDK 3 (GTK+ 3)|GTK3]] applications.<br />
<br />
=== MATLAB ===<br />
<br />
Recent versions (R2017b) of [[Matlab]] allow to set the scale factor:<br />
>> s = settings;s.matlab.desktop.DisplayScaleFactor<br />
>> s.matlab.desktop.DisplayScaleFactor.PersonalValue = 2<br />
The settings take effect after MATLAB is restarted.<br />
<br />
=== VirtualBox ===<br />
<br />
{{Note|This ony applies to KDE with scaling enabled.}}<br />
VirtualBox also applies the system-wide scaling to the virtual monitor, which reduces the maximum resolution inside VMs by your scaling factor (see [https://www.virtualbox.org/ticket/16604]).<br />
<br />
This can be worked around by calculating the inverse of your scaling factor and manually setting this new scaling factor for the VirtualBox execution, e.g.<br />
$ QT_SCALE_FACTOR=0.5 VirtualBox --startvm vm-name<br />
<br />
=== Zoom ===<br />
<br />
Zoom can be started with a proper scaling by overriding the {{ic|1=QT_SCALE_FACTOR}} environment variable.<br />
<br />
$ QT_SCALE_FACTOR=2 zoom<br />
<br />
=== Unsupported applications ===<br />
<br />
{{AUR|run_scaled-git}} can be used to scale applications (which uses {{Pkg|xpra}} internally).<br />
<br />
Another approach is to run the application full screen and without decoration in its own VNC desktop. Then scale the viewer. With Vncdesk ({{AUR|vncdesk-git}} from the [[AUR]]) you can set up a desktop per application, then start server and client with a simple command such as {{ic|vncdesk 2}}.<br />
<br />
[[x11vnc]] has an experimental option {{ic|-appshare}}, which opens one viewer per application window. Perhaps something could be hacked up with that.<br />
<br />
== Multiple displays ==<br />
The HiDPI setting applies to the whole desktop, so non-HiDPI external displays show everything too large. However, note that setting different scaling factors for different monitors is already supported in [[Wayland]].<br />
<br />
=== Side display ===<br />
{{Out of date|1=The bug with the mouse unable to reach the whole screen should be [https://bugs.freedesktop.org/show_bug.cgi?id=39949#c80 fixed in xorg 1.20].}}<br />
<br />
One workaround is to use [[xrandr]]'s scale option. To have a non-HiDPI monitor (on DP1) right of an internal HiDPI display (eDP1), one could run:<br />
<br />
xrandr --output eDP-1 --auto --output DP-1 --auto --scale 2x2 --right-of eDP-1<br />
<br />
When extending above the internal display, you may see part of the internal display on the external monitor. In that case, specify the position manually, e.g. using [https://gist.github.com/wvengen/178642bbc8236c1bdb67 this script].<br />
<br />
You may run into problems with your mouse not being able to reach the whole screen. That is a [https://bugs.freedesktop.org/show_bug.cgi?id=39949 known bug] with an xserver-org patch (or try the panning option, but that might cause other problems).<br />
<br />
An example of the panning syntax for a 4k laptop with an external 1920x1080 monitor to the right:<br />
<br />
xrandr --output eDP-1 --auto --output HDMI-1 --auto --panning 3840x2160+3840+0 --scale 2x2 --right-of eDP-1<br />
<br />
Generically if your HiDPI monitor is AxB pixels and your regular monitor is CxD and you are scaling by [ExF], the commandline for right-of is:<br />
<br />
xrandr --output eDP-1 --auto --output HDMI-1 --auto --panning [C*E]x[D*F]+[A]+0 --scale [E]x[F] --right-of eDP-1<br />
<br />
If panning is not a solution for you it may be better to set position of monitors and fix manually the total display screen.<br />
<br />
An example of the syntax for a 2560x1440 WQHD 210 DPI laptop monitor (eDP1) using native resolution placed below a 1920x1080 FHD 96 DPI external monitor (HDMI) scaled to match global DPI settings:<br />
<br />
xrandr --output eDP-1 --auto --pos 0x1458 --output HDMI-1 --scale 1.35x1.35 --auto --pos 0x0 --fb 2592x2898<br />
<br />
The total screen size (--fb) and positioning (--pos) are to be calculated taking into account the scaling factor.<br />
<br />
In this case laptop monitor (eDP1) has no scaling and uses native mode for resolution so it will total 2560x1440, but external monitor (HDMI) is scaled and it has to be considered a larger screen so (1920*1.35)x(1080*1.35) from where the eDP1 Y position came 1080*1.35=1458 and the total screen size: since one on top of the other X=(greater between eDP1 and HDMI, so 1920*1.35=2592) and Y=(sum of the calculated heights of eDP1 and HDMI, so 1440+(1080*1.35)=2898).<br />
<br />
Generically if your hidpi monitor is AxB pixels and your regular monitor is CxD and you are scaling by [ExF] and hidpi is placed below regular one, the commandline for right-of is:<br />
<br />
xrandr --output eDP-1 --auto --pos 0x(DxF) --output HDMI-1 --auto --scale [E]x[F] --pos 0x0 --fb [greater between A and (C*E)]x[B+(D*F)]<br />
<br />
You may adjust the "sharpness" parameter on your monitor settings to adjust the blur level introduced with scaling.<br />
<br />
{{Note|1=Above solution with {{ic|--scale 2x2}} does not work on some Nvidia cards. No solution is currently available. [https://bbs.archlinux.org/viewtopic.php?pid=1670840] A potential workaround exists with configuring {{ic|1=ForceFullCompositionPipeline=On}} on the {{ic|CurrentMetaMode}} via {{ic|nvidia-settings}}. For more info see [https://askubuntu.com/a/979551/763549].}}<br />
<br />
=== Multiple external monitors ===<br />
There might be some problems in scaling more than one external monitors which have lower dpi than the built-in HiDPI display. In that case, you may want to try downscaling the HiDPI display instead, with e.g.<br />
<br />
xrandr --output eDP1 --scale 0.5x0.5 --output DP2 --right-of eDP1 --output HDMI1 --right-of DP2<br />
<br />
In addition, when you downscale the HiDPI display, the font on the HiDPI display will be slightly blurry, but it's a different kind of bluriness compared with the one introduced by upscaling the external displays. You may compare and see which kind of bluriness is less problematic for you.<br />
<br />
=== Mirroring ===<br />
<br />
If all you want is to mirror ("unify") displays, this is easy as well:<br />
<br />
With AxB your native HiDPI resolution (for ex 3200x1800) and CxD your external screen resolution (for ex 1920x1200)<br />
<br />
xrandr --output HDMI --scale [A/C]x[B/D]<br />
<br />
In this example which is QHD (3200/1920 = 1.66 and 1800/1200 = 1.5)<br />
<br />
xrandr --output HDMI --scale 1.66x1.5<br />
<br />
For UHD to 1080p (3840/1920=2 2160/1080=2)<br />
<br />
xrandr --output HDMI --scale 2x2<br />
<br />
You may adjust the "sharpness" parameter on your monitor settings to adjust the blur level introduced with scaling.<br />
<br />
== Linux console ==<br />
<br />
The default [[w:Linux console|Linux console]] font will be very small on hidpi displays, the largest font present in the {{Pkg|kbd}} package is {{ic|latarcyrheb-sun32}} and other packages like {{Pkg|terminus-font}} contain further alternatives, such as {{ic|ter-132n}}(normal) and {{ic|ter-132b}}(bold). See [[Fonts#Console fonts]] for configuration details.<br />
<br />
After changing the font, it is often garbled and unreadable when changing to other virtual consoles ({{ic|tty2-6}}). To fix this you can [[Kernel_mode_setting#Forcing_modes_and_EDID|force specific mode]] for KMS, such as {{ic|1=video=2560x1600@60}} (substitute in the native resolution of your HiDPI display), and reboot.<br />
<br />
== See also ==<br />
<br />
* [http://www.phoronix.com/scan.php?page=article&item=linux_uhd4k_gpus Ultra HD 4K Linux Graphics Card Testing] (Nov 2013)<br />
* [http://www.eizo.com/library/basics/pixel_density_4k/ Understanding pixel density]</div>Pezcurrelhttps://wiki.archlinux.org/index.php?title=HiDPI&diff=541382HiDPI2018-09-15T11:14:51Z<p>Pezcurrel: /* Xfce */ Added one line about default hidpi xfwm themes, I think it can be useful to know</p>
<hr />
<div>[[Category:Graphics]]<br />
[[ja:HiDPI]]<br />
[[zh-hans:HiDPI]]<br />
{{Related articles start}}<br />
{{Related|Font configuration}}<br />
{{Related articles end}}<br />
HiDPI (High Dots Per Inch) displays, also known by Apple's "[[wikipedia:Retina Display|Retina Display]]" marketing name, are screens with a high resolution in a relatively small format. They are mostly found in high-end laptops and monitors.<br />
<br />
Not all software behaves well in high-resolution mode yet. Here are listed most common tweaks which make work on a HiDPI screen more pleasant.<br />
<br />
== Desktop environments ==<br />
<br />
=== GNOME ===<br />
To enable HiDPI, Settings > Devices > Displays,or use gsettings:<br />
<br />
$ gsettings set org.gnome.desktop.interface scaling-factor 2<br />
<br />
{{Note|1={{ic|scaling-factor}} only allows whole numbers to be set. 1 = 100%, 2 = 200%, etc...}}<br />
<br />
==== Fractional Scaling ====<br />
<br />
A setting of {{ic|2, 3, etc}}, which is all you can do with {{ic|scaling-factor}}, may not be ideal for certain HiDPI displays and smaller screens (e.g. small tablets). <br />
<br />
*wayland<br />
Enable fractional Scaling experimental-feature:<br />
<br />
$ gsettings set org.gnome.mutter experimental-features "['scale-monitor-framebuffer']"<br />
<br />
then open Settings > Devices > Displays<br />
<br />
*xorg<br />
<br />
You can achieve any non-integer scale factor by using a combination of GNOME's {{ic|scaling-factor}} and [[xrandr]]. This combination keeps the TTF fonts properly scaled so that they do not become blurry if using {{ic|xrandr}} alone. You specify zoom-in factor with {{ic|gsettings}} and zoom-out factor with [[xrandr]].<br />
<br />
First scale GNOME up to the minimum size which is too big. Usually "2" is already too big, otherwise try "3" etc. Then start scaling down by setting zoom-out factor with [[xrandr]]. First get the relevant output name, the examples below use {{ic|eDP1}}. Start e.g. with zoom-out 1.25 times. If the UI is still too big, increase the scale factor; if it is too small decrease the scale factor.<br />
$ xrandr --output eDP1 --scale 1.25x1.25<br />
<br />
{{Note|To allow the mouse to reach the whole screen, you may need to use the {{ic|--panning}} option as explained in [[#Side display]].}}<br />
<br />
{{Accuracy|The following was initially added under [[#X Resources]]. Clarify how it integrates with the info there or that above for GNOME.|section=GNOME ignores X settings}}<br />
<br />
GNOME ignores X settings due to its xsettings Plugin in Gnome Settings Daemon, where DPI setting is hard coded.<br />
There is blog entry for [http://blog.drtebi.com/2012/12/changing-dpi-setting-on-gnome-34.html recompiling Gnome Settings Daemon].<br />
In the source documentation there is another way mentioned to set X settings DPI:<br />
<br />
You can use the dconf Editor and navigate to key <br />
<br />
/org/gnome/settings-daemon/plugins/xsettings/overrides<br />
<br />
and complement the entry with the value<br />
<br />
'Xft/DPI': <153600><br />
<br />
From README.xsettings<br />
<br />
Noting that variants must be specified in the usual way (wrapped in <>).<br />
<br />
Note also that DPI in the above example is expressed in 1024ths of an inch.<br />
<br />
=== KDE ===<br />
<br />
You can use KDE's settings to fine tune font, icon, and widget scaling. This solution affects both Qt and Gtk+ applications.<br />
<br />
To adjust font, widget, and icon scaling together:<br />
<br />
# System Settings → Display and Monitor → Display Configuration → Scale Display <br />
# Drag the slider to the desired size<br />
# Restart for the settings to take effect<br />
<br />
To adjust only font scaling:<br />
<br />
# System Settings → Fonts<br />
# Check "Force fonts DPI" and adjust the DPI level to the desired value. This setting should take effect immediately for newly started applications. You will have to logout and login for it to take effect on Plasma desktop.<br />
<br />
To adjust only icon scaling:<br />
<br />
# System Settings → Icons → Advanced<br />
# Choose the desired icon size for each category listed. This should take effect immediately.<br />
<br />
'''Display Scale not integer bug :'''<br />
<br />
When you use not integer values for Display Scale it causes font render issue in some QT application ( ex. okular ).<br />
<br />
A workaround for this is to:<br />
# Set the scale value to 1<br />
# Adjust your font and icons and use the "Force fonts DPI" ( this affects all apps, also GTK but not create issue with the fonts )<br />
# Restart KDE<br />
# If required tune the GTK apps using the variables GDK_SCALE/GDK_DPI_SCALE (as described above)<br />
<br />
==== Tray icons with fixed size ====<br />
<br />
The tray icons are not scaled with the rest of the desktop, since Plasma ignores the Qt scaling settings by default. To make Plasma respect the Qt settings, set {{ic|PLASMA_USE_QT_SCALING}} to {{ic|1}}.<br />
<br />
=== Xfce ===<br />
<br />
Go to Settings Manager → Appearance → Fonts, and change the DPI parameter. The value of 180 or 192 seems to work well on Retina screens. To get a more precise number, you can use {{ic|<nowiki>xdpyinfo | grep resolution</nowiki>}}, and then double it.<br />
<br />
To enlarge icons in system tray, right-click on it (aim for empty space / top pixels / bottom pixels, so that you will not activate icons themselves) → “Properties” → set “Maximum icon size” to 32, 48 or 64.<br />
<br />
Xfwm comes with two hidpi themes: Default-hdpi and Default-xhdpi. You can set them under Settings Manager → Window Manager → Style → Theme.<br />
<br />
=== Cinnamon ===<br />
<br />
Has good support out of the box.<br />
<br />
=== Enlightenment ===<br />
<br />
For E18, go to the E Setting panel. In Look → Scaling, you can control the UI scaling ratios. A ratio of 1.2 seems to work well for the native resolution of the MBPr 15" screen.<br />
<br />
== X Server ==<br />
<br />
Some programs use the DPI given by the X server. Examples are i3 ([https://github.com/i3/i3/blob/next/libi3/dpi.c source]) and Chromium ([https://code.google.com/p/chromium/codesearch#chromium/src/ui/views/widget/desktop_aura/desktop_screen_x11.cc source]).<br />
<br />
To verify that the X Server has properly detected the physical dimensions of your monitor, use the ''xdpyinfo'' utility from the {{Pkg|xorg-xdpyinfo}} package:<br />
<br />
$ xdpyinfo | grep -B 2 resolution<br />
screen #0:<br />
dimensions: 3200x1800 pixels (423x238 millimeters)<br />
resolution: 192x192 dots per inch<br />
<br />
This example uses inaccurate dimensions (423mm x 328mm, even though the Dell XPS 9530 has 346mm x 194mm) to have a clean multiple of 96 dpi, in this case 192 dpi. This tends to work better than using the correct DPI — Pango renders fonts crisper in i3 for example.<br />
<br />
If the DPI displayed by xdpyinfo is not correct, see [[Xorg#Display size and DPI]] for how to fix it.<br />
<br />
== X Resources ==<br />
<br />
If you are not using a desktop environment such as KDE, Xfce, or other that manipulates the X settings for you, you can set the desired DPI setting manually via the {{ic|Xft.dpi}} variable in [[Xresources]]:<br />
<br />
{{hc|~/.Xresources|<nowiki><br />
Xft.dpi: 180<br />
Xft.autohint: 0<br />
Xft.lcdfilter: lcddefault<br />
Xft.hintstyle: hintfull<br />
Xft.hinting: 1<br />
Xft.antialias: 1<br />
Xft.rgba: rgb<br />
</nowiki>}}<br />
<br />
Make sure the settings are loaded properly when X starts, for instance in your {{ic|~/.xinitrc}} with {{ic|xrdb -merge ~/.Xresources}} (see [[Xresources]] for more information).<br />
<br />
This will make the font render properly in most toolkits and applications, it will however not affect things such as icon size!<br />
Setting {{ic|Xft.dpi}} at the same time as toolkit scale (e.g. {{ic|GDK_SCALE}}) may cause interface elements to be much larger than intended in some programs like firefox.<br />
<br />
== GUI toolkits ==<br />
<br />
=== Qt 5 ===<br />
<br />
Since Qt 5.6, Qt 5 applications can be instructed to honor screen DPI by setting the {{ic|QT_AUTO_SCREEN_SCALE_FACTOR}} environment variable:<br />
<br />
export QT_AUTO_SCREEN_SCALE_FACTOR=1<br />
<br />
If automatic detection of DPI does not produce the desired effect, scaling can be set manually per-screen ({{ic|QT_SCREEN_SCALE_FACTORS}}) or globally ({{ic|QT_SCALE_FACTOR}}). For more details see the [https://blog.qt.io/blog/2016/01/26/high-dpi-support-in-qt-5-6/ Qt blog post].<br />
<br />
{{Note|<br />
* If you manually set the screen factor, it is important to set {{ic|1=QT_AUTO_SCREEN_SCALE_FACTOR=0}} otherwise some applications which explicitly force high DPI enabling get scaled twice.<br />
* {{ic|QT_SCALE_FACTOR}} scales fonts, but {{ic|QT_SCREEN_SCALE_FACTORS}} does not scale fonts.<br />
* If you also set the font DPI manually in ''xrdb'' to support other toolkits, {{ic|QT_SCALE_FACTORS}} will give you huge fonts.<br />
* If you have multiple screens of differing DPI ie: [[#Side display]] you may need to do {{ic|1=QT_SCREEN_SCALE_FACTORS="2;2"}}<br />
}}<br />
<br />
=== GDK 3 (GTK+ 3) ===<br />
<br />
To scale UI elements by a factor of two:<br />
<br />
export GDK_SCALE=2<br />
<br />
To undo scaling of text:<br />
<br />
export GDK_DPI_SCALE=0.5<br />
<br />
=== GTK+ 2 ===<br />
<br />
Scaling of UI elements is not supported by the toolkit itself, however it's possible to generate a theme with elements pre-scaled for HiDPI display using {{AUR|oomox-git}}.<br />
<br />
=== Elementary (EFL) ===<br />
<br />
To scale UI elements by a factor of 1.5:<br />
<br />
export ELM_SCALE=1.5<br />
<br />
For more details see https://phab.enlightenment.org/w/elementary/<br />
<br />
== Boot managers ==<br />
<br />
=== GRUB ===<br />
<br />
==== Lower the framebuffer resolution ====<br />
Set a lower resolution for the framebuffer as explained in [[GRUB/Tips and tricks#Setting the framebuffer resolution]].<br />
<br />
==== Change GRUB font size ====<br />
Find a ttf font that you like in {{ic|/usr/share/fonts/}}.<br />
<br />
Convert the font to a format that GRUB can utilize:<br />
<br />
# grub-mkfont -s 30 -o /boot/grubfont.pf2 /usr/share/fonts/FontFamily/FontName.ttf<br />
<br />
{{Note|Change the {{ic|-s 30}} parameter to modify the font size}}<br />
<br />
Edit {{ic|/etc/default/grub}} to set the new font as shown in [[GRUB/Tips and tricks#Background image and bitmap fonts]]:<br />
<br />
GRUB_FONT="/boot/grubfont.pf2"<br />
<br />
Update GRUB configuration by running {{ic|grub-mkconfig -o /boot/grub/grub.cfg}}<br />
<br />
== Applications ==<br />
<br />
=== Browsers ===<br />
<br />
==== Firefox ====<br />
<br />
Firefox should use the [[#GDK 3 (GTK+ 3)]] settings. However, the suggested {{ic|GDK_SCALE}} suggestion doesn't consistently scale the entirety of Firefox, and doesn't work for fractional values (e.g., a factor of 158DPI/96DPI = 1.65 for a 1080p 14" laptop). You may want to use {{ic|GDK_DPI_SCALE}} instead.<br />
<br />
To override those, open Firefox advanced preferences page ({{ic|about:config}}) and set parameter {{ic|layout.css.devPixelsPerPx}} to {{ic|2}} (or find the one that suits you better; {{ic|2}} is a good choice for Retina screens), but it also doesn't consistently scale the entirety of Firefox. If Firefox is not scaling fonts, you may want to create {{ic|userChrome.css}} and add appropriate styles to it. More information about {{ic|userChrome.css}} at [http://kb.mozillazine.org/index.php?title=UserChrome.css mozillaZine].<br />
<br />
{{hc|~/.mozilla/firefox/<em><profile></em>/chrome/userChrome.css|@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");<br />
<br />
/* #tabbrowser-tabs, #navigator-toolbox, menuitem, menu, ... */<br />
* {<br />
font-size: 15px !important;<br />
}<br />
<br />
/* exception for badge on adblocker */<br />
.toolbarbutton-badge {<br />
font-size: 8px !important;<br />
}<br />
}}<br />
<br />
{{Warning|The following extension is not compatible with Firefox Quantum (version 57 and above).}}<br />
<br />
If you use a HiDPI monitor such as Retina display together with another monitor, you can use [https://addons.mozilla.org/en-US/firefox/addon/autohidpi/ AutoHiDPI] add-on in order to automatically adjust {{ic|layout.css.devPixelsPerPx}} setting for the active screen. Also, since Firefox version 49, it auto-scales based on your screen resolution, making it easier to deal with 2 or more screens.<br />
<br />
==== Chromium / Google Chrome ====<br />
<br />
Chromium should use the [[#GDK 3 (GTK+ 3)]] settings.<br />
<br />
To override those, use the {{ic|1=--force-device-scale-factor}} flag with a scaling value. This will scale all content and ui, including tab and font size. For example {{ic|1=chromium --force-device-scale-factor=2}}.<br />
<br />
Using this option, a scaling factor of 1 would be normal scaling. Floating point values can be used. To make the change permanent, for Chromium, you can add it to {{ic|~/.config/chromium-flags.conf}}:<br />
<br />
{{hc|~/.config/chromium-flags.conf|2=--force-device-scale-factor=2}}<br />
<br />
To make this work for Chrome, add the same option to {{ic|~/.config/chrome-flags.conf}} instead.<br />
<br />
If you use a HiDPI monitor such as Retina display together with another monitor, you can use the [https://chrome.google.com/webstore/detail/resolution-zoom/enjjhajnmggdgofagbokhmifgnaophmh reszoom] extension in order to automatically adjust the zoom level for the active screen.<br />
<br />
==== Opera ====<br />
<br />
Opera should use the [[#GDK 3 (GTK+ 3)]] settings.<br />
<br />
To override those, use the {{ic|1=--alt-high-dpi-setting=X}} command line option, where X is the desired DPI. For example, with {{ic|1=--alt-high-dpi-setting=144}} Opera will assume that DPI is 144. Newer versions of opera will auto detect the DPI using the font DPI setting (in KDE: the force font DPI setting.)<br />
<br />
=== Thunderbird ===<br />
<br />
See [[#Firefox]]. To access {{ic|about:config}}, go to Edit → Preferences → Advanced → Config editor.<br />
<br />
=== Wine applications ===<br />
<br />
Run<br />
$ winecfg<br />
and change the "dpi" setting found in the "Graphics" tab. This only affects the font size.<br />
<br />
=== Skype ===<br />
<br />
Skype for Linux ({{AUR|skypeforlinux-stable-bin}} package) uses [[#GDK 3 (GTK+ 3)]].<br />
<br />
=== Spotify ===<br />
<br />
You can change scale factor by simple {{ic|Ctrl++}} for zoom in, {{ic|Ctrl+-}} for zoom out and {{ic|Ctrl+0}} for default scale. Scaling setting will be saved in {{ic|~/.config/spotify/Users/YOUR-SPOTIFY-USER-NAME/prefs}}:<br />
<br />
{{hc|~/.config/spotify/Users/YOUR-SPOTIFY-USER-NAME/prefs|<nowiki><br />
app.browser.zoom-level=100<br />
</nowiki>}}<br />
<br />
Also Spotify can be launched with a custom scaling factor which will be multiplied with setting specified in {{ic|~/.config/spotify/Users/YOUR-SPOTIFY-USER-NAME/prefs}}, for example<br />
$ spotify --force-device-scale-factor=1.5<br />
<br />
=== Zathura document viewer ===<br />
<br />
No modifications required for document viewing.<br />
<br />
UI text scaling is specified via [https://pwmt.org/projects/zathura/documentation/ configuration file] (note that "font" is a [https://pwmt.org/projects/girara/options/ girara option]):<br />
<br />
set font "monospace normal 20"<br />
<br />
=== Sublime Text 3 ===<br />
Sublime Text 3 has full support for display scaling. Go to Preferences > Settings > User Settings and add {{ic|"dpi_scale": 2.0}} to your settings [http://blog.wxm.be/2014/08/30/sublime-text-3-and-high-dpi-on-linux.html (source)].<br />
<br />
=== IntelliJ IDEA ===<br />
<br />
IntelliJ IDEA 15 and above should include HiDPI support.[http://blog.jetbrains.com/idea/2015/07/intellij-idea-15-eap-comes-with-true-hidpi-support-for-windows-and-linux/] If it does not work, the most convenient way to fix the problem in this case seems to be changing the Override Default Fonts setting:<br />
<br />
:''File -> Settings -> Behaviour & Appearance -> Appearance''<br />
<br />
The addition of {{ic|1=-Dhidpi=true}} to the vmoptions file in either {{ic|$HOME/.IdeaC14/}} or {{ic|/usr/share/intelligj-idea-ultimate-edition/bin/}} of [https://youtrack.jetbrains.com/issue/IDEA-114944 release 14] should not be required anymore.<br />
<br />
=== NetBeans ===<br />
<br />
NetBeans allows the font size of its interface to be controlled using the {{ic|1=--fontsize}} parameter during startup. To make this change permanent edit the {{ic|1=/usr/share/netbeans/etc/netbeans.conf}} file and append the {{ic|1=--fontsize}} parameter to the {{ic|1=netbeans_default_options}} property.[http://wiki.netbeans.org/FaqFontSize]<br />
<br />
The editor fontsize can be controlled from Tools → Option → Fonts & Colors.<br />
<br />
The output window fontsize can be controlled from Tools → Options → Miscelaneous → Output<br />
<br />
=== Gimp 2.8 ===<br />
<br />
Use a high DPI theme, or adjust {{ic|1=gtkrc}} of an existing theme. (Change all occurrences of the size {{ic|1=button}} to {{ic|1=dialog}}, for example {{ic|1=GimpToolPalette::tool-icon-size}}.)<br />
<br />
There is also the [https://github.com/jedireza/gimp-hidpi gimp-hidpi].<br />
<br />
=== Steam ===<br />
<br />
==== Official HiDPI support ====<br />
* Starting on 25 of January 2018 in the beta program there is actual support for HiDPI and it should be automatically detected.<br />
* Steam -> Settings -> Interface -> check "Enlarge text and icons based on monitor size" (restart required)<br />
* If it not automatically detected use {{ic|1=GDK_SCALE=2}} to set the desired scale factor.<br />
<br />
==== Unofficial ====<br />
The [https://github.com/MoriTanosuke/HiDPI-Steam-Skin HiDPI-Steam-Skin] can be installed to increase the font size of the interface. While not perfect, it does improve usability. <br />
<br />
{{Note|The README for the HiDPI skin lists several possible locations for where to place the skin. The correct folder out of these can be identified by the presence of a file named {{ic|1=skins_readme.txt}}.}}<br />
<br />
[http://steamcommunity.com/groups/metroskin/discussions/0/517142253861033946/ MetroSkin Unofficial Patch] also helps with HiDPI on Steam with Linux.<br />
<br />
=== Java applications ===<br />
<br />
Java applications using the AWT/Swing framework can be scaled by defining the sun.java2d.uiScale variable when invoking java. For example,<br />
<br />
java -Dsun.java2d.uiScale=2 -jar some_application.jar<br />
<br />
Since Java 9 the GDK_SCALE environment variable is used to scale Swing applications accordingly.<br />
<br />
=== Mono applications ===<br />
<br />
According to [https://bugzilla.xamarin.com/show_bug.cgi?id=35870], Mono applications should be scalable like [[#GDK 3 (GTK+ 3)|GTK3]] applications.<br />
<br />
=== MATLAB ===<br />
<br />
Recent versions (R2017b) of [[Matlab]] allow to set the scale factor:<br />
>> s = settings;s.matlab.desktop.DisplayScaleFactor<br />
>> s.matlab.desktop.DisplayScaleFactor.PersonalValue = 2<br />
The settings take effect after MATLAB is restarted.<br />
<br />
=== VirtualBox ===<br />
<br />
{{Note|This ony applies to KDE with scaling enabled.}}<br />
VirtualBox also applies the system-wide scaling to the virtual monitor, which reduces the maximum resolution inside VMs by your scaling factor (see [https://www.virtualbox.org/ticket/16604]).<br />
<br />
This can be worked around by calculating the inverse of your scaling factor and manually setting this new scaling factor for the VirtualBox execution, e.g.<br />
$ QT_SCALE_FACTOR=0.5 VirtualBox --startvm vm-name<br />
<br />
=== Zoom ===<br />
<br />
Zoom can be started with a proper scaling by overriding the {{ic|1=QT_SCALE_FACTOR}} environment variable.<br />
<br />
$ QT_SCALE_FACTOR=2 zoom<br />
<br />
=== Unsupported applications ===<br />
<br />
{{AUR|run_scaled-git}} can be used to scale applications (which uses {{Pkg|xpra}} internally).<br />
<br />
Another approach is to run the application full screen and without decoration in its own VNC desktop. Then scale the viewer. With Vncdesk ({{AUR|vncdesk-git}} from the [[AUR]]) you can set up a desktop per application, then start server and client with a simple command such as {{ic|vncdesk 2}}.<br />
<br />
[[x11vnc]] has an experimental option {{ic|-appshare}}, which opens one viewer per application window. Perhaps something could be hacked up with that.<br />
<br />
== Multiple displays ==<br />
The HiDPI setting applies to the whole desktop, so non-HiDPI external displays show everything too large. However, note that setting different scaling factors for different monitors is already supported in [[Wayland]].<br />
<br />
=== Side display ===<br />
{{Out of date|1=The bug with the mouse unable to reach the whole screen should be [https://bugs.freedesktop.org/show_bug.cgi?id=39949#c80 fixed in xorg 1.20].}}<br />
<br />
One workaround is to use [[xrandr]]'s scale option. To have a non-HiDPI monitor (on DP1) right of an internal HiDPI display (eDP1), one could run:<br />
<br />
xrandr --output eDP-1 --auto --output DP-1 --auto --scale 2x2 --right-of eDP-1<br />
<br />
When extending above the internal display, you may see part of the internal display on the external monitor. In that case, specify the position manually, e.g. using [https://gist.github.com/wvengen/178642bbc8236c1bdb67 this script].<br />
<br />
You may run into problems with your mouse not being able to reach the whole screen. That is a [https://bugs.freedesktop.org/show_bug.cgi?id=39949 known bug] with an xserver-org patch (or try the panning option, but that might cause other problems).<br />
<br />
An example of the panning syntax for a 4k laptop with an external 1920x1080 monitor to the right:<br />
<br />
xrandr --output eDP-1 --auto --output HDMI-1 --auto --panning 3840x2160+3840+0 --scale 2x2 --right-of eDP-1<br />
<br />
Generically if your HiDPI monitor is AxB pixels and your regular monitor is CxD and you are scaling by [ExF], the commandline for right-of is:<br />
<br />
xrandr --output eDP-1 --auto --output HDMI-1 --auto --panning [C*E]x[D*F]+[A]+0 --scale [E]x[F] --right-of eDP-1<br />
<br />
If panning is not a solution for you it may be better to set position of monitors and fix manually the total display screen.<br />
<br />
An example of the syntax for a 2560x1440 WQHD 210 DPI laptop monitor (eDP1) using native resolution placed below a 1920x1080 FHD 96 DPI external monitor (HDMI) scaled to match global DPI settings:<br />
<br />
xrandr --output eDP-1 --auto --pos 0x1458 --output HDMI-1 --scale 1.35x1.35 --auto --pos 0x0 --fb 2592x2898<br />
<br />
The total screen size (--fb) and positioning (--pos) are to be calculated taking into account the scaling factor.<br />
<br />
In this case laptop monitor (eDP1) has no scaling and uses native mode for resolution so it will total 2560x1440, but external monitor (HDMI) is scaled and it has to be considered a larger screen so (1920*1.35)x(1080*1.35) from where the eDP1 Y position came 1080*1.35=1458 and the total screen size: since one on top of the other X=(greater between eDP1 and HDMI, so 1920*1.35=2592) and Y=(sum of the calculated heights of eDP1 and HDMI, so 1440+(1080*1.35)=2898).<br />
<br />
Generically if your hidpi monitor is AxB pixels and your regular monitor is CxD and you are scaling by [ExF] and hidpi is placed below regular one, the commandline for right-of is:<br />
<br />
xrandr --output eDP-1 --auto --pos 0x(DxF) --output HDMI-1 --auto --scale [E]x[F] --pos 0x0 --fb [greater between A and (C*E)]x[B+(D*F)]<br />
<br />
You may adjust the "sharpness" parameter on your monitor settings to adjust the blur level introduced with scaling.<br />
<br />
{{Note|1=Above solution with {{ic|--scale 2x2}} does not work on some Nvidia cards. No solution is currently available. [https://bbs.archlinux.org/viewtopic.php?pid=1670840] A potential workaround exists with configuring {{ic|1=ForceFullCompositionPipeline=On}} on the {{ic|CurrentMetaMode}} via {{ic|nvidia-settings}}. For more info see [https://askubuntu.com/a/979551/763549].}}<br />
<br />
=== Multiple external monitors ===<br />
There might be some problems in scaling more than one external monitors which have lower dpi than the built-in HiDPI display. In that case, you may want to try downscaling the HiDPI display instead, with e.g.<br />
<br />
xrandr --output eDP1 --scale 0.5x0.5 --output DP2 --right-of eDP1 --output HDMI1 --right-of DP2<br />
<br />
In addition, when you downscale the HiDPI display, the font on the HiDPI display will be slightly blurry, but it's a different kind of bluriness compared with the one introduced by upscaling the external displays. You may compare and see which kind of bluriness is less problematic for you.<br />
<br />
=== Mirroring ===<br />
<br />
If all you want is to mirror ("unify") displays, this is easy as well:<br />
<br />
With AxB your native HiDPI resolution (for ex 3200x1800) and CxD your external screen resolution (for ex 1920x1200)<br />
<br />
xrandr --output HDMI --scale [A/C]x[B/D]<br />
<br />
In this example which is QHD (3200/1920 = 1.66 and 1800/1200 = 1.5)<br />
<br />
xrandr --output HDMI --scale 1.66x1.5<br />
<br />
For UHD to 1080p (3840/1920=2 2160/1080=2)<br />
<br />
xrandr --output HDMI --scale 2x2<br />
<br />
You may adjust the "sharpness" parameter on your monitor settings to adjust the blur level introduced with scaling.<br />
<br />
== Linux console ==<br />
<br />
The default [[w:Linux console|Linux console]] font will be very small on hidpi displays, the largest font present in the {{Pkg|kbd}} package is {{ic|latarcyrheb-sun32}} and other packages like {{Pkg|terminus-font}} contain further alternatives, such as {{ic|ter-132n}}(normal) and {{ic|ter-132b}}(bold). See [[Fonts#Console fonts]] for configuration details.<br />
<br />
After changing the font, it is often garbled and unreadable when changing to other virtual consoles ({{ic|tty2-6}}). To fix this you can [[Kernel_mode_setting#Forcing_modes_and_EDID|force specific mode]] for KMS, such as {{ic|1=video=2560x1600@60}} (substitute in the native resolution of your HiDPI display), and reboot.<br />
<br />
== See also ==<br />
<br />
* [http://www.phoronix.com/scan.php?page=article&item=linux_uhd4k_gpus Ultra HD 4K Linux Graphics Card Testing] (Nov 2013)<br />
* [http://www.eizo.com/library/basics/pixel_density_4k/ Understanding pixel density]</div>Pezcurrelhttps://wiki.archlinux.org/index.php?title=Rsync&diff=493912Rsync2017-10-23T09:09:41Z<p>Pezcurrel: /* rsync daemon */ minor formatting fixes</p>
<hr />
<div>{{Lowercase title}}<br />
[[Category:Data compression and archiving]]<br />
[[Category:System recovery]]<br />
[[es:Rsync]]<br />
[[ja:Rsync]]<br />
[[zh-hans:Rsync]]<br />
{{Related articles start}}<br />
{{Related|System backup}}<br />
{{Related|Synchronization and backup programs}}<br />
{{Related articles end}}<br />
[https://rsync.samba.org/ rsync] is an open source utility that provides fast incremental file transfer.<br />
<br />
== Installation ==<br />
<br />
[[Install]] the {{Pkg|rsync}} package.<br />
<br />
''rsync'' must be installed on both the source and the destination machine.<br />
<br />
=== Front-ends ===<br />
<br />
* {{App|Grsync|GTK+ front-end.|http://www.opbyte.it/grsync/|{{Pkg|grsync}}}}<br />
* {{App|gutback|rsync wrapper written in Shell.|https://github.com/gutenye/gutbackup|{{Aur|gutbackup}}}}<br />
* {{App|JotaSync|Java Swing GUI for rsync with integrated scheduler.|https://trixon.se/projects/jotasync/|{{Aur|jotasync}}}}<br />
* {{App|luckyBackup|Qt front-end written in C++.|http://luckybackup.sourceforge.net/index.html|{{Aur|luckybackup}}}}<br />
<br />
== As a cp alternative ==<br />
<br />
rsync can be used as an advanced alternative for the {{ic|cp}} command, especially for copying larger files:<br />
<br />
$ rsync -P source destination<br />
<br />
The {{ic|-P}} option is the same as {{Ic|--partial --progress}}, which keeps partially transferred files and shows a progress bar during transfer.<br />
<br />
You may want to use the {{ic|-r --recursive}} option to recurse into directories.<br />
<br />
Files can be copied locally as with cp, but the motivating purpose of rsync is to copy files remotely, i.e. between two different hosts. Remote locations can be specified with a host-colon syntax:<br />
<br />
$ rsync source host:destination<br />
<br />
or<br />
<br />
$ rsync host:source destination<br />
<br />
Network file transfers use the SSH protocol by default.<br />
<br />
{{Accuracy|By default, rsync does not compare contents of files. Rsync uses a "quick check" that (by default) checks if each file’s size and time of last modification match between the sender and receiver.}}<br />
<br />
Whether transferring files locally or remotely, rsync first creates an index of block checksums of each source file. This index is used to find any identical blocks of data which might exist in the destination. Such blocks are used in-place, rather than being copied from the source. This can greatly accelerate the synchronization of large files with small changes. For more information, see [https://rsync.samba.org/documentation.html official documentation], [https://rsync.samba.org/how-rsync-works.html how rsync works].<br />
<br />
=== Trailing slash caveat ===<br />
<br />
Arch by default uses GNU cp (part of [https://www.archlinux.org/packages/?name=coreutils GNU coreutils]). However, rsync follows the convention of BSD cp, which gives special treatment to source directories with a trailing slash "/". Although<br />
<br />
$ rsync -r source destination<br />
<br />
creates a directory "destination/source" with the contents of "source", the command<br />
<br />
$ rsync -r source/ destination<br />
<br />
copies all of the files in "source/" directly into "destination", with no intervening subdirectory - just as if you had invoked it as<br />
<br />
$ rsync -r source/. destination<br />
<br />
This behavior is different from that of GNU cp, which treats "source" and "source/" identically (but not "source/."). Also, some shells automatically append the trailing slash when tab-completing directory names. Because of these factors, there can be a tendency among new or occasional rsync users to forget about rsync's different behavior, and inadvertently create a mess or even overwrite important files by leaving the trailing slash on the command line.<br />
<br />
Thus it can be prudent to use a wrapper script to automatically remove trailing slashes before invoking rsync:<br />
<br />
#!/bin/zsh<br />
new_args=();<br />
for i in "$@"; do<br />
case $i in /) i=/;; */) i=${i%/};; esac<br />
new_args+=$i;<br />
done<br />
exec rsync "${(@)new_args}"<br />
<br />
This script can be put somewhere in the path, and aliased to rsync in the shell init file.<br />
<br />
== As a backup utility ==<br />
<br />
The rsync protocol can easily be used for backups, only transferring files that have changed since the last backup. This section describes a very simple scheduled backup script using rsync, typically used for copying to removable media.<br />
<br />
=== Automated backup ===<br />
<br />
For the sake of this example, the script is created in the {{ic|/etc/cron.daily}} directory, and will be run on a daily basis if a cron [[daemon]] is installed and properly configured. Configuring and using [[cron]] is outside the scope of this article.<br />
<br />
First, create a script containing the appropriate command options:<br />
<br />
{{hc|/etc/cron.daily/backup|<br />
#!/bin/bash<br />
rsync -a --delete --quiet /folder/to/backup /location/of/backup}}<br />
<br />
; {{ic|-a}} : indicates that files should be archived, meaning that most of their characteristics are preserved (but '''not''' ACLs, hard links or extended attributes such as capabilities)<br />
; {{ic|--delete}} : means files deleted on the source are to be deleted on the backup as well<br />
<br />
Here, {{ic|/folder/to/backup}} should be changed to what needs to be backed-up ({{ic|/home}}, for example) and {{ic|/location/to/backup}} is where the backup should be saved ({{ic|/media/disk}}, for instance).<br />
<br />
Finally, the script must be executable:<br />
<br />
# chmod +x /etc/cron.daily/backup<br />
<br />
=== Automated backup with SSH ===<br />
<br />
If backing-up to a remote host using [[SSH]], use this script instead:<br />
<br />
{{hc|/etc/cron.daily/backup|<br />
#!/bin/bash<br />
rsync -a --delete --quiet -e ssh /folder/to/backup remoteuser@remotehost:/location/of/backup<br />
}}<br />
<br />
; {{ic|-e ssh}} : tells rsync to use SSH<br />
; {{ic|remoteuser}} : is the user on the host {{ic|remotehost}}<br />
; {{ic|-a}} : groups all these options {{ic|-rlptgoD}} (recursive, links, perms, times, group, owner, devices)<br />
<br />
=== Automated backup with NetworkManager ===<br />
<br />
This script starts a backup when network connection is established.<br />
<br />
First, create a script containing the appropriate command options:<br />
<br />
{{hc|/etc/NetworkManager/dispatcher.d/backup|2=<br />
#!/bin/bash<br />
<br />
if [ x"$2" = "xup" ] ; then<br />
rsync --force --ignore-errors -a --delete --bwlimit=2000 --files-from=files.rsync /folder/to/backup /location/to/backup<br />
fi<br />
}}<br />
<br />
; {{ic|-a}} : group all this options {{ic|-rlptgoD}} recursive, links, perms, times, group, owner, devices<br />
; {{ic|--files-from}} : read the relative path of ''/folder/to/backup'' from this file<br />
; {{ic|--bwlimit}} : limit I/O bandwidth; KBytes per second<br />
<br />
Also, the script must have write permission for owner (root, of course) only (see [[NetworkManager#Network services with NetworkManager dispatcher]] for details).<br />
<br />
=== Automated backup with systemd and inotify ===<br />
<br />
{{Note|<br />
* Due to the limitations of inotify and systemd (see [http://www.quora.com/Linux-Kernel/Inotify-monitoring-of-directories-is-not-recursive-Is-there-any-specific-reason-for-this-design-in-Linux-kernel this question and answer]), recursive filesystem monitoring is not possible. Although you can watch a directory and its contents, it will not recurse into subdirectories and watch the contents of them; you must explicitly specify every directory to watch, even if that directory is a child of an already watched directory.<br />
* This setup is based on a [[systemd/User]] instance.<br />
}}<br />
<br />
Instead of running time interval backups with time based schedules, such as those implemented in [[cron]], it is possible to run a backup every time one of the files you are backing up changes. {{ic|systemd.path}} units use {{ic|inotify}} to monitor the filesystem, and can be used in conjunction with {{ic|systemd.service}} files to start any process (in this case your [[rsync]] backup) based on a filesystem event.<br />
<br />
First, create the {{ic|systemd.path}} file that will monitor the files you are backing up:<br />
<br />
{{hc|~/.config/systemd/user/backup.path|<nowiki><br />
[Unit]<br />
Description=Checks if paths that are currently being backed up have changed<br />
<br />
[Path]<br />
PathChanged=%h/documents<br />
PathChanged=%h/music<br />
<br />
[Install]<br />
WantedBy=default.target<br />
</nowiki>}}<br />
<br />
Then create a {{ic|systemd.service}} file that will be activated when it detects a change. By default a service file of the same name as the path unit (in this case {{ic|backup.path}}) will be activated, except with the {{ic|.service}} extension instead of {{ic|.path}} (in this case {{ic|backup.service}}).<br />
<br />
{{Note|If you need to run multiple rsync commands, use {{ic|1=Type=oneshot}}. This allows you to specify multiple {{ic|1=ExecStart=}} parameters, one for each [[rsync]] command, that will be executed. Alternatively, you can simply write a script to perform all of your backups, just like [[cron]] scripts.}}<br />
<br />
{{hc|~/.config/systemd/user/backup.service|<nowiki><br />
[Unit]<br />
Description=Backs up files<br />
<br />
[Service]<br />
ExecStart=/usr/bin/rsync %h/./documents %h/./music -CERrltm --delete ubuntu:<br />
</nowiki>}}<br />
<br />
Now all you have to do is [[start]]/enable {{ic|backup.path}} like a normal systemd service and it will start monitoring file changes and automatically starting {{ic|backup.service}}.<br />
<br />
=== Differential backup on a week ===<br />
<br />
This is a useful option of rsync, creating a full backup and a differential backup for each day of a week.<br />
<br />
First, create a script containing the appropriate command options:<br />
<br />
{{hc|/etc/cron.daily/backup|2=<br />
#!/bin/bash<br />
<br />
DAY=$(date +%A)<br />
<br />
if [ -e /location/to/backup/incr/$DAY ] ; then<br />
rm -fr /location/to/backup/incr/$DAY<br />
fi<br />
<br />
rsync -a --delete --quiet --inplace --backup --backup-dir=/location/to/backup/incr/$DAY /folder/to/backup/ /location/to/backup/full/<br />
}}<br />
<br />
; {{ic|--inplace}} : implies {{ic|--partial}} update destination files in-place<br />
<br />
=== Snapshot backup ===<br />
<br />
The same idea can be used to maintain a tree of snapshots of your files. In other words, a directory with date-ordered copies of the files. The copies are made using hardlinks, which means that only files that did change will occupy space. Generally speaking, this is the idea behind Apple's TimeMachine.<br />
<br />
This basic script is easy to implement and creates quick incremental snapshots using the {{ic|--link-dest}} option to hardlink unchanged files: <br />
<br />
{{hc|/usr/local/bin/snapbackup.sh|<nowiki><br />
#!/bin/bash<br />
<br />
# Basic snapshot-style rsync backup script <br />
<br />
# Config<br />
OPT="-aPh"<br />
LINK="--link-dest=/snapshots/username/last/" <br />
SRC="/home/username/files/"<br />
SNAP="/snapshots/username/"<br />
LAST="/snapshots/username/last"<br />
date=`date "+%Y-%b-%d:_%T"`<br />
<br />
# Run rsync to create snapshot<br />
rsync $OPT $LINK $SRC ${SNAP}$date<br />
<br />
# Remove symlink to previous snapshot<br />
rm -f $LAST<br />
<br />
# Create new symlink to latest snapshot for the next backup to hardlink<br />
ln -s ${SNAP}$date $LAST<br />
</nowiki>}}<br />
<br />
There must be a symlink to a full backup already in existence as a target for {{ic|--link-dest}}. If the most recent snapshot is deleted, the symlink will need to be recreated to point to the most recent snapshot. If {{ic|--link-dest}} does not find a working symlink, rsync will proceed to copy all source files instead of only the changes. <br />
<br />
A more sophisticated version checks to see if a certain number of changes have been made before making the backup and utilizes {{ic|cp -al}} to hardlink unchanged files:<br />
<br />
{{hc|/usr/local/bin/rsnapshot.sh|<nowiki><br />
#!/bin/bash<br />
<br />
## my own rsync-based snapshot-style backup procedure<br />
## (cc) marcio rps AT gmail.com<br />
<br />
# config vars<br />
<br />
SRC="/home/username/files/" #dont forget trailing slash!<br />
SNAP="/snapshots/username"<br />
OPTS="-rltgoi --delay-updates --delete --chmod=a-w"<br />
MINCHANGES=20<br />
<br />
# run this process with real low priority<br />
<br />
ionice -c 3 -p $$<br />
renice +12 -p $$<br />
<br />
# sync<br />
<br />
rsync $OPTS $SRC $SNAP/latest >> $SNAP/rsync.log<br />
<br />
# check if enough has changed and if so<br />
# make a hardlinked copy named as the date<br />
<br />
COUNT=$( wc -l $SNAP/rsync.log|cut -d" " -f1 )<br />
if [ $COUNT -gt $MINCHANGES ] ; then<br />
DATETAG=$(date +%Y-%m-%d)<br />
if [ ! -e $SNAP/$DATETAG ] ; then<br />
cp -al $SNAP/latest $SNAP/$DATETAG<br />
chmod u+w $SNAP/$DATETAG<br />
mv $SNAP/rsync.log $SNAP/$DATETAG<br />
chmod u-w $SNAP/$DATETAG<br />
fi<br />
fi<br />
</nowiki>}}<br />
<br />
To make things really, really simple this script can be run from a [[systemd/Timers]] unit.<br />
<br />
=== Full system backup ===<br />
<br />
This section is about using ''rsync'' to transfer a copy of the entire {{ic|/}} tree, excluding a few selected folders. This approach is considered to be better than [[disk cloning]] with {{ic|dd}} since it allows for a different size, partition table and filesystem to be used, and better than copying with {{ic|cp -a}} as well, because it allows greater control over file permissions, attributes, [[Access Control Lists]] and [[extended attributes]].<br />
<br />
''rsync'' will work even while the system is running, but files changed during the transfer may or may not be transferred, which can cause undefined behavior of some programs using the transferred files.<br />
<br />
This approach works well for migrating an existing installation to a new hard drive or [[SSD]].<br />
<br />
Run the following command as root to make sure that rsync can access all system files and preserve the ownership:<br />
<br />
# rsync -aAXv --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} / ''/path/to/backup/folder''<br />
<br />
By using the {{ic|-aAX}} set of options, the files are transferred in archive mode which ensures that symbolic links, devices, permissions, ownerships, modification times, [[ACL]]s, and extended attributes are preserved, assuming that the target [[file system]] supports the feature.<br />
<br />
The {{ic|--exclude}} option causes files that match the given patterns to be excluded. The contents of {{ic|/dev}}, {{ic|/proc}}, {{ic|/sys}}, {{ic|/tmp}}, and {{ic|/run}} are excluded in the above command, because they are populated at boot, although the folders themselves are ''not'' created. {{ic|/lost+found}} is filesystem-specific. The command above depends on brace expansion available in both the [https://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html bash] and [http://zsh.sourceforge.net/Doc/Release/Expansion.html#Brace-Expansion zsh] shells. When using a different [[shell]], {{ic|--exclude}} patterns should be repeated manually. Quoting the exclude patterns will avoid expansion by the [[shell]], which is necessary, for example, when backing up over [[SSH]]. Ending the excluded paths with {{ic|*}} ensures that the directories themselves are created if they do not already exist.<br />
<br />
{{Note|<br />
* If you plan on backing up your system somewhere other than {{ic|/mnt}} or {{ic|/media}}, do not forget to add it to the list of exclude patterns to avoid an infinite loop.<br />
* If there are any bind mounts in the system, they should be excluded as well so that the bind mounted contents is copied only once.<br />
* If you use a [[swap file]], make sure to exclude it as well.<br />
* Consider if you want to backup the {{ic|/home/}} folder. If it contains your data it might be considerably larger than the system. Otherwise consider excluding unimportant subdirectories such as {{ic|/home/*/.thumbnails/*}}, {{ic|/home/*/.cache/mozilla/*}}, {{ic|/home/*/.cache/chromium/*}}, and {{ic|/home/*/.local/share/Trash/*}}, depending on software installed on the system. If [[GVFS]] is installed, {{ic|/home/*/.gvfs}} must be excluded to prevent rsync errors.<br />
}}<br />
<br />
You may want to include additional [[rsync]] options, such as the following. See {{man|1|rsync}} for the full list.<br />
<br />
* If you use many hard links, consider adding the {{ic|-H}} option, which is turned off by default due to its memory expense; however, it should be no problem on most modern machines. Many hard links reside under the {{ic|/usr/}} directory.<br />
* You may want to add rsync's {{ic|--delete}} option if you are running this multiple times to the same backup folder. In this case make sure that the source path does not end with {{ic|/*}}, or this option will only have effect on the files inside the subdirectories of the source directory, but it will have no effect on the files residing directly inside the source directory.<br />
* If you use any sparse files, such as virtual disks, [[Docker]] images and similar, you should add the {{ic|-S}} option.<br />
* The {{ic|--numeric-ids}} option will disable mapping of user and group names; instead, numeric group and user IDs will be transfered. This is useful when backing up over [[SSH]] or when using a live system to backup different system disk.<br />
* Choosing {{ic|1=--info=progress2}} option instead of {{ic|-v}} will show the overall progress info and transfer speed instead of the list of files being transferred.<br />
<br />
=== Restore a backup ===<br />
<br />
If you wish to restore a backup, use the same rsync command that was executed but with the source and destination reversed.<br />
<br />
== File system cloning ==<br />
<br />
rsync provides a way to do a copy of all data in a file system while preserving as much information as possible, including the file system metadata. It is a procedure of data cloning on a file system level where source and destination file systems don't need to be of the same type. It can be used for backing up, file system migration or data recovery.<br />
<br />
rsync's ''archive'' mode comes close to being fit for the job, but it doesn't back up the special file system metadata such as access control lists, extended attributes or sparse file properties. For successful cloning at the file system level, some additional options need to be provided:<br />
<br />
rsync -qaHAXS SOURCE_DIR DESTINATION_DIR<br />
<br />
And their meaning is (from the manpage):<br />
<br />
-H, --hard-links preserve hard links<br />
-A, --acls preserve ACLs (implies -p)<br />
-X, --xattrs preserve extended attributes<br />
-S, --sparse handle sparse files efficiently<br />
<br />
Produced copy can be simply reread and checked (for example after a data recovery attempt) at the file system level with {{ic|diff}}'s recursive option:<br />
<br />
diff -r SOURCE_DIR DESTINATION_DIR<br />
<br />
It is possible to do a successful file system migration by using rsync as described in this article and updating the [[fstab]] and [[bootloader]] as described in [[Migrate installation to new hardware]]. This essentially provides a way to convert any root file system to another one.<br />
<br />
== rsync daemon ==<br />
<br />
''rsync'' can be run as daemon on a server listening on port {{ic|873}}.<br />
<br />
Edit the template {{ic|/etc/rsyncd.conf}}, configure a share and [[start]] the {{ic|rsyncd.service}}.<br />
<br />
Usage from client, e.g. list server content:<br />
<br />
$ rsync rsync://''server/share''<br />
<br />
transfer file from client to server: <br />
<br />
$ rsync ''local-file'' rsync://''server/share/''<br />
<br />
Consider iptables to open port {{ic|873}} and user authentication.<br />
{{Note|All transferred data including user authentication are not encrypted.<br />
}}<br />
{{Note|As of rsync-3.1.2-5 the systemd unit file {{ic|/usr/lib/systemd/system/rsyncd.service}} included in the package has {{ic|1=ProtectHome=on}} under the {{ic|[Service]}} section as a security feature, so rsyncd will '''not''' serve home directories ({{ic|/root}} included) to clients. If you need it to serve home directories you can [[Systemd#Editing_provided_units|override]] {{ic|1=ProtectHome=On}} by issuing (as root)<br />
<br />
$ systemctl edit rsyncd.service<br />
<br />
and then adding<br />
<br />
[Service]<br />
ProtectHome<nowiki>=</nowiki>off<br />
<br />
Then save the newly created file and restart rsyncd service:<br />
<br />
$ systemctl restart rsyncd<br />
}}<br />
<br />
== See also ==<br />
<br />
* More usage examples can be searched in the [https://bbs.archlinux.org/viewforum.php?id=27 Community Contributions] and [https://bbs.archlinux.org/viewforum.php?id=33 General Programming] forums<br />
* [http://www.pointsoftware.ch/en/howto-local-and-remote-snapshot-backup-using-rsync-with-hard-links/ Howto – local and remote snapshot backup using rsync with hard links] Includes file deduplication with hard-links, MD5 integrity signature, 'chattr' protection, filter rules, disk quota, retention policy with exponential distribution (backups rotation while saving more recent backups than older)</div>Pezcurrelhttps://wiki.archlinux.org/index.php?title=Rsync&diff=493911Rsync2017-10-23T08:50:29Z<p>Pezcurrel: /* rsync daemon */ minor formatting fixes</p>
<hr />
<div>{{Lowercase title}}<br />
[[Category:Data compression and archiving]]<br />
[[Category:System recovery]]<br />
[[es:Rsync]]<br />
[[ja:Rsync]]<br />
[[zh-hans:Rsync]]<br />
{{Related articles start}}<br />
{{Related|System backup}}<br />
{{Related|Synchronization and backup programs}}<br />
{{Related articles end}}<br />
[https://rsync.samba.org/ rsync] is an open source utility that provides fast incremental file transfer.<br />
<br />
== Installation ==<br />
<br />
[[Install]] the {{Pkg|rsync}} package.<br />
<br />
''rsync'' must be installed on both the source and the destination machine.<br />
<br />
=== Front-ends ===<br />
<br />
* {{App|Grsync|GTK+ front-end.|http://www.opbyte.it/grsync/|{{Pkg|grsync}}}}<br />
* {{App|gutback|rsync wrapper written in Shell.|https://github.com/gutenye/gutbackup|{{Aur|gutbackup}}}}<br />
* {{App|JotaSync|Java Swing GUI for rsync with integrated scheduler.|https://trixon.se/projects/jotasync/|{{Aur|jotasync}}}}<br />
* {{App|luckyBackup|Qt front-end written in C++.|http://luckybackup.sourceforge.net/index.html|{{Aur|luckybackup}}}}<br />
<br />
== As a cp alternative ==<br />
<br />
rsync can be used as an advanced alternative for the {{ic|cp}} command, especially for copying larger files:<br />
<br />
$ rsync -P source destination<br />
<br />
The {{ic|-P}} option is the same as {{Ic|--partial --progress}}, which keeps partially transferred files and shows a progress bar during transfer.<br />
<br />
You may want to use the {{ic|-r --recursive}} option to recurse into directories.<br />
<br />
Files can be copied locally as with cp, but the motivating purpose of rsync is to copy files remotely, i.e. between two different hosts. Remote locations can be specified with a host-colon syntax:<br />
<br />
$ rsync source host:destination<br />
<br />
or<br />
<br />
$ rsync host:source destination<br />
<br />
Network file transfers use the SSH protocol by default.<br />
<br />
{{Accuracy|By default, rsync does not compare contents of files. Rsync uses a "quick check" that (by default) checks if each file’s size and time of last modification match between the sender and receiver.}}<br />
<br />
Whether transferring files locally or remotely, rsync first creates an index of block checksums of each source file. This index is used to find any identical blocks of data which might exist in the destination. Such blocks are used in-place, rather than being copied from the source. This can greatly accelerate the synchronization of large files with small changes. For more information, see [https://rsync.samba.org/documentation.html official documentation], [https://rsync.samba.org/how-rsync-works.html how rsync works].<br />
<br />
=== Trailing slash caveat ===<br />
<br />
Arch by default uses GNU cp (part of [https://www.archlinux.org/packages/?name=coreutils GNU coreutils]). However, rsync follows the convention of BSD cp, which gives special treatment to source directories with a trailing slash "/". Although<br />
<br />
$ rsync -r source destination<br />
<br />
creates a directory "destination/source" with the contents of "source", the command<br />
<br />
$ rsync -r source/ destination<br />
<br />
copies all of the files in "source/" directly into "destination", with no intervening subdirectory - just as if you had invoked it as<br />
<br />
$ rsync -r source/. destination<br />
<br />
This behavior is different from that of GNU cp, which treats "source" and "source/" identically (but not "source/."). Also, some shells automatically append the trailing slash when tab-completing directory names. Because of these factors, there can be a tendency among new or occasional rsync users to forget about rsync's different behavior, and inadvertently create a mess or even overwrite important files by leaving the trailing slash on the command line.<br />
<br />
Thus it can be prudent to use a wrapper script to automatically remove trailing slashes before invoking rsync:<br />
<br />
#!/bin/zsh<br />
new_args=();<br />
for i in "$@"; do<br />
case $i in /) i=/;; */) i=${i%/};; esac<br />
new_args+=$i;<br />
done<br />
exec rsync "${(@)new_args}"<br />
<br />
This script can be put somewhere in the path, and aliased to rsync in the shell init file.<br />
<br />
== As a backup utility ==<br />
<br />
The rsync protocol can easily be used for backups, only transferring files that have changed since the last backup. This section describes a very simple scheduled backup script using rsync, typically used for copying to removable media.<br />
<br />
=== Automated backup ===<br />
<br />
For the sake of this example, the script is created in the {{ic|/etc/cron.daily}} directory, and will be run on a daily basis if a cron [[daemon]] is installed and properly configured. Configuring and using [[cron]] is outside the scope of this article.<br />
<br />
First, create a script containing the appropriate command options:<br />
<br />
{{hc|/etc/cron.daily/backup|<br />
#!/bin/bash<br />
rsync -a --delete --quiet /folder/to/backup /location/of/backup}}<br />
<br />
; {{ic|-a}} : indicates that files should be archived, meaning that most of their characteristics are preserved (but '''not''' ACLs, hard links or extended attributes such as capabilities)<br />
; {{ic|--delete}} : means files deleted on the source are to be deleted on the backup as well<br />
<br />
Here, {{ic|/folder/to/backup}} should be changed to what needs to be backed-up ({{ic|/home}}, for example) and {{ic|/location/to/backup}} is where the backup should be saved ({{ic|/media/disk}}, for instance).<br />
<br />
Finally, the script must be executable:<br />
<br />
# chmod +x /etc/cron.daily/backup<br />
<br />
=== Automated backup with SSH ===<br />
<br />
If backing-up to a remote host using [[SSH]], use this script instead:<br />
<br />
{{hc|/etc/cron.daily/backup|<br />
#!/bin/bash<br />
rsync -a --delete --quiet -e ssh /folder/to/backup remoteuser@remotehost:/location/of/backup<br />
}}<br />
<br />
; {{ic|-e ssh}} : tells rsync to use SSH<br />
; {{ic|remoteuser}} : is the user on the host {{ic|remotehost}}<br />
; {{ic|-a}} : groups all these options {{ic|-rlptgoD}} (recursive, links, perms, times, group, owner, devices)<br />
<br />
=== Automated backup with NetworkManager ===<br />
<br />
This script starts a backup when network connection is established.<br />
<br />
First, create a script containing the appropriate command options:<br />
<br />
{{hc|/etc/NetworkManager/dispatcher.d/backup|2=<br />
#!/bin/bash<br />
<br />
if [ x"$2" = "xup" ] ; then<br />
rsync --force --ignore-errors -a --delete --bwlimit=2000 --files-from=files.rsync /folder/to/backup /location/to/backup<br />
fi<br />
}}<br />
<br />
; {{ic|-a}} : group all this options {{ic|-rlptgoD}} recursive, links, perms, times, group, owner, devices<br />
; {{ic|--files-from}} : read the relative path of ''/folder/to/backup'' from this file<br />
; {{ic|--bwlimit}} : limit I/O bandwidth; KBytes per second<br />
<br />
Also, the script must have write permission for owner (root, of course) only (see [[NetworkManager#Network services with NetworkManager dispatcher]] for details).<br />
<br />
=== Automated backup with systemd and inotify ===<br />
<br />
{{Note|<br />
* Due to the limitations of inotify and systemd (see [http://www.quora.com/Linux-Kernel/Inotify-monitoring-of-directories-is-not-recursive-Is-there-any-specific-reason-for-this-design-in-Linux-kernel this question and answer]), recursive filesystem monitoring is not possible. Although you can watch a directory and its contents, it will not recurse into subdirectories and watch the contents of them; you must explicitly specify every directory to watch, even if that directory is a child of an already watched directory.<br />
* This setup is based on a [[systemd/User]] instance.<br />
}}<br />
<br />
Instead of running time interval backups with time based schedules, such as those implemented in [[cron]], it is possible to run a backup every time one of the files you are backing up changes. {{ic|systemd.path}} units use {{ic|inotify}} to monitor the filesystem, and can be used in conjunction with {{ic|systemd.service}} files to start any process (in this case your [[rsync]] backup) based on a filesystem event.<br />
<br />
First, create the {{ic|systemd.path}} file that will monitor the files you are backing up:<br />
<br />
{{hc|~/.config/systemd/user/backup.path|<nowiki><br />
[Unit]<br />
Description=Checks if paths that are currently being backed up have changed<br />
<br />
[Path]<br />
PathChanged=%h/documents<br />
PathChanged=%h/music<br />
<br />
[Install]<br />
WantedBy=default.target<br />
</nowiki>}}<br />
<br />
Then create a {{ic|systemd.service}} file that will be activated when it detects a change. By default a service file of the same name as the path unit (in this case {{ic|backup.path}}) will be activated, except with the {{ic|.service}} extension instead of {{ic|.path}} (in this case {{ic|backup.service}}).<br />
<br />
{{Note|If you need to run multiple rsync commands, use {{ic|1=Type=oneshot}}. This allows you to specify multiple {{ic|1=ExecStart=}} parameters, one for each [[rsync]] command, that will be executed. Alternatively, you can simply write a script to perform all of your backups, just like [[cron]] scripts.}}<br />
<br />
{{hc|~/.config/systemd/user/backup.service|<nowiki><br />
[Unit]<br />
Description=Backs up files<br />
<br />
[Service]<br />
ExecStart=/usr/bin/rsync %h/./documents %h/./music -CERrltm --delete ubuntu:<br />
</nowiki>}}<br />
<br />
Now all you have to do is [[start]]/enable {{ic|backup.path}} like a normal systemd service and it will start monitoring file changes and automatically starting {{ic|backup.service}}.<br />
<br />
=== Differential backup on a week ===<br />
<br />
This is a useful option of rsync, creating a full backup and a differential backup for each day of a week.<br />
<br />
First, create a script containing the appropriate command options:<br />
<br />
{{hc|/etc/cron.daily/backup|2=<br />
#!/bin/bash<br />
<br />
DAY=$(date +%A)<br />
<br />
if [ -e /location/to/backup/incr/$DAY ] ; then<br />
rm -fr /location/to/backup/incr/$DAY<br />
fi<br />
<br />
rsync -a --delete --quiet --inplace --backup --backup-dir=/location/to/backup/incr/$DAY /folder/to/backup/ /location/to/backup/full/<br />
}}<br />
<br />
; {{ic|--inplace}} : implies {{ic|--partial}} update destination files in-place<br />
<br />
=== Snapshot backup ===<br />
<br />
The same idea can be used to maintain a tree of snapshots of your files. In other words, a directory with date-ordered copies of the files. The copies are made using hardlinks, which means that only files that did change will occupy space. Generally speaking, this is the idea behind Apple's TimeMachine.<br />
<br />
This basic script is easy to implement and creates quick incremental snapshots using the {{ic|--link-dest}} option to hardlink unchanged files: <br />
<br />
{{hc|/usr/local/bin/snapbackup.sh|<nowiki><br />
#!/bin/bash<br />
<br />
# Basic snapshot-style rsync backup script <br />
<br />
# Config<br />
OPT="-aPh"<br />
LINK="--link-dest=/snapshots/username/last/" <br />
SRC="/home/username/files/"<br />
SNAP="/snapshots/username/"<br />
LAST="/snapshots/username/last"<br />
date=`date "+%Y-%b-%d:_%T"`<br />
<br />
# Run rsync to create snapshot<br />
rsync $OPT $LINK $SRC ${SNAP}$date<br />
<br />
# Remove symlink to previous snapshot<br />
rm -f $LAST<br />
<br />
# Create new symlink to latest snapshot for the next backup to hardlink<br />
ln -s ${SNAP}$date $LAST<br />
</nowiki>}}<br />
<br />
There must be a symlink to a full backup already in existence as a target for {{ic|--link-dest}}. If the most recent snapshot is deleted, the symlink will need to be recreated to point to the most recent snapshot. If {{ic|--link-dest}} does not find a working symlink, rsync will proceed to copy all source files instead of only the changes. <br />
<br />
A more sophisticated version checks to see if a certain number of changes have been made before making the backup and utilizes {{ic|cp -al}} to hardlink unchanged files:<br />
<br />
{{hc|/usr/local/bin/rsnapshot.sh|<nowiki><br />
#!/bin/bash<br />
<br />
## my own rsync-based snapshot-style backup procedure<br />
## (cc) marcio rps AT gmail.com<br />
<br />
# config vars<br />
<br />
SRC="/home/username/files/" #dont forget trailing slash!<br />
SNAP="/snapshots/username"<br />
OPTS="-rltgoi --delay-updates --delete --chmod=a-w"<br />
MINCHANGES=20<br />
<br />
# run this process with real low priority<br />
<br />
ionice -c 3 -p $$<br />
renice +12 -p $$<br />
<br />
# sync<br />
<br />
rsync $OPTS $SRC $SNAP/latest >> $SNAP/rsync.log<br />
<br />
# check if enough has changed and if so<br />
# make a hardlinked copy named as the date<br />
<br />
COUNT=$( wc -l $SNAP/rsync.log|cut -d" " -f1 )<br />
if [ $COUNT -gt $MINCHANGES ] ; then<br />
DATETAG=$(date +%Y-%m-%d)<br />
if [ ! -e $SNAP/$DATETAG ] ; then<br />
cp -al $SNAP/latest $SNAP/$DATETAG<br />
chmod u+w $SNAP/$DATETAG<br />
mv $SNAP/rsync.log $SNAP/$DATETAG<br />
chmod u-w $SNAP/$DATETAG<br />
fi<br />
fi<br />
</nowiki>}}<br />
<br />
To make things really, really simple this script can be run from a [[systemd/Timers]] unit.<br />
<br />
=== Full system backup ===<br />
<br />
This section is about using ''rsync'' to transfer a copy of the entire {{ic|/}} tree, excluding a few selected folders. This approach is considered to be better than [[disk cloning]] with {{ic|dd}} since it allows for a different size, partition table and filesystem to be used, and better than copying with {{ic|cp -a}} as well, because it allows greater control over file permissions, attributes, [[Access Control Lists]] and [[extended attributes]].<br />
<br />
''rsync'' will work even while the system is running, but files changed during the transfer may or may not be transferred, which can cause undefined behavior of some programs using the transferred files.<br />
<br />
This approach works well for migrating an existing installation to a new hard drive or [[SSD]].<br />
<br />
Run the following command as root to make sure that rsync can access all system files and preserve the ownership:<br />
<br />
# rsync -aAXv --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} / ''/path/to/backup/folder''<br />
<br />
By using the {{ic|-aAX}} set of options, the files are transferred in archive mode which ensures that symbolic links, devices, permissions, ownerships, modification times, [[ACL]]s, and extended attributes are preserved, assuming that the target [[file system]] supports the feature.<br />
<br />
The {{ic|--exclude}} option causes files that match the given patterns to be excluded. The contents of {{ic|/dev}}, {{ic|/proc}}, {{ic|/sys}}, {{ic|/tmp}}, and {{ic|/run}} are excluded in the above command, because they are populated at boot, although the folders themselves are ''not'' created. {{ic|/lost+found}} is filesystem-specific. The command above depends on brace expansion available in both the [https://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html bash] and [http://zsh.sourceforge.net/Doc/Release/Expansion.html#Brace-Expansion zsh] shells. When using a different [[shell]], {{ic|--exclude}} patterns should be repeated manually. Quoting the exclude patterns will avoid expansion by the [[shell]], which is necessary, for example, when backing up over [[SSH]]. Ending the excluded paths with {{ic|*}} ensures that the directories themselves are created if they do not already exist.<br />
<br />
{{Note|<br />
* If you plan on backing up your system somewhere other than {{ic|/mnt}} or {{ic|/media}}, do not forget to add it to the list of exclude patterns to avoid an infinite loop.<br />
* If there are any bind mounts in the system, they should be excluded as well so that the bind mounted contents is copied only once.<br />
* If you use a [[swap file]], make sure to exclude it as well.<br />
* Consider if you want to backup the {{ic|/home/}} folder. If it contains your data it might be considerably larger than the system. Otherwise consider excluding unimportant subdirectories such as {{ic|/home/*/.thumbnails/*}}, {{ic|/home/*/.cache/mozilla/*}}, {{ic|/home/*/.cache/chromium/*}}, and {{ic|/home/*/.local/share/Trash/*}}, depending on software installed on the system. If [[GVFS]] is installed, {{ic|/home/*/.gvfs}} must be excluded to prevent rsync errors.<br />
}}<br />
<br />
You may want to include additional [[rsync]] options, such as the following. See {{man|1|rsync}} for the full list.<br />
<br />
* If you use many hard links, consider adding the {{ic|-H}} option, which is turned off by default due to its memory expense; however, it should be no problem on most modern machines. Many hard links reside under the {{ic|/usr/}} directory.<br />
* You may want to add rsync's {{ic|--delete}} option if you are running this multiple times to the same backup folder. In this case make sure that the source path does not end with {{ic|/*}}, or this option will only have effect on the files inside the subdirectories of the source directory, but it will have no effect on the files residing directly inside the source directory.<br />
* If you use any sparse files, such as virtual disks, [[Docker]] images and similar, you should add the {{ic|-S}} option.<br />
* The {{ic|--numeric-ids}} option will disable mapping of user and group names; instead, numeric group and user IDs will be transfered. This is useful when backing up over [[SSH]] or when using a live system to backup different system disk.<br />
* Choosing {{ic|1=--info=progress2}} option instead of {{ic|-v}} will show the overall progress info and transfer speed instead of the list of files being transferred.<br />
<br />
=== Restore a backup ===<br />
<br />
If you wish to restore a backup, use the same rsync command that was executed but with the source and destination reversed.<br />
<br />
== File system cloning ==<br />
<br />
rsync provides a way to do a copy of all data in a file system while preserving as much information as possible, including the file system metadata. It is a procedure of data cloning on a file system level where source and destination file systems don't need to be of the same type. It can be used for backing up, file system migration or data recovery.<br />
<br />
rsync's ''archive'' mode comes close to being fit for the job, but it doesn't back up the special file system metadata such as access control lists, extended attributes or sparse file properties. For successful cloning at the file system level, some additional options need to be provided:<br />
<br />
rsync -qaHAXS SOURCE_DIR DESTINATION_DIR<br />
<br />
And their meaning is (from the manpage):<br />
<br />
-H, --hard-links preserve hard links<br />
-A, --acls preserve ACLs (implies -p)<br />
-X, --xattrs preserve extended attributes<br />
-S, --sparse handle sparse files efficiently<br />
<br />
Produced copy can be simply reread and checked (for example after a data recovery attempt) at the file system level with {{ic|diff}}'s recursive option:<br />
<br />
diff -r SOURCE_DIR DESTINATION_DIR<br />
<br />
It is possible to do a successful file system migration by using rsync as described in this article and updating the [[fstab]] and [[bootloader]] as described in [[Migrate installation to new hardware]]. This essentially provides a way to convert any root file system to another one.<br />
<br />
== rsync daemon ==<br />
<br />
''rsync'' can be run as daemon on a server listening on port {{ic|873}}.<br />
<br />
Edit the template {{ic|/etc/rsyncd.conf}}, configure a share and [[start]] the {{ic|rsyncd.service}}.<br />
<br />
Usage from client, e.g. list server content:<br />
<br />
$ rsync rsync://''server/share''<br />
<br />
transfer file from client to server: <br />
<br />
$ rsync ''local-file'' rsync://''server/share/''<br />
<br />
Consider iptables to open port {{ic|873}} and user authentication.<br />
{{Note|All transferred data including user authentication are not encrypted.<br />
}}<br />
{{Note|As of rsync-3.1.2-5 the systemd unit file {{ic|/usr/lib/systemd/system/rsyncd.service}} included in the package has {{ic|ProtectHome&#61;on}} under the {{ic|[Service]}} section as a security feature, so rsyncd will '''not''' serve home directories ({{ic|/root}} included) to clients. If you need it to serve home directories you can override {{ic|ProtectHome&#61;On}} by issuing (as root)<br />
<br />
$ systemctl edit rsyncd.service<br />
<br />
and then adding<br />
<br />
[Service]<br />
ProtectHome&#61;off<br />
<br />
Then save the newly created file and restart rsyncd service:<br />
<br />
$ systemctl restart rsyncd<br />
}}<br />
<br />
== See also ==<br />
<br />
* More usage examples can be searched in the [https://bbs.archlinux.org/viewforum.php?id=27 Community Contributions] and [https://bbs.archlinux.org/viewforum.php?id=33 General Programming] forums<br />
* [http://www.pointsoftware.ch/en/howto-local-and-remote-snapshot-backup-using-rsync-with-hard-links/ Howto – local and remote snapshot backup using rsync with hard links] Includes file deduplication with hard-links, MD5 integrity signature, 'chattr' protection, filter rules, disk quota, retention policy with exponential distribution (backups rotation while saving more recent backups than older)</div>Pezcurrelhttps://wiki.archlinux.org/index.php?title=Rsync&diff=493910Rsync2017-10-23T08:36:17Z<p>Pezcurrel: /* rsync daemon */ minor formatting fixes</p>
<hr />
<div>{{Lowercase title}}<br />
[[Category:Data compression and archiving]]<br />
[[Category:System recovery]]<br />
[[es:Rsync]]<br />
[[ja:Rsync]]<br />
[[zh-hans:Rsync]]<br />
{{Related articles start}}<br />
{{Related|System backup}}<br />
{{Related|Synchronization and backup programs}}<br />
{{Related articles end}}<br />
[https://rsync.samba.org/ rsync] is an open source utility that provides fast incremental file transfer.<br />
<br />
== Installation ==<br />
<br />
[[Install]] the {{Pkg|rsync}} package.<br />
<br />
''rsync'' must be installed on both the source and the destination machine.<br />
<br />
=== Front-ends ===<br />
<br />
* {{App|Grsync|GTK+ front-end.|http://www.opbyte.it/grsync/|{{Pkg|grsync}}}}<br />
* {{App|gutback|rsync wrapper written in Shell.|https://github.com/gutenye/gutbackup|{{Aur|gutbackup}}}}<br />
* {{App|JotaSync|Java Swing GUI for rsync with integrated scheduler.|https://trixon.se/projects/jotasync/|{{Aur|jotasync}}}}<br />
* {{App|luckyBackup|Qt front-end written in C++.|http://luckybackup.sourceforge.net/index.html|{{Aur|luckybackup}}}}<br />
<br />
== As a cp alternative ==<br />
<br />
rsync can be used as an advanced alternative for the {{ic|cp}} command, especially for copying larger files:<br />
<br />
$ rsync -P source destination<br />
<br />
The {{ic|-P}} option is the same as {{Ic|--partial --progress}}, which keeps partially transferred files and shows a progress bar during transfer.<br />
<br />
You may want to use the {{ic|-r --recursive}} option to recurse into directories.<br />
<br />
Files can be copied locally as with cp, but the motivating purpose of rsync is to copy files remotely, i.e. between two different hosts. Remote locations can be specified with a host-colon syntax:<br />
<br />
$ rsync source host:destination<br />
<br />
or<br />
<br />
$ rsync host:source destination<br />
<br />
Network file transfers use the SSH protocol by default.<br />
<br />
{{Accuracy|By default, rsync does not compare contents of files. Rsync uses a "quick check" that (by default) checks if each file’s size and time of last modification match between the sender and receiver.}}<br />
<br />
Whether transferring files locally or remotely, rsync first creates an index of block checksums of each source file. This index is used to find any identical blocks of data which might exist in the destination. Such blocks are used in-place, rather than being copied from the source. This can greatly accelerate the synchronization of large files with small changes. For more information, see [https://rsync.samba.org/documentation.html official documentation], [https://rsync.samba.org/how-rsync-works.html how rsync works].<br />
<br />
=== Trailing slash caveat ===<br />
<br />
Arch by default uses GNU cp (part of [https://www.archlinux.org/packages/?name=coreutils GNU coreutils]). However, rsync follows the convention of BSD cp, which gives special treatment to source directories with a trailing slash "/". Although<br />
<br />
$ rsync -r source destination<br />
<br />
creates a directory "destination/source" with the contents of "source", the command<br />
<br />
$ rsync -r source/ destination<br />
<br />
copies all of the files in "source/" directly into "destination", with no intervening subdirectory - just as if you had invoked it as<br />
<br />
$ rsync -r source/. destination<br />
<br />
This behavior is different from that of GNU cp, which treats "source" and "source/" identically (but not "source/."). Also, some shells automatically append the trailing slash when tab-completing directory names. Because of these factors, there can be a tendency among new or occasional rsync users to forget about rsync's different behavior, and inadvertently create a mess or even overwrite important files by leaving the trailing slash on the command line.<br />
<br />
Thus it can be prudent to use a wrapper script to automatically remove trailing slashes before invoking rsync:<br />
<br />
#!/bin/zsh<br />
new_args=();<br />
for i in "$@"; do<br />
case $i in /) i=/;; */) i=${i%/};; esac<br />
new_args+=$i;<br />
done<br />
exec rsync "${(@)new_args}"<br />
<br />
This script can be put somewhere in the path, and aliased to rsync in the shell init file.<br />
<br />
== As a backup utility ==<br />
<br />
The rsync protocol can easily be used for backups, only transferring files that have changed since the last backup. This section describes a very simple scheduled backup script using rsync, typically used for copying to removable media.<br />
<br />
=== Automated backup ===<br />
<br />
For the sake of this example, the script is created in the {{ic|/etc/cron.daily}} directory, and will be run on a daily basis if a cron [[daemon]] is installed and properly configured. Configuring and using [[cron]] is outside the scope of this article.<br />
<br />
First, create a script containing the appropriate command options:<br />
<br />
{{hc|/etc/cron.daily/backup|<br />
#!/bin/bash<br />
rsync -a --delete --quiet /folder/to/backup /location/of/backup}}<br />
<br />
; {{ic|-a}} : indicates that files should be archived, meaning that most of their characteristics are preserved (but '''not''' ACLs, hard links or extended attributes such as capabilities)<br />
; {{ic|--delete}} : means files deleted on the source are to be deleted on the backup as well<br />
<br />
Here, {{ic|/folder/to/backup}} should be changed to what needs to be backed-up ({{ic|/home}}, for example) and {{ic|/location/to/backup}} is where the backup should be saved ({{ic|/media/disk}}, for instance).<br />
<br />
Finally, the script must be executable:<br />
<br />
# chmod +x /etc/cron.daily/backup<br />
<br />
=== Automated backup with SSH ===<br />
<br />
If backing-up to a remote host using [[SSH]], use this script instead:<br />
<br />
{{hc|/etc/cron.daily/backup|<br />
#!/bin/bash<br />
rsync -a --delete --quiet -e ssh /folder/to/backup remoteuser@remotehost:/location/of/backup<br />
}}<br />
<br />
; {{ic|-e ssh}} : tells rsync to use SSH<br />
; {{ic|remoteuser}} : is the user on the host {{ic|remotehost}}<br />
; {{ic|-a}} : groups all these options {{ic|-rlptgoD}} (recursive, links, perms, times, group, owner, devices)<br />
<br />
=== Automated backup with NetworkManager ===<br />
<br />
This script starts a backup when network connection is established.<br />
<br />
First, create a script containing the appropriate command options:<br />
<br />
{{hc|/etc/NetworkManager/dispatcher.d/backup|2=<br />
#!/bin/bash<br />
<br />
if [ x"$2" = "xup" ] ; then<br />
rsync --force --ignore-errors -a --delete --bwlimit=2000 --files-from=files.rsync /folder/to/backup /location/to/backup<br />
fi<br />
}}<br />
<br />
; {{ic|-a}} : group all this options {{ic|-rlptgoD}} recursive, links, perms, times, group, owner, devices<br />
; {{ic|--files-from}} : read the relative path of ''/folder/to/backup'' from this file<br />
; {{ic|--bwlimit}} : limit I/O bandwidth; KBytes per second<br />
<br />
Also, the script must have write permission for owner (root, of course) only (see [[NetworkManager#Network services with NetworkManager dispatcher]] for details).<br />
<br />
=== Automated backup with systemd and inotify ===<br />
<br />
{{Note|<br />
* Due to the limitations of inotify and systemd (see [http://www.quora.com/Linux-Kernel/Inotify-monitoring-of-directories-is-not-recursive-Is-there-any-specific-reason-for-this-design-in-Linux-kernel this question and answer]), recursive filesystem monitoring is not possible. Although you can watch a directory and its contents, it will not recurse into subdirectories and watch the contents of them; you must explicitly specify every directory to watch, even if that directory is a child of an already watched directory.<br />
* This setup is based on a [[systemd/User]] instance.<br />
}}<br />
<br />
Instead of running time interval backups with time based schedules, such as those implemented in [[cron]], it is possible to run a backup every time one of the files you are backing up changes. {{ic|systemd.path}} units use {{ic|inotify}} to monitor the filesystem, and can be used in conjunction with {{ic|systemd.service}} files to start any process (in this case your [[rsync]] backup) based on a filesystem event.<br />
<br />
First, create the {{ic|systemd.path}} file that will monitor the files you are backing up:<br />
<br />
{{hc|~/.config/systemd/user/backup.path|<nowiki><br />
[Unit]<br />
Description=Checks if paths that are currently being backed up have changed<br />
<br />
[Path]<br />
PathChanged=%h/documents<br />
PathChanged=%h/music<br />
<br />
[Install]<br />
WantedBy=default.target<br />
</nowiki>}}<br />
<br />
Then create a {{ic|systemd.service}} file that will be activated when it detects a change. By default a service file of the same name as the path unit (in this case {{ic|backup.path}}) will be activated, except with the {{ic|.service}} extension instead of {{ic|.path}} (in this case {{ic|backup.service}}).<br />
<br />
{{Note|If you need to run multiple rsync commands, use {{ic|1=Type=oneshot}}. This allows you to specify multiple {{ic|1=ExecStart=}} parameters, one for each [[rsync]] command, that will be executed. Alternatively, you can simply write a script to perform all of your backups, just like [[cron]] scripts.}}<br />
<br />
{{hc|~/.config/systemd/user/backup.service|<nowiki><br />
[Unit]<br />
Description=Backs up files<br />
<br />
[Service]<br />
ExecStart=/usr/bin/rsync %h/./documents %h/./music -CERrltm --delete ubuntu:<br />
</nowiki>}}<br />
<br />
Now all you have to do is [[start]]/enable {{ic|backup.path}} like a normal systemd service and it will start monitoring file changes and automatically starting {{ic|backup.service}}.<br />
<br />
=== Differential backup on a week ===<br />
<br />
This is a useful option of rsync, creating a full backup and a differential backup for each day of a week.<br />
<br />
First, create a script containing the appropriate command options:<br />
<br />
{{hc|/etc/cron.daily/backup|2=<br />
#!/bin/bash<br />
<br />
DAY=$(date +%A)<br />
<br />
if [ -e /location/to/backup/incr/$DAY ] ; then<br />
rm -fr /location/to/backup/incr/$DAY<br />
fi<br />
<br />
rsync -a --delete --quiet --inplace --backup --backup-dir=/location/to/backup/incr/$DAY /folder/to/backup/ /location/to/backup/full/<br />
}}<br />
<br />
; {{ic|--inplace}} : implies {{ic|--partial}} update destination files in-place<br />
<br />
=== Snapshot backup ===<br />
<br />
The same idea can be used to maintain a tree of snapshots of your files. In other words, a directory with date-ordered copies of the files. The copies are made using hardlinks, which means that only files that did change will occupy space. Generally speaking, this is the idea behind Apple's TimeMachine.<br />
<br />
This basic script is easy to implement and creates quick incremental snapshots using the {{ic|--link-dest}} option to hardlink unchanged files: <br />
<br />
{{hc|/usr/local/bin/snapbackup.sh|<nowiki><br />
#!/bin/bash<br />
<br />
# Basic snapshot-style rsync backup script <br />
<br />
# Config<br />
OPT="-aPh"<br />
LINK="--link-dest=/snapshots/username/last/" <br />
SRC="/home/username/files/"<br />
SNAP="/snapshots/username/"<br />
LAST="/snapshots/username/last"<br />
date=`date "+%Y-%b-%d:_%T"`<br />
<br />
# Run rsync to create snapshot<br />
rsync $OPT $LINK $SRC ${SNAP}$date<br />
<br />
# Remove symlink to previous snapshot<br />
rm -f $LAST<br />
<br />
# Create new symlink to latest snapshot for the next backup to hardlink<br />
ln -s ${SNAP}$date $LAST<br />
</nowiki>}}<br />
<br />
There must be a symlink to a full backup already in existence as a target for {{ic|--link-dest}}. If the most recent snapshot is deleted, the symlink will need to be recreated to point to the most recent snapshot. If {{ic|--link-dest}} does not find a working symlink, rsync will proceed to copy all source files instead of only the changes. <br />
<br />
A more sophisticated version checks to see if a certain number of changes have been made before making the backup and utilizes {{ic|cp -al}} to hardlink unchanged files:<br />
<br />
{{hc|/usr/local/bin/rsnapshot.sh|<nowiki><br />
#!/bin/bash<br />
<br />
## my own rsync-based snapshot-style backup procedure<br />
## (cc) marcio rps AT gmail.com<br />
<br />
# config vars<br />
<br />
SRC="/home/username/files/" #dont forget trailing slash!<br />
SNAP="/snapshots/username"<br />
OPTS="-rltgoi --delay-updates --delete --chmod=a-w"<br />
MINCHANGES=20<br />
<br />
# run this process with real low priority<br />
<br />
ionice -c 3 -p $$<br />
renice +12 -p $$<br />
<br />
# sync<br />
<br />
rsync $OPTS $SRC $SNAP/latest >> $SNAP/rsync.log<br />
<br />
# check if enough has changed and if so<br />
# make a hardlinked copy named as the date<br />
<br />
COUNT=$( wc -l $SNAP/rsync.log|cut -d" " -f1 )<br />
if [ $COUNT -gt $MINCHANGES ] ; then<br />
DATETAG=$(date +%Y-%m-%d)<br />
if [ ! -e $SNAP/$DATETAG ] ; then<br />
cp -al $SNAP/latest $SNAP/$DATETAG<br />
chmod u+w $SNAP/$DATETAG<br />
mv $SNAP/rsync.log $SNAP/$DATETAG<br />
chmod u-w $SNAP/$DATETAG<br />
fi<br />
fi<br />
</nowiki>}}<br />
<br />
To make things really, really simple this script can be run from a [[systemd/Timers]] unit.<br />
<br />
=== Full system backup ===<br />
<br />
This section is about using ''rsync'' to transfer a copy of the entire {{ic|/}} tree, excluding a few selected folders. This approach is considered to be better than [[disk cloning]] with {{ic|dd}} since it allows for a different size, partition table and filesystem to be used, and better than copying with {{ic|cp -a}} as well, because it allows greater control over file permissions, attributes, [[Access Control Lists]] and [[extended attributes]].<br />
<br />
''rsync'' will work even while the system is running, but files changed during the transfer may or may not be transferred, which can cause undefined behavior of some programs using the transferred files.<br />
<br />
This approach works well for migrating an existing installation to a new hard drive or [[SSD]].<br />
<br />
Run the following command as root to make sure that rsync can access all system files and preserve the ownership:<br />
<br />
# rsync -aAXv --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} / ''/path/to/backup/folder''<br />
<br />
By using the {{ic|-aAX}} set of options, the files are transferred in archive mode which ensures that symbolic links, devices, permissions, ownerships, modification times, [[ACL]]s, and extended attributes are preserved, assuming that the target [[file system]] supports the feature.<br />
<br />
The {{ic|--exclude}} option causes files that match the given patterns to be excluded. The contents of {{ic|/dev}}, {{ic|/proc}}, {{ic|/sys}}, {{ic|/tmp}}, and {{ic|/run}} are excluded in the above command, because they are populated at boot, although the folders themselves are ''not'' created. {{ic|/lost+found}} is filesystem-specific. The command above depends on brace expansion available in both the [https://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html bash] and [http://zsh.sourceforge.net/Doc/Release/Expansion.html#Brace-Expansion zsh] shells. When using a different [[shell]], {{ic|--exclude}} patterns should be repeated manually. Quoting the exclude patterns will avoid expansion by the [[shell]], which is necessary, for example, when backing up over [[SSH]]. Ending the excluded paths with {{ic|*}} ensures that the directories themselves are created if they do not already exist.<br />
<br />
{{Note|<br />
* If you plan on backing up your system somewhere other than {{ic|/mnt}} or {{ic|/media}}, do not forget to add it to the list of exclude patterns to avoid an infinite loop.<br />
* If there are any bind mounts in the system, they should be excluded as well so that the bind mounted contents is copied only once.<br />
* If you use a [[swap file]], make sure to exclude it as well.<br />
* Consider if you want to backup the {{ic|/home/}} folder. If it contains your data it might be considerably larger than the system. Otherwise consider excluding unimportant subdirectories such as {{ic|/home/*/.thumbnails/*}}, {{ic|/home/*/.cache/mozilla/*}}, {{ic|/home/*/.cache/chromium/*}}, and {{ic|/home/*/.local/share/Trash/*}}, depending on software installed on the system. If [[GVFS]] is installed, {{ic|/home/*/.gvfs}} must be excluded to prevent rsync errors.<br />
}}<br />
<br />
You may want to include additional [[rsync]] options, such as the following. See {{man|1|rsync}} for the full list.<br />
<br />
* If you use many hard links, consider adding the {{ic|-H}} option, which is turned off by default due to its memory expense; however, it should be no problem on most modern machines. Many hard links reside under the {{ic|/usr/}} directory.<br />
* You may want to add rsync's {{ic|--delete}} option if you are running this multiple times to the same backup folder. In this case make sure that the source path does not end with {{ic|/*}}, or this option will only have effect on the files inside the subdirectories of the source directory, but it will have no effect on the files residing directly inside the source directory.<br />
* If you use any sparse files, such as virtual disks, [[Docker]] images and similar, you should add the {{ic|-S}} option.<br />
* The {{ic|--numeric-ids}} option will disable mapping of user and group names; instead, numeric group and user IDs will be transfered. This is useful when backing up over [[SSH]] or when using a live system to backup different system disk.<br />
* Choosing {{ic|1=--info=progress2}} option instead of {{ic|-v}} will show the overall progress info and transfer speed instead of the list of files being transferred.<br />
<br />
=== Restore a backup ===<br />
<br />
If you wish to restore a backup, use the same rsync command that was executed but with the source and destination reversed.<br />
<br />
== File system cloning ==<br />
<br />
rsync provides a way to do a copy of all data in a file system while preserving as much information as possible, including the file system metadata. It is a procedure of data cloning on a file system level where source and destination file systems don't need to be of the same type. It can be used for backing up, file system migration or data recovery.<br />
<br />
rsync's ''archive'' mode comes close to being fit for the job, but it doesn't back up the special file system metadata such as access control lists, extended attributes or sparse file properties. For successful cloning at the file system level, some additional options need to be provided:<br />
<br />
rsync -qaHAXS SOURCE_DIR DESTINATION_DIR<br />
<br />
And their meaning is (from the manpage):<br />
<br />
-H, --hard-links preserve hard links<br />
-A, --acls preserve ACLs (implies -p)<br />
-X, --xattrs preserve extended attributes<br />
-S, --sparse handle sparse files efficiently<br />
<br />
Produced copy can be simply reread and checked (for example after a data recovery attempt) at the file system level with {{ic|diff}}'s recursive option:<br />
<br />
diff -r SOURCE_DIR DESTINATION_DIR<br />
<br />
It is possible to do a successful file system migration by using rsync as described in this article and updating the [[fstab]] and [[bootloader]] as described in [[Migrate installation to new hardware]]. This essentially provides a way to convert any root file system to another one.<br />
<br />
== rsync daemon ==<br />
<br />
''rsync'' can be run as daemon on a server listening on port {{ic|873}}.<br />
<br />
Edit the template {{ic|/etc/rsyncd.conf}}, configure a share and [[start]] the {{ic|rsyncd.service}}.<br />
<br />
Usage from client, e.g. list server content:<br />
<br />
$ rsync rsync://''server/share''<br />
<br />
transfer file from client to server: <br />
<br />
$ rsync ''local-file'' rsync://''server/share/''<br />
<br />
Consider iptables to open port {{ic|873}} and user authentication.<br />
{{Note|As of rsync-3.1.2-5 the systemd unit file /usr/lib/systemd/system/rsyncd.service included in the package has "ProtectHome&#61;on" under the "[Service]" section as a security feature, so rsyncd will *not* serve home directories (/root included) to clients. If you need it to serve home directories you can override the "ProtectHome&#61;On" by issuing (as root)<br />
<br />
$ systemctl edit rsyncd.service<br />
<br />
and then adding<br />
<br />
[Service]<br />
ProtectHome&#61;off<br />
<br />
Then save the newly created file and restart rsyncd service:<br />
<br />
$ systemctl restart rsyncd<br />
}}<br />
{{Note|All transferred data including user authentication are not encrypted.<br />
}}<br />
<br />
== See also ==<br />
<br />
* More usage examples can be searched in the [https://bbs.archlinux.org/viewforum.php?id=27 Community Contributions] and [https://bbs.archlinux.org/viewforum.php?id=33 General Programming] forums<br />
* [http://www.pointsoftware.ch/en/howto-local-and-remote-snapshot-backup-using-rsync-with-hard-links/ Howto – local and remote snapshot backup using rsync with hard links] Includes file deduplication with hard-links, MD5 integrity signature, 'chattr' protection, filter rules, disk quota, retention policy with exponential distribution (backups rotation while saving more recent backups than older)</div>Pezcurrelhttps://wiki.archlinux.org/index.php?title=Rsync&diff=493909Rsync2017-10-23T08:30:04Z<p>Pezcurrel: /* rsync daemon */ added a note to warn users about rsyncd service file having "ProtectHome=on" and its consequences, and to suggest how to override it (see also https://bugs.archlinux.org/task/56008)</p>
<hr />
<div>{{Lowercase title}}<br />
[[Category:Data compression and archiving]]<br />
[[Category:System recovery]]<br />
[[es:Rsync]]<br />
[[ja:Rsync]]<br />
[[zh-hans:Rsync]]<br />
{{Related articles start}}<br />
{{Related|System backup}}<br />
{{Related|Synchronization and backup programs}}<br />
{{Related articles end}}<br />
[https://rsync.samba.org/ rsync] is an open source utility that provides fast incremental file transfer.<br />
<br />
== Installation ==<br />
<br />
[[Install]] the {{Pkg|rsync}} package.<br />
<br />
''rsync'' must be installed on both the source and the destination machine.<br />
<br />
=== Front-ends ===<br />
<br />
* {{App|Grsync|GTK+ front-end.|http://www.opbyte.it/grsync/|{{Pkg|grsync}}}}<br />
* {{App|gutback|rsync wrapper written in Shell.|https://github.com/gutenye/gutbackup|{{Aur|gutbackup}}}}<br />
* {{App|JotaSync|Java Swing GUI for rsync with integrated scheduler.|https://trixon.se/projects/jotasync/|{{Aur|jotasync}}}}<br />
* {{App|luckyBackup|Qt front-end written in C++.|http://luckybackup.sourceforge.net/index.html|{{Aur|luckybackup}}}}<br />
<br />
== As a cp alternative ==<br />
<br />
rsync can be used as an advanced alternative for the {{ic|cp}} command, especially for copying larger files:<br />
<br />
$ rsync -P source destination<br />
<br />
The {{ic|-P}} option is the same as {{Ic|--partial --progress}}, which keeps partially transferred files and shows a progress bar during transfer.<br />
<br />
You may want to use the {{ic|-r --recursive}} option to recurse into directories.<br />
<br />
Files can be copied locally as with cp, but the motivating purpose of rsync is to copy files remotely, i.e. between two different hosts. Remote locations can be specified with a host-colon syntax:<br />
<br />
$ rsync source host:destination<br />
<br />
or<br />
<br />
$ rsync host:source destination<br />
<br />
Network file transfers use the SSH protocol by default.<br />
<br />
{{Accuracy|By default, rsync does not compare contents of files. Rsync uses a "quick check" that (by default) checks if each file’s size and time of last modification match between the sender and receiver.}}<br />
<br />
Whether transferring files locally or remotely, rsync first creates an index of block checksums of each source file. This index is used to find any identical blocks of data which might exist in the destination. Such blocks are used in-place, rather than being copied from the source. This can greatly accelerate the synchronization of large files with small changes. For more information, see [https://rsync.samba.org/documentation.html official documentation], [https://rsync.samba.org/how-rsync-works.html how rsync works].<br />
<br />
=== Trailing slash caveat ===<br />
<br />
Arch by default uses GNU cp (part of [https://www.archlinux.org/packages/?name=coreutils GNU coreutils]). However, rsync follows the convention of BSD cp, which gives special treatment to source directories with a trailing slash "/". Although<br />
<br />
$ rsync -r source destination<br />
<br />
creates a directory "destination/source" with the contents of "source", the command<br />
<br />
$ rsync -r source/ destination<br />
<br />
copies all of the files in "source/" directly into "destination", with no intervening subdirectory - just as if you had invoked it as<br />
<br />
$ rsync -r source/. destination<br />
<br />
This behavior is different from that of GNU cp, which treats "source" and "source/" identically (but not "source/."). Also, some shells automatically append the trailing slash when tab-completing directory names. Because of these factors, there can be a tendency among new or occasional rsync users to forget about rsync's different behavior, and inadvertently create a mess or even overwrite important files by leaving the trailing slash on the command line.<br />
<br />
Thus it can be prudent to use a wrapper script to automatically remove trailing slashes before invoking rsync:<br />
<br />
#!/bin/zsh<br />
new_args=();<br />
for i in "$@"; do<br />
case $i in /) i=/;; */) i=${i%/};; esac<br />
new_args+=$i;<br />
done<br />
exec rsync "${(@)new_args}"<br />
<br />
This script can be put somewhere in the path, and aliased to rsync in the shell init file.<br />
<br />
== As a backup utility ==<br />
<br />
The rsync protocol can easily be used for backups, only transferring files that have changed since the last backup. This section describes a very simple scheduled backup script using rsync, typically used for copying to removable media.<br />
<br />
=== Automated backup ===<br />
<br />
For the sake of this example, the script is created in the {{ic|/etc/cron.daily}} directory, and will be run on a daily basis if a cron [[daemon]] is installed and properly configured. Configuring and using [[cron]] is outside the scope of this article.<br />
<br />
First, create a script containing the appropriate command options:<br />
<br />
{{hc|/etc/cron.daily/backup|<br />
#!/bin/bash<br />
rsync -a --delete --quiet /folder/to/backup /location/of/backup}}<br />
<br />
; {{ic|-a}} : indicates that files should be archived, meaning that most of their characteristics are preserved (but '''not''' ACLs, hard links or extended attributes such as capabilities)<br />
; {{ic|--delete}} : means files deleted on the source are to be deleted on the backup as well<br />
<br />
Here, {{ic|/folder/to/backup}} should be changed to what needs to be backed-up ({{ic|/home}}, for example) and {{ic|/location/to/backup}} is where the backup should be saved ({{ic|/media/disk}}, for instance).<br />
<br />
Finally, the script must be executable:<br />
<br />
# chmod +x /etc/cron.daily/backup<br />
<br />
=== Automated backup with SSH ===<br />
<br />
If backing-up to a remote host using [[SSH]], use this script instead:<br />
<br />
{{hc|/etc/cron.daily/backup|<br />
#!/bin/bash<br />
rsync -a --delete --quiet -e ssh /folder/to/backup remoteuser@remotehost:/location/of/backup<br />
}}<br />
<br />
; {{ic|-e ssh}} : tells rsync to use SSH<br />
; {{ic|remoteuser}} : is the user on the host {{ic|remotehost}}<br />
; {{ic|-a}} : groups all these options {{ic|-rlptgoD}} (recursive, links, perms, times, group, owner, devices)<br />
<br />
=== Automated backup with NetworkManager ===<br />
<br />
This script starts a backup when network connection is established.<br />
<br />
First, create a script containing the appropriate command options:<br />
<br />
{{hc|/etc/NetworkManager/dispatcher.d/backup|2=<br />
#!/bin/bash<br />
<br />
if [ x"$2" = "xup" ] ; then<br />
rsync --force --ignore-errors -a --delete --bwlimit=2000 --files-from=files.rsync /folder/to/backup /location/to/backup<br />
fi<br />
}}<br />
<br />
; {{ic|-a}} : group all this options {{ic|-rlptgoD}} recursive, links, perms, times, group, owner, devices<br />
; {{ic|--files-from}} : read the relative path of ''/folder/to/backup'' from this file<br />
; {{ic|--bwlimit}} : limit I/O bandwidth; KBytes per second<br />
<br />
Also, the script must have write permission for owner (root, of course) only (see [[NetworkManager#Network services with NetworkManager dispatcher]] for details).<br />
<br />
=== Automated backup with systemd and inotify ===<br />
<br />
{{Note|<br />
* Due to the limitations of inotify and systemd (see [http://www.quora.com/Linux-Kernel/Inotify-monitoring-of-directories-is-not-recursive-Is-there-any-specific-reason-for-this-design-in-Linux-kernel this question and answer]), recursive filesystem monitoring is not possible. Although you can watch a directory and its contents, it will not recurse into subdirectories and watch the contents of them; you must explicitly specify every directory to watch, even if that directory is a child of an already watched directory.<br />
* This setup is based on a [[systemd/User]] instance.<br />
}}<br />
<br />
Instead of running time interval backups with time based schedules, such as those implemented in [[cron]], it is possible to run a backup every time one of the files you are backing up changes. {{ic|systemd.path}} units use {{ic|inotify}} to monitor the filesystem, and can be used in conjunction with {{ic|systemd.service}} files to start any process (in this case your [[rsync]] backup) based on a filesystem event.<br />
<br />
First, create the {{ic|systemd.path}} file that will monitor the files you are backing up:<br />
<br />
{{hc|~/.config/systemd/user/backup.path|<nowiki><br />
[Unit]<br />
Description=Checks if paths that are currently being backed up have changed<br />
<br />
[Path]<br />
PathChanged=%h/documents<br />
PathChanged=%h/music<br />
<br />
[Install]<br />
WantedBy=default.target<br />
</nowiki>}}<br />
<br />
Then create a {{ic|systemd.service}} file that will be activated when it detects a change. By default a service file of the same name as the path unit (in this case {{ic|backup.path}}) will be activated, except with the {{ic|.service}} extension instead of {{ic|.path}} (in this case {{ic|backup.service}}).<br />
<br />
{{Note|If you need to run multiple rsync commands, use {{ic|1=Type=oneshot}}. This allows you to specify multiple {{ic|1=ExecStart=}} parameters, one for each [[rsync]] command, that will be executed. Alternatively, you can simply write a script to perform all of your backups, just like [[cron]] scripts.}}<br />
<br />
{{hc|~/.config/systemd/user/backup.service|<nowiki><br />
[Unit]<br />
Description=Backs up files<br />
<br />
[Service]<br />
ExecStart=/usr/bin/rsync %h/./documents %h/./music -CERrltm --delete ubuntu:<br />
</nowiki>}}<br />
<br />
Now all you have to do is [[start]]/enable {{ic|backup.path}} like a normal systemd service and it will start monitoring file changes and automatically starting {{ic|backup.service}}.<br />
<br />
=== Differential backup on a week ===<br />
<br />
This is a useful option of rsync, creating a full backup and a differential backup for each day of a week.<br />
<br />
First, create a script containing the appropriate command options:<br />
<br />
{{hc|/etc/cron.daily/backup|2=<br />
#!/bin/bash<br />
<br />
DAY=$(date +%A)<br />
<br />
if [ -e /location/to/backup/incr/$DAY ] ; then<br />
rm -fr /location/to/backup/incr/$DAY<br />
fi<br />
<br />
rsync -a --delete --quiet --inplace --backup --backup-dir=/location/to/backup/incr/$DAY /folder/to/backup/ /location/to/backup/full/<br />
}}<br />
<br />
; {{ic|--inplace}} : implies {{ic|--partial}} update destination files in-place<br />
<br />
=== Snapshot backup ===<br />
<br />
The same idea can be used to maintain a tree of snapshots of your files. In other words, a directory with date-ordered copies of the files. The copies are made using hardlinks, which means that only files that did change will occupy space. Generally speaking, this is the idea behind Apple's TimeMachine.<br />
<br />
This basic script is easy to implement and creates quick incremental snapshots using the {{ic|--link-dest}} option to hardlink unchanged files: <br />
<br />
{{hc|/usr/local/bin/snapbackup.sh|<nowiki><br />
#!/bin/bash<br />
<br />
# Basic snapshot-style rsync backup script <br />
<br />
# Config<br />
OPT="-aPh"<br />
LINK="--link-dest=/snapshots/username/last/" <br />
SRC="/home/username/files/"<br />
SNAP="/snapshots/username/"<br />
LAST="/snapshots/username/last"<br />
date=`date "+%Y-%b-%d:_%T"`<br />
<br />
# Run rsync to create snapshot<br />
rsync $OPT $LINK $SRC ${SNAP}$date<br />
<br />
# Remove symlink to previous snapshot<br />
rm -f $LAST<br />
<br />
# Create new symlink to latest snapshot for the next backup to hardlink<br />
ln -s ${SNAP}$date $LAST<br />
</nowiki>}}<br />
<br />
There must be a symlink to a full backup already in existence as a target for {{ic|--link-dest}}. If the most recent snapshot is deleted, the symlink will need to be recreated to point to the most recent snapshot. If {{ic|--link-dest}} does not find a working symlink, rsync will proceed to copy all source files instead of only the changes. <br />
<br />
A more sophisticated version checks to see if a certain number of changes have been made before making the backup and utilizes {{ic|cp -al}} to hardlink unchanged files:<br />
<br />
{{hc|/usr/local/bin/rsnapshot.sh|<nowiki><br />
#!/bin/bash<br />
<br />
## my own rsync-based snapshot-style backup procedure<br />
## (cc) marcio rps AT gmail.com<br />
<br />
# config vars<br />
<br />
SRC="/home/username/files/" #dont forget trailing slash!<br />
SNAP="/snapshots/username"<br />
OPTS="-rltgoi --delay-updates --delete --chmod=a-w"<br />
MINCHANGES=20<br />
<br />
# run this process with real low priority<br />
<br />
ionice -c 3 -p $$<br />
renice +12 -p $$<br />
<br />
# sync<br />
<br />
rsync $OPTS $SRC $SNAP/latest >> $SNAP/rsync.log<br />
<br />
# check if enough has changed and if so<br />
# make a hardlinked copy named as the date<br />
<br />
COUNT=$( wc -l $SNAP/rsync.log|cut -d" " -f1 )<br />
if [ $COUNT -gt $MINCHANGES ] ; then<br />
DATETAG=$(date +%Y-%m-%d)<br />
if [ ! -e $SNAP/$DATETAG ] ; then<br />
cp -al $SNAP/latest $SNAP/$DATETAG<br />
chmod u+w $SNAP/$DATETAG<br />
mv $SNAP/rsync.log $SNAP/$DATETAG<br />
chmod u-w $SNAP/$DATETAG<br />
fi<br />
fi<br />
</nowiki>}}<br />
<br />
To make things really, really simple this script can be run from a [[systemd/Timers]] unit.<br />
<br />
=== Full system backup ===<br />
<br />
This section is about using ''rsync'' to transfer a copy of the entire {{ic|/}} tree, excluding a few selected folders. This approach is considered to be better than [[disk cloning]] with {{ic|dd}} since it allows for a different size, partition table and filesystem to be used, and better than copying with {{ic|cp -a}} as well, because it allows greater control over file permissions, attributes, [[Access Control Lists]] and [[extended attributes]].<br />
<br />
''rsync'' will work even while the system is running, but files changed during the transfer may or may not be transferred, which can cause undefined behavior of some programs using the transferred files.<br />
<br />
This approach works well for migrating an existing installation to a new hard drive or [[SSD]].<br />
<br />
Run the following command as root to make sure that rsync can access all system files and preserve the ownership:<br />
<br />
# rsync -aAXv --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} / ''/path/to/backup/folder''<br />
<br />
By using the {{ic|-aAX}} set of options, the files are transferred in archive mode which ensures that symbolic links, devices, permissions, ownerships, modification times, [[ACL]]s, and extended attributes are preserved, assuming that the target [[file system]] supports the feature.<br />
<br />
The {{ic|--exclude}} option causes files that match the given patterns to be excluded. The contents of {{ic|/dev}}, {{ic|/proc}}, {{ic|/sys}}, {{ic|/tmp}}, and {{ic|/run}} are excluded in the above command, because they are populated at boot, although the folders themselves are ''not'' created. {{ic|/lost+found}} is filesystem-specific. The command above depends on brace expansion available in both the [https://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html bash] and [http://zsh.sourceforge.net/Doc/Release/Expansion.html#Brace-Expansion zsh] shells. When using a different [[shell]], {{ic|--exclude}} patterns should be repeated manually. Quoting the exclude patterns will avoid expansion by the [[shell]], which is necessary, for example, when backing up over [[SSH]]. Ending the excluded paths with {{ic|*}} ensures that the directories themselves are created if they do not already exist.<br />
<br />
{{Note|<br />
* If you plan on backing up your system somewhere other than {{ic|/mnt}} or {{ic|/media}}, do not forget to add it to the list of exclude patterns to avoid an infinite loop.<br />
* If there are any bind mounts in the system, they should be excluded as well so that the bind mounted contents is copied only once.<br />
* If you use a [[swap file]], make sure to exclude it as well.<br />
* Consider if you want to backup the {{ic|/home/}} folder. If it contains your data it might be considerably larger than the system. Otherwise consider excluding unimportant subdirectories such as {{ic|/home/*/.thumbnails/*}}, {{ic|/home/*/.cache/mozilla/*}}, {{ic|/home/*/.cache/chromium/*}}, and {{ic|/home/*/.local/share/Trash/*}}, depending on software installed on the system. If [[GVFS]] is installed, {{ic|/home/*/.gvfs}} must be excluded to prevent rsync errors.<br />
}}<br />
<br />
You may want to include additional [[rsync]] options, such as the following. See {{man|1|rsync}} for the full list.<br />
<br />
* If you use many hard links, consider adding the {{ic|-H}} option, which is turned off by default due to its memory expense; however, it should be no problem on most modern machines. Many hard links reside under the {{ic|/usr/}} directory.<br />
* You may want to add rsync's {{ic|--delete}} option if you are running this multiple times to the same backup folder. In this case make sure that the source path does not end with {{ic|/*}}, or this option will only have effect on the files inside the subdirectories of the source directory, but it will have no effect on the files residing directly inside the source directory.<br />
* If you use any sparse files, such as virtual disks, [[Docker]] images and similar, you should add the {{ic|-S}} option.<br />
* The {{ic|--numeric-ids}} option will disable mapping of user and group names; instead, numeric group and user IDs will be transfered. This is useful when backing up over [[SSH]] or when using a live system to backup different system disk.<br />
* Choosing {{ic|1=--info=progress2}} option instead of {{ic|-v}} will show the overall progress info and transfer speed instead of the list of files being transferred.<br />
<br />
=== Restore a backup ===<br />
<br />
If you wish to restore a backup, use the same rsync command that was executed but with the source and destination reversed.<br />
<br />
== File system cloning ==<br />
<br />
rsync provides a way to do a copy of all data in a file system while preserving as much information as possible, including the file system metadata. It is a procedure of data cloning on a file system level where source and destination file systems don't need to be of the same type. It can be used for backing up, file system migration or data recovery.<br />
<br />
rsync's ''archive'' mode comes close to being fit for the job, but it doesn't back up the special file system metadata such as access control lists, extended attributes or sparse file properties. For successful cloning at the file system level, some additional options need to be provided:<br />
<br />
rsync -qaHAXS SOURCE_DIR DESTINATION_DIR<br />
<br />
And their meaning is (from the manpage):<br />
<br />
-H, --hard-links preserve hard links<br />
-A, --acls preserve ACLs (implies -p)<br />
-X, --xattrs preserve extended attributes<br />
-S, --sparse handle sparse files efficiently<br />
<br />
Produced copy can be simply reread and checked (for example after a data recovery attempt) at the file system level with {{ic|diff}}'s recursive option:<br />
<br />
diff -r SOURCE_DIR DESTINATION_DIR<br />
<br />
It is possible to do a successful file system migration by using rsync as described in this article and updating the [[fstab]] and [[bootloader]] as described in [[Migrate installation to new hardware]]. This essentially provides a way to convert any root file system to another one.<br />
<br />
== rsync daemon ==<br />
<br />
''rsync'' can be run as daemon on a server listening on port {{ic|873}}.<br />
<br />
Edit the template {{ic|/etc/rsyncd.conf}}, configure a share and [[start]] the {{ic|rsyncd.service}}.<br />
<br />
Usage from client, e.g. list server content:<br />
<br />
$ rsync rsync://''server/share''<br />
<br />
transfer file from client to server: <br />
<br />
$ rsync ''local-file'' rsync://''server/share/''<br />
<br />
Consider iptables to open port {{ic|873}} and user authentication.<br />
{{Note|As of rsync-3.1.2-5 the systemd unit file /usr/lib/systemd/system/rsyncd.service included in the package has "ProtectHome=on" under the "[Service]" section as a security feature, so rsyncd will *not* serve home directories (/root included) to clients. If you need it to serve home directories you can override the "ProtectHome=On" by issuing (as root)<br />
<br />
$ systemctl edit rsyncd.service<br />
<br />
and then adding<br />
<br />
[Service]<br />
ProtectHome=off<br />
<br />
Then save the newly created file and restart rsyncd service:<br />
<br />
$ systemctl restart rsyncd<br />
}}<br />
{{Note|All transferred data including user authentication are not encrypted.<br />
}}<br />
<br />
== See also ==<br />
<br />
* More usage examples can be searched in the [https://bbs.archlinux.org/viewforum.php?id=27 Community Contributions] and [https://bbs.archlinux.org/viewforum.php?id=33 General Programming] forums<br />
* [http://www.pointsoftware.ch/en/howto-local-and-remote-snapshot-backup-using-rsync-with-hard-links/ Howto – local and remote snapshot backup using rsync with hard links] Includes file deduplication with hard-links, MD5 integrity signature, 'chattr' protection, filter rules, disk quota, retention policy with exponential distribution (backups rotation while saving more recent backups than older)</div>Pezcurrelhttps://wiki.archlinux.org/index.php?title=Power_saving&diff=347323Power saving2014-11-30T11:07:13Z<p>Pezcurrel: Added ".rules" to "/etc/udev/rules.d/powersave", udev rules files need this, otherwise they are not considered</p>
<hr />
<div>[[Category:Power management]]<br />
[[ja:Power saving]]<br />
{{Related articles start}}<br />
{{Related|Power management}}<br />
{{Related|CPU frequency scaling}}<br />
{{Related|Hybrid graphics}}<br />
{{Related|Kernel modules}}<br />
{{Related|sysctl}}<br />
{{Related|udev}}<br />
{{Related articles end}}<br />
This article covers the configuration needed to turn on power saving features. Almost all of the features listed here are worth using whether or not the computer is on AC or battery power. Most have negligible performance impact and are just not enabled by default because of commonly broken hardware/drivers. Reducing power usage means reducing heat, which can even lead to higher performance on a modern Intel or AMD CPU, thanks to [[Wikipedia:Intel Turbo Boost|dynamic overclocking]].<br />
<br />
== Configuration ==<br />
<br />
If you would like to create your own scripts and power saving settings such as by udev rules you can take the following settings as a reference.<br />
<br />
{{Note|Most rules described below are also managed by tools like [[TLP]] and it is unwise to use multigoverning.}}<br />
<br />
=== Audio ===<br />
<br />
By default, audio power saving is turned off by most drivers. It can be enabled by setting the {{ic|power_save}} parameter; a time (in seconds) to go into idle mode. To idle the audio card after one second, create<br />
<br />
{{hc|/etc/modprobe.d/audio_powersave.conf|2=options snd_hda_intel power_save=1}}<br />
<br />
for Intel, or use<br />
<br />
options snd_ac97_codec power_save=1<br />
<br />
for ac97.<br />
<br />
{{Note|Toggling the audio card's power state can cause a popping sound or noticeable latency on some broken hardware.}}<br />
<br />
=== Backlight ===<br />
<br />
See [[Backlight]].<br />
<br />
=== Bluetooth ===<br />
<br />
{{expansion|reason=The device should likely be disabled with hciconfig first.}}<br />
<br />
To disable bluetooth completely, [[Kernel_modules#Blacklisting|blacklist]] the {{ic|btusb}} and {{ic|bluetooth}} modules.<br />
<br />
To turn off bluetooth only temporarily, use {{Pkg|rfkill}}:<br />
<br />
# rfkill block bluetooth<br />
<br />
Or with udev rule:<br />
<br />
{{hc|/etc/udev/rules.d/50-bluetooth.rules|<nowiki><br />
# disable bluetooth<br />
SUBSYSTEM=="rfkill", ATTR{type}=="bluetooth", ATTR{state}="0"<br />
</nowiki>}}<br />
<br />
Or just [[enable]] the instantiated {{ic|rfkill-block@bluetooth.service}} provided by the {{Pkg|rfkill}} package.<br />
<br />
=== Web camera ===<br />
<br />
If you will not use integrated web camera then [[Kernel_modules#Blacklisting|blacklist]] the {{ic|uvcvideo}} module.<br />
<br />
=== Kernel parameters ===<br />
<br />
This section uses configs in {{ic|/etc/sysctl.d/}}, which is ''"a drop-in directory for kernel sysctl parameters."'' See [http://0pointer.de/blog/projects/the-new-configuration-files The New Configuration Files] and more specifically [http://0pointer.de/public/systemd-man/sysctl.d.html systemd's sysctl.d man page] for more information.<br />
<br />
==== Disabling NMI watchdog ====<br />
<br />
The [[Wikipedia:Non-maskable interrupt|NMI]] watchdog is a debugging feature to catch hardware hangs that cause a kernel panic. On some systems it can generate a lot of interrupts, causing a noticeable increase in power usage:<br />
<br />
{{hc|/etc/sysctl.d/disable_watchdog.conf|2=kernel.nmi_watchdog = 0}}<br />
<br />
or add {{ic|1=nmi_watchdog=0}} to the [[kernel parameter|kernel line]] to disable it completely from early boot.<br />
<br />
==== Writeback Time ====<br />
<br />
Increasing the virtual memory dirty writeback time helps to aggregate disk I/O together, thus reducing spanned disk writes, and increasing power saving. To set the value to 60 seconds (default is 5 seconds):<br />
<br />
{{hc|/etc/sysctl.d/dirty.conf|2=vm.dirty_writeback_centisecs = 6000}}<br />
<br />
To do the same for journal commits on supported filesystems (e.g. ext4, btrfs...), use {{ic|1=commit=60}} as a option in [[fstab]].<br />
<br />
See also [[sysctl#Virtual memory]] for other parameters affecting I/O performance and power saving.<br />
<br />
==== Laptop Mode ====<br />
<br />
See the [https://www.kernel.org/doc/Documentation/laptops/laptop-mode.txt kernel documentation] on the laptop mode 'knob.' ''"A sensible value for the knob is 5 seconds."''<br />
<br />
{{hc|/etc/sysctl.d/laptop.conf|2=vm.laptop_mode = 5}}<br />
<br />
=== Network interfaces ===<br />
<br />
[[Wikipedia:Wake-on-LAN|Wake-on-LAN]] can be a useful feature, but if you are not making use of it then it is simply draining extra power waiting for a magic packet while in suspend. Disabling for all Ethernet interfaces:<br />
<br />
{{hc|/etc/udev/rules.d/70-disable_wol.rules|2=ACTION=="add", SUBSYSTEM=="net", KERNEL=="eth*", RUN+="/usr/bin/ethtool -s %k wol d"}}<br />
<br />
To enable powersaving on all wireless interfaces:<br />
<br />
{{hc|/etc/udev/rules.d/70-wifi-powersave.rules|2=ACTION=="add", SUBSYSTEM=="net", KERNEL=="wlan*", RUN+="/usr/bin/iw dev %k set power_save on"}}<br />
<br />
In these examples, {{ic|%k}} is a specifier for the kernel name of the matched device. For example, if it finds that the rule is applicable to {{ic|wlan0}}, the {{ic|%k}} specifier will be replaced with {{ic|wlan0}}. To apply the rules to only a particular interface, just replace the pattern {{ic|eth*}} and specifier {{ic|%k}} with the desired interface name. For more information, see [http://www.reactivated.net/writing_udev_rules.html Writing udev rules].<br />
<br />
In this case, the name of the configuration file is important. Due to the introduction of [[Network configuration#Device_names|persistent device names]] via {{ic|80-net-name-slot.rules}} in systemd v197, it is important that the network powersave rules are named lexicographically before {{ic|80-net-name-slot.rules}}, so that they are applied before the devices are named e.g. {{ic|enp2s0}}.<br />
<br />
=== Bus power management ===<br />
<br />
==== Active State Power Management ====<br />
<br />
If the computer is believed not to support [[Wikipedia:Active State Power Management|ASPM]] it and will be disabled on boot:<br />
<br />
$ lspci -vv | grep ASPM.*abled\;<br />
<br />
ASPM is handled by the BIOS, if ASPM is disabled it will be because [[http://wireless.kernel.org/en/users/Documentation/ASPM ref]]:<br />
<br />
# The BIOS disabled it for some reason (for conflicts?).<br />
# PCIE requires ASPM but L0s are optional (so L0s might be disabled and only L1 enabled).<br />
# The BIOS might not have been programmed for it.<br />
# The BIOS is buggy.<br />
<br />
If believing the computer has support for ASPM it can be forced on for the kernel to handle with the {{ic|1=pcie_aspm=force}} [[kernel parameter]].<br />
<br />
{{Warning|<br />
* Forcing on ASPM can cause a freeze/panic, so make sure you have a way to undo the option if it does not work.<br />
* On systems that do not support it forcing on ASPM can even increase power consumption.<br />
}}<br />
<br />
To adjust to {{ic|powersave}} do (the following command will not work unless enabled):<br />
<br />
echo powersave | tee /sys/module/pcie_aspm/parameters/policy<br />
<br />
By default it looks like this:<br />
<br />
{{hc|$ cat /sys/module/pcie_aspm/parameters/policy|[default] performance powersave}}<br />
<br />
==== PCI Runtime Power Management ====<br />
<br />
{{hc|/etc/udev/rules.d/pci_pm.rules|2=ACTION=="add", SUBSYSTEM=="pci", ATTR{power/control}="auto"}}<br />
<br />
==== Device power management ====<br />
<br />
{{Accuracy|Mass enabling for nearly all devices has negative side effects (unwanted devices such as USB are included, worse performance of the udev rule since matching devices that enable power management by default is useless, harder troubleshooting, etc). Enabling per bus/class for the devices that need it should be recommended instead.}}<br />
<br />
Enable power management for (almost) all devices, ''including USB'':<br />
<br />
{{hc|/etc/udev/rules.d/dev_power_save.rules|<nowiki><br />
# Various subsystems runtime power management (by bus or class)<br />
ACTION=="add", SUBSYSTEMS=="*", TEST=="power/control", ATTR{power/control}="auto"<br />
<br />
# Various subsystems power saving (by module)<br />
ACTION=="add", SUBSYSTEMS=="*", TEST=="parameters/power_save", ATTR{parameters/power_save}="1" </nowiki>}}<br />
<br />
To list the various devices affected:<br />
ls /sys/bus/*/devices/*/power/control<br />
ls /sys/class/*/*/power/control<br />
ls /sys/module/*/parameters/power_save<br />
<br />
To enable power management for all systems ''except USB'', you could replace the first rule with individual rules for each subsystem instead (/sys/bus/''some_subsystem'', /sys/class/''some_subsystem''):<br />
ACTION=="add", SUBSYSTEM=="some_subsystem", TEST=="power/control", ATTR{power/control}="auto"<br />
<br />
==== USB autosuspend ====<br />
<br />
The linux kernel can automatically suspend USB devices when they are not in use. This can sometimes save quite a bit of power, however some USB devices are not compatible with USB power saving and start to misbehave (common for USB mice/keyboards). [[udev]] rules based on whitelist or blacklist filtering can help to mitigate the problem.<br />
<br />
The most simple and likely useless example is enabling autosuspend for all USB devices:<br />
<br />
{{hc|/etc/udev/rules.d/50-usb_power_save.rules|<nowiki><br />
ACTION=="add", SUBSYSTEM=="usb", TEST=="power/control", ATTR{power/control}="auto"<br />
</nowiki>}}<br />
<br />
To allow autosuspend only for devices that are known to work, use simple matching against vendor and product IDs (use ''lsusb'' to get these values):<br />
<br />
{{hc|/etc/udev/rules.d/50-usb_power_save.rules|<nowiki><br />
# whitelist for usb autosuspend<br />
ACTION=="add", SUBSYSTEM=="usb", TEST=="power/control", ATTR{idVendor}=="05c6", ATTR{idProduct}=="9205", ATTR{power/control}="auto"<br />
</nowiki>}}<br />
<br />
Alternatively, to blacklist devices that are not working with USB autosuspend and enable it for all other devices:<br />
<br />
{{hc|/etc/udev/rules.d/50-usb_power_save.rules|<nowiki><br />
# blacklist for usb autosuspend<br />
ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="05c6", ATTR{idProduct}=="9205", GOTO="power_usb_rules_end"<br />
<br />
ACTION=="add", SUBSYSTEM=="usb", TEST=="power/control", ATTR{power/control}="auto"<br />
LABEL="power_usb_rules_end"<br />
</nowiki>}}<br />
<br />
The default autosuspend idle delay time is controlled by the {{ic|autosuspend}} parameter of the {{ic|usbcore}} [[kernel module]]. To set the delay to 5 seconds instead of the default 2 seconds:<br />
<br />
{{hc|/etc/modprobe.d/usb-autosuspend.conf|<nowiki><br />
options usbcore autosuspend=5<br />
</nowiki>}}<br />
<br />
Similarly to {{ic|power/control}}, the delay time can be fine-tuned per device by setting the {{ic|power/autosuspend}} attribute.<br />
<br />
See the [https://www.kernel.org/doc/Documentation/usb/power-management.txt Linux kernel documentation] for more information on USB power management.<br />
<br />
==== SATA Active Link Power Management ====<br />
<br />
{{Note|This adds latency when accessing a drive that has been idle, so it is one of the few settings that may be worth toggling based on whether you are on AC power.}}<br />
<br />
{{hc|/etc/udev/rules.d/hd_power_save.rules|2=ACTION=="add", SUBSYSTEM=="scsi_host", KERNEL=="host*", ATTR{link_power_management_policy}="min_power"}}<br />
<br />
{{Warning|SATA Active Link Power Management can lead to data loss on some devices (e.g. Lenovo T440s [http://lkml.indiana.edu/hypermail/linux/kernel/1401.2/02171.html is known to suffer] this problem)}}<br />
<br />
=== Hard disk drive ===<br />
<br />
See [[hdparm#Power management configuration]] for drive parameters that can be set.<br />
<br />
Power saving is not effective when too many programs are frequently writing to the disk. Tracking all programs, and how and when they write to disk is the way to limit disk usage. Use {{Pkg|iotop}} to see which programs use the disk frequently. See [[Solid State Drives#Tips for minimizing disk reads/writes]] for other tips, most of them are not specific to SSDs.<br />
<br />
Also little things like setting the [[Fstab#atime options|noatime]] option can help. If enough RAM is available, consider disabling or limiting [[Swap#Swappiness|swappiness]] as it has the possibility to limit a good number of disk writes.<br />
<br />
=== CD/DVD spin down ===<br />
<br />
{{Expansion|something similar without using udisks?}}<br />
<br />
To allow the CD/DVD rom to spin down after a while using [[udisks]]:<br />
<br />
# udisks --inhibit-polling /dev/sr0<br />
<br />
== Tools and scripts ==<br />
<br />
=== Packages ===<br />
<br />
Using these tools can replace setting a lot of settings by hand. Only run '''one''' of these tools to avoid possible conflicts as they all work more or less similar. Have a look at the [[:Category:Power management|power management category]] to get an overview on what power management options exist in Archlinux.<br />
<br />
These are the more popular scripts and tools designed to help power saving:<br />
<br />
* {{App| [[acpid]] | A daemon for delivering ACPI power management events with netlink support.|http://sourceforge.net/projects/acpid2/|{{Pkg|acpid}}}}<br />
* {{App|ftw| Script to configure udev rules to save power.|https://github.com/supplantr/ftw|{{AUR|ftw-git}}}}<br />
* {{App| [[Laptop Mode Tools]]| Utility to configure laptop power saving settings, considered by many to be the de facto utility for power saving though may take a bit of configuration.|https://github.com/rickysarraf/laptop-mode-tools|{{Pkg|laptop-mode-tools}}}}<br />
* {{App| [[pm-utils]] | Suspend and powerstate setting framework (largely undeveloped now).|http://pm-utils.freedesktop.org/|{{Pkg|pm-utils}}}}<br />
* {{App| [[Powerdown]] | Scripts that combine different settings to make the computer consume less energy.|https://github.com/taylorchu/powerdown|{{Aur|powerdown-git}}}}<br />
* {{App| [[powertop]] | A tool to diagnose issues with power consumption and power management to help set power saving settings.|https://01.org/powertop/|{{Pkg|powertop}}}}<br />
* {{App| [[TLP]] | Advanced power management for Linux.|http://linrunner.de/en/tlp/docs/tlp-linux-advanced-power-management.html|{{Pkg|tlp}}}}<br />
<br />
=== Using a script and an udev rule ===<br />
<br />
Since systemd users can suspend and hibernate through {{ic|systemctl suspend}} or {{ic|systemctl hibernate}} and handle acpi events with {{ic|/etc/systemd/logind.conf}}, it might be interesting to remove [[pm-utils]] and [[acpid]]. There is just one thing systemd cannot do (as of systemd-204): power management depending on whether the system is running on AC or battery. To fill this gap, you can create a single [[udev]] rule that runs a script when the AC adapter is plugged and unplugged:<br />
<br />
{{hc|/etc/udev/rules.d/powersave.rules|2=<nowiki><br />
SUBSYSTEM=="power_supply", ATTR{online}=="0", RUN+="/path/to/your/script true"<br />
SUBSYSTEM=="power_supply", ATTR{online}=="1", RUN+="/path/to/your/script false"<br />
</nowiki>}}<br />
<br />
{{Note|You can use the same script that ''pm-powersave'' uses. You just have to make it executable and place it somewhere else (for example {{ic|/usr/local/bin/}}).}}<br />
<br />
Examples of powersave scripts can be found here: [[powerdown]], [https://github.com/Unia/powersave powersave].<br />
<br />
The above udev rule should work as expected, but if your power settings are not updated after a suspend or hibernate cycle, you should add a script in {{ic|/usr/lib/systemd/system-sleep/}} with the following contents:<br />
<br />
{{hc|/usr/lib/systemd/system-sleep/00powersave|<nowiki><br />
#!/bin/sh<br />
<br />
case $1 in<br />
pre) /path/to/your/script false ;;<br />
post) <br />
if cat /sys/class/power_supply/AC0/online | grep 0 > /dev/null 2>&1<br />
then<br />
/path/to/your/script true <br />
else<br />
/path/to/your/script false<br />
fi<br />
;;<br />
esac<br />
exit 0<br />
</nowiki>}}<br />
<br />
Do not forget to make it executable!<br />
<br />
{{Note|Be aware that AC0 may be different for your laptop, change it if that is the case.}}<br />
<br />
Now you do not need pm-utils anymore. Depending on your configuration, it may be a dependency of some other package. If you wish to remove it anyway, run {{ic|pacman -Rdd pm-utils}}.<br />
<br />
=== Print power settings ===<br />
<br />
This script prints power settings and a variety of other properties for USB and PCI devices. Note that root permissions are needed to see all settings.<br />
<br />
{{bc|<nowiki><br />
#!/bin/bash<br />
<br />
for i in $(find /sys/devices -name "bMaxPower")<br />
do<br />
busdir=${i%/*}<br />
busnum=$(<$busdir/busnum)<br />
devnum=$(<$busdir/devnum)<br />
title=$(lsusb -s $busnum:$devnum)<br />
<br />
printf "\n\n+++ %s\n -%s\n" "$title" "$busdir"<br />
<br />
for ff in $(find $busdir/power -type f ! -empty 2>/dev/null)<br />
do<br />
v=$(cat $ff 2>/dev/null|tr -d "\n")<br />
[[ ${#v} -gt 0 ]] && echo -e " ${ff##*/}=$v";<br />
v=;<br />
done | sort -g;<br />
done;<br />
<br />
printf "\n\n\n+++ %s\n" "Kernel Modules"<br />
for mod in $(lspci -k | sed -n '/in use:/s,^.*: ,,p' | sort -u)<br />
do<br />
echo "+ $mod";<br />
systool -v -m $mod 2> /dev/null | sed -n "/Parameters:/,/^$/p";<br />
done<br />
</nowiki>}}<br />
<br />
== See also ==<br />
<br />
* [http://www.thinkwiki.org/wiki/How_to_reduce_power_consumption ThinkWiki:How to reduce power consumption]<br />
* [http://forum.manjaro.org/index.php?topic=1166.0 Manjro BBS topic]<br />
* [https://wiki.ubuntu.com/Kernel/PowerManagement/PowerSavingTweaks Ubuntu Wiki's Power Saving Tweaks]</div>Pezcurrel