https://wiki.archlinux.org/api.php?action=feedcontributions&user=X33a&feedformat=atomArchWiki - User contributions [en]2024-03-29T09:38:25ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=Rxvt-unicode&diff=719554Rxvt-unicode2022-02-21T06:18:09Z<p>X33a: Add section for the urxvt-confirm-paste extension. Also, clarify how to selectively disable extensions.</p>
<hr />
<div>{{DISPLAYTITLE:rxvt-unicode}}<br />
[[Category:Terminal emulators]]<br />
[[de:urxvt]]<br />
[[fr:Rxvt-unicode]]<br />
[[ja:Rxvt-unicode]]<br />
[[ru:Rxvt-unicode]]<br />
[[zh-hans: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 configuration 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 />
=== Reload the configuration ===<br />
After changing the configuration use {{Ic|xrdb ~/.Xresources}} to reload the config. The new configuration is applied for all new terminals.<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 />
If you wish to copy into {{Ic|PRIMARY}} selection and also ensure that your {{ic|CLIPBOARD}} selection is updated with the same contents, you may add the following:<br />
<br />
URxvt.perl-ext-common: ...,selection-to-clipboard,...<br />
<br />
and<br />
<br />
URxvt.clipboard.autocopy: true<br />
URxvt.keysym.M-c: perl:clipboard:copy<br />
URxvt.keysym.M-v: perl:clipboard:paste<br />
<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 />
If you need to rename the tab, you would probably want to install {{AUR|urxvt-tabbedex}} instead.<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 [https://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 />
=== Confirm paste ===<br />
<br />
The {{ic|confirm-paste}} extension is enabled by default and it displays a confirmation dialog when a paste containing control characters is detected.<br />
<br />
It can be disabled in the following way:<br />
<br />
URxvt.perl-ext-common:-confirm-paste<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 />
To selectively disable an extension, you need to prepend a hyphen before the extension name. For example:<br />
Urxvt.perl-ext-common:-extension<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 [https://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>X33ahttps://wiki.archlinux.org/index.php?title=Xrandr&diff=632254Xrandr2020-08-17T14:20:24Z<p>X33a: /* Troubleshooting */ Potential fix for dynamic interlace patterns on AOC G2590PX</p>
<hr />
<div>{{Lowercase title}}<br />
[[Category:Xorg commands]]<br />
[[ja:Xrandr]]<br />
[[pt:Xrandr]]<br />
[[ru:Xrandr]]<br />
[[zh-hans:Xrandr]]<br />
{{Related articles start}}<br />
{{Related|Xorg}}<br />
{{Related|Multihead}}<br />
{{Related articles end}}<br />
<br />
''xrandr'' is an official configuration utility to the [[Wikipedia:RandR|RandR]] (''Resize and Rotate'') [[Wikipedia:X Window System|X Window System]] extension. It can be used to set the size, orientation or reflection of the outputs for a screen. For configuring multiple monitors see the [[Multihead]] page.<br />
<br />
== Installation ==<br />
<br />
[[Install]] {{Pkg|xorg-xrandr}}.<br />
<br />
=== Graphical front-ends ===<br />
<br />
* {{App|ARandR|Provide a simple visual front end for XRandR. Relative monitor positions are shown graphically and can be changed in a drag-and-drop way.|https://christian.amsuess.com/tools/arandr/|{{Pkg|arandr}}}}<br />
* {{App|LXRandR|Screen resolution and external monitors management tool for LXDE.|https://wiki.lxde.org/en/LXRandR|GTK 2: {{Pkg|lxrandr}}, GTK 3: {{Pkg|lxrandr-gtk3}}}}<br />
<br />
=== CLI front-ends ===<br />
<br />
* {{App|xlayoutdisplay|Detects and arranges displays. Handles: laptop lid state, highest available refresh rates, calculating and applying the actual DPI. Best used in .xinitrc, then can be invoked when plugging/unplugging monitors or closing laptop lid.|https://github.com/alex-courtis/xlayoutdisplay|{{AUR|xlayoutdisplay}}}}<br />
<br />
== Testing configuration ==<br />
<br />
When run without any option, ''xrandr'' shows the names of different outputs available on the system ({{ic|VGA-1}}, {{ic|HDMI-1}}, etc.) and resolutions available on each, with a '''*''' after the current one and a '''+''' after the preferred one :<br />
<br />
{{hc|xrandr|<br />
Screen 0: minimum 320 x 200, current 3200 x 1080, maximum 8192 x 8192<br />
VGA-1 disconnected (normal left inverted right x axis y axis)<br />
HDMI-1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 531mm x 299mm<br />
1920x1080 59.93 + 60.00* 50.00 59.94 <br />
1920x1080i 60.00 50.00 59.94 <br />
1680x1050 59.88 <br />
…<br />
}}<br />
{{Note|If your resolution is not present in the above list, see [[#Adding undetected resolutions]]}}<br />
<br />
You can use ''xrandr'' to set different resolution (must be present in the above list) on some output:<br />
<br />
$ xrandr --output HDMI-1 --mode 1920x1080<br />
<br />
When multiple refresh rates are present in the list, it may be changed by the {{ic|--rate}} option, either at the same time or independently. For example:<br />
<br />
$ xrandr --output HDMI-1 --mode 1920x1080 --rate 60<br />
<br />
The {{ic|--auto}} option will turn the specified output on if it is off and set the preferred (maximum) resolution:<br />
<br />
$ xrandr --output HDMI-1 --auto<br />
<br />
It is possible to specify multiple outputs in one command, e.g. to turn off {{ic|HDMI-1}} and turn on {{ic|HDMI-2}} with preferred resolution:<br />
<br />
$ xrandr --output HDMI-1 --off --output HDMI-2 --auto<br />
<br />
{{Note|<br />
* Changes you make using ''xrandr'' will only last through the current session.<br />
* ''xrandr'' has a lot more capabilities - see {{man|1|xrandr}} for details.<br />
}}<br />
<br />
== Configuration ==<br />
<br />
''xrandr'' is just a simple interface to the RandR extension and has no configuration file. However, there are multiple ways of achieving persistent configuration:<br />
<br />
# The RandR extension can be configured via [[Xorg#Configuration|X configuration files]], see [[Multihead#RandR]] for details. This method provides only static configuration.<br />
# If you need dynamic configuration, you need to execute ''xrandr'' commands each time X server starts. See [[Autostarting#On Xorg startup]] for details. This method has the disadvantage of occurring fairly late in the startup process, thus it will not alter the resolution of the [[display manager]] if you use one.<br />
# Custom scripts calling ''xrandr'' can be bound to events (for example when external monitor is plugged in), see [[udev]] or [[acpid]] for details. The [[#Scripts]] section provides you with some example scripts that might be useful for this purpose.<br />
<br />
{{Tip|Both KDM and GDM have startup scripts that are executed when X is initiated. For GDM, these are in {{ic|/etc/gdm/}}, while for KDM this is done at {{ic|/usr/share/config/kdm/Xsetup}} and for SDDM at {{ic|/usr/share/sddm/scripts/Xsetup}}. This method requires root access and mucking around in system config files, but will take effect earlier in the startup process than using xprofile.}}<br />
<br />
=== Scripts ===<br />
<br />
==== Toggle external monitor ====<br />
<br />
This script toggles between an external monitor (specified by {{ic|$extern}}) and a default monitor (specified by {{ic|$intern}}), so that only one monitor is active at a time.<br />
<br />
The default monitor should be connected when running the script, which is always true for a laptop.<br />
<br />
{{bc|<nowiki><br />
#!/bin/bash<br />
intern=LVDS1<br />
extern=VGA1<br />
<br />
if xrandr | grep "$extern disconnected"; then<br />
xrandr --output "$extern" --off --output "$intern" --auto<br />
else<br />
xrandr --output "$intern" --off --output "$extern" --auto<br />
fi<br />
</nowiki>}}<br />
<br />
{{Note|To leave the default monitor enabled when an external monitor is connected, replace the ''else'' clause with {{ic|xrandr --output "$intern" --primary --auto --output "$extern" --right-of "$intern" --auto}}.}}<br />
<br />
==== Automatically switch configurations with autorandr ====<br />
<br />
{{Pkg|autorandr}} allows you to easily configure xrandr "profiles" that will activate automatically when you connect/disconnect displays. Autorandr is automatically executed everytime a monitor is plugged in or unplugged thanks to a udev hook. See the [https://github.com/phillipberndt/autorandr homepage] for usage examples.<br />
<br />
==== Manage 2-monitors ====<br />
<br />
{{AUR|mons}} is a POSIX-compliant shell script to quickly manage 2-monitors display.<br />
<br />
It provides well-known modes like computer, duplicate, extend and projector mode as well as selecting and positioning one or two monitors among those plugged in (for more details, see [https://github.com/Ventto/mons mons]).<br />
<br />
==== Example 3 ====<br />
<br />
{{Accuracy|1=Basic shell mistakes: relying on quoting errors to relay arguments (instead of using arrays), convoluted grep+sed pipes (instead of awk), echo -e (instead of printf), ancient backtick format (instead of {{ic|$()}})}}<br />
<br />
This script iterates through connected monitors, selects currently active monitor, turns next one on and the others off:<br />
<br />
{{bc|<nowiki><br />
# get info from xrandr<br />
connectedOutputs=$(xrandr | grep " connected" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/")<br />
activeOutput=$(xrandr | grep -E " connected (primary )?[1-9]+" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/")<br />
<br />
# initialize variables<br />
execute="xrandr "<br />
default="xrandr "<br />
i=1<br />
switch=0<br />
<br />
for display in $connectedOutputs<br />
do<br />
# build default configuration<br />
if [ $i -eq 1 ]<br />
then<br />
default=$default"--output $display --auto "<br />
else<br />
default=$default"--output $display --off "<br />
fi<br />
<br />
# build "switching" configuration<br />
if [ $switch -eq 1 ]<br />
then<br />
execute=$execute"--output $display --auto "<br />
switch=0<br />
else<br />
execute=$execute"--output $display --off "<br />
fi<br />
<br />
# check whether the next output should be switched on<br />
if [ $display = $activeOutput ]<br />
then<br />
switch=1<br />
fi<br />
<br />
i=$(( $i + 1 ))<br />
done<br />
<br />
# check if the default setup needs to be executed then run it<br />
echo "Resulting Configuration:"<br />
if [ -z "$(echo $execute | grep "auto")" ]<br />
then<br />
echo "Command: $default"<br />
`$default`<br />
else<br />
echo "Command: $execute"<br />
`$execute`<br />
fi<br />
echo -e "\n$(xrandr)"<br />
</nowiki>}}<br />
<br />
==== Avoid X crash with xrasengan ====<br />
<br />
Use this workaround to turn on connected outputs that may be in suspend mode and hence shown as disconnected, as is often the case of DisplayPort monitors:<br />
<br />
{{bc|<nowiki><br />
declare -i count=2<br />
declare -i seconds=1<br />
<br />
while ((count)); do<br />
xrandr >/dev/null<br />
sleep $seconds<br />
((count--))<br />
done<br />
</nowiki>}}<br />
<br />
{{AUR|xrasengan}} is an xrandr wrapper with this workaround built in.<br />
<br />
$ xrasengan --force -on DisplayPort-0 -off HDMI-0<br />
<br />
With the {{ic|--force}} option, ''xrasengan'' will update status of all outputs before HDMI-0 is turned off, avoiding an X crash if they were the only connected/active outputs.<br />
<br />
To force reload current settings, ''xrasengan'' provides a {{ic|--try-reload-active-layout}} option, which uses {{ic|--force}} and ''unxrandr'' from the {{Pkg|arandr}} package to assemble the command line:<br />
<br />
$ xrasengan --try-reload-active-layout<br />
<br />
This can be used in systemd unit or in a keyboard binding to avoid blank screen when resuming DisplayPort monitors from suspend.<br />
<br />
=== Configuration using arandr ===<br />
<br />
arandr can graphically arrange your monitors, change resolutions, and save a script to duplicate your setup. By default, if you "Save As" it will be saved in {{ic|~/.screenlayout/}}. These files can then be added to your {{ic|~/.profile}}. Sometimes problems arise from running the arandr script too soon after login.<br />
<br />
{{Accuracy|Graphical things don't belong into {{ic|~/.profile}}.}}<br />
<br />
Edit {{ic|~/.profile}}<br />
<br />
$ sleep 3<br />
$ /home/<user>/.screenlayout/myLayout.sh<br />
<br />
== Troubleshooting ==<br />
<br />
=== Adding undetected resolutions ===<br />
<br />
Due to buggy hardware or drivers, your monitor's correct resolutions may not always be detected by xrandr. For example, the EDID data block queried from the monitor may be incorrect. However, we can add the desired resolutions to xrandr. Also, this same procedure can be used to add refresh rates you know are supported, but not enabled by your driver.<br />
<br />
First we run {{ic|gtf}} or {{ic|cvt}} to get the '''Modeline''' for the resolution we want:<br />
<br />
{{hc|$ cvt 1280 1024|<br />
# 1280x1024 59.89 Hz (CVT 1.31M4) hsync: 63.67 kHz; pclk: 109.00 MHz<br />
Modeline "1280x1024_60.00" 109.00 1280 1368 1496 1712 1024 1027 1034 1063 -hsync +vsync<br />
}}<br />
<br />
{{Tip|1=For some LCD screens (e.g. Samsung 2343NW, Acer XB280HK), the command {{ic|cvt -r}} (= with reduced blanking) is to be used.}}<br />
<br />
{{Tip|1=If you find that the screen goes blank when the modeline is applied, try lower refresh rate (e.g. 30 or 45 instead of 60). The refresh rate should be passed as the third argument: {{ic|cvt 2560 1440 45}}}}<br />
<br />
{{Note|If the Intel video driver {{pkg|xf86-video-intel}} is used, it may report the desired resolution along with its properties in {{ic|/var/log/Xorg.0.log}} — use that first if it is different from the output of {{ic|gtf}} or {{ic|cvt}}. For instance, the log and its use with xrandr:<br />
[ 45.063] (II) intel(0): clock: 241.5 MHz Image Size: 597 x 336 mm<br />
[ 45.063] (II) intel(0): h_active: 2560 h_sync: 2600 h_sync_end 2632 h_blank_end 2720 h_border: 0<br />
[ 45.063] (II) intel(0): v_active: 1440 v_sync: 1443 v_sync_end 1448 v_blanking: 1481 v_border: 0<br />
<br />
xrandr --newmode "2560x1440" 241.50 2560 2600 2632 2720 1440 1443 1448 1481 -hsync +vsync<br />
<br />
You may also find similar lines for the modesetting driver.<br />
}}<br />
<br />
Then we create a new xrandr mode. Note that the Modeline keyword needs to be omitted.<br />
<br />
$ xrandr --newmode "1280x1024_60.00" 109.00 1280 1368 1496 1712 1024 1027 1034 1063 -hsync +vsync<br />
<br />
{{Tip|1=Some programs have trouble recognizing modes labeled with "_60.00" see [https://forums.linuxmint.com/viewtopic.php?t=211173] }}<br />
<br />
After creating it we need an extra step to add this new mode to our current output (VGA1). We use just the name of the mode, since the parameters have been set previously.<br />
<br />
$ xrandr --addmode VGA1 1280x1024_60.00<br />
<br />
Now we change the resolution of the screen to the one we just added:<br />
<br />
$ xrandr --output VGA1 --mode 1280x1024_60.00<br />
<br />
Note that these settings only take effect during this session. <br />
<br />
If you are not sure about the resolution you will test, you may add a {{ic|sleep 5}} and a safe resolution command line following, like this:<br />
<br />
$ xrandr --output VGA1 --mode 1280x1024_60.00 && sleep 5 && xrandr --newmode "1024x768-safe" 65.00 1024 1048 1184 1344 768 771 777 806 -HSync -VSync && xrandr --addmode VGA1 1024x768-safe && xrandr --output VGA1 --mode 1024x768-safe<br />
<br />
Also, change {{ic|VGA1}} to correct output name.<br />
<br />
==== EDID checksum is invalid ====<br />
<br />
If the previous method results in an {{ic|*ERROR* EDID checksum is invalid}} error during boot, see [[KMS#Forcing modes and EDID]] and [https://askubuntu.com/questions/201081/how-can-i-make-linux-behave-better-when-edid-is-unavailable].<br />
<br />
Or {{ic|xrandr --addmode}} might give you the error {{ic|X Error of failed request: BadMatch}}. NVIDIA users should read [[NVIDIA/Troubleshooting#xrandr BadMatch]]. {{ic|BadMatch}} could indicate an invalid EDID checksum. To verify that this is the case, run X in verbose mode (e.g. {{ic|startx -- -logverbose 6}}) and check your Xorg log for messages about a bad EDID.<br />
<br />
==== Screen resolution reverts back after a blink ====<br />
<br />
If you use [[GNOME]] and your monitor does not have an EDID, above [[#Adding undetected resolutions]] might not work, with your screen just blinking once, after {{ic|xrandr --output}}.<br />
<br />
Poke around with {{ic|~/.config/monitors.xml}}, or delete the file completely, and then reboot.<br />
<br />
It is better explained in [https://unix.stackexchange.com/questions/184941/gnome-prevents-high-resolution-vga-without-edid-info-over-vga this] article.<br />
<br />
=== Permanently adding undetected resolutions ===<br />
<br />
Once a suitable resolution is found using {{ic|xrandr}}, the mode can be permanently added by creating an entry in {{ic|/etc/X11/xorg.conf.d/}}:<br />
<br />
{{hc|/etc/X11/xorg.conf.d/10-monitor.conf|<br />
Section "Monitor"<br />
Identifier "VGA1"<br />
Modeline "1280x1024_60.00" 109.00 1280 1368 1496 1712 1024 1027 1034 1063 -hsync +vsync<br />
Option "PreferredMode" "1280x1024_60.00"<br />
EndSection<br />
<br />
Section "Screen"<br />
Identifier "Screen0"<br />
Monitor "VGA1"<br />
DefaultDepth 24<br />
SubSection "Display"<br />
Modes "1280x1024_60.00"<br />
EndSubSection<br />
EndSection<br />
<br />
Section "Device"<br />
Identifier "Device0"<br />
Driver "intel"<br />
EndSection}}<br />
<br />
Replace {{ic|intel}} with the right driver, e.g. {{ic|nvidia}}. When the X server is restarted, you should be able to set the new resolution.<br />
<br />
If this does not work for you, try removing the Screen and Device sections and just leaving the Monitor section. [https://bbs.archlinux.org/viewtopic.php?id=225134]<br />
<br />
=== Resolution lower than expected ===<br />
<br />
{{Tip|Try [[#Adding undetected resolutions]] first, if it does not work, you may try this method.}}<br />
<br />
If your video card is recognized but the resolution is lower than you expect, you may try this.<br />
<br />
Background: ATI X1550 based video card and two LCD monitors DELL 2408(up to 1920x1200) and Samsung 206BW(up to 1680x1050). Upon first login after installation, the resolution default to 1152x864. xrandr does not list any resolution higher than 1152x864. You may want to try editing /etc/X11/xorg.conf, add a section about virtual screen, logout, login and see if this helps. If not then read on.<br />
<br />
Change xorg.conf<br />
{{hc|/etc/X11/xorg.conf|<br />
Section "Screen"<br />
...<br />
SubSection "Display"<br />
Virtual 3600 1200<br />
EndSubSection<br />
EndSection<br />
}}<br />
<br />
About the numbers: DELL on the left and Samsung on the right. So the virtual width is of sum of both LCD width 3600=1920+1680; Height then is figured as the max of them, which is max(1200,1050)=1200. If you put one LCD above the other, use this calculation instead: (max(width1, width2), height1+height2).<br />
<br />
=== Correction of overscan tv resolutions via the underscan property ===<br />
<br />
With a flat panel TV, [[w:overscan]] looks like the picture is "zoomed in" so the edges are cut off.<br />
<br />
Check your TV if there is a parameter to change. If not check if the output has support for the underscan property (xrandr --prop), if so apply an {{ic|underscan}} and change border values. <br />
The required {{ic|underscan vborder}} and {{ic|underscan hborder}} values can be different for you, just check it and change it by more or less.<br />
<br />
$ xrandr --output HDMI-0 --set underscan on --set "underscan vborder" 25 --set "underscan hborder" 40<br />
<br />
=== Correction of overscan tv resolutions via --transform ===<br />
<br />
If underscan is not available another solution is using {{ic|xrandr --transform ''a,b,c,d,e,f,g,h,i''}}, which applies a transformation matrix on the output. See the {{man|1|xrandr|RandR_version_1.3_options}} manual page for the explanation of the transformation.<br />
<br />
For example, the transformation scaling horizontal coordinates by {{ic|0.8}}, vertical coordinates by {{ic|1.04}} and moving the screen by 35 pixels right and 19 pixels down, is:<br />
<br />
$ xrandr --output HDMI1 --transform 0.80,0,-35,0,1.04,-19,0,0,1<br />
<br />
=== Full RGB in HDMI ===<br />
<br />
It may occur that the [[Intel]] driver will not configure correctly the output of the HDMI monitor. It will set a limited color range (16-235) using the [https://patchwork.kernel.org/patch/1972181/ Broadcast RGB property], and the black will not look black, it will be grey.<br />
<br />
See [[Intel graphics#Weathered colors (color range problems)]].<br />
<br />
=== Disabling phantom monitor ===<br />
<br />
In some cases, a non-existent monitor may be detected by the system. To disable it, find the name of the phantom output, e.g. VGA1, and turn it off with<br />
<br />
$ xrandr --output VGA1 --off<br />
<br />
To make this permanent, add the following to an entry in {{ic|/etc/X11/xorg.conf.d/}}:<br />
<br />
{{hc|/etc/X11/xorg.conf.d/10-monitor.conf|<br />
Section "Monitor"<br />
Identifier "VGA1"<br />
Option "Ignore" "true"<br />
EndSection}}<br />
<br />
=== Dynamic interlace pattern artifacts with AOC G2590PX ===<br />
<br />
If you are seeing very prominent [https://web.archive.org/web/20190102230349/https://pcmonitors.info/reviews/aoc-g2590px/#Interlace_pattern_artifacts interlace pattern artifacts] (mesh or grid) when you see movement on the screen with this monitor, it might be happening because of a low refresh rate. Switching to a higher refresh rate (from 60 Hz to 119.98 Hz and perhaps even higher) might help reduce the effect.<br />
<br />
Sample xrandr output for this monitor over HDMI:<br />
HDMI-1 connected 1920x1080+0+0 (normal left inverted right x axis y axis) 544mm x 303mm<br />
1920x1080 60.00 + 119.98* 99.93 50.00 59.94<br />
<br />
As can be seen in the output above, the preferred refresh rate reported by xrandr is 60.00, but the artifacts are very visible with this refresh rate. Switching to 119.98 should help reduce the effect considerably.<br />
<br />
$ xrandr --output HDMI-1 --mode 1920x1080 --rate 119.98<br />
<br />
== See also ==<br />
* https://wiki.ubuntu.com/X/Config/Resolution<br />
* [[debian:XStrikeForce/HowToRandR12|Debian Wiki - RandR 1.2 tutorial]]<br />
* [http://www.thinkwiki.org/wiki/Xorg_RandR_1.2 Xorg RandR 1.2 on ThinkWiki]<br />
* [http://www.x.org/wiki/FAQVideoModes#ObtainingmodelinesfromWindowsprogramPowerStrip FAQVideoModes - more information about modelines]</div>X33ahttps://wiki.archlinux.org/index.php?title=CPU_frequency_scaling&diff=574145CPU frequency scaling2019-05-27T18:06:57Z<p>X33a: /* Disabling Turbo Boost */ Change codeblock style</p>
<hr />
<div>[[Category:Power management]]<br />
[[Category:CPU]]<br />
[[ar:CPU frequency scaling]]<br />
[[cs:CPU frequency scaling]]<br />
[[de:Cpufrequtils]]<br />
[[el:CPU frequency scaling]]<br />
[[es:CPU frequency scaling]]<br />
[[fr:Cpufreq]]<br />
[[it:CPU frequency scaling]]<br />
[[ja:CPU 周波数スケーリング]]<br />
[[pt:CPU frequency scaling]]<br />
[[ru:CPU frequency scaling]]<br />
[[sk:CPU frequency scaling]]<br />
[[zh-hans:CPU frequency scaling]]<br />
{{Related articles start}}<br />
{{Related|Power saving}}<br />
{{Related|Laptop Mode Tools}}<br />
{{Related|PHC}}<br />
{{Related articles end}}<br />
<br />
CPU frequency scaling enables the operating system to scale the CPU frequency up or down in order to save power. CPU frequencies can be scaled automatically depending on the system load, in response to ACPI events, or manually by userspace programs.<br />
<br />
CPU frequency scaling is implemented in the Linux kernel, the infrastructure is called ''cpufreq''. Since kernel 3.4 the necessary modules are loaded automatically and the recommended [[#Scaling governors|ondemand governor]] is enabled by default. However, userspace tools like [[#cpupower|cpupower]], [[acpid]], [[Laptop Mode Tools]], or GUI tools provided for your desktop environment, may still be used for advanced configuration.<br />
<br />
== Userspace tools ==<br />
<br />
=== thermald ===<br />
<br />
{{AUR|thermald}} is a Linux daemon used to prevent the overheating of platforms. This daemon monitors temperature and applies compensation using available cooling methods.<br />
<br />
By default, it monitors CPU temperature using available CPU digital temperature sensors and maintains CPU temperature under control, before HW takes aggressive correction action. If there is a skin temperature sensor in thermal sysfs, then it tries to keep skin temperature under 45C.<br />
<br />
The associated systemd unit is {{ic|thermald.service}}, which should be [[start]]ed and [[enable]]d.<br />
<br />
=== i7z ===<br />
<br />
{{Pkg|i7z}} is an i7 (and now i3, i5) CPU reporting tool for Linux. It can be launched from a Terminal with the command {{ic|i7z}} or as GUI with {{ic|i7z-gui}}.<br />
<br />
=== cpupower ===<br />
<br />
{{Pkg|cpupower}} is a set of userspace utilities designed to assist with CPU frequency scaling. The package is not required to use scaling, but is highly recommended because it provides useful command-line utilities and a [[systemd]] service to change the governor at boot.<br />
<br />
The configuration file for ''cpupower'' is located in {{ic|/etc/default/cpupower}}. This configuration file is read by a bash script in {{ic|/usr/lib/systemd/scripts/cpupower}} which is activated by ''systemd'' with {{ic|cpupower.service}}. You may want to [[enable]] {{ic|cpupower.service}} to start at boot.<br />
<br />
== CPU frequency driver ==<br />
<br />
{{Note|<br />
* The native CPU module is loaded automatically.<br />
* The {{ic|pstate}} power scaling driver is used automatically for modern Intel CPUs instead of the other drivers below. This driver takes priority over other drivers and is built-in as opposed to being a module. This driver is currently automatically used for Sandy Bridge and newer CPUs. If you encounter a problem while using this driver, add {{ic|1=intel_pstate=disable}} to your kernel line. You can use the same user space utilities with this driver, '''but cannot control it'''.<br />
* Even P State behavior mentioned above can be influenced with {{ic|/sys/devices/system/cpu/intel_pstate}}, e.g. Intel Turbo Boost can be deactivated with {{ic|# echo 1 > /sys/devices/system/cpu/intel_pstate/no_turbo}} for keeping CPU-Temperatures low.<br />
* Additional control for modern Intel CPUs is available with the [https://01.org/linux-thermal-daemon Linux Thermal Daemon] (available as {{AUR|thermald}}), which proactively controls thermal using P-states, T-states, and the Intel power clamp driver. thermald can also be used for older Intel CPUs. If the latest drivers are not available, then the daemon will revert to x86 model specific registers and the Linux ‘cpufreq subsystem’ to control system cooling.<br />
}}<br />
<br />
''cpupower'' requires modules to know the limits of the native CPU:<br />
<br />
{| class="wikitable sortable"<br />
!Module!!Description<br />
|-<br />
| intel_pstate || This driver implements a scaling driver with an internal governor for Intel Core (Sandy Bridge and newer) processors.<br />
|-<br />
| acpi-cpufreq || CPUFreq driver which utilizes the ACPI Processor Performance States. This driver also supports the Intel Enhanced SpeedStep (previously supported by the deprecated speedstep-centrino module).<br />
|-<br />
| speedstep-lib || CPUFreq driver for Intel SpeedStep-enabled processors (mostly Atoms and older Pentiums (before III)) <br />
|-<br />
| powernow-k8 || CPUFreq driver for K8/K10 Athlon 64/Opteron/Phenom processors. Since Linux 3.7 'acpi-cpufreq' will automatically be used for more modern CPUs from this family.<br />
|-<br />
| pcc-cpufreq || This driver supports Processor Clocking Control interface by Hewlett-Packard and Microsoft Corporation which is useful on some ProLiant servers.<br />
|-<br />
| p4-clockmod || CPUFreq driver for Intel Pentium 4/Xeon/Celeron processors which lowers the CPU temperature by skipping clocks. (You probably want to use a SpeedStep driver instead.)<br />
|}<br />
<br />
To see a full list of available modules, run:<br />
<br />
$ ls /usr/lib/modules/$(uname -r)/kernel/drivers/cpufreq/<br />
<br />
Load the appropriate module (see [[Kernel modules]] for details). Once the appropriate cpufreq driver is loaded, detailed information about the CPU(s) can be displayed by running<br />
<br />
$ cpupower frequency-info<br />
<br />
=== Setting maximum and minimum frequencies ===<br />
<br />
In rare cases, it may be necessary to manually set maximum and minimum frequencies.<br />
<br />
To set the maximum clock frequency ({{ic|''clock_freq''}} is a clock frequency with units: GHz, MHz):<br />
<br />
# cpupower frequency-set -u ''clock_freq''<br />
<br />
To set the minimum clock frequency:<br />
<br />
# cpupower frequency-set -d ''clock_freq''<br />
<br />
To set the CPU to run at a specified frequency:<br />
<br />
# cpupower frequency-set -f ''clock_freq''<br />
<br />
{{Note|<br />
* To adjust for only a single CPU core, append {{ic|-c ''core_number''}}.<br />
* The governor, maximum and minimum frequencies can be set in {{ic|/etc/default/cpupower}}.<br />
}}<br />
<br />
=== Disabling Turbo Boost ===<br />
==== intel_pstate ====<br />
<br />
# echo 1 > /sys/devices/system/cpu/intel_pstate/no_turbo<br />
<br />
==== acpi-cpufreq ====<br />
<br />
# echo 0 > /sys/devices/system/cpu/cpufreq/boost<br />
<br />
== Scaling governors ==<br />
<br />
Governors (see table below) are power schemes for the CPU. Only one may be active at a time. For details, see the [https://www.kernel.org/doc/Documentation/cpu-freq/governors.txt kernel documentation] in the kernel source.<br />
<br />
{| class="wikitable"<br />
! Governor !! Description<br />
|-<br />
| performance || Run the CPU at the maximum frequency.<br />
|-<br />
| powersave || Run the CPU at the minimum frequency.<br />
|-<br />
| userspace || Run the CPU at user specified frequencies.<br />
|-<br />
| ondemand || Scales the frequency dynamically according to current load. Jumps to the highest frequency and then possibly back off as the idle time increases.<br />
|-<br />
| conservative || Scales the frequency dynamically according to current load. Scales the frequency more gradually than ondemand.<br />
|-<br />
| schedutil || Scheduler-driven CPU frequency selection [http://lwn.net/Articles/682391/], [https://lkml.org/lkml/2016/3/17/420].<br />
|}<br />
<br />
Depending on the scaling driver, one of these governors will be loaded by default:<br />
<br />
* {{ic|ondemand}} for AMD and older Intel CPU.<br />
* {{ic|powersave}} for Intel CPUs using the {{ic|intel_pstate}} driver (Sandy Bridge and newer).<br />
<br />
{{Note|1=The {{ic|intel_pstate}} driver supports only the performance and powersave governors, but they both provide dynamic scaling. The performance governor [http://www.phoronix.com/scan.php?page=news_item&px=MTM3NDQ should give better power saving functionality than the old ondemand governor].}}<br />
<br />
{{Warning|Use CPU monitoring tools (for temperatures, voltage, etc.) when changing the default governor.}} <br />
<br />
To activate a particular governor, run:<br />
<br />
# cpupower frequency-set -g ''governor''<br />
<br />
{{Note|<br />
* To adjust for only a single CPU core, append {{ic|-c ''core_number''}} to the command above.<br />
* Activating a governor requires that specific [[kernel module]] (named {{ic|cpufreq_''governor''}}) is loaded. As of kernel 3.4, these modules are loaded automatically.<br />
}}<br />
<br />
Alternatively, you can activate a governor on every available CPU manually:<br />
<br />
# echo ''governor'' > /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor<br />
<br />
where {{ic|''governor''}} is the name of the governor, mentioned in the above table, that you want to activate.<br />
<br />
{{Tip|To monitor cpu speed in real time, run:<br />
<br />
$ watch grep \"cpu MHz\" /proc/cpuinfo<br />
<br />
}}<br />
<br />
=== Tuning the ondemand governor ===<br />
<br />
See the [https://www.kernel.org/doc/Documentation/cpu-freq/governors.txt kernel documentation] for details.<br />
<br />
==== Switching threshold ====<br />
<br />
To set the threshold for stepping up to another frequency:<br />
<br />
# echo -n ''percent'' > /sys/devices/system/cpu/cpufreq/<governor>/up_threshold<br />
<br />
To set the threshold for stepping down to another frequency:<br />
<br />
# echo -n ''percent'' > /sys/devices/system/cpu/cpufreq/<governor>/down_threshold<br />
<br />
==== Sampling rate ====<br />
<br />
The sampling rate determines how frequently the governor checks to tune the CPU. {{ic|sampling_down_factor}} is a tunable that multiplies the sampling rate when the CPU is at its highest clock frequency thereby delaying load evaluation and improving performance. Allowed values for {{ic|sampling_down_factor}} are 1 to 100000. This tunable has no effect on behavior at lower CPU frequencies/loads.<br />
<br />
To read the value (default = 1), run:<br />
<br />
$ cat /sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor<br />
<br />
To set the value, run:<br />
<br />
# echo -n ''value'' > /sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor<br />
<br />
==== Make changes permanent ====<br />
<br />
To have the desired scaling enabled at boot, [[Kernel modules#Using files in /etc/modprobe.d/|kernel module options]] and [[systemd#Temporary files]] are regular methods. <br />
<br />
For example, changing the up_threshold to 10:<br />
{{hc|/etc/tmpfiles.d/ondemand.conf|2=<br />
w- /sys/devices/system/cpu/cpufreq/ondemand/up_threshold - - - - 10<br />
}}<br />
<br />
However, in some cases race conditions, as noted in [[systemd#Temporary files]] may exist and one can use [[udev]] to avoid them.<br />
<br />
For example, to set the scaling governor of the CPU core {{ic|0}} to performance while the scaling driver is {{ic|acpi_cpufreq}}, create the following udev rule:<br />
<br />
{{hc|/etc/udev/rules.d/50-scaling-governor.rules|2=<br />
SUBSYSTEM=="module", ACTION=="add", KERNEL=="acpi_cpufreq", RUN+="/bin/sh -c 'echo performance > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor'"<br />
}}<br />
<br />
To have the rule already applied in the ''initramfs'', follow the example at [[udev#Debug output]].<br />
<br />
{{Tip|Alternatively, configure the [[#cpupower|cpupower]] utility and enable its systemd service.}}<br />
<br />
== Interaction with ACPI events ==<br />
<br />
Users may configure scaling governors to switch automatically based on different ACPI events such as connecting the AC adapter or closing a laptop lid. A quick example is given below, however it may be worth reading full article on [[acpid]].<br />
<br />
Events are defined in {{ic|/etc/acpi/handler.sh}}. If the {{Pkg|acpid}} package is installed, the file should already exist and be executable. For example, to change the scaling governor from {{ic|performance}} to {{ic|conservative}} when the AC adapter is disconnected and change it back if reconnected:<br />
<br />
{{hc|/etc/acpi/handler.sh|<nowiki><br />
[...]<br />
<br />
ac_adapter)<br />
case "$2" in<br />
AC*)<br />
case "$4" in<br />
00000000)<br />
echo "conservative" >/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor <br />
echo -n $minspeed >$setspeed<br />
#/etc/laptop-mode/laptop-mode start<br />
;;<br />
00000001)<br />
echo "performance" >/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor<br />
echo -n $maxspeed >$setspeed<br />
#/etc/laptop-mode/laptop-mode stop<br />
;;<br />
esac<br />
;;<br />
*) logger "ACPI action undefined: $2" ;;<br />
esac<br />
;;<br />
<br />
[...]<br />
</nowiki>}}<br />
<br />
== Privilege granting under GNOME ==<br />
<br />
{{Out of date|See the note below.}}<br />
<br />
{{Note|systemd introduced logind which handles consolekit and policykit actions. The following code below does not work. With logind, simply edit in the file {{ic|/usr/share/polkit-1/actions/org.gnome.cpufreqselector.policy}} the <defaults> elements according to your needs and the polkit manual [http://www.freedesktop.org/software/polkit/docs/latest/polkit.8.html].}}<br />
<br />
[[GNOME]] has a nice applet to change the governor on the fly. To use it without the need to enter the root password, simply create following file:<br />
<br />
{{hc|/var/lib/polkit-1/localauthority/50-local.d/org.gnome.cpufreqselector.pkla|2=<br />
[org.gnome.cpufreqselector]<br />
Identity=unix-user:''user''<br />
Action=org.gnome.cpufreqselector<br />
ResultAny=no<br />
ResultInactive=no<br />
ResultActive=yes<br />
}}<br />
<br />
Where the word ''user'' is replaced with the username of interest.<br />
<br />
The {{AUR|desktop-privileges}} package in the [[AUR]] contains a similar {{ic|.pkla}} file for authorizing all users of the {{ic|power}} [[user group]] to change the governor.<br />
<br />
== Troubleshooting ==<br />
<br />
{{Accuracy|Unverifiable and vague statements, lots of "some"s and "maybe"s. Troubleshooting items need to address concrete problems.}}<br />
<br />
* Some applications, like [[ntop]], do not respond well to automatic frequency scaling. In the case of ntop it can result in segmentation faults and lots of lost information as even the {{ic|on-demand}} governor cannot change the frequency quickly enough when a lot of packets suddenly arrive at the monitored network interface that cannot be handled by the current processor speed.<br />
<br />
* Some CPU's may suffer from poor performance with the default settings of the {{ic|on-demand}} governor (e.g. flash videos not playing smoothly or stuttering window animations). Instead of completely disabling frequency scaling to resolve these issues, the aggressiveness of frequency scaling can be increased by lowering the ''up_threshold'' [[sysctl]] variable for each CPU. See [[#Switching_threshold|how to change the on-demand governor's threshold]].<br />
<br />
* Sometimes the on-demand governor may not throttle to the maximum frequency but one step below. This can be solved by setting max_freq value slightly higher than the real maximum. For example, if frequency range of the CPU is from 2.00 GHz to 3.00 GHz, setting max_freq to 3.01 GHz can be a good idea.<br />
<br />
* Some combinations of [[ALSA]] drivers and sound chips may cause audio skipping as the governor changes between frequencies, switching back to a non-changing governor seems to stop the audio skipping.<br />
<br />
=== BIOS frequency limitation ===<br />
<br />
Some CPU/BIOS configurations may have difficulties to scale to the maximum frequency or scale to higher frequencies at all. This is most likely caused by BIOS events telling the OS to limit the frequency resulting in {{ic|/sys/devices/system/cpu/cpu0/cpufreq/bios_limit}} set to a lower value.<br />
<br />
Either you just made a specific Setting in the BIOS Setup Utility, (Frequency, Thermal Management, etc.) you can blame a buggy/outdated BIOS or the BIOS might have a serious reason for throttling the CPU on it's own.<br />
<br />
Reasons like that can be (assuming your machine's a notebook) that the battery is removed (or near death) so you're on AC-power only. In this case a weak AC-source might not supply enough electricity to fulfill extreme peak demands by the overall system and as there is no battery to assist this could lead to data loss, data corruption or in worst case even hardware damage!<br />
<br />
Not all BIOS'es limit the CPU-Frequency in this case, but for example most IBM/Lenovo Thinkpads do. Refer to thinkwiki for more [http://www.thinkwiki.org/wiki/Problem_with_CPU_frequency_scaling thinkpad related info on this topic].<br />
<br />
If you checked there's not just an odd BIOS setting and you know what you're doing you can make the Kernel ignore these BIOS-limitations.<br />
<br />
{{Warning|Make sure you read and understood the section above. CPU frequency limitation is a safety feature of your BIOS and you should not need to work around it.}}<br />
<br />
A special parameter has to be passed to the processor module.<br />
<br />
For trying this temporarily change the value in {{ic|/sys/module/processor/parameters/ignore_ppc}} from {{ic|0}} to {{ic|1}}.<br />
<br />
For setting it permanently [[Kernel modules#Setting module options]] describes alternatives. For example, you can add {{ic|1=processor.ignore_ppc=1}} to your kernel boot line, or create<br />
{{hc|/etc/modprobe.d/ignore_ppc.conf|2=# If the frequency of your machine gets wrongly limited by BIOS, this should help<br />
options processor ignore_ppc=1}}<br />
<br />
== See also ==<br />
<br />
* [https://www.kernel.org/doc/Documentation/cpu-freq/index.txt Linux CPUFreq - kernel documentation]<br />
* [http://www.reddit.com/r/linux/comments/1hdogn/acpi_cpufreq_or_intel_pstates/ Comprehensive explanation of pstate]<br />
* [https://www.kernel.org/doc/Documentation/cpu-freq/boost.txt Processor boosting control]</div>X33ahttps://wiki.archlinux.org/index.php?title=CPU_frequency_scaling&diff=574144CPU frequency scaling2019-05-27T18:05:28Z<p>X33a: Added link to the kernel documentation for processor boosting control for the cpufreq driver</p>
<hr />
<div>[[Category:Power management]]<br />
[[Category:CPU]]<br />
[[ar:CPU frequency scaling]]<br />
[[cs:CPU frequency scaling]]<br />
[[de:Cpufrequtils]]<br />
[[el:CPU frequency scaling]]<br />
[[es:CPU frequency scaling]]<br />
[[fr:Cpufreq]]<br />
[[it:CPU frequency scaling]]<br />
[[ja:CPU 周波数スケーリング]]<br />
[[pt:CPU frequency scaling]]<br />
[[ru:CPU frequency scaling]]<br />
[[sk:CPU frequency scaling]]<br />
[[zh-hans:CPU frequency scaling]]<br />
{{Related articles start}}<br />
{{Related|Power saving}}<br />
{{Related|Laptop Mode Tools}}<br />
{{Related|PHC}}<br />
{{Related articles end}}<br />
<br />
CPU frequency scaling enables the operating system to scale the CPU frequency up or down in order to save power. CPU frequencies can be scaled automatically depending on the system load, in response to ACPI events, or manually by userspace programs.<br />
<br />
CPU frequency scaling is implemented in the Linux kernel, the infrastructure is called ''cpufreq''. Since kernel 3.4 the necessary modules are loaded automatically and the recommended [[#Scaling governors|ondemand governor]] is enabled by default. However, userspace tools like [[#cpupower|cpupower]], [[acpid]], [[Laptop Mode Tools]], or GUI tools provided for your desktop environment, may still be used for advanced configuration.<br />
<br />
== Userspace tools ==<br />
<br />
=== thermald ===<br />
<br />
{{AUR|thermald}} is a Linux daemon used to prevent the overheating of platforms. This daemon monitors temperature and applies compensation using available cooling methods.<br />
<br />
By default, it monitors CPU temperature using available CPU digital temperature sensors and maintains CPU temperature under control, before HW takes aggressive correction action. If there is a skin temperature sensor in thermal sysfs, then it tries to keep skin temperature under 45C.<br />
<br />
The associated systemd unit is {{ic|thermald.service}}, which should be [[start]]ed and [[enable]]d.<br />
<br />
=== i7z ===<br />
<br />
{{Pkg|i7z}} is an i7 (and now i3, i5) CPU reporting tool for Linux. It can be launched from a Terminal with the command {{ic|i7z}} or as GUI with {{ic|i7z-gui}}.<br />
<br />
=== cpupower ===<br />
<br />
{{Pkg|cpupower}} is a set of userspace utilities designed to assist with CPU frequency scaling. The package is not required to use scaling, but is highly recommended because it provides useful command-line utilities and a [[systemd]] service to change the governor at boot.<br />
<br />
The configuration file for ''cpupower'' is located in {{ic|/etc/default/cpupower}}. This configuration file is read by a bash script in {{ic|/usr/lib/systemd/scripts/cpupower}} which is activated by ''systemd'' with {{ic|cpupower.service}}. You may want to [[enable]] {{ic|cpupower.service}} to start at boot.<br />
<br />
== CPU frequency driver ==<br />
<br />
{{Note|<br />
* The native CPU module is loaded automatically.<br />
* The {{ic|pstate}} power scaling driver is used automatically for modern Intel CPUs instead of the other drivers below. This driver takes priority over other drivers and is built-in as opposed to being a module. This driver is currently automatically used for Sandy Bridge and newer CPUs. If you encounter a problem while using this driver, add {{ic|1=intel_pstate=disable}} to your kernel line. You can use the same user space utilities with this driver, '''but cannot control it'''.<br />
* Even P State behavior mentioned above can be influenced with {{ic|/sys/devices/system/cpu/intel_pstate}}, e.g. Intel Turbo Boost can be deactivated with {{ic|# echo 1 > /sys/devices/system/cpu/intel_pstate/no_turbo}} for keeping CPU-Temperatures low.<br />
* Additional control for modern Intel CPUs is available with the [https://01.org/linux-thermal-daemon Linux Thermal Daemon] (available as {{AUR|thermald}}), which proactively controls thermal using P-states, T-states, and the Intel power clamp driver. thermald can also be used for older Intel CPUs. If the latest drivers are not available, then the daemon will revert to x86 model specific registers and the Linux ‘cpufreq subsystem’ to control system cooling.<br />
}}<br />
<br />
''cpupower'' requires modules to know the limits of the native CPU:<br />
<br />
{| class="wikitable sortable"<br />
!Module!!Description<br />
|-<br />
| intel_pstate || This driver implements a scaling driver with an internal governor for Intel Core (Sandy Bridge and newer) processors.<br />
|-<br />
| acpi-cpufreq || CPUFreq driver which utilizes the ACPI Processor Performance States. This driver also supports the Intel Enhanced SpeedStep (previously supported by the deprecated speedstep-centrino module).<br />
|-<br />
| speedstep-lib || CPUFreq driver for Intel SpeedStep-enabled processors (mostly Atoms and older Pentiums (before III)) <br />
|-<br />
| powernow-k8 || CPUFreq driver for K8/K10 Athlon 64/Opteron/Phenom processors. Since Linux 3.7 'acpi-cpufreq' will automatically be used for more modern CPUs from this family.<br />
|-<br />
| pcc-cpufreq || This driver supports Processor Clocking Control interface by Hewlett-Packard and Microsoft Corporation which is useful on some ProLiant servers.<br />
|-<br />
| p4-clockmod || CPUFreq driver for Intel Pentium 4/Xeon/Celeron processors which lowers the CPU temperature by skipping clocks. (You probably want to use a SpeedStep driver instead.)<br />
|}<br />
<br />
To see a full list of available modules, run:<br />
<br />
$ ls /usr/lib/modules/$(uname -r)/kernel/drivers/cpufreq/<br />
<br />
Load the appropriate module (see [[Kernel modules]] for details). Once the appropriate cpufreq driver is loaded, detailed information about the CPU(s) can be displayed by running<br />
<br />
$ cpupower frequency-info<br />
<br />
=== Setting maximum and minimum frequencies ===<br />
<br />
In rare cases, it may be necessary to manually set maximum and minimum frequencies.<br />
<br />
To set the maximum clock frequency ({{ic|''clock_freq''}} is a clock frequency with units: GHz, MHz):<br />
<br />
# cpupower frequency-set -u ''clock_freq''<br />
<br />
To set the minimum clock frequency:<br />
<br />
# cpupower frequency-set -d ''clock_freq''<br />
<br />
To set the CPU to run at a specified frequency:<br />
<br />
# cpupower frequency-set -f ''clock_freq''<br />
<br />
{{Note|<br />
* To adjust for only a single CPU core, append {{ic|-c ''core_number''}}.<br />
* The governor, maximum and minimum frequencies can be set in {{ic|/etc/default/cpupower}}.<br />
}}<br />
<br />
=== Disabling Turbo Boost ===<br />
==== intel_pstate ====<br />
<br />
{{ic|# echo 1 > /sys/devices/system/cpu/intel_pstate/no_turbo}}<br />
<br />
==== acpi-cpufreq ====<br />
<br />
{{ic|# echo 0 > /sys/devices/system/cpu/cpufreq/boost}}<br />
<br />
== Scaling governors ==<br />
<br />
Governors (see table below) are power schemes for the CPU. Only one may be active at a time. For details, see the [https://www.kernel.org/doc/Documentation/cpu-freq/governors.txt kernel documentation] in the kernel source.<br />
<br />
{| class="wikitable"<br />
! Governor !! Description<br />
|-<br />
| performance || Run the CPU at the maximum frequency.<br />
|-<br />
| powersave || Run the CPU at the minimum frequency.<br />
|-<br />
| userspace || Run the CPU at user specified frequencies.<br />
|-<br />
| ondemand || Scales the frequency dynamically according to current load. Jumps to the highest frequency and then possibly back off as the idle time increases.<br />
|-<br />
| conservative || Scales the frequency dynamically according to current load. Scales the frequency more gradually than ondemand.<br />
|-<br />
| schedutil || Scheduler-driven CPU frequency selection [http://lwn.net/Articles/682391/], [https://lkml.org/lkml/2016/3/17/420].<br />
|}<br />
<br />
Depending on the scaling driver, one of these governors will be loaded by default:<br />
<br />
* {{ic|ondemand}} for AMD and older Intel CPU.<br />
* {{ic|powersave}} for Intel CPUs using the {{ic|intel_pstate}} driver (Sandy Bridge and newer).<br />
<br />
{{Note|1=The {{ic|intel_pstate}} driver supports only the performance and powersave governors, but they both provide dynamic scaling. The performance governor [http://www.phoronix.com/scan.php?page=news_item&px=MTM3NDQ should give better power saving functionality than the old ondemand governor].}}<br />
<br />
{{Warning|Use CPU monitoring tools (for temperatures, voltage, etc.) when changing the default governor.}} <br />
<br />
To activate a particular governor, run:<br />
<br />
# cpupower frequency-set -g ''governor''<br />
<br />
{{Note|<br />
* To adjust for only a single CPU core, append {{ic|-c ''core_number''}} to the command above.<br />
* Activating a governor requires that specific [[kernel module]] (named {{ic|cpufreq_''governor''}}) is loaded. As of kernel 3.4, these modules are loaded automatically.<br />
}}<br />
<br />
Alternatively, you can activate a governor on every available CPU manually:<br />
<br />
# echo ''governor'' > /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor<br />
<br />
where {{ic|''governor''}} is the name of the governor, mentioned in the above table, that you want to activate.<br />
<br />
{{Tip|To monitor cpu speed in real time, run:<br />
<br />
$ watch grep \"cpu MHz\" /proc/cpuinfo<br />
<br />
}}<br />
<br />
=== Tuning the ondemand governor ===<br />
<br />
See the [https://www.kernel.org/doc/Documentation/cpu-freq/governors.txt kernel documentation] for details.<br />
<br />
==== Switching threshold ====<br />
<br />
To set the threshold for stepping up to another frequency:<br />
<br />
# echo -n ''percent'' > /sys/devices/system/cpu/cpufreq/<governor>/up_threshold<br />
<br />
To set the threshold for stepping down to another frequency:<br />
<br />
# echo -n ''percent'' > /sys/devices/system/cpu/cpufreq/<governor>/down_threshold<br />
<br />
==== Sampling rate ====<br />
<br />
The sampling rate determines how frequently the governor checks to tune the CPU. {{ic|sampling_down_factor}} is a tunable that multiplies the sampling rate when the CPU is at its highest clock frequency thereby delaying load evaluation and improving performance. Allowed values for {{ic|sampling_down_factor}} are 1 to 100000. This tunable has no effect on behavior at lower CPU frequencies/loads.<br />
<br />
To read the value (default = 1), run:<br />
<br />
$ cat /sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor<br />
<br />
To set the value, run:<br />
<br />
# echo -n ''value'' > /sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor<br />
<br />
==== Make changes permanent ====<br />
<br />
To have the desired scaling enabled at boot, [[Kernel modules#Using files in /etc/modprobe.d/|kernel module options]] and [[systemd#Temporary files]] are regular methods. <br />
<br />
For example, changing the up_threshold to 10:<br />
{{hc|/etc/tmpfiles.d/ondemand.conf|2=<br />
w- /sys/devices/system/cpu/cpufreq/ondemand/up_threshold - - - - 10<br />
}}<br />
<br />
However, in some cases race conditions, as noted in [[systemd#Temporary files]] may exist and one can use [[udev]] to avoid them.<br />
<br />
For example, to set the scaling governor of the CPU core {{ic|0}} to performance while the scaling driver is {{ic|acpi_cpufreq}}, create the following udev rule:<br />
<br />
{{hc|/etc/udev/rules.d/50-scaling-governor.rules|2=<br />
SUBSYSTEM=="module", ACTION=="add", KERNEL=="acpi_cpufreq", RUN+="/bin/sh -c 'echo performance > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor'"<br />
}}<br />
<br />
To have the rule already applied in the ''initramfs'', follow the example at [[udev#Debug output]].<br />
<br />
{{Tip|Alternatively, configure the [[#cpupower|cpupower]] utility and enable its systemd service.}}<br />
<br />
== Interaction with ACPI events ==<br />
<br />
Users may configure scaling governors to switch automatically based on different ACPI events such as connecting the AC adapter or closing a laptop lid. A quick example is given below, however it may be worth reading full article on [[acpid]].<br />
<br />
Events are defined in {{ic|/etc/acpi/handler.sh}}. If the {{Pkg|acpid}} package is installed, the file should already exist and be executable. For example, to change the scaling governor from {{ic|performance}} to {{ic|conservative}} when the AC adapter is disconnected and change it back if reconnected:<br />
<br />
{{hc|/etc/acpi/handler.sh|<nowiki><br />
[...]<br />
<br />
ac_adapter)<br />
case "$2" in<br />
AC*)<br />
case "$4" in<br />
00000000)<br />
echo "conservative" >/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor <br />
echo -n $minspeed >$setspeed<br />
#/etc/laptop-mode/laptop-mode start<br />
;;<br />
00000001)<br />
echo "performance" >/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor<br />
echo -n $maxspeed >$setspeed<br />
#/etc/laptop-mode/laptop-mode stop<br />
;;<br />
esac<br />
;;<br />
*) logger "ACPI action undefined: $2" ;;<br />
esac<br />
;;<br />
<br />
[...]<br />
</nowiki>}}<br />
<br />
== Privilege granting under GNOME ==<br />
<br />
{{Out of date|See the note below.}}<br />
<br />
{{Note|systemd introduced logind which handles consolekit and policykit actions. The following code below does not work. With logind, simply edit in the file {{ic|/usr/share/polkit-1/actions/org.gnome.cpufreqselector.policy}} the <defaults> elements according to your needs and the polkit manual [http://www.freedesktop.org/software/polkit/docs/latest/polkit.8.html].}}<br />
<br />
[[GNOME]] has a nice applet to change the governor on the fly. To use it without the need to enter the root password, simply create following file:<br />
<br />
{{hc|/var/lib/polkit-1/localauthority/50-local.d/org.gnome.cpufreqselector.pkla|2=<br />
[org.gnome.cpufreqselector]<br />
Identity=unix-user:''user''<br />
Action=org.gnome.cpufreqselector<br />
ResultAny=no<br />
ResultInactive=no<br />
ResultActive=yes<br />
}}<br />
<br />
Where the word ''user'' is replaced with the username of interest.<br />
<br />
The {{AUR|desktop-privileges}} package in the [[AUR]] contains a similar {{ic|.pkla}} file for authorizing all users of the {{ic|power}} [[user group]] to change the governor.<br />
<br />
== Troubleshooting ==<br />
<br />
{{Accuracy|Unverifiable and vague statements, lots of "some"s and "maybe"s. Troubleshooting items need to address concrete problems.}}<br />
<br />
* Some applications, like [[ntop]], do not respond well to automatic frequency scaling. In the case of ntop it can result in segmentation faults and lots of lost information as even the {{ic|on-demand}} governor cannot change the frequency quickly enough when a lot of packets suddenly arrive at the monitored network interface that cannot be handled by the current processor speed.<br />
<br />
* Some CPU's may suffer from poor performance with the default settings of the {{ic|on-demand}} governor (e.g. flash videos not playing smoothly or stuttering window animations). Instead of completely disabling frequency scaling to resolve these issues, the aggressiveness of frequency scaling can be increased by lowering the ''up_threshold'' [[sysctl]] variable for each CPU. See [[#Switching_threshold|how to change the on-demand governor's threshold]].<br />
<br />
* Sometimes the on-demand governor may not throttle to the maximum frequency but one step below. This can be solved by setting max_freq value slightly higher than the real maximum. For example, if frequency range of the CPU is from 2.00 GHz to 3.00 GHz, setting max_freq to 3.01 GHz can be a good idea.<br />
<br />
* Some combinations of [[ALSA]] drivers and sound chips may cause audio skipping as the governor changes between frequencies, switching back to a non-changing governor seems to stop the audio skipping.<br />
<br />
=== BIOS frequency limitation ===<br />
<br />
Some CPU/BIOS configurations may have difficulties to scale to the maximum frequency or scale to higher frequencies at all. This is most likely caused by BIOS events telling the OS to limit the frequency resulting in {{ic|/sys/devices/system/cpu/cpu0/cpufreq/bios_limit}} set to a lower value.<br />
<br />
Either you just made a specific Setting in the BIOS Setup Utility, (Frequency, Thermal Management, etc.) you can blame a buggy/outdated BIOS or the BIOS might have a serious reason for throttling the CPU on it's own.<br />
<br />
Reasons like that can be (assuming your machine's a notebook) that the battery is removed (or near death) so you're on AC-power only. In this case a weak AC-source might not supply enough electricity to fulfill extreme peak demands by the overall system and as there is no battery to assist this could lead to data loss, data corruption or in worst case even hardware damage!<br />
<br />
Not all BIOS'es limit the CPU-Frequency in this case, but for example most IBM/Lenovo Thinkpads do. Refer to thinkwiki for more [http://www.thinkwiki.org/wiki/Problem_with_CPU_frequency_scaling thinkpad related info on this topic].<br />
<br />
If you checked there's not just an odd BIOS setting and you know what you're doing you can make the Kernel ignore these BIOS-limitations.<br />
<br />
{{Warning|Make sure you read and understood the section above. CPU frequency limitation is a safety feature of your BIOS and you should not need to work around it.}}<br />
<br />
A special parameter has to be passed to the processor module.<br />
<br />
For trying this temporarily change the value in {{ic|/sys/module/processor/parameters/ignore_ppc}} from {{ic|0}} to {{ic|1}}.<br />
<br />
For setting it permanently [[Kernel modules#Setting module options]] describes alternatives. For example, you can add {{ic|1=processor.ignore_ppc=1}} to your kernel boot line, or create<br />
{{hc|/etc/modprobe.d/ignore_ppc.conf|2=# If the frequency of your machine gets wrongly limited by BIOS, this should help<br />
options processor ignore_ppc=1}}<br />
<br />
== See also ==<br />
<br />
* [https://www.kernel.org/doc/Documentation/cpu-freq/index.txt Linux CPUFreq - kernel documentation]<br />
* [http://www.reddit.com/r/linux/comments/1hdogn/acpi_cpufreq_or_intel_pstates/ Comprehensive explanation of pstate]<br />
* [https://www.kernel.org/doc/Documentation/cpu-freq/boost.txt Processor boosting control]</div>X33ahttps://wiki.archlinux.org/index.php?title=CPU_frequency_scaling&diff=574143CPU frequency scaling2019-05-27T18:03:40Z<p>X33a: /* CPU frequency driver */ Disabling turbo boost with different drivers</p>
<hr />
<div>[[Category:Power management]]<br />
[[Category:CPU]]<br />
[[ar:CPU frequency scaling]]<br />
[[cs:CPU frequency scaling]]<br />
[[de:Cpufrequtils]]<br />
[[el:CPU frequency scaling]]<br />
[[es:CPU frequency scaling]]<br />
[[fr:Cpufreq]]<br />
[[it:CPU frequency scaling]]<br />
[[ja:CPU 周波数スケーリング]]<br />
[[pt:CPU frequency scaling]]<br />
[[ru:CPU frequency scaling]]<br />
[[sk:CPU frequency scaling]]<br />
[[zh-hans:CPU frequency scaling]]<br />
{{Related articles start}}<br />
{{Related|Power saving}}<br />
{{Related|Laptop Mode Tools}}<br />
{{Related|PHC}}<br />
{{Related articles end}}<br />
<br />
CPU frequency scaling enables the operating system to scale the CPU frequency up or down in order to save power. CPU frequencies can be scaled automatically depending on the system load, in response to ACPI events, or manually by userspace programs.<br />
<br />
CPU frequency scaling is implemented in the Linux kernel, the infrastructure is called ''cpufreq''. Since kernel 3.4 the necessary modules are loaded automatically and the recommended [[#Scaling governors|ondemand governor]] is enabled by default. However, userspace tools like [[#cpupower|cpupower]], [[acpid]], [[Laptop Mode Tools]], or GUI tools provided for your desktop environment, may still be used for advanced configuration.<br />
<br />
== Userspace tools ==<br />
<br />
=== thermald ===<br />
<br />
{{AUR|thermald}} is a Linux daemon used to prevent the overheating of platforms. This daemon monitors temperature and applies compensation using available cooling methods.<br />
<br />
By default, it monitors CPU temperature using available CPU digital temperature sensors and maintains CPU temperature under control, before HW takes aggressive correction action. If there is a skin temperature sensor in thermal sysfs, then it tries to keep skin temperature under 45C.<br />
<br />
The associated systemd unit is {{ic|thermald.service}}, which should be [[start]]ed and [[enable]]d.<br />
<br />
=== i7z ===<br />
<br />
{{Pkg|i7z}} is an i7 (and now i3, i5) CPU reporting tool for Linux. It can be launched from a Terminal with the command {{ic|i7z}} or as GUI with {{ic|i7z-gui}}.<br />
<br />
=== cpupower ===<br />
<br />
{{Pkg|cpupower}} is a set of userspace utilities designed to assist with CPU frequency scaling. The package is not required to use scaling, but is highly recommended because it provides useful command-line utilities and a [[systemd]] service to change the governor at boot.<br />
<br />
The configuration file for ''cpupower'' is located in {{ic|/etc/default/cpupower}}. This configuration file is read by a bash script in {{ic|/usr/lib/systemd/scripts/cpupower}} which is activated by ''systemd'' with {{ic|cpupower.service}}. You may want to [[enable]] {{ic|cpupower.service}} to start at boot.<br />
<br />
== CPU frequency driver ==<br />
<br />
{{Note|<br />
* The native CPU module is loaded automatically.<br />
* The {{ic|pstate}} power scaling driver is used automatically for modern Intel CPUs instead of the other drivers below. This driver takes priority over other drivers and is built-in as opposed to being a module. This driver is currently automatically used for Sandy Bridge and newer CPUs. If you encounter a problem while using this driver, add {{ic|1=intel_pstate=disable}} to your kernel line. You can use the same user space utilities with this driver, '''but cannot control it'''.<br />
* Even P State behavior mentioned above can be influenced with {{ic|/sys/devices/system/cpu/intel_pstate}}, e.g. Intel Turbo Boost can be deactivated with {{ic|# echo 1 > /sys/devices/system/cpu/intel_pstate/no_turbo}} for keeping CPU-Temperatures low.<br />
* Additional control for modern Intel CPUs is available with the [https://01.org/linux-thermal-daemon Linux Thermal Daemon] (available as {{AUR|thermald}}), which proactively controls thermal using P-states, T-states, and the Intel power clamp driver. thermald can also be used for older Intel CPUs. If the latest drivers are not available, then the daemon will revert to x86 model specific registers and the Linux ‘cpufreq subsystem’ to control system cooling.<br />
}}<br />
<br />
''cpupower'' requires modules to know the limits of the native CPU:<br />
<br />
{| class="wikitable sortable"<br />
!Module!!Description<br />
|-<br />
| intel_pstate || This driver implements a scaling driver with an internal governor for Intel Core (Sandy Bridge and newer) processors.<br />
|-<br />
| acpi-cpufreq || CPUFreq driver which utilizes the ACPI Processor Performance States. This driver also supports the Intel Enhanced SpeedStep (previously supported by the deprecated speedstep-centrino module).<br />
|-<br />
| speedstep-lib || CPUFreq driver for Intel SpeedStep-enabled processors (mostly Atoms and older Pentiums (before III)) <br />
|-<br />
| powernow-k8 || CPUFreq driver for K8/K10 Athlon 64/Opteron/Phenom processors. Since Linux 3.7 'acpi-cpufreq' will automatically be used for more modern CPUs from this family.<br />
|-<br />
| pcc-cpufreq || This driver supports Processor Clocking Control interface by Hewlett-Packard and Microsoft Corporation which is useful on some ProLiant servers.<br />
|-<br />
| p4-clockmod || CPUFreq driver for Intel Pentium 4/Xeon/Celeron processors which lowers the CPU temperature by skipping clocks. (You probably want to use a SpeedStep driver instead.)<br />
|}<br />
<br />
To see a full list of available modules, run:<br />
<br />
$ ls /usr/lib/modules/$(uname -r)/kernel/drivers/cpufreq/<br />
<br />
Load the appropriate module (see [[Kernel modules]] for details). Once the appropriate cpufreq driver is loaded, detailed information about the CPU(s) can be displayed by running<br />
<br />
$ cpupower frequency-info<br />
<br />
=== Setting maximum and minimum frequencies ===<br />
<br />
In rare cases, it may be necessary to manually set maximum and minimum frequencies.<br />
<br />
To set the maximum clock frequency ({{ic|''clock_freq''}} is a clock frequency with units: GHz, MHz):<br />
<br />
# cpupower frequency-set -u ''clock_freq''<br />
<br />
To set the minimum clock frequency:<br />
<br />
# cpupower frequency-set -d ''clock_freq''<br />
<br />
To set the CPU to run at a specified frequency:<br />
<br />
# cpupower frequency-set -f ''clock_freq''<br />
<br />
{{Note|<br />
* To adjust for only a single CPU core, append {{ic|-c ''core_number''}}.<br />
* The governor, maximum and minimum frequencies can be set in {{ic|/etc/default/cpupower}}.<br />
}}<br />
<br />
=== Disabling Turbo Boost ===<br />
==== intel_pstate ====<br />
<br />
{{ic|# echo 1 > /sys/devices/system/cpu/intel_pstate/no_turbo}}<br />
<br />
==== acpi-cpufreq ====<br />
<br />
{{ic|# echo 0 > /sys/devices/system/cpu/cpufreq/boost}}{{ref<br />
<br />
== Scaling governors ==<br />
<br />
Governors (see table below) are power schemes for the CPU. Only one may be active at a time. For details, see the [https://www.kernel.org/doc/Documentation/cpu-freq/governors.txt kernel documentation] in the kernel source.<br />
<br />
{| class="wikitable"<br />
! Governor !! Description<br />
|-<br />
| performance || Run the CPU at the maximum frequency.<br />
|-<br />
| powersave || Run the CPU at the minimum frequency.<br />
|-<br />
| userspace || Run the CPU at user specified frequencies.<br />
|-<br />
| ondemand || Scales the frequency dynamically according to current load. Jumps to the highest frequency and then possibly back off as the idle time increases.<br />
|-<br />
| conservative || Scales the frequency dynamically according to current load. Scales the frequency more gradually than ondemand.<br />
|-<br />
| schedutil || Scheduler-driven CPU frequency selection [http://lwn.net/Articles/682391/], [https://lkml.org/lkml/2016/3/17/420].<br />
|}<br />
<br />
Depending on the scaling driver, one of these governors will be loaded by default:<br />
<br />
* {{ic|ondemand}} for AMD and older Intel CPU.<br />
* {{ic|powersave}} for Intel CPUs using the {{ic|intel_pstate}} driver (Sandy Bridge and newer).<br />
<br />
{{Note|1=The {{ic|intel_pstate}} driver supports only the performance and powersave governors, but they both provide dynamic scaling. The performance governor [http://www.phoronix.com/scan.php?page=news_item&px=MTM3NDQ should give better power saving functionality than the old ondemand governor].}}<br />
<br />
{{Warning|Use CPU monitoring tools (for temperatures, voltage, etc.) when changing the default governor.}} <br />
<br />
To activate a particular governor, run:<br />
<br />
# cpupower frequency-set -g ''governor''<br />
<br />
{{Note|<br />
* To adjust for only a single CPU core, append {{ic|-c ''core_number''}} to the command above.<br />
* Activating a governor requires that specific [[kernel module]] (named {{ic|cpufreq_''governor''}}) is loaded. As of kernel 3.4, these modules are loaded automatically.<br />
}}<br />
<br />
Alternatively, you can activate a governor on every available CPU manually:<br />
<br />
# echo ''governor'' > /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor<br />
<br />
where {{ic|''governor''}} is the name of the governor, mentioned in the above table, that you want to activate.<br />
<br />
{{Tip|To monitor cpu speed in real time, run:<br />
<br />
$ watch grep \"cpu MHz\" /proc/cpuinfo<br />
<br />
}}<br />
<br />
=== Tuning the ondemand governor ===<br />
<br />
See the [https://www.kernel.org/doc/Documentation/cpu-freq/governors.txt kernel documentation] for details.<br />
<br />
==== Switching threshold ====<br />
<br />
To set the threshold for stepping up to another frequency:<br />
<br />
# echo -n ''percent'' > /sys/devices/system/cpu/cpufreq/<governor>/up_threshold<br />
<br />
To set the threshold for stepping down to another frequency:<br />
<br />
# echo -n ''percent'' > /sys/devices/system/cpu/cpufreq/<governor>/down_threshold<br />
<br />
==== Sampling rate ====<br />
<br />
The sampling rate determines how frequently the governor checks to tune the CPU. {{ic|sampling_down_factor}} is a tunable that multiplies the sampling rate when the CPU is at its highest clock frequency thereby delaying load evaluation and improving performance. Allowed values for {{ic|sampling_down_factor}} are 1 to 100000. This tunable has no effect on behavior at lower CPU frequencies/loads.<br />
<br />
To read the value (default = 1), run:<br />
<br />
$ cat /sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor<br />
<br />
To set the value, run:<br />
<br />
# echo -n ''value'' > /sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor<br />
<br />
==== Make changes permanent ====<br />
<br />
To have the desired scaling enabled at boot, [[Kernel modules#Using files in /etc/modprobe.d/|kernel module options]] and [[systemd#Temporary files]] are regular methods. <br />
<br />
For example, changing the up_threshold to 10:<br />
{{hc|/etc/tmpfiles.d/ondemand.conf|2=<br />
w- /sys/devices/system/cpu/cpufreq/ondemand/up_threshold - - - - 10<br />
}}<br />
<br />
However, in some cases race conditions, as noted in [[systemd#Temporary files]] may exist and one can use [[udev]] to avoid them.<br />
<br />
For example, to set the scaling governor of the CPU core {{ic|0}} to performance while the scaling driver is {{ic|acpi_cpufreq}}, create the following udev rule:<br />
<br />
{{hc|/etc/udev/rules.d/50-scaling-governor.rules|2=<br />
SUBSYSTEM=="module", ACTION=="add", KERNEL=="acpi_cpufreq", RUN+="/bin/sh -c 'echo performance > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor'"<br />
}}<br />
<br />
To have the rule already applied in the ''initramfs'', follow the example at [[udev#Debug output]].<br />
<br />
{{Tip|Alternatively, configure the [[#cpupower|cpupower]] utility and enable its systemd service.}}<br />
<br />
== Interaction with ACPI events ==<br />
<br />
Users may configure scaling governors to switch automatically based on different ACPI events such as connecting the AC adapter or closing a laptop lid. A quick example is given below, however it may be worth reading full article on [[acpid]].<br />
<br />
Events are defined in {{ic|/etc/acpi/handler.sh}}. If the {{Pkg|acpid}} package is installed, the file should already exist and be executable. For example, to change the scaling governor from {{ic|performance}} to {{ic|conservative}} when the AC adapter is disconnected and change it back if reconnected:<br />
<br />
{{hc|/etc/acpi/handler.sh|<nowiki><br />
[...]<br />
<br />
ac_adapter)<br />
case "$2" in<br />
AC*)<br />
case "$4" in<br />
00000000)<br />
echo "conservative" >/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor <br />
echo -n $minspeed >$setspeed<br />
#/etc/laptop-mode/laptop-mode start<br />
;;<br />
00000001)<br />
echo "performance" >/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor<br />
echo -n $maxspeed >$setspeed<br />
#/etc/laptop-mode/laptop-mode stop<br />
;;<br />
esac<br />
;;<br />
*) logger "ACPI action undefined: $2" ;;<br />
esac<br />
;;<br />
<br />
[...]<br />
</nowiki>}}<br />
<br />
== Privilege granting under GNOME ==<br />
<br />
{{Out of date|See the note below.}}<br />
<br />
{{Note|systemd introduced logind which handles consolekit and policykit actions. The following code below does not work. With logind, simply edit in the file {{ic|/usr/share/polkit-1/actions/org.gnome.cpufreqselector.policy}} the <defaults> elements according to your needs and the polkit manual [http://www.freedesktop.org/software/polkit/docs/latest/polkit.8.html].}}<br />
<br />
[[GNOME]] has a nice applet to change the governor on the fly. To use it without the need to enter the root password, simply create following file:<br />
<br />
{{hc|/var/lib/polkit-1/localauthority/50-local.d/org.gnome.cpufreqselector.pkla|2=<br />
[org.gnome.cpufreqselector]<br />
Identity=unix-user:''user''<br />
Action=org.gnome.cpufreqselector<br />
ResultAny=no<br />
ResultInactive=no<br />
ResultActive=yes<br />
}}<br />
<br />
Where the word ''user'' is replaced with the username of interest.<br />
<br />
The {{AUR|desktop-privileges}} package in the [[AUR]] contains a similar {{ic|.pkla}} file for authorizing all users of the {{ic|power}} [[user group]] to change the governor.<br />
<br />
== Troubleshooting ==<br />
<br />
{{Accuracy|Unverifiable and vague statements, lots of "some"s and "maybe"s. Troubleshooting items need to address concrete problems.}}<br />
<br />
* Some applications, like [[ntop]], do not respond well to automatic frequency scaling. In the case of ntop it can result in segmentation faults and lots of lost information as even the {{ic|on-demand}} governor cannot change the frequency quickly enough when a lot of packets suddenly arrive at the monitored network interface that cannot be handled by the current processor speed.<br />
<br />
* Some CPU's may suffer from poor performance with the default settings of the {{ic|on-demand}} governor (e.g. flash videos not playing smoothly or stuttering window animations). Instead of completely disabling frequency scaling to resolve these issues, the aggressiveness of frequency scaling can be increased by lowering the ''up_threshold'' [[sysctl]] variable for each CPU. See [[#Switching_threshold|how to change the on-demand governor's threshold]].<br />
<br />
* Sometimes the on-demand governor may not throttle to the maximum frequency but one step below. This can be solved by setting max_freq value slightly higher than the real maximum. For example, if frequency range of the CPU is from 2.00 GHz to 3.00 GHz, setting max_freq to 3.01 GHz can be a good idea.<br />
<br />
* Some combinations of [[ALSA]] drivers and sound chips may cause audio skipping as the governor changes between frequencies, switching back to a non-changing governor seems to stop the audio skipping.<br />
<br />
=== BIOS frequency limitation ===<br />
<br />
Some CPU/BIOS configurations may have difficulties to scale to the maximum frequency or scale to higher frequencies at all. This is most likely caused by BIOS events telling the OS to limit the frequency resulting in {{ic|/sys/devices/system/cpu/cpu0/cpufreq/bios_limit}} set to a lower value.<br />
<br />
Either you just made a specific Setting in the BIOS Setup Utility, (Frequency, Thermal Management, etc.) you can blame a buggy/outdated BIOS or the BIOS might have a serious reason for throttling the CPU on it's own.<br />
<br />
Reasons like that can be (assuming your machine's a notebook) that the battery is removed (or near death) so you're on AC-power only. In this case a weak AC-source might not supply enough electricity to fulfill extreme peak demands by the overall system and as there is no battery to assist this could lead to data loss, data corruption or in worst case even hardware damage!<br />
<br />
Not all BIOS'es limit the CPU-Frequency in this case, but for example most IBM/Lenovo Thinkpads do. Refer to thinkwiki for more [http://www.thinkwiki.org/wiki/Problem_with_CPU_frequency_scaling thinkpad related info on this topic].<br />
<br />
If you checked there's not just an odd BIOS setting and you know what you're doing you can make the Kernel ignore these BIOS-limitations.<br />
<br />
{{Warning|Make sure you read and understood the section above. CPU frequency limitation is a safety feature of your BIOS and you should not need to work around it.}}<br />
<br />
A special parameter has to be passed to the processor module.<br />
<br />
For trying this temporarily change the value in {{ic|/sys/module/processor/parameters/ignore_ppc}} from {{ic|0}} to {{ic|1}}.<br />
<br />
For setting it permanently [[Kernel modules#Setting module options]] describes alternatives. For example, you can add {{ic|1=processor.ignore_ppc=1}} to your kernel boot line, or create<br />
{{hc|/etc/modprobe.d/ignore_ppc.conf|2=# If the frequency of your machine gets wrongly limited by BIOS, this should help<br />
options processor ignore_ppc=1}}<br />
<br />
== See also ==<br />
<br />
* [https://www.kernel.org/doc/Documentation/cpu-freq/index.txt Linux CPUFreq - kernel documentation]<br />
* [http://www.reddit.com/r/linux/comments/1hdogn/acpi_cpufreq_or_intel_pstates/ Comprehensive explanation of pstate]</div>X33ahttps://wiki.archlinux.org/index.php?title=Broadcom_wireless&diff=570756Broadcom wireless2019-04-08T18:19:05Z<p>X33a: /* No 5GHz for BCM4360 (14e4:43a0) devices */ Added another model affected by this issue, and since I am facing the issue in India, I have removed the US bit.</p>
<hr />
<div>[[Category:Wireless networking]]<br />
[[de:Broadcom WLAN]]<br />
[[ja:Broadcom ワイヤレス]]<br />
[[pt:Broadcom wireless]]<br />
[[zh-hans:Broadcom wireless]]<br />
{{Related articles start}}<br />
{{Related|Wireless}}<br />
{{Related articles end}}<br />
This article details how to install and setup a Broadcom wireless network device.<br />
<br />
== History ==<br />
<br />
Broadcom has a noted history with its support for Wi-Fi devices regarding GNU/Linux. For a good portion of its initial history, Broadcom devices were either entirely unsupported or required the user to tinker with the firmware. The limited set of wireless devices that were supported were done so by a reverse-engineered driver. The reverse-engineered {{ic|b43}} driver was introduced in the 2.6.24 kernel.<br />
<br />
In August 2008, Broadcom released the [http://www.broadcom.com/support/802.11/linux_sta.php 802.11 Linux STA driver] officially supporting Broadcom wireless devices on GNU/Linux. This is a restrictively licensed driver and it does not work with hidden ESSIDs, but Broadcom promised to work towards a more open approach in the future.<br />
<br />
In September 2010, Broadcom [http://thread.gmane.org/gmane.linux.kernel.wireless.general/55418 released] a fully open source driver. The [http://wireless.kernel.org/en/users/Drivers/brcm80211 brcm80211] driver was introduced in the 2.6.37 kernel and in the 2.6.39 kernel it was sub-divided into the {{ic|brcmsmac}} and {{ic|brcmfmac}} drivers.<br />
<br />
The types of available drivers are:<br />
<br />
{| class="wikitable"<br />
! Driver !! Description<br />
|-<br />
| brcm80211 || Kernel driver mainline version (recommended)<br />
|-<br />
| b43 || Kernel driver reverse-engineered version<br />
|-<br />
| broadcom-wl || Broadcom driver with restricted license<br />
|}<br />
<br />
== Driver selection ==<br />
<br />
To know what driver(s) are operable on the computer's Broadcom wireless network device, the [[Wikipedia:PCI configuration space|device ID]] and chipset name will need to be detected. Cross-reference them with the driver list of supported [https://wireless.wiki.kernel.org/en/users/Drivers/brcm80211#supported_chips brcm80211] and [https://wireless.wiki.kernel.org/en/users/Drivers/b43#list_of_hardware b43] devices.<br />
<br />
$ lspci -vnn -d 14e4:<br />
<br />
== Installation ==<br />
<br />
=== brcm80211 ===<br />
<br />
The kernel contains two built-in open-source drivers: '''brcmfmac''' for native FullMAC and '''brcmsmac''' for mac80211-based SoftMAC. They should be automatically loaded when booting.<br />
<br />
{{Note|<br />
*'''brcmfmac''' supports newer chipsets, and supports AP mode, P2P mode, or hardware encryption.<br />
*'''brcmsmac''' only supports old chipsets like BCM4313, BCM43224, BCM43225.<br />
}}<br />
<br />
=== b43 ===<br />
<br />
Two reverse-engineered open-source drivers are built-in to the kernel: '''b43''' and '''b43legacy'''. b43 supports most newer Broadcom chipsets, while the b43legacy driver only supports the early BCM4301 and BCM4306 rev.2 chipsets. To avoid erroneous detection of your WiFi card's chipset, [[blacklist]] the unused driver.<br />
<br />
Both of these drivers require non-free firmware to function. Install {{aur|b43-firmware}} or {{aur|b43-firmware-classic}}.<br />
<br />
{{Note|<br />
* BCM4306 rev.3, BCM4311, BCM4312 and BCM4318 rev.2 have been noticed to experience problems with '''b43-firmware'''. Use {{aur|b43-firmware-classic}} for these cards instead.<br />
* BCM4331 noticed to have problems with '''b43-firmware-classic'''. Use {{aur|b43-firmware}} for this card instead.<br />
}}<br />
<br />
=== broadcom-wl ===<br />
{{Accuracy|Is it still necessary to mention the [https://lists.archlinux.org/pipermail/arch-releng/2018-April/003810.html blacklist override]?|section=Installation: broadcom-wl is in the official repos now}}<br />
<br />
There are two variants of the restrictively licensed driver:<br />
* the regular variant: {{Pkg|broadcom-wl}}<br />
* the [[DKMS]] variant: {{Pkg|broadcom-wl-dkms}}<br />
<br />
{{Tip|The DKMS variant {{Pkg|broadcom-wl-dkms}} <br />
* is kernel agnostic. This means it supports different kernels you may use (e.g. {{AUR|linux-ck}}). <br />
* is kernel-release agnostic, too. It will be automatically rebuilt after every kernel upgrade or fresh installation. If you use {{Pkg|broadcom-wl}} or another kernel release dependant variant (e.g. {{AUR|broadcom-wl-ck}}), it may happen that kernel upgrades break wireless from time to time until the packages are in sync again.}}<br />
<br />
==== Offline installation ====<br />
<br />
An Internet connection is the ideal way to install the '''broadcom-wl''' driver; many newer laptops with Broadcom cards forgo Ethernet ports, so a USB Ethernet adapter or [[Android tethering]] may be helpful. If you have neither, you'll need to first install the {{grp|base-devel}} group during installation. Then, use another Internet-connected computer to download {{pkg|linux-headers}} and the driver tarball from the AUR, and install them in that order.<br />
<br />
==== Manually ====<br />
<br />
{{Warning|This method is not recommended. Drivers that are un-tracked can become problematic or nonfunctional on system updates.}}<br />
<br />
Install the appropriate driver for your system architecture from [https://www.broadcom.com/support/?gid=1 Broadcom's website]. After this, to avoid driver/module collisions with similar modules and make the driver available, do:<br />
<br />
# rmmod b43<br />
# rmmod ssb<br />
# modprobe wl<br />
<br />
The ''wl'' module should automatically load ''lib80211'' or ''lib80211_crypt_tkip'' otherwise they will have to be manually loaded.<br />
<br />
If the driver does not work at this point, you may need to update dependencies:<br />
<br />
# depmod -a<br />
<br />
To make the module load at boot, refer to [[Kernel modules]]. It is recommending that you [[blacklist]] conflicting modules.<br />
<br />
== Troubleshooting ==<br />
<br />
=== Setting broadcom-wl in monitor mode ===<br />
<br />
{{expansion|Explain what is monitor mode (at least briefly) and why one would want to use it}}<br />
<br />
To set broadcom-wl in monitor mode you have to set 1 to {{ic|/proc/brcm_monitor0)}}:<br />
<br />
# echo 1 > /proc/brcm_monitor0<br />
<br />
It will create a new network interface called {{ic|prism0}}.<br />
<br />
To work in monitor mode, use this newly created network interface.<br />
<br />
=== Device inaccessible after kernel upgrade ===<br />
<br />
Since the 3.3.1 kernel the '''bcma''' module was introduced. If using a '''brcm80211''' driver be sure it has not been [[Kernel_modules#Blacklisting|blacklisted]]. It should be blackisted if using a '''b43''' driver.<br />
<br />
If you are using {{Pkg|broadcom-wl}}, uninstall and reinstall it after upgrading your kernel or switch to {{Pkg|broadcom-wl-dkms}} package.<br />
<br />
=== Device with broadcom-wl driver not working/showing ===<br />
<br />
Be sure the correct modules are blacklisted and occasionally it may be necessary to blacklist the '''brcm80211''' drivers if accidentally detected before the '''wl''' driver is loaded. Furthermore, update the modules dependencies {{ic|depmod -a}}, verify the wireless interface with {{ic|ip addr}}, kernel upgrades will require an upgrade of the non-[[DKMS]] package.<br />
<br />
=== Interfaces swapped with broadcom-wl ===<br />
<br />
Users of the broadcom-wl driver may find their Ethernet and Wi-Fi interfaces have been swapped. See [[Network configuration#Network interfaces]] for an answer.<br />
<br />
=== Interface is showing but not allowing connections ===<br />
<br />
Append the following [[kernel parameter]]:<br />
<br />
b43.allhwsupport=1<br />
<br />
=== Suppressing console messages ===<br />
<br />
You may continuously get some verbose and annoying messages during the boot, similar to<br />
<br />
phy0: brcms_ops_bss_info_changed: arp filtering: enabled true, count 0 (implement)<br />
phy0: brcms_ops_bss_info_changed: qos enabled: false (implement)<br />
phy0: brcms_ops_bss_info_changed: arp filtering: enabled true, count 1 (implement)<br />
enabled, active<br />
<br />
To disable those messages, increase the loglevel of printk messages that get through to the console - see [[Silent boot#sysctl]].<br />
<br />
=== Device BCM43241 not detected ===<br />
<br />
{{Accuracy|The [https://wireless.wiki.kernel.org/en/users/drivers/brcm80211 brcm80211 Wireless Wiki page] lists this chip as supported SDIO device since Linux kernel 3.7.}}<br />
<br />
This device will not display with either {{ic|lspci}} nor {{ic|lsusb}}; there is no known solution yet. Please remove this section when resolved.<br />
<br />
=== Connection is unstable with some routers ===<br />
<br />
If no other approaches help, install {{Pkg|linux-lts}}, or use a [[Downgrading packages|previous driver version]].<br />
<br />
=== No 5GHz for BCM4360 (14e4:43a0) / BCM43602 (14e4:43ba) devices ===<br />
<br />
Issue appears to be linked to a [https://askubuntu.com/questions/749420/wireless-lost-ability-to-use-5ghz-pce-ac68 channel issue]. Changing the wireless channel to a lower channel number (like 40) seems to allow connection to 5GHz bands.<br />
<br />
=== Device works intermittently ===<br />
<br />
In some cases (e.g. using BCM4331 and {{aur|b43-firmware}}), wifi connection works intermittently. One way to fix this is to check if the card is ''hard-blocked'' or ''soft-blocked'' by kernel, and if it is, unblock it with [[rfkill]].</div>X33ahttps://wiki.archlinux.org/index.php?title=Kernel_mode_setting&diff=554438Kernel mode setting2018-11-10T18:27:17Z<p>X33a: /* Forcing modes and EDID */ Fix link and remove redundant link</p>
<hr />
<div>[[Category:Graphics]]<br />
[[Category:Kernel]]<br />
[[es:Kernel mode setting]]<br />
[[hu:Kernel mode setting]]<br />
[[ja:Kernel Mode Setting]]<br />
[[ru:Kernel mode setting]]<br />
[[zh-hans:Kernel mode setting]]<br />
[[zh-hant:Kernel mode setting]]<br />
{{Related articles start}}<br />
{{Related|ATI}}<br />
{{Related|Intel graphics}}<br />
{{Related|Nouveau}}<br />
{{Related articles end}}<br />
<br />
{{Expansion|KMS and rootless X (1.16), see [[Talk:Kernel mode setting]] and [[Xorg#Rootless Xorg (v1.16)]].}}<br />
<br />
Kernel [[Wikipedia:Mode-setting|Mode Setting]] (KMS) is a method for setting display resolution and depth in the kernel space rather than user space.<br />
<br />
The Linux kernel's implementation of KMS enables native resolution in the framebuffer and allows for instant console (tty) switching. KMS also enables newer technologies (such as DRI2) which will help reduce artifacts and increase 3D performance, even kernel space power-saving.<br />
<br />
{{Note|The proprietary [[NVIDIA]] driver (since 364.12) also implements kernel mode-setting, but it does not use the built-in kernel implementation and it lacks an fbdev driver for the high-resolution console.}}<br />
<br />
== Background ==<br />
<br />
Previously, setting up the video card was the job of the X server. Because of this, it was not easily possible to have fancy graphics in virtual consoles. Also, each time a switch from X to a virtual console was made ({{ic|Ctrl+Alt+F1}}), the server had to give control over the video card to the kernel, which was slow and caused flickering. The same "painful" process happened when the control was given back to the X server ({{ic|Ctrl+Alt+F7}}).<br />
<br />
With Kernel Mode Setting (KMS), the kernel is now able to set the mode of the video card. This makes fancy graphics during bootup, virtual console and X fast switching possible, among other things.<br />
<br />
== Installation ==<br />
<br />
At first, note that for ''any'' method you use, you should ''always'' disable:<br />
<br />
* Any {{ic|<nowiki>vga=</nowiki>}} options in your bootloader as these will conflict with the native resolution enabled by KMS.<br />
* Any {{ic|<nowiki>video=</nowiki>}} lines that enable a framebuffer that conflicts with the driver.<br />
* Any other framebuffer drivers (such as [[uvesafb]]).<br />
<br />
=== Late KMS start===<br />
<br />
[[Intel]], [[Nouveau]], [[ATI]] and [[AMDGPU]] drivers already enable KMS automatically for all chipsets, so you need not install it manually.<br />
<br />
The proprietary [[NVIDIA]] driver supports KMS (since 364.12), which has to be [[NVIDIA#DRM kernel mode setting|manually enabled]].<br />
<br />
The proprietary [[AMD Catalyst]] driver does not support KMS. In order to use KMS you have to replace it with the open-source [[ATI]] driver.<br />
<br />
=== Early KMS start ===<br />
<br />
{{Tip|If you encounter problems with the resolution, you can check whether [[#Forcing modes and EDID|enforcing the mode]] helps.}}<br />
<br />
KMS is typically initialized after the [[Arch boot process#initramfs|initramfs stage]]. However it is possible to already enable KMS during the initramfs stage. Add the module {{ic|radeon}}/{{ic|amdgpu}} (for ATI/AMD cards), {{ic|i915}} (for Intel integrated graphics) or {{ic|nouveau}} (for Nvidia cards) to the {{ic|MODULES}} line in {{ic|/etc/mkinitcpio.conf}}. For example:<br />
<br />
{{hc|/etc/mkinitcpio.conf|2=MODULES=(... i915 ...)}}<br />
<br />
{{Note|Intel users might need to add {{ic|intel_agp}} before {{ic|i915}} to suppress the ACPI errors. This might be required for resuming from hibernation to work with changed display configuration!}}<br />
<br />
If you are using a custom EDID file (not applicable for the built-in resolutions), you should embed it into initramfs as well:<br />
<br />
{{hc|/etc/mkinitcpio.conf|2=<br />
FILES=(/usr/lib/firmware/edid/your_edid.bin)<br />
}}<br />
<br />
[[Regenerate the initramfs]].<br />
<br />
== Troubleshooting ==<br />
<br />
=== My fonts are too tiny ===<br />
<br />
See [[Linux console#Fonts]] for how to change your console font to a large font. The Terminus font ({{Pkg|terminus-font}}) is available in many sizes, such as {{ic|ter-132n}} which is larger.<br />
<br />
Alternatively, [[#Disabling modesetting|disabling modesetting]] might switch to lower resolution and make fonts appear larger.<br />
<br />
=== Problem upon bootloading and dmesg ===<br />
<br />
Polling for connected display devices on older systems can be quite expensive. Poll will happen periodically and can in worst cases take several hundred milliseconds, depending on the hardware. This will cause visible stalls, for example in video playback. These stalls might happen even when your video is on HDP output but you have other non HDP outputs in your hw configuration. If you experience stalls in display output occurring every 10 seconds, disabling polling might help.<br />
<br />
If you see an error code of {{ic|0x00000010 (2)}} while booting up, (you will get about 10 lines of text, the last part denoting that error code), use:<br />
<br />
{{hc|/etc/modprobe.d/modprobe.conf|2=<br />
options drm_kms_helper poll=0<br />
}}<br />
<br />
== Forcing modes and EDID ==<br />
<br />
If your native resolution is not automatically configured or no display at all is detected, then your monitor might send none or just a skewed [[Wikipedia:EDID|EDID]] file. The kernel will try to catch this case and will set one of the most typical resolutions.<br />
<br />
In case you have the EDID file for your monitor you merely not to explicitly enforce it (see below). However most often one does not have direct access to sane file and it is necessary to either extract an existing one and fix it or to generate a new one.<br />
<br />
Generating new EDID binaries for various resolutions and configurations is possible during kernel compilation by following the [https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/EDID/HOWTO.txt upstream documentation] (also see [https://www.osadl.org/Single-View.111+M5315d29dd12.0.html here] for a short guide). Other solutions are outlined in detail this [https://kodi.wiki/view/Creating_and_using_edid.bin_via_xorg.conf article].<br />
Extracting an existing one is in most cases easier, e.g. if your monitor works fine under Windows you might have luck extracting the EDID from the corresponding driver, or if a similar monitor works which has the same settings you may use {{ic|get-edid}} from the {{Pkg|read-edid}} package.<br />
<br />
After having prepared your EDID place it in a folder, e.g. called {{ic|edid}} under {{ic|/usr/lib/firmware}} and copy your binary into it.<br />
<br />
To load it at boot, specify the following in the [[kernel command line]]:<br />
<br />
drm_kms_helper.edid_firmware=edid/your_edid.bin<br />
<br />
or alternatively (since kernel 4.15), one may also enforce the EDID information on a lower level, using:<br />
<br />
drm.edid_firmware=edid/your_edid.bin<br />
<br />
In order to apply it only to a specific monitor use:<br />
<br />
drm_kms_helper.edid_firmware=VGA-1:edid/your_edid.bin<br />
<br />
For the built-in resolutions, refer to the table below. The '''Name''' column specifies the name which one is supposed to use in order to enforce its usage.<br />
<br />
{| class="wikitable"<br />
|-<br />
| '''Resolution''' || '''Name''' <br />
|-<br />
| 800x600 || edid/800x600.bin <br />
|-<br />
| 1024x768 || edid/1024x768.bin <br />
|-<br />
| 1280x1024 || edid/1280x1024.bin <br />
|-<br />
| 1600x1200 (kernel 3.10 or higher) || edid/1600x1200.bin<br />
|-<br />
| 1680x1050 || edid/1680x1050.bin <br />
|-<br />
| 1920x1080 || edid/1920x1080.bin <br />
|}<br />
<br />
If you are doing [[#Early_KMS_start|early KMS]], you must include the custom EDID file in the initramfs, otherwise you will run into problems.<br />
<br />
=== Forcing modes ===<br />
<br />
{{Warning|The method described below is somehow incomplete because e.g. [[Xorg]] does not take into account the resolution specified, so users are encouraged to use the method described above. However, specifying resolution with {{ic|1=video=}} command line may be useful in some scenarios.}}<br />
<br />
From [http://nouveau.freedesktop.org/wiki/KernelModeSetting the nouveau wiki]:<br />
:A mode can be forced on the kernel command line. Unfortunately, the command line option video is poorly documented in the DRM case. Bits and pieces on how to use it can be found in<br />
:* http://cgit.freedesktop.org/nouveau/linux-2.6/tree/Documentation/fb/modedb.txt<br />
:* http://cgit.freedesktop.org/nouveau/linux-2.6/tree/drivers/gpu/drm/drm_fb_helper.c <br />
<br />
The format is: <br />
<br />
video=<conn>:<xres>x<yres>[M][R][-<bpp>][@<refresh>][i][m][eDd]<br />
<br />
* {{ic|<conn>}}: Connector, e.g. DVI-I-1, see {{ic|/sys/class/drm/}} for available connectors<br />
* {{ic|<xres> x <yres>}}: resolution<br />
* {{ic|M}}: compute a CVT mode?<br />
* {{ic|R}}: reduced blanking?<br />
* {{ic|-<bpp>}}: color depth<br />
* {{ic|@<refresh>}}: refresh rate<br />
* {{ic|i}}: interlaced (non-CVT mode)<br />
* {{ic|m}}: margins?<br />
* {{ic|e}}: output forced to on<br />
* {{ic|d}}: output forced to off<br />
* {{ic|D}}: digital output forced to on (e.g. DVI-I connector) <br />
<br />
You can override the modes of several outputs using {{ic|<nowiki>video=</nowiki>}} several times, for instance, to force {{ic|DVI}} to ''1024x768'' at ''85 Hz'' and {{ic|TV-out}} off: <br />
<br />
video=DVI-I-1:1024x768@85 video=TV-1:d<br />
<br />
To get the name and current status of connectors, you can use the following shell oneliner:<br />
<br />
{{hc|<nowiki>$ for p in /sys/class/drm/*/status; do con=${p%/status}; echo -n "${con#*/card?-}: "; cat $p; done</nowiki>|<br />
DVI-I-1: connected<br />
HDMI-A-1: disconnected<br />
VGA-1: disconnected<br />
}}<br />
<br />
== Disabling modesetting ==<br />
<br />
You may want to disable KMS for various reasons, such as getting a blank screen or a "no signal" error from the display, when using the Catalyst driver, etc. To disable KMS add {{ic|nomodeset}} as a kernel parameter. See [[Kernel parameters]] for more info.<br />
<br />
Along with {{ic|nomodeset}} kernel parameter, for Intel graphics card you need to add {{ic|1=i915.modeset=0}} and for Nvidia graphics card you need to add {{ic|1=nouveau.modeset=0}}. For Nvidia Optimus dual-graphics system, you need to add all the three kernel parameters (i.e. {{ic|1="nomodeset i915.modeset=0 nouveau.modeset=0"}}).<br />
<br />
{{Note|Some [[Xorg]] drivers will not work with KMS disabled. See the wiki page on your specific driver for details.}}</div>X33ahttps://wiki.archlinux.org/index.php?title=TLP&diff=552198TLP2018-10-31T13:09:10Z<p>X33a: /* Graphical interface */ Replace currently with actual date after confirming with https://github.com/d4nj1/TLPUI/blob/b803c548fa980a1f20dfccef3197f39498accfb5/README.md</p>
<hr />
<div>[[Category:Power management]]<br />
[[ja:TLP]]<br />
[[zh-hans:TLP]]<br />
{{Related articles start}}<br />
{{Related|Laptop}}<br />
{{Related|Laptop Mode Tools}}<br />
{{Related articles end}}<br />
<br />
From the [http://linrunner.de/en/tlp/tlp.html project page]:<br />
<br />
:TLP brings you the benefits of advanced power management for Linux without the need to understand every technical detail. TLP comes with a default configuration already optimized for battery life, so you may just install and forget it. Nevertheless TLP is highly customizable to fulfill your specific requirements.<br />
<br />
== Installation ==<br />
<br />
[[Install]] {{Pkg|tlp}} from the [[official repositories]] - pay attention to its optional dependencies that may help provide additional power saving.<br />
<br />
To complete TLP's install, you must [[enable]] the systemd services {{ic|tlp.service}} and {{ic|tlp-sleep.service}}. You should also [[mask]] the systemd service {{ic|systemd-rfkill.service}} and socket {{ic|systemd-rfkill.socket}} to avoid conflicts and assure proper operation of TLP's radio device switching options.<br />
<br />
{{Note|{{ic|tlp.service}} starts {{ic|NetworkManager.service}} if it is available: {{bug|43733}}. If you use a different [[List_of_applications#Network_managers|network manager]], [[mask]] {{ic|NetworkManager.service}} or [[edit]] {{ic|tlp.service}} and remove the service out of line {{ic|1=Wants=}}.}}<br />
<br />
=== ThinkPads only ===<br />
<br />
For advanced battery functions, i.e. charge thresholds and recalibration, install the following package(s):<br />
<br />
* {{Pkg|tp_smapi}} – tp-smapi is needed for battery charge thresholds, recalibration and specific status output of tlp-stat<br />
* {{Pkg|acpi_call}} – acpi-call is needed for battery charge thresholds and recalibration on Sandy Bridge and newer models (X220/T420, X230/T430 et al.)<br />
<br />
See the TLP FAQ, section [http://linrunner.de/en/tlp/docs/tlp-faq.html#kernmod "Which kernel module?"], for details.<br />
<br />
Controlling the charge thresholds using D-Bus without root privileges is possible using {{AUR|threshy}} and it's example Qt user interface {{AUR|threshy-gui}}.<br />
<br />
=== Graphical interface ===<br />
<br />
{{AUR|tlpui-git}} is a GTK user interface for TLP written in Python. As of 31 October 2018, the software is still in beta.<br />
<br />
== Configuration ==<br />
<br />
The configuration file is located at {{ic|/etc/default/tlp}} and provides a "largely" optimized power saving by default. For a full explanation of options see: [http://linrunner.de/en/tlp/docs/tlp-configuration.html TLP configuration].<br />
<br />
=== Force battery (BAT) configuration ===<br />
When no power supply can be detected, the setting for AC will be used (e.g. on desktops and embedded hardware).<br />
<br />
You may want to force the battery (BAT) settings when using TLP on these devices to enable more power saving:<br />
<br />
{{hc|/etc/default/tlp|2=<br />
# Operation mode when no power supply can be detected: AC, BAT.<br />
TLP_DEFAULT_MODE=BAT<br />
<br />
# Operation mode select: 0=depend on power source, 1=always use TLP_DEFAULT_MODE<br />
TLP_PERSISTENT_DEFAULT=1}}<br />
<br />
=== Btrfs ===<br />
<br />
{{Accuracy|Hardware/kernel-specific quirk|section=Btrfs}}<br />
<br />
To avoid filesystem corruption on btrfs formatted partitions, set:<br />
<br />
SATA_LINKPWR_ON_BAT=max_performance<br />
<br />
See also these links for discussion on this topic: [https://github.com/linrunner/TLP/issues/128 Github bug report], [https://www.reddit.com/r/archlinux/comments/4f5xvh/saving_power_is_the_btrfs_dataloss_warning_still/ Reddit follow-up discussion].<br />
<br />
=== Bumblebee with NVIDIA driver ===<br />
<br />
If you're running [[Bumblebee]] with NVIDIA driver, you need to disable power management for the GPU in TLP in order to make Bumblebee control the power of the GPU.<br />
<br />
Run {{ic|lspci}} to determine the address of the GPU (such as 01:00.0), then set the value:<br />
<br />
RUNTIME_PM_BLACKLIST="01:00.0"<br />
<br />
=== Radio Device Wizard ===<br />
<br />
The Radio Device Wizard allows a more sophisticated management of radio devices depending on network connect/disconnect events. It requires [[NetworkManager]], {{Pkg|tlp-rdw}} and [[enabling]] {{ic|NetworkManager-dispatcher.service}}.<br />
<br />
See [http://linrunner.de/en/tlp/docs/tlp-configuration.html#rdw TLP configuration] for details.<br />
<br />
=== Command line ===<br />
<br />
TLP provides several command line tools. See [http://linrunner.de/en/tlp/docs/tlp-linux-advanced-power-management.html#commands TLP commands].<br />
<br />
== Debugging ==<br />
You can display information about the currently used Mode(AC/BAT) and applied configurations:<br />
<br />
# tlp-stat<br />
<br />
== Features intentionally excluded ==<br />
<br />
* Fan control. See [[Fan speed control]]<br />
<br />
* Backlight brightness. See [[Backlight]]<br />
<br />
== See also ==<br />
<br />
* [http://linrunner.de/tlp TLP - Linux Advanced Power Management] - Project homepage & documentation.</div>X33ahttps://wiki.archlinux.org/index.php?title=Power_management&diff=469822Power management2017-03-05T10:15:18Z<p>X33a: /* SATA Active Link Power Management */ Woops, it wasn't so stray after all. In any case, I have reworded the sentence and removed an unreferenced statement.</p>
<hr />
<div>[[Category:Power management]]<br />
[[es:Power management]]<br />
[[it:Shutdown Pressing Power Button]]<br />
[[ja:電源管理]]<br />
[[uk:Shutdown Pressing Power Button]]<br />
[[zh-hans:Power management]]<br />
{{Related articles start}}<br />
{{Related|Power management/Suspend and hibernate}}<br />
{{Related|Display Power Management Signaling}}<br />
{{Related|CPU frequency scaling}}<br />
{{Related|Hybrid graphics}}<br />
{{Related|Kernel modules}}<br />
{{Related|sysctl}}<br />
{{Related|udev}}<br />
{{Related articles end}}<br />
<br />
[[Wikipedia:Power management|Power management]] is a feature that turns off the power or switches system's components to a low-power state when inactive.<br />
<br />
In Arch Linux, power management consists of two main parts:<br />
<br />
# Configuration of the Linux kernel, which interacts with the hardware.<br />
#* [[Kernel parameters]]<br />
#* [[Kernel modules]]<br />
#* [[udev]] rules<br />
# Configuration of userspace tools, which interact with the kernel and react to its events. Many userspace tools also allow to modify kernel configuration in a "user-friendly" way. See [[#Userspace tools]] for the options.<br />
<br />
== Userspace tools ==<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|aclidswitch| Simple Power Management tool to define custom lid, brightness and low battery actions depending on the laptop's AC state.|https://github.com/orschiro/aclidswitch|{{AUR|aclidswitch-git}}}}<br />
* {{App|[[acpid]]| A daemon for delivering ACPI power management events with netlink support.|http://sourceforge.net/projects/acpid2/|{{Pkg|acpid}}}}<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|{{AUR|laptop-mode-tools}}}}<br />
* {{App|[[pm-utils]]|Suspend and powerstate setting framework (largely undeveloped now).|http://pm-utils.freedesktop.org/|{{Pkg|pm-utils}}{{Broken package link|package not found}}}}<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 />
* [[systemd]]<br />
* {{App|[[TLP]]|Advanced power management for Linux.|http://linrunner.de/tlp|{{Pkg|tlp}}}}<br />
<br />
== Power management with systemd ==<br />
<br />
=== ACPI events ===<br />
<br />
''systemd'' handles some power-related [[Wikipedia:Advanced_Configuration_and_Power_Interface|ACPI]] events, whose actions can be configured in {{ic|/etc/systemd/logind.conf}} or {{ic|/etc/systemd/logind.conf.d/*.conf}} — see {{ic|man logind.conf}}. On systems with no dedicated power manager, this may replace the [[acpid]] daemon which is usually used to react to these ACPI events.<br />
<br />
The specified action for each event can be one of {{ic|ignore}}, {{ic|poweroff}}, {{ic|reboot}}, {{ic|halt}}, {{ic|suspend}}, {{ic|hibernate}}, {{ic|hybrid-sleep}}, {{ic|lock}} or {{ic|kexec}}. In case of hibernation and suspension, they must be properly [[Power management/Suspend and hibernate|set up]]. If an event is not configured, ''systemd'' will use a default action.<br />
<br />
{| class="wikitable sortable" border=1<br />
!Event handler<br />
!Description<br />
!Default action<br />
|-<br />
|{{ic|HandlePowerKey}}<br />
|Triggered when the power key/button is pressed.<br />
|{{ic|poweroff}}<br />
|-<br />
|{{ic|HandleSuspendKey}}<br />
|Triggered when the suspend key/button is pressed.<br />
|{{ic|suspend}}<br />
|-<br />
|{{ic|HandleHibernateKey}}<br />
|Triggered when the hibernate key/button is pressed.<br />
|{{ic|hibernate}}<br />
|-<br />
|{{ic|HandleLidSwitch}}<br />
|Triggered when the lid is closed, except in the cases below.<br />
|{{ic|suspend}}<br />
|-<br />
|{{ic|HandleLidSwitchDocked}}<br />
|Triggered when the lid is closed if the system is inserted in a docking station, or more than one display is connected.<br />
|{{ic|ignore}}<br />
|}<br />
<br />
To apply any changes, [[restart]] the {{ic|systemd-logind}} daemon (be warned that this will terminate all login sessions that might still be open).<br />
<br />
{{Note|''systemd'' cannot handle AC and Battery ACPI events, so if you use [[Laptop Mode Tools]] or other similar tools [[acpid]] is still required.}}<br />
<br />
==== Power managers ====<br />
<br />
Some [[desktop environment]]s include power managers which [http://www.freedesktop.org/wiki/Software/systemd/inhibit/ inhibit] (temporarily turn off) some or all of the ''systemd'' ACPI settings. If such a power manager is running, then the actions for ACPI events can be configured in the power manager alone. Changes to {{ic|/etc/systemd/logind.conf}} or {{ic|/etc/systemd/logind.conf.d/*.conf}} need be made only if you wish to configure behaviour for a particular event that is not inhibited by the power manager. <br />
<br />
Note that if the power manager does not inhibit ''systemd'' for the appropriate events you can end up with a situation where ''systemd'' suspends your system and then when the system is woken up the other power manager suspends it again. As of December 2016, the power managers of [[KDE]], [[GNOME]], [[Xfce]] and [[MATE]] issue the necessary ''inhibited'' commands. If the ''inhibited'' commands are not being issued, such as when using [[acpid]] or others to handle ACPI events, set the {{ic|Handle}} options to {{ic|ignore}}. See also {{ic|man systemd-inhibit}}.<br />
<br />
==== xss-lock ====<br />
<br />
{{AUR|xss-lock-git}} subscribes to the systemd-events {{ic|suspend}}, {{ic|hibernate}}, {{ic|lock-session}}, and {{ic|unlock-session}} with appropriate actions (run locker and wait for user to unlock or kill locker). ''xss-lock'' also reacts to [[DPMS]] events and runs or kills the locker in response.<br />
<br />
Start xss-lock in your [[autostart]], for example<br />
<br />
xss-lock -- i3lock -n -i ''background_image.png'' &<br />
<br />
=== Suspend and hibernate ===<br />
<br />
''systemd'' provides commands for suspend to RAM, hibernate and a hybrid suspend using the kernel's native suspend/resume functionality. There are also mechanisms to add hooks to customize pre- and post-suspend actions.<br />
<br />
{{Note|''systemd'' can also use other suspend backends (such as [[Uswsusp]] or [[TuxOnIce]]), in addition to the default ''kernel'' backend, in order to put the computer to sleep or hibernate. See [[Uswsusp#With systemd]] for an example.}}<br />
<br />
{{ic|systemctl suspend}} should work out of the box, for {{ic|systemctl hibernate}} to work on your system you need to follow the instructions at [[Suspend and hibernate#Hibernation]].<br />
<br />
==== Hybrid sleep ====<br />
<br />
{{ic|systemctl hybrid-sleep}} both hibernates and suspends at the same time. This combines some of the benefits and drawbacks of suspension and hibernation. This is useful in case a computer were to suddenly lose power (AC disconnection or battery depletion) since upon powerup it will resume from hibernation. If there is no power loss, then it will resume from suspension, which is much faster than resuming from hibernation. However, since "hybrid-sleep" has to dump memory to swap in order for hibernation to work, it is slower to enter sleep than a plain {{ic|systemctl suspend}}. An alternative is a [[#Delayed_hibernation_service_file|delayed hibernation service file]].<br />
<br />
=== Sleep hooks ===<br />
<br />
''systemd'' does not use [[pm-utils]] to put the machine to sleep when using {{ic|systemctl suspend}}, {{ic|systemctl hibernate}} or {{ic|systemctl hybrid-sleep}}; ''pm-utils'' hooks, including any [[Pm-utils#Creating_your_own_hooks|custom hooks]], will not be run. However, ''systemd'' provides two similar mechanisms to run custom scripts on these events.<br />
<br />
==== Suspend/resume service files ====<br />
<br />
Service files can be hooked into ''suspend.target'', ''hibernate.target'' and ''sleep.target'' to execute actions before or after suspend/hibernate. Separate files should be created for user actions and root/system actions. [[Enable]] the {{ic|suspend@''user''}} and {{ic|resume@''user''}} services to have them started at boot. Examples:<br />
<br />
{{hc|/etc/systemd/system/suspend@.service|2=<nowiki><br />
[Unit]<br />
Description=User suspend actions<br />
Before=sleep.target<br />
<br />
[Service]<br />
User=%I<br />
Type=simple<br />
Environment=DISPLAY=:0<br />
ExecStartPre= -/usr/bin/pkill -u %u unison ; /usr/local/bin/music.sh stop ; /usr/bin/mysql -e 'slave stop'<br />
ExecStart=/usr/bin/sflock<br />
ExecStartPost=/usr/bin/sleep 1<br />
<br />
[Install]<br />
WantedBy=sleep.target</nowiki>}}<br />
<br />
{{hc|/etc/systemd/system/resume@.service|2=<nowiki><br />
[Unit]<br />
Description=User resume actions<br />
After=suspend.target<br />
<br />
[Service]<br />
User=%I<br />
Type=simple<br />
ExecStartPre=/usr/local/bin/ssh-connect.sh<br />
ExecStart=/usr/bin/mysql -e 'slave start'<br />
<br />
[Install]<br />
WantedBy=suspend.target</nowiki>}}<br />
<br />
{{Note|As screen lockers may return before the screen is "locked", the screen may flash on resuming from suspend. Adding a small delay via {{ic|1=ExecStartPost=/usr/bin/sleep 1}} helps prevent this.}}<br />
<br />
For root/system actions ([[enable]] the {{ic|root-resume}} and {{ic|root-suspend}} services to have them started at boot):<br />
<br />
{{hc|/etc/systemd/system/root-resume.service|2=<nowiki><br />
[Unit]<br />
Description=Local system resume actions<br />
After=suspend.target<br />
<br />
[Service]<br />
Type=simple<br />
ExecStart=/usr/bin/systemctl restart mnt-media.automount<br />
<br />
[Install]<br />
WantedBy=suspend.target</nowiki>}}<br />
<br />
{{hc|/etc/systemd/system/root-suspend.service|2=<nowiki><br />
[Unit]<br />
Description=Local system suspend actions<br />
Before=sleep.target<br />
<br />
[Service]<br />
Type=simple<br />
ExecStart=-/usr/bin/pkill sshfs<br />
<br />
[Install]<br />
WantedBy=sleep.target</nowiki>}}<br />
<br />
A couple of handy hints about these service files (more in {{ic|man systemd.service}}):<br />
* If {{ic|1=<nowiki>Type=oneshot</nowiki>}} then you can use multiple {{ic|1=<nowiki>ExecStart=</nowiki>}} lines. Otherwise only one {{ic|ExecStart}} line is allowed. You can add more commands with either {{ic|ExecStartPre}} or by separating commands with a semicolon (see the first example above; note the spaces before and after the semicolon, as they are ''required'').<br />
* A command prefixed with {{ic|-}} will cause a non-zero exit status to be ignored and treated as a successful command. <br />
* The best place to find errors when troubleshooting these service files is of course with [[journalctl]].<br />
<br />
==== Combined Suspend/resume service file ====<br />
<br />
With the combined suspend/resume service file, a single hook does all the work for different phases (sleep/resume) and for different targets (suspend/hibernate/hybrid-sleep).<br />
<br />
Example and explanation:<br />
<br />
{{hc|/etc/systemd/system/wicd-sleep.service|2=<nowiki><br />
[Unit]<br />
Description=Wicd sleep hook<br />
Before=sleep.target<br />
StopWhenUnneeded=yes<br />
<br />
[Service]<br />
Type=oneshot<br />
RemainAfterExit=yes<br />
ExecStart=-/usr/share/wicd/daemon/suspend.py<br />
ExecStop=-/usr/share/wicd/daemon/autoconnect.py<br />
<br />
[Install]<br />
WantedBy=sleep.target</nowiki>}}<br />
<br />
* {{ic|1=<nowiki>RemainAfterExit=yes</nowiki>}}: After started, the service is considered active until it is explicitly stopped.<br />
* {{ic|1=<nowiki>StopWhenUnneeded=yes</nowiki>}}: When active, the service will be stopped if no other active service requires it. In this specific example, it will be stopped after ''sleep.target'' is stopped.<br />
* Because ''sleep.target'' is pulled in by ''suspend.target'', ''hibernate.target'' and ''hybrid-sleep.target'' and because ''sleep.target'' itself is a ''StopWhenUnneeded'' service, the hook is guaranteed to start/stop properly for different tasks.<br />
<br />
==== Delayed hibernation service file ====<br />
<br />
An alternative approach is delayed hibernation. This makes use of sleep hooks to suspend as usual but sets a timer to wake up later to perform hibernation. Here, entering sleep is faster than {{ic|systemctl hybrid-sleep}} since no hibernation is performed initially. However, unlike "hybrid-sleep", at this point there is no protection against power loss via hibernation while in suspension. This caveat makes this approach more suitable for laptops than desktops. Since hibernation is delayed, the laptop battery is only used during suspension and to trigger the eventual hibernation. This uses less power over the long-term than a "hybrid-sleep" which will remain suspended until the battery is drained. Note that if your laptop has a spinning hard disk, when it wakes up from suspend in order to hibernate, you may not want to be moving or carrying the laptop for these few seconds. Delayed hibernation may be desirable both to reduce power use as well as for security reasons (e.g. when using full disk encryption). An example script is located [http://superuser.com/questions/298672/linuxhow-to-hibernate-after-a-period-of-sleep here]. See also [https://bbs.archlinux.org/viewtopic.php?pid=1420279#p1420279 this post] for an updated systemd sleep hook. <br />
<br />
A slightly updated version of the service is:<br />
{{hc|/etc/systemd/system/suspend-to-hibernate.service|<nowiki><br />
[Unit]<br />
Description=Delayed hibernation trigger<br />
Documentation=https://bbs.archlinux.org/viewtopic.php?pid=1420279#p1420279<br />
Documentation=https://wiki.archlinux.org/index.php/Power_management<br />
Before=suspend.target<br />
Conflicts=hibernate.target hybrid-suspend.target<br />
StopWhenUnneeded=true<br />
<br />
[Service]<br />
Type=oneshot<br />
RemainAfterExit=yes<br />
Environment="WAKEALARM=/sys/class/rtc/rtc0/wakealarm"<br />
Environment="SLEEPLENGTH=+2hour"<br />
ExecStart=-/usr/bin/sh -c 'echo -n "alarm set for "; date +%%s -d$SLEEPLENGTH | tee $WAKEALARM'<br />
ExecStop=-/usr/bin/sh -c '\<br />
alarm=$(cat $WAKEALARM); \<br />
now=$(date +%%s); \<br />
if [ -z "$alarm" ] || [ "$now" -ge "$alarm" ]; then \<br />
echo "hibernate triggered"; \<br />
systemctl hibernate; \<br />
else \<br />
echo "normal wakeup"; \<br />
fi; \<br />
echo 0 > $WAKEALARM; \<br />
'<br />
<br />
[Install]<br />
WantedBy=sleep.target<br />
</nowiki><br />
}}<br />
<br />
The {{ic|Before}} and {{ic|Conflicts}} options ensure it only is run for suspension and not hibernation--otherwise the service will run twice if delayed hibernation is triggered. The {{ic|WantedBy}} and {{ic|StopWhenUnneeded}} options are so it is started before sleep and stops upon resume. (Note that the {{ic|suspend.target}} and {{ic|hibernate.target}} targets do not stop when unneeded, but {{ic|sleep.target}} does). [[Enable]] the service.<br />
<br />
{{Note|1=See [https://bbs.archlinux.org/viewtopic.php?id=204346 suspend-to-hibernate broken since systemd-update] if you encounter problems with hibernating after an RTC wake up.}}<br />
<br />
==== Hooks in /usr/lib/systemd/system-sleep ====<br />
<br />
''systemd'' runs all executables in {{ic|/usr/lib/systemd/system-sleep/}}, passing two arguments to each of them:<br />
<br />
* Argument 1: either {{ic|pre}} or {{ic|post}}, depending on whether the machine is going to sleep or waking up<br />
* Argument 2: {{ic|suspend}}, {{ic|hibernate}} or {{ic|hybrid-sleep}}, depending on which is being invoked<br />
<br />
In contrast to [[pm-utils]], ''systemd'' will run these scripts concurrently and not one after another.<br />
<br />
The output of any custom script will be logged by ''systemd-suspend.service'', ''systemd-hibernate.service'' or ''systemd-hybrid-sleep.service''. You can see its output in ''systemd''<nowiki>'</nowiki>s [[systemd#Journal|journal]]:<br />
# journalctl -b -u systemd-suspend<br />
<br />
{{Note|You can also use ''sleep.target'', ''suspend.target'', ''hibernate.target'' or ''hybrid-sleep.target'' to hook units into the sleep state logic instead of using custom scripts.}}<br />
<br />
An example of a custom sleep script:<br />
<br />
{{hc|/usr/lib/systemd/system-sleep/example.sh|<br />
#!/bin/sh<br />
case $1/$2 in<br />
pre/*)<br />
echo "Going to $2..."<br />
;;<br />
post/*)<br />
echo "Waking up from $2..."<br />
;;<br />
esac}}<br />
<br />
Do not forget to make your script executable:<br />
# chmod a+x /usr/lib/systemd/system-sleep/example.sh<br />
<br />
See {{ic|man 7 systemd.special}} and {{ic|man 8 systemd-sleep}} for more details.<br />
<br />
=== Troubleshooting ===<br />
<br />
==== Delayed lid switch action ====<br />
<br />
When performing lid switches in short succession, ''logind'' will delay the suspend action for up to 90s to detect possible docks. [http://lists.freedesktop.org/archives/systemd-devel/2015-January/027131.html] This delay was made configurable with systemd v220:[https://github.com/systemd/systemd/commit/9d10cbee89ca7f82d29b9cb27bef11e23e3803ba]<br />
{{hc|/etc/systemd/logind.conf|<nowiki><br />
...<br />
HoldoffTimeoutSec=30s<br />
...<br />
</nowiki>}}<br />
<br />
==== Suspend from corresponding laptop Fn key not working ====<br />
<br />
If, regardless of the setting in logind.conf, the sleep button does not work (pressing it does not even produce a message in syslog), then logind is probably not watching the keyboard device. [http://lists.freedesktop.org/archives/systemd-devel/2015-February/028325.html] Do:<br />
# journalctl | grep "Watching system buttons"<br />
You might see something like this:<br />
May 25 21:28:19 vmarch.lan systemd-logind[210]: Watching system buttons on /dev/input/event2 (Power Button)<br />
May 25 21:28:19 vmarch.lan systemd-logind[210]: Watching system buttons on /dev/input/event3 (Sleep Button)<br />
May 25 21:28:19 vmarch.lan systemd-logind[210]: Watching system buttons on /dev/input/event4 (Video Bus)<br />
Notice no keyboard device. Now obtain ATTRS{name} for the parent keyboard device [http://systemd-devel.freedesktop.narkive.com/Rbi3rjNN/patch-1-2-logind-add-support-for-tps65217-power-button] :<br />
# udevadm info -a /dev/input/by-path/*-kbd<br />
...<br />
KERNEL=="event0"<br />
...<br />
ATTRS{name}=="AT Translated Set 2 keyboard"<br />
Now write a custom udev rule to add the "power-switch" tag:<br />
{{hc|/etc/udev/rules.d/70-power-switch-my.rules|<nowiki><br />
ACTION=="remove", GOTO="power_switch_my_end"<br />
SUBSYSTEM=="input", KERNEL=="event*", ATTRS{name}=="AT Translated Set 2 keyboard", TAG+="power-switch"<br />
LABEL="power_switch_my_end"<br />
</nowiki>}}<br />
Restart services and reload rules:<br />
# systemctl restart systemd-udevd<br />
# udevadm trigger<br />
# systemctl restart systemd-logind<br />
Now you should see "Watching system buttons on /dev/input/event0" in syslog<br />
<br />
== Power saving ==<br />
<br />
{{Note|See [[Laptop#Power management]] for power management specific to laptops, such as battery monitoring.}}<br />
<br />
This section is a reference for creating custom scripts and power saving settings such as by udev rules. Make sure that the settings are not managed by some [[#Userspace tools|other utility]] to avoid conflicts.<br />
<br />
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 />
=== 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 the following file for Intel soundcards.<br />
<br />
{{hc|/etc/modprobe.d/audio_powersave.conf|2=options snd_hda_intel power_save=1}}<br />
<br />
Alternatively, use the following for ac97:<br />
<br />
options snd_ac97_codec power_save=1<br />
<br />
{{Note|<br />
* To retrieve the manufacturer and the corresponding kernel driver which is used for your sound card, run {{ic|lspci -k}}.<br />
* Toggling the audio card's power state can cause a popping sound or noticeable latency on some broken hardware.<br />
}}<br />
<br />
It is also possible to further reduce the audio power requirements by disabling the HDMI audio output, which can done by [[blacklisting]] the appropriate kernel modules (e.g. {{ic|snd_hda_codec_hdmi}} in case of Intel 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, [[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 [[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 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 />
Note that this value is modified as a side effect of the Laptop Mode setting below.<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 />
{{Note|You need to install {{Pkg|ethtool}} for the above to take effect.}}<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 />
{{Note|You need to install {{Pkg|iw}} for the above to take effect.}}<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 />
{{Note|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-setup-link.rules}} in systemd, it is important that the network powersave rules are named lexicographically before {{ic|80-net-setup-link.rules}} so that they are applied before the devices are named e.g. {{ic|enp2s0}}.<br />
<br />
However, be advised that commands ran with {{ic|RUN}} are executed '''after''' all rules have been processed -- in which case the naming of the rules file is irrelevant and the persistent device names should be used (the persistent device name can be referenced by replacing {{ic|%k}} with {{ic|$name}}).}}<br />
<br />
==== Intel wireless cards (iwlwifi) ====<br />
<br />
Additional power saving functions of Intel wireless cards with {{ic|iwlwifi}} driver can be enabled by passing the correct parameters to the kernel module. Making it persistent can be achieved by adding the line below to {{ic|/etc/modprobe.d/iwlwifi.conf}} file:<br />
<br />
options iwlwifi power_save=1 d0i3_disable=0 uapsd_disable=0<br />
<br />
And another one to the {{ic|/etc/modprobe.d/iwldvm.conf}} file:<br />
<br />
options iwldvm force_cam=0<br />
<br />
Keep in mind that these power saving options are experimental and can cause an unstable system.<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 />
* This forces ASPM in kernel while it can still remain disabled in hardware and not work. To check whether this is the case the {{ic|dmesg &#124; grep ASPM}} command can be used and if that is the case, hardware-specific Wiki article should be consulted.<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 />
==== 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. For example, the Lenovo T440s [http://lkml.indiana.edu/hypermail/linux/kernel/1401.2/02171.html is known to suffer] from this problem. Do not enable this setting unless you have frequent backups.}}<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 [[Improving performance#Storage devices]] for other tips.<br />
<br />
Also little things like setting the [[Fstab#atime options|noatime]] option can help. If enough RAM is available, consider disabling or limiting [[swappiness]] as it has the possibility to limit a good number of disk writes.<br />
<br />
=== CD-ROM or DVD drive === <br />
<br />
See [[Udisks#Devices do not remain unmounted (udisks)]].<br />
<br />
== Tools and scripts ==<br />
<br />
{{Style|Merged from [[Power saving]], needs reorganization to fit into this page.}}<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:<br />
<br />
* [https://github.com/supplantr/ftw ftw], package: {{AUR|ftw-git}}{{Broken package link|{{aur-mirror|ftw-git}}}}<br />
* [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 />
* [https://wiki.ubuntu.com/Kernel/PowerManagement/PowerSavingTweaks Ubuntu Wiki's Power Saving Tweaks]<br />
* [http://ivanvojtko.blogspot.sk/2016/04/how-to-get-longer-battery-life-on-linux.html How to get longer battery life on Linux]</div>X33ahttps://wiki.archlinux.org/index.php?title=Power_management&diff=469820Power management2017-03-05T10:11:58Z<p>X33a: /* SATA Active Link Power Management */ removed stray )</p>
<hr />
<div>[[Category:Power management]]<br />
[[es:Power management]]<br />
[[it:Shutdown Pressing Power Button]]<br />
[[ja:電源管理]]<br />
[[uk:Shutdown Pressing Power Button]]<br />
[[zh-hans:Power management]]<br />
{{Related articles start}}<br />
{{Related|Power management/Suspend and hibernate}}<br />
{{Related|Display Power Management Signaling}}<br />
{{Related|CPU frequency scaling}}<br />
{{Related|Hybrid graphics}}<br />
{{Related|Kernel modules}}<br />
{{Related|sysctl}}<br />
{{Related|udev}}<br />
{{Related articles end}}<br />
<br />
[[Wikipedia:Power management|Power management]] is a feature that turns off the power or switches system's components to a low-power state when inactive.<br />
<br />
In Arch Linux, power management consists of two main parts:<br />
<br />
# Configuration of the Linux kernel, which interacts with the hardware.<br />
#* [[Kernel parameters]]<br />
#* [[Kernel modules]]<br />
#* [[udev]] rules<br />
# Configuration of userspace tools, which interact with the kernel and react to its events. Many userspace tools also allow to modify kernel configuration in a "user-friendly" way. See [[#Userspace tools]] for the options.<br />
<br />
== Userspace tools ==<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|aclidswitch| Simple Power Management tool to define custom lid, brightness and low battery actions depending on the laptop's AC state.|https://github.com/orschiro/aclidswitch|{{AUR|aclidswitch-git}}}}<br />
* {{App|[[acpid]]| A daemon for delivering ACPI power management events with netlink support.|http://sourceforge.net/projects/acpid2/|{{Pkg|acpid}}}}<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|{{AUR|laptop-mode-tools}}}}<br />
* {{App|[[pm-utils]]|Suspend and powerstate setting framework (largely undeveloped now).|http://pm-utils.freedesktop.org/|{{Pkg|pm-utils}}{{Broken package link|package not found}}}}<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 />
* [[systemd]]<br />
* {{App|[[TLP]]|Advanced power management for Linux.|http://linrunner.de/tlp|{{Pkg|tlp}}}}<br />
<br />
== Power management with systemd ==<br />
<br />
=== ACPI events ===<br />
<br />
''systemd'' handles some power-related [[Wikipedia:Advanced_Configuration_and_Power_Interface|ACPI]] events, whose actions can be configured in {{ic|/etc/systemd/logind.conf}} or {{ic|/etc/systemd/logind.conf.d/*.conf}} — see {{ic|man logind.conf}}. On systems with no dedicated power manager, this may replace the [[acpid]] daemon which is usually used to react to these ACPI events.<br />
<br />
The specified action for each event can be one of {{ic|ignore}}, {{ic|poweroff}}, {{ic|reboot}}, {{ic|halt}}, {{ic|suspend}}, {{ic|hibernate}}, {{ic|hybrid-sleep}}, {{ic|lock}} or {{ic|kexec}}. In case of hibernation and suspension, they must be properly [[Power management/Suspend and hibernate|set up]]. If an event is not configured, ''systemd'' will use a default action.<br />
<br />
{| class="wikitable sortable" border=1<br />
!Event handler<br />
!Description<br />
!Default action<br />
|-<br />
|{{ic|HandlePowerKey}}<br />
|Triggered when the power key/button is pressed.<br />
|{{ic|poweroff}}<br />
|-<br />
|{{ic|HandleSuspendKey}}<br />
|Triggered when the suspend key/button is pressed.<br />
|{{ic|suspend}}<br />
|-<br />
|{{ic|HandleHibernateKey}}<br />
|Triggered when the hibernate key/button is pressed.<br />
|{{ic|hibernate}}<br />
|-<br />
|{{ic|HandleLidSwitch}}<br />
|Triggered when the lid is closed, except in the cases below.<br />
|{{ic|suspend}}<br />
|-<br />
|{{ic|HandleLidSwitchDocked}}<br />
|Triggered when the lid is closed if the system is inserted in a docking station, or more than one display is connected.<br />
|{{ic|ignore}}<br />
|}<br />
<br />
To apply any changes, [[restart]] the {{ic|systemd-logind}} daemon (be warned that this will terminate all login sessions that might still be open).<br />
<br />
{{Note|''systemd'' cannot handle AC and Battery ACPI events, so if you use [[Laptop Mode Tools]] or other similar tools [[acpid]] is still required.}}<br />
<br />
==== Power managers ====<br />
<br />
Some [[desktop environment]]s include power managers which [http://www.freedesktop.org/wiki/Software/systemd/inhibit/ inhibit] (temporarily turn off) some or all of the ''systemd'' ACPI settings. If such a power manager is running, then the actions for ACPI events can be configured in the power manager alone. Changes to {{ic|/etc/systemd/logind.conf}} or {{ic|/etc/systemd/logind.conf.d/*.conf}} need be made only if you wish to configure behaviour for a particular event that is not inhibited by the power manager. <br />
<br />
Note that if the power manager does not inhibit ''systemd'' for the appropriate events you can end up with a situation where ''systemd'' suspends your system and then when the system is woken up the other power manager suspends it again. As of December 2016, the power managers of [[KDE]], [[GNOME]], [[Xfce]] and [[MATE]] issue the necessary ''inhibited'' commands. If the ''inhibited'' commands are not being issued, such as when using [[acpid]] or others to handle ACPI events, set the {{ic|Handle}} options to {{ic|ignore}}. See also {{ic|man systemd-inhibit}}.<br />
<br />
==== xss-lock ====<br />
<br />
{{AUR|xss-lock-git}} subscribes to the systemd-events {{ic|suspend}}, {{ic|hibernate}}, {{ic|lock-session}}, and {{ic|unlock-session}} with appropriate actions (run locker and wait for user to unlock or kill locker). ''xss-lock'' also reacts to [[DPMS]] events and runs or kills the locker in response.<br />
<br />
Start xss-lock in your [[autostart]], for example<br />
<br />
xss-lock -- i3lock -n -i ''background_image.png'' &<br />
<br />
=== Suspend and hibernate ===<br />
<br />
''systemd'' provides commands for suspend to RAM, hibernate and a hybrid suspend using the kernel's native suspend/resume functionality. There are also mechanisms to add hooks to customize pre- and post-suspend actions.<br />
<br />
{{Note|''systemd'' can also use other suspend backends (such as [[Uswsusp]] or [[TuxOnIce]]), in addition to the default ''kernel'' backend, in order to put the computer to sleep or hibernate. See [[Uswsusp#With systemd]] for an example.}}<br />
<br />
{{ic|systemctl suspend}} should work out of the box, for {{ic|systemctl hibernate}} to work on your system you need to follow the instructions at [[Suspend and hibernate#Hibernation]].<br />
<br />
==== Hybrid sleep ====<br />
<br />
{{ic|systemctl hybrid-sleep}} both hibernates and suspends at the same time. This combines some of the benefits and drawbacks of suspension and hibernation. This is useful in case a computer were to suddenly lose power (AC disconnection or battery depletion) since upon powerup it will resume from hibernation. If there is no power loss, then it will resume from suspension, which is much faster than resuming from hibernation. However, since "hybrid-sleep" has to dump memory to swap in order for hibernation to work, it is slower to enter sleep than a plain {{ic|systemctl suspend}}. An alternative is a [[#Delayed_hibernation_service_file|delayed hibernation service file]].<br />
<br />
=== Sleep hooks ===<br />
<br />
''systemd'' does not use [[pm-utils]] to put the machine to sleep when using {{ic|systemctl suspend}}, {{ic|systemctl hibernate}} or {{ic|systemctl hybrid-sleep}}; ''pm-utils'' hooks, including any [[Pm-utils#Creating_your_own_hooks|custom hooks]], will not be run. However, ''systemd'' provides two similar mechanisms to run custom scripts on these events.<br />
<br />
==== Suspend/resume service files ====<br />
<br />
Service files can be hooked into ''suspend.target'', ''hibernate.target'' and ''sleep.target'' to execute actions before or after suspend/hibernate. Separate files should be created for user actions and root/system actions. [[Enable]] the {{ic|suspend@''user''}} and {{ic|resume@''user''}} services to have them started at boot. Examples:<br />
<br />
{{hc|/etc/systemd/system/suspend@.service|2=<nowiki><br />
[Unit]<br />
Description=User suspend actions<br />
Before=sleep.target<br />
<br />
[Service]<br />
User=%I<br />
Type=simple<br />
Environment=DISPLAY=:0<br />
ExecStartPre= -/usr/bin/pkill -u %u unison ; /usr/local/bin/music.sh stop ; /usr/bin/mysql -e 'slave stop'<br />
ExecStart=/usr/bin/sflock<br />
ExecStartPost=/usr/bin/sleep 1<br />
<br />
[Install]<br />
WantedBy=sleep.target</nowiki>}}<br />
<br />
{{hc|/etc/systemd/system/resume@.service|2=<nowiki><br />
[Unit]<br />
Description=User resume actions<br />
After=suspend.target<br />
<br />
[Service]<br />
User=%I<br />
Type=simple<br />
ExecStartPre=/usr/local/bin/ssh-connect.sh<br />
ExecStart=/usr/bin/mysql -e 'slave start'<br />
<br />
[Install]<br />
WantedBy=suspend.target</nowiki>}}<br />
<br />
{{Note|As screen lockers may return before the screen is "locked", the screen may flash on resuming from suspend. Adding a small delay via {{ic|1=ExecStartPost=/usr/bin/sleep 1}} helps prevent this.}}<br />
<br />
For root/system actions ([[enable]] the {{ic|root-resume}} and {{ic|root-suspend}} services to have them started at boot):<br />
<br />
{{hc|/etc/systemd/system/root-resume.service|2=<nowiki><br />
[Unit]<br />
Description=Local system resume actions<br />
After=suspend.target<br />
<br />
[Service]<br />
Type=simple<br />
ExecStart=/usr/bin/systemctl restart mnt-media.automount<br />
<br />
[Install]<br />
WantedBy=suspend.target</nowiki>}}<br />
<br />
{{hc|/etc/systemd/system/root-suspend.service|2=<nowiki><br />
[Unit]<br />
Description=Local system suspend actions<br />
Before=sleep.target<br />
<br />
[Service]<br />
Type=simple<br />
ExecStart=-/usr/bin/pkill sshfs<br />
<br />
[Install]<br />
WantedBy=sleep.target</nowiki>}}<br />
<br />
A couple of handy hints about these service files (more in {{ic|man systemd.service}}):<br />
* If {{ic|1=<nowiki>Type=oneshot</nowiki>}} then you can use multiple {{ic|1=<nowiki>ExecStart=</nowiki>}} lines. Otherwise only one {{ic|ExecStart}} line is allowed. You can add more commands with either {{ic|ExecStartPre}} or by separating commands with a semicolon (see the first example above; note the spaces before and after the semicolon, as they are ''required'').<br />
* A command prefixed with {{ic|-}} will cause a non-zero exit status to be ignored and treated as a successful command. <br />
* The best place to find errors when troubleshooting these service files is of course with [[journalctl]].<br />
<br />
==== Combined Suspend/resume service file ====<br />
<br />
With the combined suspend/resume service file, a single hook does all the work for different phases (sleep/resume) and for different targets (suspend/hibernate/hybrid-sleep).<br />
<br />
Example and explanation:<br />
<br />
{{hc|/etc/systemd/system/wicd-sleep.service|2=<nowiki><br />
[Unit]<br />
Description=Wicd sleep hook<br />
Before=sleep.target<br />
StopWhenUnneeded=yes<br />
<br />
[Service]<br />
Type=oneshot<br />
RemainAfterExit=yes<br />
ExecStart=-/usr/share/wicd/daemon/suspend.py<br />
ExecStop=-/usr/share/wicd/daemon/autoconnect.py<br />
<br />
[Install]<br />
WantedBy=sleep.target</nowiki>}}<br />
<br />
* {{ic|1=<nowiki>RemainAfterExit=yes</nowiki>}}: After started, the service is considered active until it is explicitly stopped.<br />
* {{ic|1=<nowiki>StopWhenUnneeded=yes</nowiki>}}: When active, the service will be stopped if no other active service requires it. In this specific example, it will be stopped after ''sleep.target'' is stopped.<br />
* Because ''sleep.target'' is pulled in by ''suspend.target'', ''hibernate.target'' and ''hybrid-sleep.target'' and because ''sleep.target'' itself is a ''StopWhenUnneeded'' service, the hook is guaranteed to start/stop properly for different tasks.<br />
<br />
==== Delayed hibernation service file ====<br />
<br />
An alternative approach is delayed hibernation. This makes use of sleep hooks to suspend as usual but sets a timer to wake up later to perform hibernation. Here, entering sleep is faster than {{ic|systemctl hybrid-sleep}} since no hibernation is performed initially. However, unlike "hybrid-sleep", at this point there is no protection against power loss via hibernation while in suspension. This caveat makes this approach more suitable for laptops than desktops. Since hibernation is delayed, the laptop battery is only used during suspension and to trigger the eventual hibernation. This uses less power over the long-term than a "hybrid-sleep" which will remain suspended until the battery is drained. Note that if your laptop has a spinning hard disk, when it wakes up from suspend in order to hibernate, you may not want to be moving or carrying the laptop for these few seconds. Delayed hibernation may be desirable both to reduce power use as well as for security reasons (e.g. when using full disk encryption). An example script is located [http://superuser.com/questions/298672/linuxhow-to-hibernate-after-a-period-of-sleep here]. See also [https://bbs.archlinux.org/viewtopic.php?pid=1420279#p1420279 this post] for an updated systemd sleep hook. <br />
<br />
A slightly updated version of the service is:<br />
{{hc|/etc/systemd/system/suspend-to-hibernate.service|<nowiki><br />
[Unit]<br />
Description=Delayed hibernation trigger<br />
Documentation=https://bbs.archlinux.org/viewtopic.php?pid=1420279#p1420279<br />
Documentation=https://wiki.archlinux.org/index.php/Power_management<br />
Before=suspend.target<br />
Conflicts=hibernate.target hybrid-suspend.target<br />
StopWhenUnneeded=true<br />
<br />
[Service]<br />
Type=oneshot<br />
RemainAfterExit=yes<br />
Environment="WAKEALARM=/sys/class/rtc/rtc0/wakealarm"<br />
Environment="SLEEPLENGTH=+2hour"<br />
ExecStart=-/usr/bin/sh -c 'echo -n "alarm set for "; date +%%s -d$SLEEPLENGTH | tee $WAKEALARM'<br />
ExecStop=-/usr/bin/sh -c '\<br />
alarm=$(cat $WAKEALARM); \<br />
now=$(date +%%s); \<br />
if [ -z "$alarm" ] || [ "$now" -ge "$alarm" ]; then \<br />
echo "hibernate triggered"; \<br />
systemctl hibernate; \<br />
else \<br />
echo "normal wakeup"; \<br />
fi; \<br />
echo 0 > $WAKEALARM; \<br />
'<br />
<br />
[Install]<br />
WantedBy=sleep.target<br />
</nowiki><br />
}}<br />
<br />
The {{ic|Before}} and {{ic|Conflicts}} options ensure it only is run for suspension and not hibernation--otherwise the service will run twice if delayed hibernation is triggered. The {{ic|WantedBy}} and {{ic|StopWhenUnneeded}} options are so it is started before sleep and stops upon resume. (Note that the {{ic|suspend.target}} and {{ic|hibernate.target}} targets do not stop when unneeded, but {{ic|sleep.target}} does). [[Enable]] the service.<br />
<br />
{{Note|1=See [https://bbs.archlinux.org/viewtopic.php?id=204346 suspend-to-hibernate broken since systemd-update] if you encounter problems with hibernating after an RTC wake up.}}<br />
<br />
==== Hooks in /usr/lib/systemd/system-sleep ====<br />
<br />
''systemd'' runs all executables in {{ic|/usr/lib/systemd/system-sleep/}}, passing two arguments to each of them:<br />
<br />
* Argument 1: either {{ic|pre}} or {{ic|post}}, depending on whether the machine is going to sleep or waking up<br />
* Argument 2: {{ic|suspend}}, {{ic|hibernate}} or {{ic|hybrid-sleep}}, depending on which is being invoked<br />
<br />
In contrast to [[pm-utils]], ''systemd'' will run these scripts concurrently and not one after another.<br />
<br />
The output of any custom script will be logged by ''systemd-suspend.service'', ''systemd-hibernate.service'' or ''systemd-hybrid-sleep.service''. You can see its output in ''systemd''<nowiki>'</nowiki>s [[systemd#Journal|journal]]:<br />
# journalctl -b -u systemd-suspend<br />
<br />
{{Note|You can also use ''sleep.target'', ''suspend.target'', ''hibernate.target'' or ''hybrid-sleep.target'' to hook units into the sleep state logic instead of using custom scripts.}}<br />
<br />
An example of a custom sleep script:<br />
<br />
{{hc|/usr/lib/systemd/system-sleep/example.sh|<br />
#!/bin/sh<br />
case $1/$2 in<br />
pre/*)<br />
echo "Going to $2..."<br />
;;<br />
post/*)<br />
echo "Waking up from $2..."<br />
;;<br />
esac}}<br />
<br />
Do not forget to make your script executable:<br />
# chmod a+x /usr/lib/systemd/system-sleep/example.sh<br />
<br />
See {{ic|man 7 systemd.special}} and {{ic|man 8 systemd-sleep}} for more details.<br />
<br />
=== Troubleshooting ===<br />
<br />
==== Delayed lid switch action ====<br />
<br />
When performing lid switches in short succession, ''logind'' will delay the suspend action for up to 90s to detect possible docks. [http://lists.freedesktop.org/archives/systemd-devel/2015-January/027131.html] This delay was made configurable with systemd v220:[https://github.com/systemd/systemd/commit/9d10cbee89ca7f82d29b9cb27bef11e23e3803ba]<br />
{{hc|/etc/systemd/logind.conf|<nowiki><br />
...<br />
HoldoffTimeoutSec=30s<br />
...<br />
</nowiki>}}<br />
<br />
==== Suspend from corresponding laptop Fn key not working ====<br />
<br />
If, regardless of the setting in logind.conf, the sleep button does not work (pressing it does not even produce a message in syslog), then logind is probably not watching the keyboard device. [http://lists.freedesktop.org/archives/systemd-devel/2015-February/028325.html] Do:<br />
# journalctl | grep "Watching system buttons"<br />
You might see something like this:<br />
May 25 21:28:19 vmarch.lan systemd-logind[210]: Watching system buttons on /dev/input/event2 (Power Button)<br />
May 25 21:28:19 vmarch.lan systemd-logind[210]: Watching system buttons on /dev/input/event3 (Sleep Button)<br />
May 25 21:28:19 vmarch.lan systemd-logind[210]: Watching system buttons on /dev/input/event4 (Video Bus)<br />
Notice no keyboard device. Now obtain ATTRS{name} for the parent keyboard device [http://systemd-devel.freedesktop.narkive.com/Rbi3rjNN/patch-1-2-logind-add-support-for-tps65217-power-button] :<br />
# udevadm info -a /dev/input/by-path/*-kbd<br />
...<br />
KERNEL=="event0"<br />
...<br />
ATTRS{name}=="AT Translated Set 2 keyboard"<br />
Now write a custom udev rule to add the "power-switch" tag:<br />
{{hc|/etc/udev/rules.d/70-power-switch-my.rules|<nowiki><br />
ACTION=="remove", GOTO="power_switch_my_end"<br />
SUBSYSTEM=="input", KERNEL=="event*", ATTRS{name}=="AT Translated Set 2 keyboard", TAG+="power-switch"<br />
LABEL="power_switch_my_end"<br />
</nowiki>}}<br />
Restart services and reload rules:<br />
# systemctl restart systemd-udevd<br />
# udevadm trigger<br />
# systemctl restart systemd-logind<br />
Now you should see "Watching system buttons on /dev/input/event0" in syslog<br />
<br />
== Power saving ==<br />
<br />
{{Note|See [[Laptop#Power management]] for power management specific to laptops, such as battery monitoring.}}<br />
<br />
This section is a reference for creating custom scripts and power saving settings such as by udev rules. Make sure that the settings are not managed by some [[#Userspace tools|other utility]] to avoid conflicts.<br />
<br />
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 />
=== 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 the following file for Intel soundcards.<br />
<br />
{{hc|/etc/modprobe.d/audio_powersave.conf|2=options snd_hda_intel power_save=1}}<br />
<br />
Alternatively, use the following for ac97:<br />
<br />
options snd_ac97_codec power_save=1<br />
<br />
{{Note|<br />
* To retrieve the manufacturer and the corresponding kernel driver which is used for your sound card, run {{ic|lspci -k}}.<br />
* Toggling the audio card's power state can cause a popping sound or noticeable latency on some broken hardware.<br />
}}<br />
<br />
It is also possible to further reduce the audio power requirements by disabling the HDMI audio output, which can done by [[blacklisting]] the appropriate kernel modules (e.g. {{ic|snd_hda_codec_hdmi}} in case of Intel 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, [[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 [[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 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 />
Note that this value is modified as a side effect of the Laptop Mode setting below.<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 />
{{Note|You need to install {{Pkg|ethtool}} for the above to take effect.}}<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 />
{{Note|You need to install {{Pkg|iw}} for the above to take effect.}}<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 />
{{Note|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-setup-link.rules}} in systemd, it is important that the network powersave rules are named lexicographically before {{ic|80-net-setup-link.rules}} so that they are applied before the devices are named e.g. {{ic|enp2s0}}.<br />
<br />
However, be advised that commands ran with {{ic|RUN}} are executed '''after''' all rules have been processed -- in which case the naming of the rules file is irrelevant and the persistent device names should be used (the persistent device name can be referenced by replacing {{ic|%k}} with {{ic|$name}}).}}<br />
<br />
==== Intel wireless cards (iwlwifi) ====<br />
<br />
Additional power saving functions of Intel wireless cards with {{ic|iwlwifi}} driver can be enabled by passing the correct parameters to the kernel module. Making it persistent can be achieved by adding the line below to {{ic|/etc/modprobe.d/iwlwifi.conf}} file:<br />
<br />
options iwlwifi power_save=1 d0i3_disable=0 uapsd_disable=0<br />
<br />
And another one to the {{ic|/etc/modprobe.d/iwldvm.conf}} file:<br />
<br />
options iwldvm force_cam=0<br />
<br />
Keep in mind that these power saving options are experimental and can cause an unstable system.<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 />
* This forces ASPM in kernel while it can still remain disabled in hardware and not work. To check whether this is the case the {{ic|dmesg &#124; grep ASPM}} command can be used and if that is the case, hardware-specific Wiki article should be consulted.<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 />
==== 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. Issue is still verified to occur on Linux kernel version 4.5.1. Do not enable this setting unless you have frequent backups.}}<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 [[Improving performance#Storage devices]] for other tips.<br />
<br />
Also little things like setting the [[Fstab#atime options|noatime]] option can help. If enough RAM is available, consider disabling or limiting [[swappiness]] as it has the possibility to limit a good number of disk writes.<br />
<br />
=== CD-ROM or DVD drive === <br />
<br />
See [[Udisks#Devices do not remain unmounted (udisks)]].<br />
<br />
== Tools and scripts ==<br />
<br />
{{Style|Merged from [[Power saving]], needs reorganization to fit into this page.}}<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:<br />
<br />
* [https://github.com/supplantr/ftw ftw], package: {{AUR|ftw-git}}{{Broken package link|{{aur-mirror|ftw-git}}}}<br />
* [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 />
* [https://wiki.ubuntu.com/Kernel/PowerManagement/PowerSavingTweaks Ubuntu Wiki's Power Saving Tweaks]<br />
* [http://ivanvojtko.blogspot.sk/2016/04/how-to-get-longer-battery-life-on-linux.html How to get longer battery life on Linux]</div>X33ahttps://wiki.archlinux.org/index.php?title=Power_management&diff=469819Power management2017-03-05T10:10:23Z<p>X33a: /* Network interfaces */ add a note for the packages required</p>
<hr />
<div>[[Category:Power management]]<br />
[[es:Power management]]<br />
[[it:Shutdown Pressing Power Button]]<br />
[[ja:電源管理]]<br />
[[uk:Shutdown Pressing Power Button]]<br />
[[zh-hans:Power management]]<br />
{{Related articles start}}<br />
{{Related|Power management/Suspend and hibernate}}<br />
{{Related|Display Power Management Signaling}}<br />
{{Related|CPU frequency scaling}}<br />
{{Related|Hybrid graphics}}<br />
{{Related|Kernel modules}}<br />
{{Related|sysctl}}<br />
{{Related|udev}}<br />
{{Related articles end}}<br />
<br />
[[Wikipedia:Power management|Power management]] is a feature that turns off the power or switches system's components to a low-power state when inactive.<br />
<br />
In Arch Linux, power management consists of two main parts:<br />
<br />
# Configuration of the Linux kernel, which interacts with the hardware.<br />
#* [[Kernel parameters]]<br />
#* [[Kernel modules]]<br />
#* [[udev]] rules<br />
# Configuration of userspace tools, which interact with the kernel and react to its events. Many userspace tools also allow to modify kernel configuration in a "user-friendly" way. See [[#Userspace tools]] for the options.<br />
<br />
== Userspace tools ==<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|aclidswitch| Simple Power Management tool to define custom lid, brightness and low battery actions depending on the laptop's AC state.|https://github.com/orschiro/aclidswitch|{{AUR|aclidswitch-git}}}}<br />
* {{App|[[acpid]]| A daemon for delivering ACPI power management events with netlink support.|http://sourceforge.net/projects/acpid2/|{{Pkg|acpid}}}}<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|{{AUR|laptop-mode-tools}}}}<br />
* {{App|[[pm-utils]]|Suspend and powerstate setting framework (largely undeveloped now).|http://pm-utils.freedesktop.org/|{{Pkg|pm-utils}}{{Broken package link|package not found}}}}<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 />
* [[systemd]]<br />
* {{App|[[TLP]]|Advanced power management for Linux.|http://linrunner.de/tlp|{{Pkg|tlp}}}}<br />
<br />
== Power management with systemd ==<br />
<br />
=== ACPI events ===<br />
<br />
''systemd'' handles some power-related [[Wikipedia:Advanced_Configuration_and_Power_Interface|ACPI]] events, whose actions can be configured in {{ic|/etc/systemd/logind.conf}} or {{ic|/etc/systemd/logind.conf.d/*.conf}} — see {{ic|man logind.conf}}. On systems with no dedicated power manager, this may replace the [[acpid]] daemon which is usually used to react to these ACPI events.<br />
<br />
The specified action for each event can be one of {{ic|ignore}}, {{ic|poweroff}}, {{ic|reboot}}, {{ic|halt}}, {{ic|suspend}}, {{ic|hibernate}}, {{ic|hybrid-sleep}}, {{ic|lock}} or {{ic|kexec}}. In case of hibernation and suspension, they must be properly [[Power management/Suspend and hibernate|set up]]. If an event is not configured, ''systemd'' will use a default action.<br />
<br />
{| class="wikitable sortable" border=1<br />
!Event handler<br />
!Description<br />
!Default action<br />
|-<br />
|{{ic|HandlePowerKey}}<br />
|Triggered when the power key/button is pressed.<br />
|{{ic|poweroff}}<br />
|-<br />
|{{ic|HandleSuspendKey}}<br />
|Triggered when the suspend key/button is pressed.<br />
|{{ic|suspend}}<br />
|-<br />
|{{ic|HandleHibernateKey}}<br />
|Triggered when the hibernate key/button is pressed.<br />
|{{ic|hibernate}}<br />
|-<br />
|{{ic|HandleLidSwitch}}<br />
|Triggered when the lid is closed, except in the cases below.<br />
|{{ic|suspend}}<br />
|-<br />
|{{ic|HandleLidSwitchDocked}}<br />
|Triggered when the lid is closed if the system is inserted in a docking station, or more than one display is connected.<br />
|{{ic|ignore}}<br />
|}<br />
<br />
To apply any changes, [[restart]] the {{ic|systemd-logind}} daemon (be warned that this will terminate all login sessions that might still be open).<br />
<br />
{{Note|''systemd'' cannot handle AC and Battery ACPI events, so if you use [[Laptop Mode Tools]] or other similar tools [[acpid]] is still required.}}<br />
<br />
==== Power managers ====<br />
<br />
Some [[desktop environment]]s include power managers which [http://www.freedesktop.org/wiki/Software/systemd/inhibit/ inhibit] (temporarily turn off) some or all of the ''systemd'' ACPI settings. If such a power manager is running, then the actions for ACPI events can be configured in the power manager alone. Changes to {{ic|/etc/systemd/logind.conf}} or {{ic|/etc/systemd/logind.conf.d/*.conf}} need be made only if you wish to configure behaviour for a particular event that is not inhibited by the power manager. <br />
<br />
Note that if the power manager does not inhibit ''systemd'' for the appropriate events you can end up with a situation where ''systemd'' suspends your system and then when the system is woken up the other power manager suspends it again. As of December 2016, the power managers of [[KDE]], [[GNOME]], [[Xfce]] and [[MATE]] issue the necessary ''inhibited'' commands. If the ''inhibited'' commands are not being issued, such as when using [[acpid]] or others to handle ACPI events, set the {{ic|Handle}} options to {{ic|ignore}}. See also {{ic|man systemd-inhibit}}.<br />
<br />
==== xss-lock ====<br />
<br />
{{AUR|xss-lock-git}} subscribes to the systemd-events {{ic|suspend}}, {{ic|hibernate}}, {{ic|lock-session}}, and {{ic|unlock-session}} with appropriate actions (run locker and wait for user to unlock or kill locker). ''xss-lock'' also reacts to [[DPMS]] events and runs or kills the locker in response.<br />
<br />
Start xss-lock in your [[autostart]], for example<br />
<br />
xss-lock -- i3lock -n -i ''background_image.png'' &<br />
<br />
=== Suspend and hibernate ===<br />
<br />
''systemd'' provides commands for suspend to RAM, hibernate and a hybrid suspend using the kernel's native suspend/resume functionality. There are also mechanisms to add hooks to customize pre- and post-suspend actions.<br />
<br />
{{Note|''systemd'' can also use other suspend backends (such as [[Uswsusp]] or [[TuxOnIce]]), in addition to the default ''kernel'' backend, in order to put the computer to sleep or hibernate. See [[Uswsusp#With systemd]] for an example.}}<br />
<br />
{{ic|systemctl suspend}} should work out of the box, for {{ic|systemctl hibernate}} to work on your system you need to follow the instructions at [[Suspend and hibernate#Hibernation]].<br />
<br />
==== Hybrid sleep ====<br />
<br />
{{ic|systemctl hybrid-sleep}} both hibernates and suspends at the same time. This combines some of the benefits and drawbacks of suspension and hibernation. This is useful in case a computer were to suddenly lose power (AC disconnection or battery depletion) since upon powerup it will resume from hibernation. If there is no power loss, then it will resume from suspension, which is much faster than resuming from hibernation. However, since "hybrid-sleep" has to dump memory to swap in order for hibernation to work, it is slower to enter sleep than a plain {{ic|systemctl suspend}}. An alternative is a [[#Delayed_hibernation_service_file|delayed hibernation service file]].<br />
<br />
=== Sleep hooks ===<br />
<br />
''systemd'' does not use [[pm-utils]] to put the machine to sleep when using {{ic|systemctl suspend}}, {{ic|systemctl hibernate}} or {{ic|systemctl hybrid-sleep}}; ''pm-utils'' hooks, including any [[Pm-utils#Creating_your_own_hooks|custom hooks]], will not be run. However, ''systemd'' provides two similar mechanisms to run custom scripts on these events.<br />
<br />
==== Suspend/resume service files ====<br />
<br />
Service files can be hooked into ''suspend.target'', ''hibernate.target'' and ''sleep.target'' to execute actions before or after suspend/hibernate. Separate files should be created for user actions and root/system actions. [[Enable]] the {{ic|suspend@''user''}} and {{ic|resume@''user''}} services to have them started at boot. Examples:<br />
<br />
{{hc|/etc/systemd/system/suspend@.service|2=<nowiki><br />
[Unit]<br />
Description=User suspend actions<br />
Before=sleep.target<br />
<br />
[Service]<br />
User=%I<br />
Type=simple<br />
Environment=DISPLAY=:0<br />
ExecStartPre= -/usr/bin/pkill -u %u unison ; /usr/local/bin/music.sh stop ; /usr/bin/mysql -e 'slave stop'<br />
ExecStart=/usr/bin/sflock<br />
ExecStartPost=/usr/bin/sleep 1<br />
<br />
[Install]<br />
WantedBy=sleep.target</nowiki>}}<br />
<br />
{{hc|/etc/systemd/system/resume@.service|2=<nowiki><br />
[Unit]<br />
Description=User resume actions<br />
After=suspend.target<br />
<br />
[Service]<br />
User=%I<br />
Type=simple<br />
ExecStartPre=/usr/local/bin/ssh-connect.sh<br />
ExecStart=/usr/bin/mysql -e 'slave start'<br />
<br />
[Install]<br />
WantedBy=suspend.target</nowiki>}}<br />
<br />
{{Note|As screen lockers may return before the screen is "locked", the screen may flash on resuming from suspend. Adding a small delay via {{ic|1=ExecStartPost=/usr/bin/sleep 1}} helps prevent this.}}<br />
<br />
For root/system actions ([[enable]] the {{ic|root-resume}} and {{ic|root-suspend}} services to have them started at boot):<br />
<br />
{{hc|/etc/systemd/system/root-resume.service|2=<nowiki><br />
[Unit]<br />
Description=Local system resume actions<br />
After=suspend.target<br />
<br />
[Service]<br />
Type=simple<br />
ExecStart=/usr/bin/systemctl restart mnt-media.automount<br />
<br />
[Install]<br />
WantedBy=suspend.target</nowiki>}}<br />
<br />
{{hc|/etc/systemd/system/root-suspend.service|2=<nowiki><br />
[Unit]<br />
Description=Local system suspend actions<br />
Before=sleep.target<br />
<br />
[Service]<br />
Type=simple<br />
ExecStart=-/usr/bin/pkill sshfs<br />
<br />
[Install]<br />
WantedBy=sleep.target</nowiki>}}<br />
<br />
A couple of handy hints about these service files (more in {{ic|man systemd.service}}):<br />
* If {{ic|1=<nowiki>Type=oneshot</nowiki>}} then you can use multiple {{ic|1=<nowiki>ExecStart=</nowiki>}} lines. Otherwise only one {{ic|ExecStart}} line is allowed. You can add more commands with either {{ic|ExecStartPre}} or by separating commands with a semicolon (see the first example above; note the spaces before and after the semicolon, as they are ''required'').<br />
* A command prefixed with {{ic|-}} will cause a non-zero exit status to be ignored and treated as a successful command. <br />
* The best place to find errors when troubleshooting these service files is of course with [[journalctl]].<br />
<br />
==== Combined Suspend/resume service file ====<br />
<br />
With the combined suspend/resume service file, a single hook does all the work for different phases (sleep/resume) and for different targets (suspend/hibernate/hybrid-sleep).<br />
<br />
Example and explanation:<br />
<br />
{{hc|/etc/systemd/system/wicd-sleep.service|2=<nowiki><br />
[Unit]<br />
Description=Wicd sleep hook<br />
Before=sleep.target<br />
StopWhenUnneeded=yes<br />
<br />
[Service]<br />
Type=oneshot<br />
RemainAfterExit=yes<br />
ExecStart=-/usr/share/wicd/daemon/suspend.py<br />
ExecStop=-/usr/share/wicd/daemon/autoconnect.py<br />
<br />
[Install]<br />
WantedBy=sleep.target</nowiki>}}<br />
<br />
* {{ic|1=<nowiki>RemainAfterExit=yes</nowiki>}}: After started, the service is considered active until it is explicitly stopped.<br />
* {{ic|1=<nowiki>StopWhenUnneeded=yes</nowiki>}}: When active, the service will be stopped if no other active service requires it. In this specific example, it will be stopped after ''sleep.target'' is stopped.<br />
* Because ''sleep.target'' is pulled in by ''suspend.target'', ''hibernate.target'' and ''hybrid-sleep.target'' and because ''sleep.target'' itself is a ''StopWhenUnneeded'' service, the hook is guaranteed to start/stop properly for different tasks.<br />
<br />
==== Delayed hibernation service file ====<br />
<br />
An alternative approach is delayed hibernation. This makes use of sleep hooks to suspend as usual but sets a timer to wake up later to perform hibernation. Here, entering sleep is faster than {{ic|systemctl hybrid-sleep}} since no hibernation is performed initially. However, unlike "hybrid-sleep", at this point there is no protection against power loss via hibernation while in suspension. This caveat makes this approach more suitable for laptops than desktops. Since hibernation is delayed, the laptop battery is only used during suspension and to trigger the eventual hibernation. This uses less power over the long-term than a "hybrid-sleep" which will remain suspended until the battery is drained. Note that if your laptop has a spinning hard disk, when it wakes up from suspend in order to hibernate, you may not want to be moving or carrying the laptop for these few seconds. Delayed hibernation may be desirable both to reduce power use as well as for security reasons (e.g. when using full disk encryption). An example script is located [http://superuser.com/questions/298672/linuxhow-to-hibernate-after-a-period-of-sleep here]. See also [https://bbs.archlinux.org/viewtopic.php?pid=1420279#p1420279 this post] for an updated systemd sleep hook. <br />
<br />
A slightly updated version of the service is:<br />
{{hc|/etc/systemd/system/suspend-to-hibernate.service|<nowiki><br />
[Unit]<br />
Description=Delayed hibernation trigger<br />
Documentation=https://bbs.archlinux.org/viewtopic.php?pid=1420279#p1420279<br />
Documentation=https://wiki.archlinux.org/index.php/Power_management<br />
Before=suspend.target<br />
Conflicts=hibernate.target hybrid-suspend.target<br />
StopWhenUnneeded=true<br />
<br />
[Service]<br />
Type=oneshot<br />
RemainAfterExit=yes<br />
Environment="WAKEALARM=/sys/class/rtc/rtc0/wakealarm"<br />
Environment="SLEEPLENGTH=+2hour"<br />
ExecStart=-/usr/bin/sh -c 'echo -n "alarm set for "; date +%%s -d$SLEEPLENGTH | tee $WAKEALARM'<br />
ExecStop=-/usr/bin/sh -c '\<br />
alarm=$(cat $WAKEALARM); \<br />
now=$(date +%%s); \<br />
if [ -z "$alarm" ] || [ "$now" -ge "$alarm" ]; then \<br />
echo "hibernate triggered"; \<br />
systemctl hibernate; \<br />
else \<br />
echo "normal wakeup"; \<br />
fi; \<br />
echo 0 > $WAKEALARM; \<br />
'<br />
<br />
[Install]<br />
WantedBy=sleep.target<br />
</nowiki><br />
}}<br />
<br />
The {{ic|Before}} and {{ic|Conflicts}} options ensure it only is run for suspension and not hibernation--otherwise the service will run twice if delayed hibernation is triggered. The {{ic|WantedBy}} and {{ic|StopWhenUnneeded}} options are so it is started before sleep and stops upon resume. (Note that the {{ic|suspend.target}} and {{ic|hibernate.target}} targets do not stop when unneeded, but {{ic|sleep.target}} does). [[Enable]] the service.<br />
<br />
{{Note|1=See [https://bbs.archlinux.org/viewtopic.php?id=204346 suspend-to-hibernate broken since systemd-update] if you encounter problems with hibernating after an RTC wake up.}}<br />
<br />
==== Hooks in /usr/lib/systemd/system-sleep ====<br />
<br />
''systemd'' runs all executables in {{ic|/usr/lib/systemd/system-sleep/}}, passing two arguments to each of them:<br />
<br />
* Argument 1: either {{ic|pre}} or {{ic|post}}, depending on whether the machine is going to sleep or waking up<br />
* Argument 2: {{ic|suspend}}, {{ic|hibernate}} or {{ic|hybrid-sleep}}, depending on which is being invoked<br />
<br />
In contrast to [[pm-utils]], ''systemd'' will run these scripts concurrently and not one after another.<br />
<br />
The output of any custom script will be logged by ''systemd-suspend.service'', ''systemd-hibernate.service'' or ''systemd-hybrid-sleep.service''. You can see its output in ''systemd''<nowiki>'</nowiki>s [[systemd#Journal|journal]]:<br />
# journalctl -b -u systemd-suspend<br />
<br />
{{Note|You can also use ''sleep.target'', ''suspend.target'', ''hibernate.target'' or ''hybrid-sleep.target'' to hook units into the sleep state logic instead of using custom scripts.}}<br />
<br />
An example of a custom sleep script:<br />
<br />
{{hc|/usr/lib/systemd/system-sleep/example.sh|<br />
#!/bin/sh<br />
case $1/$2 in<br />
pre/*)<br />
echo "Going to $2..."<br />
;;<br />
post/*)<br />
echo "Waking up from $2..."<br />
;;<br />
esac}}<br />
<br />
Do not forget to make your script executable:<br />
# chmod a+x /usr/lib/systemd/system-sleep/example.sh<br />
<br />
See {{ic|man 7 systemd.special}} and {{ic|man 8 systemd-sleep}} for more details.<br />
<br />
=== Troubleshooting ===<br />
<br />
==== Delayed lid switch action ====<br />
<br />
When performing lid switches in short succession, ''logind'' will delay the suspend action for up to 90s to detect possible docks. [http://lists.freedesktop.org/archives/systemd-devel/2015-January/027131.html] This delay was made configurable with systemd v220:[https://github.com/systemd/systemd/commit/9d10cbee89ca7f82d29b9cb27bef11e23e3803ba]<br />
{{hc|/etc/systemd/logind.conf|<nowiki><br />
...<br />
HoldoffTimeoutSec=30s<br />
...<br />
</nowiki>}}<br />
<br />
==== Suspend from corresponding laptop Fn key not working ====<br />
<br />
If, regardless of the setting in logind.conf, the sleep button does not work (pressing it does not even produce a message in syslog), then logind is probably not watching the keyboard device. [http://lists.freedesktop.org/archives/systemd-devel/2015-February/028325.html] Do:<br />
# journalctl | grep "Watching system buttons"<br />
You might see something like this:<br />
May 25 21:28:19 vmarch.lan systemd-logind[210]: Watching system buttons on /dev/input/event2 (Power Button)<br />
May 25 21:28:19 vmarch.lan systemd-logind[210]: Watching system buttons on /dev/input/event3 (Sleep Button)<br />
May 25 21:28:19 vmarch.lan systemd-logind[210]: Watching system buttons on /dev/input/event4 (Video Bus)<br />
Notice no keyboard device. Now obtain ATTRS{name} for the parent keyboard device [http://systemd-devel.freedesktop.narkive.com/Rbi3rjNN/patch-1-2-logind-add-support-for-tps65217-power-button] :<br />
# udevadm info -a /dev/input/by-path/*-kbd<br />
...<br />
KERNEL=="event0"<br />
...<br />
ATTRS{name}=="AT Translated Set 2 keyboard"<br />
Now write a custom udev rule to add the "power-switch" tag:<br />
{{hc|/etc/udev/rules.d/70-power-switch-my.rules|<nowiki><br />
ACTION=="remove", GOTO="power_switch_my_end"<br />
SUBSYSTEM=="input", KERNEL=="event*", ATTRS{name}=="AT Translated Set 2 keyboard", TAG+="power-switch"<br />
LABEL="power_switch_my_end"<br />
</nowiki>}}<br />
Restart services and reload rules:<br />
# systemctl restart systemd-udevd<br />
# udevadm trigger<br />
# systemctl restart systemd-logind<br />
Now you should see "Watching system buttons on /dev/input/event0" in syslog<br />
<br />
== Power saving ==<br />
<br />
{{Note|See [[Laptop#Power management]] for power management specific to laptops, such as battery monitoring.}}<br />
<br />
This section is a reference for creating custom scripts and power saving settings such as by udev rules. Make sure that the settings are not managed by some [[#Userspace tools|other utility]] to avoid conflicts.<br />
<br />
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 />
=== 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 the following file for Intel soundcards.<br />
<br />
{{hc|/etc/modprobe.d/audio_powersave.conf|2=options snd_hda_intel power_save=1}}<br />
<br />
Alternatively, use the following for ac97:<br />
<br />
options snd_ac97_codec power_save=1<br />
<br />
{{Note|<br />
* To retrieve the manufacturer and the corresponding kernel driver which is used for your sound card, run {{ic|lspci -k}}.<br />
* Toggling the audio card's power state can cause a popping sound or noticeable latency on some broken hardware.<br />
}}<br />
<br />
It is also possible to further reduce the audio power requirements by disabling the HDMI audio output, which can done by [[blacklisting]] the appropriate kernel modules (e.g. {{ic|snd_hda_codec_hdmi}} in case of Intel 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, [[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 [[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 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 />
Note that this value is modified as a side effect of the Laptop Mode setting below.<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 />
{{Note|You need to install {{Pkg|ethtool}} for the above to take effect.}}<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 />
{{Note|You need to install {{Pkg|iw}} for the above to take effect.}}<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 />
{{Note|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-setup-link.rules}} in systemd, it is important that the network powersave rules are named lexicographically before {{ic|80-net-setup-link.rules}} so that they are applied before the devices are named e.g. {{ic|enp2s0}}.<br />
<br />
However, be advised that commands ran with {{ic|RUN}} are executed '''after''' all rules have been processed -- in which case the naming of the rules file is irrelevant and the persistent device names should be used (the persistent device name can be referenced by replacing {{ic|%k}} with {{ic|$name}}).}}<br />
<br />
==== Intel wireless cards (iwlwifi) ====<br />
<br />
Additional power saving functions of Intel wireless cards with {{ic|iwlwifi}} driver can be enabled by passing the correct parameters to the kernel module. Making it persistent can be achieved by adding the line below to {{ic|/etc/modprobe.d/iwlwifi.conf}} file:<br />
<br />
options iwlwifi power_save=1 d0i3_disable=0 uapsd_disable=0<br />
<br />
And another one to the {{ic|/etc/modprobe.d/iwldvm.conf}} file:<br />
<br />
options iwldvm force_cam=0<br />
<br />
Keep in mind that these power saving options are experimental and can cause an unstable system.<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 />
* This forces ASPM in kernel while it can still remain disabled in hardware and not work. To check whether this is the case the {{ic|dmesg &#124; grep ASPM}} command can be used and if that is the case, hardware-specific Wiki article should be consulted.<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 />
==== 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. Issue is still verified to occur on Linux kernel version 4.5.1. Do not enable this setting unless you have frequent backups.)}}<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 [[Improving performance#Storage devices]] for other tips.<br />
<br />
Also little things like setting the [[Fstab#atime options|noatime]] option can help. If enough RAM is available, consider disabling or limiting [[swappiness]] as it has the possibility to limit a good number of disk writes.<br />
<br />
=== CD-ROM or DVD drive === <br />
<br />
See [[Udisks#Devices do not remain unmounted (udisks)]].<br />
<br />
== Tools and scripts ==<br />
<br />
{{Style|Merged from [[Power saving]], needs reorganization to fit into this page.}}<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:<br />
<br />
* [https://github.com/supplantr/ftw ftw], package: {{AUR|ftw-git}}{{Broken package link|{{aur-mirror|ftw-git}}}}<br />
* [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 />
* [https://wiki.ubuntu.com/Kernel/PowerManagement/PowerSavingTweaks Ubuntu Wiki's Power Saving Tweaks]<br />
* [http://ivanvojtko.blogspot.sk/2016/04/how-to-get-longer-battery-life-on-linux.html How to get longer battery life on Linux]</div>X33ahttps://wiki.archlinux.org/index.php?title=X_resources&diff=469809X resources2017-03-05T09:23:32Z<p>X33a: /* Include files */ gcc -> cpp</p>
<hr />
<div>[[Category:Dotfiles]]<br />
[[Category:X server]]<br />
[[de:Xdefaults]]<br />
[[ja:X resources]]<br />
[[ru:X resources]]<br />
'''Xresources''' is a user-level configuration ''dotfile'', typically located at {{ic|~/.Xresources}}. It can be used to set [[Wikipedia:X resources|X resources]], which are configuration parameters for X client applications.<br />
<br />
They can do many operations, including:<br />
<br />
* defining terminal colours<br />
* configuring terminal preferences<br />
* setting DPI, antialiasing, hinting and other X font settings<br />
* changing the Xcursor theme<br />
* theming xscreensaver<br />
* altering preferences on low-level X applications (xclock ({{Pkg|xorg-xclock}}), {{Pkg|xpdf}}, {{Pkg|rxvt-unicode}}, etc.)<br />
<br />
== Installation ==<br />
<br />
[[Install]] the {{pkg|xorg-xrdb}} package.<br />
<br />
== Usage ==<br />
<br />
=== Load resource file ===<br />
<br />
Resources are stored in the X server, so have to only be read once. They are also accessible to ''remote'' X11 clients (such as those forwarded over SSH).<br />
<br />
Load a resource file (such as the conventional {{ic|.Xresources}}), replacing any current settings:<br />
<br />
$ xrdb ''~/.Xresources''<br />
<br />
Load a resource file, and merge with the current settings:<br />
<br />
$ xrdb -merge ''~/.Xresources''<br />
<br />
{{Note|<br />
* Most [[Display manager]]s will load the {{ic|~/.Xresources}} file on login.<br />
* The older {{ic|~/.Xdefaults}} file is read when an X11 program starts, but only if ''xrdb'' has not been used in the current session. [https://groups.google.com/forum/#!msg/comp.windows.x/hQBEdql8l-Q/hF3DETcIHGwJ]<br />
}}<br />
<br />
=== xinitrc ===<br />
<br />
If you are using a copy of the default [[xinitrc]] as your {{ic|.xinitrc}} it already merges {{ic|~/.Xresources}}.<br />
<br />
If you are using a custom {{ic|.xinitrc}} add the following line:<br />
<br />
<nowiki>[[ -f ~/.Xresources ]] && xrdb -merge -I$HOME ~/.Xresources</nowiki><br />
<br />
{{Warning|Never background the xrdb command within {{ic|~/.xinitrc}}. Otherwise, programs launched after xrdb may look for resources before it has finished loading them.}}<br />
<br />
=== Default settings ===<br />
<br />
To see the default settings for your installed X11 apps, look in {{ic|/usr/share/X11/app-defaults/}}.<br />
<br />
Detailed information on program-specific resources is usually provided in the man page for the program. xterm's man page is a good example, as it contains a list of X resources and their default values.<br />
<br />
To see the current loaded resources:<br />
<br />
xrdb -query -all<br />
<br />
===Xresources syntax===<br />
<br />
====Basic syntax====<br />
<br />
The syntax of an Xresources file is as follows:<br />
'''name.Class.resource: value'''<br />
and here is a real world example:<br />
xscreensaver.Dialog.headingFont: -*-fixed-bold-r-*-*-*-100-*-*-*-*-iso8859-1<br />
<br />
;name<br />
:The name of the application, such as xterm, xpdf, etc<br />
<br />
;class<br />
:The classification used to group resources together. Class names are typically uppercase.<br />
<br />
;resource<br />
:The name of the resource whose value is to be changed. Resources are typically lowercase with uppercase concatenation.<br />
<br />
;value<br />
:The actual value of the resource. This can be 1 of 3 types:<br />
:* Integer (whole numbers)<br />
:* Boolean (true/false, yes/no, on/off)<br />
:* String (a string of characters) (for example a word ({{ic|white}}), a color ({{ic|#ffffff}}), or a path ({{ic|/usr/bin/firefox}}))<br />
<br />
;delimiters<br />
:A dot ({{ic|'''.'''}}) is used to signify each step down into the hierarchy — in the above example we start at name, then descend into Class, and finally into the resource itself. A colon ({{ic|''':'''}}) is used to separate the resource declaration from the actual value.<br />
<br />
====Wildcard matching====<br />
<br />
The asterisk can be used as a wildcard, making it easy to write a single rule that can be applied to many different applications or elements. <br />
<br />
Using the previous example, if you want to apply the same font to all programs (not just XScreenSaver) that contain the class name {{ic|Dialog}} which contains the resource name {{ic|headingFont}}, you would write:<br />
<br />
'''*'''Dialog.headingFont: -*-fixed-bold-r-*-*-*-100-*-*-*-*-iso8859-1<br />
<br />
If you want to apply this same rule to all programs that contain the resource {{ic|headingFont}}, regardless of its class, you would write:<br />
<br />
'''*'''headingFont: -*-fixed-bold-r-*-*-*-100-*-*-*-*-iso8859-1<br />
<br />
==== Commenting ====<br />
<br />
To add a comment to your Xresources file, simply prefix it with an exclamation mark ({{ic|!}}), for example:<br />
<br />
! The following rule will be ignored because it has been commented out<br />
!Xft.antialias: true<br />
<br />
==== Include files ====<br />
{{Note|You need to have a C preprocessor, such as {{ic|GNU CPP}}, installed to use this functionality.}}<br />
<br />
To use different files for each application, use {{ic|#include}} in the main file. For example:<br />
<br />
{{hc|~/.Xresources|<br />
#include ".Xresources.d/xterm"<br />
#include ".Xresources.d/rxvt-unicode"<br />
#include ".Xresources.d/fonts"<br />
#include ".Xresources.d/xscreensaver"<br />
}}<br />
<br />
If files fail to load, specify the directory to ''xrdb'' with the {{ic|-I}} parameter. For example:<br />
<br />
{{hc|~/.xinitrc|<br />
xrdb -I''$HOME'' ~/.Xresources<br />
}}<br />
<br />
==Sample usage==<br />
The following samples should provide a good understanding of how application settings can be modified using an Xresources file. See [https://gist.github.com/anonymous/fa98de9fd70b51611303] for more examples. Refer to the man page of the application in question otherwise.<br />
<br />
===Terminal colors===<br />
<br />
See [[Color output in console#Terminal emulators]].<br />
<br />
=== Xcursor ===<br />
<br />
See [[Cursor themes#X resources]].<br />
<br />
=== Xft ===<br />
<br />
See [[Font configuration#Applications without fontconfig support]].<br />
<br />
=== Xterm ===<br />
<br />
See [[Xterm#Configuration]].<br />
<br />
=== rxvt-unicode ===<br />
<br />
See [[Rxvt-unicode#Configuration]].<br />
<br />
=== Xpdf ===<br />
<br />
See {{ic|'''Options'''}} in [http://linux.die.net/man/1/xpdf man xpdf].<br />
<br />
== Troubleshooting ==<br />
<br />
=== Parsing errors ===<br />
<br />
[[Display manager]]s such as [[GDM]] may use the {{ic|--nocpp}} argument for ''xrdb''.<br />
<br />
==See also==<br />
<br />
* [https://engineering.purdue.edu/ECN/Support/KB/Docs/UsingTheXdefaultsFil Using the Xdefaults File] - An in-depth article on how X interprets the Xdefaults file</div>X33ahttps://wiki.archlinux.org/index.php?title=X_resources&diff=469808X resources2017-03-05T09:15:14Z<p>X33a: /* Include files */ Include files won't get processed without a preprocessor installed</p>
<hr />
<div>[[Category:Dotfiles]]<br />
[[Category:X server]]<br />
[[de:Xdefaults]]<br />
[[ja:X resources]]<br />
[[ru:X resources]]<br />
'''Xresources''' is a user-level configuration ''dotfile'', typically located at {{ic|~/.Xresources}}. It can be used to set [[Wikipedia:X resources|X resources]], which are configuration parameters for X client applications.<br />
<br />
They can do many operations, including:<br />
<br />
* defining terminal colours<br />
* configuring terminal preferences<br />
* setting DPI, antialiasing, hinting and other X font settings<br />
* changing the Xcursor theme<br />
* theming xscreensaver<br />
* altering preferences on low-level X applications (xclock ({{Pkg|xorg-xclock}}), {{Pkg|xpdf}}, {{Pkg|rxvt-unicode}}, etc.)<br />
<br />
== Installation ==<br />
<br />
[[Install]] the {{pkg|xorg-xrdb}} package.<br />
<br />
== Usage ==<br />
<br />
=== Load resource file ===<br />
<br />
Resources are stored in the X server, so have to only be read once. They are also accessible to ''remote'' X11 clients (such as those forwarded over SSH).<br />
<br />
Load a resource file (such as the conventional {{ic|.Xresources}}), replacing any current settings:<br />
<br />
$ xrdb ''~/.Xresources''<br />
<br />
Load a resource file, and merge with the current settings:<br />
<br />
$ xrdb -merge ''~/.Xresources''<br />
<br />
{{Note|<br />
* Most [[Display manager]]s will load the {{ic|~/.Xresources}} file on login.<br />
* The older {{ic|~/.Xdefaults}} file is read when an X11 program starts, but only if ''xrdb'' has not been used in the current session. [https://groups.google.com/forum/#!msg/comp.windows.x/hQBEdql8l-Q/hF3DETcIHGwJ]<br />
}}<br />
<br />
=== xinitrc ===<br />
<br />
If you are using a copy of the default [[xinitrc]] as your {{ic|.xinitrc}} it already merges {{ic|~/.Xresources}}.<br />
<br />
If you are using a custom {{ic|.xinitrc}} add the following line:<br />
<br />
<nowiki>[[ -f ~/.Xresources ]] && xrdb -merge -I$HOME ~/.Xresources</nowiki><br />
<br />
{{Warning|Never background the xrdb command within {{ic|~/.xinitrc}}. Otherwise, programs launched after xrdb may look for resources before it has finished loading them.}}<br />
<br />
=== Default settings ===<br />
<br />
To see the default settings for your installed X11 apps, look in {{ic|/usr/share/X11/app-defaults/}}.<br />
<br />
Detailed information on program-specific resources is usually provided in the man page for the program. xterm's man page is a good example, as it contains a list of X resources and their default values.<br />
<br />
To see the current loaded resources:<br />
<br />
xrdb -query -all<br />
<br />
===Xresources syntax===<br />
<br />
====Basic syntax====<br />
<br />
The syntax of an Xresources file is as follows:<br />
'''name.Class.resource: value'''<br />
and here is a real world example:<br />
xscreensaver.Dialog.headingFont: -*-fixed-bold-r-*-*-*-100-*-*-*-*-iso8859-1<br />
<br />
;name<br />
:The name of the application, such as xterm, xpdf, etc<br />
<br />
;class<br />
:The classification used to group resources together. Class names are typically uppercase.<br />
<br />
;resource<br />
:The name of the resource whose value is to be changed. Resources are typically lowercase with uppercase concatenation.<br />
<br />
;value<br />
:The actual value of the resource. This can be 1 of 3 types:<br />
:* Integer (whole numbers)<br />
:* Boolean (true/false, yes/no, on/off)<br />
:* String (a string of characters) (for example a word ({{ic|white}}), a color ({{ic|#ffffff}}), or a path ({{ic|/usr/bin/firefox}}))<br />
<br />
;delimiters<br />
:A dot ({{ic|'''.'''}}) is used to signify each step down into the hierarchy — in the above example we start at name, then descend into Class, and finally into the resource itself. A colon ({{ic|''':'''}}) is used to separate the resource declaration from the actual value.<br />
<br />
====Wildcard matching====<br />
<br />
The asterisk can be used as a wildcard, making it easy to write a single rule that can be applied to many different applications or elements. <br />
<br />
Using the previous example, if you want to apply the same font to all programs (not just XScreenSaver) that contain the class name {{ic|Dialog}} which contains the resource name {{ic|headingFont}}, you would write:<br />
<br />
'''*'''Dialog.headingFont: -*-fixed-bold-r-*-*-*-100-*-*-*-*-iso8859-1<br />
<br />
If you want to apply this same rule to all programs that contain the resource {{ic|headingFont}}, regardless of its class, you would write:<br />
<br />
'''*'''headingFont: -*-fixed-bold-r-*-*-*-100-*-*-*-*-iso8859-1<br />
<br />
==== Commenting ====<br />
<br />
To add a comment to your Xresources file, simply prefix it with an exclamation mark ({{ic|!}}), for example:<br />
<br />
! The following rule will be ignored because it has been commented out<br />
!Xft.antialias: true<br />
<br />
==== Include files ====<br />
{{Note|You need to have a preprocessor, such as {{Pkg|gcc}}, installed to use this functionality.}}<br />
<br />
To use different files for each application, use {{ic|#include}} in the main file. For example:<br />
<br />
{{hc|~/.Xresources|<br />
#include ".Xresources.d/xterm"<br />
#include ".Xresources.d/rxvt-unicode"<br />
#include ".Xresources.d/fonts"<br />
#include ".Xresources.d/xscreensaver"<br />
}}<br />
<br />
If files fail to load, specify the directory to ''xrdb'' with the {{ic|-I}} parameter. For example:<br />
<br />
{{hc|~/.xinitrc|<br />
xrdb -I''$HOME'' ~/.Xresources<br />
}}<br />
<br />
==Sample usage==<br />
The following samples should provide a good understanding of how application settings can be modified using an Xresources file. See [https://gist.github.com/anonymous/fa98de9fd70b51611303] for more examples. Refer to the man page of the application in question otherwise.<br />
<br />
===Terminal colors===<br />
<br />
See [[Color output in console#Terminal emulators]].<br />
<br />
=== Xcursor ===<br />
<br />
See [[Cursor themes#X resources]].<br />
<br />
=== Xft ===<br />
<br />
See [[Font configuration#Applications without fontconfig support]].<br />
<br />
=== Xterm ===<br />
<br />
See [[Xterm#Configuration]].<br />
<br />
=== rxvt-unicode ===<br />
<br />
See [[Rxvt-unicode#Configuration]].<br />
<br />
=== Xpdf ===<br />
<br />
See {{ic|'''Options'''}} in [http://linux.die.net/man/1/xpdf man xpdf].<br />
<br />
== Troubleshooting ==<br />
<br />
=== Parsing errors ===<br />
<br />
[[Display manager]]s such as [[GDM]] may use the {{ic|--nocpp}} argument for ''xrdb''.<br />
<br />
==See also==<br />
<br />
* [https://engineering.purdue.edu/ECN/Support/KB/Docs/UsingTheXdefaultsFil Using the Xdefaults File] - An in-depth article on how X interprets the Xdefaults file</div>X33ahttps://wiki.archlinux.org/index.php?title=LVM&diff=468111LVM2017-02-11T05:22:10Z<p>X33a: /* Create */ fix typo</p>
<hr />
<div>[[Category:File systems]]<br />
[[cs:LVM]]<br />
[[de:LVM]]<br />
[[es:LVM]]<br />
[[fr:LVM]]<br />
[[it:LVM]]<br />
[[ja:LVM]]<br />
[[ru:LVM]]<br />
[[tr:LVM]]<br />
[[zh-hans:LVM]]<br />
{{Related articles start}}<br />
{{Related|Software RAID and LVM}}<br />
{{Related|dm-crypt/Encrypting an entire system#LVM on LUKS}}<br />
{{Related|dm-crypt/Encrypting an entire system#LUKS on LVM}}<br />
{{Related|Resizing LVM-on-LUKS}}<br />
{{Related articles end}}<br />
From [[Wikipedia:Logical Volume Manager (Linux)]]:<br />
:LVM is a [[Wikipedia:logical volume management|logical volume manager]] for the [[Wikipedia:Linux kernel|Linux kernel]]; it manages disk drives and similar mass-storage devices.<br />
<br />
== LVM Building Blocks ==<br />
<br />
Logical Volume Management utilizes the kernel's [http://sources.redhat.com/dm/ device-mapper] feature to provide a system of partitions independent of underlying disk layout. With LVM you abstract your storage and have "virtual partitions", making [[#Resizing volumes|extending/shrinking]] easier (subject to potential filesystem limitations).<br />
<br />
Virtual partitions allow addition and removal without worry of whether you have enough contiguous space on a particular disk, getting caught up fdisking a disk in use (and wondering whether the kernel is using the old or new partition table), or, having to move other partitions out of the way. This is strictly an ease-of-management solution: LVM adds no security.<br />
<br />
Basic building blocks of LVM:<br />
<br />
; Physical volume (PV): Partition on hard disk (or even the disk itself or loopback file) on which you can have volume groups. It has a special header and is divided into physical extents. Think of physical volumes as big building blocks used to build your hard drive.<br />
; Volume group (VG): Group of physical volumes used as a storage volume (as one disk). They contain logical volumes. Think of volume groups as hard drives.<br />
; Logical volume (LV): A "virtual/logical partition" that resides in a volume group and is composed of physical extents. Think of logical volumes as normal partitions.<br />
; Physical extent (PE): The smallest size in the physical volume that can be assigned to a logical volume (default 4MiB). Think of physical extents as parts of disks that can be allocated to any partition.<br />
<br />
Example:<br />
'''Physical disks'''<br />
<br />
Disk1 (/dev/sda):<br />
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _<br />
|Partition1 50GB (Physical volume) |Partition2 80GB (Physical volume) |<br />
|/dev/sda1 |/dev/sda2 |<br />
|_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |<br />
<br />
Disk2 (/dev/sdb):<br />
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _<br />
|Partition1 120GB (Physical volume) |<br />
|/dev/sdb1 |<br />
| _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ __ _ _|<br />
<br />
'''LVM logical volumes'''<br />
<br />
Volume Group1 (/dev/MyStorage/ = /dev/sda1 + /dev/sda2 + /dev/sdb1):<br />
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ <br />
|Logical volume1 15GB |Logical volume2 35GB |Logical volume3 200GB |<br />
|/dev/MyStorage/rootvol|/dev/MyStorage/homevol |/dev/MyStorage/mediavol |<br />
|_ _ _ _ _ _ _ _ _ _ _ |_ _ _ _ _ _ _ _ _ _ _ _ _ |_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |<br />
<br />
== Advantages ==<br />
<br />
LVM gives you more flexibility than just using normal hard drive partitions:<br />
<br />
* Use any number of disks as one big disk.<br />
* Have logical volumes stretched over several disks.<br />
* Create small logical volumes and resize them "dynamically" as they get filled up.<br />
* Resize logical volumes regardless of their order on disk. It does not depend on the position of the LV within VG, there is no need to ensure surrounding available space.<br />
* Resize/create/delete logical and physical volumes online. File systems on them still need to be resized, but some (such as ext4) support online resizing.<br />
* Online/live migration of LV being used by services to different disks without having to restart services.<br />
* Snapshots allow you to backup a frozen copy of the file system, while keeping service downtime to a minimum.<br />
* Support for various device-mapper targets, including transparent filesystem encryption and caching of frequently used data. This allows creating a system with (one or more) physical disks (encrypted with LUKS) and [[dm-crypt/Encrypting an entire system#LVM on LUKS|LVM on top]] to allow for easy resizing and management of separate volumes for ''/'', ''/home'',''/backup'', etc. without the hassle of entering a key multiple times on boot.<br />
<br />
== Disadvantages ==<br />
<br />
* Additional steps in setting up the system, more complicated.<br />
* If dual-booting, note that Windows does not support LVM; you will be unable to access any LVM partitions from Windows.<br />
<br />
== Installing Arch Linux on LVM ==<br />
<br />
You should create your LVM Volumes between the [[partitioning]] and [[File_systems#Create a file system|formatting]] steps of the [[Installation guide|installation procedure]]. Instead of directly formatting a partition to be your root file system, the file system will be created inside a logical volume (LV). <br />
<br />
Make sure the {{pkg|lvm2}} package is [[pacman|installed]].<br />
<br />
Quick overview: <br />
<br />
* Create partition(s) where your PV(s) will reside. Set the partition type to 'Linux LVM', which is 8e if you use MBR, 8e00 for GPT.<br />
* Create your physical volumes (PVs). If you have one disk it is best to just create one PV in one large partition. If you have multiple disks you can create partitions on each of them and create a PV on each partition.<br />
* Create your volume group (VG) and add all PVs to it.<br />
* Create logical volumes (LVs) inside that VG.<br />
* Continue with [[Installation guide#Format the partitions]].<br />
* When you reach the “Create initial ramdisk environment” step in the Installation guide, add the {{ic|lvm}} hook to {{ic|/etc/mkinitcpio.conf}} (see below for details).<br />
<br />
{{Warning|{{ic|/boot}} cannot reside in LVM when using a boot loader, which does not support LVM, you must create a separate {{ic|/boot}} partition and format it directly. Only [[GRUB]] is known to support LVM.}}<br />
<br />
=== Create partitions ===<br />
<br />
If LVM has to be set on the entire disk, there is no need to create any partitions.<br />
<br />
Otherwise, [[partition]] the device as required before configuring LVM.<br />
<br />
=== Create physical volumes ===<br />
<br />
To list all your devices capable of being used as a physical volume:<br />
<br />
# lvmdiskscan<br />
<br />
{{Warning|Make sure you target the correct device, or below commands will result in data loss!}}<br />
<br />
Create a physical volume on them:<br />
<br />
# pvcreate ''DEVICE''<br />
<br />
This command creates a header on each device so it can be used for LVM. As defined in [[#LVM Building Blocks]], ''DEVICE'' can be a disk (e.g. {{ic|/dev/sda}}), a partition (e.g. {{ic|/dev/sda2}}) or a loop back device. For example: <br />
<br />
# pvcreate /dev/sda2<br />
<br />
You can track created physical volumes with:<br />
<br />
# pvdisplay<br />
<br />
{{Note|If using a SSD without partitioning it first, use {{ic|pvcreate --dataalignment 1m /dev/sda}} (for erase block size < 1MiB), see e.g. [http://serverfault.com/questions/356534/ssd-erase-block-size-lvm-pv-on-raw-device-alignment here]}}<br />
<br />
=== Create volume group ===<br />
<br />
The next step is to create a volume group on this physical volume.<br />
<br />
First you need to create a volume group on one of the physical volumes:<br />
<br />
# vgcreate <''volume_group''> <''physical_volume''><br />
<br />
For example:<br />
<br />
# vgcreate VolGroup00 /dev/sda2<br />
<br />
Then add to it all other physical volumes you want to have in it:<br />
<br />
# vgextend <''volume_group''> <''physical_volume''><br />
# vgextend <''volume_group''> <''another_physical_volume''><br />
# ...<br />
<br />
For example:<br />
<br />
# vgextend VolGroup00 /dev/sdb1<br />
# vgextend VolGroup00 /dev/sdc<br />
<br />
You can track how your volume group grows with:<br />
<br />
# vgdisplay<br />
<br />
{{Note|You can create more than one volume group if you need to, but then you will not have all your storage presented as one disk.}}<br />
<br />
=== Create in one step ===<br />
<br />
LVM allows you to combine the creation of a volume group and the physical volumes in one easy step. For example, to create the group VolGroup00 with the three devices mentioned above, you can run:<br />
<br />
# vgcreate VolGroup00 /dev/sda2 /dev/sdb1 /dev/sdc<br />
<br />
This command will first set up the three partitions as physical volumes (if necessary) and then create the volume group with the three volumes. The command will warn you it detects an existing filesystem on any of the devices.<br />
<br />
=== Create logical volumes ===<br />
<br />
Now we need to create logical volumes on this volume group. You create a logical volume with the next command by giving the name of a new logical volume, its size, and the volume group it will live on:<br />
<br />
# lvcreate -L <''size''> <''volume_group''> -n <''logical_volume''><br />
<br />
For example:<br />
<br />
# lvcreate -L 10G VolGroup00 -n lvolhome<br />
<br />
This will create a logical volume that you can access later with {{ic|/dev/mapper/Volgroup00-lvolhome}} or {{ic|/dev/VolGroup00/lvolhome}}. Same as with the volume groups, you can use any name you want for your logical volume when creating it.<br />
<br />
You can also specify one or more physical volumes to restrict where LVM allocates the data. For example, you may wish to create a logical volume for the root filesystem on your small SSD, and your home volume on a slower mechanical drive. Simply add the physical volume devices to the command line, for example:<br />
<br />
# lvcreate -L 10G VolGroup00 -n lvolhome /dev/sdc1<br />
<br />
If you want to fill all the free space left on a volume group, use the next command:<br />
<br />
# lvcreate -l 100%FREE <''volume_group''> -n <''logical_volume''><br />
<br />
You can track created logical volumes with:<br />
<br />
# lvdisplay<br />
<br />
{{Note|You may need to load the ''device-mapper'' kernel module ({{ic|modprobe dm_mod'}}) for the above commands to succeed.}}<br />
<br />
{{Tip|You can start out with relatively small logical volumes and expand them later if needed. For simplicity, leave some free space in the volume group so there is room for expansion.}}<br />
<br />
=== Create file systems and mount logical volumes ===<br />
<br />
Your logical volumes should now be located in {{ic|/dev/mapper/}} and {{ic|/dev/''YourVolumeGroupName''}}. If you cannot find them, use the next commands to bring up the module for creating device nodes and to make volume groups available:<br />
<br />
# modprobe dm_mod<br />
# vgscan<br />
# vgchange -ay<br />
<br />
Now you can create file systems on logical volumes and mount them as normal partitions (if you are installing Arch linux, refer to [[mount|mounting the partitions]] for additional details):<br />
<br />
# mkfs.<''fstype''> /dev/mapper/<''volume_group''>-<''logical_volume''><br />
# mount /dev/mapper/<''volume_group''>-<''logical_volume''> /<''mountpoint''><br />
<br />
For example:<br />
<br />
# mkfs.ext4 /dev/mapper/VolGroup00-lvolhome<br />
# mount /dev/mapper/VolGroup00-lvolhome /home<br />
<br />
{{Warning|When choosing mountpoints, just select your newly created logical volumes (use: {{ic|/dev/mapper/Volgroup00-lvolhome}}). Do '''not''' select the actual partitions on which logical volumes were created (do not use: {{ic|/dev/sda2}}).}}<br />
<br />
=== Configure mkinitcpio ===<br />
<br />
In case your root filesystem is on LVM, you will need to enable the appropriate [[mkinitcpio]] hooks, otherwise your system might not boot. Enable:<br />
<br />
* {{ic|udev}} and {{ic|lvm2}} for the default busybox based initramfs<br />
* {{ic|systemd}} and {{ic|sd-lvm2}} for systemd based initramfs<br />
<br />
{{ic|udev}} is there by default. Edit the file and insert {{ic|lvm2}} between {{ic|block}} and {{ic|filesystems}} like so:<br />
<br />
{{hc|1= /etc/mkinitcpio.conf|2= HOOKS="base udev ... block '''lvm2''' filesystems"}}<br />
<br />
For systemd based initramfs:<br />
<br />
{{hc|1= /etc/mkinitcpio.conf|2= HOOKS="base systemd ... block '''sd-lvm2''' filesystems"}}<br />
<br />
Afterwards, you can continue in normal installation instructions with the [[Mkinitcpio#Image_creation_and_activation|create an initial ramdisk]] step.<br />
<br />
{{Tip|<br />
* The {{ic|lvm2}} and {{ic|sd-lvm2}} hooks are installed by {{pkg|lvm2}}, not {{pkg|mkinitcpio}}. If you are running ''mkinitcpio'' in an ''arch-chroot'' for a new installation, {{pkg|lvm2}} must be installed inside the ''arch-chroot'' for ''mkinitcpio'' to find the {{ic|lvm2}} or {{ic|sd-lvm2}} hook. If {{pkg|lvm2}} only exists outside the ''arch-chroot'', ''mkinitcpio'' will output {{ic|Error: Hook 'lvm2' cannot be found}}.<br />
* If your root filesystem is on LVM RAID you will also need to add {{ic|dm-raid}} and the appropriate RAID modules (e.g. {{ic|raid0}}, {{ic|raid1}}, {{ic|raid10}} or {{ic|raid456}}) to the MODULES section of {{ic|mkinitcpio.conf}}.<br />
}}<br />
<br />
=== Kernel options ===<br />
<br />
If the root file system resides in a logical volume, the {{ic|<nowiki>root=</nowiki>}} [[kernel parameter]] must be pointed to the mapped device, e.g {{ic|/dev/mapper/''vg-name''-''lv-name''}}.<br />
<br />
== Volume operations ==<br />
<br />
{{Expansion|Add instructions for thin-provisioned volume creation.}}<br />
<br />
=== Advanced options ===<br />
<br />
If you need monitoring (needed for snapshots) you can enable lvmetad. <br />
For this set {{ic|1=use_lvmetad = 1}} in {{ic|/etc/lvm/lvm.conf}}.<br />
This is the default by now. <br />
<br />
You can restrict the volumes that are activated automatically by setting the {{Ic|auto_activation_volume_list}} in {{Ic|/etc/lvm/lvm.conf}}. If in doubt, leave this option commented out.<br />
<br />
=== Resizing volumes ===<br />
<br />
==== Physical volumes ====<br />
<br />
After extending or prior to reducing the size of a device that has a physical volume on it, you need to grow or shrink the PV using {{ic|pvresize}}.<br />
<br />
===== Growing =====<br />
<br />
To expand the PV on {{ic|/dev/sda1}} after enlarging the [[partition]], run:<br />
<br />
# pvresize /dev/sda1<br />
<br />
This will automatically detect the new size of the device and extend the PV to its maximum.<br />
<br />
{{Note|This command can be done while the volume is online.}}<br />
<br />
===== Shrinking =====<br />
<br />
To shrink a physical volume prior to reducing its underlying device, add the {{ic|--setphysicalvolumesize ''size''}} parameters to the command, ''e.g.'':<br />
<br />
# pvresize --setphysicalvolumesize 40G /dev/sda1<br />
<br />
The above command may leave you with this error:<br />
<br />
/dev/sda1: cannot resize to 25599 extents as later ones are allocated.<br />
0 physical volume(s) resized / 1 physical volume(s) not resized<br />
<br />
Indeed {{ic|pvresize}} will refuse to shrink a PV if it has allocated extents after where its new end would be. One needs to run [[#Move physical extents|pvmove]] beforehand to relocate these elsewhere in the volume group if there is sufficient free space.<br />
<br />
====== Move physical extents ======<br />
<br />
Before moving free extents to the end of the volume, one must run {{ic|# pvdisplay -v -m}} to see physical segments. In the below example, there is one physical volume on {{ic|/dev/sdd1}}, one volume group {{ic|vg1}} and one logical volume {{ic|backup}}.<br />
<br />
{{hc|# pvdisplay -v -m|<br />
Finding all volume groups.<br />
Using physical volume(s) on command line.<br />
--- Physical volume ---<br />
PV Name /dev/sdd1<br />
VG Name vg1<br />
PV Size 1.52 TiB / not usable 1.97 MiB<br />
Allocatable yes <br />
PE Size 4.00 MiB<br />
Total PE 399669<br />
Free PE 153600<br />
Allocated PE 246069<br />
PV UUID MR9J0X-zQB4-wi3k-EnaV-5ksf-hN1P-Jkm5mW<br />
<br />
--- Physical Segments ---<br />
Physical extent 0 to 153600:<br />
FREE<br />
Physical extent 153601 to 307199:<br />
Logical volume /dev/vg1/backup<br />
Logical extents 1 to 153599<br />
Physical extent 307200 to 307200:<br />
FREE<br />
Physical extent 307201 to 399668:<br />
Logical volume /dev/vg1/backup<br />
Logical extents 153601 to 246068<br />
}}<br />
<br />
One can observe FREE space are split across the volume. To shrink the physical volume, we must first move all used segments to the beginning.<br />
<br />
Here, the first free segment is from 0 to 153600 and leaves us with 153601 free extents. We can now move this segment number from the last physical extent to the first extent. The command will thus be:<br />
<br />
{{hc|# pvmove --alloc anywhere /dev/sdd1:307201-399668 /dev/sdd1:0-92466|<br />
/dev/sdd1: Moved: 0.1 %<br />
/dev/sdd1: Moved: 0.2 %<br />
...<br />
/dev/sdd1: Moved: 99.9 %<br />
/dev/sdd1: Moved: 100,0%<br />
}}<br />
<br />
{{Note|<br />
* this command tells to move 92468 (399668-307200) PE '''from''' the last segment '''to''' the first segment. This is possible as first segment enclosed FREE 153600 PE, which can contains the 92467 moved PE.<br />
* the {{ic|--alloc anywhere}} option is used as we move PE inside the same partition. In case of different partitions, the command would look something like this: {{ic|# pvmove /dev/sdb1:1000-1999 /dev/sdc1:0-999}}<br />
* the move can takes long (one/two hours) in case of large size. It can be a good idea to run this command in a [[Tmux]] or [[GNU Screen]] session. Any unwanted stop of the process can be fatal.<br />
* once the operation is complete, run [[Fsck]] to make sure your file system is valid.<br />
}}<br />
<br />
====== Resize physical volume ======<br />
<br />
Once all your free physical segments are on the last physical extent, run {{ic|# vgdisplay}} and see your free PE.<br />
<br />
Then you can now run again the command:<br />
<br />
# pvresize --setphysicalvolumesize ''size'' ''PhysicalVolume''<br />
<br />
See the result:<br />
<br />
{{hc|# pvs|<br />
PV VG Fmt Attr PSize PFree <br />
/dev/sdd1 vg1 lvm2 a-- 1t 500g<br />
}}<br />
<br />
====== Resize partition ======<br />
<br />
Last, you need to shrink the partition with your favorite [[Partitioning#Partitioning tools|partitioning tool]].<br />
<br />
==== Logical volumes ====<br />
<br />
{{Note|''lvresize'' provides more or less the same options as the specialized {{ic|lvextend}} and {{ic|lvreduce}} commands, while allowing to do both types of operation. Notwithstanding this, all those utilities offer a {{ic|-r, --resizefs}} option which allows to resize the file system together with the LV using {{man|8|fsadm}} (''ext2'', [[ext3]], [[ext4]], ''ReiserFS'' and [[XFS]] supported). Therefore it may be easier to simply use {{ic|lvresize}} for both operations and use {{ic|--resizefs}} to simplify things a bit, except if you have specific needs or want full control over the process.}}<br />
<br />
===== Growing or shrinking with lvresize =====<br />
<br />
{{Warning|While enlarging a file system can often be done on-line (''i.e.'' while it is mounted), even for the root partition, shrinking will nearly always require to first unmount the file system so as to prevent data loss. Make sure your FS supports what you are trying to do.}}<br />
<br />
Extend logical volume ''lv1'' within volume group ''vg1'' by 2GB ''without'' touching its file system:<br />
<br />
# lvresize -L +2G vg1/lv1<br />
<br />
Reduce the size of {{ic|vg1/lv1}} by 500MB ''without'' resizing its file system (make sure it is [[#Resizing the file system separately|already shrunk]] in that case):<br />
<br />
# lvresize -L -500M vg1/lv1<br />
<br />
Set {{ic|vg1/lv1}} to 15GB and resize its file system ''all at once'':<br />
<br />
# lvresize -L 15G -r vg1/lv1<br />
<br />
{{Note|Only ''ext2'', [[ext3]], [[ext4]], ''ReiserFS'' and [[XFS]] [[file systems]] are supported. For a different type of file system look for the [[File_systems#Types_of_file_systems|appropriate utility]].}}<br />
<br />
If you want to fill all the free space on a volume group, use the following command:<br />
<br />
# lvresize -l +100%FREE ''vg''/''lv''<br />
<br />
See {{man|8|lvresize}} for more detailed options.<br />
<br />
===== Extending the logical volume and file system in one go =====<br />
<br />
{{Merge|#Growing or shrinking with lvresize|No need to split the sections.}}<br />
<br />
{{Warning|Not all file systems support resizing without loss of data and/or resizing online.}}<br />
<br />
Extend the logical volume ''home'' in ''volume-group'' with 10GB<br />
<br />
# lvresize -L +10G /dev/''volume-group''/''home'' --resize-fs<br />
<br />
Alternatively with a XFS filesystem<br />
<br />
# lvextend -L+10G /dev/''volume-group''/''home''<br />
# xfs_growfs /home<br />
<br />
Note: ''xfs_growfs'' takes a mount point as argument. See {{man|8|xfs_growfs}} for more detailed options.<br />
<br />
===== Resizing the file system separately =====<br />
<br />
{{Move|Ext4|File system specific operations should be placed in their respective wiki pages.}}<br />
<br />
If not using the {{ic|-r, --resizefs}} option to {{ic|lv{resize,extend,reduce<nowiki>}</nowiki>}} or using a file system unspported by {{man|8|fsadm}} ([[Btrfs]], [[ZFS]]...), you need to manually resize the FS before shrinking the LV or after expanding it.<br />
<br />
{{Warning|Not all file systems support resizing without loss of data and/or resizing online.}}<br />
<br />
For example with an ext2/ext3/ext4 file system:<br />
<br />
# resize2fs ''vg''/''lv''<br />
<br />
will expand the FS to the maximum size of the underlying LV, while<br />
<br />
# resize2fs -M ''vg''/''lv''<br />
<br />
will shrink it to its minimum size. To resize it to a specified size, use:<br />
<br />
# resize2fs ''vg''/''lv'' ''NewSize''<br />
<br />
=== Remove logical volume ===<br />
<br />
{{Warning|Before you remove a logical volume, make sure to move all data that you want to keep somewhere else; otherwise, it will be lost!}}<br />
<br />
First, find out the name of the logical volume you want to remove. You can get a list of all logical volumes with:<br />
<br />
# lvs<br />
<br />
Next, look up the mountpoint of the chosen logical volume:<br />
<br />
$ lsblk<br />
<br />
Then unmount the filesystem on the logical volume:<br />
<br />
# umount /<''mountpoint''><br />
<br />
Finally, remove the logical volume:<br />
<br />
# lvremove <''volume_group''>/<''logical_volume''><br />
<br />
For example:<br />
<br />
# lvremove VolGroup00/lvolhome<br />
<br />
Confirm by typing in {{ic|y}}.<br />
<br />
Update {{ic|/etc/fstab}} as necessary.<br />
<br />
You can verify the removal of the logical volume by typing {{ic|lvs}} as root again (see first step of this section).<br />
<br />
=== Add physical volume to a volume group ===<br />
<br />
You first create a new physical volume on the block device you wish to use, then extend your volume group<br />
<br />
# pvcreate /dev/sdb1<br />
# vgextend VolGroup00 /dev/sdb1<br />
<br />
This of course will increase the total number of physical extents on your volume group, which can be allocated by logical volumes as you see fit.<br />
<br />
{{Note|It is considered good form to have a [[Partitioning|partition table]] on your storage medium below LVM. Use the appropriate type code: {{ic|8e}} for MBR, and {{ic|8e00}} for GPT partitions.}}<br />
<br />
=== Remove partition from a volume group ===<br />
<br />
If you created a logical volume on the partition, [[#Remove logical volume|remove]] it first.<br />
<br />
All of the data on that partition needs to be moved to another partition. Fortunately, LVM makes this easy:<br />
<br />
# pvmove /dev/sdb1<br />
<br />
If you want to have the data on a specific physical volume, specify that as the second argument to {{Ic|pvmove}}:<br />
<br />
# pvmove /dev/sdb1 /dev/sdf1<br />
<br />
Then the physical volume needs to be removed from the volume group:<br />
<br />
# vgreduce myVg /dev/sdb1<br />
<br />
Or remove all empty physical volumes:<br />
<br />
# vgreduce --all vg0<br />
<br />
And lastly, if you want to use the partition for something else, and want to avoid LVM thinking that the partition is a physical volume:<br />
<br />
# pvremove /dev/sdb1<br />
<br />
=== Deactivate volume group ===<br />
<br />
Just invoke <br />
<br />
# vgchange -a n my_volume_group<br />
<br />
This will deactivate the volume group and allow you to unmount the container it is stored in.<br />
<br />
=== Snapshots ===<br />
<br />
LVM allows you to take a snapshot of your system in a much more efficient way than a traditional backup. It does this efficiently by using a COW (copy-on-write) policy. The initial snapshot you take simply contains hard-links to the inodes of your actual data. So long as your data remains unchanged, the snapshot merely contains its inode pointers and not the data itself. Whenever you modify a file or directory that the snapshot points to, LVM automatically clones the data, the old copy referenced by the snapshot, and the new copy referenced by your active system. Thus, you can snapshot a system with 35GB of data using just 2GB of free space so long as you modify less than 2GB (on both the original and snapshot).<br />
<br />
==== Configuration ====<br />
<br />
You create snapshot logical volumes just like normal ones.<br />
<br />
# lvcreate --size 100M --snapshot --name snap01 /dev/mapper/vg0-pv<br />
<br />
With that volume, you may modify less than 100M of data, before the snapshot volume fills up.<br />
<br />
Reverting the modified 'pv' logical volume to the state when the 'snap01' snapshot was taken can be done with<br />
<br />
# lvconvert --merge /dev/vg0/snap01<br />
<br />
In case the origin logical volume is active, merging will occur on the next reboot.(Merging can be done even from a LiveCD)<br />
<br />
The snapshot will no longer exist after merging.<br />
<br />
Also multiple snapshots can be taken and each one can be merged with the origin logical volume at will.<br />
<br />
The snapshot can be mounted and backed up with '''dd''' or '''tar'''. The size of the backup file done with '''dd''' will be the size of the files residing on the snapshot volume. <br />
To restore just create a snapshot, mount it, and write or extract the backup to it. And then merge it with the origin.<br />
<br />
It is important to have the ''dm_snapshot'' module listed in the MODULES variable of {{ic|/etc/mkinitcpio.conf}}, otherwise the system will not boot. If you do this on an already installed system, make sure to [[regenerate the initramfs]].<br />
<br />
{{Expansion|scripts to automate snapshots of root before updates, to rollback... updating {{ic|menu.lst}} to boot snapshots (separate article?)}}<br />
<br />
Snapshots are primarily used to provide a frozen copy of a file system to make backups; a backup taking two hours provides a more consistent image of the file system than directly backing up the partition.<br />
<br />
See [[Create root filesystem snapshots with LVM]] for automating the creation of clean root file system snapshots during system startup for backup and rollback.<br />
<br />
[[Dm-crypt/Encrypting an entire system#LVM on LUKS]] and [[Dm-crypt/Encrypting an entire system#LUKS on LVM]].<br />
<br />
If you have LVM volumes not activated via the [[initramfs]], [[enable]] {{ic|lvm-monitoring.service}}, which is provided by the {{pkg|lvm2}} package.<br />
<br />
=== LVM Cache (lvmcache) ===<br />
<br />
From {{man|7|lvmcache}}:<br />
<br />
: ''The cache logical volume type uses a small and fast LV to improve the performance of a large and slow LV. It does this by storing the frequently used blocks on the faster LV. LVM refers to the small fast LV as a cache pool LV. The large slow LV is called the origin LV. Due to requirements from dm-cache (the kernel driver), LVM further splits the cache pool LV into two devices - the cache data LV and cache metadata LV. The cache data LV is where copies of data blocks are kept from the origin LV to increase speed. The cache metadata LV holds the accounting information that specifies where data blocks are stored (e.g. on the origin LV or on the cache data LV). Users should be familiar with these LVs if they wish to create the best and most robust cached logical volumes. All of these associated LVs must be in the same VG.''<br />
<br />
==== Create ====<br />
<br />
The fast method is creating a PV (if necessary) on the fast disk and add it to the existing volume group:<br />
<br />
# vgextend dataVG /dev/sdx<br />
<br />
Create a cache pool with automatic meta data on sdb, and convert the existing logical volume (dataLV) to a cached volume, all in one step:<br />
<br />
# lvcreate --type cache --cachemode writethrough -L 20G -n dataLV_cachepool dataVG/dataLV /dev/sdx<br />
<br />
Obviously, if you want your cache to be bigger, you can change the {{ic|-L}} parameter to a different size.<br />
{{Note|Cachemode has two possible options:<br />
* {{ic|writethrough}} ensures that any data written will be stored both in the cache pool LV and on the origin LV. The loss of a device associated with the cache pool LV in this case would not mean the loss of any data;<br />
* {{ic|writeback}} ensures better performance, but at the cost of a higher risk of data loss in case the drive used for cache fails.<br />
<br />
If a specific {{ic|--cachemode}} is not indicated, the system will assume {{ic|writethrough}} as default.<br />
}}<br />
<br />
==== Remove ====<br />
<br />
If you ever need to undo the one step creation operation above:<br />
<br />
# lvconvert --uncache dataVG/dataLV<br />
<br />
This commits any pending writes still in the cache back to the origin LV, then deletes the cache. Other options are available and described in {{man|7|lvmcache}}.<br />
<br />
== Graphical configuration ==<br />
<br />
There is no "official" GUI tool for managing LVM volumes, but {{AUR|system-config-lvm}} covers most of the common operations, and provides simple visualizations of volume state. It can automatically resize many file systems when resizing logical volumes.<br />
<br />
== Troubleshooting ==<br />
<br />
=== Changes that could be required due to changes in the Arch-Linux defaults ===<br />
<br />
The {{ic|1=use_lvmetad = 1}} must be set in {{ic|/etc/lvm/lvm.conf}}. This is the default now - if you have a {{ic|lvm.conf.pacnew}} file, you must merge this change.<br />
<br />
=== LVM commands do not work ===<br />
<br />
* Load proper module:<br />
<br />
# modprobe dm_mod<br />
<br />
The {{ic|dm_mod}} module should be automatically loaded. In case it does not, you can try:<br />
{{Accuracy|Should module loading at boot be done using "/etc/modules-load.d" instead?}}<br />
<br />
{{hc|/etc/mkinitcpio.conf:|2=<br />
MODULES="dm_mod ..."<br />
}}<br />
<br />
You will need to [[Mkinitcpio#Image_creation_and_activation|rebuild]] the initramfs to commit any changes you made.<br />
<br />
* Try preceding commands with ''lvm'' like this:<br />
<br />
# lvm pvdisplay<br />
<br />
=== Logical Volumes do not show up ===<br />
<br />
If you are trying to mount existing logical volumes, but they do not show up in {{ic|lvscan}}, you can use the following commands to activate them:<br />
<br />
# vgscan<br />
# vgchange -ay<br />
<br />
=== LVM on removable media ===<br />
<br />
Symptoms:<br />
{{hc|# vgscan|<br />
Reading all physical volumes. This may take a while...<br />
/dev/backupdrive1/backup: read failed after 0 of 4096 at 319836585984: Input/output error<br />
/dev/backupdrive1/backup: read failed after 0 of 4096 at 319836643328: Input/output error<br />
/dev/backupdrive1/backup: read failed after 0 of 4096 at 0: Input/output error<br />
/dev/backupdrive1/backup: read failed after 0 of 4096 at 4096: Input/output error<br />
Found volume group "backupdrive1" using metadata type lvm2<br />
Found volume group "networkdrive" using metadata type lvm2<br />
}}<br />
<br />
Cause:<br />
:Removing an external LVM drive without deactivating the volume group(s) first. Before you disconnect, make sure to:<br />
<br />
# vgchange -an ''volume group name''<br />
<br />
Fix: assuming you already tried to activate the volume group with {{ic|# vgchange -ay ''vg''}}, and are receiving the Input/output errors:<br />
<br />
# vgchange -an ''volume group name''<br />
<br />
Unplug the external drive and wait a few minutes:<br />
<br />
# vgscan<br />
# vgchange -ay ''volume group name''<br />
<br />
=== Resizing a contiguous logical volume fails ===<br />
<br />
If trying to extend a logical volume errors with:<br />
<br />
" Insufficient suitable contiguous allocatable extents for logical volume "<br />
<br />
The reason is that the logical volume was created with an explicit contiguous allocation policy (options {{ic|-C y}} or {{ic|--alloc contiguous}}) and no further adjacent contiguous extents are available (see also [http://www.hostatic.ro/2010/02/15/lvm-inherit-and-contiguous-policies/ reference]).<br />
<br />
To fix this, prior to extending the logical volume, change its allocation policy with {{ic|lvchange --alloc inherit <logical_volume>}}. If you need to keep the contiguous allocation policy, an alternative approach is to move the volume to a disk area with sufficient free extents (see [http://superuser.com/questions/435075/how-to-align-logical-volumes-on-contiguous-physical-extents]).<br />
<br />
=== Command "grub-mkconfig" reports "unknown filesystem" errors ===<br />
<br />
Make sure to remove snapshot volumes before [[GRUB#Generate_the_main_configuration_file|generating grub.cfg]].<br />
<br />
=== Thinly-provisioned root volume device times out ===<br />
<br />
With a large number of snapshots, {{Ic|thin_check}} runs for a long enough time so that waiting for the root device times out. To compensate, add the {{Ic|1=rootdelay=60}} kernel boot parameter to your boot loader configuration.<br />
<br />
=== Delay on shutdown ===<br />
<br />
If you use RAID, snapshots or thin provisioning and experience a delay on shutdown, [[enable]] and [[start]] {{ic|lvm2-monitor.service}}. See {{Bug|50420}}.<br />
<br />
== See also ==<br />
<br />
* [http://sourceware.org/lvm2/ LVM2 Resource Page] on SourceWare.org<br />
* [http://wiki.gentoo.org/wiki/LVM LVM] article at Gentoo wiki<br />
* [http://www.tutonics.com/2012/11/ubuntu-lvm-guide-part-1.html Ubuntu LVM Guide Part 1][http://www.tutonics.com/2012/12/lvm-guide-part-2-snapshots.html Part 2 detals snapshots]<br />
* [https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Logical_Volume_Manager_Administration/index.html Red Hat: Logical Volume Manager Administration]</div>X33ahttps://wiki.archlinux.org/index.php?title=Pacman&diff=461365Pacman2017-01-04T03:28:37Z<p>X33a: moved pkgfile, pacman -F section to usage</p>
<hr />
<div>{{Lowercase title}}<br />
[[Category:Package management]]<br />
[[ar:Pacman]]<br />
[[cs:Pacman]]<br />
[[da:Pacman]]<br />
[[de:Pacman]]<br />
[[el:Pacman]]<br />
[[es:Pacman]]<br />
[[fa:Pacman]]<br />
[[fr:Pacman]]<br />
[[id:Pacman]]<br />
[[it:Pacman]]<br />
[[ja:Pacman]]<br />
[[ko:Pacman]]<br />
[[nl:Pacman]]<br />
[[pl:Pacman]]<br />
[[pt:Pacman]]<br />
[[ro:Pacman]]<br />
[[ru:Pacman]]<br />
[[sr:Pacman]]<br />
[[sv:Pacman]]<br />
[[tr:pacman]]<br />
[[uk:Pacman]]<br />
[[zh-CN:Pacman]]<br />
[[zh-TW:Pacman]]<br />
{{Related articles start}}<br />
{{Related|Creating packages}}<br />
{{Related|Downgrading packages}}<br />
{{Related|pacman/Package signing}}<br />
{{Related|pacman/Pacnew and Pacsave}}<br />
{{Related|pacman/Restore local database}}<br />
{{Related|pacman/Rosetta}}<br />
{{Related|pacman/Tips and tricks}}<br />
{{Related|FAQ#Package management}}<br />
{{Related|System maintenance}}<br />
{{Related|Arch Build System}}<br />
{{Related|Official repositories}}<br />
{{Related|Arch User Repository}}<br />
{{Related articles end}}<br />
<br />
The [https://www.archlinux.org/pacman/ pacman] [[Wikipedia:Package manager|package manager]] is one of the major distinguishing features of Arch Linux. It combines a simple binary package format with an easy-to-use [[Arch Build System|build system]]. The goal of ''pacman'' is to make it possible to easily manage packages, whether they are from the [[official repositories]] or the user's own builds.<br />
<br />
''pacman'' keeps the system up to date by synchronizing package lists with the master server. This server/client model also allows the user to download/install packages with a simple command, complete with all required dependencies.<br />
<br />
''pacman'' is written in the C programming language and uses the ''.pkg.tar.xz'' package format.<br />
<br />
{{Tip|The {{Pkg|pacman}} package contains other useful tools such as [[makepkg]], '''pactree''', '''vercmp''', and [[checkupdates]]. Run {{ic|pacman -Qlq pacman <nowiki>|</nowiki> grep bin}} to see the full list.}}<br />
<br />
== Usage ==<br />
<br />
What follows is just a small sample of the operations that ''pacman'' can perform. To read more examples, refer to {{man|8|pacman|url=https://www.archlinux.org/pacman/pacman.8.html#_examples}}.<br />
<br />
{{Tip|For those who have used other Linux distributions before, there is a helpful [[Pacman Rosetta]] article.}}<br />
<br />
=== Installing packages ===<br />
<br />
{{Note|Packages often have a series of [[PKGBUILD#optdepends|optional dependencies]] which are packages that provide additional functionality to the application, albeit not strictly required for running it. When installing a package, ''pacman'' will list its optional dependencies among the output messages, but they will not be found in {{ic|pacman.log}}: use the [[#Querying package databases|pacman -Si]] command to view the optional dependencies of a package, together with short descriptions of their functionality.}}<br />
<br />
{{Warning|1=When installing packages in Arch, avoid refreshing the package list without [[#Upgrading packages|upgrading the system]] (for example, when a [[#Packages cannot be retrieved on installation|package is no longer found]] in the official repositories). In practice, do '''not''' run {{ic|pacman -Sy ''package_name''}} instead of {{ic|pacman -Sy'''u''' ''package_name''}}, as this could lead to dependency issues. See [[System maintenance#Partial upgrades are unsupported]] and [https://bbs.archlinux.org/viewtopic.php?id=89328 BBS#89328].}}<br />
<br />
==== Installing specific packages ====<br />
<br />
To install a single package or list of packages (including dependencies), issue the following command:<br />
<br />
# pacman -S ''package_name1'' ''package_name2'' ...<br />
<br />
To install a list of packages with regex (see [https://bbs.archlinux.org/viewtopic.php?id=7179 this forum thread]):<br />
<br />
# pacman -S $(pacman -Ssq ''package_regex'')<br />
<br />
Sometimes there are multiple versions of a package in different repositories, e.g. ''extra'' and ''testing''. To install the former version, the repository needs to be defined in front:<br />
<br />
# pacman -S extra/''package_name''<br />
<br />
To install a number of packages sharing similar patterns in their names -- not the entire group nor all matching packages; eg. {{Grp|plasma}}:<br />
<br />
# pacman -S plasma-{desktop,mediacenter,nm}<br />
<br />
Of course, that is not limited and can be expanded to however many levels needed:<br />
<br />
# pacman -S plasma-{workspace{,-wallpapers},pa}<br />
<br />
==== Installing package groups ====<br />
<br />
Some packages belong to a [[Creating_packages#Meta_packages_and_groups|group of packages]] that can all be installed simultaneously. For example, issuing the command:<br />
<br />
# pacman -S gnome<br />
<br />
will prompt you to select the packages from the {{Grp|gnome}} group that you wish to install.<br />
<br />
Sometimes a package group will contain a large amount of packages, and there may be only a few that you do or do not want to install. Instead of having to enter all the numbers except the ones you do not want, it is sometimes more convenient to select or exclude packages or ranges of packages with the following syntax:<br />
<br />
Enter a selection (default=all): 1-10 15<br />
<br />
which will select packages 1 through 10 and 15 for installation, or:<br />
<br />
Enter a selection (default=all): ^5-8 ^2<br />
<br />
which will select all packages except 5 through 8 and 2 for installation.<br />
<br />
To see what packages belong to the gnome group, run:<br />
<br />
# pacman -Sg gnome<br />
<br />
Also visit https://www.archlinux.org/groups/ to see what package groups are available.<br />
<br />
{{Note|If a package in the list is already installed on the system, it will be reinstalled even if it is already up to date. This behavior can be overridden with the {{ic|--needed}} option.}}<br />
<br />
=== Removing packages ===<br />
<br />
To remove a single package, leaving all of its dependencies installed:<br />
<br />
# pacman -R ''package_name''<br />
<br />
To remove a package and its dependencies which are not required by any other installed package:<br />
<br />
# pacman -Rs ''package_name''<br />
<br />
To remove a package, its dependencies and all the packages that depend on the target package:<br />
<br />
{{Warning|This operation is recursive, and must be used with care since it can remove many potentially needed packages.}}<br />
<br />
# pacman -Rsc ''package_name''<br />
<br />
To remove a package, which is required by another package, without removing the dependent package:<br />
<br />
# pacman -Rdd ''package_name''<br />
<br />
''pacman'' saves important configuration files when removing certain applications and names them with the extension: ''.pacsave''. To prevent the creation of these backup files use the {{ic|-n}} option:<br />
<br />
# pacman -Rn ''package_name''<br />
<br />
{{Note|''pacman'' will not remove configurations that the application itself creates (for example "dotfiles" in the home folder).}}<br />
<br />
=== Upgrading packages ===<br />
<br />
{{Merge|System maintenance||Talk:Pacman#Don't rush upgrades}}<br />
{{Warning|Arch only supports full system upgrades. See [[System maintenance#Partial upgrades are unsupported]] and [[#Installing packages]] for details.}}<br />
<br />
It is recommended that users [[System_maintenance#Upgrading the system|upgrade their system regularly]]. When requesting support from the community, it will usually be assumed that the system is up to date.<br />
<br />
Before upgrading, users are expected to visit the [https://www.archlinux.org/ Arch Linux home page] to check the latest news, or alternatively subscribe to the [https://www.archlinux.org/feeds/news/ RSS feed], [https://mailman.archlinux.org/mailman/listinfo/arch-announce/ arch-announce mailing list], or follow [https://twitter.com/archlinux @archlinux] on Twitter: when updates require out-of-the-ordinary user intervention (more than what can be handled simply by following the instructions given by ''pacman''), an appropriate news post will be made. Users must equally be aware that upgrading packages can raise '''unexpected''' problems that could need immediate intervention, therefore it is discouraged to upgrade a stable system shortly before it is required for carrying out an important task: it is wise to wait instead to have enough time in order to be able to deal with possible post-upgrade issues.<br />
<br />
''pacman'' can update all packages on the system with just one command. This could take quite a while depending on how up-to-date the system is. This command can synchronize the repository databases ''and'' update the system's packages (excluding "local" packages that are not in the configured repositories):<br />
<br />
# pacman -Syu<br />
<br />
''pacman'' is a powerful package management tool, but it does not attempt to handle all corner cases. Users must be vigilant and take responsibility for maintaining their own system. '''When performing a system update, it is essential that users read all information output by ''pacman'' and use common sense.''' If a user-modified configuration file needs to be upgraded for a new version of a package, a ''.pacnew'' file will be created to avoid overwriting settings modified by the user. ''pacman'' will prompt the user to merge them. These files require manual intervention from the user and it is good practice to handle them right after every package upgrade or removal. See [[Pacnew and Pacsave files]] for more information.<br />
<br />
{{Tip|<br />
* Remember that ''pacman'''s output is logged in {{ic|/var/log/pacman.log}}.<br />
* You can use a log viewer such as {{AUR|wat-git}} to search the pacman logs.}}<br />
<br />
If one encounters problems that cannot be solved by these instructions, make sure to search the forum. It is likely that others have encountered the same problem and have posted instructions for solving it.<br />
<br />
=== Querying package databases ===<br />
<br />
''pacman'' queries the local package database with the {{ic|-Q}} flag; see:<br />
<br />
$ pacman -Q --help<br />
<br />
and queries the sync databases with the {{ic|-S}} flag; see:<br />
<br />
$ pacman -S --help<br />
<br />
''pacman'' can search for packages in the database, searching both in packages' names and descriptions:<br />
<br />
$ pacman -Ss ''string1'' ''string2'' ...<br />
<br />
Sometimes, {{Ic|-s}}'s builtin ERE can cause a lot of unwanted results, so it has to be limited to match the package name only; not the description nor any other field:<br />
<br />
# pacman -Ss '^vim-'<br />
<br />
To search for already installed packages:<br />
<br />
$ pacman -Qs ''string1'' ''string2'' ...<br />
<br />
To display extensive information about a given package:<br />
<br />
$ pacman -Si ''package_name''<br />
<br />
For locally installed packages:<br />
<br />
$ pacman -Qi ''package_name''<br />
<br />
Passing two {{ic|-i}} flags will also display the list of backup files and their modification states:<br />
<br />
$ pacman -Qii ''package_name''<br />
<br />
To retrieve a list of the files installed by a package:<br />
<br />
$ pacman -Ql ''package_name''<br />
<br />
For packages not installed, use [[pkgfile]].<br />
<br />
To verify the presence of the files installed by a package:<br />
<br />
$ pacman -Qk ''package_name''<br />
<br />
Passing the {{ic|k}} flag twice will perform a more thorough check.<br />
<br />
One can also query the database to know which package a file in the file system belongs to:<br />
<br />
$ pacman -Qo ''/path/to/file_name''<br />
<br />
To list all packages no longer required as dependencies (orphans):<br />
<br />
$ pacman -Qdt<br />
<br />
To list all packages explicitly installed and not required as dependencies:<br />
<br />
$ pacman -Qet<br />
<br />
To list a dependency tree of a package:<br />
<br />
$ pactree ''package_name''<br />
<br />
To list all the packages recursively depending on an ''installed'' package, use ''whoneeds'' from {{AUR|pkgtools}}:<br />
<br />
$ whoneeds ''package_name''<br />
<br />
or the reverse flag to ''pactree'':<br />
<br />
$ pactree -r ''package_name''<br />
<br />
See [[pacman tips]] for more examples.<br />
<br />
==== Database structure ====<br />
<br />
The pacman databases are normally located at {{ic|/var/lib/pacman/sync}}. For each repository specified in {{ic|/etc/pacman.conf}} there will be a corresponding database file located there. Database files are tar-gzipped archives containing one directory for each package, for example for the {{Pkg|which}} package:<br />
<br />
{{bc|<br />
% tree which-2.20-6 <br />
which-2.20-6<nowiki><br />
|-- depends<br />
`-- desc</nowiki><br />
}}<br />
<br />
The {{ic|depends}} file lists the packages this package depends on, while {{ic|desc}} has a description of the package such as the file size and the MD5 hash.<br />
<br />
=== Cleaning the package cache ===<br />
<br />
''pacman'' stores its downloaded packages in {{ic|/var/cache/pacman/pkg/}} and does not remove the old or uninstalled versions automatically, therefore it is necessary to deliberately clean up that folder periodically to prevent such folder to grow indefinitely in size.<br />
<br />
The built-in option to remove all the cached packages that are not currently installed is:<br />
<br />
# pacman -Sc<br />
<br />
{{Warning|<br />
* Only do this when certain that previous package versions are not required, for example for a later [[downgrade]]. {{ic|pacman -Sc}} only leaves the versions of packages which are ''currently installed'' available, older versions would have to be retrieved through other means, such as the [[Archive]].<br />
* It is possible to empty the cache folder fully with {{ic|pacman -Scc}}. In addition to the above, this also prevents from reinstalling a package directly ''from'' the cache folder in case of need, thus requiring a new download. It should be avoided unless there is an immediate need for disk space.<br />
}}<br />
<br />
Because of the above limitations, consider an alternative for more control over which packages, and how many, are deleted from the cache:<br />
<br />
The ''paccache'' script, provided by the {{Pkg|pacman}} package itself, deletes all cached versions of each package regardless of whether they're installed or not, except for the most recent 3, by default:<br />
<br />
# paccache -r<br />
<br />
You can also define how many recent versions you want to keep:<br />
<br />
# paccache -rk 1<br />
<br />
To remove all cached versions of uninstalled packages, re-run ''paccache'' with:<br />
<br />
# paccache -ruk0<br />
<br />
See {{ic|paccache -h}} for more options.<br />
<br />
{{AUR|pkgcacheclean}} and {{AUR|pacleaner}} are two further alternatives.<br />
<br />
=== Additional commands ===<br />
<br />
Download a package without installing it:<br />
<br />
# pacman -Sw ''package_name''<br />
<br />
Install a 'local' package that is not from a remote repository (e.g. the package is from the [[AUR]]):<br />
<br />
# pacman -U ''/path/to/package/package_name-version.pkg.tar.xz''<br />
<br />
To keep a copy of the local package in ''pacman'''s cache, use:<br />
<br />
# pacman -U file:///''path/to/package/package_name-version.pkg.tar.xz''<br />
<br />
Install a 'remote' package (not from a repository stated in ''pacman'''s configuration files):<br />
<br />
# pacman -U ''<nowiki>http://www.example.com/repo/example.pkg.tar.xz</nowiki>''<br />
<br />
To inhibit the {{ic|-S}}, {{ic|-U}} and {{ic|-R}} actions, {{ic|-p}} can be used.<br />
<br />
''pacman'' always lists packages to be installed or removed and asks for permission before it takes action.<br />
<br />
=== Installation reason ===<br />
<br />
The ''pacman'' database distinguishes the installed packages in two groups according to the reason why they were installed:<br />
<br />
* '''explicitly-installed''': the packages that were literally passed to a generic ''pacman'' {{ic|-S}} or {{ic|-U}} command;<br />
* '''dependencies''': the packages that, despite never (in general) having been passed to a ''pacman'' installation command, were implicitly installed because [[dependency|required]] by another package that was explicitly installed.<br />
<br />
When installing a package, it is possible to force its installation reason to ''dependency'' with:<br />
<br />
# pacman -S --asdeps ''package_name''<br />
<br />
When '''re'''installing a package, though, the current installation reason is preserved by default.<br />
<br />
The list of explicitly-installed packages can be shown with {{ic|pacman -Qe}}, while the complementary list of dependencies can be shown with {{ic|pacman -Qd}}.<br />
<br />
To change the installation reason of an already installed package, execute:<br />
<br />
# pacman -D --asdeps ''package_name''<br />
<br />
Use {{ic|--asexplicit}} to do the opposite operation.<br />
<br />
=== Search for a package that contains a specific file ===<br />
<br />
==== Using pkgfile ====<br />
Install [[pkgfile]] which uses a separate database with all files and their associated packages.<br />
<br />
==== Using pacman ====<br />
<br />
Since v5.0.0, pacman itself can do basic searching of files in sync repositories. [https://git.archlinux.org/pacman.git/tree/NEWS?h=v5.0.0#n5]<br />
<br />
Sync the files database:<br />
# pacman -Fy<br />
<br />
Search for a package containing a file, for e.g.:<br />
# pacman -Fs pacman<br />
core/pacman 5.0.1-4<br />
usr/bin/pacman<br />
usr/share/bash-completion/completions/pacman<br />
extra/xscreensaver 5.36-1<br />
usr/lib/xscreensaver/pacman<br />
<br />
{{Tip|You can set a cron job or a systemd timer to sync the files database regularly.}}<br />
<br />
== Configuration ==<br />
<br />
''pacman'''s settings are located in {{ic|/etc/pacman.conf}}: this is the place where the user configures the program to work in the desired manner. In-depth information about the configuration file can be found in {{man|5|pacman.conf|url=https://www.archlinux.org/pacman/pacman.conf.5.html}}.<br />
<br />
=== General options ===<br />
<br />
General options are in the {{ic|[options]}} section. Read {{man|8|pacman|url=https://www.archlinux.org/pacman/pacman.8.html}} or look in the default {{ic|pacman.conf}} for information on what can be done here.<br />
<br />
==== Comparing versions before updating ====<br />
<br />
To see old and new versions of available packages, uncomment the "VerbosePkgLists" line in {{ic|/etc/pacman.conf}}. The output of {{ic|pacman -Syu}} will be like this:<br />
<br />
Package (6) Old Version New Version Net Change Download Size<br />
<br />
extra/libmariadbclient 10.1.9-4 10.1.10-1 0.03 MiB 4.35 MiB<br />
extra/libpng 1.6.19-1 1.6.20-1 0.00 MiB 0.23 MiB<br />
extra/mariadb 10.1.9-4 10.1.10-1 0.26 MiB 13.80 MiB<br />
<br />
==== Skip package from being upgraded ====<br />
<br />
To have a specific package skipped when [[#Upgrading packages|upgrading]] the system, specify it as such:<br />
<br />
IgnorePkg=linux<br />
<br />
For multiple packages use a space-separated list, or use additional {{ic|IgnorePkg}} lines. Also, glob patterns can be used. If you want to skip packages just once, you can also use the {{ic|--ignore}} option on the command-line - this time with a comma-separated list.<br />
<br />
It will still be possible to upgrade the ignored packages using {{ic|pacman -S}}: in this case ''pacman'' will remind you that the packages have been included in an {{ic|IgnorePkg}} statement.<br />
<br />
==== Skip package group from being upgraded ====<br />
<br />
As with packages, skipping a whole package group is also possible:<br />
<br />
IgnoreGroup=gnome<br />
<br />
==== Skip files from being installed to system ====<br />
<br />
To always skip installation of specific directories list them under {{Ic|NoExtract}}. For example, to avoid installation of [[systemd]] units use this:<br />
<br />
NoExtract=usr/lib/systemd/system/*<br />
<br />
Later rules override previous ones, and you can negate a rule by prepending {{ic|!}}.<br />
<br />
{{Tip|''pacman'' issues warning messages about missing locales when updating a package for which locales have been cleared by ''localepurge'' or ''bleachbit''. Commenting the {{ic|CheckSpace}} option in {{ic|pacman.conf}} suppresses such warnings, but consider that the space-checking functionality will be disabled for all packages.}}<br />
<br />
==== Maintain several configuration files ====<br />
<br />
If you have several configuration files (e.g. main configuration and configuration with [[testing]] repository enabled) and would have to share options between configurations you may use {{ic|Include}} option declared in the configuration files, e.g.:<br />
<br />
Include = ''/path/to/common/settings''<br />
<br />
where {{ic|''/path/to/common/settings''}} file contains the same options for both configurations.<br />
<br />
==== Hooks ====<br />
<br />
''pacman'' can run pre- and post-transaction hooks from the {{ic|/usr/share/libalpm/hooks/}} directory; more directories can be specified with the {{ic|HookDir}} option in {{ic|pacman.conf}}, which defaults to {{ic|/etc/pacman.d/hooks}}. Hook file names must be suffixed with ''.hook''.<br />
<br />
For more information on alpm hooks, see {{man|5|alpm-hooks|url=https://www.archlinux.org/pacman/alpm-hooks.5.html}}.<br />
<br />
=== Repositories and mirrors ===<br />
<br />
Besides the special [[#General options|[options]]] section, each other {{ic|[section]}} in {{ic|pacman.conf}} defines a package repository to be used. A ''repository'' is a ''logical'' collection of packages, which are ''physically'' stored on one or more servers: for this reason each server is called a ''mirror'' for the repository.<br />
<br />
Repositories are distinguished between [[Official repositories|official]] and [[Unofficial user repositories|unofficial]]. The order of repositories in the configuration file matters; repositories listed first will take precedence over those listed later in the file when packages in two repositories have identical names, regardless of version number. In order to use a repository after adding it, you will need to [[#Upgrading packages|upgrade]] the whole system first.<br />
<br />
Each repository section allows defining the list of its mirrors directly or in a dedicated external file through the {{ic|Include}} directive: for example, the mirrors for the official repositories are included from {{ic|/etc/pacman.d/mirrorlist}}. See the [[Mirrors]] article for mirror configuration.<br />
<br />
==== Package security ====<br />
<br />
''pacman'' supports package signatures, which add an extra layer of security to the packages. The default configuration, {{ic|1=SigLevel = Required DatabaseOptional}}, enables signature verification for all the packages on a global level: this can be overridden by per-repository {{ic|SigLevel}} lines. For more details on package signing and signature verification, take a look at [[pacman-key]].<br />
<br />
== Troubleshooting ==<br />
<br />
=== "Failed to commit transaction (conflicting files)" error ===<br />
<br />
If you see the following error: [https://bbs.archlinux.org/viewtopic.php?id=56373]<br />
<br />
error: could not prepare transaction<br />
error: failed to commit transaction (conflicting files)<br />
''package'': ''/path/to/file'' exists in filesystem<br />
Errors occurred, no packages were upgraded.<br />
<br />
Why this is happening: ''pacman'' has detected a file conflict, and by design, will not overwrite files for you. This is a design feature, not a flaw.<br />
<br />
The problem is usually trivial to solve. A safe way is to first check if another package owns the file ({{ic|pacman -Qo ''/path/to/file''}}). If the file is owned by another package, [[Reporting bug guidelines|file a bug report]]. If the file is not owned by another package, rename the file which 'exists in filesystem' and re-issue the update command. If all goes well, the file may then be removed.<br />
<br />
If you had installed a program manually without using ''pacman'' or a frontend, for example through {{ic|make install}}, you have to remove it and all its files and reinstall properly using ''pacman''. See also [[Pacman tips#Identify files not owned by any package]].<br />
<br />
Every installed package provides a {{ic|/var/lib/pacman/local/''$package-$version''/files}} file that contains metadata about this package. If this file gets corrupted, is empty or goes missing, it results in {{ic|file exists in filesystem}} errors when trying to update the package. Such an error usually concerns only one package. Instead of manually renaming and later removing all the files that belong to the package in question, you may exceptionally run {{ic|pacman -S --force $package}} to force ''pacman'' to overwrite these files.<br />
<br />
{{Warning|Take care when using the {{ic|--force}} switch (for example {{ic|pacman -Syu --force}}) as it can cause major problems if used improperly. It is highly recommended to only use this option when the Arch news instructs the user to do so.}}<br />
<br />
=== "Failed to commit transaction (invalid or corrupted package)" error ===<br />
<br />
Look for ''.part'' files (partially downloaded packages) in {{ic|/var/cache/pacman/pkg}} and remove them (often caused by usage of a custom {{ic|XferCommand}} in {{ic|pacman.conf}}).<br />
<br />
# find /var/cache/pacman/pkg/ -iname "*.part" -exec rm {} \;<br />
<br />
=== "Failed to init transaction (unable to lock database)" error ===<br />
<br />
When ''pacman'' is about to alter the package database, for example installing a package, it creates a lock file at {{ic|/var/lib/pacman/db.lck}}. This prevents another instance of ''pacman'' from trying to alter the package database at the same time.<br />
<br />
If ''pacman'' is interrupted while changing the database, this stale lock file can remain. If you are certain that no instances of ''pacman'' are running then delete the lock file:<br />
<br />
# rm /var/lib/pacman/db.lck<br />
<br />
=== Packages cannot be retrieved on installation ===<br />
<br />
This error manifests as {{ic|Not found in sync db}}, {{ic|Target not found}} or {{ic|Failed retrieving file}}.<br />
<br />
Firstly, ensure the package actually exists (and watch out for typos!). If certain the package exists, your package list may be out-of-date or your repositories may be incorrectly configured. Try running {{ic|pacman -Syyu}} to force a refresh of all package lists and upgrade.<br />
<br />
It could also be that the repository containing the package is not enabled on your system, e.g. the package could be in the ''multilib'' repository, but ''multilib'' is not enabled in your ''pacman.conf''.<br />
<br />
See also [[FAQ#Why is there only a single version of each shared library in the official repositories?]].<br />
<br />
=== Manually reinstalling pacman ===<br />
<br />
{{Warning|It is extremely easy to break your system even worse using this approach. Use this only as a last resort if the method from [[#pacman crashes during an upgrade]] is not an option.}}<br />
<br />
Even if ''pacman'' is terribly broken, you can fix it manually by downloading the latest packages and extracting them to the correct locations. The rough steps to perform are<br />
<br />
# Determine dependencies to install<br />
# Download each package from a mirror of your choice<br />
# Extract each package to root<br />
# Reinstall these packages with {{ic|pacman -Sf}} to update the package database accordingly<br />
# Do a full system upgrade<br />
<br />
If you have a healthy Arch system on hand, you can see the full list of dependencies with<br />
<br />
$ pacman -Q $(pactree -u pacman)<br />
<br />
but you may only need to update a few of them depending on your issue. An example of extracting a package is<br />
<br />
# tar -xvpwf ''package.tar.xz'' -C / --exclude .PKGINFO --exclude .INSTALL<br />
<br />
Note the use of the {{ic|w}} flag for interactive mode. Running non-interactively is very risky since you might end up overwriting an important file. Also take care to extract packages in the correct order (i.e. dependencies first). [https://bbs.archlinux.org/viewtopic.php?id=95007 This forum post] contains an example of this process where only a couple ''pacman'' dependencies are broken.<br />
<br />
=== pacman crashes during an upgrade ===<br />
<br />
In the case that ''pacman'' crashes with a "database write" error while removing packages, and reinstalling or upgrading packages fails thereafter, do the following:<br />
<br />
# Boot using the Arch installation media. Preferably use a recent media so that the ''pacman'' version matches/is newer than the system. <br />
# Mount the system's root filesystem, e.g. {{ic|mount /dev/sdaX /mnt}} as root, and check the mount has sufficient space with {{ic|df -h}} <br />
# If the system uses default database and directory locations, you can now update the system's pacman database and upgrade it via {{ic|1=pacman --root=/mnt --cachedir=/mnt/var/cache/pacman/pkg -Syyu}} as root. <br />
# After the upgrade, one way to double-check for not upgraded but still broken packages: {{ic|find /mnt/usr/lib -size 0}} <br />
# Followed by a re-install of any still broken package via {{ic|1=pacman --root /mnt --cachedir=/mnt/var/cache/pacman/pkg -S ''package''}}.<br />
<br />
=== "Unable to find root device" error after rebooting ===<br />
<br />
Most likely your initramfs got broken during a kernel update (improper use of ''pacman'''s {{ic|--force}} option can be a cause). You have two options; first, try the ''Fallback'' entry:<br />
<br />
{{Tip|In case you removed this entry for whatever reason, you can always press the {{ic|Tab}} key when the bootloader menu shows up (for Syslinux) or {{ic|e}} (for GRUB or systemd-boot), rename it {{ic|initramfs-linux-fallback.img}} and press {{ic|Enter}} or {{ic|b}} (depending on your bootloader) to boot with the new parameters.}}<br />
<br />
Once the system starts, run this command (for the stock {{Pkg|linux}} kernel) either from the console or from a terminal to rebuild the initramfs image:<br />
<br />
# mkinitcpio -p linux<br />
<br />
If that does not work, from a current Arch release (CD/DVD or USB stick), run:<br />
<br />
{{Note|If you do not have a current release or if you only have some other "live" Linux distribution laying around, you can [[chroot]] using the old fashioned way. Obviously, there will be more typing than simply running the {{ic|arch-chroot}} script.}}<br />
<br />
# mount /dev/sdxY /mnt # Your root partition.<br />
# mount /dev/sdxZ /mnt/boot # If you use a separate /boot partition.<br />
# arch-chroot /mnt<br />
# pacman -Syu mkinitcpio systemd linux<br />
<br />
{{Note|If ''pacman'' fails with {{ic|Could not resolve host}}, please [[Network_configuration#Check_the_connection|check your internet connection]].}}<br />
<br />
Reinstalling the kernel (the {{Pkg|linux}} package) will automatically re-generate the initramfs image with {{ic|mkinitcpio -p linux}}. There is no need to do this separately.<br />
<br />
Afterwards, it is recommended that you run {{ic|exit}}, {{ic|umount /mnt/{boot,} }} and {{ic|reboot}}.<br />
<br />
{{Note|If you cannot enter the arch-chroot or chroot environment but need to re-install packages you can use the command {{ic|pacman -r /mnt -Syu foo bar}} to use ''pacman'' on your root partition.}}<br />
<br />
=== Signature from "User <email@gmail.com>" is unknown trust, installation failed ===<br />
<br />
Follow [[pacman-key#Resetting all the keys]]. Or you can try to either:<br />
* update the known keys, i.e. {{ic|pacman-key --refresh-keys}};<br />
* or manually upgrade {{Pkg|archlinux-keyring}} package first, i.e. {{ic|pacman -S archlinux-keyring}}.<br />
<br />
=== Request on importing PGP keys ===<br />
<br />
If [[Installation guide|installing]] Arch with an outdated ISO, you are likely prompted to import PGP keys. Agree to download the key to proceed. If you are unable to add the PGP key successfully, update the keyring or upgrade {{Pkg|archlinux-keyring}} (see [[#Signature from "User <email@gmail.com>" is unknown trust, installation failed|above]]).<br />
<br />
=== Signature from "User <email@archlinux.org>" is invalid, installation failed ===<br />
<br />
When the system time is faulty, signing keys are considered expired (or invalid) and signature checks on packages will fail with the following error:<br />
<br />
error: ''package'': signature from "User <email@archlinux.org>" is invalid<br />
error: failed to commit transaction (invalid or corrupted package (PGP signature))<br />
Errors occured, no packages were upgraded.<br />
<br />
Make sure to correct the [[time]], for example with {{ic|ntpd -qg}} run as root, and run {{ic|hwclock -w}} as root before subsequent installations or upgrades.<br />
<br />
=== "Warning: current locale is invalid; using default "C" locale" error ===<br />
<br />
As the error message says, your locale is not correctly configured. See [[Locale]].<br />
<br />
=== pacman does not honor proxy settings ===<br />
<br />
Make sure that the relevant environment variables ({{ic|$http_proxy}}, {{ic|$ftp_proxy}} etc.) are set up. If you use ''pacman'' with [[sudo]], you need to configure sudo to [[sudo#Environment variables|pass these environment variables to pacman]].<br />
<br />
=== How do I reinstall all packages, retaining information on whether something was explicitly installed or as a dependency? ===<br />
<br />
To reinstall all the native packages: {{ic|<nowiki>pacman -Qnq | pacman -S -</nowiki>}} (the {{ic|-S}} option preserves the installation reason by default).<br />
<br />
You will then need to reinstall all the foreign packages, which can be listed with {{ic|pacman -Qmq}}.<br />
<br />
=== "Cannot open shared object file" error ===<br />
<br />
It looks like previous ''pacman'' transaction removed or corrupted shared libraries needed for pacman itself.<br />
<br />
To recover from this situation you need to unpack required libraries to your filesystem manually. First find what package contains the missed library and then locate it in the ''pacman'' cache ({{ic|/var/cache/pacman/pkg/}}). Unpack required shared library to the filesystem. This will allow to run ''pacman''.<br />
<br />
Now you need to [[#Installing specific packages|reinstall]] the broken package. Note that you need to use {{ic|--force}} flag as you just unpacked system files and ''pacman'' does not know about it. ''pacman'' will correctly replace our shared library file with one from package.<br />
<br />
That's it. Update the rest of the system.<br />
<br />
=== Freeze of package downloads ===<br />
<br />
Some issues have been reported regarding network problems that prevent ''pacman'' from updating/synchronizing repositories. [https://bbs.archlinux.org/viewtopic.php?id&#61;68944] [https://bbs.archlinux.org/viewtopic.php?id&#61;65728] When installing Arch Linux natively, these issues have been resolved by replacing the default ''pacman'' file downloader with an alternative (see [[Improve pacman performance]] for more details). When installing Arch Linux as a guest OS in [[VirtualBox]], this issue has also been addressed by using ''Host interface'' instead of ''NAT'' in the machine properties.<br />
<br />
=== Failed retrieving file 'core.db' from mirror ===<br />
<br />
If you receive this error message with correct [[mirrors]], try setting a different [[Resolv.conf|name server]].<br />
<br />
== See also ==<br />
<br />
* [https://www.archlinux.org/pacman/ Pacman Home Page]<br />
* {{man|3|libalpm|url=https://www.archlinux.org/pacman/libalpm.3.html}}<br />
* {{man|8|pacman|url=https://www.archlinux.org/pacman/pacman.8.html}}<br />
* {{man|5|pacman.conf|url=https://www.archlinux.org/pacman/pacman.conf.5.html}}<br />
* {{man|8|repo-add|url=https://www.archlinux.org/pacman/repo-add.8.html}}</div>X33ahttps://wiki.archlinux.org/index.php?title=Pacman&diff=461254Pacman2017-01-03T13:56:40Z<p>X33a: Removing the expansion tag as I have added content on -F and one example for -D already exists.</p>
<hr />
<div>{{Lowercase title}}<br />
[[Category:Package management]]<br />
[[ar:Pacman]]<br />
[[cs:Pacman]]<br />
[[da:Pacman]]<br />
[[de:Pacman]]<br />
[[el:Pacman]]<br />
[[es:Pacman]]<br />
[[fa:Pacman]]<br />
[[fr:Pacman]]<br />
[[id:Pacman]]<br />
[[it:Pacman]]<br />
[[ja:Pacman]]<br />
[[ko:Pacman]]<br />
[[nl:Pacman]]<br />
[[pl:Pacman]]<br />
[[pt:Pacman]]<br />
[[ro:Pacman]]<br />
[[ru:Pacman]]<br />
[[sr:Pacman]]<br />
[[sv:Pacman]]<br />
[[tr:pacman]]<br />
[[uk:Pacman]]<br />
[[zh-CN:Pacman]]<br />
[[zh-TW:Pacman]]<br />
{{Related articles start}}<br />
{{Related|Creating packages}}<br />
{{Related|Downgrading packages}}<br />
{{Related|pacman/Package signing}}<br />
{{Related|pacman/Pacnew and Pacsave}}<br />
{{Related|pacman/Restore local database}}<br />
{{Related|pacman/Rosetta}}<br />
{{Related|pacman/Tips and tricks}}<br />
{{Related|FAQ#Package management}}<br />
{{Related|System maintenance}}<br />
{{Related|Arch Build System}}<br />
{{Related|Official repositories}}<br />
{{Related|Arch User Repository}}<br />
{{Related articles end}}<br />
<br />
The [https://www.archlinux.org/pacman/ pacman] [[Wikipedia:Package manager|package manager]] is one of the major distinguishing features of Arch Linux. It combines a simple binary package format with an easy-to-use [[Arch Build System|build system]]. The goal of ''pacman'' is to make it possible to easily manage packages, whether they are from the [[official repositories]] or the user's own builds.<br />
<br />
''pacman'' keeps the system up to date by synchronizing package lists with the master server. This server/client model also allows the user to download/install packages with a simple command, complete with all required dependencies.<br />
<br />
''pacman'' is written in the C programming language and uses the ''.pkg.tar.xz'' package format.<br />
<br />
{{Tip|The {{Pkg|pacman}} package contains other useful tools such as [[makepkg]], '''pactree''', '''vercmp''', and [[checkupdates]]. Run {{ic|pacman -Qlq pacman <nowiki>|</nowiki> grep bin}} to see the full list.}}<br />
<br />
== Usage ==<br />
<br />
What follows is just a small sample of the operations that ''pacman'' can perform. To read more examples, refer to {{man|8|pacman|url=https://www.archlinux.org/pacman/pacman.8.html#_examples}}.<br />
<br />
{{Tip|For those who have used other Linux distributions before, there is a helpful [[Pacman Rosetta]] article.}}<br />
<br />
=== Installing packages ===<br />
<br />
{{Note|Packages often have a series of [[PKGBUILD#optdepends|optional dependencies]] which are packages that provide additional functionality to the application, albeit not strictly required for running it. When installing a package, ''pacman'' will list its optional dependencies among the output messages, but they will not be found in {{ic|pacman.log}}: use the [[#Querying package databases|pacman -Si]] command to view the optional dependencies of a package, together with short descriptions of their functionality.}}<br />
<br />
{{Warning|1=When installing packages in Arch, avoid refreshing the package list without [[#Upgrading packages|upgrading the system]] (for example, when a [[#Packages cannot be retrieved on installation|package is no longer found]] in the official repositories). In practice, do '''not''' run {{ic|pacman -Sy ''package_name''}} instead of {{ic|pacman -Sy'''u''' ''package_name''}}, as this could lead to dependency issues. See [[System maintenance#Partial upgrades are unsupported]] and [https://bbs.archlinux.org/viewtopic.php?id=89328 BBS#89328].}}<br />
<br />
==== Installing specific packages ====<br />
<br />
To install a single package or list of packages (including dependencies), issue the following command:<br />
<br />
# pacman -S ''package_name1'' ''package_name2'' ...<br />
<br />
To install a list of packages with regex (see [https://bbs.archlinux.org/viewtopic.php?id=7179 this forum thread]):<br />
<br />
# pacman -S $(pacman -Ssq ''package_regex'')<br />
<br />
Sometimes there are multiple versions of a package in different repositories, e.g. ''extra'' and ''testing''. To install the former version, the repository needs to be defined in front:<br />
<br />
# pacman -S extra/''package_name''<br />
<br />
To install a number of packages sharing similar patterns in their names -- not the entire group nor all matching packages; eg. {{Grp|plasma}}:<br />
<br />
# pacman -S plasma-{desktop,mediacenter,nm}<br />
<br />
Of course, that is not limited and can be expanded to however many levels needed:<br />
<br />
# pacman -S plasma-{workspace{,-wallpapers},pa}<br />
<br />
==== Installing package groups ====<br />
<br />
Some packages belong to a [[Creating_packages#Meta_packages_and_groups|group of packages]] that can all be installed simultaneously. For example, issuing the command:<br />
<br />
# pacman -S gnome<br />
<br />
will prompt you to select the packages from the {{Grp|gnome}} group that you wish to install.<br />
<br />
Sometimes a package group will contain a large amount of packages, and there may be only a few that you do or do not want to install. Instead of having to enter all the numbers except the ones you do not want, it is sometimes more convenient to select or exclude packages or ranges of packages with the following syntax:<br />
<br />
Enter a selection (default=all): 1-10 15<br />
<br />
which will select packages 1 through 10 and 15 for installation, or:<br />
<br />
Enter a selection (default=all): ^5-8 ^2<br />
<br />
which will select all packages except 5 through 8 and 2 for installation.<br />
<br />
To see what packages belong to the gnome group, run:<br />
<br />
# pacman -Sg gnome<br />
<br />
Also visit https://www.archlinux.org/groups/ to see what package groups are available.<br />
<br />
{{Note|If a package in the list is already installed on the system, it will be reinstalled even if it is already up to date. This behavior can be overridden with the {{ic|--needed}} option.}}<br />
<br />
=== Removing packages ===<br />
<br />
To remove a single package, leaving all of its dependencies installed:<br />
<br />
# pacman -R ''package_name''<br />
<br />
To remove a package and its dependencies which are not required by any other installed package:<br />
<br />
# pacman -Rs ''package_name''<br />
<br />
To remove a package, its dependencies and all the packages that depend on the target package:<br />
<br />
{{Warning|This operation is recursive, and must be used with care since it can remove many potentially needed packages.}}<br />
<br />
# pacman -Rsc ''package_name''<br />
<br />
To remove a package, which is required by another package, without removing the dependent package:<br />
<br />
# pacman -Rdd ''package_name''<br />
<br />
''pacman'' saves important configuration files when removing certain applications and names them with the extension: ''.pacsave''. To prevent the creation of these backup files use the {{ic|-n}} option:<br />
<br />
# pacman -Rn ''package_name''<br />
<br />
{{Note|''pacman'' will not remove configurations that the application itself creates (for example "dotfiles" in the home folder).}}<br />
<br />
=== Upgrading packages ===<br />
<br />
{{Merge|System maintenance||Talk:Pacman#Don't rush upgrades}}<br />
{{Warning|Arch only supports full system upgrades. See [[System maintenance#Partial upgrades are unsupported]] and [[#Installing packages]] for details.}}<br />
<br />
It is recommended that users [[System_maintenance#Upgrading the system|upgrade their system regularly]]. When requesting support from the community, it will usually be assumed that the system is up to date.<br />
<br />
Before upgrading, users are expected to visit the [https://www.archlinux.org/ Arch Linux home page] to check the latest news, or alternatively subscribe to the [https://www.archlinux.org/feeds/news/ RSS feed], [https://mailman.archlinux.org/mailman/listinfo/arch-announce/ arch-announce mailing list], or follow [https://twitter.com/archlinux @archlinux] on Twitter: when updates require out-of-the-ordinary user intervention (more than what can be handled simply by following the instructions given by ''pacman''), an appropriate news post will be made. Users must equally be aware that upgrading packages can raise '''unexpected''' problems that could need immediate intervention, therefore it is discouraged to upgrade a stable system shortly before it is required for carrying out an important task: it is wise to wait instead to have enough time in order to be able to deal with possible post-upgrade issues.<br />
<br />
''pacman'' can update all packages on the system with just one command. This could take quite a while depending on how up-to-date the system is. This command can synchronize the repository databases ''and'' update the system's packages (excluding "local" packages that are not in the configured repositories):<br />
<br />
# pacman -Syu<br />
<br />
''pacman'' is a powerful package management tool, but it does not attempt to handle all corner cases. Users must be vigilant and take responsibility for maintaining their own system. '''When performing a system update, it is essential that users read all information output by ''pacman'' and use common sense.''' If a user-modified configuration file needs to be upgraded for a new version of a package, a ''.pacnew'' file will be created to avoid overwriting settings modified by the user. ''pacman'' will prompt the user to merge them. These files require manual intervention from the user and it is good practice to handle them right after every package upgrade or removal. See [[Pacnew and Pacsave files]] for more information.<br />
<br />
{{Tip|<br />
* Remember that ''pacman'''s output is logged in {{ic|/var/log/pacman.log}}.<br />
* You can use a log viewer such as {{AUR|wat-git}} to search the pacman logs.}}<br />
<br />
If one encounters problems that cannot be solved by these instructions, make sure to search the forum. It is likely that others have encountered the same problem and have posted instructions for solving it.<br />
<br />
=== Querying package databases ===<br />
<br />
''pacman'' queries the local package database with the {{ic|-Q}} flag; see:<br />
<br />
$ pacman -Q --help<br />
<br />
and queries the sync databases with the {{ic|-S}} flag; see:<br />
<br />
$ pacman -S --help<br />
<br />
''pacman'' can search for packages in the database, searching both in packages' names and descriptions:<br />
<br />
$ pacman -Ss ''string1'' ''string2'' ...<br />
<br />
Sometimes, {{Ic|-s}}'s builtin ERE can cause a lot of unwanted results, so it has to be limited to match the package name only; not the description nor any other field:<br />
<br />
# pacman -Ss '^vim-'<br />
<br />
To search for already installed packages:<br />
<br />
$ pacman -Qs ''string1'' ''string2'' ...<br />
<br />
To display extensive information about a given package:<br />
<br />
$ pacman -Si ''package_name''<br />
<br />
For locally installed packages:<br />
<br />
$ pacman -Qi ''package_name''<br />
<br />
Passing two {{ic|-i}} flags will also display the list of backup files and their modification states:<br />
<br />
$ pacman -Qii ''package_name''<br />
<br />
To retrieve a list of the files installed by a package:<br />
<br />
$ pacman -Ql ''package_name''<br />
<br />
For packages not installed, use [[pkgfile]].<br />
<br />
To verify the presence of the files installed by a package:<br />
<br />
$ pacman -Qk ''package_name''<br />
<br />
Passing the {{ic|k}} flag twice will perform a more thorough check.<br />
<br />
One can also query the database to know which package a file in the file system belongs to:<br />
<br />
$ pacman -Qo ''/path/to/file_name''<br />
<br />
To list all packages no longer required as dependencies (orphans):<br />
<br />
$ pacman -Qdt<br />
<br />
To list all packages explicitly installed and not required as dependencies:<br />
<br />
$ pacman -Qet<br />
<br />
To list a dependency tree of a package:<br />
<br />
$ pactree ''package_name''<br />
<br />
To list all the packages recursively depending on an ''installed'' package, use ''whoneeds'' from {{AUR|pkgtools}}:<br />
<br />
$ whoneeds ''package_name''<br />
<br />
or the reverse flag to ''pactree'':<br />
<br />
$ pactree -r ''package_name''<br />
<br />
See [[pacman tips]] for more examples.<br />
<br />
==== Database structure ====<br />
<br />
The pacman databases are normally located at {{ic|/var/lib/pacman/sync}}. For each repository specified in {{ic|/etc/pacman.conf}} there will be a corresponding database file located there. Database files are tar-gzipped archives containing one directory for each package, for example for the {{Pkg|which}} package:<br />
<br />
{{bc|<br />
% tree which-2.20-6 <br />
which-2.20-6<nowiki><br />
|-- depends<br />
`-- desc</nowiki><br />
}}<br />
<br />
The {{ic|depends}} file lists the packages this package depends on, while {{ic|desc}} has a description of the package such as the file size and the MD5 hash.<br />
<br />
=== Cleaning the package cache ===<br />
<br />
''pacman'' stores its downloaded packages in {{ic|/var/cache/pacman/pkg/}} and does not remove the old or uninstalled versions automatically, therefore it is necessary to deliberately clean up that folder periodically to prevent such folder to grow indefinitely in size.<br />
<br />
The built-in option to remove all the cached packages that are not currently installed is:<br />
<br />
# pacman -Sc<br />
<br />
{{Warning|<br />
* Only do this when certain that previous package versions are not required, for example for a later [[downgrade]]. {{ic|pacman -Sc}} only leaves the versions of packages which are ''currently installed'' available, older versions would have to be retrieved through other means, such as the [[Archive]].<br />
* It is possible to empty the cache folder fully with {{ic|pacman -Scc}}. In addition to the above, this also prevents from reinstalling a package directly ''from'' the cache folder in case of need, thus requiring a new download. It should be avoided unless there is an immediate need for disk space.<br />
}}<br />
<br />
Because of the above limitations, consider an alternative for more control over which packages, and how many, are deleted from the cache:<br />
<br />
The ''paccache'' script, provided by the {{Pkg|pacman}} package itself, deletes all cached versions of each package regardless of whether they're installed or not, except for the most recent 3, by default:<br />
<br />
# paccache -r<br />
<br />
You can also define how many recent versions you want to keep:<br />
<br />
# paccache -rk 1<br />
<br />
To remove all cached versions of uninstalled packages, re-run ''paccache'' with:<br />
<br />
# paccache -ruk0<br />
<br />
See {{ic|paccache -h}} for more options.<br />
<br />
{{AUR|pkgcacheclean}} and {{AUR|pacleaner}} are two further alternatives.<br />
<br />
=== Additional commands ===<br />
<br />
Download a package without installing it:<br />
<br />
# pacman -Sw ''package_name''<br />
<br />
Install a 'local' package that is not from a remote repository (e.g. the package is from the [[AUR]]):<br />
<br />
# pacman -U ''/path/to/package/package_name-version.pkg.tar.xz''<br />
<br />
To keep a copy of the local package in ''pacman'''s cache, use:<br />
<br />
# pacman -U file:///''path/to/package/package_name-version.pkg.tar.xz''<br />
<br />
Install a 'remote' package (not from a repository stated in ''pacman'''s configuration files):<br />
<br />
# pacman -U ''<nowiki>http://www.example.com/repo/example.pkg.tar.xz</nowiki>''<br />
<br />
To inhibit the {{ic|-S}}, {{ic|-U}} and {{ic|-R}} actions, {{ic|-p}} can be used.<br />
<br />
''pacman'' always lists packages to be installed or removed and asks for permission before it takes action.<br />
<br />
=== Installation reason ===<br />
<br />
The ''pacman'' database distinguishes the installed packages in two groups according to the reason why they were installed:<br />
<br />
* '''explicitly-installed''': the packages that were literally passed to a generic ''pacman'' {{ic|-S}} or {{ic|-U}} command;<br />
* '''dependencies''': the packages that, despite never (in general) having been passed to a ''pacman'' installation command, were implicitly installed because [[dependency|required]] by another package that was explicitly installed.<br />
<br />
When installing a package, it is possible to force its installation reason to ''dependency'' with:<br />
<br />
# pacman -S --asdeps ''package_name''<br />
<br />
When '''re'''installing a package, though, the current installation reason is preserved by default.<br />
<br />
The list of explicitly-installed packages can be shown with {{ic|pacman -Qe}}, while the complementary list of dependencies can be shown with {{ic|pacman -Qd}}.<br />
<br />
To change the installation reason of an already installed package, execute:<br />
<br />
# pacman -D --asdeps ''package_name''<br />
<br />
Use {{ic|--asexplicit}} to do the opposite operation.<br />
<br />
== Configuration ==<br />
<br />
''pacman'''s settings are located in {{ic|/etc/pacman.conf}}: this is the place where the user configures the program to work in the desired manner. In-depth information about the configuration file can be found in {{man|5|pacman.conf|url=https://www.archlinux.org/pacman/pacman.conf.5.html}}.<br />
<br />
=== General options ===<br />
<br />
General options are in the {{ic|[options]}} section. Read {{man|8|pacman|url=https://www.archlinux.org/pacman/pacman.8.html}} or look in the default {{ic|pacman.conf}} for information on what can be done here.<br />
<br />
==== Comparing versions before updating ====<br />
<br />
To see old and new versions of available packages, uncomment the "VerbosePkgLists" line in {{ic|/etc/pacman.conf}}. The output of {{ic|pacman -Syu}} will be like this:<br />
<br />
Package (6) Old Version New Version Net Change Download Size<br />
<br />
extra/libmariadbclient 10.1.9-4 10.1.10-1 0.03 MiB 4.35 MiB<br />
extra/libpng 1.6.19-1 1.6.20-1 0.00 MiB 0.23 MiB<br />
extra/mariadb 10.1.9-4 10.1.10-1 0.26 MiB 13.80 MiB<br />
<br />
==== Skip package from being upgraded ====<br />
<br />
To have a specific package skipped when [[#Upgrading packages|upgrading]] the system, specify it as such:<br />
<br />
IgnorePkg=linux<br />
<br />
For multiple packages use a space-separated list, or use additional {{ic|IgnorePkg}} lines. Also, glob patterns can be used. If you want to skip packages just once, you can also use the {{ic|--ignore}} option on the command-line - this time with a comma-separated list.<br />
<br />
It will still be possible to upgrade the ignored packages using {{ic|pacman -S}}: in this case ''pacman'' will remind you that the packages have been included in an {{ic|IgnorePkg}} statement.<br />
<br />
==== Skip package group from being upgraded ====<br />
<br />
As with packages, skipping a whole package group is also possible:<br />
<br />
IgnoreGroup=gnome<br />
<br />
==== Skip files from being installed to system ====<br />
<br />
To always skip installation of specific directories list them under {{Ic|NoExtract}}. For example, to avoid installation of [[systemd]] units use this:<br />
<br />
NoExtract=usr/lib/systemd/system/*<br />
<br />
Later rules override previous ones, and you can negate a rule by prepending {{ic|!}}.<br />
<br />
{{Tip|''pacman'' issues warning messages about missing locales when updating a package for which locales have been cleared by ''localepurge'' or ''bleachbit''. Commenting the {{ic|CheckSpace}} option in {{ic|pacman.conf}} suppresses such warnings, but consider that the space-checking functionality will be disabled for all packages.}}<br />
<br />
==== Maintain several configuration files ====<br />
<br />
If you have several configuration files (e.g. main configuration and configuration with [[testing]] repository enabled) and would have to share options between configurations you may use {{ic|Include}} option declared in the configuration files, e.g.:<br />
<br />
Include = ''/path/to/common/settings''<br />
<br />
where {{ic|''/path/to/common/settings''}} file contains the same options for both configurations.<br />
<br />
==== Hooks ====<br />
<br />
''pacman'' can run pre- and post-transaction hooks from the {{ic|/usr/share/libalpm/hooks/}} directory; more directories can be specified with the {{ic|HookDir}} option in {{ic|pacman.conf}}, which defaults to {{ic|/etc/pacman.d/hooks}}. Hook file names must be suffixed with ''.hook''.<br />
<br />
For more information on alpm hooks, see {{man|5|alpm-hooks|url=https://www.archlinux.org/pacman/alpm-hooks.5.html}}.<br />
<br />
=== Repositories and mirrors ===<br />
<br />
Besides the special [[#General options|[options]]] section, each other {{ic|[section]}} in {{ic|pacman.conf}} defines a package repository to be used. A ''repository'' is a ''logical'' collection of packages, which are ''physically'' stored on one or more servers: for this reason each server is called a ''mirror'' for the repository.<br />
<br />
Repositories are distinguished between [[Official repositories|official]] and [[Unofficial user repositories|unofficial]]. The order of repositories in the configuration file matters; repositories listed first will take precedence over those listed later in the file when packages in two repositories have identical names, regardless of version number. In order to use a repository after adding it, you will need to [[#Upgrading packages|upgrade]] the whole system first.<br />
<br />
Each repository section allows defining the list of its mirrors directly or in a dedicated external file through the {{ic|Include}} directive: for example, the mirrors for the official repositories are included from {{ic|/etc/pacman.d/mirrorlist}}. See the [[Mirrors]] article for mirror configuration.<br />
<br />
==== Package security ====<br />
<br />
''pacman'' supports package signatures, which add an extra layer of security to the packages. The default configuration, {{ic|1=SigLevel = Required DatabaseOptional}}, enables signature verification for all the packages on a global level: this can be overridden by per-repository {{ic|SigLevel}} lines. For more details on package signing and signature verification, take a look at [[pacman-key]].<br />
<br />
== Troubleshooting ==<br />
<br />
=== "Failed to commit transaction (conflicting files)" error ===<br />
<br />
If you see the following error: [https://bbs.archlinux.org/viewtopic.php?id=56373]<br />
<br />
error: could not prepare transaction<br />
error: failed to commit transaction (conflicting files)<br />
''package'': ''/path/to/file'' exists in filesystem<br />
Errors occurred, no packages were upgraded.<br />
<br />
Why this is happening: ''pacman'' has detected a file conflict, and by design, will not overwrite files for you. This is a design feature, not a flaw.<br />
<br />
The problem is usually trivial to solve. A safe way is to first check if another package owns the file ({{ic|pacman -Qo ''/path/to/file''}}). If the file is owned by another package, [[Reporting bug guidelines|file a bug report]]. If the file is not owned by another package, rename the file which 'exists in filesystem' and re-issue the update command. If all goes well, the file may then be removed.<br />
<br />
If you had installed a program manually without using ''pacman'' or a frontend, for example through {{ic|make install}}, you have to remove it and all its files and reinstall properly using ''pacman''. See also [[Pacman tips#Identify files not owned by any package]].<br />
<br />
Every installed package provides a {{ic|/var/lib/pacman/local/''$package-$version''/files}} file that contains metadata about this package. If this file gets corrupted, is empty or goes missing, it results in {{ic|file exists in filesystem}} errors when trying to update the package. Such an error usually concerns only one package. Instead of manually renaming and later removing all the files that belong to the package in question, you may exceptionally run {{ic|pacman -S --force $package}} to force ''pacman'' to overwrite these files.<br />
<br />
{{Warning|Take care when using the {{ic|--force}} switch (for example {{ic|pacman -Syu --force}}) as it can cause major problems if used improperly. It is highly recommended to only use this option when the Arch news instructs the user to do so.}}<br />
<br />
=== "Failed to commit transaction (invalid or corrupted package)" error ===<br />
<br />
Look for ''.part'' files (partially downloaded packages) in {{ic|/var/cache/pacman/pkg}} and remove them (often caused by usage of a custom {{ic|XferCommand}} in {{ic|pacman.conf}}).<br />
<br />
# find /var/cache/pacman/pkg/ -iname "*.part" -exec rm {} \;<br />
<br />
=== "Failed to init transaction (unable to lock database)" error ===<br />
<br />
When ''pacman'' is about to alter the package database, for example installing a package, it creates a lock file at {{ic|/var/lib/pacman/db.lck}}. This prevents another instance of ''pacman'' from trying to alter the package database at the same time.<br />
<br />
If ''pacman'' is interrupted while changing the database, this stale lock file can remain. If you are certain that no instances of ''pacman'' are running then delete the lock file:<br />
<br />
# rm /var/lib/pacman/db.lck<br />
<br />
=== Packages cannot be retrieved on installation ===<br />
<br />
This error manifests as {{ic|Not found in sync db}}, {{ic|Target not found}} or {{ic|Failed retrieving file}}.<br />
<br />
Firstly, ensure the package actually exists (and watch out for typos!). If certain the package exists, your package list may be out-of-date or your repositories may be incorrectly configured. Try running {{ic|pacman -Syyu}} to force a refresh of all package lists and upgrade.<br />
<br />
It could also be that the repository containing the package is not enabled on your system, e.g. the package could be in the ''multilib'' repository, but ''multilib'' is not enabled in your ''pacman.conf''.<br />
<br />
See also [[FAQ#Why is there only a single version of each shared library in the official repositories?]].<br />
<br />
=== Search for a package that contains a specific file ===<br />
<br />
==== Using pkgfile ====<br />
Install [[pkgfile]] which uses a separate database with all files and their associated packages.<br />
<br />
==== Using Pacman ====<br />
<br />
Since v5.0.0, Pacman itself can do basic searching of files in sync repositories. [https://git.archlinux.org/pacman.git/tree/NEWS?h=v5.0.0#n5]<br />
<br />
Sync the files database:<br />
# pacman -Fy<br />
<br />
Search for a package containing a file, for e.g.:<br />
# pacman -Fs pacman<br />
core/pacman 5.0.1-4<br />
usr/bin/pacman<br />
usr/share/bash-completion/completions/pacman<br />
extra/xscreensaver 5.36-1<br />
usr/lib/xscreensaver/pacman<br />
<br />
{{Tip|You can set a cron job or a systemd timer to sync the files database regularly.}}<br />
<br />
=== Manually reinstalling pacman ===<br />
<br />
{{Warning|It is extremely easy to break your system even worse using this approach. Use this only as a last resort if the method from [[#pacman crashes during an upgrade]] is not an option.}}<br />
<br />
Even if ''pacman'' is terribly broken, you can fix it manually by downloading the latest packages and extracting them to the correct locations. The rough steps to perform are<br />
<br />
# Determine dependencies to install<br />
# Download each package from a mirror of your choice<br />
# Extract each package to root<br />
# Reinstall these packages with {{ic|pacman -Sf}} to update the package database accordingly<br />
# Do a full system upgrade<br />
<br />
If you have a healthy Arch system on hand, you can see the full list of dependencies with<br />
<br />
$ pacman -Q $(pactree -u pacman)<br />
<br />
but you may only need to update a few of them depending on your issue. An example of extracting a package is<br />
<br />
# tar -xvpwf ''package.tar.xz'' -C / --exclude .PKGINFO --exclude .INSTALL<br />
<br />
Note the use of the {{ic|w}} flag for interactive mode. Running non-interactively is very risky since you might end up overwriting an important file. Also take care to extract packages in the correct order (i.e. dependencies first). [https://bbs.archlinux.org/viewtopic.php?id=95007 This forum post] contains an example of this process where only a couple ''pacman'' dependencies are broken.<br />
<br />
=== pacman crashes during an upgrade ===<br />
<br />
In the case that ''pacman'' crashes with a "database write" error while removing packages, and reinstalling or upgrading packages fails thereafter, do the following:<br />
<br />
# Boot using the Arch installation media. Preferably use a recent media so that the ''pacman'' version matches/is newer than the system. <br />
# Mount the system's root filesystem, e.g. {{ic|mount /dev/sdaX /mnt}} as root, and check the mount has sufficient space with {{ic|df -h}} <br />
# If the system uses default database and directory locations, you can now update the system's pacman database and upgrade it via {{ic|1=pacman --root=/mnt --cachedir=/mnt/var/cache/pacman/pkg -Syyu}} as root. <br />
# After the upgrade, one way to double-check for not upgraded but still broken packages: {{ic|find /mnt/usr/lib -size 0}} <br />
# Followed by a re-install of any still broken package via {{ic|1=pacman --root /mnt --cachedir=/mnt/var/cache/pacman/pkg -S ''package''}}.<br />
<br />
=== "Unable to find root device" error after rebooting ===<br />
<br />
Most likely your initramfs got broken during a kernel update (improper use of ''pacman'''s {{ic|--force}} option can be a cause). You have two options; first, try the ''Fallback'' entry:<br />
<br />
{{Tip|In case you removed this entry for whatever reason, you can always press the {{ic|Tab}} key when the bootloader menu shows up (for Syslinux) or {{ic|e}} (for GRUB or systemd-boot), rename it {{ic|initramfs-linux-fallback.img}} and press {{ic|Enter}} or {{ic|b}} (depending on your bootloader) to boot with the new parameters.}}<br />
<br />
Once the system starts, run this command (for the stock {{Pkg|linux}} kernel) either from the console or from a terminal to rebuild the initramfs image:<br />
<br />
# mkinitcpio -p linux<br />
<br />
If that does not work, from a current Arch release (CD/DVD or USB stick), run:<br />
<br />
{{Note|If you do not have a current release or if you only have some other "live" Linux distribution laying around, you can [[chroot]] using the old fashioned way. Obviously, there will be more typing than simply running the {{ic|arch-chroot}} script.}}<br />
<br />
# mount /dev/sdxY /mnt # Your root partition.<br />
# mount /dev/sdxZ /mnt/boot # If you use a separate /boot partition.<br />
# arch-chroot /mnt<br />
# pacman -Syu mkinitcpio systemd linux<br />
<br />
{{Note|If ''pacman'' fails with {{ic|Could not resolve host}}, please [[Network_configuration#Check_the_connection|check your internet connection]].}}<br />
<br />
Reinstalling the kernel (the {{Pkg|linux}} package) will automatically re-generate the initramfs image with {{ic|mkinitcpio -p linux}}. There is no need to do this separately.<br />
<br />
Afterwards, it is recommended that you run {{ic|exit}}, {{ic|umount /mnt/{boot,} }} and {{ic|reboot}}.<br />
<br />
{{Note|If you cannot enter the arch-chroot or chroot environment but need to re-install packages you can use the command {{ic|pacman -r /mnt -Syu foo bar}} to use ''pacman'' on your root partition.}}<br />
<br />
=== Signature from "User <email@gmail.com>" is unknown trust, installation failed ===<br />
<br />
Follow [[pacman-key#Resetting all the keys]]. Or you can try to either:<br />
* update the known keys, i.e. {{ic|pacman-key --refresh-keys}};<br />
* or manually upgrade {{Pkg|archlinux-keyring}} package first, i.e. {{ic|pacman -S archlinux-keyring}}.<br />
<br />
=== Request on importing PGP keys ===<br />
<br />
If [[Installation guide|installing]] Arch with an outdated ISO, you are likely prompted to import PGP keys. Agree to download the key to proceed. If you are unable to add the PGP key successfully, update the keyring or upgrade {{Pkg|archlinux-keyring}} (see [[#Signature from "User <email@gmail.com>" is unknown trust, installation failed|above]]).<br />
<br />
=== Signature from "User <email@archlinux.org>" is invalid, installation failed ===<br />
<br />
When the system time is faulty, signing keys are considered expired (or invalid) and signature checks on packages will fail with the following error:<br />
<br />
error: ''package'': signature from "User <email@archlinux.org>" is invalid<br />
error: failed to commit transaction (invalid or corrupted package (PGP signature))<br />
Errors occured, no packages were upgraded.<br />
<br />
Make sure to correct the [[time]], for example with {{ic|ntpd -qg}} run as root, and run {{ic|hwclock -w}} as root before subsequent installations or upgrades.<br />
<br />
=== "Warning: current locale is invalid; using default "C" locale" error ===<br />
<br />
As the error message says, your locale is not correctly configured. See [[Locale]].<br />
<br />
=== pacman does not honor proxy settings ===<br />
<br />
Make sure that the relevant environment variables ({{ic|$http_proxy}}, {{ic|$ftp_proxy}} etc.) are set up. If you use ''pacman'' with [[sudo]], you need to configure sudo to [[sudo#Environment variables|pass these environment variables to pacman]].<br />
<br />
=== How do I reinstall all packages, retaining information on whether something was explicitly installed or as a dependency? ===<br />
<br />
To reinstall all the native packages: {{ic|<nowiki>pacman -Qnq | pacman -S -</nowiki>}} (the {{ic|-S}} option preserves the installation reason by default).<br />
<br />
You will then need to reinstall all the foreign packages, which can be listed with {{ic|pacman -Qmq}}.<br />
<br />
=== "Cannot open shared object file" error ===<br />
<br />
It looks like previous ''pacman'' transaction removed or corrupted shared libraries needed for pacman itself.<br />
<br />
To recover from this situation you need to unpack required libraries to your filesystem manually. First find what package contains the missed library and then locate it in the ''pacman'' cache ({{ic|/var/cache/pacman/pkg/}}). Unpack required shared library to the filesystem. This will allow to run ''pacman''.<br />
<br />
Now you need to [[#Installing specific packages|reinstall]] the broken package. Note that you need to use {{ic|--force}} flag as you just unpacked system files and ''pacman'' does not know about it. ''pacman'' will correctly replace our shared library file with one from package.<br />
<br />
That's it. Update the rest of the system.<br />
<br />
=== Freeze of package downloads ===<br />
<br />
Some issues have been reported regarding network problems that prevent ''pacman'' from updating/synchronizing repositories. [https://bbs.archlinux.org/viewtopic.php?id&#61;68944] [https://bbs.archlinux.org/viewtopic.php?id&#61;65728] When installing Arch Linux natively, these issues have been resolved by replacing the default ''pacman'' file downloader with an alternative (see [[Improve pacman performance]] for more details). When installing Arch Linux as a guest OS in [[VirtualBox]], this issue has also been addressed by using ''Host interface'' instead of ''NAT'' in the machine properties.<br />
<br />
=== Failed retrieving file 'core.db' from mirror ===<br />
<br />
If you receive this error message with correct [[mirrors]], try setting a different [[Resolv.conf|name server]].<br />
<br />
== See also ==<br />
<br />
* [https://www.archlinux.org/pacman/ Pacman Home Page]<br />
* {{man|3|libalpm|url=https://www.archlinux.org/pacman/libalpm.3.html}}<br />
* {{man|8|pacman|url=https://www.archlinux.org/pacman/pacman.8.html}}<br />
* {{man|5|pacman.conf|url=https://www.archlinux.org/pacman/pacman.conf.5.html}}<br />
* {{man|8|repo-add|url=https://www.archlinux.org/pacman/repo-add.8.html}}</div>X33ahttps://wiki.archlinux.org/index.php?title=Pacman&diff=461253Pacman2017-01-03T13:53:03Z<p>X33a: /* Search for a package that contains a specific file */ Added content about pacman's built-in functionality</p>
<hr />
<div>{{Lowercase title}}<br />
[[Category:Package management]]<br />
[[ar:Pacman]]<br />
[[cs:Pacman]]<br />
[[da:Pacman]]<br />
[[de:Pacman]]<br />
[[el:Pacman]]<br />
[[es:Pacman]]<br />
[[fa:Pacman]]<br />
[[fr:Pacman]]<br />
[[id:Pacman]]<br />
[[it:Pacman]]<br />
[[ja:Pacman]]<br />
[[ko:Pacman]]<br />
[[nl:Pacman]]<br />
[[pl:Pacman]]<br />
[[pt:Pacman]]<br />
[[ro:Pacman]]<br />
[[ru:Pacman]]<br />
[[sr:Pacman]]<br />
[[sv:Pacman]]<br />
[[tr:pacman]]<br />
[[uk:Pacman]]<br />
[[zh-CN:Pacman]]<br />
[[zh-TW:Pacman]]<br />
{{Related articles start}}<br />
{{Related|Creating packages}}<br />
{{Related|Downgrading packages}}<br />
{{Related|pacman/Package signing}}<br />
{{Related|pacman/Pacnew and Pacsave}}<br />
{{Related|pacman/Restore local database}}<br />
{{Related|pacman/Rosetta}}<br />
{{Related|pacman/Tips and tricks}}<br />
{{Related|FAQ#Package management}}<br />
{{Related|System maintenance}}<br />
{{Related|Arch Build System}}<br />
{{Related|Official repositories}}<br />
{{Related|Arch User Repository}}<br />
{{Related articles end}}<br />
<br />
The [https://www.archlinux.org/pacman/ pacman] [[Wikipedia:Package manager|package manager]] is one of the major distinguishing features of Arch Linux. It combines a simple binary package format with an easy-to-use [[Arch Build System|build system]]. The goal of ''pacman'' is to make it possible to easily manage packages, whether they are from the [[official repositories]] or the user's own builds.<br />
<br />
''pacman'' keeps the system up to date by synchronizing package lists with the master server. This server/client model also allows the user to download/install packages with a simple command, complete with all required dependencies.<br />
<br />
''pacman'' is written in the C programming language and uses the ''.pkg.tar.xz'' package format.<br />
<br />
{{Tip|The {{Pkg|pacman}} package contains other useful tools such as [[makepkg]], '''pactree''', '''vercmp''', and [[checkupdates]]. Run {{ic|pacman -Qlq pacman <nowiki>|</nowiki> grep bin}} to see the full list.}}<br />
<br />
== Usage ==<br />
<br />
{{Expansion|1=pacman 5.0 added some new operations: {{ic|-F}} and {{ic|-D}} [https://projects.archlinux.org/pacman.git/tree/NEWS?h=v5.0.0]. Compare {{ic|-F}} with [[pkgfile]], which is already linked below.}}<br />
<br />
What follows is just a small sample of the operations that ''pacman'' can perform. To read more examples, refer to {{man|8|pacman|url=https://www.archlinux.org/pacman/pacman.8.html#_examples}}.<br />
<br />
{{Tip|For those who have used other Linux distributions before, there is a helpful [[Pacman Rosetta]] article.}}<br />
<br />
=== Installing packages ===<br />
<br />
{{Note|Packages often have a series of [[PKGBUILD#optdepends|optional dependencies]] which are packages that provide additional functionality to the application, albeit not strictly required for running it. When installing a package, ''pacman'' will list its optional dependencies among the output messages, but they will not be found in {{ic|pacman.log}}: use the [[#Querying package databases|pacman -Si]] command to view the optional dependencies of a package, together with short descriptions of their functionality.}}<br />
<br />
{{Warning|1=When installing packages in Arch, avoid refreshing the package list without [[#Upgrading packages|upgrading the system]] (for example, when a [[#Packages cannot be retrieved on installation|package is no longer found]] in the official repositories). In practice, do '''not''' run {{ic|pacman -Sy ''package_name''}} instead of {{ic|pacman -Sy'''u''' ''package_name''}}, as this could lead to dependency issues. See [[System maintenance#Partial upgrades are unsupported]] and [https://bbs.archlinux.org/viewtopic.php?id=89328 BBS#89328].}}<br />
<br />
==== Installing specific packages ====<br />
<br />
To install a single package or list of packages (including dependencies), issue the following command:<br />
<br />
# pacman -S ''package_name1'' ''package_name2'' ...<br />
<br />
To install a list of packages with regex (see [https://bbs.archlinux.org/viewtopic.php?id=7179 this forum thread]):<br />
<br />
# pacman -S $(pacman -Ssq ''package_regex'')<br />
<br />
Sometimes there are multiple versions of a package in different repositories, e.g. ''extra'' and ''testing''. To install the former version, the repository needs to be defined in front:<br />
<br />
# pacman -S extra/''package_name''<br />
<br />
To install a number of packages sharing similar patterns in their names -- not the entire group nor all matching packages; eg. {{Grp|plasma}}:<br />
<br />
# pacman -S plasma-{desktop,mediacenter,nm}<br />
<br />
Of course, that is not limited and can be expanded to however many levels needed:<br />
<br />
# pacman -S plasma-{workspace{,-wallpapers},pa}<br />
<br />
==== Installing package groups ====<br />
<br />
Some packages belong to a [[Creating_packages#Meta_packages_and_groups|group of packages]] that can all be installed simultaneously. For example, issuing the command:<br />
<br />
# pacman -S gnome<br />
<br />
will prompt you to select the packages from the {{Grp|gnome}} group that you wish to install.<br />
<br />
Sometimes a package group will contain a large amount of packages, and there may be only a few that you do or do not want to install. Instead of having to enter all the numbers except the ones you do not want, it is sometimes more convenient to select or exclude packages or ranges of packages with the following syntax:<br />
<br />
Enter a selection (default=all): 1-10 15<br />
<br />
which will select packages 1 through 10 and 15 for installation, or:<br />
<br />
Enter a selection (default=all): ^5-8 ^2<br />
<br />
which will select all packages except 5 through 8 and 2 for installation.<br />
<br />
To see what packages belong to the gnome group, run:<br />
<br />
# pacman -Sg gnome<br />
<br />
Also visit https://www.archlinux.org/groups/ to see what package groups are available.<br />
<br />
{{Note|If a package in the list is already installed on the system, it will be reinstalled even if it is already up to date. This behavior can be overridden with the {{ic|--needed}} option.}}<br />
<br />
=== Removing packages ===<br />
<br />
To remove a single package, leaving all of its dependencies installed:<br />
<br />
# pacman -R ''package_name''<br />
<br />
To remove a package and its dependencies which are not required by any other installed package:<br />
<br />
# pacman -Rs ''package_name''<br />
<br />
To remove a package, its dependencies and all the packages that depend on the target package:<br />
<br />
{{Warning|This operation is recursive, and must be used with care since it can remove many potentially needed packages.}}<br />
<br />
# pacman -Rsc ''package_name''<br />
<br />
To remove a package, which is required by another package, without removing the dependent package:<br />
<br />
# pacman -Rdd ''package_name''<br />
<br />
''pacman'' saves important configuration files when removing certain applications and names them with the extension: ''.pacsave''. To prevent the creation of these backup files use the {{ic|-n}} option:<br />
<br />
# pacman -Rn ''package_name''<br />
<br />
{{Note|''pacman'' will not remove configurations that the application itself creates (for example "dotfiles" in the home folder).}}<br />
<br />
=== Upgrading packages ===<br />
<br />
{{Merge|System maintenance||Talk:Pacman#Don't rush upgrades}}<br />
{{Warning|Arch only supports full system upgrades. See [[System maintenance#Partial upgrades are unsupported]] and [[#Installing packages]] for details.}}<br />
<br />
It is recommended that users [[System_maintenance#Upgrading the system|upgrade their system regularly]]. When requesting support from the community, it will usually be assumed that the system is up to date.<br />
<br />
Before upgrading, users are expected to visit the [https://www.archlinux.org/ Arch Linux home page] to check the latest news, or alternatively subscribe to the [https://www.archlinux.org/feeds/news/ RSS feed], [https://mailman.archlinux.org/mailman/listinfo/arch-announce/ arch-announce mailing list], or follow [https://twitter.com/archlinux @archlinux] on Twitter: when updates require out-of-the-ordinary user intervention (more than what can be handled simply by following the instructions given by ''pacman''), an appropriate news post will be made. Users must equally be aware that upgrading packages can raise '''unexpected''' problems that could need immediate intervention, therefore it is discouraged to upgrade a stable system shortly before it is required for carrying out an important task: it is wise to wait instead to have enough time in order to be able to deal with possible post-upgrade issues.<br />
<br />
''pacman'' can update all packages on the system with just one command. This could take quite a while depending on how up-to-date the system is. This command can synchronize the repository databases ''and'' update the system's packages (excluding "local" packages that are not in the configured repositories):<br />
<br />
# pacman -Syu<br />
<br />
''pacman'' is a powerful package management tool, but it does not attempt to handle all corner cases. Users must be vigilant and take responsibility for maintaining their own system. '''When performing a system update, it is essential that users read all information output by ''pacman'' and use common sense.''' If a user-modified configuration file needs to be upgraded for a new version of a package, a ''.pacnew'' file will be created to avoid overwriting settings modified by the user. ''pacman'' will prompt the user to merge them. These files require manual intervention from the user and it is good practice to handle them right after every package upgrade or removal. See [[Pacnew and Pacsave files]] for more information.<br />
<br />
{{Tip|<br />
* Remember that ''pacman'''s output is logged in {{ic|/var/log/pacman.log}}.<br />
* You can use a log viewer such as {{AUR|wat-git}} to search the pacman logs.}}<br />
<br />
If one encounters problems that cannot be solved by these instructions, make sure to search the forum. It is likely that others have encountered the same problem and have posted instructions for solving it.<br />
<br />
=== Querying package databases ===<br />
<br />
''pacman'' queries the local package database with the {{ic|-Q}} flag; see:<br />
<br />
$ pacman -Q --help<br />
<br />
and queries the sync databases with the {{ic|-S}} flag; see:<br />
<br />
$ pacman -S --help<br />
<br />
''pacman'' can search for packages in the database, searching both in packages' names and descriptions:<br />
<br />
$ pacman -Ss ''string1'' ''string2'' ...<br />
<br />
Sometimes, {{Ic|-s}}'s builtin ERE can cause a lot of unwanted results, so it has to be limited to match the package name only; not the description nor any other field:<br />
<br />
# pacman -Ss '^vim-'<br />
<br />
To search for already installed packages:<br />
<br />
$ pacman -Qs ''string1'' ''string2'' ...<br />
<br />
To display extensive information about a given package:<br />
<br />
$ pacman -Si ''package_name''<br />
<br />
For locally installed packages:<br />
<br />
$ pacman -Qi ''package_name''<br />
<br />
Passing two {{ic|-i}} flags will also display the list of backup files and their modification states:<br />
<br />
$ pacman -Qii ''package_name''<br />
<br />
To retrieve a list of the files installed by a package:<br />
<br />
$ pacman -Ql ''package_name''<br />
<br />
For packages not installed, use [[pkgfile]].<br />
<br />
To verify the presence of the files installed by a package:<br />
<br />
$ pacman -Qk ''package_name''<br />
<br />
Passing the {{ic|k}} flag twice will perform a more thorough check.<br />
<br />
One can also query the database to know which package a file in the file system belongs to:<br />
<br />
$ pacman -Qo ''/path/to/file_name''<br />
<br />
To list all packages no longer required as dependencies (orphans):<br />
<br />
$ pacman -Qdt<br />
<br />
To list all packages explicitly installed and not required as dependencies:<br />
<br />
$ pacman -Qet<br />
<br />
To list a dependency tree of a package:<br />
<br />
$ pactree ''package_name''<br />
<br />
To list all the packages recursively depending on an ''installed'' package, use ''whoneeds'' from {{AUR|pkgtools}}:<br />
<br />
$ whoneeds ''package_name''<br />
<br />
or the reverse flag to ''pactree'':<br />
<br />
$ pactree -r ''package_name''<br />
<br />
See [[pacman tips]] for more examples.<br />
<br />
==== Database structure ====<br />
<br />
The pacman databases are normally located at {{ic|/var/lib/pacman/sync}}. For each repository specified in {{ic|/etc/pacman.conf}} there will be a corresponding database file located there. Database files are tar-gzipped archives containing one directory for each package, for example for the {{Pkg|which}} package:<br />
<br />
{{bc|<br />
% tree which-2.20-6 <br />
which-2.20-6<nowiki><br />
|-- depends<br />
`-- desc</nowiki><br />
}}<br />
<br />
The {{ic|depends}} file lists the packages this package depends on, while {{ic|desc}} has a description of the package such as the file size and the MD5 hash.<br />
<br />
=== Cleaning the package cache ===<br />
<br />
''pacman'' stores its downloaded packages in {{ic|/var/cache/pacman/pkg/}} and does not remove the old or uninstalled versions automatically, therefore it is necessary to deliberately clean up that folder periodically to prevent such folder to grow indefinitely in size.<br />
<br />
The built-in option to remove all the cached packages that are not currently installed is:<br />
<br />
# pacman -Sc<br />
<br />
{{Warning|<br />
* Only do this when certain that previous package versions are not required, for example for a later [[downgrade]]. {{ic|pacman -Sc}} only leaves the versions of packages which are ''currently installed'' available, older versions would have to be retrieved through other means, such as the [[Archive]].<br />
* It is possible to empty the cache folder fully with {{ic|pacman -Scc}}. In addition to the above, this also prevents from reinstalling a package directly ''from'' the cache folder in case of need, thus requiring a new download. It should be avoided unless there is an immediate need for disk space.<br />
}}<br />
<br />
Because of the above limitations, consider an alternative for more control over which packages, and how many, are deleted from the cache:<br />
<br />
The ''paccache'' script, provided by the {{Pkg|pacman}} package itself, deletes all cached versions of each package regardless of whether they're installed or not, except for the most recent 3, by default:<br />
<br />
# paccache -r<br />
<br />
You can also define how many recent versions you want to keep:<br />
<br />
# paccache -rk 1<br />
<br />
To remove all cached versions of uninstalled packages, re-run ''paccache'' with:<br />
<br />
# paccache -ruk0<br />
<br />
See {{ic|paccache -h}} for more options.<br />
<br />
{{AUR|pkgcacheclean}} and {{AUR|pacleaner}} are two further alternatives.<br />
<br />
=== Additional commands ===<br />
<br />
Download a package without installing it:<br />
<br />
# pacman -Sw ''package_name''<br />
<br />
Install a 'local' package that is not from a remote repository (e.g. the package is from the [[AUR]]):<br />
<br />
# pacman -U ''/path/to/package/package_name-version.pkg.tar.xz''<br />
<br />
To keep a copy of the local package in ''pacman'''s cache, use:<br />
<br />
# pacman -U file:///''path/to/package/package_name-version.pkg.tar.xz''<br />
<br />
Install a 'remote' package (not from a repository stated in ''pacman'''s configuration files):<br />
<br />
# pacman -U ''<nowiki>http://www.example.com/repo/example.pkg.tar.xz</nowiki>''<br />
<br />
To inhibit the {{ic|-S}}, {{ic|-U}} and {{ic|-R}} actions, {{ic|-p}} can be used.<br />
<br />
''pacman'' always lists packages to be installed or removed and asks for permission before it takes action.<br />
<br />
=== Installation reason ===<br />
<br />
The ''pacman'' database distinguishes the installed packages in two groups according to the reason why they were installed:<br />
<br />
* '''explicitly-installed''': the packages that were literally passed to a generic ''pacman'' {{ic|-S}} or {{ic|-U}} command;<br />
* '''dependencies''': the packages that, despite never (in general) having been passed to a ''pacman'' installation command, were implicitly installed because [[dependency|required]] by another package that was explicitly installed.<br />
<br />
When installing a package, it is possible to force its installation reason to ''dependency'' with:<br />
<br />
# pacman -S --asdeps ''package_name''<br />
<br />
When '''re'''installing a package, though, the current installation reason is preserved by default.<br />
<br />
The list of explicitly-installed packages can be shown with {{ic|pacman -Qe}}, while the complementary list of dependencies can be shown with {{ic|pacman -Qd}}.<br />
<br />
To change the installation reason of an already installed package, execute:<br />
<br />
# pacman -D --asdeps ''package_name''<br />
<br />
Use {{ic|--asexplicit}} to do the opposite operation.<br />
<br />
== Configuration ==<br />
<br />
''pacman'''s settings are located in {{ic|/etc/pacman.conf}}: this is the place where the user configures the program to work in the desired manner. In-depth information about the configuration file can be found in {{man|5|pacman.conf|url=https://www.archlinux.org/pacman/pacman.conf.5.html}}.<br />
<br />
=== General options ===<br />
<br />
General options are in the {{ic|[options]}} section. Read {{man|8|pacman|url=https://www.archlinux.org/pacman/pacman.8.html}} or look in the default {{ic|pacman.conf}} for information on what can be done here.<br />
<br />
==== Comparing versions before updating ====<br />
<br />
To see old and new versions of available packages, uncomment the "VerbosePkgLists" line in {{ic|/etc/pacman.conf}}. The output of {{ic|pacman -Syu}} will be like this:<br />
<br />
Package (6) Old Version New Version Net Change Download Size<br />
<br />
extra/libmariadbclient 10.1.9-4 10.1.10-1 0.03 MiB 4.35 MiB<br />
extra/libpng 1.6.19-1 1.6.20-1 0.00 MiB 0.23 MiB<br />
extra/mariadb 10.1.9-4 10.1.10-1 0.26 MiB 13.80 MiB<br />
<br />
==== Skip package from being upgraded ====<br />
<br />
To have a specific package skipped when [[#Upgrading packages|upgrading]] the system, specify it as such:<br />
<br />
IgnorePkg=linux<br />
<br />
For multiple packages use a space-separated list, or use additional {{ic|IgnorePkg}} lines. Also, glob patterns can be used. If you want to skip packages just once, you can also use the {{ic|--ignore}} option on the command-line - this time with a comma-separated list.<br />
<br />
It will still be possible to upgrade the ignored packages using {{ic|pacman -S}}: in this case ''pacman'' will remind you that the packages have been included in an {{ic|IgnorePkg}} statement.<br />
<br />
==== Skip package group from being upgraded ====<br />
<br />
As with packages, skipping a whole package group is also possible:<br />
<br />
IgnoreGroup=gnome<br />
<br />
==== Skip files from being installed to system ====<br />
<br />
To always skip installation of specific directories list them under {{Ic|NoExtract}}. For example, to avoid installation of [[systemd]] units use this:<br />
<br />
NoExtract=usr/lib/systemd/system/*<br />
<br />
Later rules override previous ones, and you can negate a rule by prepending {{ic|!}}.<br />
<br />
{{Tip|''pacman'' issues warning messages about missing locales when updating a package for which locales have been cleared by ''localepurge'' or ''bleachbit''. Commenting the {{ic|CheckSpace}} option in {{ic|pacman.conf}} suppresses such warnings, but consider that the space-checking functionality will be disabled for all packages.}}<br />
<br />
==== Maintain several configuration files ====<br />
<br />
If you have several configuration files (e.g. main configuration and configuration with [[testing]] repository enabled) and would have to share options between configurations you may use {{ic|Include}} option declared in the configuration files, e.g.:<br />
<br />
Include = ''/path/to/common/settings''<br />
<br />
where {{ic|''/path/to/common/settings''}} file contains the same options for both configurations.<br />
<br />
==== Hooks ====<br />
<br />
''pacman'' can run pre- and post-transaction hooks from the {{ic|/usr/share/libalpm/hooks/}} directory; more directories can be specified with the {{ic|HookDir}} option in {{ic|pacman.conf}}, which defaults to {{ic|/etc/pacman.d/hooks}}. Hook file names must be suffixed with ''.hook''.<br />
<br />
For more information on alpm hooks, see {{man|5|alpm-hooks|url=https://www.archlinux.org/pacman/alpm-hooks.5.html}}.<br />
<br />
=== Repositories and mirrors ===<br />
<br />
Besides the special [[#General options|[options]]] section, each other {{ic|[section]}} in {{ic|pacman.conf}} defines a package repository to be used. A ''repository'' is a ''logical'' collection of packages, which are ''physically'' stored on one or more servers: for this reason each server is called a ''mirror'' for the repository.<br />
<br />
Repositories are distinguished between [[Official repositories|official]] and [[Unofficial user repositories|unofficial]]. The order of repositories in the configuration file matters; repositories listed first will take precedence over those listed later in the file when packages in two repositories have identical names, regardless of version number. In order to use a repository after adding it, you will need to [[#Upgrading packages|upgrade]] the whole system first.<br />
<br />
Each repository section allows defining the list of its mirrors directly or in a dedicated external file through the {{ic|Include}} directive: for example, the mirrors for the official repositories are included from {{ic|/etc/pacman.d/mirrorlist}}. See the [[Mirrors]] article for mirror configuration.<br />
<br />
==== Package security ====<br />
<br />
''pacman'' supports package signatures, which add an extra layer of security to the packages. The default configuration, {{ic|1=SigLevel = Required DatabaseOptional}}, enables signature verification for all the packages on a global level: this can be overridden by per-repository {{ic|SigLevel}} lines. For more details on package signing and signature verification, take a look at [[pacman-key]].<br />
<br />
== Troubleshooting ==<br />
<br />
=== "Failed to commit transaction (conflicting files)" error ===<br />
<br />
If you see the following error: [https://bbs.archlinux.org/viewtopic.php?id=56373]<br />
<br />
error: could not prepare transaction<br />
error: failed to commit transaction (conflicting files)<br />
''package'': ''/path/to/file'' exists in filesystem<br />
Errors occurred, no packages were upgraded.<br />
<br />
Why this is happening: ''pacman'' has detected a file conflict, and by design, will not overwrite files for you. This is a design feature, not a flaw.<br />
<br />
The problem is usually trivial to solve. A safe way is to first check if another package owns the file ({{ic|pacman -Qo ''/path/to/file''}}). If the file is owned by another package, [[Reporting bug guidelines|file a bug report]]. If the file is not owned by another package, rename the file which 'exists in filesystem' and re-issue the update command. If all goes well, the file may then be removed.<br />
<br />
If you had installed a program manually without using ''pacman'' or a frontend, for example through {{ic|make install}}, you have to remove it and all its files and reinstall properly using ''pacman''. See also [[Pacman tips#Identify files not owned by any package]].<br />
<br />
Every installed package provides a {{ic|/var/lib/pacman/local/''$package-$version''/files}} file that contains metadata about this package. If this file gets corrupted, is empty or goes missing, it results in {{ic|file exists in filesystem}} errors when trying to update the package. Such an error usually concerns only one package. Instead of manually renaming and later removing all the files that belong to the package in question, you may exceptionally run {{ic|pacman -S --force $package}} to force ''pacman'' to overwrite these files.<br />
<br />
{{Warning|Take care when using the {{ic|--force}} switch (for example {{ic|pacman -Syu --force}}) as it can cause major problems if used improperly. It is highly recommended to only use this option when the Arch news instructs the user to do so.}}<br />
<br />
=== "Failed to commit transaction (invalid or corrupted package)" error ===<br />
<br />
Look for ''.part'' files (partially downloaded packages) in {{ic|/var/cache/pacman/pkg}} and remove them (often caused by usage of a custom {{ic|XferCommand}} in {{ic|pacman.conf}}).<br />
<br />
# find /var/cache/pacman/pkg/ -iname "*.part" -exec rm {} \;<br />
<br />
=== "Failed to init transaction (unable to lock database)" error ===<br />
<br />
When ''pacman'' is about to alter the package database, for example installing a package, it creates a lock file at {{ic|/var/lib/pacman/db.lck}}. This prevents another instance of ''pacman'' from trying to alter the package database at the same time.<br />
<br />
If ''pacman'' is interrupted while changing the database, this stale lock file can remain. If you are certain that no instances of ''pacman'' are running then delete the lock file:<br />
<br />
# rm /var/lib/pacman/db.lck<br />
<br />
=== Packages cannot be retrieved on installation ===<br />
<br />
This error manifests as {{ic|Not found in sync db}}, {{ic|Target not found}} or {{ic|Failed retrieving file}}.<br />
<br />
Firstly, ensure the package actually exists (and watch out for typos!). If certain the package exists, your package list may be out-of-date or your repositories may be incorrectly configured. Try running {{ic|pacman -Syyu}} to force a refresh of all package lists and upgrade.<br />
<br />
It could also be that the repository containing the package is not enabled on your system, e.g. the package could be in the ''multilib'' repository, but ''multilib'' is not enabled in your ''pacman.conf''.<br />
<br />
See also [[FAQ#Why is there only a single version of each shared library in the official repositories?]].<br />
<br />
=== Search for a package that contains a specific file ===<br />
<br />
==== Using pkgfile ====<br />
Install [[pkgfile]] which uses a separate database with all files and their associated packages.<br />
<br />
==== Using Pacman ====<br />
<br />
Since v5.0.0, Pacman itself can do basic searching of files in sync repositories. [https://git.archlinux.org/pacman.git/tree/NEWS?h=v5.0.0#n5]<br />
<br />
Sync the files database:<br />
# pacman -Fy<br />
<br />
Search for a package containing a file, for e.g.:<br />
# pacman -Fs pacman<br />
core/pacman 5.0.1-4<br />
usr/bin/pacman<br />
usr/share/bash-completion/completions/pacman<br />
extra/xscreensaver 5.36-1<br />
usr/lib/xscreensaver/pacman<br />
<br />
{{Tip|You can set a cron job or a systemd timer to sync the files database regularly.}}<br />
<br />
=== Manually reinstalling pacman ===<br />
<br />
{{Warning|It is extremely easy to break your system even worse using this approach. Use this only as a last resort if the method from [[#pacman crashes during an upgrade]] is not an option.}}<br />
<br />
Even if ''pacman'' is terribly broken, you can fix it manually by downloading the latest packages and extracting them to the correct locations. The rough steps to perform are<br />
<br />
# Determine dependencies to install<br />
# Download each package from a mirror of your choice<br />
# Extract each package to root<br />
# Reinstall these packages with {{ic|pacman -Sf}} to update the package database accordingly<br />
# Do a full system upgrade<br />
<br />
If you have a healthy Arch system on hand, you can see the full list of dependencies with<br />
<br />
$ pacman -Q $(pactree -u pacman)<br />
<br />
but you may only need to update a few of them depending on your issue. An example of extracting a package is<br />
<br />
# tar -xvpwf ''package.tar.xz'' -C / --exclude .PKGINFO --exclude .INSTALL<br />
<br />
Note the use of the {{ic|w}} flag for interactive mode. Running non-interactively is very risky since you might end up overwriting an important file. Also take care to extract packages in the correct order (i.e. dependencies first). [https://bbs.archlinux.org/viewtopic.php?id=95007 This forum post] contains an example of this process where only a couple ''pacman'' dependencies are broken.<br />
<br />
=== pacman crashes during an upgrade ===<br />
<br />
In the case that ''pacman'' crashes with a "database write" error while removing packages, and reinstalling or upgrading packages fails thereafter, do the following:<br />
<br />
# Boot using the Arch installation media. Preferably use a recent media so that the ''pacman'' version matches/is newer than the system. <br />
# Mount the system's root filesystem, e.g. {{ic|mount /dev/sdaX /mnt}} as root, and check the mount has sufficient space with {{ic|df -h}} <br />
# If the system uses default database and directory locations, you can now update the system's pacman database and upgrade it via {{ic|1=pacman --root=/mnt --cachedir=/mnt/var/cache/pacman/pkg -Syyu}} as root. <br />
# After the upgrade, one way to double-check for not upgraded but still broken packages: {{ic|find /mnt/usr/lib -size 0}} <br />
# Followed by a re-install of any still broken package via {{ic|1=pacman --root /mnt --cachedir=/mnt/var/cache/pacman/pkg -S ''package''}}.<br />
<br />
=== "Unable to find root device" error after rebooting ===<br />
<br />
Most likely your initramfs got broken during a kernel update (improper use of ''pacman'''s {{ic|--force}} option can be a cause). You have two options; first, try the ''Fallback'' entry:<br />
<br />
{{Tip|In case you removed this entry for whatever reason, you can always press the {{ic|Tab}} key when the bootloader menu shows up (for Syslinux) or {{ic|e}} (for GRUB or systemd-boot), rename it {{ic|initramfs-linux-fallback.img}} and press {{ic|Enter}} or {{ic|b}} (depending on your bootloader) to boot with the new parameters.}}<br />
<br />
Once the system starts, run this command (for the stock {{Pkg|linux}} kernel) either from the console or from a terminal to rebuild the initramfs image:<br />
<br />
# mkinitcpio -p linux<br />
<br />
If that does not work, from a current Arch release (CD/DVD or USB stick), run:<br />
<br />
{{Note|If you do not have a current release or if you only have some other "live" Linux distribution laying around, you can [[chroot]] using the old fashioned way. Obviously, there will be more typing than simply running the {{ic|arch-chroot}} script.}}<br />
<br />
# mount /dev/sdxY /mnt # Your root partition.<br />
# mount /dev/sdxZ /mnt/boot # If you use a separate /boot partition.<br />
# arch-chroot /mnt<br />
# pacman -Syu mkinitcpio systemd linux<br />
<br />
{{Note|If ''pacman'' fails with {{ic|Could not resolve host}}, please [[Network_configuration#Check_the_connection|check your internet connection]].}}<br />
<br />
Reinstalling the kernel (the {{Pkg|linux}} package) will automatically re-generate the initramfs image with {{ic|mkinitcpio -p linux}}. There is no need to do this separately.<br />
<br />
Afterwards, it is recommended that you run {{ic|exit}}, {{ic|umount /mnt/{boot,} }} and {{ic|reboot}}.<br />
<br />
{{Note|If you cannot enter the arch-chroot or chroot environment but need to re-install packages you can use the command {{ic|pacman -r /mnt -Syu foo bar}} to use ''pacman'' on your root partition.}}<br />
<br />
=== Signature from "User <email@gmail.com>" is unknown trust, installation failed ===<br />
<br />
Follow [[pacman-key#Resetting all the keys]]. Or you can try to either:<br />
* update the known keys, i.e. {{ic|pacman-key --refresh-keys}};<br />
* or manually upgrade {{Pkg|archlinux-keyring}} package first, i.e. {{ic|pacman -S archlinux-keyring}}.<br />
<br />
=== Request on importing PGP keys ===<br />
<br />
If [[Installation guide|installing]] Arch with an outdated ISO, you are likely prompted to import PGP keys. Agree to download the key to proceed. If you are unable to add the PGP key successfully, update the keyring or upgrade {{Pkg|archlinux-keyring}} (see [[#Signature from "User <email@gmail.com>" is unknown trust, installation failed|above]]).<br />
<br />
=== Signature from "User <email@archlinux.org>" is invalid, installation failed ===<br />
<br />
When the system time is faulty, signing keys are considered expired (or invalid) and signature checks on packages will fail with the following error:<br />
<br />
error: ''package'': signature from "User <email@archlinux.org>" is invalid<br />
error: failed to commit transaction (invalid or corrupted package (PGP signature))<br />
Errors occured, no packages were upgraded.<br />
<br />
Make sure to correct the [[time]], for example with {{ic|ntpd -qg}} run as root, and run {{ic|hwclock -w}} as root before subsequent installations or upgrades.<br />
<br />
=== "Warning: current locale is invalid; using default "C" locale" error ===<br />
<br />
As the error message says, your locale is not correctly configured. See [[Locale]].<br />
<br />
=== pacman does not honor proxy settings ===<br />
<br />
Make sure that the relevant environment variables ({{ic|$http_proxy}}, {{ic|$ftp_proxy}} etc.) are set up. If you use ''pacman'' with [[sudo]], you need to configure sudo to [[sudo#Environment variables|pass these environment variables to pacman]].<br />
<br />
=== How do I reinstall all packages, retaining information on whether something was explicitly installed or as a dependency? ===<br />
<br />
To reinstall all the native packages: {{ic|<nowiki>pacman -Qnq | pacman -S -</nowiki>}} (the {{ic|-S}} option preserves the installation reason by default).<br />
<br />
You will then need to reinstall all the foreign packages, which can be listed with {{ic|pacman -Qmq}}.<br />
<br />
=== "Cannot open shared object file" error ===<br />
<br />
It looks like previous ''pacman'' transaction removed or corrupted shared libraries needed for pacman itself.<br />
<br />
To recover from this situation you need to unpack required libraries to your filesystem manually. First find what package contains the missed library and then locate it in the ''pacman'' cache ({{ic|/var/cache/pacman/pkg/}}). Unpack required shared library to the filesystem. This will allow to run ''pacman''.<br />
<br />
Now you need to [[#Installing specific packages|reinstall]] the broken package. Note that you need to use {{ic|--force}} flag as you just unpacked system files and ''pacman'' does not know about it. ''pacman'' will correctly replace our shared library file with one from package.<br />
<br />
That's it. Update the rest of the system.<br />
<br />
=== Freeze of package downloads ===<br />
<br />
Some issues have been reported regarding network problems that prevent ''pacman'' from updating/synchronizing repositories. [https://bbs.archlinux.org/viewtopic.php?id&#61;68944] [https://bbs.archlinux.org/viewtopic.php?id&#61;65728] When installing Arch Linux natively, these issues have been resolved by replacing the default ''pacman'' file downloader with an alternative (see [[Improve pacman performance]] for more details). When installing Arch Linux as a guest OS in [[VirtualBox]], this issue has also been addressed by using ''Host interface'' instead of ''NAT'' in the machine properties.<br />
<br />
=== Failed retrieving file 'core.db' from mirror ===<br />
<br />
If you receive this error message with correct [[mirrors]], try setting a different [[Resolv.conf|name server]].<br />
<br />
== See also ==<br />
<br />
* [https://www.archlinux.org/pacman/ Pacman Home Page]<br />
* {{man|3|libalpm|url=https://www.archlinux.org/pacman/libalpm.3.html}}<br />
* {{man|8|pacman|url=https://www.archlinux.org/pacman/pacman.8.html}}<br />
* {{man|5|pacman.conf|url=https://www.archlinux.org/pacman/pacman.conf.5.html}}<br />
* {{man|8|repo-add|url=https://www.archlinux.org/pacman/repo-add.8.html}}</div>X33ahttps://wiki.archlinux.org/index.php?title=Syslog-ng&diff=458861Syslog-ng2016-12-09T17:52:08Z<p>X33a: Change initial note: syslog-ng doesn't come by default on Arch.</p>
<hr />
<div>{{Lowercase title}}<br />
[[Category:Daemons and system services]]<br />
[[ja:Syslog-ng]]<br />
{{Related articles start}}<br />
{{Related|rsyslog}}<br />
{{Related articles end}}<br />
<br />
{{Note|With systemd's journal, syslog-ng is not needed by most users.}}<br />
<br />
== Overview ==<br />
<br />
syslog-ng takes incoming log messages from defined '[[#Sources|sources]]' and forwards them to the appropriate [[#Destinations|destinations]], based on powerful [[#Creating Filters for Messages|filter]] directives. In a typical simple set-up, syslog-ng will read messages from three sources:<br />
<br />
# the default {{ic|/dev/log}} device, where most logs are sent<br />
# syslog-ng "internal" log messages<br />
# {{ic|/proc/kmsg}} kernel messages<br />
<br />
Sources are defined using the "source" directive. These incoming messages are then filtered according to defined filters ("filter" keyword), i.e. according to originating program or log level, and sent to the appropriate "destination". Destinations include log files (e.g. {{ic|/var/log/messages.log}}), printing messages on a console and remote servers. The pivotal function is [[#Log Paths|log]]. This function defines which filters should be applied to a certain source, and where the resulting messages should be sent to.<br />
<br />
{{out of date|This seems very specific to transitioning from systemd 215 to 216. Some of this can be updated/removed.}}<br />
<br />
[[Enable]] syslog-ng with the {{ic|syslog-ng.service}} service file. As of ''systemd'' 216, messages are no longer forwarded to syslog by default. Syslog-ng did not become journald aware until months later with the release of syslog-ng 3.6. This meant that if you were running systemd 216 or greater and syslog-ng you needed to set the option {{ic|1=ForwardToSyslog=yes}} in {{ic|/etc/systemd/journald.conf}} to actually use ''syslog-ng'' with ''journald''. <br />
<br />
If you use a current {{Pkg|syslog-ng}}, it is not necessary to change the option because [[syslog-ng]] pulls the messages from the journal. If you have set {{ic|1=ForwardToSyslog=yes}} you should revert it to {{ic|1=ForwardToSyslog=no}} in order to avoid the overhead associated with the socket and to avoid [https://github.com/balabit/syslog-ng/issues/314 needless error messages in the log]. If on the other hand you do not want to store your logs twice and turn ''journald'''s {{ic|1=Storage=none}}, you '''will''' need {{ic|1=ForwardToSyslog=yes}}, as ''syslog-ng'' tries to follow the 'journald' journal file.<br />
<br />
== Sources ==<br />
syslog-ng receives log messages from a source. To define a source you should follow the following syntax:<br />
source <identifier> { source-driver(params); source-driver(params); ... };<br />
<br />
You can look at the identifiers and source-drivers in the [http://www.balabit.com/support/documentation/ official manuals]. <br />
This will follow the manual to explain the configuration file above. The unix-stream() source-driver opens the given AF_UNIX<br />
[[wikipedia:Berkeley_sockets|socket]] and starts listening on it for messages. <br />
The internal() source-driver gets messages generated by syslog-ng.<br />
<br />
Therefore, the following means: {{ic|src}} gets messages from the {{ic|/dev/log}} socket and syslog-ng.<br />
source src { unix-stream("/dev/log"); internal(); };<br />
<br />
The kernel sends log messages to {{ic|/proc/kmsg}} and the file() driver reads log messages from files. Therefore, the following means:<br />
kernsrc gets messages from file {{ic|/proc/kmsg}}<br />
source kernsrc { file("/proc/kmsg"); };<br />
<br />
In the default configuration file after emerging syslog-ng, the source is defined as:<br />
source src { unix-stream("/dev/log"); internal(); pipe("/proc/kmsg"); };<br />
<br />
Reading messages by {{ic|pipe("/proc/kmsg")}} gives a better performance but because it opens its argument in read-write mode can be a security<br />
hazard as the [http://www.balabit.com/sites/default/files/documents/syslog-ng-v3.0-guide-admin-en.html/index.html-single.html#configuring_sources_pipe syslog-ng admin guide] states in section 3.3.3:<br />
<br />
"Pipe is very similar to the file() driver, but there are a few differences, for example pipe() opens its argument in read-write mode, therefore it is not recommended to be used on special files like {{ic|/proc/kmsg}}." (You can follow this discussion in [http://forums.gentoo.org/viewtopic-t-558161.html this post].)<br />
<br />
To open a port to read data from a remote server a source must be defined with this syntax:<br />
source s_net { udp(); };<br />
<br />
for UDP or<br />
source s_net { tcp(); };<br />
<br />
to receive log messages via TCP. Both listen on port 514.<br />
<br />
=== syslog-ng and systemd journal===<br />
Starting with syslog-ng version 3.6.1 the default {{ic|system()}} source on Linux systems using systemd uses journald as its standard {{ic|system()}} source.<br />
<br />
If you wish to use both the journald and syslog-ng files, ensure the following settings are in effect. For systemd-journald, in the {{ic|/etc/systemd/journald.conf}} file, {{ic|1=Storage=}} either set to {{ic|auto}} or unset (which defaults to auto) and {{ic|1=ForwardToSyslog=}} set to {{ic|no}} or unset (defaults to no). For {{ic|/etc/syslog-ng/syslog-ng.conf}}, you need the following {{ic|source}} stanza:<br />
<br />
{{bc|<nowiki><br />
source src {<br />
system();<br />
internal();<br />
};</nowiki>}}<br />
<br />
If, on the other hand, you wish ''not'' to retain the journald logs, but only syslog-ng's text logs, set {{ic|<nowiki>Storage=volatile</nowiki>}} and {{ic|1=ForwardToSyslog=yes}} in {{ic|/etc/systemd/journald.conf}}. This will store journald in ram. As of syslog-ng 3.6.3, syslog-ng is using journald as the system(); source so if you set {{ic|1=Storage=none}}, the systemd journal will drop all messages and '''not''' forward them to syslog-ng.<br />
<br />
After the change [[restart]] the {{ic|systemd-journald.service}} and {{ic|syslog-ng.service}} daemons.<br />
<br />
== Destinations ==<br />
In syslog-ng, log messages are sent to files. The syntax is very similar to sources:<br />
destination <identifier> {destination-driver(params); destination-driver(params); ... };<br />
<br />
You will be normally logging to a file, but you could log to a different destination-driver: pipe, Unix socket, TCP-UDP ports,<br />
terminals or to specific programs. Therefore, this means sending authlog messages to {{ic|/var/log/auth.log}}:<br />
destination authlog { file("/var/log/auth.log"); };<br />
<br />
If the user is logged in, {{ic|usertty()}} sends messages to the terminal of the specified user. If you want to send console messages<br />
to root's terminal if it is logged in:<br />
destination console { usertty("root"); };<br />
<br />
Messages can be sent to a pipe with {{ic|pipe()}}. The following sends xconsole messages to the pipe {{ic|/dev/xconsole}}.<br />
This needs some more configuration, so you could look at the sub-section xconsole below.<br />
destination xconsole { pipe("/dev/xconsole"); };<br />
<br />
To send messages on the network, use {{ic|udp()}}. The following will send your log data out to another server.<br />
destination remote_server { udp("10.0.0.2" port(514)); };<br />
<br />
== Creating Filters for Messages ==<br />
The syntax for the filter statement is:<br />
filter <identifier> { expression; };<br />
<br />
Functions can be used in the expression, such as the function {{ic|facility()}} which selects messages based on the facility codes. <br />
The Linux kernel has a few facilities you can use for logging. Each facility has a log-level; where debug is the most verbose,<br />
and panic only shows serious errors. You can find the facilities, log levels and priority names in {{ic|/usr/include/sys/syslog.h}}.<br />
To filter those messages coming from authorization, like <br />
''<nowiki>May 11 23:42:31 mimosinnet su(pam_unix)[18569]: session opened for user root by (uid=1000)</nowiki>'', use the following:<br />
filter f_auth { facility(auth); };<br />
<br />
The facility expression can use the boolean operators {{ic|and}}, {{ic|or}}, and {{ic|not}}, so the following filter<br />
selects those messages not coming from authorization, network news or mail:<br />
filter f_debug { not facility(auth, authpriv, news, mail); };<br />
<br />
The function {{ic|level()}} selects messages based on its priority level, so if you want to select informational levels:<br />
filter f_info { level(info); };<br />
<br />
Functions and boolean operators can be combined in more complex expressions. The following line filters messages with a priority level from<br />
informational to warning not coming from auth, authpriv, mail and news facilities:<br />
filter f_messages { level(info..warn) and not facility(auth, authpriv, mail, news); };<br />
<br />
Messages can also be selected by matching a regular expression in the message with the function {{ic|match("regex" value("TEMPLATE"))}}. For example:<br />
filter f_failed { match("failed" value("MESSAGE")); };<br />
<br />
here is a list of templates : <br />
"AMPM", "BSDTAG", "DATE, C_DATE, R_DATE, S_DATE", "DAY, C_DAY, R_DAY, S_DAY", "FACILITY", "FACILITY_NUM", "FULLDATE, C_FULLDATE, R_FULLDATE, S_FULLDATE", "FULLHOST", "FULLHOST_FROM", "HOUR, C_HOUR, R_HOUR, S_HOUR", "HOUR12, C_HOUR12, R_HOUR12, S_HOUR12", "HOST", "HOST_FROM", "ISODATE, C_ISODATE, R_ISODATE, S_ISODATE", "LEVEL_NUM", "LOGHOST", "MIN, C_MIN, R_MIN, S_MIN", "MONTH, C_MONTH, R_MONTH, S_MONTH", "MONTH_ABBREV, C_MONTH_ABBREV, R_MONTH_ABBREV, S_MONTH_ABBREV", "MONTH_NAME, C_MONTH_NAME, R_MONTH_NAME, S_MONTH_NAME", "MONTH_WEEK, C_MONTH_WEEK, R_MONTH_WEEK, S_MONTH_WEEK", "MSEC, C_MSEC, R_MSEC, S_MSEC", "MSG or MESSAGE", "MSGHDR", "MSGID", "MSGONLY", "PID", "PRI", "PRIORITY or LEVEL", "PROGRAM", "SDATA, .SDATA.SDID.SDNAME", "SEC, C_SEC, R_SEC, S_SEC", "SOURCEIP", "SEQNUM", "STAMP, R_STAMP, S_STAMP", "SYSUPTIME", "TAG", "TAGS", "TZ, C_TZ, R_TZ, S_TZ", "TZOFFSET, C_TZOFFSET, R_TZOFFSET, S_TZOFFSET", "UNIXTIME, C_UNIXTIME, R_UNIXTIME, S_UNIXTIME", "USEC, C_USEC, R_USEC, S_USEC", "YEAR, C_YEAR, R_YEAR, S_YEAR", "WEEK, C_WEEK, R_WEEK, S_WEEK", "WEEK_ABBREV, C_WEEK_ABBREV, R_WEEK_ABBREV, S_WEEK_ABBREV", "WEEK_DAY, C_WEEK_DAY, R_WEEK_DAY, S_WEEK_DAY", "WEEKDAY, C_WEEKDAY, R_WEEKDAY, S_WEEKDAY", "WEEK_DAY_NAME, C_WEEK_DAY_NAME, R_WEEK_DAY_NAME, S_WEEK_DAY_NAME".<br />
<br />
To filter messages received from a particular remote host, the {{ic|host()}} function must be used:<br />
filter f_host { host( "192.168.1.1" ); };<br />
<br />
== Log Paths ==<br />
syslog-ng connects sources, filters and destinations with log statements. The syntax is:<br />
log {source(s1); source(s2); ...<br />
filter(f1); filter(f2); ...<br />
destination(d1); destination(d2); ...<br />
flags(flag1[, flag2...]); };<br />
<br />
The following for example sends messages from {{ic|src}} source to {{ic|mailinfo}} destination filtered by {{ic|f_info}} filter.<br />
log { source(src); filter(f_mail); filter(f_info); destination(mailinfo); };<br />
<br />
== Tips and Tricks ==<br />
After understanding the logic behind syslog-ng, many possible and complex configuration are possible. Here there are some examples.<br />
<br />
=== Have syslog-ng reload the configuration file ===<br />
<br />
You can make syslog-ng re-evaluate the configuration file. You can do so manually by sending a {{ic|SIGHUP}} to the process, or call the reload function with systemctl:<br />
# systemctl reload syslog-ng<br />
<br />
=== Failover Logging to Remote Host ===<br />
This setup shows how to send the default unencrypted syslog packets across both TCP and UDP protocols, using the standard port (514) and an alternate port. This is sending the same output to the same machine 4 different ways to try and make sure packets make it. Mostly useful if you are debugging a remote server that fails to reboot. The different ports and protocols are to make it past any firewall filters or other network problems. Also useful for port-forwarding and using tunnels. Something like this setup is ideal to tunnel across an ssh connection that the prone-to-failover host initiates through a reverse connection.<br />
<br />
{{bc|<nowiki>#sending to a remote syslog server on TCP and UDP ports (not encrypted)<br />
destination askapache_failover_loghost {<br />
tcp("208.86.158.195" port(25214));<br />
udp("208.86.158.195" port(25214));<br />
udp("mysyslog1.dyndns.org" port(514));<br />
};<br />
log { <br />
source(src); <br />
destination(askapache_failover_loghost);<br />
};</nowiki><br />
}}<br />
<br />
And then on the loghost receiving these logs:<br />
<br />
{{bc|<nowiki>#a USB redirected console for flexible viewing<br />
destination debugging_console {<br />
file("/dev/ttyU1");<br />
};<br />
<br />
# listens on IP addresses and ports, sets the incoming settings<br />
source prone_to_failover_host {<br />
tcp(ip(208.86.158.195),port(25214));<br />
udp(ip(208.86.158.195) port(25214));<br />
<br />
udp(default-facility(syslog) default-priority(emerg));<br />
tcp(default-facility(syslog) default-priority(emerg));<br />
}<br />
<br />
# log it<br />
log {<br />
source(prone_to_failover_host); <br />
destination(debugging_console);<br />
};</nowiki><br />
}}<br />
<br />
=== Move log to another file ===<br />
In order to move some log from {{ic|/var/log/messages}} to another file:<br />
<br />
{{bc|<nowiki>#sshd configuration<br />
destination ssh { file("/var/log/ssh.log"); };<br />
filter f_ssh { program("sshd"); };<br />
log { source(src); filter(f_ssh); destination(ssh); };</nowiki><br />
}}<br />
<br />
=== Configuring as a loghost ===<br />
Configuring your system to be a loghost is quite simple. Drop the following into your configuration, and create the needed directory.<br />
With this simple configuration, log filenames will be based on the [[Wikipedia:FQDN|FQDN]] of the remote host,<br />
and located in {{ic|/var/log/remote/}}. After creating the remote directory, reload your syslog-ng configuration.<br />
<br />
{{bc|<nowiki>source net { udp(); };<br />
destination remote { file("/var/log/remote/${FULLHOST}-log"); };<br />
log { source(net); destination(remote); };</nowiki><br />
}}<br />
<br />
=== Improve Performance ===<br />
syslog-ng's performance can be improved in different ways:<br />
<br />
==== Write every so often ====<br />
It seems that the old {{ic|sync(X)}} '''option''' is called {{ic|flush_lines(X)}} now, where the writing to the file is buffered for {{ic|X}} lines. Default is 0 (no buffering).<br />
<br />
==== Avoid redundant processing and disk space ====<br />
A single log message can be sent to different log files several times. For example, in the initial configuration file, we have the following definitions:<br />
<br />
{{bc|<nowiki>destination cron { file("/var/log/cron.log"); };<br />
destination messages { file("/var/log/messages"); };<br />
filter f_cron { facility(cron); };<br />
filter f_messages { level(info..warn) <br />
and not facility(auth, authpriv, mail, news); };<br />
log { source(src); filter(f_cron); destination(cron); };<br />
log { source(src); filter(f_messages); destination(messages); };</nowiki><br />
}}<br />
<br />
The same message from the {{ic|cron}} facility will end up in both the {{ic|cron.log}} and {{ic|messages}} files. To change this behavior we can use the {{ic|final}} flag, <br />
ending up further processing with the message. Therefore, in this example, if we want messages from the {{ic|cron}} facility not ending up in the<br />
messages file, we should change the cron's log sentence by:<br />
<br />
log { source(src); filter(f_cron); destination(cron); flags(final); };<br />
<br />
another way is to exclude the {{ic|cron}} facility from {{ic|f_messages}} filter:<br />
filter f_messages { level(info..warn) and not facility(cron, auth, authpriv, mail, news); };<br />
<br />
=== PostgreSQL Destination ===<br />
This section will use two roles: {{ic|syslog}} and {{ic|logwriter}}. {{ic|syslog}} will be the administrator of the database {{ic|syslog}} and {{ic|logwriter}} will only be able to add records to the {{ic|logs}} table.<br />
<br />
No longer needed to create table for logs. syslog-ng will create automatically.<br />
psql -U postgres<br />
<br />
postgres=# CREATE ROLE syslog WITH LOGIN;<br />
postgres=# \password syslog # Using the \password function is secure because<br />
postgres=# CREATE ROLE logwriter WITH LOGIN;<br />
postgres=# \password logwriter # the password is not saved in history.<br />
postgres=# CREATE DATABASE syslog OWNER syslog;<br />
postgres=# \q # You are done here for the moment<br />
<br />
Edit {{ic|pg_hba.conf}} to allow {{ic|syslog}} and {{ic|logwriter}} to establish a connection to PostgreSQL.<br />
<br />
{{hc|/var/lib/postgres/data/pg_hba.conf|<br />
# TYPE DATABASE USER CIDR-ADDRESS METHOD<br />
<br />
host syslog logwriter 192.168.0.1/24 md5<br />
host syslog syslog 192.168.0.10/32 md5<br />
}}<br />
<br />
Tell PostgreSQL to reload the configuration files:<br />
<br />
# systemctl reload postgresql<br />
<br />
Edit {{ic|/etc/syslog-ng/syslog-ng.conf}} so that it knows where and how to write to PostgreSQL. syslog-ng will utilize the {{ic|logwriter}} role.<br />
<br />
{{bc|<nowiki>...<br />
#<br />
# SQL logging support<br />
#<br />
<br />
destination d_pgsql {<br />
sql(type(pgsql)<br />
host("127.0.0.1") username("logwriter") password("password")<br />
database("syslog")<br />
table("logs_${HOST}_${R_YEAR}${R_MONTH}${R_DAY}") #or whatever you want, example ${HOST}" for hosts, ${LEVEL}" for levels.. etc<br />
columns("datetime timestamp with time zone", "host varchar(32)", "program varchar(16)", "pid varchar(16)", "message varchar(200)")<br />
values("$R_ISODATE", "$HOST", "$PROGRAM", "$PID", "$MSG")<br />
indexes("datetime", "host", "program", "pid", "message"));<br />
};<br />
<br />
log { source(src); destination(d_pgsql); };</nowiki><br />
}}<br />
<br />
Finally, restart syslog-ng.<br />
# systemctl restart syslog-ng<br />
<br />
And check to see if things are being logged.<br />
psql -U logwriter -d syslog<br />
syslog=> SELECT * FROM <your table name> ORDER BY datetime DESC LIMIT 10;<br />
<br />
=== ISO 8601 timestamps ===<br />
'''Before''' :<br />
#logger These timestamps are not optimal.<br />
#tail -n 1 /var/log/messages.log<br />
Feb 18 14:25:01 hostname logger: These timestamps are not optimal.<br />
#<br />
<br />
Add {{ic|ts_format(iso);}} to {{ic|/etc/syslog-ng/syslog-ng.conf}} in the options section. Example:<br />
options {<br />
stats_freq (0);<br />
flush_lines (0);<br />
time_reopen (10);<br />
log_fifo_size (1000);<br />
long_hostnames(off); <br />
use_dns (no);<br />
use_fqdn (no);<br />
create_dirs (no);<br />
keep_hostname (yes);<br />
perm(0640);<br />
group("log");<br />
ts_format(iso); #make ISO-8601 timestamps<br />
};<br />
<br />
Then:<br />
# systemctl reload syslog-ng<br />
<br />
'''After''' :<br />
#logger Now THAT is a timestamp!<br />
#tail -n 2 /var/log/messages.log<br />
Feb 18 14:25:01 hostname logger: These timestamps are not optimal.<br />
2010-02-18T20:23:58-05:00 electron logger: Now THAT is a timestamp!<br />
#<br />
<br />
=== RFC 3339 timestamps ===<br />
Same as above, except use {{ic|rfc3339}} instead of {{ic|iso}} for {{ic|ts_format}}<br />
<br />
=== Log Levels ===<br />
<br />
Log levels are defined separately for each logged facility in syslog-ng config. Available log levels are listed in /usr/include/sys/syslog.h :<br />
<br />
define LOG_EMERG 0 /* system is unusable */<br />
define LOG_ALERT 1 /* action must be taken immediately */<br />
define LOG_CRIT 2 /* critical conditions */<br />
define LOG_ERR 3 /* error conditions */<br />
define LOG_WARNING 4 /* warning conditions */<br />
define LOG_NOTICE 5 /* normal but significant condition */<br />
define LOG_INFO 6 /* informational */<br />
define LOG_DEBUG 7 /* debug-level messages */<br />
<br />
=== Macros and Variables ===<br />
Macros can be used in both templates, and in destination file names. [http://www.balabit.com/sites/default/files/documents/syslog-ng-ose-3.4-guides/en/syslog-ng-ose-v3.4-guide-admin/html/reference-macros.html Macros of syslog-ng OSE].<br />
<br />
The following code will write the log lines to {{ic|/var/log/test.log}} in the format of {{ic|<nowiki>macroname=value@</nowiki>}}. <br />
<br />
{{bc|<nowiki>template t_test { template("PROGRAM=$PROGRAM@PID=$PID@BSDTAG=$BSDTAG@TAG=$TAG@TAGS=$TAGS@FACILITY=$FACILITY@FACILITY_NUM=$FACILITY_NUM@LEVEL=$LEVEL@LEVEL_NUM=$LEVEL_NUM@PRI=$PRI@PRIORITY=$PRIORITY@FULLHOST=$FULLHOST@FULLHOST_FROM=$FULLHOST_FROM@HOST=$HOST@HOST_FROM=$HOST_FROM@LOGHOST=$LOGHOST@MSGHDR=$MSGHDR@MSGID=$MSGID@MSGONLY=$MSGONLY@MSG=$MSG@MESSAGE=$MESSAGE@SOURCE=$SOURCE@SOURCEIP=$SOURCEIP@SOURCE_IP=$SOURCE_IP@SEQNUM=$SEQNUM@UNIXTIME=$UNIXTIME@FULLDATE=$FULLDATE@ISODATE=$ISODATE@DATE=$DATE@STAMP=$STAMP@TZ=$TZ@TZOFFSET=$TZOFFSET@SEC=$SEC@MIN=$MIN@HOUR=$HOUR@HOUR12=$HOUR12@DAY=$DAY@WEEK=$WEEK@WEEK_DAY=$WEEK_DAY@WEEK_DAY_ABBREV=$WEEK_DAY_ABBREV@WEEK_DAY_NAME=$WEEK_DAY_NAME@MONTH=$MONTH@MONTH_ABBREV=$MONTH_ABBREV@MONTH_NAME=$MONTH_NAME@MONTH_WEEK=$MONTH_WEEK@YEAR=$YEAR@YEAR_DAY=$YEAR_DAY<br />
\n"); template_escape(no); };<br />
<br />
destination d_test { file("/var/log/test.log" template(t_test)); };<br />
<br />
log { source(s_local); destination(d_test); flags(final); };<br />
</nowiki>}}<br />
<br />
You can create your own value list as below once syslog-ng is restarted with:<br />
{{ic|<nowiki>tail /var/log/test.log|tr "@" "\n"</nowiki>}}<br />
<br />
{{bc|<nowiki><br />
PROGRAM=kernel<br />
PID=<br />
BSDTAG=4A<br />
TAG=04<br />
TAGS=.source.s_local<br />
FACILITY=kern<br />
FACILITY_NUM=0<br />
LEVEL=warning<br />
LEVEL_NUM=4<br />
PRI=4<br />
PRIORITY=warning<br />
FULLHOST=www.askapache.com<br />
FULLHOST_FROM=www.askapache.com<br />
HOST=www.askapache.com<br />
HOST_FROM=www.askapache.com<br />
LOGHOST=<br />
MSGHDR=kernel: <br />
MSGID=<br />
MSGONLY=Firewall: *INVALID* IN=eth0 OUT= MAC=00:00 SRC=x.x.x.x DST=198.101.159.98 LEN=40 TOS=0x00 PREC=0x00 TTL=113 ID=7730 DF PROTO=TCP SPT=52369 DPT=80 WINDOW=0 RES=0x00 ACK RST URGP=0 <br />
MSG=Firewall: *INVALID* IN=eth0 OUT= MAC=00:00 SRC=x.x.x.x DST=198.101.159.98 LEN=40 TOS=0x00 PREC=0x00 TTL=113 ID=7730 DF PROTO=TCP SPT=52369 DPT=80 WINDOW=0 RES=0x00 ACK RST URGP=0 <br />
MESSAGE=Firewall: *INVALID* IN=eth0 OUT= MAC=00:00 SRC=x.x.x.x DST=198.101.159.98 LEN=40 TOS=0x00 PREC=0x00 TTL=113 ID=7730 DF PROTO=TCP SPT=52369 DPT=80 WINDOW=0 RES=0x00 ACK RST URGP=0 <br />
SOURCE=s_local<br />
SOURCEIP=127.0.0.1<br />
SOURCE_IP=<br />
UNIXTIME=1369742458<br />
FULLDATE=2013 May 28 08:00:58<br />
ISODATE=2013-05-28T08:00:58-04:00<br />
DATE=May 28 08:00:58<br />
STAMP=2013-05-28T08:00:58-04:00<br />
TZ=-04:00<br />
TZOFFSET=-04:00<br />
SEC=58<br />
MIN=00<br />
HOUR=08<br />
HOUR12=<br />
DAY=28<br />
WEEK=21<br />
WEEK_DAY=3<br />
WEEK_DAY_ABBREV=Tue<br />
WEEK_DAY_NAME=Tuesday<br />
MONTH=05<br />
MONTH_ABBREV=May<br />
MONTH_NAME=May<br />
MONTH_WEEK=4<br />
YEAR=2013<br />
YEAR_DAY=148<br />
</nowiki>}}<br />
<br />
=== See Also ===<br />
* [[Netconsole]] A kernel module that sends all kernel log messages (i.e. dmesg) over the network to another computer, without involving user space (e.g. syslogd).<br />
<br />
== External Links ==<br />
* [http://www.balabit.com/network-security/syslog-ng/opensource-logging-system/overview syslog-ng OSE Project Page]<br />
* [http://www.balabit.com/support/documentation/ Portal to syslog-ng Documentation]<br />
** [http://www.balabit.com/sites/default/files/documents/syslog-ng-ose-3.4-guides/en/syslog-ng-ose-v3.4-guide-admin/html/index.html The syslog-ng 3.4 Administrator Guide]<br />
** [http://www.balabit.com/sites/default/files/documents/syslog-ng-ose-3.4-guides/en/syslog-ng-ose-v3.4-guide-admin/html/syslog-ng-parameter-index.html List of syslog-ng 3.4 Parameters]<br />
** [http://www.balabit.com/sites/default/files/documents/syslog-ng-ose-3.4-guides/en/syslog-ng-ose-v3.4-guide-admin/html/reference-macros.html List of syslog-ng 3.4 Macros]<br />
* [http://freshmeat.net/projects/syslog-ng/ syslog-ng Project Page on Freshmeat]<br />
* [https://wiki.gentoo.org/wiki/Syslog-ng Gentoo syslog-ng wiki]<br />
* [http://www.gentoo.org/doc/en/security/security-handbook.xml?part=1&chap=3 Gentoo Security Handbook on Logging]<br />
* [http://www.pcwdld.com/what-is-syslog-including-servers-and-ports What is Syslog? Logging with PostgreSQL HOWTO]<br />
* [[wikipedia:ISO_8601|ISO_8601]] Wikipedia page for ISO 8601<br />
* [http://tools.ietf.org/html/rfc3164 RFC 3164] - The BSD syslog Protocol<br />
* [http://tools.ietf.org/html/rfc3164 RFC 5424] - The Syslog Protocol<br />
** [http://tools.ietf.org/html/rfc5425 RFC 5425] - Transport Layer Security (TLS) Transport Mapping for Syslog<br />
** [http://tools.ietf.org/html/rfc5425 RFC 5426] - Transmission of Syslog Messages over UDP<br />
** [http://tools.ietf.org/html/rfc5425 RFC 5427] - Textual Conventions for Syslog Management<br />
** [http://tools.ietf.org/html/rfc5425 RFC 5428] - MIB for PacketCable and IPCablecom-Compliant Devices<br />
* [http://tools.ietf.org/html/rfc3339 RFC 3339] - Date and Time on the Internet: Timestamps</div>X33ahttps://wiki.archlinux.org/index.php?title=Xinit&diff=457199Xinit2016-11-19T18:39:45Z<p>X33a: Add a section about output redirection</p>
<hr />
<div>{{Lowercase title}}<br />
[[Category:Desktop environments]]<br />
[[Category:X server]]<br />
[[de:Xinitrc]]<br />
[[el:Xinitrc]]<br />
[[es:Xinitrc]]<br />
[[fr:Startx]]<br />
[[it:Xinitrc]]<br />
[[ja:Xinitrc]]<br />
[[ru:Xinitrc]]<br />
[[zh-CN:Xinitrc]]<br />
{{Related articles start}}<br />
{{Related|Display manager}}<br />
{{Related|Xorg}}<br />
{{Related|xprofile}}<br />
{{Related|Xresources}}<br />
{{Related articles end}}<br />
<br />
The {{ic|~/.xinitrc}} file is a shell script read by ''xinit'' and by its front-end ''startx''. It is mainly used to execute [[desktop environment]]s, [[window manager]]s and other programs when starting the X server (e.g., starting daemons and setting environment variables). The ''xinit'' program starts the [[X Window System]] server and works as first client program on systems that are not using a [[display manager]].<br />
<br />
One of the main functions of {{ic|~/.xinitrc}} is to dictate which client for the X Window System is invoked with ''startx'' or ''xinit'' programs on a per-user basis. There exists numerous additional specifications and commands that may also be added to {{ic|~/.xinitrc}} as you further customize your system.<br />
<br />
Most display managers also source the similar [[xprofile]] before xinit.<br />
<br />
== Installation ==<br />
<br />
[[Install]] the {{Pkg|xorg-xinit}} package, which provides both ''xinit'', ''startx'', and a default xinitrc configuration file.<br />
<br />
== Configuration ==<br />
<br />
=== xserverrc ===<br />
<br />
The {{ic|xserverrc}} file is a shell script responsible for starting up the X server. Both ''startx'' and ''xinit'' execute {{ic|~/.xserverrc}} if it exists, ''startx'' will use {{ic|/etc/X11/xinit/xserverrc}} otherwise.<br />
<br />
In order to maintain an [[General troubleshooting#Session permissions|authenticated session]] with {{ic|logind}} and to prevent bypassing the screen locker by switching terminals, [[Xorg]] has to be started on the same virtual terminal where the login occurred.[http://blog.falconindy.com/articles/back-to-basics-with-x-and-systemd.html] Therefore it is recommended to specify {{ic|vt$XDG_VTNR}} in the {{ic|~/.xserverrc}} file:<br />
<br />
{{hc|~/.xserverrc|<br />
#!/bin/sh<br />
<br />
exec /usr/bin/Xorg -nolisten tcp "$@" vt$XDG_VTNR<br />
}}<br />
<br />
Alternatively, if you wish to have the X display on a separate console from the one where the server is invoked, you can do so by using the X server wrapper provided by {{ic|/usr/lib/systemd/systemd-multi-seat-x}}. For convenience, ''xinit'' and ''startx'' can be set up to use this wrapper by modifying your {{ic|~/.xserverrc}}.<br />
<br />
=== xinitrc ===<br />
<br />
If {{ic|.xinitrc}} is present in a user's home directory, ''startx'' and ''xinit'' execute it. Otherwise ''startx'' will run the default {{ic|/etc/X11/xinit/xinitrc}}.<br />
{{note|''Xinit'' has its own default behaviour instead of executing the file. See {{ic|man 1 xinit}} for details.}}<br />
This default xinitrc will start a basic environment with [[Twm]], {{Pkg|xorg-xclock}} and [[Xterm]] (assuming that the necessary packages are installed). Therefore, to start a different window manager or desktop environment, first create a copy of the default {{ic|xinitrc}} in home directory:<br />
<br />
$ cp /etc/X11/xinit/xinitrc ~/.xinitrc<br />
<br />
The reason of doing this (instead of creating one from scratch) is to preserve some desired default behaviour in the original file, such as sourcing shell scripts from {{ic|/etc/X11/xinit/xinitrc.d}}. Scripts in this directory without {{ic|.sh}} extension are not sourced.<br />
<br />
Append desired commands and ''remove/comment the conflicting lines''. Remember, lines following {{ic|exec}} would be ignored. For example, to start [[Openbox#Standalone|openbox]]:<br />
<br />
{{hc|~/.xinitrc|<br />
...<br />
<br />
if [ -d /etc/X11/xinit/xinitrc.d ] ; then<br />
for f in /etc/X11/xinit/xinitrc.d/'''?*.sh''' ; do<br />
[ -x "$f" ] && . "$f"<br />
done<br />
unset f<br />
fi<br />
<br />
# twm &<br />
# xclock -geometry 50x50-1+1 &<br />
# xterm -geometry 80x50+494+51 &<br />
# xterm -geometry 80x20+494-0 &<br />
# exec xterm -geometry 80x66+0+0 -name login<br />
<br />
## some applications that should be run in the background<br />
xscreensaver '''&'''<br />
xsetroot -cursor_name left_ptr '''&'''<br />
<br />
'''exec''' openbox-session<br />
}}<br />
<br />
{{Note|At the very least, ensure that the ''if block'' in the example above is present in your {{ic|.xinitrc}} file to ensure that the scripts in {{ic|/etc/X11/xinit/xinitrc.d}} are sourced.}} <br />
<br />
Long-running programs started before the window manager, such as a screensaver and wallpaper application, must either fork themselves or be run in the background by appending an {{ic|&}} sign. Otherwise, the script would halt and wait for each program to exit before executing the window manager or desktop environment. Note that some programs should instead not be forked, to avoid race bugs, as is the case of [[xrdb]]. Prepending {{ic|exec}} will replace the script process with the window manager process, so that X does not exit even if this process forks to the background.<br />
<br />
== Usage ==<br />
<br />
To now run Xorg as a regular user, issue:<br />
<br />
$ startx<br />
<br />
or<br />
<br />
$ xinit -- :1<br />
<br />
{{Note|''xinit'' does not handle multiple displays when another X server is already started. For that you must specify the display by appending {{ic|-- :''display_number''}}, where {{ic|''display_number''}} is 1 or more.}}<br />
<br />
Your window manager (or desktop environment) of choice should now start correctly.<br />
<br />
To quit X, run your window manager's exit function (assuming it has one). If it lacks such functionality, run:<br />
<br />
$ pkill -15 Xorg<br />
<br />
{{Note|''pkill'' will kill all running X instances. To specifically kill the window manager on the current virtual terminal, run:<br />
<br />
$ pkill -15 -t tty"$XDG_VTNR" Xorg<br />
<br />
The program {{ic|xprop}} is provided by the {{Pkg|xorg-xprop}} package.<br />
}}<br />
<br />
== Autostart X at login ==<br />
<br />
Make sure that ''startx'' is properly [[#Configuration|configured]].<br />
<br />
For [[Bash]], add the following to the bottom of {{ic|~/.bash_profile}}. If the file does not exist, copy a skeleton version from {{ic|/etc/skel/.bash_profile}}. For [[Zsh]], add it to {{ic|~/.zprofile}}.<br />
<br />
{{bc|1=<nowiki><br />
if [ -z "$DISPLAY" ] && [ -n "$XDG_VTNR" ] && [ "$XDG_VTNR" -eq 1 ]; then<br />
exec startx<br />
fi<br />
</nowiki>}}<br />
<br />
{{Note|<br />
* You can replace the {{ic|-eq 1}} comparison with one like {{ic|-le 3}} (for vt1 to vt3) if you want to use graphical logins on more than one virtual terminal.<br />
* Alternative conditions to detect the virtual terminal include {{ic|<nowiki>"$(tty)" == "/dev/tty1"</nowiki>}}, which does not allow comparison with {{ic|-le}}, and {{ic|<nowiki>"$(fgconsole 2>/dev/null || echo -1)" -eq 1</nowiki>}}, which does not work in [[serial console]]s.<br />
* If you would like to remain logged in when the X session ends, remove {{ic|exec}}.<br />
}}<br />
<br />
See also [[Fish#Start X at login]] and [[Systemd/User#Automatic login into Xorg without display manager]].<br />
<br />
=== Automatic login to the virtual console ===<br />
<br />
This method can be combined with [[automatic login to virtual console]].<br />
<br />
== Tips and tricks ==<br />
<br />
=== Override xinitrc from command line ===<br />
<br />
If you have a working {{ic|~/.xinitrc}}, but just want to try other window manager or desktop environment, you can run it by issuing ''startx'' followed by the path to the window manager:<br />
<br />
$ startx /full/path/to/window-manager<br />
<br />
If the window manager takes arguments, they need to be enquoted to be recognized as part of the first parameter of ''startx'':<br />
<br />
$ startx "/full/path/to/window-manager --key value"<br />
<br />
Note that the full path is '''required'''. Optionally, you can also specify custom options for [[#xserverrc]] script by appending them after {{ic|--}}, e.g.:<br />
<br />
$ startx /usr/bin/enlightenment -- -br +bs -dpi 96<br />
<br />
See also {{ic|man startx}}.<br />
<br />
{{Tip|This can be used even to start a regular GUI programs but without any of the window manager features. See also [[#Starting applications without a window manager]] and [[Running program in separate X display]].}}<br />
<br />
=== Switching between desktop environments/window managers ===<br />
<br />
If you are frequently switching between different desktop environments or window managers, it is convenient to either use a [[display manager]] or expand {{ic|.xinitrc}} to make the switching possible.<br />
<br />
The following example {{ic|~/.xinitrc}} shows how to start a particular desktop environment or window manager with an argument:<br />
<br />
{{hc|~/.xinitrc|<nowiki><br />
...<br />
<br />
# Here Xfce is kept as default<br />
session=${1:-xfce}<br />
<br />
case $session in<br />
awesome ) exec awesome;;<br />
bspwm ) exec bspwm;;<br />
catwm ) exec catwm;;<br />
cinnamon ) exec cinnamon-session;;<br />
dwm ) exec dwm;;<br />
enlightenment ) exec enlightenment_start;;<br />
ede ) exec startede;;<br />
fluxbox ) exec startfluxbox;;<br />
gnome ) exec gnome-session;;<br />
gnome-classic ) exec gnome-session --session=gnome-classic;;<br />
i3|i3wm ) exec i3;;<br />
icewm ) exec icewm-session;;<br />
jwm ) exec jwm;;<br />
kde ) exec startkde;;<br />
mate ) exec mate-session;;<br />
monster|monsterwm ) exec monsterwm;;<br />
notion ) exec notion;;<br />
openbox ) exec openbox-session;;<br />
unity ) exec unity;;<br />
xfce|xfce4 ) exec startxfce4;;<br />
xmonad ) exec xmonad;;<br />
# No known session, try to run it as command<br />
*) exec $1;;<br />
esac<br />
</nowiki>}}<br />
<br />
To pass the argument:<br />
<br />
$ xinit<br />
$ xinit gnome<br />
$ xinit kde<br />
$ xinit wmaker<br />
<br />
or<br />
<br />
$ startx<br />
$ startx ~/.xinitrc gnome<br />
$ startx ~/.xinitrc kde<br />
$ startx ~/.xinitrc wmaker<br />
<br />
=== Starting applications without a window manager ===<br />
<br />
It is possible to start only specific applications without a window manager, although most likely this is only useful with a single application shown in full-screen mode. For example:<br />
<br />
{{hc|~/.xinitrc|<br />
...<br />
<br />
exec chromium<br />
}}<br />
<br />
With this method you need to set each application window's geometry through its own configuration files, if possible at all.<br />
<br />
{{Tip|This method can be useful to launch graphical games, especially on systems where excluding the memory or CPU usage of a window manager or desktop environment, and possible accessory applications, can help improve the game's execution performance.}}<br />
<br />
See also [[Display manager#Starting applications without a window manager]].<br />
<br />
=== Output redirection using startx ===<br />
<br />
If you want to redirect the output of startx, specifically {{ic|stderr}}, you can pass the {{ic|keeptty}} server option to startx. For example:<br />
<br />
startx -- -keeptty > ~/.xorg.log 2>&1</div>X33ahttps://wiki.archlinux.org/index.php?title=Apple_Keyboard&diff=456791Apple Keyboard2016-11-14T16:08:10Z<p>X33a: /* Swap the Fn key and Left Ctrl key */ refactored the section</p>
<hr />
<div>[[Category:Keyboards]]<br />
[[ja:Apple Keyboard]]<br />
{{Style|Continues the tradition of Apple* articles of violating [[Help:Style]] in every way imaginable}}<br />
== More Information ==<br />
For background information see this page: https://help.ubuntu.com/community/AppleKeyboard<br />
<br />
{{Note|Some of the settings can be made permanent with a configuration file for a [[kernel module]]. For this to work, the file has to be added to FILES in [[mkinitcpio.conf]] cause the kernel module will be autoloaded while booting.}}<br />
<br />
{{Tip|If you want to use [[sudo]] to write into a system directory you can't use shell redirection. Use {{ic|tee}} like so<br />
$ echo 0 &#124; sudo tee /sys/module/hid_apple/parameters/iso_layout<br />
}}<br />
<br />
==Numlock is on==<br />
<br />
You may experience that numlock is on. The symptoms are present when only the physical keys, 7,8,9,u,i,o,j,k,l and surounding keys only work and output numbers. To fix this hit {{ic|Fn}}+{{ic|F6}} twice.<br />
<br />
==Repeating Keys==<br />
Unpair the keyboard and then re-pair it. The trick is to hold down the power button throughout the entire pairing proccess (it's a two hand job)<br />
<br />
==Function keys do not work==<br />
<br />
If your {{ic|F<num>}} keys do not work, this is probably because the kernel driver for the keyboard has defaulted to using the media keys and requiring you to use the {{ic|Fn}} key to get to the {{ic|F<num>}} keys. To change this behaviour, you have to change the driver setting. Do the following as root:<br />
<br />
# echo 2 > /sys/module/hid_apple/parameters/fnmode<br />
<br />
If it tells you that the file doesn't exist, you probably have an older kernel and will have to do the following instead:<br />
<br />
# echo 2 > /sys/module/hid/parameters/pb_fnmode<br />
<br />
Place whatever option worked for you in {{ic|/etc/modprobe.d/hid_apple.conf}} to make the setting permanent:<br />
<br />
{{hc|/etc/modprobe.d/hid_apple.conf|<nowiki><br />
options hid_apple fnmode=2<br />
</nowiki>}}<br />
<br />
Don't forget to add this file to FILES in [[mkinitcpio.conf]] and rebuild the initial ramdisk, otherwise it will not work.<br />
<br />
===If the above doesn't work for your wireless keyboard===<br />
<br />
If {{ic|hid_apple/parameters}} and/or {{ic|hid/parameters/pb_fnmode}} is missing in a recent Apple Bluetooth keyboard model and kernel 3.4.<br />
<br />
First thing: identify your keyboard. Execute as root ({{ic|hidd}} is part of package {{Pkg|bluez}} from the [[official repositories]]):<br />
# hidd --show<br />
<br />
You should see something like:<br />
40:CA:EC:32:85:AB Apple Wireless Keyboard [05ac:0255] connected <br />
<br />
So with the vendor (05ac) and device (0255) ID it's easier to find out if the current kernel has support for it.<br />
Actually, the above device is listed in the linux kernel 3.4. If you check {{ic|drivers/hid/hid-ids.h}} you should see the following line:<br />
<br />
#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI 0x0255<br />
<br />
But support for the Function Key is missing.<br />
<br />
In order to fix it rebuild your kernel from [[abs]] with the following patch:<br />
http://pastebin.com/CvFJz3Fn<br />
<br />
This bug is already reported upstream<br />
https://bugzilla.kernel.org/show_bug.cgi?id=43135<br />
and part of the vanilla kernel since 3.5<br />
<br />
==< and > have changed place with § and ½==<br />
<br />
If the '''<''' and '''>''' are switched with the '''§''' and '''½''' keys, run the following command in your graphical environment:<br />
<br />
$ setxkbmap -option apple:badmap<br />
<br />
Place that command into {{ic|~/.bashrc}} file to have it run automatically when you log in.<br />
<br />
You can also apply the change system-wide by creating (or editing) {{ic|/etc/X11/xorg.conf.d/10-keymap.conf}} as such:<br />
Section "InputClass"<br />
Identifier "keyboard catchall"<br />
MatchIsKeyboard "true"<br />
Driver "evdev"<br />
Option "XkbOptions" "apple:badmap"<br />
EndSection<br />
<br />
<br />
If the above approach doesn't seem to work, you can add these two lines to your {{ic|~/.Xmodmap}} file:<br />
<br />
keycode 49 = less greater less greater bar brokenbar<br />
keycode 94 = section degree section degree notsign notsign<br />
<br />
If you use a Canadian multilingual layout (where the "ù" and the "/" is switch) use this :<br />
<br />
keycode 94 = slash backslash slash backslash bar brokenbar<br />
keycode 49 = ugrave Ugrave ugrave Ugrave notsign notsign<br />
<br />
Then run {{Ic|xmodmap ~/.Xmodmap}}. This command can also go into {{ic|~/.bashrc}}.<br />
<br />
==< and > have changed place with ^ and ° (or @ and #)==<br />
With German layout, circumflex/degree symbol and 'smaller than'/'bigger than' are exchanged. With French layout, @/# are exchanged.<br />
<br />
'''The new way:'''<br />
<br />
First, try if the new method works for you (you have to be root)<br />
# echo 0 > /sys/module/hid_apple/parameters/iso_layout<br />
To make the changes permanent add the following line to {{ic|/etc/modprobe.d/hid_apple.conf}}:<br />
options hid_apple iso_layout=0<br />
<br />
'''To fix this the old way, do the following:'''<br />
$ xmodmap -e 'keycode 49 = less greater less greater bar brokenbar bar' -e 'keycode 94 = dead_circumflex degree dead_circumflex degree U2032 U2033 U2032'<br />
<br />
Now try your keys. When it works, you may want the change permanently. So execute this:<br />
$ xmodmap -pke | grep " 49" >> ~/.Xmodmap<br />
$ xmodmap -pke | grep " 94" >> ~/.Xmodmap<br />
<br />
==The ` and ~ keys output < and >==<br />
With the US layout, the backtick and tilde keys output lessthan or graterthan.<br />
<br />
First, try if the new method works for you (you have to be root)<br />
# echo 0 > /sys/module/hid_apple/parameters/iso_layout<br />
To make the changes permanent add<br />
options hid_apple iso_layout=0<br />
to {{ic|/etc/modprobe.d/hid_apple.conf}} and run {{ic|mkinitcpio -p linux}} as root.<br />
<br />
==Media Keys==<br />
<br />
The evdev driver should produce keycodes that map to the appropriate keysyms for your media keys by default. You can confirm that by running {{Ic|xev}} in a console window and watching the console output as you press your media keys.<br />
<br />
For these keys to have any effect, you will have to assign actions to them. Refer to [[Extra keyboard keys in Xorg]] for more about that.<br />
<br />
<br />
If you have confirmed that your media keys are ''not'' producing the correct keycodes, create or edit the {{ic|~/.Xmodmap}} file so that it includes these lines:<br />
{{bc|1=keycode 160 = XF86AudioMute<br />
keycode 176 = XF86AudioRaiseVolume<br />
keycode 174 = XF86AudioLowerVolume<br />
<br />
keycode 144 = XF86AudioPrev<br />
keycode 162 = XF86AudioPlay<br />
keycode 153 = XF86AudioNext<br />
<br />
keycode 101 = XF86MonBrightnessDown<br />
keycode 212 = XF86MonBrightnessUp<br />
<br />
keycode 204 = XF86Eject}}<br />
and then run {{Ic|xmodmap ~/.Xmodmap}}. Place that command in the {{ic|~/.bashrc}} file to have it run automatically when you log in.<br />
<br />
==PrintScreen and SysRq==<br />
<br />
Apple Keyboards have an {{ic|F13}} key instead of a {{ic|PrintScreen}}/{{ic|SysRq}} key. This means that [[Keyboard shortcuts#Kernel|Alt+SysRq sequences]] do not work, and application actions associated with {{ic|PrintScreen}} (such as taking screenshots in many games that work under [[Wine]]) do not work.<br />
Both issues can be addressed by installing {{AUR|keyfuzz}} from the [[Arch User Repository]].<br />
<br />
With keyfuzz installed, run the following command:<br />
echo "458856 99" | /usr/sbin/keyfuzz -s -d /dev/input/by-id/usb-Apple__Inc_Apple_keyboard-event-kbd<br />
458856 (0x070068) is the scancode of {{ic|F13}}, and 99 is the keycode of {{ic|PrintScreen}}/{{ic|SysRq}}. You can determine the scancode of a particular key with {{AUR|getscancodes}}{{Broken package link|{{aur-mirror|getscancodes}}}} from the [[AUR]], and the keycode from {{ic|/usr/include/linux/input.h}}.<br />
<br />
Other versions of the Apple Aluminum Keyboard may require a slightly different device path, so adjust it as needed. You can make this change permanent by putting the command in {{ic|/etc/rc.local}}.<br />
<br />
==Treating Apple Keyboards Like Regular Keyboards==<br />
<br />
If you want to use your Apple keyboard like a regular US-layout keyboard, with {{ic|Alt}} on the left side of {{ic|Meta}}, you can use the [[AUR]] package {{AUR|un-apple-keyboard}}. Currently it only works for the aluminium USB model. The package does the following things:<br />
<br />
*Adds a {{ic|/etc/modprobe.d/hid_apple.conf}} file which enables the {{ic|F}} keys by default, as above.<br />
*Uses keyfuzz to remap {{ic|F13-15}} to {{ic|PrintScreen}}/{{ic|SysRq}}, {{ic|Scroll Lock}}, and {{ic|Pause}}, respectively<br />
*Swaps the ordering of the {{ic|Alt}} and {{ic|Meta}} ({{ic|Command}}) keys to match all other keyboards, again using {{ic|/etc/modprobe.d/hid_apple.conf}}.<br />
*Applies these changes automatically when you plug in your keyboard, with a [[udev]] rule.<br />
<br />
You will need to add {{ic|/etc/modprobe.d/hid_apple.conf}} to FILES in [[mkinitcpio.conf]]. Otherwise if you boot your computer with the Apple keyboard plugged in, the F keys will not be the default.<br />
<br />
==Swap the Alt key and Command key(Meta/Super)==<br />
<br />
'''Temporarily'''<br />
<br />
The following command will swap cmd and Alt keys with immediate effect, but restarting will reset the configuration:<br />
<br />
$ echo 1 | sudo tee /sys/module/hid_apple/parameters/swap_opt_cmd<br />
<br />
'''Permanently'''<br />
<br />
Run the following command to append the configuration line to the file /etc/modprobe.d/hid_apple.conf creating it if necessary: <br />
<br />
$ echo options hid_apple swap_opt_cmd=1 | sudo tee -a /etc/modprobe.d/hid_apple.conf<br />
Then reboot.<br />
<br />
==Swap the Fn key and Left Ctrl key==<br />
<br />
While the original hid-apple module doesn't have an option to swap the fn and left control keys, there is a patch adding this functionality to the module: [https://github.com/free5lot/hid-apple-patched hid-apple-patched].<br />
<br />
You can install this module from the AUR: {{AUR|hid-apple-patched-git}}<br />
<br />
Once the package has been installed, follow the below given instructions to swap the keys.<br />
<br />
'''Temporarily'''<br />
<br />
The following command will swap the fn and left control keys with immediate effect, but restarting your system will reset the configuration:<br />
<br />
$ echo 1 | sudo tee /sys/module/hid_apple/parameters/swap_fn_leftctrl<br />
<br />
'''Permanently'''<br />
<br />
The default configuration file {{ic|/etc/modprobe.d/hid_apple.conf}} comes with the option to swap the fn and left control keys already set, i.e., {{ic|1=swap_fn_leftctrl=1}}.<br />
<br />
{{Note|The default configuration also swaps the left option and command keys, i.e., {{ic|1=swap_opt_cmd=1}}, so you don't have to follow the previous section to do that.}} <br />
<br />
{{Note|This patch also provides an option to use ejectcd key as the missing delete key on Apple keyboard. It is enabled by default through the {{ic|1=ejectcd_as_delete=1}} option.}}</div>X33ahttps://wiki.archlinux.org/index.php?title=HiDPI&diff=456759HiDPI2016-11-14T14:12:54Z<p>X33a: /* GNOME */ use better grep syntax</p>
<hr />
<div>[[Category:Graphics]]<br />
[[ja: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 />
<br />
To enable HiDPI, 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 />
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 />
Alternatively, you can achieve any non-integer scale factor by using a combination of {{ic|scaling-factor}} and {{ic|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 {{ic|xrandr}}.<br />
<br />
{{Style|This is not a script, so comments belong to wikitext and not the code blocks.}}<br />
<br />
Here is a method to find a comfortable scale factor for your screen:<br />
<br />
First scale Gnome up to the minimum size which is too big.<br />
Usually "2" is already too big, but if "2" is still small for you, try "3", etc.<br />
gsettings set org.gnome.desktop.interface scaling-factor 2<br />
Now start scaling down by setting zoom-out factor with xrandr.<br />
First get the output name:<br />
{{hc|<nowiki>xrandr | grep -w connected | cut -d' ' -f1</nowiki>|eDP1}}<br />
<br />
Use this value to specify --output further on.<br />
If you have two or more screens you can set their scale independently.<br />
<br />
Now, to zoom-out 1.2 times, run the following:<br />
xrandr --output eDP1 --scale 1.2x1.2<br />
If the UI is still too big, increase the scale:<br />
xrandr --output eDP1 --scale 1.25x1.25<br />
If UI becomes too small, decrease the scale factor a bit.<br />
Repeat until you find a value which works best for your screen and your eyes.<br />
<br />
Finally, you need to allow the mouse to navigate the whole screen.<br />
To do this you need to get the current scaled resolution:<br />
<br />
{{hc|<nowiki>xrandr | grep eDP1</nowiki>|eDP1 connected primary 2304x1296+0+0 (normal left inverted right x axis y axis) 239mm x 134mm}}<br />
<br />
Now use the acquired resolution value to set correct panning:<br />
xrandr --output eDP1 --panning 2304x1296<br />
<br />
=== KDE ===<br />
<br />
KDE plasma 5 provides decent support for HiDPI screens.<br />
<br />
Please follow these guidelines for HiDPI support in KDE plasma 5 <br />
<br />
# System Settings → Display and Monitor → Display Configuration → Scale Display<br />
# Then drag the slider to 2<br />
# Log out and back in for all applications to take the new setting into account<br />
<br />
==== Tray icons with fixed size ====<br />
If the tray icons are not scaled with the rest of the desktop, the size can be set editing the default value for ''iconSize'' in {{ic|/usr/share/plasma/plasmoids/org.kde.plasma.private.systemtray/contents/config/main.xml}} (e.g. the value 2 may be fine):<br />
{{hc|/usr/share/plasma/plasmoids/org.kde.plasma.private.systemtray/contents/config/main.xml|<nowiki><br />
<entry name="iconSize" type="Int"><br />
<label>Default icon size for the systray icons, it's an enum which values mean, <br />
Small, SmallMedium, Medium, Large, Huge, Enormous respectively. On low <br />
DPI systems they correspond to 16, 22, 32, 48, 64, 128 pixels. On high<br />
DPI systems those values would be scaled up, depending on the DPI.</label> <br />
<default></nowiki>'''2'''<nowiki></default><br />
</entry><br />
</nowiki>}}<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 <code>xdpyinfo | grep resolution</code>, 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 />
=== Cinnamon ===<br />
<br />
Supports HiDPI since 2.2. The support is pretty good (e.g. window borders are correctly sized, which is not the case under Xfce).<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 examples 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 GNOME, 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 {{ic|~/.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, for example by creating a file {{ic|/etc/profile.d/qt-hidpi.sh}}<br />
<br />
export QT_AUTO_SCREEN_SCALE_FACTOR=1<br />
<br />
And set the executable bit on it.<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 if you manually set the screen factor, it's important to set QT_AUTO_SCREEN_SCALE_FACTOR=0 otherwise some applications which explicitly force high DPI enabling get scaled twice.<br />
<br />
QT_SCALE_FACTOR will scale fonts<br />
QT_SCREEN_SCALE_FACTORS will *not* scale fonts<br />
<br />
If you also set the font DPI manually in xrdb to support other toolkits - QT_SCALE_FACTORS will give you a huge fonts.<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 />
== Display managers ==<br />
<br />
=== SDDM ===<br />
<br />
{{Accuracy|General issue, see [[HiDPI#X_Server]]}}<br />
<br />
To scale SDDM you have to change the following properties in {{ic|/etc/sddm.conf}}.<br />
It is recommended to make a backup of your config before editing it.<br />
<br />
[XDisplay]<br />
# X server arguments<br />
ServerArguments=-nolisten tcp -dpi 144<br />
<br />
==== Alternative way using Xrandr ====<br />
<br />
If setting ServerArguments fails, it is possible to directly change the DPI setting via xrandr.<br />
Modify {{ic|/etc/sddm.conf}} and add the following section into file:<br />
<br />
[XDisplay]<br />
# script to execute when starting the display server<br />
# default to /usr/share/sddm/scripts/Xsetup<br />
DisplayCommand=/etc/sddm/Xsetup<br />
<br />
Then copy {{ic|/usr/share/sddm/scripts/Xsetup}} into {{ic|/etc/sddm/Xsetup}} with the following<br />
lines:<br />
<br />
#!/bin/sh<br />
# Xsetup - run as root before the login dialog appears<br />
/usr/bin/xrandr --dpi 144<br />
<br />
Please read {{ic|sddm.conf(5)}} for detailed configuration parameters.<br />
<br />
== Boot managers ==<br />
<br />
=== GRUB ===<br />
<br />
A possible solution is to use a big size font. Generate a GRUB font of custom size, e.g. using the font DejaVu Sans Mono and size 36:<br />
<br />
# grub-mkfont --output=/boot/grub/fonts/DejaVuSansMono36.pf2 --size=36 /usr/share/fonts/TTF/DejaVuSansMono.ttf<br />
<br />
then set GRUB to use it, adding the {{ic|1=GRUB_FONT}} line to {{ic|1=/etc/default/grub}}<br />
<br />
{{hc|1=/etc/default/grub|2=GRUB_FONT=/boot/grub/fonts/DejaVuSansMono36.pf2}}<br />
<br />
and finally update GRUB configuration with<br />
<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
== Applications ==<br />
<br />
=== Browsers ===<br />
<br />
==== Firefox ====<br />
<br />
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).<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.<br />
<br />
From Firefox version 38 onwards, your system (GTK+ 3.10) settings should be taken into account.[https://bugzilla.mozilla.org/show_bug.cgi?id=975919]<br />
<br />
==== Chromium / Google Chrome ====<br />
<br />
Full out of the box HiDPI support is available in {{Pkg|chromium}} and {{AUR|google-chrome}} as tested (with google-chrome) on Gnome and Cinnamon. Additionally, for environments where out of the box support does not work, the browser can be launched with the command line flag {{ic|--force-device-scale-factor}} and a scaling value. This will scale all content and ui, including tab and font size. For example:<br />
<br />
{{bc|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.<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 />
Since version 24 one can alter Opera's DPI by starting it with 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 />
Generally speaking, Opera's HiDPI support is excellent. Since it is also built using Chromium's blink renderer, and has an extension which runs most Chrome extensions, it is a very viable alternative to Chromium/Chrome.<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 is a Qt program, and needs to be configured separately. You cannot change the DPI setting for it, but at least you can change font size. Install {{Pkg|qt4}} and run {{ic|qtconfig-qt4}} to do it.<br />
<br />
=== Spotify ===<br />
<br />
Spotify can be launched with a custom scaling factor, 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 />
=== 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 [http://gimpforums.com/thread-increase-all-icons-on-hidpi-screen?pid=39113#pid39113 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's also the [https://github.com/jedireza/gimp-hidpi gimp-hidpi].<br />
<br />
=== VLC ===<br />
<br />
As of May 2015, the git version {{AUR|vlc-git}} seems to solve some of the problems.<br />
<br />
=== Steam ===<br />
<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 skin must be downloaded to {{ic|1=~/.local/share/Steam/skins}}, not {{ic|1=~/.steam/skins/}} as the README says.}}<br />
<br />
=== Unsupported applications ===<br />
<br />
One 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.<br />
<br />
=== Side display ===<br />
One workaround is to using [[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 />
<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 />
=== 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=1.98)<br />
<br />
xrandr --output HDMI --scale 2x1.98<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>X33ahttps://wiki.archlinux.org/index.php?title=Mac&diff=456376Mac2016-11-08T17:14:40Z<p>X33a: /* Setup bootloader */ use correct case</p>
<hr />
<div>[[Category:Apple]]<br />
[[de:ArchLinux auf einem MacBook]]<br />
[[fr:MacBook]]<br />
[[it:MacBook]]<br />
[[ja:MacBook]]<br />
[[zh-CN:MacBook]]<br />
{{Related articles start}}<br />
{{Related|Installation guide}}<br />
{{Related|General recommendations}}<br />
{{Related|MacBook4,2 (late 2008)}}<br />
{{Related|MacBook5,2 (early-mid 2009)}}<br />
{{Related|MacBookPro7,1}}<br />
{{Related|MacBookPro8,1/8,2/8,3 (2011)}}<br />
{{Related|MacBookPro9,2 (Mid-2012)}}<br />
{{Related|MacBookPro10,x}}<br />
{{Related|MacBookPro11,x}}<br />
{{Related|iMac Aluminum}}<br />
{{Related|Apple Fusion Drive}}<br />
{{Related articles end}}<br />
<br />
Installing Arch Linux on a MacBook (12"/Air/Pro) or an iMac is quite similar to installing it on any other computer. However, due to the specific hardware configuration of a Mac, there are a few deviations and special considerations which warrant a separate guide. For more background information, please see the [[Installation guide]] and [[UEFI]]. This guide contains installation-instructions that can be used on any Apple computer whose hardware is supported by the Linux kernel. Please see 'related' pages (on the top right of this page) for model-specific tips and troubleshooting.<br />
<br />
== Overview ==<br />
<br />
Specifically, the procedure for installing Arch Linux on a MacBook is:<br />
<br />
# '''[[#Firmware updates | Firmware updates]]''': It always helps to start from a clean, backed up, and up-to-date install of OS X.<br />
# '''[[#Partitions|Partition]]''': Resizing or deleting the OS X partition to create partitions for Arch Linux.<br />
# '''[[#Setup bootloader|Setup bootloader]]''': Making sure that the new partition is bootable.<br />
# '''[[#Installation|Install Arch Linux]]''': Actually installing Arch Linux.<br />
# '''[[#Post-installation|Post-installation]]''': MacBook-specific configuration.<br />
<br />
== Firmware updates ==<br />
<br />
Before proceeding with the installation of Arch Linux, it is important to ensure that the latest firmware updates for you MacBook are installed. This procedure requires OS X.<br />
In OS X, open the App Store and check for updates. If your mac finds and installs any updates, make sure to '''reboot''' your computer, and then check again for updates to make sure that you installed everything.<br />
<br />
{{Note|If you uninstalled OS X or want to reinstall it, [https://support.apple.com/en-us/HT204904 Apple] has great instructions.}}<br />
<br />
It is advisable to keep OS X installed, because MacBook firmware updates can only be installed using OS X. However, if you plan to remove OS X completely, make backups of these files, which you will need in Linux for adjusting the [[#Color Profile|color profile]]:<br />
/Library/ColorSync/Profiles/Displays/*<br />
<br />
Continue to [[#Partitions]]<br />
<br />
== Partitions ==<br />
<br />
Partitioning of the storage drive is no different from any other laptop. However, if you plan on keeping OS X for dual booting, you should consider that, by default, a MacBook's drive is formatted using GPT and contains at least 3 partitions:<br />
<br />
* '''EFI''': the ~200 MB [[EFI System Partition]].<br />
* '''OS X''': the main partition containing your OS X installation. It is formatted using [[File_systems|HFS+]].<br />
* '''Recovery''': A recovery partition present in almost all MacBooks running OS X 10.7 or newer. It is usually hidden from OS X but can be viewed with partitioning tools.<br />
<br />
{{Note|In Macs that use the [[Apple Fusion Drive]], the partition scheme could be different.}}<br />
<br />
How to partition depends on how many operating systems you want install. The following options will be explained:<br />
<br />
* Single boot: [[#Arch Linux only]]<br />
* Dual boot: [[#OS X with Arch Linux]] ''(recommended so you can still return to OS X when needed)''<br />
* Triple boot: [[#OS X, Windows XP, and Arch Linux triple boot]]<br />
<br />
<br />
=== Arch Linux only ===<br />
<br />
This situation is the easiest to deal with. Partitioning is the same as any other hardware that Arch Linux can be installed on. Please refer to the standard [[Installation_guide|Installation guide]] for details.<br />
<br />
{{Note|It is advisable to '''disable''' the MacBook startup sound before proceeding with partitioning. Just boot in OS X, mute your system sound and reboot again to the Arch Linux Installation media. Please keep in mind that the volume of the startup sound can only be modified reliably in OS X.}}<br />
<br />
If you want to configure you system in order to have full-disk encryption, please look at the [https://wiki.archlinux.org/index.php/Dm-crypt/Encrypting_an_entire_system following] page for details.<br />
<br />
An example for a very basic partitioning, that does not consider a separate {{ic|/home}} partition nor encryption or LVM, is the following:<br />
partition mountpoint size type label<br />
/dev/sda1 /boot 200MiB vfat EFI<br />
/dev/sda2 /swap adjust swap swap<br />
/dev/sda3 / remain ext4 root<br />
<br />
* Done, you can continue to [[#Installation]]<br />
<br />
<br />
=== Arch Linux with OS X or other operating systems ===<br />
<br />
You need to partition your hard drive while keeping the partitions used for OS X/Windows. If you wish to keep OS X, the easiest way is to use partitioning tools in OS X and then finish with Arch Linux tools.<br />
<br />
{{Warning| If you OS X partition is encrypted with FileVault 2, you '''must''' disable the disk encryption before proceeding. After the OS X partition has been resized, FileVault 2 can be re-enabled.}}<br />
<br />
'''Procedure''':<br />
* In OS X, run ''Disk Utility.app'' (located in {{ic|/Applications/Utilities}})<br />
* Select the drive to be partitioned in the left-hand column (not the partitions!). Click on the '''Partition''' button.<br />
* Add a new partition by pressing the '''+''' button and choose how much space you want to leave for OS X, and how much for the new partition. Keep in mind the new partition will be formatted in Arch Linux, so you can choose any partition type you want. <br />
* If the above completed successfully, then you can continue. If not, then you may need to fix your partitions from within OS X first.<br />
* Boot the Arch installation media or [[USB flash installation media|LiveUSB]] by holding down the {{ic|Alt}} '''during boot'''. Proceed with [[#Installation]].<br />
<br />
It is possible to resize the newly created partition from within the Arch installation media, or delete it in order to proceed with the creation of other partitions (eg. swap).<br />
<br />
{{Tip|Instead of cluttering your drive with different partition, it is possible to use a [[Swap#Swap file|swapfile]] instead of a dedicated partition. Another solution can be setting up [[LVM]] in order to use the newly-created partition as a container. Please refer to the linked articles.}}<br />
<br />
<br />
==== Option 1: EFI ====<br />
<br />
* Run ''cgdisk''<br />
<br />
* Delete the partition you made in ''Disk Utility.app'' and create the necessary partitions for Arch Linux. OS X likes to see a 128 MiB gap after partitions, so when you create the first partition after the last OS X-partition, type in '''+128M''' when cgdisk asks for the first sector for the partition. More information about Apple's partitioning policy can be read [https://developer.apple.com/library/mac/technotes/tn2166/_index.html#//apple_ref/doc/uid/DTS10003927-CH1-SUBSECTION5 here]. A simple example (no LVM, crypto):<br />
<br />
{{Note|<br />
* The swap partition is optional on machines with 4GB of RAM or more. A '''[[swap file]]''' can be created later.<br />
* The easiest dual-boot option is to install rEFInd from inside OS X, to its root directory (default for {{ic|install.sh}}). Following that, copy the driver folder from the installation tarball into the new rEFInd location, and uncomment the lines ''"scan_all_linux_kernels"'' and ''"also_scan_dirs"'' options in {{ic|refind.conf}}. Configuration of boot options can then be done from a {{ic|refind_linux.conf}} in Arch's {{ic|/boot}} directory.<br />
* If you want to be able to boot GRUB from the Apple boot loader, you can create a small hfs+ partition (for convenience, use OS X to format it in ''Disk Utility.app'' afterwards). Follow the GRUB EFI install procedure, and mount your {{ic|/boot/efi}} directory to the hfs+ partition you created. Finally, finish up again in OS X by blessing the partition. This will set GRUB as the default boot option (holding alt at startup goes to the mac boot options screen still. See http://mjg59.dreamwidth.org/7468.html).,<br />
* OS X's EFI partition can be shared with Arch Linux, making the creation of an additional EFI partition dedicated to Arch completely optional.<br />
}}<br />
<br />
{{Note|For more information on partitioning, see [[Partitioning]]}}<br />
partition mountpoint size type label<br />
/dev/sda1 /boot/efi 200MiB vfat EFI<br />
/dev/sda2 - ? hfs+ OS X<br />
/dev/sda3 - ? hfs+ Recovery<br />
/dev/sda4 - 100MiB hfs+ Boot Arch Linux from the Apple boot loader (optional)<br />
/dev/sda5 /boot 100MiB boot boot<br />
/dev/sda6 - ? swap swap (optional)<br />
/dev/sda7 / 10GiB ext4 root<br />
/dev/sda8 /home remaining ext4 home<br />
<br />
* Done, you can continue to [[#Installation]]<br />
<br />
==== Option 2: BIOS-compatibility ====<br />
<br />
* Run ''parted'' as root.<br />
<br />
* Delete the empty space partition and partition the space as you would for any other installation. Note that MBR is limited to 4 primary partitions (including the efi partition). That leaves 2 primary partitions for Arch. One strategy is to have a system and home partition, and use a swap file (I have not tried to use logical partitions). Another is to dedicate one partition to a shared partition (see below).<br />
<br />
* Next, create new filesystems on those partitions which need them, especially the partition which will contain {{ic|/boot}}. If you are not sure how to do this using {{ic|mkfs.ext2}} (or whatever), run {{ic|/arch/setup}} and work through until you get to Prepare Hard Drive and use the ''"Manually configure block devices..."'' option, then exit the installer. This is necessary so that rEFIt will set the right partition type in the MBR in the next step (without an existing filesystem, it seems to ignore the partition type set by parted), without which GRUB will refuse to install to the right partition.<br />
<br />
* At this point you should reboot your computer and have rEFIt fix the partition tables on your hard drive. (If you do not do this, you may have to reinstall GRUB later on in order to have your Mac recognize the Linux partition.) When you are into the rEFIt menu, select '''update partition table''', then press {{ic|y}}. Reboot.<br />
<br />
* Done, you can continue with [[#Installation]].<br />
<br />
=== OS X, Windows XP, and Arch Linux triple boot ===<br />
<br />
This may not work for everyone but it has been successfully tested on a MacBook from late 2009.<br />
<br />
The easiest way to partition your hard drive, so that all these operating systems can co-exist, is to use disk utility in OS X, use the formatter on windows XP, install XP and then finish with Arch Linux tools.<br />
<br />
{{Warning|It is highly recommended that this only be attempted after a clean install of OS X. Using these methods on a pre-existing system may have undesired results. At least back your stuff up with timemachine or clonezilla before you begin.}}<br />
<br />
'''Procedure''':<br />
* In OS X, run '''Disk Utility''' (located in {{ic|/Applications/Utilities}}).<br />
<br />
* Select the drive to be partitioned in the left-hand column (not the partitions!). Click on the '''partition''' tab on the right.<br />
<br />
* Select the volume to be resized in the '''volume scheme.'''<br />
<br />
* Decide how much space you wish to have for your OS X partition, how much for XP, and how much for Arch Linux. Remember that a typical installation of OS X requires around 15-20 GiB, and XP about the same, depending on the number of software applications and files. Something like OS X 200Gb, XP 25Gb, Arch 25Gb should be fine.<br />
<br />
* Put your decisions into action by pressing the + button and adding the new partitions, Label them as you like and make sure that your XP partition is the last one on the disk and is formatted for FAT32. It is probably best to have Arch formatted in HFS format as to not confuse you later, it will be reformatted anyway.<br />
<br />
So in linux terms your partitions will be something like:<br />
<br />
:*sda (disk)<br />
:*sda1 (Mac boot partition - you cannot see this one in OS X)<br />
:*sda2 (OS X install in HFS+)<br />
:*sda3 (Arch install temporarly in HFS)<br />
:*sda4 (XP install in FAT32)<br />
<br />
* Finally, click '''apply'''. This will create a new partition out of the empty space.<br />
<br />
{{Note|Using this method you may not be able to have a shared partition between OS X and Arch Linux, this is because the mac will only allow for 4 active partitions. You will however be able to mount a HFS partition in Arch for one workaround. There are other workarounds possible also.}}<br />
<br />
* If the above completed successfully, you can continue. If not, then you may need to fix your partitions from within OS X first.<br />
<br />
* You will not be needing boot camp this way, the program rEFIt is much more flexible (though not as flexible as GRUB). Download and install rEFIt [http://refit.sourceforge.net/]<br />
<br />
* Go into a terminal in OS X and perform the following, this will enable the rEFIt boot manager. <br />
<br />
cd /efi/refit<br />
./enable.sh<br />
<br />
* Reboot to check the rEFIt is working, it should appear on boot. When it comes up go to the rEFIt partition manager and agree to the changes.<br />
<br />
* Put your XP install CD and boot it with rEFIt - You may have to reboot a few times until it is recognized by the boot loader. Install XP and once it is installed use the OS X installation CD to get your drivers running nicely in XP.<br />
** Note: when installing XP make sure you select your XP partition and format it again inside the XP installer. If you do not reformat it will not work.<br />
<br />
* Boot the Arch install CD, log in as root and run {{ic|# /arch/setup}}.<br />
<br />
* Follow the install as normal but note that you will have to tell that arch installer to mount sda3 as the root partition and format it as ext3, there will not be a /boot or swap partition so ignore those warnings.<br />
<br />
* At this point, if you are dual booting, you should reboot your computer and have rEFIt fix the partition tables on your hard drive. (If you do not do this, you may have to reinstall GRUB later on in order to have your Mac recognize the Linux partition.) When you are into the rEFIt menu, select '''update partition table''', then press Y.<br />
# reboot<br />
<br />
* Done! You can continue to [[#Installation]] but make sure you read [[#Booting directly from GRUB]]{{Broken section link}} for the stage "* (for booting with EFI) After the install boot loader stage, exit the installer and install GRUB."<br />
<br />
== Setup bootloader ==<br />
<br />
=== Using the native Apple bootloader with systemd-boot (Recommended) ===<br />
<br />
Apple's native EFI bootloader reads {{ic|.efi}} files located inside the [[EFI System Partition]] at {{ic|/EFI/BOOT/BOOTX64.EFI}}. Luckly, this is also the default install location the [[systemd-boot]] binary. This means that booting linux using ''systemd-boot'' is very simple.<br />
* First, make sure you mounted the EFI System Partition at {{ic|/boot}}<br />
* Proceed with [[#Installation]] normally<br />
* Once inside the chrooted enviroment, type the following command to install ''systemd-boot'':<br />
{{bc|1=# bootctl --path=/boot install}}<br />
The above command will copy the ''systemd-boot'' binary to {{ic|/boot/EFI/BOOT/BOOTX64.EFI}} and add ''systemd-boot'' itself as the default EFI application (default boot entry) loaded by the EFI Boot Manager. <br />
* Proceed to [[systemd-boot#Configuration]] in order to correctly set up the bootloader<br />
At the next reboot, the Apple Boot Manager, shown when holding down the option key when booting the MacBook, should display Arch Linux (it will be displayed as {{ic|EFI Boot}} as a possible boot option.<br />
{{Tip|If you installed Arch Linux alongside OS X, you will be able to change the default boot location from system Settings inside OS X. If Arch Linux does not show up as a possible boot option, you will have to mount the EFI System Partition inside OS X before selecting your boot option:<br />
{{bc|$ diskutil mount disk0s1}}<br />
}}<br />
<br />
=== Using the native Apple bootloader with GRUB ===<br />
<br />
Despite using UEFI, the MacBook's native EFI bootloader [http://refit.sourceforge.net/myths/ does not use the EFI partition for booting]. Instead, it looks for .efi files inside all the partitions in internal and external drives and shows them as possible boot options if certain conditions are satisfied. For example, MacBooks can detect an existing OSX installation after checking that:<br />
* there is a partition formatted as HFS+<br />
* the partition contains the partition id {{ic|af00}} <br />
* in the root of that partition, there is a file called {{ic|mach_kernel}}<br />
* inside that partition, there a {{ic|boot.efi}} file inside {{ic|/System/Library/CoreServices}}<br />
<br />
This means that configuring an Arch installation to be automatically recognized by the MacBook bootloader is possible. Moreover, it simply requires a properly-formatted HFS+ {{ic|/boot}} partition and does not require meddling with the EFI system partition. The advantage of this method is that it can coexist with OS X nicely and allows to avoid other bootloaders such as rEFInd. However, this requires manual configuration. The following steps will illustrate how to perform this configuration using GRUB.<br />
* First, while configuring a new Arch installation, create a separate {{ic|/boot}} partition. Many tools are available in the Arch ISO, for example '''cgdisk'''.<br />
* Make sure the partition is at least ~250 MB in size, since it will be used to store the kernel as well as any custom kernel you will install in the future. Moreover, make sure the partition type is set as Apple HFS/HFS+ (it will appear as {{ic|Apple HFS/HFS+}} in fdisk/cgdisk or {{ic|af00}} in gdisk)<br />
* Since the Arch installation ISO does not include the package {{Pkg|hfsprogs}}, we need to install it in the installation environment before proceeding with formatting the new partition as HFS+<br />
# pacman -Sy hfsprogs<br />
# modprobe hfsplus<br />
# mkfs.hfsplus /dev/sd'''X''' -v "Arch Linux"<br />
<br />
Note: replace /dev/sd'''X''' with the correct device as appropriate<br />
<br />
* Done, proceed with [[#Installation]]<br />
<br />
{{Warning|<br />
Once inside the chrooted enviroment, don’t forget to install {{Pkg|hfsprogs}} on the newly installed system as well. After the installation of the package, regenerate the initramfs while chrooted<br />
# mkinitcpio -p linux<br />
}}<br />
<br />
* Once inside the chrooted enviroment, install the {{Pkg|grub}} and {{Pkg|efibootmgr}} packages. The following steps install the GRUB UEFI application to {{ic|/boot/EFI/arch/System/Library/CoreServices/boot.efi}} and install its modules to {{ic|/boot/grub/x86_64-efi}}.<br />
# grub-install --target=x86_64-efi --efi-directory=/boot<br />
<br />
After that, remember to create a standard configuration file:<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
As you can see, the directory structure of the {{ic|boot.efi}} is not correct, as the {{ic|/System/Library/CoreServices}} directory is not supposed to be a subdirectory of the {{ic|/boot/EFI/}} folder. For this reason, we need to relocate the {{ic|boot.efi}} stub in a location the MacBook bootloader is able to recognize:<br />
# mv /boot/EFI/arch/System/ /boot/<br />
# rm -r /boot/EFI/<br />
<br />
Also, create a dummy {{ic|mach_kernel}} file<br />
# touch /boot/mach_kernel<br />
<br />
After that, you need to create the following file <br />
<br />
{{hc|1=# nano /boot/System/Library/CoreServices/SystemVersion.plist|2=<br />
<?xml version="1.0" encoding="UTF-8"?><br />
<plist version="1.0"><br />
<dict><br />
<key>ProductBuildVersion</key><br />
<string></string><br />
<key>ProductName</key><br />
<string>Linux</string><br />
<key>ProductVersion</key><br />
<string>Arch Linux</string><br />
</dict><br />
</plist><br />
}}<br />
<br />
At the next reboot, the Apple Boot Manager, shown when holding down the option key when booting the MacBook, should display Arch Linux as a possible boot option. Selecting that option will boot GRUB.<br />
<br />
Done! GRUB can now be selected on the standard MacBook bootloader and you can boot into your newly installed Arch Linux.<br />
<br />
{{Tip| After the installation, it is optionally possible to set a custom icon that will be displayed in the MacBook boot loader. In order to do that, you need to install the {{Pkg|wget}}, {{Pkg|librsvg}} and {{AUR|libicns}} packages. After that, just follow the following commands:<br />
$ wget -O /tmp/archlinux.svg https://www.archlinux.org/logos/archlinux-icon-crystal-64.svg<br />
$ rsvg-convert -w 128 -h 128 -o /tmp/archlogo.png /tmp/archlinux.svg<br />
$ sudo png2icns /boot/.VolumeIcon.icns /tmp/archlogo.png<br />
$ rm /tmp/archlogo.png<br />
$ rm /tmp/archlinux.svg<br />
Obviously, you can replace the Arch logo with any other icon you like.<br />
}}<br />
<br />
<br />
=== Other methods ===<br />
<br />
{{Out of date | Section that describes bootloader setup for other setups should be revised and re-structured into more readable way}}<br />
{{Tip|rEFIt is a popular bootloader for EFI-firmware computers (including Macs). It can be installed at any time during the installation. For instructions, please see [[#rEFIt]]. }}<br />
<br />
If you are going for an Arch Linux-only setup, installing the bootloader is no different than on any other machine: Install [[systemd-boot]], [[rEFInd]] or other bootloader of your choice.<br />
<br />
If, on the other hand, you are dual/triple booting, then read on.<br />
<br />
<br />
=== Installing GRUB to EFI partition directly ===<br />
<br />
* If you would like to use GRUB as your main bootloader and use the "boot while holding the Alt/Option key" method to go back to OS X rather than using alternatives such as rEFIt (http://refit.sourceforge.net/, mentioned previously in [[#BIOS-compatibility]]{{Broken section link}} and [[#OS X, Windows XP, and Arch Linux triple boot]]) then you must install {{Pkg|grub}} to your Mac's '''already-existing''' EFI partition (see below). <br />
<br />
{{Note| These instructions are known to work on a MacBook Pro (Early 2011). Please read the procedure carefully '''as well as the details following it'''.}}<br />
<br />
{{Note| With a new MacBook Pro (Mid 2014), this procedure worked only after installing the<br />
{{Pkg|efibootmgr}} package.}}<br />
<br />
'''Procedure''':<br />
<br />
* Install {{Pkg|grub}}<br />
<br />
* Make a directory named {{ic|efi}} in {{ic|/boot}} <br />
<br />
* Mount the '''already-existing''' EFI partition on your Mac to this {{ic|/boot/efi}} directory<br />
<br />
* Install GRUB to this directory<br />
<br />
* Make a directory named {{ic| locale}} in {{ic| /boot/grub}}<br />
<br />
* Copy {{ic| grub.mo}} from {{ic| /usr/share/locale/en\@quot/LC_MESSAGES/}} to {{ic| /boot/grub/locale}} <br />
<br />
* Generate a configuration for GRUB<br />
<br />
* Done! GRUB will now start on reboot and you can boot into your newly installed Arch Linux.<br />
<br />
* Remember to hold ALT/Option key '''while''' starting your computer if you want to boot back into OS X.<br />
<br />
'''Details (quoted from [[GRUB EFI Examples#M5A97]]):'''<br />
<br />
Finish the standard Arch install procedures, making sure that you install {{Pkg|grub}} and partition your boot hard disk as GPT.<br />
<br />
From [[GRUB#Install_to_UEFI_system_partition]]{{Broken section link}}:<br />
<br />
The UEFI system partition will need to be mounted at {{ic|/boot/efi/}} for the GRUB install script to detect it:<br />
<br />
# mkdir -p /boot/efi<br />
# mount -t vfat /dev/sdXY /boot/efi<br />
<br />
Where X is your boot hard disk and Y is the efi partition you created earlier.<br />
<br />
Install GRUB UEFI application to and its modules to {{ic|/boot/grub/x86_64-efi}} using:<br />
<br />
# modprobe dm-mod<br />
# grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=arch_grub --recheck --debug<br />
# mkdir -p /boot/grub/locale<br />
# cp /usr/share/locale/en\@quot/LC_MESSAGES/grub.mo /boot/grub/locale/en.mo<br />
<br />
Generate a configuration for GRUB<br />
<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
=== Using blessing ===<br />
<br />
It is possible to boot directly from GRUB in EFI mode without using rEFIt through what is known as "blessing" after placing GRUB on a '''separate partition'''. These instructions are known to work on a MacBook7,1. It is advisable to host GRUB on either a FAT32 or HFS+ partition, but ext2 or ext3 may also work. GRUB's appleloader command does not currently work with the 7,1, but support can be added with the patch available [https://savannah.gnu.org/bugs/index.php?33185 here].<br />
<br />
After the GRUB install is in the desired location, the firmware needs to be instructed to boot from that location. This can be done from either an existing OS X install or an OS X install disk. The following command assumes that the GRUB install is in {{ic|/efi/grub}} on an existing OS X partition:<br />
# bless --folder /efi/grub --file /efi/grub/grub.efi<br />
<br />
=== Compilation ===<br />
<br />
Some models may need EFI_ARCH set to i386.<br />
bzr branch --revision -2 bzr://bzr.savannah.gnu.org/grub/trunk/grub grub<br />
cd grub<br />
./autogen.sh<br />
patch -p1 < appleloader_macbook_7_1.patch<br />
export EFI_ARCH=x86_64<br />
./configure --with-platform=efi --target=${EFI_ARCH} --program-prefix=""<br />
make<br />
cd grub-core<br />
../grub-mkimage -O ${EFI_ARCH}-efi -d . -o grub.efi -p "" part_gpt part_msdos ntfs ntfscomp hfsplus fat ext2 normal chain boot configfile linux multiboot<br />
cp grub.efi *.mod *.lst yourinstalllocation<br />
<br />
== Installation ==<br />
<br />
{{Note|This section is only required if you want to have OS X installed along with Arch Linux. If not, follow the steps in the official install guide, then skip to [[#Post-installation]].}}<br />
<br />
* Boot from the Arch Linux install CD, from the latest [[Archboot]] iso (unofficial), or from a [[USB flash installation media#Using manual formatting|manually created]] bootable USB drive.<br />
{{Note|<br />
* On a MacBookPro7,1, I had an error booting the installation media Version 2012.12.01: "unable to handle kernel NULL pointer dereference at 0000000000000010" during pacpi_set_dmamode. To fix this problem, boot with the option: acpi&#61;off. After chrooting, add MODULES&#61;"ata_generic" into /etc/mkinitcpio.conf and execute mkinitcpio -p linux, see: [[Installation guide#Configure_the_system|Installation Guide, 9 Configure the system]].<br />
* Some MacBook users report strange keyboard output such as long delays and character doubling. To fix this problem, boot with the following options: arch noapic irqpoll acpi&#61;force}}<br />
<br />
* Proceed through the installation as described in the [[Installation guide]] '''except''' in the following areas:<br />
** Skip the [[Installation guide#Partition the disks|partition the disks]] stage, do only the [[Installation guide#Format the partitions|partition formatting]] and [[Installation guide#Mount the partitions|mounting]] steps, taking care to assign the correct partitions. Partitions have already been created if you followed [[#Partitions]]<br />
** '''(for booting with EFI''') After the [[Installation guide#Boot_loader|install boot loader]] stage, exit the installer and install [[GRUB]].<br />
** '''(for booting with BIOS-compatibility)''' In the [[Installation guide#Boot_loader|install boot loader]] stage, edit the menu.lst file and add '''reboot=pci''' to the end of the '''kernel''' lines, for example: {{bc|1=kernel /vmlinuz26 root=/dev/sda5 ro reboot=pci}} This will allow your MacBook to reboot correctly from Arch.<br />
** '''(for booting with BIOS-compatibility)''' Also in the [[Installation guide#Install a boot loader|install boot loader]]{{Broken section link}} stage, install GRUB on whatever partition that {{ic|/boot}} is on. {{Warning|Do not install GRUB onto ''/dev/sda'' !!! Doing so is likely to lead to an unstable post-environment.}}<br />
** In the [[Installation guide#Configure the system|configure system]] stage, edit /etc/mkinitcpio.conf and ensure the '''keyboard''' hook is in the '''HOOKS''' line somewhere after the '''autodetect''' hook. This will load the drivers for your keyboard in case you need to use it before Arch boots (e.g. entering a [[LUKS]] password or using the troubleshooting shell).<br />
<br />
* When the install process is complete, reboot your computer.<br />
<br />
* If using optical media, hold down the eject key as your MacBook starts, this should eject the Arch Linux install disk.<br />
<br />
* If dual-booting OS X and Arch Linux, hold down the alt (option) key while the system boots to use the Mac bootloader to select which OS to boot.<br />
<br />
== Post-installation ==<br />
<br />
{{Style|Duplicated information, does not comply with [[Help:Style]].}}<br />
<br />
See [[General recommendations]] for system management directions and post-installation tutorials like setting up a graphical user interface, sound or a touchpad.<br />
<br />
==== Video ====<br />
<br />
Different MacBook models have different graphic cards.<br />
To see which graphics card you have type:<br />
<br />
$ lspci | grep VGA<br />
<br />
* If it returns a string containing '''intel''', read [[Intel graphics]].<br />
<br />
* If it returns '''nVidia''', read [[NVIDIA]].<br />
<br />
* Otherwise if it returns '''ATI''' or '''AMD''', read [[ATI]].<br />
<br />
===== NVIDIA note =====<br />
<br />
{{Tip|If you have installed OS in EFI mode and NVIDIA binary drivers are working only in BIOS mode (e.g. you get black screen on EFI boot), try this approach: http://askubuntu.com/a/613573/492886 }}<br />
<br />
For MacBooks with NVIDIA graphics, for the backlight to work properly you may need the {{AUR|nvidia-bl}} package.<br />
<br />
{{Tip|<br />
* If backlight control does not work after installing nvidia-bl, you should [[blacklist]] apple_bl kernel module.<br />
* If backlight control does not work even this way, try setting module parameters, e.g. {{ic|1=options nvidiabl screen_type=3 min=0 max=44000}} in {{ic|/etc/modprobe.conf}} in case of MacBook Air 3.2<br />
* Alternatively, you can choose to use the {{AUR|pommed-light}} package. If you do so, you may wish to change the step settings in {{ic|/etc/pommed.conf.mactel}} to something around 5000-10000 depending on how many levels of brightness you desire. The max brightness is around 80000, so take that into account.}}<br />
<br />
==== Touchpad ====<br />
<br />
The touchpad should have basic functionality by default. A true multitouch driver which behaves very similarly to native OS X is included in the {{AUR|xf86-input-multitouch-git}}{{Broken package link|{{aur-mirror|xf86-input-multitouch-git}}}} package. It supports 1, 2 and 3 finger gestures, including differentiation between horizontal and vertical 3 finger swipe. Additional details are available at [http://bitmath.org/code/multitouch/ the driver's project page].<br />
<br />
xf86-input-multitouch-git does not support any sort of configuration without editing the driver's source. Some users are also experiencing issues with false clicks from palm touches. There is now a much more configurable fork available as {{AUR|xf86-input-mtrack-git}}. Configuration options are documented in the [https://github.com/BlueDragonX/xf86-input-mtrack readme].<br />
<br />
The following mtrack options work well on a MacBook7,1:<br />
<br />
Option "Thumbsize" "50"<br />
Option "ScrollDistance" "100"<br />
<br />
Probably you need also to add:<br />
<br />
MatchDevicePath "/dev/input/event10"<br />
<br />
To disable tap-to-click (that is, to press down to click) by default, add the following to your mtrack configuration section<br />
<br />
Option "TapButton1" "0" <br />
Option "TapButton2" "0"<br />
Option "TapButton3" "0"<br />
<br />
'''Natural scrolling:''' To configure natural two finger scrolling similar to [http://www.apple.com/au/osx/what-is/gestures.html#gallery-gestures-scroll OS X], refer to [[Touchpad Synaptics#Natural scrolling]]. If you are using GNOME, it will override these settings - in this case refer to [[GNOME#Natural_scrolling_touchpad]]{{Broken section link}}.<br />
<br />
If you are using {{AUR|xf86-input-mtrack-git}}, you can simply swap the scroll up and scroll down buttons (along with the scroll left and scroll right):<br />
{{hc|/etc/X11/xorg.conf.d/10-mtrack.conf|<br />
...<br />
Option "ScrollUpButton" "5"<br />
Option "ScrollDownButton" "4"<br />
Option "ScrollLeftButton" "7"<br />
Option "ScrollRightButton" "6"<br />
...}}<br />
<br />
<br />
'''Special Note About Older Macbook Models (confirmed on MacBook2,1):''' On older Macbook models (pre-multitouch), the touchpad will not function properly until you install the xf86-input-synaptics package. Please see [[Touchpad Synaptics]] for more information on installing and configuring this package.<br />
<br />
'''Note on MacBookPro5,5:''' I found it is much simpler to use the {{Pkg|xf86-input-synaptics}} in Extra. Although it does not have much function as 3 finger swipe, this driver provides faster response. {{Pkg|gpointing-device-settings}} also provides a simple GUI config. Below is a Xorg config file /etc/X11/xorg.conf.d/60-synaptics.conf for reference only.<br />
Section "InputClass"<br />
Identifier "touchpad catchall"<br />
Driver "synaptics"<br />
MatchIsTouchpad "on"<br />
MatchDevicePath "/dev/input/event*"<br />
Option "SHMConfig" "on"<br />
Option "TapButton1" "1"<br />
Option "TapButton2" "3"<br />
Option "TapButton3" "2"<br />
Option "PalmDetect" "on"<br />
Option "VertEdgeScroll" "off"<br />
Option "HorizEdgeScroll" "off"<br />
Option "CornerCoasting" "off"<br />
Option "EdgeMotionUseAlways" "off"<br />
Option "AreaLeftEdge" "10"<br />
Option "AreaRightEdge" "1270"<br />
EndSection<br />
'''For some users, the two-finger right-click may not work correctly and trackpad may also become less responsive after these settings. For me, removing the 'AreaLeftEdge' and 'AreaRightEdge', solved that problem.'''<br />
'''OS X like MultiTouch Gestures''' ''currently broken due to newer synaptic drivers!'' For users looking to add more of OS X's multitouch gestures to Arch, [https://github.com/iberianpig/xSwipe xSwipe] is a highly customisable, light weight perl script, which does just that. Once installed and configured (see xSwipe wiki on Github) I would recommend adding xSwipe as a [[Autostarting|start up item]].<br />
<br />
==== Keyboard ====<br />
<br />
MacBook keyboards work by default. For swaping fn keys with Fx keys see [[Apple Keyboard]].<br />
<br />
To enable it you can map with right application like '''xbindkeys''' or through DE preferences; but another very good way, that we recommend, is to install the {{AUR|pommed}}{{Broken package link|{{aur-mirror|pommed}}}} package.<br />
<br />
Edit the {{ic|/etc/pommed.conf}} according to your hardware on MacBook, building it from {{ic|/etc/pommed.conf.mac}} or {{ic|/etc/pommed.conf.ppc}} example files.<br />
<br />
Note that you can also run it without a configuration file, the defaults may work for you. Then [[enable]] and start {{ic|pommed.service}}.<br />
<br />
{{Tip|if you are using Gnome or KDE you can easily configure ''3rd level functionality'', ''multimedia key'', etc. in Keyboard Preferences.}}<br />
<br />
{{Note|See the [[Xorg input hotplugging]] page for other configuration information.}}<br />
<br />
===== Keyboard Backlight =====<br />
<br />
The keyboard backlight is controlled by {{ic|/sys/class/leds/smc::kbd_backlight}}. Write the desired value to {{ic|brightness}} in that directory.<br />
<br />
You may also use {{AUR|kbdlight}} to control keyboard backlight though scripts or by running it via [[sxhkd]]. It has the advantage of allowing keyboard light-level changes without being root.<br />
<br />
====== NVIDIA note ======<br />
<br />
If the brightness does not function correctly through pommed, make sure you have installed the {{AUR|nvidia-bl}} package and insert<br />
<br />
find . -name "*" -exec sed -i 's/mbp_backlight/nvidia_backlight/' '{}' \;<br />
<br />
into the second line of the pommed PKGBUILD build() function and remake the package. From [https://bbs.archlinux.org/viewtopic.php?id=105091 this forum post].<br />
<br />
Another possible solution is to modify the pommed PKGBUILD build():<br />
<br />
find . -name "*" -exec sed -i 's/nvidia_backlight/apple_backlight/' '{}' \;<br />
<br />
If the previous does not work try the following,<br />
<br />
run nvidia-settings, edit the file '/etc/X11/xorg.conf' and add this line into the Device section:<br />
<br />
Option "RegistryDwords" "EnableBrightnessControl=1"<br />
Save and reboot and check backlight buttons work.<br />
More information available at [https://help.ubuntu.com/community/MacBookPro5-5/Precise#LCD Ubuntu MacBookPro5,5]<br />
<br />
=== Wi-Fi ===<br />
<br />
Different MacBook models have different wireless cards.<br />
<br />
You can easily check what card do your MacBook have by:<br />
<br />
# lspci | grep Network<br />
<br />
* If you have an Atheros card, all should work out-of-the-box.<br />
<br />
* If you have a Broadcom card, follow the [[Broadcom BCM4312]] page.<br />
<br />
* 5.0 and 6.0 generation MacBooks may have a BCM43xx, follow the instructions for the broadcom-wl driver on the [[Broadcom wireless]] page. The interfaces can swap during reboot so its best to define them in a udev rule (instructions on the [[Broadcom wireless]] page).<br />
<br />
* 8.1 generation MacBooks have BCM4331, for which support is not present in either Linux (3.0 and 3.1) or the proprietary drivers by Broadcom. There is however preliminary support for it in Linux 3.2. To run the drivers on earlier kernels, you will need to use [https://backports.wiki.kernel.org/index.php/Documentation/compat-drivers compat-drivers]<br />
<br />
{{Note|If your connection frequently drops, you may have to turn off Wi-Fi power management. If you are running [[pm-utils]], you may override wireless power management by creating an executable file {{ic|/etc/pm/wireless}} with the lines:<br />
#!/bin/sh<br />
iwconfig wlp2s0 power off<br />
}}<br />
<br />
=== Power management ===<br />
<br />
[[Powerdown]] is a very simple to set up set of scripts what will maximize your battery duration. A MacBook Air 2013 with powerdown provides about 11 hours of light usage with just powerdown installed.<br />
All the usual [[power management]] recomendations apply as well.<br />
<br />
Adding 'acpi_osi=' to kernel parameters reportedly (as well as for me) brings the battery life of a Mac book Air 2013 from 5 hours to 11-12 hours. See [https://bbs.archlinux.org/viewtopic.php?pid=1530283#p1530283 this forum post] for more information.<br />
<br />
==== Suspend and Hibernate ====<br />
<br />
Suspending (suspend to ram) and hibernating (suspend to disk) work fine out of the box:<br />
<br />
systemctl suspend<br />
<br />
Issues were reported where the machine would "suspend immediately after resume" in certain conditions when suspending by closing the lid. This was solved by de-selecting the option "event_when_closed_battery" in gconf-editor &rarr; gnome-power-manager &rarr; actions).<br />
<br />
See [[Suspend and hibernate]] for details on how to configure hibernation. Noticably, you'll need a swap partition or file (see the mentioned article for further instructions).<br />
<br />
If after suspend laptop is woken up after few seconds, may help to disable all stuff in /proc/acpi/wakeup, exclude LID0:<br />
# echo XHC1 > /proc/acpi/wakeup<br />
$ cat /proc/acpi/wakeup<br />
Device S-state Status Sysfs node<br />
P0P2 S3 *disabled<br />
EC S3 *disabled<br />
HDEF S3 *disabled pci:0000:00:1b.0<br />
RP01 S3 *disabled pci:0000:00:1c.0<br />
RP02 S3 *disabled pci:0000:00:1c.1<br />
RP03 S3 *disabled pci:0000:00:1c.2<br />
ARPT S4 *disabled pci:0000:03:00.0<br />
RP05 S3 *disabled pci:0000:00:1c.4<br />
RP06 S3 *disabled pci:0000:00:1c.5<br />
SPIT S3 *disabled<br />
XHC1 S3 *disabled pci:0000:00:14.0<br />
ADP1 S3 *disabled<br />
LID0 S3 *enabled<br />
And for permanent disabling:<br />
$ cat /etc/udev/rules.d/90-xhc_sleep.rules <br />
<br />
# disable wake from S3 on XHC1<br />
SUBSYSTEM=="pci", KERNEL=="0000:00:14.0", ATTR{power/wakeup}="disabled"<br />
<br />
If this does not work, check that ARPT is disabled, and add a corresponding rule to udev, like this:<br />
<br />
SUBSYSTEM=="pci", KERNEL=="0000:03:00.0", ATTR{power/wakeup}="disabled"<br />
<br />
If this still does not work, try disabling LID0.<br />
This way suspending via lid-closing should be made impossible, so you might want to follow the instructions in [https://bbs.archlinux.org/viewtopic.php?pid=1556046#p1556046 this forum post] to make suspending via both lid-closing and systemd possible, by using systemd services.<br />
<br />
=== Light sensor ===<br />
<br />
The values can be read from:<br />
<br />
/sys/devices/platform/applesmc.768/light<br />
<br />
A "cat" on this path returns two-tuples like (4,0). The below referenced lighter script ignores the second value - which always seems to be 0 - and uses the first number as measured environment lighting brightness value.<br />
<br />
If you want to use the built in light sensor to automatically adjust screen and keyboard backlight brightness check out<br />
'''Lighter''' [https://github.com/Janhouse/lighter] (simple perl script, easy to fine-tune) and '''Lightum''' [https://github.com/poliva/lightum] (Requires Gnome or KDE but is older and more complete than Lighter).<br />
<br />
=== Sound ===<br />
<br />
{{Tip| If using [[ALSA]], the internal speaker might not be disabled when using the headphone jack. To solve this, enable "Auto-mute" using {{ic|alsamixer}}}}<br />
<br />
First of all follow [[ALSA]] wiki page, then if something does not work correctly, continue reading this part.<br />
<br />
Edit your {{ic|/etc/modprobe.d/50-sound.conf}} or {{ic|/etc/modprobe.d/modprobe.conf}} appending this line:<br />
<br />
options snd_hda_intel model=intel-mac-auto<br />
<br />
This should automatically specify the codec in your MacBook. If you have a MacBookPro12,1, you might need<br />
<br />
options snd-hda-intel index=1,0<br />
<br />
instead. Alternatively, for MacBookPro5,X, you can use:<br />
<br />
options snd_hda_intel model=mb5<br />
<br />
(note that the jack output is controlled with "HP").<br />
<br />
If you have an iMac8,1, you should instead use<br />
<br />
options snd-hda-intel model=mbp3 position_fix=2<br />
<br />
You can try to specify other options, that depend on your hardware. All other possible settings are listed in Kernel Documentation, avaible online:<br />
<br />
* [http://www.kernel.org/doc/Documentation/sound/alsa/ALSA-Configuration.txt ALSA-Configuration.txt]<br />
* [http://www.kernel.org/doc/Documentation/sound/alsa/HD-Audio.txt HD-Audio.txt]<br />
* [http://www.kernel.org/doc/Documentation/sound/alsa/HD-Audio-Models.txt HD-Audio-Models.txt].}}<br />
<br />
Then, reboot.<br />
<br />
=== Bluetooth ===<br />
<br />
Bluetooth should work out-of-the box. See the article on [[Bluetooth]] to install and configure all software needed.<br />
<br />
=== Webcam ===<br />
<br />
==== iSight ====<br />
<br />
{{Note|Linux kernel from 2.6.26 includes the Linux UVC driver natively. '''MBP 6,2+ (Kernel ~2.6.37+) iSight works out of the box''' without the need to use firmware from OS X. Only use {{ic|isight-firmware-tools}} if it doesn't work normally.}}<br />
<br />
iSight webcams on MacBooks or pre 6,2 MacBook Pros (6,2 came out around 2010) require the Apple's proprietary firmware that cannot be redistributed. It must be extracted from OS X and loaded onto Arch.<br />
<br />
You will need to install {{AUR|isight-firmware-tools}} to extract the firmware. This package also includes a udev rule and ELF binary that are necessary, even once you have extracted the firmware file into {{ic|/lib/firmware/isight.fw}}, for the file to be loaded every time you boot your computer (namely {{ic|/etc/udev/rules.d/isight.rules}} which uses {{ic|/usr/lib/udev/ift-load}}).<br />
<br />
Instructions:<br />
<br />
First you need to get the firmware out of a particular file located on your OS X install. It is located in {{ic|/System/Library/Extensions/IOUSBFamily.kext/Contents/PlugIns/AppleUSBVideoSupport.kext/Contents/MacOS/AppleUSBVideoSupport}}.<br />
<br />
{{ Tip | The {{ic|AppleUSBVideoSupport}} file from a OS X 10.6 (Snow Leopard) installation may not work properly. If possible, use the file from OS X 10.5 or earlier.}}<br />
<br />
To mount the OS X drive if multi-booting:<br />
<br />
# sudo mkdir /media/OSX<br />
# sudo mount -t hfsplus /dev/sda2 /media/OSX<br />
<br />
Then, install the {{AUR|isight-firmware-tools}} package.<br />
<br />
Locate the {{ic|AppleUSBVideoSupport}} file in the OS X directory listed above. Either copy it over to your Arch system (Any OS X installation should do, such as an iMac, not just one specific to your system) or, if multi-booting, mount the OS X drive and navigate to the directory. (On 10.7 (Lion) the directory is {{ic|/System/Library/Extensions/IOUSBFamily.kext/Contents/PlugIns/AppleUSBVideoSupport.kext/Contents/MacOS}}.) In that directory you can go ahead and extract the driver:<br />
<br />
# ift-extract --apple-driver AppleUSBVideoSupport<br />
<br />
When it's done, check that the firmware has been found:<br />
<br />
# ls /lib/firmware/isight.fw<br />
<br />
Once successful, completely '''SHUTDOWN''' your Mac and start it back up again (to clear the hardware state of the webcam). Do ''not'' reboot.<br />
<br />
It should be automatically loaded at boot; if it isn't you can load the '''uvcvideo''' module [[Kernel modules|manually or load it at boot]].<br />
<br />
You can use many applications to test the webcam:<br />
<br />
* MPlayer<br />
<br />
# mplayer tv:// -tv driver=v4l2:width=320:height=240:device=/dev/video0 -fps 30<br />
<br />
* Cheese<br />
* Skype<br />
* Ekiga<br />
<br />
A simple solution to take snapshots is:<br />
<br />
# mplayer tv:// -vf screenshot<br />
<br />
and the pressing the s key to take a snapshot. Files are of the format {{ic|shot\d\d\d\d.png}} and are reported in the standard output.<br />
<br />
==== Facetime HD ====<br />
According to Apple, all recent MacBook models contain a Facetime HD camera instead of the iSight. The following list is an example:<br />
* iMac (21,5" mid 2011)<br />
* iMac (27" mid 2011)<br />
* MacBook Air (mid 2011)<br />
* MacBook Pro (15" early 2011)<br />
* MacBook Pro (17" early 2011)<br />
* MacBook Pro (13" early 2011)<br />
If your MacBook is more recent than the models listed above, it is likely equipped with the Facetime HD camera as well.<br />
<br />
In order to make the camera work, you need to install the {{AUR|bcwc-pcie-dkms}} and {{AUR|bcwc-pcie-firmware}} packages. This will enable camera video support through the {{ic|facetimehd}} kernel module.<br />
<br />
In order to verify if the Facetime camera is working after the installation of both packages, you'll need to reboot your system.<br />
<br />
{{Note|Keep in mind that, although working, this is a reverse-engineered driver. PC suspension is not supported if a program that is keeping the camera active is running.}}<br />
<br />
=== Temperature Sensors ===<br />
<br />
For reading temperature just install {{Pkg|lm_sensors}}. See the [[lm_sensors]] page for more information.<br />
<br />
=== Color Profile ===<br />
<br />
We can use color profiles from OS X.<br />
<br />
First, install the {{AUR|xcalib}} package.<br />
<br />
Second copy pre-saved color profiles placed in {{ic|/Library/ColorSync/Profiles/Displays/}} on OS X partition to {{ic|~/colorprofiles/}} for example.<br />
<br />
There are color profile files agree with in MacBook models; select the right one:<br />
<br />
* '''Color LCD-4271800.icc''' for MacBook Pro with CoreDuo CPU<br />
* '''Color LCD-4271880.icc''' for MacBook with Core2Duo<br />
* '''Color LCD-4271780.icc''' for MacBook (non-Pro) based on CoreDuo or Core2Duo.<br />
<br />
{{Tip|Also OS X allows to save current color profile from ''Displays > Color'' section of the ''Mac OS System Preferences'', in this case file is saved to {{ic|/Users/<username>/Library/ColorSync/Profiles}}.}}<br />
<br />
Finally you can activate it by running<br />
<br />
# xcalib ~/colorprofile.icc<br />
<br />
{{Note|Previous command set the color profile only for the current session; this mean that you must run it every time you login in your system. For automating it you can execute the command by '''Autostart Application''', concording with your DE (or add the command to your login manager's initialization script, e.g. /etc/gdm/Init/Default).}}<br />
<br />
{{Warning|GNOME will revert the profile set by xcalib. It's preferable to set the profile using '''Color''' in settings.}}<br />
<br />
=== Apple Remote ===<br />
<br />
First, to correctly install and configure the '''lirc''' software that control IR see [[LIRC]] wiki.<br />
<br />
Then make LIRC use {{ic|/dev/usb/hiddev0}} (or {{ic|/dev/hiddev0}}) by editing {{ic|/etc/conf.d/lircd}}. Here is how mine look:<br />
<br />
#<br />
# Parameters for lirc daemon<br />
#<br />
LIRC_DEVICE="/dev/usb/hiddev0"<br />
LIRC_DRIVER="macmini"<br />
LIRC_EXTRAOPTS=""<br />
LIRC_CONFIGFILE="/etc/lirc/lircd.conf"<br />
<br />
Use '''irrecord''' (available when installing '''lirc''') to create a configuration file matching your remote control signals (alternatively, you can try to use the {{ic|lircd.conf}} below):<br />
<br />
# irrecord -d /dev/usb/hiddev0 -H macmini output_conf_file<br />
<br />
Start '''lircd''' and use '''irw''' to check if it works.<br />
<br />
Example of an {{ic|/etc/lirc/lircd.conf}}:<br />
<br />
begin remote<br />
<br />
name lircd.conf.macbook<br />
bits 8<br />
eps 30<br />
aeps 100<br />
<br />
one 0 0<br />
zero 0 0<br />
pre_data_bits 24<br />
pre_data 0x87EEFD<br />
gap 211994<br />
toggle_bit_mask 0x87EEFD01<br />
<br />
begin codes<br />
Repeat 0x01<br />
Menu 0x03<br />
Play 0x05<br />
Prev 0x09<br />
Next 0x06<br />
Up 0x0A<br />
Down 0x0C<br />
end codes<br />
<br />
end remote<br />
<br />
=== HFS partition sharing ===<br />
<br />
First, install the {{Pkg|hfsprogs}} package. <br />
<br />
we have to list our partitions. Use<br />
<br />
fdisk -l /dev/sda<br />
<br />
example output:<br />
<br />
# fdisk -l /dev/sda<br />
Device Boot Start End Blocks Id Type<br />
/dev/sda1 1 26 204819 ee GPT<br />
/dev/sda2 26 13602 109051903+ af Unknown<br />
/dev/sda3 * 13602 14478 7031250 83 Linux<br />
/dev/sda4 14478 14594 932832+ 82 Linux swap / Solaris<br />
<br />
As we see, the "Unknown" partition is our OS X partition, which is located in {{ic|/dev/sda2}}.<br />
<br />
Create a "mac" folder in /media:<br />
<br />
# mkdir /media/mac<br />
<br />
Add at the end of ''/etc/fstab'' this line:<br />
<br />
/dev/sda2 /media/mac hfsplus auto,user,rw,exec 0 0<br />
<br />
Mount it :<br />
<br />
mount /media/mac<br />
<br />
and check it:<br />
<br />
ls /media/mac<br />
<br />
=== HFS+ Partitions ===<br />
<br />
==== Journaling ====<br />
<br />
HFS+ partitions, now the default in OS X, are not fully supported by Linux and are mounted as read-only by default. In order to write to an HFS+ partition, the safe way is to disable journaling. This can be accomplished using the OS X Disk Utility. Refer to this [http://support.apple.com/kb/ht2355 Apple support page] for more information or try to do it from the command line:<br />
<br />
Find your partition:<br />
<br />
$ diskutil list<br />
/dev/disk0<br />
#: TYPE NAME SIZE IDENTIFIER<br />
0: GUID_partition_scheme *750.2 GB disk0<br />
1: EFI EFI 209.7 MB disk0s1<br />
2: Apple_HFS OSX 149.5 GB disk0s2<br />
3: Apple_HFS Macintosh HD 599.2 GB disk0s3<br />
4: Apple_Boot Recovery HD 650.0 MB disk0s4<br />
<br />
In this example we will use ''disk0s3'' partition named as ''Macintosh HD''. To know if journaling is activate or not you could execute:<br />
<br />
$ diskutil info /dev/disk0s3 | grep -i journal<br />
File System Personality: Journaled HFS+<br />
Name (User Visible): Mac OS Extended (Journaled)<br />
Journal: Journal size 49152 KB at offset 0x1176000<br />
<br />
As you can read the journaling is active. To turn off the journaling you could execute:<br />
<br />
$ sudo diskutil disableJournal disk0s3<br />
Password:<br />
Journaling has been disabled for volume Macintosh HD on disk0s3<br />
<br />
To verify it is done execute the info command again:<br />
<br />
$diskutil info /dev/disk0s3 | grep -i journal<br />
$<br />
<br />
If you get noting as output, then journaling is disabled.<br />
<br />
However, if you fail to disable journaling. You can change "auto,user,rw,exec" in "/etc/fstab" to "auto,user,force,rw,exec" and mount it.<br />
<br />
====Yosemite and later====<br />
<br />
Since Yosemite, HFS+ partitions are now wrapped a CoreStorage volume. Verify that you have an CoreStorage volume.<br />
<br />
# fdisk -l /dev/sdX<br />
Disk /dev/sdX: 298.1 GiB, 320072933376 bytes, 625142448 sectors<br />
Units: sectors of 1* 512 = 512 bytes<br />
Sector size (logical/physical): 512 bytes / 4096 bytes<br />
I/O size (minimum/optimal): 4096 bytes / 4096 bytes<br />
Disklabel type: gpt<br />
Device Start End Sectors Size Type<br />
/dev/sdX1 40 409639 409600 200M EFI System<br />
/dev/sdX2 409640 623872871 623463232 297.3G Apple Core storage<br />
/dev/sdX3 623872872 625142407 1269536 916.0M Apple boot<br />
<br />
HFS+ uses two volume headers, one 1024 bytes into the device and one 1024 from the end of the device. With the HFS+ partition wrapped in the CoreStorage volume the end of the partition is not actually 1024 bytes from the end of the {{ic|/dev/sdX2}} partition.<br />
To fix this you need to specify {{ic|1=sizelimit=X}} when mounting.<br />
<br />
To determine {{ic|sizelimit}} do the following:<br />
<br />
# Run {{ic|testdisk /dev/sdX}} and select your drive<br />
# Select {{ic|EFI GPT}}<br />
# Select {{ic|Analyse}} and then {{ic|Quick Search}}<br />
<br />
Sample output:<br />
TestDisk 7.0, Data Recovery Utility, April 2015<br />
Christophe GRENIER <grenier@cgsecurity.org><br />
http://www.cgsecurity.org<br />
<br />
Disk /dev/sdX - 320 GB / 298 GiB - CHS 38913 255 63<br />
Partition Start End Size in sectors<br />
P EFI System 40 409639 409600 [EFI]<br />
P Mac HFS 409640 623147815 622738176<br />
P Mac HFS 623872872 625142407 1269536<br />
<br />
What you see now is the output of the HFS partition itself without the CoreStorage volume. Take the size in sectors (622738176 in this example) and multiply by the number of bytes in your logical sector size (512 in this example).<br />
<br />
622738176 * 512 = 318841946112<br />
<br />
Finally, mount your disk with the {{ic|1=sizelimit=X}} option.<br />
<br />
mount /dev/sdX -t hfsplus -o ro,sizelimit=318841946112<br />
<br />
===Home Sharing===<br />
<br />
'''''UID Synchronization'''''<br />
<br />
==== In OS X ====<br />
<br />
{{Note|It is strongly recommended that UID/GID manipulation be done immediately after a new user account is created, in OS X as well as in Arch Linux. If you installed OS X from scratch, then this operation is guaranteed to work after logging into your account for the first time.}}<br />
<br />
===== Step 1: change UID and GID(s) =====<br />
<br />
'''''Pre-Leopard'''''<br />
<br />
# Open '''NetInfo Manager''' located in the ''/Applications/Utilities'' folder.<br />
# If not done for you already, enable access to user account transactions by clicking on the closed lock at the bottom of the window, and entering your account password, or root password if you have created a root account.<br />
# Navigate to ''/users/<new user name>'' where <new user name> is the name of the account that will have read/write access to the folder that will be shared with the primary user in Arch.<br />
# Change the '''UID''' value to 1000 (the value used by default for first user created in Arch).<br />
# Also change the '''GID''' value to 1000 (the value used by default for user account creation in Arch).<br />
# Navigate to {{ic|/groups/<new user name>}}, automatically saving the changes you have made so far.<br />
<br />
{{Note|If you get an error message that the transaction is not allowed, log out and log back in.}}<br />
<br />
'''''Leopard'''''<br />
<br />
In Leopard, the '''NetInfo Manager''' application is not present. A different set of steps is required for UID synchronization:<br />
<br />
# Open '''System Preferences'''.<br />
# Click on '''Users & Groups'''.<br />
# Unlock the pane if not already done so.<br />
# Right-click on the desired user and select '''Advanced Options'''.<br />
# Write down the value of the '''User ID''' field, you will need it later on. Change both the UID and GID to match the UID and GID of the account wished to be shared with in Arch (1000 by default for the first user created in Arch).<br />
<br />
===== Step 2: change "Home" permissions =====<br />
<br />
# Open up '''Terminal''' in the {{ic|/Applications/Utilities}} folder.<br />
<br />
# Enter the following command to reclaim the permission settings of your home folder, replacing <your user name>, <your user group> and <your old UID> with the user name whose UID and GID values you just changed, the group name whose GID value you just changed and the old UID number, respectively.<br />
<br />
# find /User/<your user name> -user <your old UID> -exec chown <your user name>:<your user group> {} \;<br />
<br />
==== In Arch ====<br />
<br />
To synchronize your UID in Arch Linux, you are advised to perform this operation ''while creating a new user account''.<br />
It is therefore recommended that you do this as soon as you install Arch Linux.<br />
<br />
Now you must substitute Arch's home with OS X's home, by modify entries of {{ic|/etc/fstab}}.<br />
<br />
=== Avoid long EFI wait before booting ===<br />
<br />
If your MacBook spends 30 seconds with "white screen" before booting you need to tell the firmware where is the booting partition.<br />
<br />
Boot OS X, if do not have it installed, you can use the install DVD (select language, then click Utilities->Terminal), or another MacBook with OS X (connect the two computers via firewire or thunderbolt, start the other MacBook keeping pressed T, boot your MacBook keeping pressed Options).<br />
<br />
Either way, once you got a OS X terminal running on your MacBook you need to execute, as root, a different command if the boot partition is EFI or it is not:<br />
<br />
# bless --device /dev/disk0s1 --setBoot # if the booting partition is EFI<br />
or<br />
# bless --device /dev/disk0s1 --setBoot --legacy # if the booting partition is not EFI<br />
<br />
(given that if your GRUB or EFI is on sda1, /dev/disk1s2 if it is on sdb2, etc). See also https://bbs.archlinux.org/viewtopic.php?pid=833215 and https://support.apple.com/kb/HT1533 .<br />
<br />
=== Mute startup chime ===<br />
<br />
The startup chime volume is controlled by the EFI variable ''SystemAudioVolume-7c436110-ab2a-4bbb-a880-fe41995c9f82''. So it can be muted with<br />
<br />
# printf "\x07\x00\x00\x00\x00" > /sys/firmware/efi/efivars/SystemAudioVolume-7c436110-ab2a-4bbb-a880-fe41995c9f82<br />
<br />
Alternatively, you can use a OS X install disk to mute the chime. Boot from it, select language, then click ''Utilities > Terminal'', and enter<br />
<br />
# /usr/sbin/nvram SystemAudioVolume=%01<br />
<br />
(or whatever volume you want).<br />
<br />
{{Note|Required formatting of the value provided for key SystemAudioVolume may differ depending on MacBook model and perhaps the version of OS X install media. If the above command fails to work, try enclosing the value in double quotes.}}<br />
<br />
=== kworker using high CPU ===<br />
Sometime with the addition of Yosemite, some users found that kworker CPU usage will spike, as disccused [https://bbs.archlinux.org/viewtopic.php?id=171883&p=11 here]. This is sometimes the result of runaway ACPI interrupts.<br />
<br />
To check and see, you can count the number of recent ACPI interrupts and see if any of them are out of control.<br />
<br />
grep . -r /sys/firmware/acpi/interrupts/<br />
<br />
<br />
If you see that one particular interrupt is out of control (possibly GPE66), i.e., registering hundreds of thousands of lines, you can try disabling it (replace XX with the runaway interrupt):<br />
<br />
<br />
echo "disable" > /sys/firmware/acpi/interrupts/gpeXX<br />
<br />
<br />
Disabling random ACPI interrupts could cause all kinds of problems, so do this at your own risk. If this fixes the problem, there is discussion about how to make a systemd service that automatically disables an interrupt at every boot [https://bbs.archlinux.org/viewtopic.php?pid=1488371 here].<br />
<br />
== rEFIt ==<br />
<br />
{{Note|<br />
* You probably want to have a look at [http://www.rodsbooks.com/refind/ rEFInd], which is some type of successor of rEFIt.<br />
* This is not a requirement. It only gives you a menu to choose between OS X and Arch Linux upon every boot.<br />
}}<br />
<br />
For more see, [http://refit.sourceforge.net/myths/ rEFIt myths].<br />
<br />
In OS X, download the ".dmg" from [http://refit.sourceforge.net/ rEFIt Homepage] and install it.<br />
<br />
{{Note|If you have already partitioned your hard disk in preparation for the Arch installation, rEFIt may not be enabled by default. You will have to run the "enable.sh" script installed in /efi/refit/.}}<br />
<br />
Open up '''Terminal''' and enter:<br />
<br />
cd /efi/refit;<br />
./enable.sh<br />
<br />
=== Problems with rEFIt ===<br />
<br />
If you experience problems after the install of Arch or rEFIt, especially is the right OS is not showing up to boot to or if it dumps you at a GRUB prompt stuck like the following:<br />
<br />
GRUB>_<br />
<br />
Then have a look at this link:<br />
<br />
http://mac.linux.be/content/problems-refit-and-grub-after-installation<br />
<br />
It can give you a basic idea on how to boot off the Arch live cd, mount the problem Arch install, chroot, use gptsync, and reinstall GRUB. This is probably for more advanced users who can translate the commands from a debian system to an Arch system and also apply it to the partitions on their machine. Be careful not to install GRUB in the wrong spot.<br />
<br />
If you need a copy of gptsync you can wget it from here:<br />
http://packages.debian.org/sid/gptsync<br />
or try these, for 64 bit:<br />
<br />
wget http://ftp.us.debian.org/debian/pool/main/r/refit/gptsync_0.14-2_amd64.deb<br />
<br />
and for i386:<br />
<br />
wget http://ftp.us.debian.org/debian/pool/main/r/refit/gptsync_0.14-2_i386.deb<br />
<br />
since they are .deb packages you will need the program {{AUR|deb2targz}}.<br />
<br />
==== Mavericks upgrade breaks Arch boot option ====<br />
For some multi-boot users who utilize a separate Linux boot partition, the OS X Mavericks upgrade may overwrite the boot partition with Apple's own recovery boot filesystem. This breaks the Arch Linux boot option in rEFIt/rEFInd. The best way to proceed in this situation is to abandon a separate boot partition and use the EFI system partition (ESP) to install the bootloader of your choice. It is also recommended that you use rEFInd instead of rEFIt as development on the latter has halted.<br />
<br />
Assuming grub2 as the bootloader:<br />
<br />
Use the Arch LiveCD to boot to a shell and [[Change root|chroot]] to your broken Arch Linux environment.<br />
<br />
Mount the ESP on /boot.<br />
<br />
Edit the fstab and remove the old boot partition and make ESP the new boot partition. Now mount the ESP as the new /boot parition.<br />
# mount -a<br />
<br />
[[install|Reinstall]] {{pkg|linux}}.<br />
<br />
Create a new initramfs and vmlinuz in /boot.<br />
# mkinitcpio -p linux<br />
<br />
Install grub.<br />
# grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=grub --recheck --debug<br />
<br />
Create a new grub.cfg file.<br />
# grub-mkconfig -o /boot/EFI/grub/grub.cfg<br />
<br />
Make sure that grub.cfg is in the same directory as grubx64.efi.<br />
<br />
Generate a new refind_linux.conf file in /boot simply by running mkrlconf.sh which comes with rEFInd.<br />
<br />
Exit the chroot environment.<br />
<br />
Reboot. You should see a new entry for Arch Linux in rEFInd and it should boot to your Arch Linux installation.<br />
<br />
== Model-specific information ==<br />
<br />
=== MacBook ===<br />
<br />
==== April 2016 12" - Version 9,1 ====<br />
<br />
* Booting from USB via EFI works fine, when giving the {{ic|noapic}} kernel option. (On Ubuntu, also {{ic|noacpi nomodeset}} seem to be necessary.) Remember to hold the Alt key on booting.<br />
<br />
* The wireless card works out of the box with {{ic|brcmfmac}}.<br />
<br />
* Suspend-to-RAM works out of the box.<br />
<br />
* The built-in flash drive does ''not'' work with kernel 4.5.4-1-ARCH, but it ''does'' work with kernel 4.6.0-mainline (install {{AUR|linux-mainline}}). As long as a [http://lists.infradead.org/pipermail/linux-nvme/2016-May/004618.html rather trivial patch] is not merged into the kernel, either this patch must be applied locally or one puts {{ic|modprobe nvme; echo 106b 2003 > /sys/bus/pci/drivers/nvme/new_id}} into a mkinitcpio hook (to be started after the udev hook). The reason is that the NVMe controller of the flash drive doesn't advertise itself with the correct PCI device class. Note that with the patch, a short sleep still seems to be necessary.<br />
<br />
* Audio recording works out of the box. Audio playback doesn't work (still looking for a solution).<br />
<br />
* The keyboard and the touchpad do ''not'' work (still looking for a solution).<br />
** There's a WIP driver [https://github.com/cb22/macbook12-spi-driver here] that sort of works with a DSDT hack (the previous problem with this driver related to battery drain has been fixed now).<br />
<br />
==== Mid 2007 13" - Version 2,1 ====<br />
<br />
{{Note|I used the 201212 ISO image.}}<br />
<br />
Since older Macbooks have a 32bit EFI running, the usual installation image is not recognized. You need to either remove the UEFI support from the disc ([[Unified_Extensible_Firmware_Interface#Remove_UEFI_boot_support_from_ISO]]) or build a 32bit EFI version of the disc. The paragraphs below will take the first path to success, booting into BIOS mode and its pitfalls. For a try the other way round, read [[Unified_Extensible_Firmware_Interface#Create_UEFI_bootable_USB_from_ISO]] first.<br />
<br />
First prepare your harddisc according to your wishes. In this scenario it was a "Linux only" approach with<br />
<br />
/dev/sda1 HFS+ AF00 200M -> EFI boot system on Apple HFS+ partition<br />
/dev/sda2 ext4 8300 147G -> arch system<br />
/dev/sda3 swap 8200 1G -> swap<br />
<br />
The {{AUR|hfsprogs}} package contains the tools to handle HFS/HFS+ filesystems. The rEFInd bootloader recognizes it on its own. Usually the partition for the EFI bootloader is a FAT32 (vfat) partition. In this case I tried rEFIt first, which apparently needs the HFS+ filesystem to work, and kept it at that.<br />
<br />
The mount points are:<br />
<br />
/dev/sda2 -> /<br />
/dev/sda1 -> /boot<br />
<br />
The bootloader in use was [http://www.rodsbooks.com/refind/index.html rEFInd] instead of rEFIt. To install it, the rEFInd homepage provides a good guide. Usually it is simply done by copying rEFInd:<br />
<br />
mkdir /boot/EFI<br />
cp -vr /usr/share/refind/drivers_ia32 /boot/EFI/refind/<br />
cp -vr /usr/share/refind/tools_ia32 /boot/EFI/refind/<br />
cp -vr /usr/share/refind/fonts /boot/EFI/refind/<br />
cp -vr /usr/share/refind/icons /boot/EFI/refind/<br />
cp -v /usr/share/refind/refind_ia32.efi /boot/EFI/refind/<br />
cp -v /usr/share/refind/refind.conf-sample /boot/EFI/refind/refind.conf<br />
cp -v /usr/share/refind/refind_linux.conf-sample /boot/refind_linux.conf<br />
<br />
{{Note|I'm using the 32bit version of Arch and refind, since the EFI of the old MacBooks is 32bit. I'm not sure about 32bit rEFInd booting a 64bit Arch...}}<br />
<br />
The pitfall here is, that the system bootet in BIOS compatibility mode and not in EFI mode. You cannot therefore use {{ic|efibootmgr}}, because the EFI variables (even with 'modprobe efivars') are not available. While installing the system get {{AUR|mactel-boot}}. The {{ic|hfs-bless}} utility comes in handy, when blessing the EFI bootloader. This is done by calling:<br />
<br />
hfs-bless /boot/EFI/refind/refind_ia32.efi<br />
<br />
Since the Linux kernel does come with EFI stub enabled, it seems a good idea to run it through a bootloader first. Especially if it runs not out of the box. But using rEFInd makes GRUB (or any other bootloader) obsolete, because of that.<br />
<br />
{{Note|In the refind_linux.conf you add any kernel option you may want as long as you use the EFI stub of your kernel. In refind.conf you adjust your needs for the bootloader itself, like menu entries. If you use them (menu entries), rEFInd should not look for these EFI stub kernels itself, so blacklist the directories used in here, like {{ic|/boot/}}.}}<br />
<br />
Not running out of the box is unfortunately the initial stage for the kernel. Since we installed it in BIOS mode, two modules are missing to grant access to the root partition while booting. Hence the 'initfsram-linux.img' can not be found/loaded. Adding the following modules to your 'MODULES' line in {{ic|/etc/mkinitcpio.conf}} solved this ([https://bbs.archlinux.org/viewtopic.php?pid=1139226#p1139226 original post]).<br />
<br />
{{hc|/etc/mkinitcpio.conf|2=<br />
MODULES="ahci sd_mod"}}<br />
<br />
Rebuild your kernel image:<br />
<br />
mkinitcpio -p linux<br />
<br />
The bootloader rEFInd can scan kernels even out of the '/boot/...' directory and assumes an efi kernel even without the extension '.efi'. If you do not want to try out special kernels, this should work without the hassle to copy each kernel after building to some spot special.<br />
<br />
If you happen to get multiple entries for one boot image, it often results of a previous installation of a bootloader within the MBR. To remove that, try the following - taken from the [http://ubuntuforums.org/showpost.php?p=7828260&postcount=4 original post]. This is valid for GPT partitioned discs, so please check your environment and save your MBR first.<br />
<br />
# dd if=/dev/zero of=/dev/sda bs=440 count=1<br />
<br />
=== MacBook Pro with Retina display ===<br />
<br />
==== Early 2015 13"/15" - Version 12,x/11,4+ ====<br />
<br />
===== Wireless =====<br />
The {{ic|brcmfmac}} driver is working as of 2015-11-20, with newer firmware necessary for working 5GHz support ([https://bugzilla.kernel.org/show_bug.cgi?id=100201#c65 see here.])<br />
<br />
===== Bluetooth =====<br />
Bluetooth is fully supported starting from kernel-4.4.0.<br />
<br />
===== Suspend & Power Off (11,4+) =====<br />
The 11,4 and 11,5 MacBook Pros do not shutdown or suspend correctly with the default kernel. This issue is being addressed in [https://bugzilla.kernel.org/show_bug.cgi?id=103211 Bug 103211] and a temporary patch is currently available in {{AUR|linux-macbook}}.<br />
<br />
===== Keyboard & Trackpad =====<br />
Haptic feedback works out of the box due to the trackpad's built-in firmware.<br />
<br />
There are several drivers available that provide multitouch support. The following have been confirmed working with the MacBookPro12,1.<br />
<br />
For {{Pkg|xf86-input-libinput}} the following configuration emulates some features from the OS X functionality. For more options see {{man|4|libinput|url=https://www.mankier.com/4/libinput}}.<br />
{{hc|1=/etc/X11/xorg.conf.d/90-libinput.conf|2=<br />
Section "InputClass"<br />
Identifier "libinput touchpad catchall"<br />
MatchIsTouchpad "on"<br />
MatchDevicePath "/dev/input/event*"<br />
Driver "libinput"<br />
Option "NaturalScrolling" "true"<br />
EndSection<br />
}}<br />
<br />
For {{Pkg|xf86-input-synaptics}} the following configuration is necessary to make the touchpad work fully.<br />
{{hc|1=/etc/X11/xorg.conf.d/60-magictrackpad.conf|2=<br />
Section "InputClass"<br />
Identifier "Trackpad"<br />
Driver "synaptics"<br />
MatchIsTouchpad "on"<br />
MatchDevicePath "/dev/input/event*"<br />
EndSection<br />
}}<br />
<br />
Further, some US/ANSI keyboards suffer from an issue where the tilde key (~, the key vertically between Esc and Tab) registers as < and >. The following config file fixes this issue.<br />
<br />
{{hc|1=/etc/modprobe.d/hid_apple.conf|2=<br />
options hid_apple iso_layout=0<br />
}}<br />
<br />
See [https://bugzilla.kernel.org/show_bug.cgi?id=96771 this kernel bugzilla] for more details and the relevant patches for earlier kernels.<br />
<br />
===== Graphics =====<br />
For Intel-only graphics, install {{Pkg|xf86-video-intel}}. For more information or OpenGL/3D support, follow instructions at [[Intel graphics]].<br />
<br />
For Dual Graphics see [https://wiki.archlinux.org/index.php/MacBookPro11,x#Graphics this section on the 11,3].<br />
<br />
{{Note|The kernel parameters ''acpi_backlight'', ''i915.lvds_downclock'', ''i915.enable_ips'', and ''intel_iommu'' are no longer necessary as of kernel 4.2.}}<br />
<br />
==== 2012 - 2014 models ====<br />
<br />
* [[MacBookPro11,x]] (Late 2013—Mid 2014)<br />
* [[MacBookPro10,x]] (Mid 2012—Early 2013)<br />
<br />
=== MacBook Air===<br />
<br />
==== Early 2014 11" - Version 6,1 ====<br />
This is almost the same as the 2013 version, where the only known difference is a slightly faster processor. The version numbers have not been changed since the 2013 version.<br />
<br />
It works excellently after following the instructions for the MBA 2013 13" here and in the forum thread.<br />
Bluetooth, which has been reported not working for some people with the 2013 version, works without trouble for the 2014 version, although it should be excactly the same.<br />
<br />
{{Note| Unless you have a local repository on a USB disk, you need a USB to ethernet adaptor or a USB wireless adaptor supported natively by the kernel to easily install Arch Linux, since you have to install the {{AUR|broadcom-wl-dkms}} package to make the internal wireless adaptor work.}}<br />
<br />
Unresolved issues:<br />
<br />
- There is no driver for the webcam yet.<br />
- rEFInd uses 30 seconds to start booting. Using the bless trick stops rEFInd from loading, and it has to be re-installed.<br />
<br />
==== Mid 2013 13" - Version 6,2 ====<br />
[https://bbs.archlinux.org/viewtopic.php?id=165899 Dedicated forum thread]<br />
===== Installing and booting =====<br />
Booting from a normal 2013.6 USB key works fine, but I could not seem to get either GRUB or Syslinux working.<br />
<br />
I was able to boot by first installing Arch Linux following the MacBook guide at the wiki (having a separate FAT32 /boot partition). Skip the bootloader installation. <br />
<br />
Installing [http://www.rodsbooks.com/refind/getting.html rEFInd] from OS X (important!) and installing the EFI stub loader made me able to boot fine.<br />
<br />
[https://bbs.archlinux.org/viewtopic.php?id=165710 Dedicated thread].<br />
<br />
{{Note| Installing [http://www.rodsbooks.com/refind/getting.html rEFInd] from Linux (or from OS X, but to the esp) also works fine}}<br />
<br />
===== Arch Only Installation =====<br />
This method works without rEFInd and uses grub to boot EFI. Partition as follows:<br />
<br />
/dev/sda1 200M Microsoft basic data<br />
/dev/sda2 256M Linux filesystem<br />
/dev/sda3 4G Linux swap<br />
/dev/sda4 108.6G Linux filesystem<br />
<br />
sda1 can also be a HFS+ partition for EFI. This example chooses to use FAT32 (vfat). Although swap is optional, it is required for hibernation. Instead of sda4 for root and home, an alternative partition scheme would be to make sda4 as root and sda5 as home.<br />
<br />
Format and mount:<br />
<br />
mkfs.vfat -F 32 /dev/sda1<br />
mkfs.ext2 /dev/sda2<br />
mkswap /dev/sda3<br />
swapon /dev/sda3<br />
mkfs.ext4 /dev/sda4<br />
<br />
mount /dev/sda4 /mnt<br />
mkdir /mnt/boot<br />
mount/dev/sda2 /mnt/boot<br />
mkdir /mnt/boot/efi<br />
mount /dev/sda1 /mnt/boot/efi<br />
<br />
Finish the installation according to the [[Installation guide]] and skip anything after the bootloader. After you have generated your initramfs and set root passwd follow below to setup grub:<br />
<br />
pacman -S grub efibootmgr<br />
mount -t efivarfs efivarfs /sys/firmware/efi/efivars<br />
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=grub --recheck --debug<br />
grub-mkconfig -o /boot/efi/EFI/grub/grub.cfg<br />
cp /boot/efi/EFI/grub/grub.cfg /boot/grub/grub.cfg<br />
cp /boot/efi/EFI/grub/grubx64.efi /boot/efi/EFI/boot/bootx64.efi}}<br />
<br />
Now you can exit/unmount/reboot:<br />
exit<br />
umount -R /mnt<br />
reboot<br />
<br />
===== Stability problems =====<br />
{{Note| Passing {{ic|<nowiki>libata.force=1:noncq</nowiki>}} to the kernel parameters solves the problem.}}<br />
This is the big worry for me. Every now and then my system hangs for a brief moment and everything involving net or disk access just hangs there for a while and then it seems to work. <br />
So far it only seems to happen when I run something disk- or CPU-intensive. Also had an occassion when I could not start X and just got this repeating all over my screen:<br />
<br />
ata1.00: failed command: WRITE FPDMA QUEUED<br />
ata1.00: cmd 61/08:f0:10:8c:c2/00:00:0b:00:00/40 tag 30 ncq 4096 out<br />
res 40/00:00:00:00:00/00:00:00:00:00/00 Emask 0x4 (timeout)<br />
ata1.00: status: { DRDY }<br />
<br />
On the next attempt it worked fine.<br />
I did SMART short and long tests on my disk and they returned fine:<br />
<br />
[http://pastebin.com/vRE4T2Ld smartctl -a]<br />
<br />
There are some messages in my boot that indicate this could be disk and/or ACPI related.<br />
<br />
These are with 2013-06 ISO, 3.9.7-1 2013 x86_64 kernel.<br />
<br />
[http://pastebin.com/mjTJaPFa journalctl -b]<br />
Seems to only work with the headphone jack, not with the speakers.<br />
<br />
[http://pastebin.com/SdAcHuKh dmesg]<br />
<br />
===== Marvell ATA suspend bugs =====<br />
If you have 2013 MacBook Air with a Marvell 128 or 256 GB drive, you might get the following ata errors instead after pm-suspend/resumes:<br />
<br />
ata1: exception Emask 0x10 SAct 0x0 SErr 0x10000 action 0xe frozen<br />
ata1: irq_stat 0x00400000, PHY RDY changed<br />
ata1: SError: { PHYRdyChg }<br />
ata1: hard resetting link<br />
ata1: SATA link up 1.5 Gbps (SStatus 113 SControl 310)<br />
ata1.00: unexpected _GTF length (8)<br />
ata1.00: unexpected _GTF length (8)<br />
ata1.00: configured for UDMA/33<br />
ata1: EH complete<br />
<br />
Try what Patrick and Tejun figured out on the [https://bugzilla.kernel.org/show_bug.cgi?id=62351 linux bug]. I followed what Patrick describes with sata_alpm, and I haven't seen the issue since.<br />
<br />
There are more steps on how to resolve this issue in [https://bbs.archlinux.org/viewtopic.php?pid=1562168#p1562168 this thread on the Arch forum]<br />
<br />
===== Suspend/Resume =====<br />
Brightness is either 0% or 100% after resuming from suspend. Until the kernel is fixed, use patjak's fix by installing {{AUR|mba6x_bl-dkms}}. Patjak's github is at [https://github.com/patjak/mba6x_bl].<br />
===== WiFi =====<br />
WiFi does not work out of the box. Install {{AUR|broadcom-wl-dkms}} to connect to a network. <br />
<br />
===== Touchpad =====<br />
Since 3.10.3 kernel touchpad works perfectly with {{Pkg|xf86-input-synaptics}}.<br />
<br />
===== Audio =====<br />
As of Linux 3.12, sound works out of the box. If you do not get sound with only {{pkg|alsa-utils}}, you may need to create a /etc/asound.conf with below entries:<br />
<br />
defaults.pcm.card 1<br />
defaults.pcm.device 0<br />
defaults.ctl.card 1<br />
<br />
==== Mid 2012 13" — version 5,2 ====<br />
<br />
Kernel panics using default boot media under arch kernel 3.5. Adding <code>intremap=off</code> fixes this. Additionally, there are problems loading the <code>applesmc</code> module (meaning the temperature sensors, fan, and keyboard backlight do not work). These problems are fixed in the linux 3.6-rc4 mainline kernel (I have tested).<br />
<br />
==== Mid 2012 11.5" — Version 5,1 ====<br />
<br />
If you have issues with waking from sleep while in X11 such as a black screen or showing the console with a frozen mouse cursor then remove {{Pkg|xf86-input-synaptics}} and install {{AUR|xf86-input-mtrack-git}}. This fixed errors such as <br />
(EE) [dix] bcm5974: unable to find touch point 0<br />
and backtraces that causes X11 to crash. This might apply to Version 5,2 assuming they use the same trackpad.<br />
<br />
===== Installing using the Archboot 2012.06 image =====<br />
<br />
Several people have reported problems installing Arch Linux on the MBA version 5,2 (See [https://bbs.archlinux.org/viewtopic.php?id=144089 problems booting Arch Linux on a MacBook Air Mid 2012]). A common problem is that the screen is not detected and therefore goes black when the installer boots. To fix this problem one has to select the normal install (Not the LTS) during boot and press tab to edit the boot flags. Then add noapic flag to the boot line. This should fix the screen going black. Install the system as you normally would. It may help later in the configuration process if the support packages are installed already at this stage.<br />
<br />
When the install has finished again add the noapic flag to the GRUB boot line (if you use GRUB) and also add i915.diescreaming=1 (or perhaps i915.die). This should keep the screen from going black when booting the new system. After you enter the system the wireless driver should be loaded. If you installed the support packages during installation you should have the wifi-menu command. Run it and select the network you want to use. One could also use wpa_supplicant but wifi-menu is quite fast to use at this stage. Now you are ready to upgrade the system. As of writing there have been a lot of changes to Arch Linux since the 2012.06 image of Archboot was released ([https://www.archlinux.org/news/filesystem-upgrade-manual-intervention-required-1/ filesystem] and [https://www.archlinux.org/news/the-lib-directory-becomes-a-symlink/ glibc]). Therefore the upgrade process can be a bit difficult. The current solution has sucessfully upgraded a standart archboot version to a up-to-date version as of October 2012 and this step should be obsolete in future releases of archboot.<br />
<br />
First ignore the new "big" changes to Arch Linux,<br />
<br />
pacman -Suy --ignore glibc,libarchive,curl,filesystem <br />
<br />
If this only upgrades pacman then run the command again. Remember to make sure that pacman is ignoring the packages you do not want upgraded now. Otherwise you may break the system and have to reinstall! Now upgrade to the new filesystem,<br />
<br />
pacman -S filesystem --force<br />
<br />
As described in [[DeveloperWiki:usrlib|Glibc upgrade guide]] there may be conflicts with installed packages that require the /lib directory. Follow the guide and remove any packages that use /lib. The stock 3.4.2 kernel from Archboot should be on this list so first upgrade this,<br />
<br />
pacman -S linux<br />
<br />
This may give some errors saying that the system may not boot because of missing modules. Ignore this warning for now. The stock install may also contain gcc in the /lib directory so also remove this if needed and any other packages that have conflicts. Now Glibc should be the only package in /lib so run the system upgrade and accept all changes, <br />
<br />
pacman -Su<br />
<br />
Finally reinstall the kernel so that it can find the correct modules.<br />
<br />
Now this command should not give any errors like last time. You can also reinstall gcc at this point. After a rebooted the system should startup and the new kernel should have fixed the problem with the screen going black. If want to boot Xorg then you may need to remove the i915.diescreaming=1 line from GRUB. If not then attach a external screen and try to fix the problem that way. Some people have reported commands that may help on the [https://bbs.archlinux.org/viewtopic.php?id=144089 forum].<br />
<br />
==== Mid 2011 — version 4,x ====<br />
<br />
Works out-of-the-box since kernel 3.2. It is recommended to use [[Archboot]], install [[GRUB]] and use EFI.<br />
<br />
==== Early 2008 — version 1,1 ====<br />
<br />
Everything works out of the box though you will need {{Pkg|b43-fwcutter}} (or simply {{AUR|b43-firmware}}) for the wireless adapter to work.<br />
<br />
Since this model has only one USB port, you may find it easiest to install Arch with a powered USB hub. Plug a USB network adapter (wireless or ethernet adapter to plug into a USB port) and your Arch installation media into the USB hub.<br />
<br />
If you can't get any result by scanning wireless network after boot, unload modules <code>b43</code> and <code>ssb</code> and load them again:<br />
<br />
rmmod ssb<br />
rmmod b43<br />
modprobe b43<br />
<br />
There is a good chance you will find what's wrong with DMA from the dmesg log.<br />
<br />
Even if you can scan wireless networks after reloading the modules, it's still possible that you will only be able to connect to some networks, but not all of them. According to a more detailed discussion here: http://crunchbang.org/forums/viewtopic.php?id=17368, adding <code>pio=1,qos=0</code> options to the b43 module can solve this problem.<br />
<br />
I tested this for a 13' MacBookAir1,1 with a BCM4321 chipset, and it works.<br />
<br />
== See also ==<br />
* '''MacBook Air'''<br />
** [http://dabase.com/blog/Macbook_Air_Early_2014_Archlinux/ Macbook Air Early 2014 — dabase.com]<br />
** [http://www.frankshin.com/installing-archlinux-on-macbook-air-2013/ Installing Archlinux on Macbook Air 2013 — Frank Shin]<br />
** [http://blog.panks.me/posts/2013/06/arch-linux-installation-with-os-x-on-macbook-air-dual-boot/ Arch Linux Installation with OS X on Macbook Air (Dual Boot) — Pankaj Kumar]<br />
** [http://ryangehrig.com/index.php/arch-linux-on-macbook-air-2013/ Arch Linux – MacBook Air 2013 — Ryan Gehrig]<br />
** [http://www.nico.schottelius.org/blog/macbook-air-42-archlinux/ Installing Linux on a Macbook Air (4,2) — Nico Schottelius]<br />
** [http://www.dm9.se/?p=398 Arch linux single, pure efi boot on the macbook air3,1/3,2 — DIMENSION9]<br />
* '''MacBook Pro'''<br />
** http://www.netsoc.tcd.ie/~theorie/interblag/2010/01/30/installing-arch-linux-on-a-mac-pro/<br />
** http://allanmcrae.com/2010/04/installing-arch-on-a-macbook-pro-5-5/<br />
** http://allanmcrae.com/2012/04/installing-arch-on-a-macbook-pro-8-1/<br />
** http://linux-junky.blogspot.com/2011/08/triple-boot-archlinux-windows-7-and-mac.html</div>X33ahttps://wiki.archlinux.org/index.php?title=Mac&diff=456365Mac2016-11-08T15:46:49Z<p>X33a: /* Arch Linux with OS X or other operative systems */ fix typo</p>
<hr />
<div>[[Category:Apple]]<br />
[[de:ArchLinux auf einem MacBook]]<br />
[[fr:MacBook]]<br />
[[it:MacBook]]<br />
[[ja:MacBook]]<br />
[[zh-CN:MacBook]]<br />
{{Related articles start}}<br />
{{Related|Installation guide}}<br />
{{Related|General recommendations}}<br />
{{Related|MacBook4,2 (late 2008)}}<br />
{{Related|MacBook5,2 (early-mid 2009)}}<br />
{{Related|MacBookPro7,1}}<br />
{{Related|MacBookPro8,1/8,2/8,3 (2011)}}<br />
{{Related|MacBookPro9,2 (Mid-2012)}}<br />
{{Related|MacBookPro10,x}}<br />
{{Related|MacBookPro11,x}}<br />
{{Related|iMac Aluminum}}<br />
{{Related|Apple Fusion Drive}}<br />
{{Related articles end}}<br />
<br />
Installing Arch Linux on a MacBook (12"/Air/Pro) or an iMac is quite similar to installing it on any other computer. However, due to the specific hardware configuration of a Mac, there are a few deviations and special considerations which warrant a separate guide. For more background information, please see the [[Installation guide]] and [[UEFI]]. This guide contains installation-instructions that can be used on any Apple computer whose hardware is supported by the Linux kernel. Please see 'related' pages (on the top right of this page) for model-specific tips and troubleshooting.<br />
<br />
== Overview ==<br />
<br />
Specifically, the procedure for installing Arch Linux on a MacBook is:<br />
<br />
# '''[[#Firmware updates | Firmware updates]]''': It always helps to start from a clean, backed up, and up-to-date install of OS X.<br />
# '''[[#Partitions|Partition]]''': Resizing or deleting the OS X partition to create partitions for Arch Linux.<br />
# '''[[#Setup bootloader|Setup bootloader]]''': Making sure that the new partition is bootable.<br />
# '''[[#Installation|Install Arch Linux]]''': Actually installing Arch Linux.<br />
# '''[[#Post-installation|Post-installation]]''': MacBook-specific configuration.<br />
<br />
== Firmware updates ==<br />
<br />
Before proceeding with the installation of Arch Linux, it is important to ensure that the latest firmware updates for you MacBook are installed. This procedure requires OS X.<br />
In OS X, open the App Store and check for updates. If your mac finds and installs any updates, make sure to '''reboot''' your computer, and then check again for updates to make sure that you installed everything.<br />
<br />
{{Note|If you uninstalled OS X or want to reinstall it, [https://support.apple.com/en-us/HT204904 Apple] has great instructions.}}<br />
<br />
It is advisable to keep OS X installed, because MacBook firmware updates can only be installed using OS X. However, if you plan to remove OS X completely, make backups of these files, which you will need in Linux for adjusting the [[#Color Profile|color profile]]:<br />
/Library/ColorSync/Profiles/Displays/*<br />
<br />
Continue to [[#Partitions]]<br />
<br />
== Partitions ==<br />
<br />
Partitioning of the storage drive is no different from any other laptop. However, if you plan on keeping OS X for dual booting, you should consider that, by default, a MacBook's drive is formatted using GPT and contains at least 3 partitions:<br />
<br />
* '''EFI''': the ~200 MB [[EFI System Partition]].<br />
* '''OS X''': the main partition containing your OS X installation. It is formatted using [[File_systems|HFS+]].<br />
* '''Recovery''': A recovery partition present in almost all MacBooks running OS X 10.7 or newer. It is usually hidden from OS X but can be viewed with partitioning tools.<br />
<br />
{{Note|In Macs that use the [[Apple Fusion Drive]], the partition scheme could be different.}}<br />
<br />
How to partition depends on how many operating systems you want install. The following options will be explained:<br />
<br />
* Single boot: [[#Arch Linux only]]<br />
* Dual boot: [[#OS X with Arch Linux]] ''(recommended so you can still return to OS X when needed)''<br />
* Triple boot: [[#OS X, Windows XP, and Arch Linux triple boot]]<br />
<br />
<br />
=== Arch Linux only ===<br />
<br />
This situation is the easiest to deal with. Partitioning is the same as any other hardware that Arch Linux can be installed on. Please refer to the standard [[Installation_guide|Installation guide]] for details.<br />
<br />
{{Note|It is advisable to '''disable''' the MacBook startup sound before proceeding with partitioning. Just boot in OS X, mute your system sound and reboot again to the Arch Linux Installation media. Please keep in mind that the volume of the startup sound can only be modified reliably in OS X.}}<br />
<br />
If you want to configure you system in order to have full-disk encryption, please look at the [https://wiki.archlinux.org/index.php/Dm-crypt/Encrypting_an_entire_system following] page for details.<br />
<br />
An example for a very basic partitioning, that does not consider a separate {{ic|/home}} partition nor encryption or LVM, is the following:<br />
partition mountpoint size type label<br />
/dev/sda1 /boot 200MiB vfat EFI<br />
/dev/sda2 /swap adjust swap swap<br />
/dev/sda3 / remain ext4 root<br />
<br />
* Done, you can continue to [[#Installation]]<br />
<br />
<br />
=== Arch Linux with OS X or other operating systems ===<br />
<br />
You need to partition your hard drive while keeping the partitions used for OS X/Windows. If you wish to keep OS X, the easiest way is to use partitioning tools in OS X and then finish with Arch Linux tools.<br />
<br />
{{Warning| If you OS X partition is encrypted with FileVault 2, you '''must''' disable the disk encryption before proceeding. After the OS X partition has been resized, FileVault 2 can be re-enabled.}}<br />
<br />
'''Procedure''':<br />
* In OS X, run ''Disk Utility.app'' (located in {{ic|/Applications/Utilities}})<br />
* Select the drive to be partitioned in the left-hand column (not the partitions!). Click on the '''Partition''' button.<br />
* Add a new partition by pressing the '''+''' button and choose how much space you want to leave for OS X, and how much for the new partition. Keep in mind the new partition will be formatted in Arch Linux, so you can choose any partition type you want. <br />
* If the above completed successfully, then you can continue. If not, then you may need to fix your partitions from within OS X first.<br />
* Boot the Arch installation media or [[USB flash installation media|LiveUSB]] by holding down the {{ic|Alt}} '''during boot'''. Proceed with [[#Installation]].<br />
<br />
It is possible to resize the newly created partition from within the Arch installation media, or delete it in order to proceed with the creation of other partitions (eg. swap).<br />
<br />
{{Tip|Instead of cluttering your drive with different partition, it is possible to use a [[Swap#Swap file|swapfile]] instead of a dedicated partition. Another solution can be setting up [[LVM]] in order to use the newly-created partition as a container. Please refer to the linked articles.}}<br />
<br />
<br />
==== Option 1: EFI ====<br />
<br />
* Run ''cgdisk''<br />
<br />
* Delete the partition you made in ''Disk Utility.app'' and create the necessary partitions for Arch Linux. OS X likes to see a 128 MiB gap after partitions, so when you create the first partition after the last OS X-partition, type in '''+128M''' when cgdisk asks for the first sector for the partition. More information about Apple's partitioning policy can be read [https://developer.apple.com/library/mac/technotes/tn2166/_index.html#//apple_ref/doc/uid/DTS10003927-CH1-SUBSECTION5 here]. A simple example (no LVM, crypto):<br />
<br />
{{Note|<br />
* The swap partition is optional on machines with 4GB of RAM or more. A '''[[swap file]]''' can be created later.<br />
* The easiest dual-boot option is to install rEFInd from inside OS X, to its root directory (default for {{ic|install.sh}}). Following that, copy the driver folder from the installation tarball into the new rEFInd location, and uncomment the lines ''"scan_all_linux_kernels"'' and ''"also_scan_dirs"'' options in {{ic|refind.conf}}. Configuration of boot options can then be done from a {{ic|refind_linux.conf}} in Arch's {{ic|/boot}} directory.<br />
* If you want to be able to boot GRUB from the Apple boot loader, you can create a small hfs+ partition (for convenience, use OS X to format it in ''Disk Utility.app'' afterwards). Follow the GRUB EFI install procedure, and mount your {{ic|/boot/efi}} directory to the hfs+ partition you created. Finally, finish up again in OS X by blessing the partition. This will set GRUB as the default boot option (holding alt at startup goes to the mac boot options screen still. See http://mjg59.dreamwidth.org/7468.html).,<br />
* OS X's EFI partition can be shared with Arch Linux, making the creation of an additional EFI partition dedicated to Arch completely optional.<br />
}}<br />
<br />
{{Note|For more information on partitioning, see [[Partitioning]]}}<br />
partition mountpoint size type label<br />
/dev/sda1 /boot/efi 200MiB vfat EFI<br />
/dev/sda2 - ? hfs+ OS X<br />
/dev/sda3 - ? hfs+ Recovery<br />
/dev/sda4 - 100MiB hfs+ Boot Arch Linux from the Apple boot loader (optional)<br />
/dev/sda5 /boot 100MiB boot boot<br />
/dev/sda6 - ? swap swap (optional)<br />
/dev/sda7 / 10GiB ext4 root<br />
/dev/sda8 /home remaining ext4 home<br />
<br />
* Done, you can continue to [[#Installation]]<br />
<br />
==== Option 2: BIOS-compatibility ====<br />
<br />
* Run ''parted'' as root.<br />
<br />
* Delete the empty space partition and partition the space as you would for any other installation. Note that MBR is limited to 4 primary partitions (including the efi partition). That leaves 2 primary partitions for Arch. One strategy is to have a system and home partition, and use a swap file (I have not tried to use logical partitions). Another is to dedicate one partition to a shared partition (see below).<br />
<br />
* Next, create new filesystems on those partitions which need them, especially the partition which will contain {{ic|/boot}}. If you are not sure how to do this using {{ic|mkfs.ext2}} (or whatever), run {{ic|/arch/setup}} and work through until you get to Prepare Hard Drive and use the ''"Manually configure block devices..."'' option, then exit the installer. This is necessary so that rEFIt will set the right partition type in the MBR in the next step (without an existing filesystem, it seems to ignore the partition type set by parted), without which GRUB will refuse to install to the right partition.<br />
<br />
* At this point you should reboot your computer and have rEFIt fix the partition tables on your hard drive. (If you do not do this, you may have to reinstall GRUB later on in order to have your Mac recognize the Linux partition.) When you are into the rEFIt menu, select '''update partition table''', then press {{ic|y}}. Reboot.<br />
<br />
* Done, you can continue with [[#Installation]].<br />
<br />
=== OS X, Windows XP, and Arch Linux triple boot ===<br />
<br />
This may not work for everyone but it has been successfully tested on a MacBook from late 2009.<br />
<br />
The easiest way to partition your hard drive, so that all these operating systems can co-exist, is to use disk utility in OS X, use the formatter on windows XP, install XP and then finish with Arch Linux tools.<br />
<br />
{{Warning|It is highly recommended that this only be attempted after a clean install of OS X. Using these methods on a pre-existing system may have undesired results. At least back your stuff up with timemachine or clonezilla before you begin.}}<br />
<br />
'''Procedure''':<br />
* In OS X, run '''Disk Utility''' (located in {{ic|/Applications/Utilities}}).<br />
<br />
* Select the drive to be partitioned in the left-hand column (not the partitions!). Click on the '''partition''' tab on the right.<br />
<br />
* Select the volume to be resized in the '''volume scheme.'''<br />
<br />
* Decide how much space you wish to have for your OS X partition, how much for XP, and how much for Arch Linux. Remember that a typical installation of OS X requires around 15-20 GiB, and XP about the same, depending on the number of software applications and files. Something like OS X 200Gb, XP 25Gb, Arch 25Gb should be fine.<br />
<br />
* Put your decisions into action by pressing the + button and adding the new partitions, Label them as you like and make sure that your XP partition is the last one on the disk and is formatted for FAT32. It is probably best to have Arch formatted in HFS format as to not confuse you later, it will be reformatted anyway.<br />
<br />
So in linux terms your partitions will be something like:<br />
<br />
:*sda (disk)<br />
:*sda1 (Mac boot partition - you cannot see this one in OS X)<br />
:*sda2 (OS X install in HFS+)<br />
:*sda3 (Arch install temporarly in HFS)<br />
:*sda4 (XP install in FAT32)<br />
<br />
* Finally, click '''apply'''. This will create a new partition out of the empty space.<br />
<br />
{{Note|Using this method you may not be able to have a shared partition between OS X and Arch Linux, this is because the mac will only allow for 4 active partitions. You will however be able to mount a HFS partition in Arch for one workaround. There are other workarounds possible also.}}<br />
<br />
* If the above completed successfully, you can continue. If not, then you may need to fix your partitions from within OS X first.<br />
<br />
* You will not be needing boot camp this way, the program rEFIt is much more flexible (though not as flexible as GRUB). Download and install rEFIt [http://refit.sourceforge.net/]<br />
<br />
* Go into a terminal in OS X and perform the following, this will enable the rEFIt boot manager. <br />
<br />
cd /efi/refit<br />
./enable.sh<br />
<br />
* Reboot to check the rEFIt is working, it should appear on boot. When it comes up go to the rEFIt partition manager and agree to the changes.<br />
<br />
* Put your XP install CD and boot it with rEFIt - You may have to reboot a few times until it is recognized by the boot loader. Install XP and once it is installed use the OS X installation CD to get your drivers running nicely in XP.<br />
** Note: when installing XP make sure you select your XP partition and format it again inside the XP installer. If you do not reformat it will not work.<br />
<br />
* Boot the Arch install CD, log in as root and run {{ic|# /arch/setup}}.<br />
<br />
* Follow the install as normal but note that you will have to tell that arch installer to mount sda3 as the root partition and format it as ext3, there will not be a /boot or swap partition so ignore those warnings.<br />
<br />
* At this point, if you are dual booting, you should reboot your computer and have rEFIt fix the partition tables on your hard drive. (If you do not do this, you may have to reinstall GRUB later on in order to have your Mac recognize the Linux partition.) When you are into the rEFIt menu, select '''update partition table''', then press Y.<br />
# reboot<br />
<br />
* Done! You can continue to [[#Installation]] but make sure you read [[#Booting directly from GRUB]]{{Broken section link}} for the stage "* (for booting with EFI) After the install boot loader stage, exit the installer and install GRUB."<br />
<br />
== Setup bootloader ==<br />
<br />
=== Using the native Apple bootloader with systemd-boot (Recommended) ===<br />
<br />
Apple's native EFI bootloader reads {{ic|.efi}} files located inside the [[EFI System Partition]] at {{ic|/EFI/BOOT/BOOTX64.EFI}}. Luckly, this is also the default install location the [[systemd-boot]] binary. This means that booting linux using ''systemd-boot'' is very simple.<br />
* First, make sure you mounted the EFI System Partition at {{ic|/boot}}<br />
* Proceed with [[#Installation]] normally<br />
* Once inside the chrooted enviroment, type the following command to install ''systemd-boot'':<br />
{{bc|1=# bootctl --path=/boot install}}<br />
The above command will copy the ''systemd-boot'' binary to {{ic|/boot/EFI/Boot/BOOTX64.EFI}} and add ''systemd-boot'' itself as the default EFI application (default boot entry) loaded by the EFI Boot Manager. <br />
* Proceed to [[systemd-boot#Configuration]] in order to correctly set up the bootloader<br />
At the next reboot, the Apple Boot Manager, shown when holding down the option key when booting the MacBook, should display Arch Linux (it will be displayed as {{ic|EFI Boot}} as a possible boot option.<br />
{{Tip|If you installed Arch Linux alongside OS X, you will be able to change the default boot location from system Settings inside OS X. If Arch Linux does not show up as a possible boot option, you will have to mount the EFI System Partition inside OS X before selecting your boot option:<br />
{{bc|$ diskutil mount disk0s1}}<br />
}}<br />
<br />
=== Using the native Apple bootloader with GRUB ===<br />
<br />
Despite using UEFI, the MacBook's native EFI bootloader [http://refit.sourceforge.net/myths/ does not use the EFI partition for booting]. Instead, it looks for .efi files inside all the partitions in internal and external drives and shows them as possible boot options if certain conditions are satisfied. For example, MacBooks can detect an existing OSX installation after checking that:<br />
* there is a partition formatted as HFS+<br />
* the partition contains the partition id {{ic|af00}} <br />
* in the root of that partition, there is a file called {{ic|mach_kernel}}<br />
* inside that partition, there a {{ic|boot.efi}} file inside {{ic|/System/Library/CoreServices}}<br />
<br />
This means that configuring an Arch installation to be automatically recognized by the MacBook bootloader is possible. Moreover, it simply requires a properly-formatted HFS+ {{ic|/boot}} partition and does not require meddling with the EFI system partition. The advantage of this method is that it can coexist with OS X nicely and allows to avoid other bootloaders such as rEFInd. However, this requires manual configuration. The following steps will illustrate how to perform this configuration using GRUB.<br />
* First, while configuring a new Arch installation, create a separate {{ic|/boot}} partition. Many tools are available in the Arch ISO, for example '''cgdisk'''.<br />
* Make sure the partition is at least ~250 MB in size, since it will be used to store the kernel as well as any custom kernel you will install in the future. Moreover, make sure the partition type is set as Apple HFS/HFS+ (it will appear as {{ic|Apple HFS/HFS+}} in fdisk/cgdisk or {{ic|af00}} in gdisk)<br />
* Since the Arch installation ISO does not include the package {{Pkg|hfsprogs}}, we need to install it in the installation environment before proceeding with formatting the new partition as HFS+<br />
# pacman -Sy hfsprogs<br />
# modprobe hfsplus<br />
# mkfs.hfsplus /dev/sd'''X''' -v "Arch Linux"<br />
<br />
Note: replace /dev/sd'''X''' with the correct device as appropriate<br />
<br />
* Done, proceed with [[#Installation]]<br />
<br />
{{Warning|<br />
Once inside the chrooted enviroment, don’t forget to install {{Pkg|hfsprogs}} on the newly installed system as well. After the installation of the package, regenerate the initramfs while chrooted<br />
# mkinitcpio -p linux<br />
}}<br />
<br />
* Once inside the chrooted enviroment, install the {{Pkg|grub}} and {{Pkg|efibootmgr}} packages. The following steps install the GRUB UEFI application to {{ic|/boot/EFI/arch/System/Library/CoreServices/boot.efi}} and install its modules to {{ic|/boot/grub/x86_64-efi}}.<br />
# grub-install --target=x86_64-efi --efi-directory=/boot<br />
<br />
After that, remember to create a standard configuration file:<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
As you can see, the directory structure of the {{ic|boot.efi}} is not correct, as the {{ic|/System/Library/CoreServices}} directory is not supposed to be a subdirectory of the {{ic|/boot/EFI/}} folder. For this reason, we need to relocate the {{ic|boot.efi}} stub in a location the MacBook bootloader is able to recognize:<br />
# mv /boot/EFI/arch/System/ /boot/<br />
# rm -r /boot/EFI/<br />
<br />
Also, create a dummy {{ic|mach_kernel}} file<br />
# touch /boot/mach_kernel<br />
<br />
After that, you need to create the following file <br />
<br />
{{hc|1=# nano /boot/System/Library/CoreServices/SystemVersion.plist|2=<br />
<?xml version="1.0" encoding="UTF-8"?><br />
<plist version="1.0"><br />
<dict><br />
<key>ProductBuildVersion</key><br />
<string></string><br />
<key>ProductName</key><br />
<string>Linux</string><br />
<key>ProductVersion</key><br />
<string>Arch Linux</string><br />
</dict><br />
</plist><br />
}}<br />
<br />
At the next reboot, the Apple Boot Manager, shown when holding down the option key when booting the MacBook, should display Arch Linux as a possible boot option. Selecting that option will boot GRUB.<br />
<br />
Done! GRUB can now be selected on the standard MacBook bootloader and you can boot into your newly installed Arch Linux.<br />
<br />
{{Tip| After the installation, it is optionally possible to set a custom icon that will be displayed in the MacBook boot loader. In order to do that, you need to install the {{Pkg|wget}}, {{Pkg|librsvg}} and {{AUR|libicns}} packages. After that, just follow the following commands:<br />
$ wget -O /tmp/archlinux.svg https://www.archlinux.org/logos/archlinux-icon-crystal-64.svg<br />
$ rsvg-convert -w 128 -h 128 -o /tmp/archlogo.png /tmp/archlinux.svg<br />
$ sudo png2icns /boot/.VolumeIcon.icns /tmp/archlogo.png<br />
$ rm /tmp/archlogo.png<br />
$ rm /tmp/archlinux.svg<br />
Obviously, you can replace the Arch logo with any other icon you like.<br />
}}<br />
<br />
<br />
=== Other methods ===<br />
<br />
{{Out of date | Section that describes bootloader setup for other setups should be revised and re-structured into more readable way}}<br />
{{Tip|rEFIt is a popular bootloader for EFI-firmware computers (including Macs). It can be installed at any time during the installation. For instructions, please see [[#rEFIt]]. }}<br />
<br />
If you are going for an Arch Linux-only setup, installing the bootloader is no different than on any other machine: Install [[systemd-boot]], [[rEFInd]] or other bootloader of your choice.<br />
<br />
If, on the other hand, you are dual/triple booting, then read on.<br />
<br />
<br />
=== Installing GRUB to EFI partition directly ===<br />
<br />
* If you would like to use GRUB as your main bootloader and use the "boot while holding the Alt/Option key" method to go back to OS X rather than using alternatives such as rEFIt (http://refit.sourceforge.net/, mentioned previously in [[#BIOS-compatibility]]{{Broken section link}} and [[#OS X, Windows XP, and Arch Linux triple boot]]) then you must install {{Pkg|grub}} to your Mac's '''already-existing''' EFI partition (see below). <br />
<br />
{{Note| These instructions are known to work on a MacBook Pro (Early 2011). Please read the procedure carefully '''as well as the details following it'''.}}<br />
<br />
{{Note| With a new MacBook Pro (Mid 2014), this procedure worked only after installing the<br />
{{Pkg|efibootmgr}} package.}}<br />
<br />
'''Procedure''':<br />
<br />
* Install {{Pkg|grub}}<br />
<br />
* Make a directory named {{ic|efi}} in {{ic|/boot}} <br />
<br />
* Mount the '''already-existing''' EFI partition on your Mac to this {{ic|/boot/efi}} directory<br />
<br />
* Install GRUB to this directory<br />
<br />
* Make a directory named {{ic| locale}} in {{ic| /boot/grub}}<br />
<br />
* Copy {{ic| grub.mo}} from {{ic| /usr/share/locale/en\@quot/LC_MESSAGES/}} to {{ic| /boot/grub/locale}} <br />
<br />
* Generate a configuration for GRUB<br />
<br />
* Done! GRUB will now start on reboot and you can boot into your newly installed Arch Linux.<br />
<br />
* Remember to hold ALT/Option key '''while''' starting your computer if you want to boot back into OS X.<br />
<br />
'''Details (quoted from [[GRUB EFI Examples#M5A97]]):'''<br />
<br />
Finish the standard Arch install procedures, making sure that you install {{Pkg|grub}} and partition your boot hard disk as GPT.<br />
<br />
From [[GRUB#Install_to_UEFI_system_partition]]{{Broken section link}}:<br />
<br />
The UEFI system partition will need to be mounted at {{ic|/boot/efi/}} for the GRUB install script to detect it:<br />
<br />
# mkdir -p /boot/efi<br />
# mount -t vfat /dev/sdXY /boot/efi<br />
<br />
Where X is your boot hard disk and Y is the efi partition you created earlier.<br />
<br />
Install GRUB UEFI application to and its modules to {{ic|/boot/grub/x86_64-efi}} using:<br />
<br />
# modprobe dm-mod<br />
# grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=arch_grub --recheck --debug<br />
# mkdir -p /boot/grub/locale<br />
# cp /usr/share/locale/en\@quot/LC_MESSAGES/grub.mo /boot/grub/locale/en.mo<br />
<br />
Generate a configuration for GRUB<br />
<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
=== Using blessing ===<br />
<br />
It is possible to boot directly from GRUB in EFI mode without using rEFIt through what is known as "blessing" after placing GRUB on a '''separate partition'''. These instructions are known to work on a MacBook7,1. It is advisable to host GRUB on either a FAT32 or HFS+ partition, but ext2 or ext3 may also work. GRUB's appleloader command does not currently work with the 7,1, but support can be added with the patch available [https://savannah.gnu.org/bugs/index.php?33185 here].<br />
<br />
After the GRUB install is in the desired location, the firmware needs to be instructed to boot from that location. This can be done from either an existing OS X install or an OS X install disk. The following command assumes that the GRUB install is in {{ic|/efi/grub}} on an existing OS X partition:<br />
# bless --folder /efi/grub --file /efi/grub/grub.efi<br />
<br />
=== Compilation ===<br />
<br />
Some models may need EFI_ARCH set to i386.<br />
bzr branch --revision -2 bzr://bzr.savannah.gnu.org/grub/trunk/grub grub<br />
cd grub<br />
./autogen.sh<br />
patch -p1 < appleloader_macbook_7_1.patch<br />
export EFI_ARCH=x86_64<br />
./configure --with-platform=efi --target=${EFI_ARCH} --program-prefix=""<br />
make<br />
cd grub-core<br />
../grub-mkimage -O ${EFI_ARCH}-efi -d . -o grub.efi -p "" part_gpt part_msdos ntfs ntfscomp hfsplus fat ext2 normal chain boot configfile linux multiboot<br />
cp grub.efi *.mod *.lst yourinstalllocation<br />
<br />
== Installation ==<br />
<br />
{{Note|This section is only required if you want to have OS X installed along with Arch Linux. If not, follow the steps in the official install guide, then skip to [[#Post-installation]].}}<br />
<br />
* Boot from the Arch Linux install CD, from the latest [[Archboot]] iso (unofficial), or from a [[USB flash installation media#Using manual formatting|manually created]] bootable USB drive.<br />
{{Note|<br />
* On a MacBookPro7,1, I had an error booting the installation media Version 2012.12.01: "unable to handle kernel NULL pointer dereference at 0000000000000010" during pacpi_set_dmamode. To fix this problem, boot with the option: acpi&#61;off. After chrooting, add MODULES&#61;"ata_generic" into /etc/mkinitcpio.conf and execute mkinitcpio -p linux, see: [[Installation guide#Configure_the_system|Installation Guide, 9 Configure the system]].<br />
* Some MacBook users report strange keyboard output such as long delays and character doubling. To fix this problem, boot with the following options: arch noapic irqpoll acpi&#61;force}}<br />
<br />
* Proceed through the installation as described in the [[Installation guide]] '''except''' in the following areas:<br />
** Skip the [[Installation guide#Partition the disks|partition the disks]] stage, do only the [[Installation guide#Format the partitions|partition formatting]] and [[Installation guide#Mount the partitions|mounting]] steps, taking care to assign the correct partitions. Partitions have already been created if you followed [[#Partitions]]<br />
** '''(for booting with EFI''') After the [[Installation guide#Boot_loader|install boot loader]] stage, exit the installer and install [[GRUB]].<br />
** '''(for booting with BIOS-compatibility)''' In the [[Installation guide#Boot_loader|install boot loader]] stage, edit the menu.lst file and add '''reboot=pci''' to the end of the '''kernel''' lines, for example: {{bc|1=kernel /vmlinuz26 root=/dev/sda5 ro reboot=pci}} This will allow your MacBook to reboot correctly from Arch.<br />
** '''(for booting with BIOS-compatibility)''' Also in the [[Installation guide#Install a boot loader|install boot loader]]{{Broken section link}} stage, install GRUB on whatever partition that {{ic|/boot}} is on. {{Warning|Do not install GRUB onto ''/dev/sda'' !!! Doing so is likely to lead to an unstable post-environment.}}<br />
** In the [[Installation guide#Configure the system|configure system]] stage, edit /etc/mkinitcpio.conf and ensure the '''keyboard''' hook is in the '''HOOKS''' line somewhere after the '''autodetect''' hook. This will load the drivers for your keyboard in case you need to use it before Arch boots (e.g. entering a [[LUKS]] password or using the troubleshooting shell).<br />
<br />
* When the install process is complete, reboot your computer.<br />
<br />
* If using optical media, hold down the eject key as your MacBook starts, this should eject the Arch Linux install disk.<br />
<br />
* If dual-booting OS X and Arch Linux, hold down the alt (option) key while the system boots to use the Mac bootloader to select which OS to boot.<br />
<br />
== Post-installation ==<br />
<br />
{{Style|Duplicated information, does not comply with [[Help:Style]].}}<br />
<br />
See [[General recommendations]] for system management directions and post-installation tutorials like setting up a graphical user interface, sound or a touchpad.<br />
<br />
==== Video ====<br />
<br />
Different MacBook models have different graphic cards.<br />
To see which graphics card you have type:<br />
<br />
$ lspci | grep VGA<br />
<br />
* If it returns a string containing '''intel''', read [[Intel graphics]].<br />
<br />
* If it returns '''nVidia''', read [[NVIDIA]].<br />
<br />
* Otherwise if it returns '''ATI''' or '''AMD''', read [[ATI]].<br />
<br />
===== NVIDIA note =====<br />
<br />
{{Tip|If you have installed OS in EFI mode and NVIDIA binary drivers are working only in BIOS mode (e.g. you get black screen on EFI boot), try this approach: http://askubuntu.com/a/613573/492886 }}<br />
<br />
For MacBooks with NVIDIA graphics, for the backlight to work properly you may need the {{AUR|nvidia-bl}} package.<br />
<br />
{{Tip|<br />
* If backlight control does not work after installing nvidia-bl, you should [[blacklist]] apple_bl kernel module.<br />
* If backlight control does not work even this way, try setting module parameters, e.g. {{ic|1=options nvidiabl screen_type=3 min=0 max=44000}} in {{ic|/etc/modprobe.conf}} in case of MacBook Air 3.2<br />
* Alternatively, you can choose to use the {{AUR|pommed-light}} package. If you do so, you may wish to change the step settings in {{ic|/etc/pommed.conf.mactel}} to something around 5000-10000 depending on how many levels of brightness you desire. The max brightness is around 80000, so take that into account.}}<br />
<br />
==== Touchpad ====<br />
<br />
The touchpad should have basic functionality by default. A true multitouch driver which behaves very similarly to native OS X is included in the {{AUR|xf86-input-multitouch-git}}{{Broken package link|{{aur-mirror|xf86-input-multitouch-git}}}} package. It supports 1, 2 and 3 finger gestures, including differentiation between horizontal and vertical 3 finger swipe. Additional details are available at [http://bitmath.org/code/multitouch/ the driver's project page].<br />
<br />
xf86-input-multitouch-git does not support any sort of configuration without editing the driver's source. Some users are also experiencing issues with false clicks from palm touches. There is now a much more configurable fork available as {{AUR|xf86-input-mtrack-git}}. Configuration options are documented in the [https://github.com/BlueDragonX/xf86-input-mtrack readme].<br />
<br />
The following mtrack options work well on a MacBook7,1:<br />
<br />
Option "Thumbsize" "50"<br />
Option "ScrollDistance" "100"<br />
<br />
Probably you need also to add:<br />
<br />
MatchDevicePath "/dev/input/event10"<br />
<br />
To disable tap-to-click (that is, to press down to click) by default, add the following to your mtrack configuration section<br />
<br />
Option "TapButton1" "0" <br />
Option "TapButton2" "0"<br />
Option "TapButton3" "0"<br />
<br />
'''Natural scrolling:''' To configure natural two finger scrolling similar to [http://www.apple.com/au/osx/what-is/gestures.html#gallery-gestures-scroll OS X], refer to [[Touchpad Synaptics#Natural scrolling]]. If you are using GNOME, it will override these settings - in this case refer to [[GNOME#Natural_scrolling_touchpad]]{{Broken section link}}.<br />
<br />
If you are using {{AUR|xf86-input-mtrack-git}}, you can simply swap the scroll up and scroll down buttons (along with the scroll left and scroll right):<br />
{{hc|/etc/X11/xorg.conf.d/10-mtrack.conf|<br />
...<br />
Option "ScrollUpButton" "5"<br />
Option "ScrollDownButton" "4"<br />
Option "ScrollLeftButton" "7"<br />
Option "ScrollRightButton" "6"<br />
...}}<br />
<br />
<br />
'''Special Note About Older Macbook Models (confirmed on MacBook2,1):''' On older Macbook models (pre-multitouch), the touchpad will not function properly until you install the xf86-input-synaptics package. Please see [[Touchpad Synaptics]] for more information on installing and configuring this package.<br />
<br />
'''Note on MacBookPro5,5:''' I found it is much simpler to use the {{Pkg|xf86-input-synaptics}} in Extra. Although it does not have much function as 3 finger swipe, this driver provides faster response. {{Pkg|gpointing-device-settings}} also provides a simple GUI config. Below is a Xorg config file /etc/X11/xorg.conf.d/60-synaptics.conf for reference only.<br />
Section "InputClass"<br />
Identifier "touchpad catchall"<br />
Driver "synaptics"<br />
MatchIsTouchpad "on"<br />
MatchDevicePath "/dev/input/event*"<br />
Option "SHMConfig" "on"<br />
Option "TapButton1" "1"<br />
Option "TapButton2" "3"<br />
Option "TapButton3" "2"<br />
Option "PalmDetect" "on"<br />
Option "VertEdgeScroll" "off"<br />
Option "HorizEdgeScroll" "off"<br />
Option "CornerCoasting" "off"<br />
Option "EdgeMotionUseAlways" "off"<br />
Option "AreaLeftEdge" "10"<br />
Option "AreaRightEdge" "1270"<br />
EndSection<br />
'''For some users, the two-finger right-click may not work correctly and trackpad may also become less responsive after these settings. For me, removing the 'AreaLeftEdge' and 'AreaRightEdge', solved that problem.'''<br />
'''OS X like MultiTouch Gestures''' ''currently broken due to newer synaptic drivers!'' For users looking to add more of OS X's multitouch gestures to Arch, [https://github.com/iberianpig/xSwipe xSwipe] is a highly customisable, light weight perl script, which does just that. Once installed and configured (see xSwipe wiki on Github) I would recommend adding xSwipe as a [[Autostarting|start up item]].<br />
<br />
==== Keyboard ====<br />
<br />
MacBook keyboards work by default. For swaping fn keys with Fx keys see [[Apple Keyboard]].<br />
<br />
To enable it you can map with right application like '''xbindkeys''' or through DE preferences; but another very good way, that we recommend, is to install the {{AUR|pommed}}{{Broken package link|{{aur-mirror|pommed}}}} package.<br />
<br />
Edit the {{ic|/etc/pommed.conf}} according to your hardware on MacBook, building it from {{ic|/etc/pommed.conf.mac}} or {{ic|/etc/pommed.conf.ppc}} example files.<br />
<br />
Note that you can also run it without a configuration file, the defaults may work for you. Then [[enable]] and start {{ic|pommed.service}}.<br />
<br />
{{Tip|if you are using Gnome or KDE you can easily configure ''3rd level functionality'', ''multimedia key'', etc. in Keyboard Preferences.}}<br />
<br />
{{Note|See the [[Xorg input hotplugging]] page for other configuration information.}}<br />
<br />
===== Keyboard Backlight =====<br />
<br />
The keyboard backlight is controlled by {{ic|/sys/class/leds/smc::kbd_backlight}}. Write the desired value to {{ic|brightness}} in that directory.<br />
<br />
You may also use {{AUR|kbdlight}} to control keyboard backlight though scripts or by running it via [[sxhkd]]. It has the advantage of allowing keyboard light-level changes without being root.<br />
<br />
====== NVIDIA note ======<br />
<br />
If the brightness does not function correctly through pommed, make sure you have installed the {{AUR|nvidia-bl}} package and insert<br />
<br />
find . -name "*" -exec sed -i 's/mbp_backlight/nvidia_backlight/' '{}' \;<br />
<br />
into the second line of the pommed PKGBUILD build() function and remake the package. From [https://bbs.archlinux.org/viewtopic.php?id=105091 this forum post].<br />
<br />
Another possible solution is to modify the pommed PKGBUILD build():<br />
<br />
find . -name "*" -exec sed -i 's/nvidia_backlight/apple_backlight/' '{}' \;<br />
<br />
If the previous does not work try the following,<br />
<br />
run nvidia-settings, edit the file '/etc/X11/xorg.conf' and add this line into the Device section:<br />
<br />
Option "RegistryDwords" "EnableBrightnessControl=1"<br />
Save and reboot and check backlight buttons work.<br />
More information available at [https://help.ubuntu.com/community/MacBookPro5-5/Precise#LCD Ubuntu MacBookPro5,5]<br />
<br />
=== Wi-Fi ===<br />
<br />
Different MacBook models have different wireless cards.<br />
<br />
You can easily check what card do your MacBook have by:<br />
<br />
# lspci | grep Network<br />
<br />
* If you have an Atheros card, all should work out-of-the-box.<br />
<br />
* If you have a Broadcom card, follow the [[Broadcom BCM4312]] page.<br />
<br />
* 5.0 and 6.0 generation MacBooks may have a BCM43xx, follow the instructions for the broadcom-wl driver on the [[Broadcom wireless]] page. The interfaces can swap during reboot so its best to define them in a udev rule (instructions on the [[Broadcom wireless]] page).<br />
<br />
* 8.1 generation MacBooks have BCM4331, for which support is not present in either Linux (3.0 and 3.1) or the proprietary drivers by Broadcom. There is however preliminary support for it in Linux 3.2. To run the drivers on earlier kernels, you will need to use [https://backports.wiki.kernel.org/index.php/Documentation/compat-drivers compat-drivers]<br />
<br />
{{Note|If your connection frequently drops, you may have to turn off Wi-Fi power management. If you are running [[pm-utils]], you may override wireless power management by creating an executable file {{ic|/etc/pm/wireless}} with the lines:<br />
#!/bin/sh<br />
iwconfig wlp2s0 power off<br />
}}<br />
<br />
=== Power management ===<br />
<br />
[[Powerdown]] is a very simple to set up set of scripts what will maximize your battery duration. A MacBook Air 2013 with powerdown provides about 11 hours of light usage with just powerdown installed.<br />
All the usual [[power management]] recomendations apply as well.<br />
<br />
Adding 'acpi_osi=' to kernel parameters reportedly (as well as for me) brings the battery life of a Mac book Air 2013 from 5 hours to 11-12 hours. See [https://bbs.archlinux.org/viewtopic.php?pid=1530283#p1530283 this forum post] for more information.<br />
<br />
==== Suspend and Hibernate ====<br />
<br />
Suspending (suspend to ram) and hibernating (suspend to disk) work fine out of the box:<br />
<br />
systemctl suspend<br />
<br />
Issues were reported where the machine would "suspend immediately after resume" in certain conditions when suspending by closing the lid. This was solved by de-selecting the option "event_when_closed_battery" in gconf-editor &rarr; gnome-power-manager &rarr; actions).<br />
<br />
See [[Suspend and hibernate]] for details on how to configure hibernation. Noticably, you'll need a swap partition or file (see the mentioned article for further instructions).<br />
<br />
If after suspend laptop is woken up after few seconds, may help to disable all stuff in /proc/acpi/wakeup, exclude LID0:<br />
# echo XHC1 > /proc/acpi/wakeup<br />
$ cat /proc/acpi/wakeup<br />
Device S-state Status Sysfs node<br />
P0P2 S3 *disabled<br />
EC S3 *disabled<br />
HDEF S3 *disabled pci:0000:00:1b.0<br />
RP01 S3 *disabled pci:0000:00:1c.0<br />
RP02 S3 *disabled pci:0000:00:1c.1<br />
RP03 S3 *disabled pci:0000:00:1c.2<br />
ARPT S4 *disabled pci:0000:03:00.0<br />
RP05 S3 *disabled pci:0000:00:1c.4<br />
RP06 S3 *disabled pci:0000:00:1c.5<br />
SPIT S3 *disabled<br />
XHC1 S3 *disabled pci:0000:00:14.0<br />
ADP1 S3 *disabled<br />
LID0 S3 *enabled<br />
And for permanent disabling:<br />
$ cat /etc/udev/rules.d/90-xhc_sleep.rules <br />
<br />
# disable wake from S3 on XHC1<br />
SUBSYSTEM=="pci", KERNEL=="0000:00:14.0", ATTR{power/wakeup}="disabled"<br />
<br />
If this does not work, check that ARPT is disabled, and add a corresponding rule to udev, like this:<br />
<br />
SUBSYSTEM=="pci", KERNEL=="0000:03:00.0", ATTR{power/wakeup}="disabled"<br />
<br />
If this still does not work, try disabling LID0.<br />
This way suspending via lid-closing should be made impossible, so you might want to follow the instructions in [https://bbs.archlinux.org/viewtopic.php?pid=1556046#p1556046 this forum post] to make suspending via both lid-closing and systemd possible, by using systemd services.<br />
<br />
=== Light sensor ===<br />
<br />
The values can be read from:<br />
<br />
/sys/devices/platform/applesmc.768/light<br />
<br />
A "cat" on this path returns two-tuples like (4,0). The below referenced lighter script ignores the second value - which always seems to be 0 - and uses the first number as measured environment lighting brightness value.<br />
<br />
If you want to use the built in light sensor to automatically adjust screen and keyboard backlight brightness check out<br />
'''Lighter''' [https://github.com/Janhouse/lighter] (simple perl script, easy to fine-tune) and '''Lightum''' [https://github.com/poliva/lightum] (Requires Gnome or KDE but is older and more complete than Lighter).<br />
<br />
=== Sound ===<br />
<br />
{{Tip| If using [[ALSA]], the internal speaker might not be disabled when using the headphone jack. To solve this, enable "Auto-mute" using {{ic|alsamixer}}}}<br />
<br />
First of all follow [[ALSA]] wiki page, then if something does not work correctly, continue reading this part.<br />
<br />
Edit your {{ic|/etc/modprobe.d/50-sound.conf}} or {{ic|/etc/modprobe.d/modprobe.conf}} appending this line:<br />
<br />
options snd_hda_intel model=intel-mac-auto<br />
<br />
This should automatically specify the codec in your MacBook. If you have a MacBookPro12,1, you might need<br />
<br />
options snd-hda-intel index=1,0<br />
<br />
instead. Alternatively, for MacBookPro5,X, you can use:<br />
<br />
options snd_hda_intel model=mb5<br />
<br />
(note that the jack output is controlled with "HP").<br />
<br />
If you have an iMac8,1, you should instead use<br />
<br />
options snd-hda-intel model=mbp3 position_fix=2<br />
<br />
You can try to specify other options, that depend on your hardware. All other possible settings are listed in Kernel Documentation, avaible online:<br />
<br />
* [http://www.kernel.org/doc/Documentation/sound/alsa/ALSA-Configuration.txt ALSA-Configuration.txt]<br />
* [http://www.kernel.org/doc/Documentation/sound/alsa/HD-Audio.txt HD-Audio.txt]<br />
* [http://www.kernel.org/doc/Documentation/sound/alsa/HD-Audio-Models.txt HD-Audio-Models.txt].}}<br />
<br />
Then, reboot.<br />
<br />
=== Bluetooth ===<br />
<br />
Bluetooth should work out-of-the box. See the article on [[Bluetooth]] to install and configure all software needed.<br />
<br />
=== Webcam ===<br />
<br />
==== iSight ====<br />
<br />
{{Note|Linux kernel from 2.6.26 includes the Linux UVC driver natively. '''MBP 6,2+ (Kernel ~2.6.37+) iSight works out of the box''' without the need to use firmware from OS X. Only use {{ic|isight-firmware-tools}} if it doesn't work normally.}}<br />
<br />
iSight webcams on MacBooks or pre 6,2 MacBook Pros (6,2 came out around 2010) require the Apple's proprietary firmware that cannot be redistributed. It must be extracted from OS X and loaded onto Arch.<br />
<br />
You will need to install {{AUR|isight-firmware-tools}} to extract the firmware. This package also includes a udev rule and ELF binary that are necessary, even once you have extracted the firmware file into {{ic|/lib/firmware/isight.fw}}, for the file to be loaded every time you boot your computer (namely {{ic|/etc/udev/rules.d/isight.rules}} which uses {{ic|/usr/lib/udev/ift-load}}).<br />
<br />
Instructions:<br />
<br />
First you need to get the firmware out of a particular file located on your OS X install. It is located in {{ic|/System/Library/Extensions/IOUSBFamily.kext/Contents/PlugIns/AppleUSBVideoSupport.kext/Contents/MacOS/AppleUSBVideoSupport}}.<br />
<br />
{{ Tip | The {{ic|AppleUSBVideoSupport}} file from a OS X 10.6 (Snow Leopard) installation may not work properly. If possible, use the file from OS X 10.5 or earlier.}}<br />
<br />
To mount the OS X drive if multi-booting:<br />
<br />
# sudo mkdir /media/OSX<br />
# sudo mount -t hfsplus /dev/sda2 /media/OSX<br />
<br />
Then, install the {{AUR|isight-firmware-tools}} package.<br />
<br />
Locate the {{ic|AppleUSBVideoSupport}} file in the OS X directory listed above. Either copy it over to your Arch system (Any OS X installation should do, such as an iMac, not just one specific to your system) or, if multi-booting, mount the OS X drive and navigate to the directory. (On 10.7 (Lion) the directory is {{ic|/System/Library/Extensions/IOUSBFamily.kext/Contents/PlugIns/AppleUSBVideoSupport.kext/Contents/MacOS}}.) In that directory you can go ahead and extract the driver:<br />
<br />
# ift-extract --apple-driver AppleUSBVideoSupport<br />
<br />
When it's done, check that the firmware has been found:<br />
<br />
# ls /lib/firmware/isight.fw<br />
<br />
Once successful, completely '''SHUTDOWN''' your Mac and start it back up again (to clear the hardware state of the webcam). Do ''not'' reboot.<br />
<br />
It should be automatically loaded at boot; if it isn't you can load the '''uvcvideo''' module [[Kernel modules|manually or load it at boot]].<br />
<br />
You can use many applications to test the webcam:<br />
<br />
* MPlayer<br />
<br />
# mplayer tv:// -tv driver=v4l2:width=320:height=240:device=/dev/video0 -fps 30<br />
<br />
* Cheese<br />
* Skype<br />
* Ekiga<br />
<br />
A simple solution to take snapshots is:<br />
<br />
# mplayer tv:// -vf screenshot<br />
<br />
and the pressing the s key to take a snapshot. Files are of the format {{ic|shot\d\d\d\d.png}} and are reported in the standard output.<br />
<br />
==== Facetime HD ====<br />
According to Apple, all recent MacBook models contain a Facetime HD camera instead of the iSight. The following list is an example:<br />
* iMac (21,5" mid 2011)<br />
* iMac (27" mid 2011)<br />
* MacBook Air (mid 2011)<br />
* MacBook Pro (15" early 2011)<br />
* MacBook Pro (17" early 2011)<br />
* MacBook Pro (13" early 2011)<br />
If your MacBook is more recent than the models listed above, it is likely equipped with the Facetime HD camera as well.<br />
<br />
In order to make the camera work, you need to install the {{AUR|bcwc-pcie-dkms}} and {{AUR|bcwc-pcie-firmware}} packages. This will enable camera video support through the {{ic|facetimehd}} kernel module.<br />
<br />
In order to verify if the Facetime camera is working after the installation of both packages, you'll need to reboot your system.<br />
<br />
{{Note|Keep in mind that, although working, this is a reverse-engineered driver. PC suspension is not supported if a program that is keeping the camera active is running.}}<br />
<br />
=== Temperature Sensors ===<br />
<br />
For reading temperature just install {{Pkg|lm_sensors}}. See the [[lm_sensors]] page for more information.<br />
<br />
=== Color Profile ===<br />
<br />
We can use color profiles from OS X.<br />
<br />
First, install the {{AUR|xcalib}} package.<br />
<br />
Second copy pre-saved color profiles placed in {{ic|/Library/ColorSync/Profiles/Displays/}} on OS X partition to {{ic|~/colorprofiles/}} for example.<br />
<br />
There are color profile files agree with in MacBook models; select the right one:<br />
<br />
* '''Color LCD-4271800.icc''' for MacBook Pro with CoreDuo CPU<br />
* '''Color LCD-4271880.icc''' for MacBook with Core2Duo<br />
* '''Color LCD-4271780.icc''' for MacBook (non-Pro) based on CoreDuo or Core2Duo.<br />
<br />
{{Tip|Also OS X allows to save current color profile from ''Displays > Color'' section of the ''Mac OS System Preferences'', in this case file is saved to {{ic|/Users/<username>/Library/ColorSync/Profiles}}.}}<br />
<br />
Finally you can activate it by running<br />
<br />
# xcalib ~/colorprofile.icc<br />
<br />
{{Note|Previous command set the color profile only for the current session; this mean that you must run it every time you login in your system. For automating it you can execute the command by '''Autostart Application''', concording with your DE (or add the command to your login manager's initialization script, e.g. /etc/gdm/Init/Default).}}<br />
<br />
{{Warning|GNOME will revert the profile set by xcalib. It's preferable to set the profile using '''Color''' in settings.}}<br />
<br />
=== Apple Remote ===<br />
<br />
First, to correctly install and configure the '''lirc''' software that control IR see [[LIRC]] wiki.<br />
<br />
Then make LIRC use {{ic|/dev/usb/hiddev0}} (or {{ic|/dev/hiddev0}}) by editing {{ic|/etc/conf.d/lircd}}. Here is how mine look:<br />
<br />
#<br />
# Parameters for lirc daemon<br />
#<br />
LIRC_DEVICE="/dev/usb/hiddev0"<br />
LIRC_DRIVER="macmini"<br />
LIRC_EXTRAOPTS=""<br />
LIRC_CONFIGFILE="/etc/lirc/lircd.conf"<br />
<br />
Use '''irrecord''' (available when installing '''lirc''') to create a configuration file matching your remote control signals (alternatively, you can try to use the {{ic|lircd.conf}} below):<br />
<br />
# irrecord -d /dev/usb/hiddev0 -H macmini output_conf_file<br />
<br />
Start '''lircd''' and use '''irw''' to check if it works.<br />
<br />
Example of an {{ic|/etc/lirc/lircd.conf}}:<br />
<br />
begin remote<br />
<br />
name lircd.conf.macbook<br />
bits 8<br />
eps 30<br />
aeps 100<br />
<br />
one 0 0<br />
zero 0 0<br />
pre_data_bits 24<br />
pre_data 0x87EEFD<br />
gap 211994<br />
toggle_bit_mask 0x87EEFD01<br />
<br />
begin codes<br />
Repeat 0x01<br />
Menu 0x03<br />
Play 0x05<br />
Prev 0x09<br />
Next 0x06<br />
Up 0x0A<br />
Down 0x0C<br />
end codes<br />
<br />
end remote<br />
<br />
=== HFS partition sharing ===<br />
<br />
First, install the {{Pkg|hfsprogs}} package. <br />
<br />
we have to list our partitions. Use<br />
<br />
fdisk -l /dev/sda<br />
<br />
example output:<br />
<br />
# fdisk -l /dev/sda<br />
Device Boot Start End Blocks Id Type<br />
/dev/sda1 1 26 204819 ee GPT<br />
/dev/sda2 26 13602 109051903+ af Unknown<br />
/dev/sda3 * 13602 14478 7031250 83 Linux<br />
/dev/sda4 14478 14594 932832+ 82 Linux swap / Solaris<br />
<br />
As we see, the "Unknown" partition is our OS X partition, which is located in {{ic|/dev/sda2}}.<br />
<br />
Create a "mac" folder in /media:<br />
<br />
# mkdir /media/mac<br />
<br />
Add at the end of ''/etc/fstab'' this line:<br />
<br />
/dev/sda2 /media/mac hfsplus auto,user,rw,exec 0 0<br />
<br />
Mount it :<br />
<br />
mount /media/mac<br />
<br />
and check it:<br />
<br />
ls /media/mac<br />
<br />
=== HFS+ Partitions ===<br />
<br />
==== Journaling ====<br />
<br />
HFS+ partitions, now the default in OS X, are not fully supported by Linux and are mounted as read-only by default. In order to write to an HFS+ partition, the safe way is to disable journaling. This can be accomplished using the OS X Disk Utility. Refer to this [http://support.apple.com/kb/ht2355 Apple support page] for more information or try to do it from the command line:<br />
<br />
Find your partition:<br />
<br />
$ diskutil list<br />
/dev/disk0<br />
#: TYPE NAME SIZE IDENTIFIER<br />
0: GUID_partition_scheme *750.2 GB disk0<br />
1: EFI EFI 209.7 MB disk0s1<br />
2: Apple_HFS OSX 149.5 GB disk0s2<br />
3: Apple_HFS Macintosh HD 599.2 GB disk0s3<br />
4: Apple_Boot Recovery HD 650.0 MB disk0s4<br />
<br />
In this example we will use ''disk0s3'' partition named as ''Macintosh HD''. To know if journaling is activate or not you could execute:<br />
<br />
$ diskutil info /dev/disk0s3 | grep -i journal<br />
File System Personality: Journaled HFS+<br />
Name (User Visible): Mac OS Extended (Journaled)<br />
Journal: Journal size 49152 KB at offset 0x1176000<br />
<br />
As you can read the journaling is active. To turn off the journaling you could execute:<br />
<br />
$ sudo diskutil disableJournal disk0s3<br />
Password:<br />
Journaling has been disabled for volume Macintosh HD on disk0s3<br />
<br />
To verify it is done execute the info command again:<br />
<br />
$diskutil info /dev/disk0s3 | grep -i journal<br />
$<br />
<br />
If you get noting as output, then journaling is disabled.<br />
<br />
However, if you fail to disable journaling. You can change "auto,user,rw,exec" in "/etc/fstab" to "auto,user,force,rw,exec" and mount it.<br />
<br />
====Yosemite and later====<br />
<br />
Since Yosemite, HFS+ partitions are now wrapped a CoreStorage volume. Verify that you have an CoreStorage volume.<br />
<br />
# fdisk -l /dev/sdX<br />
Disk /dev/sdX: 298.1 GiB, 320072933376 bytes, 625142448 sectors<br />
Units: sectors of 1* 512 = 512 bytes<br />
Sector size (logical/physical): 512 bytes / 4096 bytes<br />
I/O size (minimum/optimal): 4096 bytes / 4096 bytes<br />
Disklabel type: gpt<br />
Device Start End Sectors Size Type<br />
/dev/sdX1 40 409639 409600 200M EFI System<br />
/dev/sdX2 409640 623872871 623463232 297.3G Apple Core storage<br />
/dev/sdX3 623872872 625142407 1269536 916.0M Apple boot<br />
<br />
HFS+ uses two volume headers, one 1024 bytes into the device and one 1024 from the end of the device. With the HFS+ partition wrapped in the CoreStorage volume the end of the partition is not actually 1024 bytes from the end of the {{ic|/dev/sdX2}} partition.<br />
To fix this you need to specify {{ic|1=sizelimit=X}} when mounting.<br />
<br />
To determine {{ic|sizelimit}} do the following:<br />
<br />
# Run {{ic|testdisk /dev/sdX}} and select your drive<br />
# Select {{ic|EFI GPT}}<br />
# Select {{ic|Analyse}} and then {{ic|Quick Search}}<br />
<br />
Sample output:<br />
TestDisk 7.0, Data Recovery Utility, April 2015<br />
Christophe GRENIER <grenier@cgsecurity.org><br />
http://www.cgsecurity.org<br />
<br />
Disk /dev/sdX - 320 GB / 298 GiB - CHS 38913 255 63<br />
Partition Start End Size in sectors<br />
P EFI System 40 409639 409600 [EFI]<br />
P Mac HFS 409640 623147815 622738176<br />
P Mac HFS 623872872 625142407 1269536<br />
<br />
What you see now is the output of the HFS partition itself without the CoreStorage volume. Take the size in sectors (622738176 in this example) and multiply by the number of bytes in your logical sector size (512 in this example).<br />
<br />
622738176 * 512 = 318841946112<br />
<br />
Finally, mount your disk with the {{ic|1=sizelimit=X}} option.<br />
<br />
mount /dev/sdX -t hfsplus -o ro,sizelimit=318841946112<br />
<br />
===Home Sharing===<br />
<br />
'''''UID Synchronization'''''<br />
<br />
==== In OS X ====<br />
<br />
{{Note|It is strongly recommended that UID/GID manipulation be done immediately after a new user account is created, in OS X as well as in Arch Linux. If you installed OS X from scratch, then this operation is guaranteed to work after logging into your account for the first time.}}<br />
<br />
===== Step 1: change UID and GID(s) =====<br />
<br />
'''''Pre-Leopard'''''<br />
<br />
# Open '''NetInfo Manager''' located in the ''/Applications/Utilities'' folder.<br />
# If not done for you already, enable access to user account transactions by clicking on the closed lock at the bottom of the window, and entering your account password, or root password if you have created a root account.<br />
# Navigate to ''/users/<new user name>'' where <new user name> is the name of the account that will have read/write access to the folder that will be shared with the primary user in Arch.<br />
# Change the '''UID''' value to 1000 (the value used by default for first user created in Arch).<br />
# Also change the '''GID''' value to 1000 (the value used by default for user account creation in Arch).<br />
# Navigate to {{ic|/groups/<new user name>}}, automatically saving the changes you have made so far.<br />
<br />
{{Note|If you get an error message that the transaction is not allowed, log out and log back in.}}<br />
<br />
'''''Leopard'''''<br />
<br />
In Leopard, the '''NetInfo Manager''' application is not present. A different set of steps is required for UID synchronization:<br />
<br />
# Open '''System Preferences'''.<br />
# Click on '''Users & Groups'''.<br />
# Unlock the pane if not already done so.<br />
# Right-click on the desired user and select '''Advanced Options'''.<br />
# Write down the value of the '''User ID''' field, you will need it later on. Change both the UID and GID to match the UID and GID of the account wished to be shared with in Arch (1000 by default for the first user created in Arch).<br />
<br />
===== Step 2: change "Home" permissions =====<br />
<br />
# Open up '''Terminal''' in the {{ic|/Applications/Utilities}} folder.<br />
<br />
# Enter the following command to reclaim the permission settings of your home folder, replacing <your user name>, <your user group> and <your old UID> with the user name whose UID and GID values you just changed, the group name whose GID value you just changed and the old UID number, respectively.<br />
<br />
# find /User/<your user name> -user <your old UID> -exec chown <your user name>:<your user group> {} \;<br />
<br />
==== In Arch ====<br />
<br />
To synchronize your UID in Arch Linux, you are advised to perform this operation ''while creating a new user account''.<br />
It is therefore recommended that you do this as soon as you install Arch Linux.<br />
<br />
Now you must substitute Arch's home with OS X's home, by modify entries of {{ic|/etc/fstab}}.<br />
<br />
=== Avoid long EFI wait before booting ===<br />
<br />
If your MacBook spends 30 seconds with "white screen" before booting you need to tell the firmware where is the booting partition.<br />
<br />
Boot OS X, if do not have it installed, you can use the install DVD (select language, then click Utilities->Terminal), or another MacBook with OS X (connect the two computers via firewire or thunderbolt, start the other MacBook keeping pressed T, boot your MacBook keeping pressed Options).<br />
<br />
Either way, once you got a OS X terminal running on your MacBook you need to execute, as root, a different command if the boot partition is EFI or it is not:<br />
<br />
# bless --device /dev/disk0s1 --setBoot # if the booting partition is EFI<br />
or<br />
# bless --device /dev/disk0s1 --setBoot --legacy # if the booting partition is not EFI<br />
<br />
(given that if your GRUB or EFI is on sda1, /dev/disk1s2 if it is on sdb2, etc). See also https://bbs.archlinux.org/viewtopic.php?pid=833215 and https://support.apple.com/kb/HT1533 .<br />
<br />
=== Mute startup chime ===<br />
<br />
The startup chime volume is controlled by the EFI variable ''SystemAudioVolume-7c436110-ab2a-4bbb-a880-fe41995c9f82''. So it can be muted with<br />
<br />
# printf "\x07\x00\x00\x00\x00" > /sys/firmware/efi/efivars/SystemAudioVolume-7c436110-ab2a-4bbb-a880-fe41995c9f82<br />
<br />
Alternatively, you can use a OS X install disk to mute the chime. Boot from it, select language, then click ''Utilities > Terminal'', and enter<br />
<br />
# /usr/sbin/nvram SystemAudioVolume=%01<br />
<br />
(or whatever volume you want).<br />
<br />
{{Note|Required formatting of the value provided for key SystemAudioVolume may differ depending on MacBook model and perhaps the version of OS X install media. If the above command fails to work, try enclosing the value in double quotes.}}<br />
<br />
=== kworker using high CPU ===<br />
Sometime with the addition of Yosemite, some users found that kworker CPU usage will spike, as disccused [https://bbs.archlinux.org/viewtopic.php?id=171883&p=11 here]. This is sometimes the result of runaway ACPI interrupts.<br />
<br />
To check and see, you can count the number of recent ACPI interrupts and see if any of them are out of control.<br />
<br />
grep . -r /sys/firmware/acpi/interrupts/<br />
<br />
<br />
If you see that one particular interrupt is out of control (possibly GPE66), i.e., registering hundreds of thousands of lines, you can try disabling it (replace XX with the runaway interrupt):<br />
<br />
<br />
echo "disable" > /sys/firmware/acpi/interrupts/gpeXX<br />
<br />
<br />
Disabling random ACPI interrupts could cause all kinds of problems, so do this at your own risk. If this fixes the problem, there is discussion about how to make a systemd service that automatically disables an interrupt at every boot [https://bbs.archlinux.org/viewtopic.php?pid=1488371 here].<br />
<br />
== rEFIt ==<br />
<br />
{{Note|<br />
* You probably want to have a look at [http://www.rodsbooks.com/refind/ rEFInd], which is some type of successor of rEFIt.<br />
* This is not a requirement. It only gives you a menu to choose between OS X and Arch Linux upon every boot.<br />
}}<br />
<br />
For more see, [http://refit.sourceforge.net/myths/ rEFIt myths].<br />
<br />
In OS X, download the ".dmg" from [http://refit.sourceforge.net/ rEFIt Homepage] and install it.<br />
<br />
{{Note|If you have already partitioned your hard disk in preparation for the Arch installation, rEFIt may not be enabled by default. You will have to run the "enable.sh" script installed in /efi/refit/.}}<br />
<br />
Open up '''Terminal''' and enter:<br />
<br />
cd /efi/refit;<br />
./enable.sh<br />
<br />
=== Problems with rEFIt ===<br />
<br />
If you experience problems after the install of Arch or rEFIt, especially is the right OS is not showing up to boot to or if it dumps you at a GRUB prompt stuck like the following:<br />
<br />
GRUB>_<br />
<br />
Then have a look at this link:<br />
<br />
http://mac.linux.be/content/problems-refit-and-grub-after-installation<br />
<br />
It can give you a basic idea on how to boot off the Arch live cd, mount the problem Arch install, chroot, use gptsync, and reinstall GRUB. This is probably for more advanced users who can translate the commands from a debian system to an Arch system and also apply it to the partitions on their machine. Be careful not to install GRUB in the wrong spot.<br />
<br />
If you need a copy of gptsync you can wget it from here:<br />
http://packages.debian.org/sid/gptsync<br />
or try these, for 64 bit:<br />
<br />
wget http://ftp.us.debian.org/debian/pool/main/r/refit/gptsync_0.14-2_amd64.deb<br />
<br />
and for i386:<br />
<br />
wget http://ftp.us.debian.org/debian/pool/main/r/refit/gptsync_0.14-2_i386.deb<br />
<br />
since they are .deb packages you will need the program {{AUR|deb2targz}}.<br />
<br />
==== Mavericks upgrade breaks Arch boot option ====<br />
For some multi-boot users who utilize a separate Linux boot partition, the OS X Mavericks upgrade may overwrite the boot partition with Apple's own recovery boot filesystem. This breaks the Arch Linux boot option in rEFIt/rEFInd. The best way to proceed in this situation is to abandon a separate boot partition and use the EFI system partition (ESP) to install the bootloader of your choice. It is also recommended that you use rEFInd instead of rEFIt as development on the latter has halted.<br />
<br />
Assuming grub2 as the bootloader:<br />
<br />
Use the Arch LiveCD to boot to a shell and [[Change root|chroot]] to your broken Arch Linux environment.<br />
<br />
Mount the ESP on /boot.<br />
<br />
Edit the fstab and remove the old boot partition and make ESP the new boot partition. Now mount the ESP as the new /boot parition.<br />
# mount -a<br />
<br />
[[install|Reinstall]] {{pkg|linux}}.<br />
<br />
Create a new initramfs and vmlinuz in /boot.<br />
# mkinitcpio -p linux<br />
<br />
Install grub.<br />
# grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=grub --recheck --debug<br />
<br />
Create a new grub.cfg file.<br />
# grub-mkconfig -o /boot/EFI/grub/grub.cfg<br />
<br />
Make sure that grub.cfg is in the same directory as grubx64.efi.<br />
<br />
Generate a new refind_linux.conf file in /boot simply by running mkrlconf.sh which comes with rEFInd.<br />
<br />
Exit the chroot environment.<br />
<br />
Reboot. You should see a new entry for Arch Linux in rEFInd and it should boot to your Arch Linux installation.<br />
<br />
== Model-specific information ==<br />
<br />
=== MacBook ===<br />
<br />
==== April 2016 12" - Version 9,1 ====<br />
<br />
* Booting from USB via EFI works fine, when giving the {{ic|noapic}} kernel option. (On Ubuntu, also {{ic|noacpi nomodeset}} seem to be necessary.) Remember to hold the Alt key on booting.<br />
<br />
* The wireless card works out of the box with {{ic|brcmfmac}}.<br />
<br />
* Suspend-to-RAM works out of the box.<br />
<br />
* The built-in flash drive does ''not'' work with kernel 4.5.4-1-ARCH, but it ''does'' work with kernel 4.6.0-mainline (install {{AUR|linux-mainline}}). As long as a [http://lists.infradead.org/pipermail/linux-nvme/2016-May/004618.html rather trivial patch] is not merged into the kernel, either this patch must be applied locally or one puts {{ic|modprobe nvme; echo 106b 2003 > /sys/bus/pci/drivers/nvme/new_id}} into a mkinitcpio hook (to be started after the udev hook). The reason is that the NVMe controller of the flash drive doesn't advertise itself with the correct PCI device class. Note that with the patch, a short sleep still seems to be necessary.<br />
<br />
* Audio recording works out of the box. Audio playback doesn't work (still looking for a solution).<br />
<br />
* The keyboard and the touchpad do ''not'' work (still looking for a solution).<br />
** There's a WIP driver [https://github.com/cb22/macbook12-spi-driver here] that sort of works with a DSDT hack (the previous problem with this driver related to battery drain has been fixed now).<br />
<br />
==== Mid 2007 13" - Version 2,1 ====<br />
<br />
{{Note|I used the 201212 ISO image.}}<br />
<br />
Since older Macbooks have a 32bit EFI running, the usual installation image is not recognized. You need to either remove the UEFI support from the disc ([[Unified_Extensible_Firmware_Interface#Remove_UEFI_boot_support_from_ISO]]) or build a 32bit EFI version of the disc. The paragraphs below will take the first path to success, booting into BIOS mode and its pitfalls. For a try the other way round, read [[Unified_Extensible_Firmware_Interface#Create_UEFI_bootable_USB_from_ISO]] first.<br />
<br />
First prepare your harddisc according to your wishes. In this scenario it was a "Linux only" approach with<br />
<br />
/dev/sda1 HFS+ AF00 200M -> EFI boot system on Apple HFS+ partition<br />
/dev/sda2 ext4 8300 147G -> arch system<br />
/dev/sda3 swap 8200 1G -> swap<br />
<br />
The {{AUR|hfsprogs}} package contains the tools to handle HFS/HFS+ filesystems. The rEFInd bootloader recognizes it on its own. Usually the partition for the EFI bootloader is a FAT32 (vfat) partition. In this case I tried rEFIt first, which apparently needs the HFS+ filesystem to work, and kept it at that.<br />
<br />
The mount points are:<br />
<br />
/dev/sda2 -> /<br />
/dev/sda1 -> /boot<br />
<br />
The bootloader in use was [http://www.rodsbooks.com/refind/index.html rEFInd] instead of rEFIt. To install it, the rEFInd homepage provides a good guide. Usually it is simply done by copying rEFInd:<br />
<br />
mkdir /boot/EFI<br />
cp -vr /usr/share/refind/drivers_ia32 /boot/EFI/refind/<br />
cp -vr /usr/share/refind/tools_ia32 /boot/EFI/refind/<br />
cp -vr /usr/share/refind/fonts /boot/EFI/refind/<br />
cp -vr /usr/share/refind/icons /boot/EFI/refind/<br />
cp -v /usr/share/refind/refind_ia32.efi /boot/EFI/refind/<br />
cp -v /usr/share/refind/refind.conf-sample /boot/EFI/refind/refind.conf<br />
cp -v /usr/share/refind/refind_linux.conf-sample /boot/refind_linux.conf<br />
<br />
{{Note|I'm using the 32bit version of Arch and refind, since the EFI of the old MacBooks is 32bit. I'm not sure about 32bit rEFInd booting a 64bit Arch...}}<br />
<br />
The pitfall here is, that the system bootet in BIOS compatibility mode and not in EFI mode. You cannot therefore use {{ic|efibootmgr}}, because the EFI variables (even with 'modprobe efivars') are not available. While installing the system get {{AUR|mactel-boot}}. The {{ic|hfs-bless}} utility comes in handy, when blessing the EFI bootloader. This is done by calling:<br />
<br />
hfs-bless /boot/EFI/refind/refind_ia32.efi<br />
<br />
Since the Linux kernel does come with EFI stub enabled, it seems a good idea to run it through a bootloader first. Especially if it runs not out of the box. But using rEFInd makes GRUB (or any other bootloader) obsolete, because of that.<br />
<br />
{{Note|In the refind_linux.conf you add any kernel option you may want as long as you use the EFI stub of your kernel. In refind.conf you adjust your needs for the bootloader itself, like menu entries. If you use them (menu entries), rEFInd should not look for these EFI stub kernels itself, so blacklist the directories used in here, like {{ic|/boot/}}.}}<br />
<br />
Not running out of the box is unfortunately the initial stage for the kernel. Since we installed it in BIOS mode, two modules are missing to grant access to the root partition while booting. Hence the 'initfsram-linux.img' can not be found/loaded. Adding the following modules to your 'MODULES' line in {{ic|/etc/mkinitcpio.conf}} solved this ([https://bbs.archlinux.org/viewtopic.php?pid=1139226#p1139226 original post]).<br />
<br />
{{hc|/etc/mkinitcpio.conf|2=<br />
MODULES="ahci sd_mod"}}<br />
<br />
Rebuild your kernel image:<br />
<br />
mkinitcpio -p linux<br />
<br />
The bootloader rEFInd can scan kernels even out of the '/boot/...' directory and assumes an efi kernel even without the extension '.efi'. If you do not want to try out special kernels, this should work without the hassle to copy each kernel after building to some spot special.<br />
<br />
If you happen to get multiple entries for one boot image, it often results of a previous installation of a bootloader within the MBR. To remove that, try the following - taken from the [http://ubuntuforums.org/showpost.php?p=7828260&postcount=4 original post]. This is valid for GPT partitioned discs, so please check your environment and save your MBR first.<br />
<br />
# dd if=/dev/zero of=/dev/sda bs=440 count=1<br />
<br />
=== MacBook Pro with Retina display ===<br />
<br />
==== Early 2015 13"/15" - Version 12,x/11,4+ ====<br />
<br />
===== Wireless =====<br />
The {{ic|brcmfmac}} driver is working as of 2015-11-20, with newer firmware necessary for working 5GHz support ([https://bugzilla.kernel.org/show_bug.cgi?id=100201#c65 see here.])<br />
<br />
===== Bluetooth =====<br />
Bluetooth is fully supported starting from kernel-4.4.0.<br />
<br />
===== Suspend & Power Off (11,4+) =====<br />
The 11,4 and 11,5 MacBook Pros do not shutdown or suspend correctly with the default kernel. This issue is being addressed in [https://bugzilla.kernel.org/show_bug.cgi?id=103211 Bug 103211] and a temporary patch is currently available in {{AUR|linux-macbook}}.<br />
<br />
===== Keyboard & Trackpad =====<br />
Haptic feedback works out of the box due to the trackpad's built-in firmware.<br />
<br />
There are several drivers available that provide multitouch support. The following have been confirmed working with the MacBookPro12,1.<br />
<br />
For {{Pkg|xf86-input-libinput}} the following configuration emulates some features from the OS X functionality. For more options see {{man|4|libinput|url=https://www.mankier.com/4/libinput}}.<br />
{{hc|1=/etc/X11/xorg.conf.d/90-libinput.conf|2=<br />
Section "InputClass"<br />
Identifier "libinput touchpad catchall"<br />
MatchIsTouchpad "on"<br />
MatchDevicePath "/dev/input/event*"<br />
Driver "libinput"<br />
Option "NaturalScrolling" "true"<br />
EndSection<br />
}}<br />
<br />
For {{Pkg|xf86-input-synaptics}} the following configuration is necessary to make the touchpad work fully.<br />
{{hc|1=/etc/X11/xorg.conf.d/60-magictrackpad.conf|2=<br />
Section "InputClass"<br />
Identifier "Trackpad"<br />
Driver "synaptics"<br />
MatchIsTouchpad "on"<br />
MatchDevicePath "/dev/input/event*"<br />
EndSection<br />
}}<br />
<br />
Further, some US/ANSI keyboards suffer from an issue where the tilde key (~, the key vertically between Esc and Tab) registers as < and >. The following config file fixes this issue.<br />
<br />
{{hc|1=/etc/modprobe.d/hid_apple.conf|2=<br />
options hid_apple iso_layout=0<br />
}}<br />
<br />
See [https://bugzilla.kernel.org/show_bug.cgi?id=96771 this kernel bugzilla] for more details and the relevant patches for earlier kernels.<br />
<br />
===== Graphics =====<br />
For Intel-only graphics, install {{Pkg|xf86-video-intel}}. For more information or OpenGL/3D support, follow instructions at [[Intel graphics]].<br />
<br />
For Dual Graphics see [https://wiki.archlinux.org/index.php/MacBookPro11,x#Graphics this section on the 11,3].<br />
<br />
{{Note|The kernel parameters ''acpi_backlight'', ''i915.lvds_downclock'', ''i915.enable_ips'', and ''intel_iommu'' are no longer necessary as of kernel 4.2.}}<br />
<br />
==== 2012 - 2014 models ====<br />
<br />
* [[MacBookPro11,x]] (Late 2013—Mid 2014)<br />
* [[MacBookPro10,x]] (Mid 2012—Early 2013)<br />
<br />
=== MacBook Air===<br />
<br />
==== Early 2014 11" - Version 6,1 ====<br />
This is almost the same as the 2013 version, where the only known difference is a slightly faster processor. The version numbers have not been changed since the 2013 version.<br />
<br />
It works excellently after following the instructions for the MBA 2013 13" here and in the forum thread.<br />
Bluetooth, which has been reported not working for some people with the 2013 version, works without trouble for the 2014 version, although it should be excactly the same.<br />
<br />
{{Note| Unless you have a local repository on a USB disk, you need a USB to ethernet adaptor or a USB wireless adaptor supported natively by the kernel to easily install Arch Linux, since you have to install the {{AUR|broadcom-wl-dkms}} package to make the internal wireless adaptor work.}}<br />
<br />
Unresolved issues:<br />
<br />
- There is no driver for the webcam yet.<br />
- rEFInd uses 30 seconds to start booting. Using the bless trick stops rEFInd from loading, and it has to be re-installed.<br />
<br />
==== Mid 2013 13" - Version 6,2 ====<br />
[https://bbs.archlinux.org/viewtopic.php?id=165899 Dedicated forum thread]<br />
===== Installing and booting =====<br />
Booting from a normal 2013.6 USB key works fine, but I could not seem to get either GRUB or Syslinux working.<br />
<br />
I was able to boot by first installing Arch Linux following the MacBook guide at the wiki (having a separate FAT32 /boot partition). Skip the bootloader installation. <br />
<br />
Installing [http://www.rodsbooks.com/refind/getting.html rEFInd] from OS X (important!) and installing the EFI stub loader made me able to boot fine.<br />
<br />
[https://bbs.archlinux.org/viewtopic.php?id=165710 Dedicated thread].<br />
<br />
{{Note| Installing [http://www.rodsbooks.com/refind/getting.html rEFInd] from Linux (or from OS X, but to the esp) also works fine}}<br />
<br />
===== Arch Only Installation =====<br />
This method works without rEFInd and uses grub to boot EFI. Partition as follows:<br />
<br />
/dev/sda1 200M Microsoft basic data<br />
/dev/sda2 256M Linux filesystem<br />
/dev/sda3 4G Linux swap<br />
/dev/sda4 108.6G Linux filesystem<br />
<br />
sda1 can also be a HFS+ partition for EFI. This example chooses to use FAT32 (vfat). Although swap is optional, it is required for hibernation. Instead of sda4 for root and home, an alternative partition scheme would be to make sda4 as root and sda5 as home.<br />
<br />
Format and mount:<br />
<br />
mkfs.vfat -F 32 /dev/sda1<br />
mkfs.ext2 /dev/sda2<br />
mkswap /dev/sda3<br />
swapon /dev/sda3<br />
mkfs.ext4 /dev/sda4<br />
<br />
mount /dev/sda4 /mnt<br />
mkdir /mnt/boot<br />
mount/dev/sda2 /mnt/boot<br />
mkdir /mnt/boot/efi<br />
mount /dev/sda1 /mnt/boot/efi<br />
<br />
Finish the installation according to the [[Installation guide]] and skip anything after the bootloader. After you have generated your initramfs and set root passwd follow below to setup grub:<br />
<br />
pacman -S grub efibootmgr<br />
mount -t efivarfs efivarfs /sys/firmware/efi/efivars<br />
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=grub --recheck --debug<br />
grub-mkconfig -o /boot/efi/EFI/grub/grub.cfg<br />
cp /boot/efi/EFI/grub/grub.cfg /boot/grub/grub.cfg<br />
cp /boot/efi/EFI/grub/grubx64.efi /boot/efi/EFI/boot/bootx64.efi}}<br />
<br />
Now you can exit/unmount/reboot:<br />
exit<br />
umount -R /mnt<br />
reboot<br />
<br />
===== Stability problems =====<br />
{{Note| Passing {{ic|<nowiki>libata.force=1:noncq</nowiki>}} to the kernel parameters solves the problem.}}<br />
This is the big worry for me. Every now and then my system hangs for a brief moment and everything involving net or disk access just hangs there for a while and then it seems to work. <br />
So far it only seems to happen when I run something disk- or CPU-intensive. Also had an occassion when I could not start X and just got this repeating all over my screen:<br />
<br />
ata1.00: failed command: WRITE FPDMA QUEUED<br />
ata1.00: cmd 61/08:f0:10:8c:c2/00:00:0b:00:00/40 tag 30 ncq 4096 out<br />
res 40/00:00:00:00:00/00:00:00:00:00/00 Emask 0x4 (timeout)<br />
ata1.00: status: { DRDY }<br />
<br />
On the next attempt it worked fine.<br />
I did SMART short and long tests on my disk and they returned fine:<br />
<br />
[http://pastebin.com/vRE4T2Ld smartctl -a]<br />
<br />
There are some messages in my boot that indicate this could be disk and/or ACPI related.<br />
<br />
These are with 2013-06 ISO, 3.9.7-1 2013 x86_64 kernel.<br />
<br />
[http://pastebin.com/mjTJaPFa journalctl -b]<br />
Seems to only work with the headphone jack, not with the speakers.<br />
<br />
[http://pastebin.com/SdAcHuKh dmesg]<br />
<br />
===== Marvell ATA suspend bugs =====<br />
If you have 2013 MacBook Air with a Marvell 128 or 256 GB drive, you might get the following ata errors instead after pm-suspend/resumes:<br />
<br />
ata1: exception Emask 0x10 SAct 0x0 SErr 0x10000 action 0xe frozen<br />
ata1: irq_stat 0x00400000, PHY RDY changed<br />
ata1: SError: { PHYRdyChg }<br />
ata1: hard resetting link<br />
ata1: SATA link up 1.5 Gbps (SStatus 113 SControl 310)<br />
ata1.00: unexpected _GTF length (8)<br />
ata1.00: unexpected _GTF length (8)<br />
ata1.00: configured for UDMA/33<br />
ata1: EH complete<br />
<br />
Try what Patrick and Tejun figured out on the [https://bugzilla.kernel.org/show_bug.cgi?id=62351 linux bug]. I followed what Patrick describes with sata_alpm, and I haven't seen the issue since.<br />
<br />
There are more steps on how to resolve this issue in [https://bbs.archlinux.org/viewtopic.php?pid=1562168#p1562168 this thread on the Arch forum]<br />
<br />
===== Suspend/Resume =====<br />
Brightness is either 0% or 100% after resuming from suspend. Until the kernel is fixed, use patjak's fix by installing {{AUR|mba6x_bl-dkms}}. Patjak's github is at [https://github.com/patjak/mba6x_bl].<br />
===== WiFi =====<br />
WiFi does not work out of the box. Install {{AUR|broadcom-wl-dkms}} to connect to a network. <br />
<br />
===== Touchpad =====<br />
Since 3.10.3 kernel touchpad works perfectly with {{Pkg|xf86-input-synaptics}}.<br />
<br />
===== Audio =====<br />
As of Linux 3.12, sound works out of the box. If you do not get sound with only {{pkg|alsa-utils}}, you may need to create a /etc/asound.conf with below entries:<br />
<br />
defaults.pcm.card 1<br />
defaults.pcm.device 0<br />
defaults.ctl.card 1<br />
<br />
==== Mid 2012 13" — version 5,2 ====<br />
<br />
Kernel panics using default boot media under arch kernel 3.5. Adding <code>intremap=off</code> fixes this. Additionally, there are problems loading the <code>applesmc</code> module (meaning the temperature sensors, fan, and keyboard backlight do not work). These problems are fixed in the linux 3.6-rc4 mainline kernel (I have tested).<br />
<br />
==== Mid 2012 11.5" — Version 5,1 ====<br />
<br />
If you have issues with waking from sleep while in X11 such as a black screen or showing the console with a frozen mouse cursor then remove {{Pkg|xf86-input-synaptics}} and install {{AUR|xf86-input-mtrack-git}}. This fixed errors such as <br />
(EE) [dix] bcm5974: unable to find touch point 0<br />
and backtraces that causes X11 to crash. This might apply to Version 5,2 assuming they use the same trackpad.<br />
<br />
===== Installing using the Archboot 2012.06 image =====<br />
<br />
Several people have reported problems installing Arch Linux on the MBA version 5,2 (See [https://bbs.archlinux.org/viewtopic.php?id=144089 problems booting Arch Linux on a MacBook Air Mid 2012]). A common problem is that the screen is not detected and therefore goes black when the installer boots. To fix this problem one has to select the normal install (Not the LTS) during boot and press tab to edit the boot flags. Then add noapic flag to the boot line. This should fix the screen going black. Install the system as you normally would. It may help later in the configuration process if the support packages are installed already at this stage.<br />
<br />
When the install has finished again add the noapic flag to the GRUB boot line (if you use GRUB) and also add i915.diescreaming=1 (or perhaps i915.die). This should keep the screen from going black when booting the new system. After you enter the system the wireless driver should be loaded. If you installed the support packages during installation you should have the wifi-menu command. Run it and select the network you want to use. One could also use wpa_supplicant but wifi-menu is quite fast to use at this stage. Now you are ready to upgrade the system. As of writing there have been a lot of changes to Arch Linux since the 2012.06 image of Archboot was released ([https://www.archlinux.org/news/filesystem-upgrade-manual-intervention-required-1/ filesystem] and [https://www.archlinux.org/news/the-lib-directory-becomes-a-symlink/ glibc]). Therefore the upgrade process can be a bit difficult. The current solution has sucessfully upgraded a standart archboot version to a up-to-date version as of October 2012 and this step should be obsolete in future releases of archboot.<br />
<br />
First ignore the new "big" changes to Arch Linux,<br />
<br />
pacman -Suy --ignore glibc,libarchive,curl,filesystem <br />
<br />
If this only upgrades pacman then run the command again. Remember to make sure that pacman is ignoring the packages you do not want upgraded now. Otherwise you may break the system and have to reinstall! Now upgrade to the new filesystem,<br />
<br />
pacman -S filesystem --force<br />
<br />
As described in [[DeveloperWiki:usrlib|Glibc upgrade guide]] there may be conflicts with installed packages that require the /lib directory. Follow the guide and remove any packages that use /lib. The stock 3.4.2 kernel from Archboot should be on this list so first upgrade this,<br />
<br />
pacman -S linux<br />
<br />
This may give some errors saying that the system may not boot because of missing modules. Ignore this warning for now. The stock install may also contain gcc in the /lib directory so also remove this if needed and any other packages that have conflicts. Now Glibc should be the only package in /lib so run the system upgrade and accept all changes, <br />
<br />
pacman -Su<br />
<br />
Finally reinstall the kernel so that it can find the correct modules.<br />
<br />
Now this command should not give any errors like last time. You can also reinstall gcc at this point. After a rebooted the system should startup and the new kernel should have fixed the problem with the screen going black. If want to boot Xorg then you may need to remove the i915.diescreaming=1 line from GRUB. If not then attach a external screen and try to fix the problem that way. Some people have reported commands that may help on the [https://bbs.archlinux.org/viewtopic.php?id=144089 forum].<br />
<br />
==== Mid 2011 — version 4,x ====<br />
<br />
Works out-of-the-box since kernel 3.2. It is recommended to use [[Archboot]], install [[GRUB]] and use EFI.<br />
<br />
==== Early 2008 — version 1,1 ====<br />
<br />
Everything works out of the box though you will need {{Pkg|b43-fwcutter}} (or simply {{AUR|b43-firmware}}) for the wireless adapter to work.<br />
<br />
Since this model has only one USB port, you may find it easiest to install Arch with a powered USB hub. Plug a USB network adapter (wireless or ethernet adapter to plug into a USB port) and your Arch installation media into the USB hub.<br />
<br />
If you can't get any result by scanning wireless network after boot, unload modules <code>b43</code> and <code>ssb</code> and load them again:<br />
<br />
rmmod ssb<br />
rmmod b43<br />
modprobe b43<br />
<br />
There is a good chance you will find what's wrong with DMA from the dmesg log.<br />
<br />
Even if you can scan wireless networks after reloading the modules, it's still possible that you will only be able to connect to some networks, but not all of them. According to a more detailed discussion here: http://crunchbang.org/forums/viewtopic.php?id=17368, adding <code>pio=1,qos=0</code> options to the b43 module can solve this problem.<br />
<br />
I tested this for a 13' MacBookAir1,1 with a BCM4321 chipset, and it works.<br />
<br />
== See also ==<br />
* '''MacBook Air'''<br />
** [http://dabase.com/blog/Macbook_Air_Early_2014_Archlinux/ Macbook Air Early 2014 — dabase.com]<br />
** [http://www.frankshin.com/installing-archlinux-on-macbook-air-2013/ Installing Archlinux on Macbook Air 2013 — Frank Shin]<br />
** [http://blog.panks.me/posts/2013/06/arch-linux-installation-with-os-x-on-macbook-air-dual-boot/ Arch Linux Installation with OS X on Macbook Air (Dual Boot) — Pankaj Kumar]<br />
** [http://ryangehrig.com/index.php/arch-linux-on-macbook-air-2013/ Arch Linux – MacBook Air 2013 — Ryan Gehrig]<br />
** [http://www.nico.schottelius.org/blog/macbook-air-42-archlinux/ Installing Linux on a Macbook Air (4,2) — Nico Schottelius]<br />
** [http://www.dm9.se/?p=398 Arch linux single, pure efi boot on the macbook air3,1/3,2 — DIMENSION9]<br />
* '''MacBook Pro'''<br />
** http://www.netsoc.tcd.ie/~theorie/interblag/2010/01/30/installing-arch-linux-on-a-mac-pro/<br />
** http://allanmcrae.com/2010/04/installing-arch-on-a-macbook-pro-5-5/<br />
** http://allanmcrae.com/2012/04/installing-arch-on-a-macbook-pro-8-1/<br />
** http://linux-junky.blogspot.com/2011/08/triple-boot-archlinux-windows-7-and-mac.html</div>X33ahttps://wiki.archlinux.org/index.php?title=Cmus&diff=443305Cmus2016-07-26T17:26:22Z<p>X33a: /* See also */ add link to 3rd party scripts and status display programs</p>
<hr />
<div>[[Category:Multimedia players]]<br />
[[ja:Cmus]]<br />
[[sr:Cmus]]<br />
[http://cmus.sourceforge.net/ cmus] ''(C* MUsic Player)'' is a small, fast and powerful console audio player which supports most major audio formats. Various features include gapless playback, ReplayGain support, MP3 and Ogg streaming, live filtering, instant startup, customizable key-bindings, and vi-style default key-bindings.<br />
<br />
== Installation ==<br />
<br />
[[Install]] the {{Pkg|cmus}} package, or {{AUR|cmus-git}} for the development version.<br />
<br />
=== Using cmus with alsa ===<br />
When using cmus with [[Advanced Linux Sound Architecture]] the default configuration does not allow playing music. What you might encounter when trying to start cmus is a blank terminal line with no output whatsoever. To fix it, create a new config file and set the following variables<br />
{{hc|~/.config/cmus/rc|2=<br />
set output_plugin=alsa<br />
set dsp.alsa.device=default<br />
set mixer.alsa.device=default<br />
set mixer.alsa.channel=Master<br />
}}<br />
<br />
==Usage==<br />
Cmus comes with a great reference manual.<br />
$ man cmus <br />
$ man cmus-tutorial<br />
$ man cmus-remote<br />
<br />
=== Starting Cmus ===<br />
<br />
To start cmus, type:<br />
$ cmus<br />
<br />
When you first launch cmus it will open to the album/artist tab.<br />
<br />
=== Adding Music ===<br />
Press {{ic|5}} to switch to the file-browser tab so we can add some music.<br />
Now, use the arrow keys ({{ic|up}}, {{ic|down}}), {{ic|Enter}} and {{ic|Backspace}} to navigate to where you have audio files stored. Alternatively, you may use the vim bindings ({{ic|k}}, {{ic|j}}) to navigate up and down through your music.<br />
<br />
To add music to your cmus library, use the arrow keys to highlight a file or folder, and press {{ic|a}}. When you press {{ic|a}} cmus will move you to the next line down (so that it is easy to add a bunch of files/folders in a row) and start adding the file/folder you pressed {{ic|a}} in to your library. This may take a bit if you added a folder with a lot of music in it. As files are added, you will see the second time in the bottom right go up. This is the total duration of all the music in the cmus library.<br />
{{Note|cmus does not move, duplicate or change your files. It just remembers where they are and caches the metadata (duration, artist, etc.)}} <br />
{{Note|Cmus automatically saves your settings, library and everything when you quit.}}<br />
<br />
=== Playing Tracks ===<br />
Press {{ic|1}} to go to the simple library view. Use the {{ic|up}} and {{ic|down}} arrow keys (or {{ic|k}}, {{ic|j}}) to select an artist and album you would like to hear. Pressing {{ic|space}} on the artist name will collapse or expand the albums it contains. Switch between list of tracks and artist/album view by pressing {{ic|Tab}} and press {{ic|Enter}} to play the selected track. Here is some keys to control the playback:<br />
:Press {{ic|c}} to pause/unpause<br />
:Press {{ic|right}}/{{ic|left}} (or {{ic|h}}, {{ic|l}}) arrow keys to seek by 10 seconds<br />
:Press {{ic|<}}/{{ic|>}} seek by one minute<br />
<br />
=== Keybindings ===<br />
See the configuration section on how to change keybindings.<br />
<br />
==Tabs==<br />
There are 7 tabs in cmus. Press keys {{ic|1}}-{{ic|7}} to change active tab. <br />
<br />
=== Library tab (1) ===<br />
Display all tracks in so-called '''library'''. Tracks are sorted artist/album tree. Artist sorting is done alphabetically. Albums are sorted by year. <br />
<br />
=== Sorted library tab (2) ===<br />
Displays same content as view, but as a simple list which is automatically sorted by user criteria. <br />
<br />
=== Playlist tab (3) ===<br />
Displays editable playlist with optional sorting. <br />
<br />
=== Play Queue tab (4) ===<br />
Displays queue of tracks which are played next. These tracks are played before anything else (i.e. the playlist or library).<br />
<br />
=== Browser (5) ===<br />
Directory browser. In this tab, music can be added to either the library, playlist or queue from the filesystem. <br />
<br />
=== Filters tab (6) ===<br />
Lists user defined filters.<br />
<br />
=== Settings tab (7) ===<br />
Change settings. See configuration for further information.<br />
<br />
== Configuration ==<br />
To configure cmus start it and switch to the configuration tab by pressing {{ic|7}}. Now you can see a list of default keybindings. Select a field in the list with the arrow keys and press{{ic|Enter}} to edit the values. You can also remove bindings with {{ic|D}} or {{ic|del}}. To edit unbound commands and option variables scroll down in the list to the relevant section. Variables can also be toggled instead of edited with {{ic|space}}. Cmus allows changing the color of nearly every interface element. You can prefix colors with "light" to make them appear brighter and set attributes for some text elements.<br />
<br />
=== Remote Control ===<br />
Cmus can be controlled externally through a unix-socket with {{ic|cmus-remote}}. This makes it easy to control playback through an external application or key-binding.<br />
<br />
One such usage of this feature is to control playback in Cmus with the XF86 keyboard events. The following script when run will start Cmus in an xterm terminal if it is not running, otherwise it will will toggle play/pause:<br />
<br />
{{bc|1=<br />
#!/bin/sh<br />
# This command will break if you rename it to<br />
# something containing "cmus".<br />
<br />
if ! pgrep cmus ; then<br />
xterm -e cmus<br />
else<br />
cmus-remote -u<br />
fi<br />
}}<br />
<br />
To use the previous script in [[Openbox]], copy the code above into a file {{ic|~/bin/cplay}}. Make the file executable using {{ic|chmod +x ~/bin/cplay}}. Next edit {{ic|~/.config/openbox/rc.xml}} and change the following key-bindings to look like this:<br />
{{note|Make sure there are no conflicting keybindings in rc.xml}}<br />
<br />
{{hc|~/.config/openbox/rc.xml|<nowiki><br />
<keyboard><br />
<keybind key="XF86AudioPlay"><br />
<action name="Execute"><br />
<command>cmus-remote -u</command><br />
</action><br />
</keybind><br />
<keybind key="XF86AudioNext"><br />
<action name="Execute"><br />
<command>cmus-remote -n</command><br />
</action><br />
</keybind><br />
<keybind key="XF86AudioPrev"><br />
<action name="Execute"><br />
<command>cmus-remote -r</command><br />
</action><br />
</keybind><br />
</keyboard><br />
</nowiki>}}<br />
<br />
Now when you use the {{ic|XF86AudioPlay}} key on your keyboard, cmus will open up. If it is opened already it will then start playing. Using the XF86AudioNext and XF86AudioPrev keys will change tracks.<br />
<br />
== See also ==<br />
<br />
* [https://github.com/cmus/cmus Git Repository]<br />
* [https://cmus.github.io/ Website]<br />
* [https://github.com/cmus/cmus/wiki User submitted scripts]</div>X33ahttps://wiki.archlinux.org/index.php?title=Talk:Forum_etiquette&diff=426452Talk:Forum etiquette2016-03-19T05:54:23Z<p>X33a: /* Addition to Cross-posting */ forgot to sign</p>
<hr />
<div>== Is ok that "malignant code" is not tolerated on the forum, but is not ok to say is illegal ==<br />
<br />
It says is illegal the creation of "malignant code" (I guess that includes things like trojan horses, viruses etc):<br />
<br />
Therefore, do not post discussions about or link to criminal solicitation in any form. This includes, but is not limited (...) creation of malignant code (...)<br />
<br />
I'm '''not''' saying it should be tolerated here, mostly because Arch forums are not for that. However, the ''creation'' of '''code with pontential malignant uses''' is LEGAL. (and there is no such thing as "malignant code"; code is not good or evil) <br />
About viruses and other malware, the illegal part is the use you give to the code.<br />
<br />
So I think that bit should be moved out from the legality section to another part (not sure which one fits)<br />
<br />
--[[User:Chrisl|Chrisl]] ([[User talk:Chrisl|talk]]) 22:30, 29 October 2012 (UTC)<br />
<br />
:Hi Chrisl, <br />
<br />
:The intent of this section seems clear to me from the following section (emphasis is mine):<br />
<br />
:''In this context, "criminal solicitation" shall mean, "To actively or '''passively inform about,''' facilitate, incite, move, or persuade others to '''some act of lawlessness''' or '''illegal activity'''."''<br />
<br />
:Perhaps it is a legally grey (or even white) area in some countries, but providing such information may indeed "passively inform [others] about" illegal activities. As such, to err on the safe side, the existing content seems proper.<br />
<br />
:Cheers!<br />
:[[User:AdamT|AdamT]] ([[User talk:AdamT|talk]]) 05:10, 18 June 2013 (UTC)<br />
<br />
== Posted image size ==<br />
1. Do we keep [https://wiki.archlinux.org/index.php/Forum_etiquette#Pasting_Pictures_and_Code the current restrictions] or do we loosen / revise them? The current 250x250px and < 50 klilobyte is fine with me, but we currently use [http://en.wikipedia.org/wiki/Kilobyte Kb] which seems to be the wrong unit, <s>even though [http://en.wikipedia.org/wiki/KB the disambiguation page] says "Kilobyte (Kb)". I've always thought [http://en.wikipedia.org/wiki/Kilobit 'b' is for 'bit', not 'byte'].</s>.<br />
:[https://en.wikipedia.org/w/index.php?title=KB&diff=600496395&oldid=596484221 'Kb' is a recent change], [https://en.wikipedia.org/w/index.php?title=KB&diff=next&oldid=600496395 I've undone it]. -- [[User:Karol|Karol]] ([[User talk:Karol|talk]]) 12:42, 24 March 2014 (UTC)<br />
<br />
2. What forum sections / threads are free from these restrictions?<br />
-- [[User:Karol|Karol]] ([[User talk:Karol|talk]]) 12:35, 24 March 2014 (UTC)<br />
:The only thread where this is disregarded is the "I'm bored, let's have an image thread." [[User:Jasonwryan|jasonwryan]] ([[User talk:Jasonwryan|talk]]) 16:38, 24 March 2014 (UTC)<br />
<br />
::I don't think we need an extra rule for just one thread ... -- [[User:Alad|Alad]] ([[User talk:Alad|talk]]) 09:00, 12 February 2016 (UTC)<br />
<br />
== <s>Ad “Pasting pictures and code”: always post links (incl. thumbs with links)</s> ==<br />
<br />
A little suggestion: can the following fragment:<br />
::''“Do not post full screen pictures; use thumbnails instead.”''<br />
be replaced with this?<br />
::''“Do not post full screen pictures; use links to the images instead, optionally with thumbnails.”''<br />
The latter puts more emphasis on linking the resource instead of embedding it, and treats thumbnails as an aid for the thread reader, not the content itself.<br />
<br />
'''Rationale:''' pictures without links are problematic to users who have embedded pictures disabled, block hotlinking from some servers or use text-mode browsers (not that unusual during early OS setup or fixing things).<br />
--[[User:Mpan|Mpan]] ([[User talk:Mpan|talk]]) 08:48, 12 February 2016 (UTC)<br />
<br />
:Good suggestion, implemented. [https://wiki.archlinux.org/index.php?title=Forum_etiquette&diff=420151&oldid=395918] Closing. -- [[User:Alad|Alad]] ([[User talk:Alad|talk]]) 08:59, 12 February 2016 (UTC)<br />
<br />
== Ad “Pasting pictures and code”: link to [[Copying text from a terminal]] ==<br />
<br />
May a link to [[Copying text from a terminal]] be added in the following fragment?<br />
: ''“Do not post screenshots of text output; post the actual text.”''<br />
Expected result:<br />
: ''“Do not post screenshots of text output; post [[Copying text from a terminal|the actual text]].”''<br />
--[[User:Mpan|Mpan]] ([[User talk:Mpan|talk]]) 08:47, 12 February 2016 (UTC)<br />
<br />
== Addition to Cross-posting ==<br />
<br />
Currently we have the cross-posting section which says:<br />
<br />
Cross-posting is posting the same question multiple times in different subforums.<br />
<br />
It doesn't cover the scenario when users post multiple threads pertaining to the same topic, with or without minor changes, in the same subforum. So, I suggest that the section be changed to "Cross-posting/Posting multiple topics" and cover the above mentioned scenario in that.<br />
<br />
[[User:X33a|X33a]] ([[User talk:X33a|talk]]) 05:54, 19 March 2016 (UTC)</div>X33ahttps://wiki.archlinux.org/index.php?title=Talk:Forum_etiquette&diff=426451Talk:Forum etiquette2016-03-19T05:53:39Z<p>X33a: addition to cross-posting</p>
<hr />
<div>== Is ok that "malignant code" is not tolerated on the forum, but is not ok to say is illegal ==<br />
<br />
It says is illegal the creation of "malignant code" (I guess that includes things like trojan horses, viruses etc):<br />
<br />
Therefore, do not post discussions about or link to criminal solicitation in any form. This includes, but is not limited (...) creation of malignant code (...)<br />
<br />
I'm '''not''' saying it should be tolerated here, mostly because Arch forums are not for that. However, the ''creation'' of '''code with pontential malignant uses''' is LEGAL. (and there is no such thing as "malignant code"; code is not good or evil) <br />
About viruses and other malware, the illegal part is the use you give to the code.<br />
<br />
So I think that bit should be moved out from the legality section to another part (not sure which one fits)<br />
<br />
--[[User:Chrisl|Chrisl]] ([[User talk:Chrisl|talk]]) 22:30, 29 October 2012 (UTC)<br />
<br />
:Hi Chrisl, <br />
<br />
:The intent of this section seems clear to me from the following section (emphasis is mine):<br />
<br />
:''In this context, "criminal solicitation" shall mean, "To actively or '''passively inform about,''' facilitate, incite, move, or persuade others to '''some act of lawlessness''' or '''illegal activity'''."''<br />
<br />
:Perhaps it is a legally grey (or even white) area in some countries, but providing such information may indeed "passively inform [others] about" illegal activities. As such, to err on the safe side, the existing content seems proper.<br />
<br />
:Cheers!<br />
:[[User:AdamT|AdamT]] ([[User talk:AdamT|talk]]) 05:10, 18 June 2013 (UTC)<br />
<br />
== Posted image size ==<br />
1. Do we keep [https://wiki.archlinux.org/index.php/Forum_etiquette#Pasting_Pictures_and_Code the current restrictions] or do we loosen / revise them? The current 250x250px and < 50 klilobyte is fine with me, but we currently use [http://en.wikipedia.org/wiki/Kilobyte Kb] which seems to be the wrong unit, <s>even though [http://en.wikipedia.org/wiki/KB the disambiguation page] says "Kilobyte (Kb)". I've always thought [http://en.wikipedia.org/wiki/Kilobit 'b' is for 'bit', not 'byte'].</s>.<br />
:[https://en.wikipedia.org/w/index.php?title=KB&diff=600496395&oldid=596484221 'Kb' is a recent change], [https://en.wikipedia.org/w/index.php?title=KB&diff=next&oldid=600496395 I've undone it]. -- [[User:Karol|Karol]] ([[User talk:Karol|talk]]) 12:42, 24 March 2014 (UTC)<br />
<br />
2. What forum sections / threads are free from these restrictions?<br />
-- [[User:Karol|Karol]] ([[User talk:Karol|talk]]) 12:35, 24 March 2014 (UTC)<br />
:The only thread where this is disregarded is the "I'm bored, let's have an image thread." [[User:Jasonwryan|jasonwryan]] ([[User talk:Jasonwryan|talk]]) 16:38, 24 March 2014 (UTC)<br />
<br />
::I don't think we need an extra rule for just one thread ... -- [[User:Alad|Alad]] ([[User talk:Alad|talk]]) 09:00, 12 February 2016 (UTC)<br />
<br />
== <s>Ad “Pasting pictures and code”: always post links (incl. thumbs with links)</s> ==<br />
<br />
A little suggestion: can the following fragment:<br />
::''“Do not post full screen pictures; use thumbnails instead.”''<br />
be replaced with this?<br />
::''“Do not post full screen pictures; use links to the images instead, optionally with thumbnails.”''<br />
The latter puts more emphasis on linking the resource instead of embedding it, and treats thumbnails as an aid for the thread reader, not the content itself.<br />
<br />
'''Rationale:''' pictures without links are problematic to users who have embedded pictures disabled, block hotlinking from some servers or use text-mode browsers (not that unusual during early OS setup or fixing things).<br />
--[[User:Mpan|Mpan]] ([[User talk:Mpan|talk]]) 08:48, 12 February 2016 (UTC)<br />
<br />
:Good suggestion, implemented. [https://wiki.archlinux.org/index.php?title=Forum_etiquette&diff=420151&oldid=395918] Closing. -- [[User:Alad|Alad]] ([[User talk:Alad|talk]]) 08:59, 12 February 2016 (UTC)<br />
<br />
== Ad “Pasting pictures and code”: link to [[Copying text from a terminal]] ==<br />
<br />
May a link to [[Copying text from a terminal]] be added in the following fragment?<br />
: ''“Do not post screenshots of text output; post the actual text.”''<br />
Expected result:<br />
: ''“Do not post screenshots of text output; post [[Copying text from a terminal|the actual text]].”''<br />
--[[User:Mpan|Mpan]] ([[User talk:Mpan|talk]]) 08:47, 12 February 2016 (UTC)<br />
<br />
== Addition to Cross-posting ==<br />
<br />
Currently we have the cross-posting section which says:<br />
<br />
Cross-posting is posting the same question multiple times in different subforums.<br />
<br />
It doesn't cover the scenario when users post multiple threads pertaining to the same topic, with or without minor changes, in the same subforum. So, I suggest that the section be changed to "Cross-posting/Posting multiple topics" and cover the above mentioned scenario in that.</div>X33ahttps://wiki.archlinux.org/index.php?title=Pacman&diff=419295Pacman2016-02-06T12:03:05Z<p>X33a: /* Skip files from being installed to system */ Added note regarding bleachbit and localepurge with pacman 5</p>
<hr />
<div>{{Lowercase title}}<br />
[[Category:Package management]]<br />
[[ar:Pacman]]<br />
[[cs:Pacman]]<br />
[[da:Pacman]]<br />
[[de:Pacman]]<br />
[[el:Pacman]]<br />
[[es:Pacman]]<br />
[[fa:Pacman]]<br />
[[fr:Pacman]]<br />
[[id:Pacman]]<br />
[[it:Pacman]]<br />
[[ja:Pacman]]<br />
[[ko:Pacman]]<br />
[[nl:Pacman]]<br />
[[pl:Pacman]]<br />
[[pt:Pacman]]<br />
[[ro:Pacman]]<br />
[[ru:Pacman]]<br />
[[sr:Pacman]]<br />
[[sv:Pacman]]<br />
[[tr:pacman]]<br />
[[uk:Pacman]]<br />
[[zh-CN:Pacman]]<br />
[[zh-TW:Pacman]]<br />
{{Related articles start}}<br />
{{Related|Creating packages}}<br />
{{Related|Downgrading packages}}<br />
{{Related|pacman/Package signing}}<br />
{{Related|pacman/Pacnew and Pacsave}}<br />
{{Related|pacman/Rosetta}}<br />
{{Related|pacman/Tips and tricks}}<br />
{{Related|FAQ#Package Management}}<br />
{{Related|System maintenance}}<br />
{{Related|Arch Build System}}<br />
{{Related|Official repositories}}<br />
{{Related|Arch User Repository}}<br />
{{Related articles end}}<br />
<br />
The [https://www.archlinux.org/pacman/ pacman] [[Wikipedia:Package management system|package manager]] is one of the major distinguishing features of Arch Linux. It combines a simple binary package format with an easy-to-use [[Arch Build System|build system]]. The goal of ''pacman'' is to make it possible to easily manage packages, whether they are from the [[official repositories]] or the user's own builds.<br />
<br />
''pacman'' keeps the system up to date by synchronizing package lists with the master server. This server/client model also allows the user to download/install packages with a simple command, complete with all required dependencies.<br />
<br />
''pacman'' is written in the C programming language and uses the ''.pkg.tar.xz'' package format.<br />
<br />
{{Tip|The {{Pkg|pacman}} package contains other useful tools such as '''makepkg''', '''pactree''', '''vercmp''', and [[checkupdates]]. Run {{ic|pacman -Qlq pacman <nowiki>|</nowiki> grep bin}} to see the full list.}}<br />
<br />
== Usage ==<br />
<br />
{{Expansion|1=pacman 5.0 added some new operations: {{ic|-F}} and {{ic|-D}} [https://projects.archlinux.org/pacman.git/tree/NEWS?h=v5.0.0].}}<br />
<br />
What follows is just a small sample of the operations that ''pacman'' can perform. To read more examples, refer to [https://www.archlinux.org/pacman/pacman.8.html man pacman].<br />
<br />
{{Tip|For those who have used other Linux distributions before, there is a helpful [[Pacman Rosetta]] article.}}<br />
<br />
=== Installing packages ===<br />
<br />
{{Note|Packages often have a series of [[PKGBUILD#optdepends|optional dependencies]] which are packages that provide additional functionality to the application, albeit not strictly required for running it. When installing a package, ''pacman'' will list its optional dependencies among the output messages, but they will not be found in {{ic|pacman.log}}: refer to [[#Querying package databases]] when you want to view the optional dependencies of an already installed package, together with short descriptions of their functionality.}}<br />
<br />
{{Warning|1=When installing packages in Arch, avoid refreshing the package list without [[#Upgrading packages|upgrading the system]] (for example, when a [[#Packages cannot be retrieved on installation|package is no longer found]] in the official repositories). In practice, do '''not''' run {{ic|pacman -Sy ''package_name''}} instead of {{ic|pacman -Sy'''u''' ''package_name''}}, as this could lead to dependency issues. See [[System maintenance#Partial upgrades are unsupported]] and [https://bbs.archlinux.org/viewtopic.php?id=89328 BBS#89328].}}<br />
<br />
==== Installing specific packages ====<br />
<br />
To install a single package or list of packages (including dependencies), issue the following command:<br />
<br />
# pacman -S ''package_name1'' ''package_name2'' ...<br />
<br />
To install a list of packages with regex (see [[pacman tips#Operations and Bash syntax]] and [https://bbs.archlinux.org/viewtopic.php?id=7179 this forum thread]):<br />
<br />
# pacman -S $(pacman -Ssq ''package_regex'')<br />
<br />
Sometimes there are multiple versions of a package in different repositories, e.g. ''extra'' and ''testing''. To install the former version, the repository needs to be defined in front:<br />
<br />
# pacman -S extra/''package_name''<br />
<br />
==== Installing package groups ====<br />
<br />
Some packages belong to a [[Creating_packages#Meta_packages_and_groups|group of packages]] that can all be installed simultaneously. For example, issuing the command:<br />
<br />
# pacman -S gnome<br />
<br />
will prompt you to select the packages from the {{Grp|gnome}} group that you wish to install.<br />
<br />
Sometimes a package group will contain a large amount of packages, and there may be only a few that you do or do not want to install. Instead of having to enter all the numbers except the ones you do not want, it is sometimes more convenient to select or exclude packages or ranges of packages with the following syntax:<br />
<br />
Enter a selection (default=all): 1-10 15<br />
<br />
which will select packages 1 through 10 and 15 for installation, or:<br />
<br />
Enter a selection (default=all): ^5-8 ^2<br />
<br />
which will select all packages except 5 through 8 and 2 for installation.<br />
<br />
To see what packages belong to the gnome group, run:<br />
<br />
# pacman -Sg gnome<br />
<br />
Also visit https://www.archlinux.org/groups/ to see what package groups are available.<br />
<br />
{{Note|If a package in the list is already installed on the system, it will be reinstalled even if it is already up to date. This behavior can be overridden with the {{ic|--needed}} option.}}<br />
<br />
=== Removing packages ===<br />
<br />
To remove a single package, leaving all of its dependencies installed:<br />
<br />
# pacman -R ''package_name''<br />
<br />
To remove a package and its dependencies which are not required by any other installed package:<br />
<br />
# pacman -Rs ''package_name''<br />
<br />
To remove a package, its dependencies and all the packages that depend on the target package:<br />
<br />
{{Warning|This operation is recursive, and must be used with care since it can remove many potentially needed packages.}}<br />
<br />
# pacman -Rsc ''package_name''<br />
<br />
To remove a package, which is required by another package, without removing the dependent package:<br />
<br />
# pacman -Rdd ''package_name''<br />
<br />
''pacman'' saves important configuration files when removing certain applications and names them with the extension: ''.pacsave''. To prevent the creation of these backup files use the {{ic|-n}} option:<br />
<br />
# pacman -Rn ''package_name''<br />
<br />
{{Note|''pacman'' will not remove configurations that the application itself creates (for example "dotfiles" in the home folder).}}<br />
<br />
=== Upgrading packages ===<br />
<br />
{{Merge|System maintenance||Talk:Pacman#Don't rush upgrades}}<br />
{{Warning|Arch only supports full system upgrades. See [[System maintenance#Partial upgrades are unsupported]] and [[#Installing packages]] for details.}}<br />
<br />
It is recommended that users [[System_maintenance#Upgrading the system|upgrade their system regularly]]. When requesting support from the community, it will usually be assumed that the system is up to date.<br />
<br />
Before upgrading, users are expected to visit the [https://www.archlinux.org/ Arch Linux home page] to check the latest news, or alternatively subscribe to the [https://www.archlinux.org/feeds/news/ RSS feed], [https://mailman.archlinux.org/mailman/listinfo/arch-announce/ arch-announce mailing list], or follow [https://twitter.com/archlinux @archlinux] on Twitter: when updates require out-of-the-ordinary user intervention (more than what can be handled simply by following the instructions given by ''pacman''), an appropriate news post will be made. Users must equally be aware that upgrading packages can raise '''unexpected''' problems that could need immediate intervention, therefore it is discouraged to upgrade a stable system shortly before it is required for carrying out an important task: it is wise to wait instead to have enough time in order to be able to deal with possible post-upgrade issues.<br />
<br />
''pacman'' can update all packages on the system with just one command. This could take quite a while depending on how up-to-date the system is. This command can synchronize the repository databases ''and'' update the system's packages (excluding "local" packages that are not in the configured repositories):<br />
<br />
# pacman -Syu<br />
<br />
''pacman'' is a powerful package management tool, but it does not attempt to handle all corner cases. Users must be vigilant and take responsibility for maintaining their own system. '''When performing a system update, it is essential that users read all information output by ''pacman'' and use common sense.''' If a user-modified configuration file needs to be upgraded for a new version of a package, a ''.pacnew'' file will be created to avoid overwriting settings modified by the user. ''pacman'' will prompt the user to merge them. These files require manual intervention from the user and it is good practice to handle them right after every package upgrade or removal. See [[Pacnew and Pacsave files]] for more information.<br />
<br />
{{Tip|<br />
* Remember that ''pacman'''s output is logged in {{ic|/var/log/pacman.log}}.<br />
* You can use a log viewer such as {{AUR|wat-git}} to search the pacman logs.}}<br />
<br />
If one encounters problems that cannot be solved by these instructions, make sure to search the forum. It is likely that others have encountered the same problem and have posted instructions for solving it.<br />
<br />
=== Querying package databases ===<br />
<br />
''pacman'' queries the local package database with the {{ic|-Q}} flag; see:<br />
<br />
$ pacman -Q --help<br />
<br />
and queries the sync databases with the {{ic|-S}} flag; see:<br />
<br />
$ pacman -S --help<br />
<br />
''pacman'' can search for packages in the database, searching both in packages' names and descriptions:<br />
<br />
$ pacman -Ss ''string1'' ''string2'' ...<br />
<br />
To search for already installed packages:<br />
<br />
$ pacman -Qs ''string1'' ''string2'' ...<br />
<br />
To display extensive information about a given package:<br />
<br />
$ pacman -Si ''package_name''<br />
<br />
For locally installed packages:<br />
<br />
$ pacman -Qi ''package_name''<br />
<br />
Passing two {{ic|-i}} flags will also display the list of backup files and their modification states:<br />
<br />
$ pacman -Qii ''package_name''<br />
<br />
To retrieve a list of the files installed by a package:<br />
<br />
$ pacman -Ql ''package_name''<br />
<br />
For packages not installed, use [[pkgfile]].<br />
<br />
To verify the presence of the files installed by a package:<br />
<br />
$ pacman -Qk ''package_name''<br />
<br />
Passing the {{ic|k}} flag twice will perform a more thorough check.<br />
<br />
One can also query the database to know which package a file in the file system belongs to:<br />
<br />
$ pacman -Qo ''/path/to/file_name''<br />
<br />
To list all packages no longer required as dependencies (orphans):<br />
<br />
$ pacman -Qdt<br />
<br />
To list all packages explicitly installed and not required as dependencies:<br />
<br />
$ pacman -Qet<br />
<br />
To list a dependency tree of a package:<br />
<br />
$ pactree ''package_name''<br />
<br />
To list all the packages recursively depending on an ''installed'' package, use ''whoneeds'' from {{AUR|pkgtools}}:<br />
<br />
$ whoneeds ''package_name''<br />
<br />
or the reverse flag to ''pactree'':<br />
<br />
$ pactree -r ''package_name''<br />
<br />
See [[pacman tips]] for more examples.<br />
<br />
==== Database structure ====<br />
<br />
The pacman databases are normally located at {{ic|/var/lib/pacman/sync}}. For each repository specified in {{ic|/etc/pacman.conf}} there will be a corresponding database file located there. Database files are tar-gzipped archives containing one directory for each package, for example for the {{Pkg|which}} package:<br />
<br />
{{bc|<br />
% tree which-2.20-6 <br />
which-2.20-6<nowiki><br />
|-- depends<br />
`-- desc</nowiki><br />
}}<br />
<br />
The {{ic|depends}} file lists the packages this package depends on, while {{ic|desc}} has a description of the package such as the file size and the MD5 hash.<br />
<br />
=== Cleaning the package cache ===<br />
<br />
''pacman'' stores its downloaded packages in {{ic|/var/cache/pacman/pkg/}} and does not remove the old or uninstalled versions automatically, therefore it is necessary to deliberately clean up that folder periodically to prevent such folder to grow indefinitely in size.<br />
<br />
The built-in option to remove all the cached packages that are not currently installed is:<br />
<br />
# pacman -Sc<br />
<br />
{{Warning|<br />
* Only do this when certain that previous package versions are not required, for example for a later [[downgrade]]. {{ic|pacman -Sc}} only leaves the versions of packages which are ''currently installed'' available, older versions would have to be retrieved through other means, such as the [[Archive]].<br />
* It is possible to empty the cache folder fully with {{ic|pacman -Scc}}. In addition to the above, this also also prevents from reinstalling a package directly ''from'' the cache folder in case of need, thus requiring a new download. It should be avoided unless there is an immediate need for disk space.<br />
}}<br />
<br />
Because of the above limitations, consider an alternative for more control over which packages, and how many, are deleted from the cache:<br />
<br />
The ''paccache'' script, provided by the {{Pkg|pacman}} package itself, deletes all cached versions of each package, except for the most recent 3, by default:<br />
<br />
# paccache -r<br />
<br />
Used this way, it will ''not'' check whether a package is still installed or not, and uninstalled packages will remain in the cache. To remove all cached versions of uninstalled packages, re-run ''paccache'' with:<br />
<br />
# paccache -ruk0<br />
<br />
See {{ic|paccache -h}} for more options.<br />
<br />
{{AUR|pkgcacheclean}} and {{AUR|pacleaner}} are two further alternatives.<br />
<br />
=== Additional commands ===<br />
<br />
Download a package without installing it:<br />
<br />
# pacman -Sw ''package_name''<br />
<br />
Install a 'local' package that is not from a remote repository (e.g. the package is from the [[AUR]]):<br />
<br />
# pacman -U /path/to/package/package_name-version.pkg.tar.xz<br />
<br />
To keep a copy of the local package in ''pacman'''s cache, use:<br />
<br />
# pacman -U file:///path/to/package/package_name-version.pkg.tar.xz<br />
<br />
Install a 'remote' package (not from a repository stated in ''pacman'''s configuration files):<br />
<br />
# pacman -U <nowiki>http://www.example.com/repo/example.pkg.tar.xz</nowiki><br />
<br />
To inhibit the {{ic|-S}}, {{ic|-U}} and {{ic|-R}} actions, {{ic|-p}} can be used.<br />
<br />
''pacman'' always lists packages to be installed or removed and asks for permission before it takes action.<br />
<br />
== Configuration ==<br />
<br />
''pacman'''s settings are located in {{ic|/etc/pacman.conf}}. This is the place where the user configures the program to work in the desired manner. In-depth information about the configuration file can be found in [https://www.archlinux.org/pacman/pacman.conf.5.html man pacman.conf].<br />
<br />
=== General options ===<br />
<br />
General options are in the {{ic|[options]}} section. Read the [[man page]] or look in the default {{ic|pacman.conf}} for information on what can be done here.<br />
<br />
==== Color output ====<br />
<br />
Pacman has a color option. Uncomment the "Color" line in {{ic|/etc/pacman.conf}}.<br />
<br />
==== Comparing versions before updating ====<br />
<br />
To see old and new versions of available packages, uncomment the "VerbosePkgLists" line in {{ic|/etc/pacman.conf}}. The output of {{ic|pacman -Syu}} will be like this:<br />
<br />
Package (6) Old Version New Version Net Change Download Size<br />
<br />
extra/libmariadbclient 10.1.9-4 10.1.10-1 0.03 MiB 4.35 MiB<br />
extra/libpng 1.6.19-1 1.6.20-1 0.00 MiB 0.23 MiB<br />
extra/mariadb 10.1.9-4 10.1.10-1 0.26 MiB 13.80 MiB<br />
<br />
==== Skip package from being upgraded ====<br />
<br />
To have a specific package skipped when [[#Upgrading packages|upgrading]] the system, specify it as such:<br />
<br />
IgnorePkg=linux<br />
<br />
For multiple packages use a space-separated list, or use additional {{ic|IgnorePkg}} lines. Also, glob patterns can be used. If you want to skip packages just once, you can also use the {{ic|--ignore}} option on the command-line - this time with a comma-separated list.<br />
<br />
It will still be possible to upgrade the ignored packages using {{ic|pacman -S}}: in this case ''pacman'' will remind you that the packages have been included in an {{ic|IgnorePkg}} statement.<br />
<br />
==== Skip package group from being upgraded ====<br />
<br />
As with packages, skipping a whole package group is also possible:<br />
<br />
IgnoreGroup=gnome<br />
<br />
==== Skip files from being installed to system ====<br />
<br />
To always skip installation of specific directories list them under {{Ic|NoExtract}}. For example, to avoid installation of [[systemd]] units use this:<br />
<br />
NoExtract=usr/lib/systemd/system/*<br />
<br />
Or as a preemptive alternative to {{AUR|localepurge}}, to avoid installing non-English localizations:<br />
<br />
{{Note|Since pacman 5, while updating a package for which locales have been cleared by localepurge or bleachbit, pacman issues warning messages about the missing locales. To suppress such warning messages, comment the {{ic|CheckSpace}} option in {{ic|pacman.conf}}}}<br />
<br />
NoExtract = usr/share/help/* !usr/share/help/en*<br />
NoExtract = usr/share/locale/* !usr/share/locale/en*<br />
NoExtract = usr/share/man/* !usr/share/man/man*<br />
NoExtract = usr/share/vim/vim74/lang/*<br />
<br />
Later rules override previous ones, and you can negate a rule by prepending {{ic|!}} — this allows you to keep the locales you need.<br />
<br />
==== Maintain several configuration files ====<br />
<br />
If you have several configuration files (e.g. main configuration and configuration with [[testing]] repository enabled) and would have to share options between configurations you may use {{ic|Include}} option declared in the configuration files, e.g.:<br />
<br />
Include = /path/to/common/settings<br />
<br />
where {{ic|/path/to/common/settings}} file contains the same options for both configurations.<br />
<br />
=== Repositories ===<br />
<br />
{{Expansion|mirrorlist contains only official repositories, even though some [[unofficial user repositories]] also provide their own mirrors.}}<br />
<br />
This section defines which [[Official repositories|repositories]] to use, as referred to in {{ic|/etc/pacman.conf}}. They can be stated here directly or included from another file (such as {{ic|/etc/pacman.d/mirrorlist}}), thus making it necessary to maintain only one list. See [[Mirrors]] article for mirror configuration.<br />
<br />
The order of repositories in the configuration files matters; repositories listed first will take precedence over those listed later in the file when packages in two repositories have identical names, regardless of version number.<br />
<br />
=== Package security ===<br />
<br />
''pacman'' 4 supports package signatures, which add an extra layer of security to the packages. The default configuration, {{ic|1=SigLevel = Required DatabaseOptional}}, enables signature verification for all the packages on a global level: this can be overridden by per-repository {{ic|SigLevel}} lines as shown above. For more details on package signing and signature verification, take a look at [[pacman-key]].<br />
<br />
== Troubleshooting ==<br />
<br />
=== "Failed to commit transaction (conflicting files)" error ===<br />
<br />
If you see the following error: [https://bbs.archlinux.org/viewtopic.php?id=56373]<br />
<br />
error: could not prepare transaction<br />
error: failed to commit transaction (conflicting files)<br />
''package'': ''/path/to/file'' exists in filesystem<br />
Errors occurred, no packages were upgraded.<br />
<br />
Why this is happening: ''pacman'' has detected a file conflict, and by design, will not overwrite files for you. This is a design feature, not a flaw.<br />
<br />
The problem is usually trivial to solve. A safe way is to first check if another package owns the file ({{ic|pacman -Qo ''/path/to/file''}}). If the file is owned by another package, [[Reporting bug guidelines|file a bug report]]. If the file is not owned by another package, rename the file which 'exists in filesystem' and re-issue the update command. If all goes well, the file may then be removed.<br />
<br />
If you had installed a program manually without using ''pacman'' or a frontend, for example through {{ic|make install}}, you have to remove it and all its files and reinstall properly using ''pacman''. See also [[Pacman tips#Identify files not owned by any package]].<br />
<br />
Every installed package provides a {{ic|/var/lib/pacman/local/''$package-$version''/files}} file that contains metadata about this package. If this file gets corrupted, is empty or goes missing, it results in {{ic|file exists in filesystem}} errors when trying to update the package. Such an error usually concerns only one package. Instead of manually renaming and later removing all the files that belong to the package in question, you may exceptionally run {{ic|pacman -S --force $package}} to force ''pacman'' to overwrite these files.<br />
<br />
{{Warning|Take care when using the {{ic|--force}} switch (for example {{ic|pacman -Syu --force}}) as it can cause major problems if used improperly. It is highly recommended to only use this option when the Arch news instructs the user to do so.}}<br />
<br />
=== "Failed to commit transaction (invalid or corrupted package)" error ===<br />
<br />
Look for ''.part'' files (partially downloaded packages) in {{ic|/var/cache/pacman/pkg}} and remove them (often caused by usage of a custom {{ic|XferCommand}} in {{ic|pacman.conf}}).<br />
<br />
# find /var/cache/pacman/pkg/ -iname "*.part" -exec rm {} \;<br />
<br />
=== "Failed to init transaction (unable to lock database)" error ===<br />
<br />
When ''pacman'' is about to alter the package database, for example installing a package, it creates a lock file at {{ic|/var/lib/pacman/db.lck}}. This prevents another instance of ''pacman'' from trying to alter the package database at the same time.<br />
<br />
If ''pacman'' is interrupted while changing the database, this stale lock file can remain. If you are certain that no instances of ''pacman'' are running then delete the lock file:<br />
<br />
# rm /var/lib/pacman/db.lck<br />
<br />
=== Packages cannot be retrieved on installation ===<br />
<br />
This error manifests as {{ic|Not found in sync db}}, {{ic|Target not found}} or {{ic|Failed retrieving file}}.<br />
<br />
Firstly, ensure the package actually exists (and watch out for typos!). If certain the package exists, your package list may be out-of-date or your repositories may be incorrectly configured. Try running {{ic|pacman -Syyu}} to force a refresh of all package lists and upgrade.<br />
<br />
It could also be that the repository containing the package is not enabled on your system, e.g. the package could be in the ''multilib'' repository, but ''multilib'' is not enabled in your ''pacman.conf''.<br />
<br />
See also [[FAQ#Why is there only a single version of each shared library in the official repositories?]].<br />
<br />
=== The same package is upgraded repeatedly ===<br />
<br />
{{Note|''pacman'' version 3.4 should display an error in case of duplicate entries, which should make this note obsolete.}}<br />
<br />
This is due to duplicate entries in {{ic|/var/lib/pacman/local/}}, such as two {{ic|linux}} instances. {{ic|pacman -Qi}} outputs the correct version, but {{ic|pacman -Qu}} recognizes the old version and therefore will attempt to upgrade.<br />
<br />
The solution is to delete the offending entry in {{ic|/var/lib/pacman/local/}}.<br />
<br />
=== Search for a package that contains a specific file ===<br />
<br />
Install [[pkgfile]] which uses a separate database with all files and their associated packages.<br />
<br />
=== pacman is broken beyond repair ===<br />
<br />
{{Accuracy|Any broken dependency of ''pacman'' also breaks ''pacman'', but many dependencies are not mentioned (run {{ic|<nowiki>pactree -l pacman | sort -u | cut -f 1 -d ' '</nowiki>}} to see them all). The info below is likely just a specific case where only two dependencies were broken.}}<br />
<br />
In the case that ''pacman'' is broken beyond repair, manually download the necessary packages ({{Pkg|openssl}}, {{Pkg|libarchive}}, and {{Pkg|pacman}}) and extract them to root. The ''pacman'' binary will be restored along with its default configuration file. Afterwards, reinstall these packages with ''pacman'' to maintain package database integrity. Additional information and an example (outdated) script that automates the process is available in [https://bbs.archlinux.org/viewtopic.php?id=95007 this] forum post.<br />
<br />
Alternatively, you can also use an Arch live media and follow [[#pacman crashes during an upgrade]] to re-install pacman.<br />
<br />
=== pacman crashes during an upgrade ===<br />
<br />
In the case that ''pacman'' crashes with a "database write" error while removing packages, and reinstalling or upgrading packages fails thereafter, do the following:<br />
<br />
# Boot using the Arch installation media. Preferably use a recent media so that the ''pacman'' version matches/is newer than the system. <br />
# Mount the system's root filesystem, e.g. {{ic|mount /dev/sdaX /mnt}} as root, and check the mount has sufficient space with {{ic|df -h}} <br />
# If the system uses default database and directory locations, you can now update the system's pacman database and upgrade it via {{ic|1=pacman --root=/mnt --cachedir=/mnt/var/cache/pacman/pkg -Syyu}} as root. <br />
# After the upgrade, one way to double-check for not upgraded but still broken packages: {{ic|find /mnt/usr/lib -size 0}} <br />
# Followed by a re-install of any still broken package via {{ic|1=pacman --root /mnt --cachedir=/mnt/var/cache/pacman/pkg -S ''package''}}.<br />
<br />
=== pacman crashes the official installation media ===<br />
<br />
The official installation media (ISO) before version 10.2015 are not setup to be updated itself at runtime. Running {{ic|pacman -Syu}} from a booted install media console may crash unexpectedly any time, as soon as memory is depleted. This happens because the install media image build reports an arbitrary capacity (of 32GB) to pacman, regardless of available free memory.[https://bugs.archlinux.org/task/45618#comment137346] At the same time the ISO reserves only a low static memory allotment for operations ({{ic|/run/archiso/cowspace}} of {{ic|256MB}} RAM) of the live system, in order to allow installation on machines with low resources. If the machine has more RAM available, you can override the allotment by setting the {{ic|1=cow_spacesize=}} kernel option for the ISO manually, e.g. {{ic|1=cow_spacesize=2GB}}. <br />
<br />
If you use the install media to update an installed system, you simply have to use the {{ic|1=--root=}} option along with a {{ic|1=--cachedir=}} path to point pacman to available real storage. For example, see [[#pacman crashes during an upgrade]]. <br />
<br />
If you ''require'' an install media with persistent dataspace, the [[Archiso]] build script can be used to create one along with its [https://projects.archlinux.org/archiso.git/tree/docs/README.bootparams boot options].<br />
<br />
=== "Unable to find root device" error after rebooting ===<br />
<br />
Most likely your initramfs got broken during a kernel update (improper use of ''pacman'''s {{ic|--force}} option can be a cause). You have two options; first, try the ''Fallback'' entry:<br />
<br />
{{Tip|In case you removed this entry for whatever reason, you can always press the {{ic|Tab}} key when the bootloader menu shows up (for Syslinux) or {{ic|e}} (for GRUB or gummiboot), rename it {{ic|initramfs-linux-fallback.img}} and press {{ic|Enter}} or {{ic|b}} (depending on your bootloader) to boot with the new parameters.}}<br />
<br />
Once the system starts, run this command (for the stock {{Pkg|linux}} kernel) either from the console or from a terminal to rebuild the initramfs image:<br />
<br />
# mkinitcpio -p linux<br />
<br />
If that does not work, from a current Arch release (CD/DVD or USB stick), run:<br />
<br />
{{Note|If you do not have a current release or if you only have some other "live" Linux distribution laying around, you can [[chroot]] using the old fashioned way. Obviously, there will be more typing than simply running the {{ic|arch-chroot}} script.}}<br />
<br />
# mount /dev/sdxY /mnt # Your root partition.<br />
# mount /dev/sdxZ /mnt/boot # If you use a separate /boot partition.<br />
# arch-chroot /mnt<br />
# pacman -Syu mkinitcpio systemd linux<br />
<br />
{{Note|If ''pacman'' fails with {{ic|Could not resolve host}}, please [[Network_configuration#Check_the_connection|check your internet connection]].}}<br />
<br />
Reinstalling the kernel (the {{Pkg|linux}} package) will automatically re-generate the initramfs image with {{ic|mkinitcpio -p linux}}. There is no need to do this separately.<br />
<br />
Afterwards, it is recommended that you run {{ic|exit}}, {{ic|umount /mnt/{boot,} }} and {{ic|reboot}}.<br />
<br />
{{Note|If you cannot enter the arch-chroot or chroot environment but need to re-install packages you can use the command {{ic|pacman -r /mnt -Syu foo bar}} to use ''pacman'' on your root partition.}}<br />
<br />
=== Signature from "User <email@gmail.com>" is unknown trust, installation failed ===<br />
<br />
Follow [[pacman-key#Resetting all the keys]]. Or you can try to either:<br />
* update the known keys, i.e. {{ic|pacman-key --refresh-keys}};<br />
* or manually upgrade {{Pkg|archlinux-keyring}} package first, i.e. {{ic|pacman -S archlinux-keyring}}.<br />
<br />
=== Request on importing PGP keys ===<br />
<br />
If [[Installation guide|installing]] Arch with an outdated ISO, you are likely prompted to import PGP keys. Agree to download the key to proceed. If you are unable to add the PGP key successfully, update the keyring or upgrade {{Pkg|archlinux-keyring}} (see [[#Signature from "User <email@gmail.com>" is unknown trust, installation failed|above]]).<br />
<br />
=== Signature from "User <email@archlinux.org>" is invalid, installation failed ===<br />
<br />
When the system time is faulty, signing keys are considered expired (or invalid) and signature checks on packages will fail with the following error:<br />
<br />
error: ''package'': signature from "User <email@archlinux.org>" is invalid<br />
error: failed to commit transaction (invalid or corrupted package (PGP signature))<br />
Errors occured, no packages were upgraded.<br />
<br />
Make sure to correct the [[time]], for example with {{ic|ntpd -qg}} run as root, and run {{ic|hwclock -w}} as root before subsequent installations or upgrades.<br />
<br />
=== "Warning: current locale is invalid; using default "C" locale" error ===<br />
<br />
As the error message says, your locale is not correctly configured. See [[Locale]].<br />
<br />
=== pacman does not honor proxy settings ===<br />
<br />
Make sure that the relevant environment variables ({{ic|$http_proxy}}, {{ic|$ftp_proxy}} etc.) are set up. If you use ''pacman'' with [[sudo]], you need to configure sudo to [[sudo#Environment variables|pass these environment variables to pacman]].<br />
<br />
=== How do I reinstall all packages, retaining information on whether something was explicitly installed or as a dependency? ===<br />
<br />
To reinstall all the native packages: {{ic|<nowiki>pacman -Qnq | pacman -S -</nowiki>}} (the {{ic|-S}} option preserves the installation reason by default).<br />
<br />
You will then need to reinstall all the foreign packages, which can be listed with {{ic|pacman -Qmq}}.<br />
<br />
=== "Cannot open shared object file" error ===<br />
<br />
It looks like previous ''pacman'' transaction removed or corrupted shared libraries needed for pacman itself.<br />
<br />
To recover from this situation you need to unpack required libraries to your filesystem manually. First find what package contains the missed library and then locate it in the ''pacman'' cache ({{ic|/var/cache/pacman/pkg/}}). Unpack required shared library to the filesystem. This will allow to run ''pacman''.<br />
<br />
Now you need to [[#Installing specific packages|reinstall]] the broken package. Note that you need to use {{ic|--force}} flag as you just unpacked system files and ''pacman'' does not know about it. ''pacman'' will correctly replace our shared library file with one from package.<br />
<br />
That's it. Update the rest of the system.<br />
<br />
=== Freeze of package downloads ===<br />
<br />
Some issues have been reported regarding network problems that prevent ''pacman'' from updating/synchronizing repositories. [https://bbs.archlinux.org/viewtopic.php?id&#61;68944] [https://bbs.archlinux.org/viewtopic.php?id&#61;65728] When installing Arch Linux natively, these issues have been resolved by replacing the default ''pacman'' file downloader with an alternative (see [[Improve pacman performance]] for more details). When installing Arch Linux as a guest OS in [[VirtualBox]], this issue has also been addressed by using ''Host interface'' instead of ''NAT'' in the machine properties.<br />
<br />
=== Failed retrieving file 'core.db' from mirror ===<br />
<br />
If you receive this error message with correct [[mirrors]], try setting a different [[Resolv.conf|name server]].<br />
<br />
== See also ==<br />
<br />
* [https://www.archlinux.org/pacman/ Pacman's homepage]<br />
* [https://www.archlinux.org/pacman/libalpm.3.html libalpm(3) Manual Page]<br />
* [https://www.archlinux.org/pacman/pacman.8.html pacman(8) Manual Page]<br />
* [https://www.archlinux.org/pacman/pacman.conf.5.html pacman.conf(5) Manual Page]<br />
* [https://www.archlinux.org/pacman/repo-add.8.html repo-add(8) Manual Page]</div>X33ahttps://wiki.archlinux.org/index.php?title=Xmonad&diff=417798Xmonad2016-01-29T05:36:06Z<p>X33a: /* Steam games (Half-Life, Left 4 Dead, …) and xmonad */ language fixes</p>
<hr />
<div>{{Lowercase title}}<br />
[[Category:Tiling WMs]]<br />
[[fr:Xmonad]]<br />
[[ja:Xmonad]]<br />
[[ru:Xmonad]]<br />
[[tr:Xmonad Pencere Yöneticisi]]<br />
[[zh-CN:Xmonad]]<br />
[http://xmonad.org/ xmonad] is a tiling window manager for X. Windows are arranged automatically to tile the screen without gaps or overlap, maximizing screen use. Window manager features are accessible from the keyboard: a mouse is optional.<br />
<br />
xmonad is written, configured and extensible in [http://haskell.org/ Haskell]. Custom layout algorithms, key bindings and other extensions may be written by the user in configuration files.<br />
<br />
Layouts are applied dynamically, and different layouts may be used on each workspace. Xinerama is fully supported, allowing windows to be tiled on several physical screens.<br />
<br />
For more information, please visit the xmonad website: http://xmonad.org/<br />
<br />
== Installation ==<br />
<br />
[[Install]] the {{Pkg|xmonad}} package, and possibly {{Pkg|xmonad-contrib}} for third party tiling algorithms, configurations, scripts, etc.<br />
<br />
Alternatively, install {{AUR|xmonad-git}}, the development version, with some additional dependencies; and likewise {{AUR|xmonad-contrib-git}} if wanted.<br />
<br />
{{Note|If you choose to use the [[ArchHaskell]] repositories, you need to install the ''haskell-xmonad'' package instead of {{Pkg|xmonad}}, as they have different dependencies.}}<br />
<br />
== Starting xmonad ==<br />
<br />
Select ''Xmonad'' from the session menu in a [[display manager]] of choice.<br />
<br />
Alternatively, append {{ic|exec xmonad}} to the {{ic|~/.xinitrc}} file and then start the session by executing ''startx''.<br />
<br />
{{Note|By default, xmonad does not set an X cursor, therefore the "cross" cursor is usually displayed. To set the expected left-pointer, add the following to your {{ic|~/.xinitrc}} (or {{ic|~/.xprofile}} if you are using a display manager):<br />
{{ic|xsetroot -cursor_name left_ptr}}}}<br />
<br />
== Configuration ==<br />
<br />
Create the {{ic|~/.xmonad}} directory and the {{ic|~/.xmonad/xmonad.hs}} file and edit it as described below.<br />
<br />
After changes to {{ic|~/.xmonad/xmonad.hs}} are made, use the Mod+q shortcut to recompile and have them take effect.<br />
<br />
{{Tip|The default configuration for xmonad is quite usable and it is achieved by simply running without an {{ic|xmonad.hs}} entirely.}}<br />
<br />
Because the xmonad configuration file is written in Haskell, non-programmers may have a difficult time adjusting settings. For detailed HOWTO's and example configurations, we refer you to the following resources:<br />
<br />
* [http://wiki.haskell.org/Xmonad xmonad wiki]<br />
* [http://wiki.haskell.org/Xmonad/Config_archive xmonad configuration archive]<br />
* [http://wiki.haskell.org/Xmonad/Frequently_asked_questions xmonad FAQ]<br />
* Arch Linux [https://bbs.archlinux.org/viewtopic.php?id=40636 forum thread]<br />
<br />
The best approach is to only place your changes and customizations in {{ic|~/.xmonad/xmonad.hs}} and write it such that any unset parameters are picked up from the built-in defaultConfig.<br />
<br />
This is achieved by writing an {{ic|xmonad.hs}} like this:<br />
<br />
import XMonad<br />
<br />
main = xmonad defaultConfig<br />
{ terminal = "urxvt"<br />
, modMask = mod4Mask<br />
, borderWidth = 3<br />
}<br />
<br />
This simply overrides the default terminal and borderWidth while leaving all other settings at their defaults (inherited from the XConfig value defaultConfig).<br />
<br />
As things get more complicated, it can be handy to call configuration options by function name inside the main function, and define these separately in their own sections of your {{ic|~/.xmonad/xmonad.hs}}. This makes large customizations like your layout and manage hooks easier to visualize and maintain.<br />
<br />
The simple {{ic|xmonad.hs}} from above could have been written like this:<br />
<br />
import XMonad<br />
<br />
main = do<br />
xmonad $ defaultConfig<br />
{ terminal = myTerminal<br />
, modMask = myModMask<br />
, borderWidth = myBorderWidth<br />
}<br />
<br />
myTerminal = "urxvt"<br />
myModMask = mod4Mask -- Win key or Super_L<br />
myBorderWidth = 3<br />
<br />
Also, order at top level (main, myTerminal, myModMask etc.), or within the {} does not matter in Haskell, as long as imports come first.<br />
<br />
The following is taken from the 0.9 configuration file template. It is an example of the most common functions one might want to define in their main do block.<br />
<br />
{<br />
terminal = myTerminal,<br />
focusFollowsMouse = myFocusFollowsMouse,<br />
borderWidth = myBorderWidth,<br />
modMask = myModMask,<br />
-- numlockMask deprecated in 0.9.1<br />
-- numlockMask = myNumlockMask,<br />
workspaces = myWorkspaces,<br />
normalBorderColor = myNormalBorderColor,<br />
focusedBorderColor = myFocusedBorderColor,<br />
<br />
-- key bindings<br />
keys = myKeys,<br />
mouseBindings = myMouseBindings,<br />
<br />
-- hooks, layouts<br />
layoutHook = myLayout,<br />
manageHook = myManageHook,<br />
handleEventHook = myEventHook,<br />
logHook = myLogHook,<br />
startupHook = myStartupHook<br />
}<br />
<br />
The package itself also includes a {{ic|xmonad.hs}}, which is the latest official example {{ic|xmonad.hs}} that comes with the '''xmonad''' Haskell module as an example of how to override everything. This should not be used as a template configuration, but as examples of parts you can pick to use in your own configuration. It is located in an architecture and version dependant directory in {{ic|/usr/share/}} (e.g. {{ic|find /usr/share -name xmonad.hs}}).<br />
<br />
=== A base desktop configuration ===<br />
In {{Pkg|xmonad-contrib}} is a better default configuration for average desktop uses. It is also helps with problems in some modern programs like Chromium.<br />
<br />
It can be added like so:<br />
<br />
import XMonad<br />
import XMonad.Config.Desktop<br />
<br />
baseConfig = desktopConfig<br />
<br />
main = xmonad baseConfig<br />
{ terminal = "urxvt"<br />
, modMask = mod4Mask<br />
}<br />
<br />
== Exiting xmonad ==<br />
<br />
To end the current xmonad session, press {{ic|Mod+Shift+Q}}. By default, {{ic|Mod}} is the {{ic|Alt}} key.<br />
<br />
== Tips and tricks ==<br />
<br />
=== X-Selection-Paste ===<br />
<br />
The keyboard-centered operation in Xmonad can be further supported with a keyboard shortcut for [[Keyboard shortcuts#Key binding for X-selection-paste|X-Selection-Paste]].<br />
<br />
Also, there exists a function "pasteSelection" in XMonad.Util.Paste that can be bound to a key using a line like:<br />
{{hc|xmonad.hs|<br />
-- X-selection-paste buffer<br />
, ((0, xK_Insert), pasteSelection)}}<br />
Pressing the "Insert" key will now paste the mouse buffer in the active window.<br />
<br />
=== Keyboard shortcuts ===<br />
<br />
If you use Xmonad as a stand alone window manager, you can edit the xmonad.hs to add unbound keyboard keys. You just need to find the Xf86 name of the key (such as XF86PowerDown) and look it up in {{Ic|/usr/include/X11/XF86keysym.h}}. It will give you a keycode (like 0x1008FF2A) which you can use to add a line like the following in the keybindings section of your {{ic|xmonad.hs}}:<br />
<br />
((0, 0x1008FF2A), spawn "sudo pm-suspend")<br />
<br />
=== Complementary applications ===<br />
<br />
There are number of complementary utilities that work well with xmonad. The most common of these include:<br />
<br />
* {{App|[[xmobar]]|A lightweight, text-based, status bar written in Haskell.|http://projects.haskell.org/xmobar/|{{Pkg|xmobar}}, {{AUR|xmobar-git}}}}<br />
* {{App|xmonad-log-applet|https://github.com/alexkay/xmonad-log-applet|An applet for the GNOME, MATE or xfce panel.|{{AUR|xmonad-log-applet-xfce4-git}}{{Broken package link|{{aur-mirror|xmonad-log-applet-xfce4-git}}}}, {{AUR|xmonad-log-applet-gnome-git}}{{Broken package link|{{aur-mirror|xmonad-log-applet-gnome-git}}}}}}<br />
<br />
=== Increase the number of workspaces ===<br />
<br />
By default, xmonad uses 9 workspaces. You can increase this to 14 by extending the following line like this:<br />
{{hc|xmonad.hs|<br />
-- (i, k) <- zip (XMonad.workspaces conf) [xK_1, xK_2, xK_3, xK_4, xK_5, xK_6, xK_7, xK_8, xK_9]<br />
(i, k) <- zip (XMonad.workspaces conf) [xK_grave, xK_1, xK_2, xK_3, xK_4, xK_5, xK_6, xK_7, xK_8, xK_9, xK_0, xK_minus, xK_equal, xK_BackSpace]}}<br />
<br />
=== Making room for Conky or tray apps ===<br />
<br />
Wrap your layouts with avoidStruts from XMonad.Hooks.ManageDocks for automatic dock/panel/trayer spacing:<br />
<br />
import XMonad<br />
import XMonad.Hooks.ManageDocks<br />
<br />
main=do<br />
xmonad $ defaultConfig<br />
{ ...<br />
, layoutHook=avoidStruts $ layoutHook defaultConfig<br />
, manageHook=manageHook defaultConfig <+> manageDocks<br />
, ...<br />
}<br />
<br />
If you ever want to toggle the gaps, this action can be added to your key bindings:<br />
,((modMask x, xK_b ), sendMessage ToggleStruts)<br />
<br />
=== Using xmobar with xmonad ===<br />
<br />
{{Merge|xmobar|Make use of the separate article available}}<br />
<br />
'''[[xmobar]]''' is a light and minimalistic text-based bar, designed to work with xmonad.<br />
To use xmobar with xmonad, you will need two packages in addition to the {{Pkg|xmonad}} package. These packages are {{Pkg|xmonad-contrib}} and {{Pkg|xmobar}} from the [[official repositories]], or you can use {{AUR|xmobar-git}} from the [[AUR]] instead of the official {{Pkg|xmobar}} package.<br />
<br />
Here we will start xmobar from within xmonad, which reloads xmobar whenever you reload xmonad.<br />
<br />
Open {{ic|~/.xmonad/xmonad.hs}} in your favorite editor, and choose one of the two following options:<br />
<br />
==== Quick, less flexible ====<br />
<br />
{{Note|There is also {{Pkg|dzen2}} which you can substitute for {{Pkg|xmobar}} in either case.}}<br />
<br />
Common imports:<br />
import XMonad<br />
import XMonad.Hooks.DynamicLog<br />
<br />
The xmobar action starts xmobar and returns a modified configuration that includes all of the options described in [[#More configurable]].<br />
main = xmonad =<< xmobar defaultConfig { modMask = mod4Mask {- or any other configurations here ... -}}<br />
<br />
==== More configurable ====<br />
<br />
As of xmonad(-contrib) 0.9, there is a new [http://xmonad.org/xmonad-docs/xmonad-contrib/XMonad-Hooks-DynamicLog.html#v%3AstatusBar statusBar] function in [http://xmonad.org/xmonad-docs/xmonad-contrib/XMonad-Hooks-DynamicLog.html XMonad.Hooks.DynamicLog]. It allows you to use your own configuration for:<br />
* The command used to execute the bar<br />
* The PP that determines what is being written to the bar<br />
* The key binding to toggle the gap for the bar<br />
<br />
The following is an example of how to use it:<br />
{{hc|~/.xmonad/xmonad.hs|<nowiki><br />
-- Imports.<br />
import XMonad<br />
import XMonad.Hooks.DynamicLog<br />
<br />
-- The main function.<br />
main = xmonad =<< statusBar myBar myPP toggleStrutsKey myConfig<br />
<br />
-- Command to launch the bar.<br />
myBar = "xmobar"<br />
<br />
-- Custom PP, configure it as you like. It determines what is being written to the bar.<br />
myPP = xmobarPP { ppCurrent = xmobarColor "#429942" "" . wrap "<" ">" }<br />
<br />
-- Key binding to toggle the gap for the bar.<br />
toggleStrutsKey XConfig {XMonad.modMask = modMask} = (modMask, xK_b)<br />
<br />
-- Main configuration, override the defaults to your liking.<br />
myConfig = defaultConfig { modMask = mod4Mask }<br />
</nowiki>}}<br />
<br />
==== Verify XMobar config ====<br />
<br />
The template and default xmobarrc contains this.<br />
<br />
At last, open up {{ic|~/.xmobarrc}} and make sure you have {{ic|StdinReader}} in the template and run the plugin. E.g.<br />
{{hc|~/.xmobarrc|<nowiki><br />
Config { ...<br />
, commands = [ Run StdinReader .... ]<br />
...<br />
, template = " %StdinReader% ... "<br />
}<br />
</nowiki>}}<br />
<br />
Now, all you should have to do is either to start, or restart, xmonad.<br />
<br />
=== Controlling xmonad with external scripts ===<br />
Here are a few ways to do it,<br />
<br />
* use the following xmonad extension, [http://xmonad.org/xmonad-docs/xmonad-contrib/XMonad-Hooks-ServerMode.html XMonad.Hooks.ServerMode].<br />
<br />
* simulate keypress events using {{Pkg|xdotool}} or similar programs. See this [http://ubuntuforums.org/archive/index.php/t-658040.html Ubuntu forums thread]. The following command would simulate the keypress {{ic|Super+n}}:<br />
xdotool key Super+n<br />
<br />
* {{Pkg|wmctrl}} -If you have desktopConfig or EwmhDesktops configured, this is a very easy to use and standard utility.<br />
<br />
=== Launching another window manager within xmonad ===<br />
<br />
If you are using {{AUR|xmonad-git}}, as of January of 2011, you can restart to another window manager from within xmonad. You just need to write a small script, and add stuff to your {{ic|~/.xmonad/xmonad.hs}}. Here is the script.<br />
<br />
{{hc|~/bin/obtoxmd|<nowiki><br />
#!/bin/sh<br />
openbox<br />
xmonad<br />
</nowiki>}}<br />
<br />
And here are the modifications you need to add to your {{ic|~/.xmonad/xmonad.hs}}:<br />
<br />
{{hc|~/.xmonad/xmonad.hs|<nowiki><br />
import XMonad<br />
--You need to add this import<br />
import XMonad.Util.Replace<br />
<br />
main do<br />
-- And this "replace"<br />
replace<br />
xmonad $ defaultConfig<br />
{<br />
--Add the usual here<br />
}<br />
<br />
</nowiki>}}<br />
<br />
You also need to add the following key binding:<br />
{{hc|~/xmonad/xmonad.hs|<nowiki><br />
--Add a keybinding as follows:<br />
((modm .|. shiftMask, xK_o ), restart "/home/abijr/bin/obtoxmd" True)<br />
</nowiki>}}<br />
<br />
Just remember to add a comma before or after and change the path to your actual script path. Now just {{ic|Mod+q}} (restart xmonad to refresh the configuration), and then hit {{ic|Mod+Shift+o}} and you should have Openbox running with the same windows open as in xmonad. To return to xmonad you should just exit Openbox. Here is a link to adamvo's {{ic|~/.xmonad/xmonad.hs}} which uses this setup [http://wiki.haskell.org/Xmonad/Config_archive/adamvo%27s_xmonad.hs Adamvo's xmonad.hs]<br />
<br />
=== KDE and xmonad ===<br />
<br />
The xmonad wiki has instructions on how to [https://wiki.haskell.org/Xmonad/Using_xmonad_in_KDE run xmonad inside KDE]<br />
<br />
It also might be a good idea to set a global keyboard shortcut in KDE to start xmonad in case it is accidentally killed or closed.<br />
<br />
=== IM Layout for Skype ===<br />
<br />
In orded to create an IM layout for the newer versions of skype, the following code can be used:<br />
{{hc|xmonad.hs|<nowiki><br />
myIMLayout = withIM (1%7) skype Grid<br />
where<br />
skype = And (ClassName "Skype") (Role "")<br />
</nowiki>}}<br />
<br />
=== Example configurations ===<br />
<br />
Below are some example configurations from fellow xmonad users. Feel free to add links to your own.<br />
<br />
* brisbin33 :: simple, useful, readable :: [https://github.com/pbrisbin/xmonad-config config] [http://files.pbrisbin.com/screenshots/current_desktop.png screenshot]<br />
* jelly :: Configuration with prompt, different layouts, twinview with xmobar :: [http://github.com/jelly/dotfiles/tree/master/.xmonad/xmonad.hs xmonad.hs]<br />
* MrElendig :: Simple configuration, with xmobar :: [http://github.com/MrElendig/dotfiles-alice/blob/master/.xmonad/xmonad.hs xmonad.hs], [http://github.com/MrElendig/dotfiles-alice/blob/master/.xmobarrc .xmobarrc], [http://arch.har-ikkje.net/gfx/ss/2010-09-05-163305_2960x1050_scrot.png screenshot].<br />
* thayer :: A minimal mouse-friendly config ideal for netbooks :: [http://wiki.haskell.org/Xmonad/Config_archive/Thayer_Williams%27_xmonad.hs configs] [http://wiki.haskell.org/Image:Thayer-xmonad-20110511.png screenshot]<br />
* vicfryzel :: Beautiful and usable xmonad configuration, along with xmobar configuration, xinitrc, dmenu, and other scripts that make xmonad more usable. :: [https://github.com/vicfryzel/xmonad-config git repository], [https://github.com/vicfryzel/xmonad-config/raw/master/screenshot.png screenshot].<br />
* vogt :: Check out adamvo's config and many others in the official [http://wiki.haskell.org/Xmonad/Config_archive Xmonad/Config archive]<br />
* wulax :: Example of using xmonad inside Xfce. Contains two layouts for GIMP. :: [https://gist.github.com/jsjolund/94f6821b248ff79586ba xmonad.hs], [https://i.imgur.com/at9AbOl.png screenshot].<br />
<br />
== Troubleshooting ==<br />
<br />
=== GNOME 3 and xmonad ===<br />
{{accuracy|This no longer works with GNOME. It might still work with [[GNOME Flashback]].}}<br />
<br />
With the release of GNOME 3 [[GNOME#Custom GNOME sessions|custom GNOME sessions]] require additional steps to make GNOME play nicely with xmonad. <br />
<br />
Either install {{AUR|xmonad-gnome3}}{{Broken package link|{{aur-mirror|xmonad-gnome3}}}} from the AUR, or, manually:<br />
<br />
Add an xmonad session file for use by gnome-session ({{ic|/usr/share/gnome-session/sessions/xmonad.session}}):<br />
<br />
{{bc|1=<br />
[GNOME Session]<br />
Name=Xmonad session<br />
RequiredComponents=gnome-panel;gnome-settings-daemon;<br />
RequiredProviders=windowmanager;notifications;<br />
DefaultProvider-windowmanager=xmonad<br />
DefaultProvider-notifications=notification-daemon<br />
}}<br />
<br />
Create a desktop file for GDM ({{ic|/usr/share/xsessions/xmonad-gnome-session.desktop}}):<br />
{{bc|1=<br />
[Desktop Entry]<br />
Name=Xmonad GNOME<br />
Comment=Tiling window manager<br />
TryExec=/usr/bin/gnome-session<br />
Exec=gnome-session --session=xmonad<br />
Type=XSession<br />
}}<br />
<br />
Create or edit this file ({{ic|/usr/share/applications/xmonad.desktop}}):<br />
{{bc|1=<br />
[Desktop Entry]<br />
Type=Application<br />
Encoding=UTF-8<br />
Name=Xmonad<br />
Exec=xmonad<br />
NoDisplay=true<br />
X-GNOME-WMName=Xmonad<br />
X-GNOME-Autostart-Phase=WindowManager<br />
X-GNOME-Provides=windowmanager<br />
X-GNOME-Autostart-Notify=false<br />
}}<br />
<br />
Finally, install {{pkg|xmonad-contrib}} and create or edit {{ic|~/.xmonad/xmonad.hs}} to have the following<br />
<br />
{{bc|1=<br />
import XMonad<br />
import XMonad.Config.Gnome<br />
<br />
main = xmonad gnomeConfig<br />
}}<br />
<br />
Xmonad should now appear in the list of GDM sessions and also play nicely with gnome-session itself.<br />
<br />
==== Compositing in GNOME and Xmonad ====<br />
<br />
Some applications look better (e.g. GNOME Do) when composition is enabled. This is, however not, the case in the default Xmonad window manager. To enable it add an additional .desktop file {{ic|/usr/share/xsessions/xmonad-gnome-session-composite.desktop}}:<br />
{{bc|1=<br />
[Desktop Entry]<br />
Name=Xmonad GNOME (Composite)<br />
Comment=Tiling window manager<br />
TryExec=/usr/bin/gnome-session<br />
Exec=/usr/sbin/gnome-xmonad-composite<br />
Type=XSession<br />
}}<br />
<br />
And create {{ic|/usr/sbin/gnome-xmonad-composite}} and {{ic|chmod +x /usr/sbin/gnome-xmonad-composite}}:<br />
<br />
{{bc|1=<br />
xcompmgr &<br />
gnome-session --session=xmonad<br />
}}<br />
<br />
Now choose "Xmonad GNOME (Composite)" in the list of sessions during login. Reference {{ic|man xcompmgr}} for additional "eye candy".<br />
<br />
=== Xfce 4 and xmonad ===<br />
<br />
Use {{ic|xfceConfig}} instead of {{ic|defaultConfig}} after importing {{ic|XMonad.Config.Xfce}} in {{ic|~/.xmonad/xmonad.hs}}, e.g. adapting the minimal configuration above:<br />
<br />
import XMonad<br />
import XMonad.Config.Xfce<br />
<br />
main = xmonad xfceConfig<br />
{ terminal = "urxvt"<br />
, modMask = mod4Mask<br />
}<br />
<br />
Also add an entry to ''Settings > Session and Startup > Application Autostart'' that runs {{ic|xmonad --replace}}.<br />
<br />
=== Missing xmonad-i386-linux or xmonad-x86_64-linux ===<br />
<br />
Xmonad should automatically create the {{ic|xmonad-i386-linux}} file (in {{ic|~/.xmonad/}}). If this it not the case, grab a configuration file from the [http://wiki.haskell.org/Xmonad/Config_archive xmonad wiki] or create your [http://wiki.haskell.org/Xmonad/Config_archive/John_Goerzen's_Configuration own]. Put the {{ic|.hs}} and all others files in {{ic|~/.xmonad/}} and run this command from the folder:<br />
xmonad --recompile<br />
<br />
Now you should see the file.<br />
<br />
{{Note|A reason you may get an error message saying that xmonad-x86_64-linux is missing is that {{Pkg|xmonad-contrib}} is not installed.}}<br />
<br />
=== Problems with Java applications === <br />
If you have problems, like Java application Windows not resizing, or menus immediately closing after you click, see [[Java#Applications not resizing with WM, menus immediately closing]].<br />
<br />
=== Empty space at the bottom of gvim or terminals ===<br />
See [[Vim#Empty space at the bottom of gVim windows]] for a solution which makes the area match the background color.<br />
<br />
For [[rxvt-unicode]], you can use {{AUR|rxvt-unicode-patched}}.<br />
<br />
You can also configure xmonad to respect size hints, but this will leave a gap instead. See [http://www.eng.uwaterloo.ca/~aavogt/xmonad/docs/xmonad-contrib/XMonad-Layout-LayoutHints.html the documentation on Xmonad.Layout.LayoutHints].<br />
<br />
=== Chromium/Chrome will not go fullscreen ===<br />
If Chrome fails to go fullscreen when {{ic|F11}} is pressed, you can use the [http://xmonad.org/xmonad-docs/xmonad-contrib/XMonad-Hooks-EwmhDesktops.html XMonad.Hooks.EwmhDesktops] extension found in the {{Pkg|xmonad-contrib}} package. Simply add the {{ic|import}} statement to your {{ic|~/.xmonad/xmonad.hs}}:<br />
import XMonad.Hooks.EwmhDesktops<br />
<br />
and then add {{ic|handleEventHook <nowiki>=</nowiki> fullscreenEventHook}} to the appropriate place; for example:<br />
{{bc|<nowiki><br />
...<br />
xmonad $ defaultConfig<br />
{ modMask = mod4Mask<br />
, handleEventHook = fullscreenEventHook<br />
}<br />
...<br />
</nowiki>}}<br />
<br />
After a recompile/restart of xmonad, Chromium should now respond to {{ic|F11}} (fullscreen) as expected.<br />
<br />
=== Multitouch / touchegg ===<br />
<br />
Touchégg polls the window manager for the {{ic|_NET_CLIENT_LIST}} (in order to fetch a list of windows it should listen for mouse events on.) By default, xmonad does not supply this property. To enable this, use the [http://xmonad.org/xmonad-docs/xmonad-contrib/XMonad-Hooks-EwmhDesktops.html XMonad.Hooks.EwmhDesktops] extension found in the {{Pkg|xmonad-contrib}} package.<br />
<br />
=== Keybinding issues with an azerty keyboard layout ===<br />
<br />
Users with a keyboard with azerty layout can run into issues with certain keybindings. Using the [http://xmonad.org/xmonad-docs/xmonad-contrib/XMonad-Config-Azerty.html XMonad.Config.Azerty] module will solve this.<br />
<br />
=== GNOME 3 mod4+p changes display configuration instead of launching dmenu ===<br />
<br />
If you do not need the capability to switch the display-setup in the gnome-control-center, just execute<br />
{{bc|<nowiki>dconf write /org/gnome/settings-daemon/plugins/xrandr/active false</nowiki>}}<br />
as your user, to disable the xrandr plugin which grabs Super+p.<br />
<br />
=== Problems with focused border in VirtualBox ===<br />
<br />
A known issue with Virtualbox ([https://www.virtualbox.org/ticket/6479 Ticket #6479]) can cause problems with the focused window border. A solution can be found by installing a compositing manager like [[xcompmgr]] which overrides the incorrect behavior of vboxvideo.<br />
<br />
=== Steam games (Half-Life, Left 4 Dead, …) and xmonad ===<br />
<br />
There seems to be some trouble with xmonad and Source engine based games like Half-Life. If they do not start or get stuck with a black screen, a workaround is to start them in windowed mode. To do so, right click on the game in your Steam library and choose properties, click on launch options and enter [http://steamcommunity.com/app/221410/discussions/0/864960353968561426/]:<br />
<br />
-windowed<br />
<br />
Another solution is to float the window of the game using the manage hook. For example, the following line can be used for Half-Life:<br />
<br />
className =? "hl_linux" --> doFloat<br />
<br />
This can also be worked around by making XMonad pay attention to EWMH hints and including its fullscreen hook [http://xmonad.org/xmonad-docs/xmonad-contrib/XMonad-Hooks-EwmhDesktops.html]:<br />
<br />
main = xmonad $ ewmh defaultConfig{ handleEventHook =<br />
handleEventHook defaultConfig <+> fullscreenEventHook }<br />
<br />
This has a few other effects and makes it behave more akin to fullscreen apps in other WMs.<br />
<br />
=== LibreOffice - focus flicking between main window and dialog ===<br />
<br />
The LibreOffice UI defaults to the gtk engine outside a desktop environment. This may cause problems with some xmonad configurations resulting in focus rapidly flicking between the LibreOffice main window and any open LibreOffice dialog window. Effectively locking the application. In this case the environment variable SAL_USE_VCLPLUGIN can be set to explicitly force LibreOffice to use another UI theme as outlined in [[LibreOffice#Theme]] For instance<br />
<br />
export SAL_USE_VCLPLUGIN=gen lowriter<br />
<br />
to use the general (QT) UI.<br />
<br />
== See also ==<br />
<br />
*[http://xmonad.org/ xmonad] - The official xmonad website<br />
*[https://wiki.haskell.org/Xmonad/Config_archive/Template_xmonad.hs xmonad.hs] - Template xmonad.hs<br />
*[http://xmonad.org/tour.html xmonad: a guided tour]<br />
*[[dzen]] - General purpose messaging and notification program<br />
*[[dmenu]] - Dynamic X menu for the quick launching of programs<br />
*[[Comparison of tiling window managers]] - Arch wiki article providing an overview of mainstream tiling window managers<br />
*[https://bbs.archlinux.org/viewtopic.php?id=94969 Share your xmonad desktop!]<br />
*[https://bbs.archlinux.org/viewtopic.php?id=40636 xmonad hacking thread]</div>X33ahttps://wiki.archlinux.org/index.php?title=Disk_quota&diff=409511Disk quota2015-11-18T12:40:32Z<p>X33a: /* Journaled quota */</p>
<hr />
<div>[[Category:Security]]<br />
[[Category:File systems]]<br />
From [[Wikipedia:Disk quota|Wikipedia]]:<br />
:"''A '''disk quota''' is a limit set by a system administrator that restricts certain aspects of file system usage on modern operating systems. The function of setting quotas to disks is to allocate limited disk-space in a reasonable way.''"<br />
This article covers the installation and setup of disk quota.<br />
<br />
==Installing==<br />
Disk quota only requires one package:<br />
# pacman -S quota-tools<br />
<br />
==Enabling==<br />
''For journaled quota, see the notes in [[#Journaled quota]].''<br />
<br />
1. First, edit {{ic|/etc/fstab}} to enable the quota mount option(s) on selected file systems:<br />
/dev/sda1 /home ext4 defaults 1 1<br />
:edit it as follows;<br />
/dev/sda1 /home ext4 defaults''',usrquota''' 1 1<br />
:or aditionally enable the group quota mount option;<br />
/dev/sda1 /home ext4 defaults''',usrquota,grpquota''' 1 1<br />
<br />
2. Create the quota files in the file system:<br />
# touch /home/aquota.user<br />
# touch /home/aquota.group # For group quota<br />
<br />
2. The next step is to remount:<br />
# mount -vo remount /home<br />
<br />
4. Create the quota index:<br />
# quotacheck -vgum /home<br />
:or for all partitions with the quota mount options in {{ic|/etc/mtab}};<br />
# quotacheck -vguma<br />
{{tip|If you end up with the output "[...]Quotafile $FILE was probably truncated. Cannot save quota settings..." you can try removing the previously created files aquota*}}<br />
{{tip|If you get the output "quotacheck: Mountpoint (or device) /home not found or has no quota enabled.<br><br />
quotacheck: Cannot find filesystem to check or filesystem not mounted with quota option." and you are using a custom kernel, make sure quota support is enabled in your kernel.}}<br />
{{tip|In Addition you can try to use "-F vfsold" and "-F vfsv0" afterwards <b>NOTE:</b> As of 3.1.6-1, Arch does not support "vfsv1"}}<br />
<br />
5. Finally, enable quotas:<br />
# quotaon -av<br />
Consider adding this command to your start-up, see [[Autostarting]].<br />
<br />
===Journaled quota===<br />
Enabling journaling for disk quota adds the same benefits journaled file systems do for forced shutdowns, meaning that data is less likely to become corrupt.<br />
<br />
Setting up journaled quota is the same as above, except for the mount options:<br />
/dev/sda1 /home ext4 defaults''',usrjquota=aquota.user,jqfmt=vfsv0''' 1 1<br />
or additionally, enable the group quota mount option;<br />
/dev/sda1 /home ext4 defaults''',usrjquota=aquota.user,grpjquota=aquota.group,jqfmt=vfsv0''' 1 1<br />
<br />
==Configuring==<br />
{{Note|To find out how many '''1k''' blocks are there for a partition use '''# df'''}}<br />
Replace {{ic|$USER}} as appropriate and edit the quota as root:<br />
{{hc|$ edquota ''$USER''|<br />
Disk quotas for user '''$USER''' (uid 1000):<br />
Filesystem blocks soft hard inodes soft hard<br />
/dev/sda1 1944 0 0 120 0 0<br />
}}<br />
{{note|to edit group quotas, use {{ic|edquota -g $GROUP}}.}}<br />
;blocks: Number of 1k blocks currently used by {{ic|$USER}}<br />
{{note|Block size is statically set to 1k regardless of filesystem block size. [http://stackoverflow.com/questions/2506288/detect-block-size-for-quota-in-linux/2506311#2506311 Explanation]}}<br />
;inodes: Number of entries by {{ic|$USER}} in directory file <br />
;soft: Max number of blocks/inodes {{ic|$USER}} may have on partition before warning is issued and grace period countdown begins. If set to "0" (zero) then no limit is enforced.<br />
;hard: Max number of blocks/inodes {{ic|$USER}} may have on partition. If set to "0" (zero) then no limit is enforced.<br />
<br />
Example configuration:<br />
Disk quotas for user testuser (uid 1000):<br />
Filesystem blocks soft hard inodes soft hard <br />
/dev/sda1 695879 10000 15000 6741 0 0<br />
<br />
The {{ic|soft}} limit means that once ''testuser'' uses over 10MB of space a warning email gets ensued, and after a period of time the soft limit gets enforced. <br />
<br />
The {{ic|hard}} limit is stricter, so to speak; a user cannot go over this limit.<br />
<br />
Next configure the {{ic|soft}} limit grace period:<br />
# edquota -t<br />
<br />
==Managing==<br />
''Checking for quota limits and advanced operations''<br />
<br />
===Basics===<br />
Use this command to check for quotas on a specific partition:<br />
# repquota /home<br />
<br />
Use this command to check for all quotas that apply to a user:<br />
# quota -u $USER<br />
for groups;<br />
# quota -g $GROUP<br />
<br />
===Copying quota settings===<br />
To copy quota from one user or group to the other, use this command:<br />
# edquota -p user1 user2<br />
User1 is the user you copy from, user2 is the user you copy quota to. Of course you can replace user with group, when necessary.<br />
<br />
====Multiple users====<br />
The idea is to make a temporary user acount, modify the quota settings for that user, and then copy the generated quota files for all users to use. After setting quota settings for ''quotauser'', copy the settings:<br />
# edquota -p '''quotauser''' `awk -F: '$3 > 999 {print $1}' /etc/passwd`<br />
This applies the settings to users with a UID equal to or greater than 1000.<br />
<br />
===Other commands===<br />
There are several useful commands:<br />
repquota -a # Shows the status on disk usage<br />
warnquota # Can be used to warn the users about their quota, configuration in /etc/warnquota.conf<br />
setquota # Non-interactive quota setting--useful for scripting<br />
<br />
Lasty, {{ic|quotastats}} is used to give thorough information about the quota system:<br />
{{hc|$ quotastats|<br />
Number of dquot lookups: 101289<br />
Number of dquot drops: 101271<br />
Number of still active inodes with quota : 18<br />
Number of dquot reads: 93<br />
Number of dquot writes: 2077<br />
Number of quotafile syncs: 134518740<br />
Number of dquot cache hits: 7391<br />
Number of allocated dquots: 90<br />
Number of free dquots: 2036<br />
Number of in use dquot entries (user/group): -1946<br />
}}<br />
<br />
==More resources==<br />
* http://tldp.org/HOWTO/Quota.html<br />
* http://www.sf.net/projects/linuxquota/<br />
* http://www.yolinux.com/TUTORIALS/LinuxTutorialQuotas.html<br />
* http://www.redhat.com/docs/manuals/linux/RHL-8.0-Manual/admin-primer/s1-storage-quotas.html</div>X33ahttps://wiki.archlinux.org/index.php?title=Disk_quota&diff=409510Disk quota2015-11-18T12:40:05Z<p>X33a: /* Journaled quota */ fix typo</p>
<hr />
<div>[[Category:Security]]<br />
[[Category:File systems]]<br />
From [[Wikipedia:Disk quota|Wikipedia]]:<br />
:"''A '''disk quota''' is a limit set by a system administrator that restricts certain aspects of file system usage on modern operating systems. The function of setting quotas to disks is to allocate limited disk-space in a reasonable way.''"<br />
This article covers the installation and setup of disk quota.<br />
<br />
==Installing==<br />
Disk quota only requires one package:<br />
# pacman -S quota-tools<br />
<br />
==Enabling==<br />
''For journaled quota, see the notes in [[#Journaled quota]].''<br />
<br />
1. First, edit {{ic|/etc/fstab}} to enable the quota mount option(s) on selected file systems:<br />
/dev/sda1 /home ext4 defaults 1 1<br />
:edit it as follows;<br />
/dev/sda1 /home ext4 defaults''',usrquota''' 1 1<br />
:or aditionally enable the group quota mount option;<br />
/dev/sda1 /home ext4 defaults''',usrquota,grpquota''' 1 1<br />
<br />
2. Create the quota files in the file system:<br />
# touch /home/aquota.user<br />
# touch /home/aquota.group # For group quota<br />
<br />
2. The next step is to remount:<br />
# mount -vo remount /home<br />
<br />
4. Create the quota index:<br />
# quotacheck -vgum /home<br />
:or for all partitions with the quota mount options in {{ic|/etc/mtab}};<br />
# quotacheck -vguma<br />
{{tip|If you end up with the output "[...]Quotafile $FILE was probably truncated. Cannot save quota settings..." you can try removing the previously created files aquota*}}<br />
{{tip|If you get the output "quotacheck: Mountpoint (or device) /home not found or has no quota enabled.<br><br />
quotacheck: Cannot find filesystem to check or filesystem not mounted with quota option." and you are using a custom kernel, make sure quota support is enabled in your kernel.}}<br />
{{tip|In Addition you can try to use "-F vfsold" and "-F vfsv0" afterwards <b>NOTE:</b> As of 3.1.6-1, Arch does not support "vfsv1"}}<br />
<br />
5. Finally, enable quotas:<br />
# quotaon -av<br />
Consider adding this command to your start-up, see [[Autostarting]].<br />
<br />
===Journaled quota===<br />
Enabling journaling for disk quota adds the same benefits journaled file systems do for forced shutdowns, meaning that data is less likely to become corrupt.<br />
<br />
Setting up journaled quota is the same as above, except for the mount options:<br />
/dev/sda1 /home ext4 defaults''',usrjquota=aquota.user,jqfmt=vfsv0''' 1 1<br />
or additionally enable the group quota mount option;<br />
/dev/sda1 /home ext4 defaults''',usrjquota=aquota.user,grpjquota=aquota.group,jqfmt=vfsv0''' 1 1<br />
<br />
==Configuring==<br />
{{Note|To find out how many '''1k''' blocks are there for a partition use '''# df'''}}<br />
Replace {{ic|$USER}} as appropriate and edit the quota as root:<br />
{{hc|$ edquota ''$USER''|<br />
Disk quotas for user '''$USER''' (uid 1000):<br />
Filesystem blocks soft hard inodes soft hard<br />
/dev/sda1 1944 0 0 120 0 0<br />
}}<br />
{{note|to edit group quotas, use {{ic|edquota -g $GROUP}}.}}<br />
;blocks: Number of 1k blocks currently used by {{ic|$USER}}<br />
{{note|Block size is statically set to 1k regardless of filesystem block size. [http://stackoverflow.com/questions/2506288/detect-block-size-for-quota-in-linux/2506311#2506311 Explanation]}}<br />
;inodes: Number of entries by {{ic|$USER}} in directory file <br />
;soft: Max number of blocks/inodes {{ic|$USER}} may have on partition before warning is issued and grace period countdown begins. If set to "0" (zero) then no limit is enforced.<br />
;hard: Max number of blocks/inodes {{ic|$USER}} may have on partition. If set to "0" (zero) then no limit is enforced.<br />
<br />
Example configuration:<br />
Disk quotas for user testuser (uid 1000):<br />
Filesystem blocks soft hard inodes soft hard <br />
/dev/sda1 695879 10000 15000 6741 0 0<br />
<br />
The {{ic|soft}} limit means that once ''testuser'' uses over 10MB of space a warning email gets ensued, and after a period of time the soft limit gets enforced. <br />
<br />
The {{ic|hard}} limit is stricter, so to speak; a user cannot go over this limit.<br />
<br />
Next configure the {{ic|soft}} limit grace period:<br />
# edquota -t<br />
<br />
==Managing==<br />
''Checking for quota limits and advanced operations''<br />
<br />
===Basics===<br />
Use this command to check for quotas on a specific partition:<br />
# repquota /home<br />
<br />
Use this command to check for all quotas that apply to a user:<br />
# quota -u $USER<br />
for groups;<br />
# quota -g $GROUP<br />
<br />
===Copying quota settings===<br />
To copy quota from one user or group to the other, use this command:<br />
# edquota -p user1 user2<br />
User1 is the user you copy from, user2 is the user you copy quota to. Of course you can replace user with group, when necessary.<br />
<br />
====Multiple users====<br />
The idea is to make a temporary user acount, modify the quota settings for that user, and then copy the generated quota files for all users to use. After setting quota settings for ''quotauser'', copy the settings:<br />
# edquota -p '''quotauser''' `awk -F: '$3 > 999 {print $1}' /etc/passwd`<br />
This applies the settings to users with a UID equal to or greater than 1000.<br />
<br />
===Other commands===<br />
There are several useful commands:<br />
repquota -a # Shows the status on disk usage<br />
warnquota # Can be used to warn the users about their quota, configuration in /etc/warnquota.conf<br />
setquota # Non-interactive quota setting--useful for scripting<br />
<br />
Lasty, {{ic|quotastats}} is used to give thorough information about the quota system:<br />
{{hc|$ quotastats|<br />
Number of dquot lookups: 101289<br />
Number of dquot drops: 101271<br />
Number of still active inodes with quota : 18<br />
Number of dquot reads: 93<br />
Number of dquot writes: 2077<br />
Number of quotafile syncs: 134518740<br />
Number of dquot cache hits: 7391<br />
Number of allocated dquots: 90<br />
Number of free dquots: 2036<br />
Number of in use dquot entries (user/group): -1946<br />
}}<br />
<br />
==More resources==<br />
* http://tldp.org/HOWTO/Quota.html<br />
* http://www.sf.net/projects/linuxquota/<br />
* http://www.yolinux.com/TUTORIALS/LinuxTutorialQuotas.html<br />
* http://www.redhat.com/docs/manuals/linux/RHL-8.0-Manual/admin-primer/s1-storage-quotas.html</div>X33ahttps://wiki.archlinux.org/index.php?title=Isync&diff=407953Isync2015-11-02T04:38:45Z<p>X33a: Undo revision 407931 by Rovanion (talk) ~/.cache isn't suitable for storing critical data. Please see the definition for $XDG_CACHE_HOME</p>
<hr />
<div>{{DISPLAYTITLE:isync}}<br />
[[Category:Email clients]]<br />
isync is a command line application which synchronizes mailboxes; currently Maildir and IMAP4 mailboxes are supported. New messages, message deletions and flag changes can be propagated both ways.<br />
<br />
Synchronization is based on unique message identifiers (UIDs), so no identification conflicts can occur (as opposed to some other mail synchronizers).<br />
Synchronization state is kept in one local text file per mailbox pair; multiple replicas of a mailbox can be maintained.<br />
{{note|isync is the name of the project, mbsync is the name of the executable}}<br />
<br />
==Features==<br />
<br />
*Fine-grained selection of synchronization operations to perform<br />
*Synchronizes single mailboxes or entire mailbox collections<br />
*Partial mirrors possible: keep only the latest messages locally<br />
*Trash functionality: backup messages before removing them<br />
*IMAP features:<br />
**Security: supports TLS/SSL via imaps: (port 993) and STARTTLS; CRAM-MD5 for authentication<br />
**Supports NAMESPACE for simplified configuration<br />
**Pipelining for maximum speed (currently only partially implemented)<br />
<br />
==Installing==<br />
Install {{Pkg|isync}} from the [[official repositories]] or {{AUR|isync-git}} can be installed from the [[AUR]].<br />
<br />
==Configuring==<br />
<br />
First create and customize the main configuration file using this example ~/.mbsyncrc:<br />
{{hc|~/.mbsyncrc|2=<br />
<nowiki><br />
IMAPAccount gmail<br />
# Address to connect to<br />
Host imap.gmail.com<br />
User username@gmail.com<br />
Pass ***************<br />
# To store the password in an encrypted file use PassCmd instead of Pass<br />
# PassCmd "gpg2 -q --for-your-eyes-only --no-tty -d ~/.mailpass.gpg"<br />
#<br />
# Use SSL<br />
SSLType IMAPS<br />
# The following line should work. If get certificate errors, uncomment the two following lines and read the "Troubleshooting" section.<br />
CertificateFile /etc/ssl/certs/ca-certificates.crt<br />
#CertificateFile ~/.cert/imap.gmail.com.pem<br />
#CertificateFile ~/.cert/Equifax_Secure_CA.pem<br />
<br />
IMAPStore gmail-remote<br />
Account gmail<br />
<br />
MaildirStore gmail-local<br />
# The trailing "/" is important<br />
Path ~/.mail/gmail/<br />
Inbox ~/.mail/gmail/Inbox<br />
<br />
Channel gmail<br />
Master :gmail-remote:<br />
Slave :gmail-local:<br />
# Exclude everything under the internal [Gmail] folder, except the interesting folders<br />
Patterns * ![Gmail]* "[Gmail]/Sent Mail" "[Gmail]/Starred" "[Gmail]/All Mail"<br />
# Or include everything<br />
#Patterns *<br />
# Automatically create missing mailboxes, both locally and on the server<br />
Create Both<br />
# Save the synchronization state files in the relevant directory<br />
SyncState *<br />
</nowiki><br />
}}<br />
<br />
To get rid of the [Gmail]-Stuff (or [Google Mail] as in my case) in each mailbox name, it's possible to use separate Channels for each directory, and later merge them to a group:<br />
{{hc|~/.mbsyncrc|2=<br />
<nowiki><br />
Channel sync-googlemail-default<br />
Master :googlemail-remote:<br />
Slave :googlemail-local:<br />
# Select some mailboxes to sync<br />
Patterns "INBOX" "arch"<br />
<br />
Channel sync-googlemail-sent<br />
Master :googlemail-remote:"[Google Mail]/Gesendet"<br />
Slave :googlemail-local:sent<br />
<br />
Channel sync-googlemail-trash<br />
Master :googlemail-remote:"[Google Mail]/Papierkorb"<br />
Slave :googlemail-local:trash<br />
<br />
# Get all the channels together into a group.<br />
Group googlemail<br />
Channel sync-googlemail-default<br />
Channel sync-googlemail-sent<br />
Channel sync-googlemail-trash<br />
</nowiki><br />
}}<br />
As you can see, name-translations are possible this way, as well. Now calling<br />
mbsync googlemail<br />
will sync all the folders.<br />
<br />
==Usage==<br />
First make any folders that were specified as Maildirs.<br />
$ mkdir -p ~/.mail/gmail<br />
Then to retrieve the mail for a specific channel run:<br />
$ mbsync gmail<br />
or to retrive the mail for all channels:<br />
$ mbsync -a<br />
<br />
==Automatic synchronization==<br />
If you want to automatically synchronize your mailboxes, isync can be started automatically with a [[systemd]] unit. The following service file can start the '''mbsync''' command :<br />
<br />
{{hc|/etc/systemd/system/mbsync@.service|2=<br />
<nowiki><br />
[Unit]<br />
Description=Mailbox synchronization service for user %I<br />
<br />
[Service]<br />
Type=oneshot<br />
ExecStart=/usr/bin/mbsync -Va<br />
User=%i<br />
StandardOutput=syslog<br />
StandardError=syslog<br />
</nowiki><br />
}}<br />
<br />
The following timer configures '''mbsync''' to be started every day :<br />
<br />
{{hc|/etc/systemd/system/mbsync@.timer|2=<br />
<nowiki><br />
[Unit]<br />
Description=Mailbox synchronization timer<br />
<br />
[Timer]<br />
OnBootSec=10min<br />
OnActiveSec=1d<br />
Unit=mbsync@%i.service<br />
<br />
[Install]<br />
WantedBy=timers.target<br />
</nowiki><br />
}}<br />
<br />
Once those two files are created, reload systemd, enable and start the timer :<br />
<br />
systemctl daemon-reload<br />
systemctl enable mbsync@user.timer<br />
systemctl start mbsync@user.timer<br />
<br />
==Troubleshooting==<br />
If you get certificate related errors, you may need to retrieve the server's certificates manually in order for mbsync to correctly verify it.<br />
<br />
=== Step #1: Get the certificates ===<br />
<br />
{{Accuracy|This may not always be needed, e.g. for gmail {{ic|CertificateFile /etc/ssl/certs/ca-certificates.crt}} in the config file may be suffcient|section=Step #1: Get the certificates}}<br />
<br />
{{bc|<br />
<nowiki><br />
$ mkdir ~/.cert<br />
$ openssl s_client -connect some.imap.server:port -showcerts 2>&1 < /dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sed -ne '1,/-END CERTIFICATE-/p' > ~/.cert/some.imap.server.pem<br />
</nowiki><br />
}}<br />
<br />
This will create a certificate file called {{ic|~/.cert/some.imap.server.pem}} (e.g. {{ic|~/.cert/imap.gmail.com.pem}}). If you wish to do this manually, you may enter:<br />
<br />
{{bc|<br />
<nowiki><br />
$ openssl s_client -connect some.imap.server:port -showcerts<br />
</nowiki><br />
}}<br />
<br />
and it will display output something like:<br />
<br />
{{bc|<br />
<nowiki><br />
CONNECTED(00000003)<br />
depth=1 C = US, O = Google Inc, CN = Google Internet Authority<br />
verify error:num=20:unable to get local issuer certificate<br />
verify return:0<br />
---<br />
Certificate chain<br />
0 s:/C=US/ST=California/L=Mountain View/O=Google Inc/CN=imap.gmail.com<br />
i:/C=US/O=Google Inc/CN=Google Internet Authority<br />
-----BEGIN CERTIFICATE-----<br />
MIIDgDCCAumgAwIBAgIKO3MmiwAAAABopTANBgkqhkiG9w0BAQUFADBGMQswCQYD<br />
VQQGEwJVUzETMBEGA1UEChMKR29vZ2xlIEluYzEiMCAGA1UEAxMZR29vZ2xlIElu<br />
dGVybmV0IEF1dGhvcml0eTAeFw0xMjA5MTIxMTU1NDlaFw0xMzA2MDcxOTQzMjda<br />
MGgxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1N<br />
b3VudGFpbiBWaWV3MRMwEQYDVQQKEwpHb29nbGUgSW5jMRcwFQYDVQQDEw5pbWFw<br />
LmdtYWlsLmNvbTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA2OmU9DjI+DFQ<br />
ThqIN4vL6EqZbzH0ejLKcc+zhxsq9BU5hXohSJ1sS5FUU2vReDKk8fd+ZR3cWtpf<br />
CTYAUSvdnz1ZFjESSzyUBmGRqByhoc0yqdfb61NosA4CDaO+z7DtAgKyecqnAJad<br />
TPYYf9aLk/UgJuc6GseitjzFYonXi6ECAwEAAaOCAVEwggFNMB0GA1UdJQQWMBQG<br />
CCsGAQUFBwMBBggrBgEFBQcDAjAdBgNVHQ4EFgQUFuLyTg2NcsyaEESytZbLbQan<br />
YIowHwYDVR0jBBgwFoAUv8Aw6/VDET5nup6R+/xq2uNrEiQwWwYDVR0fBFQwUjBQ<br />
oE6gTIZKaHR0cDovL3d3dy5nc3RhdGljLmNvbS9Hb29nbGVJbnRlcm5ldEF1dGhv<br />
cml0eS9Hb29nbGVJbnRlcm5ldEF1dGhvcml0eS5jcmwwZgYIKwYBBQUHAQEEWjBY<br />
MFYGCCsGAQUFBzAChkpodHRwOi8vd3d3LmdzdGF0aWMuY29tL0dvb2dsZUludGVy<br />
bmV0QXV0aG9yaXR5L0dvb2dsZUludGVybmV0QXV0aG9yaXR5LmNydDAMBgNVHRMB<br />
Af8EAjAAMBkGA1UdEQQSMBCCDmltYXAuZ21haWwuY29tMA0GCSqGSIb3DQEBBQUA<br />
A4GBAC1LV7tM6pcyVJLcwdPml4DomtowsjTrqvy5ZFa3SMKANK0iZBgFu74O0THX<br />
8SxP/vn4eAs0yRQxcT1ZuoishLGQl5NoimLaQ4BGQnzFQHDJendfaVKDl21GenJp<br />
is72sIrAeprsVU8PbNsllUamWsIjKr3DH5xQdH54hDtzQojY<br />
-----END CERTIFICATE-----<br />
1 s:/C=US/O=Google Inc/CN=Google Internet Authority<br />
i:/C=US/O=Equifax/OU=Equifax Secure Certificate Authority<br />
-----BEGIN CERTIFICATE-----<br />
MIICsDCCAhmgAwIBAgIDC2dxMA0GCSqGSIb3DQEBBQUAME4xCzAJBgNVBAYTAlVT<br />
MRAwDgYDVQQKEwdFcXVpZmF4MS0wKwYDVQQLEyRFcXVpZmF4IFNlY3VyZSBDZXJ0<br />
aWZpY2F0ZSBBdXRob3JpdHkwHhcNMDkwNjA4MjA0MzI3WhcNMTMwNjA3MTk0MzI3<br />
WjBGMQswCQYDVQQGEwJVUzETMBEGA1UEChMKR29vZ2xlIEluYzEiMCAGA1UEAxMZ<br />
R29vZ2xlIEludGVybmV0IEF1dGhvcml0eTCBnzANBgkqhkiG9w0BAQEFAAOBjQAw<br />
gYkCgYEAye23pIucV+eEPkB9hPSP0XFjU5nneXQUr0SZMyCSjXvlKAy6rWxJfoNf<br />
NFlOCnowzdDXxFdF7dWq1nMmzq0yE7jXDx07393cCDaob1FEm8rWIFJztyaHNWrb<br />
qeXUWaUr/GcZOfqTGBhs3t0lig4zFEfC7wFQeeT9adGnwKziV28CAwEAAaOBozCB<br />
oDAOBgNVHQ8BAf8EBAMCAQYwHQYDVR0OBBYEFL/AMOv1QxE+Z7qekfv8atrjaxIk<br />
MB8GA1UdIwQYMBaAFEjmaPkr0rKV10fYIyAQTzOYkJ/UMBIGA1UdEwEB/wQIMAYB<br />
Af8CAQAwOgYDVR0fBDMwMTAvoC2gK4YpaHR0cDovL2NybC5nZW90cnVzdC5jb20v<br />
Y3Jscy9zZWN1cmVjYS5jcmwwDQYJKoZIhvcNAQEFBQADgYEAuIojxkiWsRF8YHde<br />
BZqrocb6ghwYB8TrgbCoZutJqOkM0ymt9e8kTP3kS8p/XmOrmSfLnzYhLLkQYGfN<br />
0rTw8Ktx5YtaiScRhKqOv5nwnQkhClIZmloJ0pC3+gz4fniisIWvXEyZ2VxVKfml<br />
UUIuOss4jHg7y/j7lYe8vJD5UDI=<br />
-----END CERTIFICATE-----<br />
---<br />
Server certificate<br />
subject=/C=US/ST=California/L=Mountain View/O=Google Inc/CN=imap.gmail.com<br />
issuer=/C=US/O=Google Inc/CN=Google Internet Authority<br />
---<br />
No client certificate CA names sent<br />
---<br />
SSL handshake has read 2108 bytes and written 350 bytes<br />
---<br />
New, TLSv1/SSLv3, Cipher is ECDHE-RSA-RC4-SHA<br />
Server public key is 1024 bit<br />
Secure Renegotiation IS supported<br />
Compression: NONE<br />
Expansion: NONE<br />
SSL-Session:<br />
Protocol : TLSv1.1<br />
Cipher : ECDHE-RSA-RC4-SHA<br />
Session-ID: 77136647F42633D82DEDFBB9EB62AB516547A3697D83BD1884726034613C1C09<br />
Session-ID-ctx: <br />
Master-Key: 635957FBA0762B10694560488905F73BDD2DB674C41970542ED079446F27234E2CA51CF26938B8CA56DF5BBC71E429A7<br />
Key-Arg : None<br />
PSK identity: None<br />
PSK identity hint: None<br />
SRP username: None<br />
TLS session ticket lifetime hint: 100800 (seconds)<br />
TLS session ticket:<br />
0000 - d6 5b a0 a7 10 0e 64 04-72 93 7c 9f 94 fa 07 57 .[....d.r.|....W<br />
0010 - f1 8b 9d 24 8b 9d 1b f3-a8 b1 4d 2c a9 00 e1 82 ...$......M,....<br />
0020 - 00 83 1e 3f e5 f2 b2 2c-d2 a8 87 83 16 02 0d 1e ...?...,........<br />
0030 - bf b6 c1 d6 75 21 04 e6-63 6b ab 5b ed 94 7a 30 ....u!..ck.[..z0<br />
0040 - 1a d0 aa 44 c2 04 9b 10-06 28 b5 7b a0 43 a6 0d ...D.....(.{.C..<br />
0050 - 3b 4a 85 1f 2e 07 0a e1-32 9b bd 5d 65 41 4c e2 ;J......2..]eAL.<br />
0060 - 7c d7 43 ec c4 18 77 53-b5 d4 84 b4 c9 bd 51 d6 |.C...wS......Q.<br />
0070 - 2d 4f 2e 10 a6 ed 38 c5-8e 9d f8 8b 8a 63 3f 7b -O....8......c?{<br />
0080 - ee e6 b8 bf 7a f8 b8 e8-47 92 84 f1 9b 0c 63 30 ....z...G.....c0<br />
0090 - 76 d8 e1 44 v..D<br />
<br />
Start Time: 1352632558<br />
Timeout : 300 (sec)<br />
Verify return code: 20 (unable to get local issuer certificate)<br />
---<br />
* OK Gimap ready for requests from 108.78.162.240 o67if11168976yhc.67<br />
</nowiki><br />
}}<br />
<br />
Simply copy the first block that begins with {{ic|-----BEGIN CERTIFICATE-----}} and ends with {{ic|-----END CERTIFICATE-----}}, paste into a file, and save with a .pem extension (this is necessary for the next step). Older instructions state that, with Gmail, both certificate blocks must be saved but on testing this was found to be unnecessary.<br />
<br />
Now, copy the root issuer certificate to your local certificate folder. In this example (Gmail), the root issuer is Equifax Secure Certificate Authority. This certificate is included in the {{pkg|ca-certificates}} package.<br />
<br />
{{bc|<br />
<nowiki><br />
cp /usr/share/ca-certificates/mozilla/Equifax_Secure_CA.crt ~/.cert/Equifax_Secure_CA.pem<br />
</nowiki><br />
}}<br />
<br />
===Step #2: Rehash the certificates ===<br />
<br />
{{bc|<br />
<nowiki><br />
$ c_rehash ~/.cert<br />
</nowiki><br />
}}<br />
<br />
Sample Output:<br />
{{bc|<br />
<nowiki><br />
Doing ~/.cert/<br />
some.imap.server.pem => 1d97af50.0<br />
Equifax_Secure_CA.pem => 28def021.3<br />
</nowiki><br />
}}<br />
<br />
This creates a symlink to the certificate file named with a cryptographic hash of its contents.<br />
<br />
<br />
=== Exchange 2003 ===<br />
<br />
When connecting to an MS Exchange 2003 server, there could be problems when using pipelining (i.e. executing multiple imap commands concurrently). Such an issue could look as follows:<br />
{{bc|sample output of `mbsync -V exchange'<br />
<nowiki><br />
>>> 9 SELECT "arch"^M<br />
* 250 EXISTS<br />
* 0 RECENT<br />
* FLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent)<br />
* OK [PERMANENTFLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent)] Permanent flags<br />
* OK [UNSEEN 241] Is the first unseen message<br />
* OK [UIDVALIDITY 4352] UIDVALIDITY value<br />
9 OK [READ-WRITE] SELECT completed.<br />
>>> 10 UID FETCH 1:1000000000 (UID FLAGS)^M<br />
* 1 FETCH (UID 1 FLAGS (\Seen \Answered))<br />
* 2 FETCH (UID 2 FLAGS (\Seen \Answered))<br />
...<br />
* 249 FETCH (UID 696 FLAGS ())<br />
* 250 FETCH (UID 697 FLAGS (\Seen))<br />
10 OK FETCH completed.<br />
>>> 11 APPEND "arch" (\Seen) {4878+}^M<br />
(1 in progress) >>> 12 UID FETCH 697 (BODY.PEEK[])^M<br />
(2 in progress) >>> 13 UID STORE 696 +FLAGS.SILENT (\Deleted)^M<br />
12 BAD Command is not valid in this state.<br />
</nowiki><br />
}}<br />
So command 9 is to select a new folder, command 10 checks the mail and commands 11, 12 and 13 run in parallel, writing/getting/flagging a mail. In this case, the Exchange server would terminate the connection after the BAD return value and go on to the next channel. (And if all went well in this channel, mbsync would return with 0.) After setting<br />
PipelineDepth 1<br />
in the IMAPStore config part of the Exchange, this problem did not occur any more.<br />
<br />
==External Links==<br />
*[http://isync.sourceforge.net/ Home page]<br />
*[http://sourceforge.net/projects/isync/ Sourceforge page]<br />
*[http://kevin.deldycke.com/2012/08/gmail-backup-mbsync/ backing up gmail with mbsync]<br />
*[http://www.cyberciti.biz/faq/test-ssl-certificates-diagnosis-ssl-certificate/ How To Verify SSL Certificate From A Shell Prompt]</div>X33ahttps://wiki.archlinux.org/index.php?title=Isync&diff=405635Isync2015-10-20T05:54:08Z<p>X33a: /* Installing */ package again available on the AUR</p>
<hr />
<div>{{DISPLAYTITLE:isync}}<br />
[[Category:Email clients]]<br />
isync is a command line application which synchronizes mailboxes; currently Maildir and IMAP4 mailboxes are supported. New messages, message deletions and flag changes can be propagated both ways.<br />
<br />
Synchronization is based on unique message identifiers (UIDs), so no identification conflicts can occur (as opposed to some other mail synchronizers).<br />
Synchronization state is kept in one local text file per mailbox pair; multiple replicas of a mailbox can be maintained.<br />
{{note|isync is the name of the project, mbsync is the name of the executable}}<br />
<br />
==Features==<br />
<br />
*Fine-grained selection of synchronization operations to perform<br />
*Synchronizes single mailboxes or entire mailbox collections<br />
*Partial mirrors possible: keep only the latest messages locally<br />
*Trash functionality: backup messages before removing them<br />
*IMAP features:<br />
**Security: supports TLS/SSL via imaps: (port 993) and STARTTLS; CRAM-MD5 for authentication<br />
**Supports NAMESPACE for simplified configuration<br />
**Pipelining for maximum speed (currently only partially implemented)<br />
<br />
==Installing==<br />
Install {{Pkg|isync}} from the [[official repositories]] or {{AUR|isync-git}} can be installed from the [[AUR]].<br />
<br />
==Configuring==<br />
<br />
First create and customize the main configuration file using this example ~/.mbsyncrc:<br />
{{hc|~/.mbsyncrc|2=<br />
<nowiki><br />
IMAPAccount gmail<br />
# Address to connect to<br />
Host imap.gmail.com<br />
User username@gmail.com<br />
Pass ***************<br />
# To store the password in an encrypted file use PassCmd instead of Pass<br />
# PassCmd "gpg2 -q --for-your-eyes-only --no-tty -d ~/.mailpass.gpg"<br />
#<br />
# Use SSL<br />
SSLType IMAPS<br />
# The following line should work. If get certificate errors, uncomment the two following lines and read the "Troubleshooting" section.<br />
CertificateFile /etc/ssl/certs/ca-certificates.crt<br />
#CertificateFile ~/.cert/imap.gmail.com.pem<br />
#CertificateFile ~/.cert/Equifax_Secure_CA.pem<br />
<br />
IMAPStore gmail-remote<br />
Account gmail<br />
<br />
MaildirStore gmail-local<br />
# The trailing "/" is important<br />
Path ~/.mail/gmail/<br />
Inbox ~/.mail/gmail/Inbox<br />
<br />
Channel gmail<br />
Master :gmail-remote:<br />
Slave :gmail-local:<br />
# Exclude everything under the internal [Gmail] folder, except the interesting folders<br />
Patterns * ![Gmail]* "[Gmail]/Sent Mail" "[Gmail]/Starred" "[Gmail]/All Mail"<br />
# Or include everything<br />
#Patterns *<br />
# Automatically create missing mailboxes, both locally and on the server<br />
Create Both<br />
# Save the synchronization state files in the relevant directory<br />
SyncState *<br />
</nowiki><br />
}}<br />
<br />
To get rid of the [Gmail]-Stuff (or [Google Mail] as in my case) in each mailbox name, it's possible to use separate Channels for each directory, and later merge them to a group:<br />
{{hc|~/.mbsyncrc|2=<br />
<nowiki><br />
Channel sync-googlemail-default<br />
Master :googlemail-remote:<br />
Slave :googlemail-local:<br />
# Select some mailboxes to sync<br />
Patterns "INBOX" "arch"<br />
<br />
Channel sync-googlemail-sent<br />
Master :googlemail-remote:"[Google Mail]/Gesendet"<br />
Slave :googlemail-local:sent<br />
<br />
Channel sync-googlemail-trash<br />
Master :googlemail-remote:"[Google Mail]/Papierkorb"<br />
Slave :googlemail-local:trash<br />
<br />
# Get all the channels together into a group.<br />
Group googlemail<br />
Channel sync-googlemail-default<br />
Channel sync-googlemail-sent<br />
Channel sync-googlemail-trash<br />
</nowiki><br />
}}<br />
As you can see, name-translations are possible this way, as well. Now calling<br />
mbsync googlemail<br />
will sync all the folders.<br />
<br />
==Usage==<br />
First make any folders that were specified as Maildirs.<br />
$ mkdir -p ~/.mail/gmail<br />
Then to retrieve the mail for a specific channel run:<br />
$ mbsync gmail<br />
or to retrive the mail for all channels:<br />
$ mbsync -a<br />
<br />
==Automatic synchronization==<br />
If you want to automatically synchronize your mailboxes, isync can be started automatically with a [[systemd]] unit. The following service file can start the '''mbsync''' command :<br />
<br />
{{hc|/etc/systemd/system/mbsync@.service|2=<br />
<nowiki><br />
[Unit]<br />
Description=Mailbox synchronization service for user %I<br />
<br />
[Service]<br />
Type=oneshot<br />
ExecStart=/usr/bin/mbsync -Va<br />
User=%i<br />
StandardOutput=syslog<br />
StandardError=syslog<br />
</nowiki><br />
}}<br />
<br />
The following timer configures '''mbsync''' to be started every day :<br />
<br />
{{hc|/etc/systemd/system/mbsync@.timer|2=<br />
<nowiki><br />
[Unit]<br />
Description=Mailbox synchronization timer<br />
<br />
[Timer]<br />
OnBootSec=10min<br />
OnActiveSec=1d<br />
Unit=mbsync@%i.service<br />
<br />
[Install]<br />
WantedBy=timers.target<br />
</nowiki><br />
}}<br />
<br />
Once those two files are created, reload systemd, enable and start the timer :<br />
<br />
systemctl daemon-reload<br />
systemctl enable mbsync@user.timer<br />
systemctl start mbsync@user.timer<br />
<br />
==Troubleshooting==<br />
If you get certificate related errors, you may need to retrieve the server's certificates manually in order for mbsync to correctly verify it.<br />
<br />
=== Step #1: Get the certificates ===<br />
<br />
{{Accuracy|This may not always be needed, e.g. for gmail {{ic|CertificateFile /etc/ssl/certs/ca-certificates.crt}} in the config file may be suffcient|section=Step #1: Get the certificates}}<br />
<br />
{{bc|<br />
<nowiki><br />
$ mkdir ~/.cert<br />
$ openssl s_client -connect some.imap.server:port -showcerts 2>&1 < /dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sed -ne '1,/-END CERTIFICATE-/p' > ~/.cert/some.imap.server.pem<br />
</nowiki><br />
}}<br />
<br />
This will create a certificate file called {{ic|~/.cert/some.imap.server.pem}} (e.g. {{ic|~/.cert/imap.gmail.com.pem}}). If you wish to do this manually, you may enter:<br />
<br />
{{bc|<br />
<nowiki><br />
$ openssl s_client -connect some.imap.server:port -showcerts<br />
</nowiki><br />
}}<br />
<br />
and it will display output something like:<br />
<br />
{{bc|<br />
<nowiki><br />
CONNECTED(00000003)<br />
depth=1 C = US, O = Google Inc, CN = Google Internet Authority<br />
verify error:num=20:unable to get local issuer certificate<br />
verify return:0<br />
---<br />
Certificate chain<br />
0 s:/C=US/ST=California/L=Mountain View/O=Google Inc/CN=imap.gmail.com<br />
i:/C=US/O=Google Inc/CN=Google Internet Authority<br />
-----BEGIN CERTIFICATE-----<br />
MIIDgDCCAumgAwIBAgIKO3MmiwAAAABopTANBgkqhkiG9w0BAQUFADBGMQswCQYD<br />
VQQGEwJVUzETMBEGA1UEChMKR29vZ2xlIEluYzEiMCAGA1UEAxMZR29vZ2xlIElu<br />
dGVybmV0IEF1dGhvcml0eTAeFw0xMjA5MTIxMTU1NDlaFw0xMzA2MDcxOTQzMjda<br />
MGgxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1N<br />
b3VudGFpbiBWaWV3MRMwEQYDVQQKEwpHb29nbGUgSW5jMRcwFQYDVQQDEw5pbWFw<br />
LmdtYWlsLmNvbTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA2OmU9DjI+DFQ<br />
ThqIN4vL6EqZbzH0ejLKcc+zhxsq9BU5hXohSJ1sS5FUU2vReDKk8fd+ZR3cWtpf<br />
CTYAUSvdnz1ZFjESSzyUBmGRqByhoc0yqdfb61NosA4CDaO+z7DtAgKyecqnAJad<br />
TPYYf9aLk/UgJuc6GseitjzFYonXi6ECAwEAAaOCAVEwggFNMB0GA1UdJQQWMBQG<br />
CCsGAQUFBwMBBggrBgEFBQcDAjAdBgNVHQ4EFgQUFuLyTg2NcsyaEESytZbLbQan<br />
YIowHwYDVR0jBBgwFoAUv8Aw6/VDET5nup6R+/xq2uNrEiQwWwYDVR0fBFQwUjBQ<br />
oE6gTIZKaHR0cDovL3d3dy5nc3RhdGljLmNvbS9Hb29nbGVJbnRlcm5ldEF1dGhv<br />
cml0eS9Hb29nbGVJbnRlcm5ldEF1dGhvcml0eS5jcmwwZgYIKwYBBQUHAQEEWjBY<br />
MFYGCCsGAQUFBzAChkpodHRwOi8vd3d3LmdzdGF0aWMuY29tL0dvb2dsZUludGVy<br />
bmV0QXV0aG9yaXR5L0dvb2dsZUludGVybmV0QXV0aG9yaXR5LmNydDAMBgNVHRMB<br />
Af8EAjAAMBkGA1UdEQQSMBCCDmltYXAuZ21haWwuY29tMA0GCSqGSIb3DQEBBQUA<br />
A4GBAC1LV7tM6pcyVJLcwdPml4DomtowsjTrqvy5ZFa3SMKANK0iZBgFu74O0THX<br />
8SxP/vn4eAs0yRQxcT1ZuoishLGQl5NoimLaQ4BGQnzFQHDJendfaVKDl21GenJp<br />
is72sIrAeprsVU8PbNsllUamWsIjKr3DH5xQdH54hDtzQojY<br />
-----END CERTIFICATE-----<br />
1 s:/C=US/O=Google Inc/CN=Google Internet Authority<br />
i:/C=US/O=Equifax/OU=Equifax Secure Certificate Authority<br />
-----BEGIN CERTIFICATE-----<br />
MIICsDCCAhmgAwIBAgIDC2dxMA0GCSqGSIb3DQEBBQUAME4xCzAJBgNVBAYTAlVT<br />
MRAwDgYDVQQKEwdFcXVpZmF4MS0wKwYDVQQLEyRFcXVpZmF4IFNlY3VyZSBDZXJ0<br />
aWZpY2F0ZSBBdXRob3JpdHkwHhcNMDkwNjA4MjA0MzI3WhcNMTMwNjA3MTk0MzI3<br />
WjBGMQswCQYDVQQGEwJVUzETMBEGA1UEChMKR29vZ2xlIEluYzEiMCAGA1UEAxMZ<br />
R29vZ2xlIEludGVybmV0IEF1dGhvcml0eTCBnzANBgkqhkiG9w0BAQEFAAOBjQAw<br />
gYkCgYEAye23pIucV+eEPkB9hPSP0XFjU5nneXQUr0SZMyCSjXvlKAy6rWxJfoNf<br />
NFlOCnowzdDXxFdF7dWq1nMmzq0yE7jXDx07393cCDaob1FEm8rWIFJztyaHNWrb<br />
qeXUWaUr/GcZOfqTGBhs3t0lig4zFEfC7wFQeeT9adGnwKziV28CAwEAAaOBozCB<br />
oDAOBgNVHQ8BAf8EBAMCAQYwHQYDVR0OBBYEFL/AMOv1QxE+Z7qekfv8atrjaxIk<br />
MB8GA1UdIwQYMBaAFEjmaPkr0rKV10fYIyAQTzOYkJ/UMBIGA1UdEwEB/wQIMAYB<br />
Af8CAQAwOgYDVR0fBDMwMTAvoC2gK4YpaHR0cDovL2NybC5nZW90cnVzdC5jb20v<br />
Y3Jscy9zZWN1cmVjYS5jcmwwDQYJKoZIhvcNAQEFBQADgYEAuIojxkiWsRF8YHde<br />
BZqrocb6ghwYB8TrgbCoZutJqOkM0ymt9e8kTP3kS8p/XmOrmSfLnzYhLLkQYGfN<br />
0rTw8Ktx5YtaiScRhKqOv5nwnQkhClIZmloJ0pC3+gz4fniisIWvXEyZ2VxVKfml<br />
UUIuOss4jHg7y/j7lYe8vJD5UDI=<br />
-----END CERTIFICATE-----<br />
---<br />
Server certificate<br />
subject=/C=US/ST=California/L=Mountain View/O=Google Inc/CN=imap.gmail.com<br />
issuer=/C=US/O=Google Inc/CN=Google Internet Authority<br />
---<br />
No client certificate CA names sent<br />
---<br />
SSL handshake has read 2108 bytes and written 350 bytes<br />
---<br />
New, TLSv1/SSLv3, Cipher is ECDHE-RSA-RC4-SHA<br />
Server public key is 1024 bit<br />
Secure Renegotiation IS supported<br />
Compression: NONE<br />
Expansion: NONE<br />
SSL-Session:<br />
Protocol : TLSv1.1<br />
Cipher : ECDHE-RSA-RC4-SHA<br />
Session-ID: 77136647F42633D82DEDFBB9EB62AB516547A3697D83BD1884726034613C1C09<br />
Session-ID-ctx: <br />
Master-Key: 635957FBA0762B10694560488905F73BDD2DB674C41970542ED079446F27234E2CA51CF26938B8CA56DF5BBC71E429A7<br />
Key-Arg : None<br />
PSK identity: None<br />
PSK identity hint: None<br />
SRP username: None<br />
TLS session ticket lifetime hint: 100800 (seconds)<br />
TLS session ticket:<br />
0000 - d6 5b a0 a7 10 0e 64 04-72 93 7c 9f 94 fa 07 57 .[....d.r.|....W<br />
0010 - f1 8b 9d 24 8b 9d 1b f3-a8 b1 4d 2c a9 00 e1 82 ...$......M,....<br />
0020 - 00 83 1e 3f e5 f2 b2 2c-d2 a8 87 83 16 02 0d 1e ...?...,........<br />
0030 - bf b6 c1 d6 75 21 04 e6-63 6b ab 5b ed 94 7a 30 ....u!..ck.[..z0<br />
0040 - 1a d0 aa 44 c2 04 9b 10-06 28 b5 7b a0 43 a6 0d ...D.....(.{.C..<br />
0050 - 3b 4a 85 1f 2e 07 0a e1-32 9b bd 5d 65 41 4c e2 ;J......2..]eAL.<br />
0060 - 7c d7 43 ec c4 18 77 53-b5 d4 84 b4 c9 bd 51 d6 |.C...wS......Q.<br />
0070 - 2d 4f 2e 10 a6 ed 38 c5-8e 9d f8 8b 8a 63 3f 7b -O....8......c?{<br />
0080 - ee e6 b8 bf 7a f8 b8 e8-47 92 84 f1 9b 0c 63 30 ....z...G.....c0<br />
0090 - 76 d8 e1 44 v..D<br />
<br />
Start Time: 1352632558<br />
Timeout : 300 (sec)<br />
Verify return code: 20 (unable to get local issuer certificate)<br />
---<br />
* OK Gimap ready for requests from 108.78.162.240 o67if11168976yhc.67<br />
</nowiki><br />
}}<br />
<br />
Simply copy the first block that begins with {{ic|-----BEGIN CERTIFICATE-----}} and ends with {{ic|-----END CERTIFICATE-----}}, paste into a file, and save with a .pem extension (this is necessary for the next step). Older instructions state that, with Gmail, both certificate blocks must be saved but on testing this was found to be unnecessary.<br />
<br />
Now, copy the root issuer certificate to your local certificate folder. In this example (Gmail), the root issuer is Equifax Secure Certificate Authority. This certificate is included in the {{pkg|ca-certificates}} package.<br />
<br />
{{bc|<br />
<nowiki><br />
cp /usr/share/ca-certificates/mozilla/Equifax_Secure_CA.crt ~/.cert/Equifax_Secure_CA.pem<br />
</nowiki><br />
}}<br />
<br />
===Step #2: Rehash the certificates ===<br />
<br />
{{bc|<br />
<nowiki><br />
$ c_rehash ~/.cert<br />
</nowiki><br />
}}<br />
<br />
Sample Output:<br />
{{bc|<br />
<nowiki><br />
Doing ~/.cert/<br />
some.imap.server.pem => 1d97af50.0<br />
Equifax_Secure_CA.pem => 28def021.3<br />
</nowiki><br />
}}<br />
<br />
This creates a symlink to the certificate file named with a cryptographic hash of its contents.<br />
<br />
<br />
=== Exchange 2003 ===<br />
<br />
When connecting to an MS Exchange 2003 server, there could be problems when using pipelining (i.e. executing multiple imap commands concurrently). Such an issue could look as follows:<br />
{{bc|sample output of `mbsync -V exchange'<br />
<nowiki><br />
>>> 9 SELECT "arch"^M<br />
* 250 EXISTS<br />
* 0 RECENT<br />
* FLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent)<br />
* OK [PERMANENTFLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent)] Permanent flags<br />
* OK [UNSEEN 241] Is the first unseen message<br />
* OK [UIDVALIDITY 4352] UIDVALIDITY value<br />
9 OK [READ-WRITE] SELECT completed.<br />
>>> 10 UID FETCH 1:1000000000 (UID FLAGS)^M<br />
* 1 FETCH (UID 1 FLAGS (\Seen \Answered))<br />
* 2 FETCH (UID 2 FLAGS (\Seen \Answered))<br />
...<br />
* 249 FETCH (UID 696 FLAGS ())<br />
* 250 FETCH (UID 697 FLAGS (\Seen))<br />
10 OK FETCH completed.<br />
>>> 11 APPEND "arch" (\Seen) {4878+}^M<br />
(1 in progress) >>> 12 UID FETCH 697 (BODY.PEEK[])^M<br />
(2 in progress) >>> 13 UID STORE 696 +FLAGS.SILENT (\Deleted)^M<br />
12 BAD Command is not valid in this state.<br />
</nowiki><br />
}}<br />
So command 9 is to select a new folder, command 10 checks the mail and commands 11, 12 and 13 run in parallel, writing/getting/flagging a mail. In this case, the Exchange server would terminate the connection after the BAD return value and go on to the next channel. (And if all went well in this channel, mbsync would return with 0.) After setting<br />
PipelineDepth 1<br />
in the IMAPStore config part of the Exchange, this problem did not occur any more.<br />
<br />
==External Links==<br />
*[http://isync.sourceforge.net/ Home page]<br />
*[http://sourceforge.net/projects/isync/ Sourceforge page]<br />
*[http://kevin.deldycke.com/2012/08/gmail-backup-mbsync/ backing up gmail with mbsync]<br />
*[http://www.cyberciti.biz/faq/test-ssl-certificates-diagnosis-ssl-certificate/ How To Verify SSL Certificate From A Shell Prompt]</div>X33ahttps://wiki.archlinux.org/index.php?title=Autofs&diff=386023Autofs2015-07-21T05:18:22Z<p>X33a: /* See also */ dead links</p>
<hr />
<div>[[Category:File systems]]<br />
[[es:Autofs]]<br />
[[it:Autofs]]<br />
[[ru:Autofs]]<br />
[[uk:Autofs]]<br />
[[zh-CN:Autofs]]<br />
This document outlines the procedure needed to set up AutoFS, a package that provides support for automounting removable media or network shares when they are inserted or accessed.<br />
<br />
== Installation ==<br />
<br />
[[Install]] the {{Pkg|autofs}}.<br />
<br />
{{Note|You no longer need to load {{ic|autofs4}} module.}}<br />
<br />
== Configuration ==<br />
<br />
AutoFS uses template files for configuration which are located in {{ic|/etc/autofs}} The main template is called {{ic|auto.master}}, which can point to one or more other templates for specific media types.<br />
<br />
* Open the file {{ic|/etc/autofs/auto.master}} with your favorite editor, you will see something similar to this:<br />
<br />
{{hc|/etc/autofs/auto.master|2=<br />
#/media /etc/autofs/auto.media<br />
<br />
}}<br />
<br />
The first value on each line determines the base directory under which all the media in a template are mounted, the second value is which template to use. The default base path is {{ic|/media}}, but you can change this to any other location you prefer. For instance:<br />
<br />
{{hc|/etc/autofs/auto.master|2=<br />
/media/misc /etc/autofs/auto.misc --timeout=5<br />
/media/net /etc/autofs/auto.net --timeout=60<br />
<br />
}}<br />
{{Note|Make sure there is an empty line on the end of template files (press {{ic|ENTER}} after last word). If there is no correct EOF (end of file) line, the AutoFS daemon will not properly load.}}<br />
<br />
The optional parameter {{ic|timeout}} sets the amount of seconds after which to unmount directories.<br />
<br />
The base directory will be created if it does not exist on your system. The base directory will be mounted on to load the dynamically loaded media, which means any content in the base directory will not be accessible while autofs is on. This procedure is however non-destructive, so if you accidentally automount into a live directory you can just change the location in {{ic|auto.master}} and restart AutoFS to regain the original contents.<br />
<br />
If you still want to automount to a target non-empty directory and want to have the original files available even after the dynamically loaded directories are mounted, you can use autofs to mount them to another directory (e.g. /var/autofs/net) and create soft links.<br />
<br />
# ln -s /var/autofs/net/share_name /media/share_name<br />
<br />
Alternatively, you can have autofs mount your media to a specific folder, rather than inside a common folder.<br />
<br />
{{hc|/etc/autofs/auto.master|2=<br />
/- /etc/autofs/auto.template<br />
}}<br />
{{hc|/etc/autofs/auto.template|2=<br />
/path/to/folder -options :/device/path<br />
/home/user/usbstick -fstype=auto,async,nodev,nosuid,umask=000 :/dev/sdb1<br />
}}<br />
{{Note|This can cause problems with resources getting locked if the connection to the share is lost. When trying to access the folder, programs will get locked into waiting for a response, and either the connection has to be restored or the process has to be forcibly killed before unmounting is possible. To mitigate this, only use if you will always be connected to the share, and do not use your home folder or other commonly used folders lest your file browser reads ahead into the disconnected folder}}<br />
<br />
* Open the file {{ic|/etc/nsswitch.conf}} and add an entry for automount:<br />
automount: files<br />
<br />
* When you are done configuring your templates (see below), launch the AutoFS daemon as root by [[enabling]] and starting the {{ic|autofs.service}}.<br />
<br />
Devices are now automatically mounted when they are accessed, they will remain mounted as long as you access them.<br />
<br />
=== Removable media ===<br />
<br />
* Open {{ic|/etc/autofs/auto.misc}} to add, remove or edit miscellaneous devices. For instance:<br />
<br />
{{hc|/etc/autofs/auto.misc|<nowiki><br />
#kernel -ro ftp.kernel.org:/pub/linux<br />
#boot -fstype=ext2 :/dev/hda1<br />
usbstick -fstype=auto,async,nodev,nosuid,umask=000 :/dev/sdb1<br />
cdrom -fstype=iso9660,ro :/dev/cdrom<br />
#floppy -fstype=auto :/dev/fd0<br />
</nowiki>}}<br />
<br />
If you have a CD/DVD combo-drive you can change the {{ic|cdrom}} line with {{ic|-fstype<nowiki>=</nowiki>auto}} to have the media type autodetected.<br />
<br />
=== NFS network mounts ===<br />
<br />
AutoFS provides a new way of automatically discovering and mounting [[NFS]]-shares on remote servers (the AutoFS network template in {{ic|/etc/autofs/auto.net}} has been removed in autofs5). To enable automagic discovery and mounting of network shares from all accessible servers without any further configuration, you will need to add the following to the {{ic|/etc/autofs/auto.master}} file:<br />
<br />
/net -hosts --timeout=60<br />
<br />
'''Each host name needs to be resolveable, e.g. the name an IP address in {{ic|/etc/hosts}} or via [[Wikipedia:Domain_Name_System|DNS]] and please make sure you have {{Pkg|nfs-utils}} installed and working. You also have to enable RPC (systemctl start|enable rpcbind) to browse shared Folders.'''<br />
<br />
For instance, if you have a remote server ''fileserver'' (the name of the directory is the hostname of the server) with an NFS share named ''/home/share'', you can just access the share by typing:<br />
<br />
# cd /net/fileserver/home/share<br />
<br />
{{Note|Please note that ''ghosting'', i.e. automatically creating directory placeholders before mounting shares is enabled by default, although AutoFS installation notes claim to remove that option from {{ic|/etc/conf.d/autofs}} in order to start the AutoFS daemon.}}<br />
<br />
The {{ic|-hosts}} option uses a similar mechanism as the {{ic|showmount}} command to detect remote shares. You can see the exported shares by typing:<br />
<br />
# showmount <servername> -e <br />
<br />
Replacing ''<servername>'' with the name of your own server.<br />
<br />
An alternative Way is to use the automount-service from Systemd, see [[NFS#Mount using /etc/fstab with systemd|NFS with systemd-automount]]<br />
<br />
==== Manual NFS configuration ====<br />
To mount a NFS share on server_name called /srv/shared_dir to another computer named client_pc at location /mnt/foo, edit auto.master and create a config file for the share (auto.server_name):<br />
{{hc|<nowiki>/etc/autofs/auto.master</nowiki>|<nowiki>/mnt /etc/auto.server_name --timeout 60</nowiki>}}<br />
{{hc|<nowiki>/etc/autofs/auto.server_name</nowiki>|<nowiki>foo -rw,soft,intr,rsize=8192,wsize=8192 server_name:/srv/shared_dir</nowiki>}}<br />
<br />
=== Samba ===<br />
<br />
The Arch package does not provide any [[Samba]] or CIFS templates/scripts (23.07.2009), but the following should work for single shares:<br />
<br />
Add the following to {{ic|/etc/autofs/auto.master}}:<br />
/media/[my_server] /etc/autofs/auto.[my_server] --timeout=60 --ghost<br />
where {{ic|--timeout}} defines how many seconds to wait before the file system is unmounted. The {{ic|--ghost}} option creates empty folders for each mount-point in the file in order to prevent timeouts, if a network share cannot be contacted. <br />
<br />
Next create a file {{ic|/etc/autofs/auto.[my_server]}}<br />
[any_name] -fstype=cifs,[other_options] ://[remote_server]/[remote_share_name]<br />
<br />
You can specify a user name and password to use with the share in the {{ic|other_options}} section:<br />
[any_name] -fstype=cifs,username=[username],password=[password],[other_options] ://[remote_server]/[remote_share_name]<br />
<br />
{{Note|Escape &#36;, and other characters, with a backslash when neccessary.}}<br />
<br />
=== FTP and SSH (with FUSE) ===<br />
<br />
Remote FTP and [[SSH]] servers can be accessed seamlessly with AutoFS using [[Wikipedia:Filesystem in Userspace|FUSE]], a virtual file system layer. <br />
<br />
==== Remote FTP ====<br />
<br />
First, install the {{Pkg|curlftpfs}} package.<br />
Load the '''fuse''' module:<br />
<br />
# modprobe fuse<br />
<br />
Create a {{ic|/etc/modules-load.d/fuse.conf}} file containg {{ic|fuse}} to load it on each system boot.<br />
<br />
Next, add a new entry for FTP servers in {{ic|/etc/autofs/auto.master}}:<br />
<br />
/media/ftp /etc/autofs/auto.ftp --timeout=60<br />
<br />
Create the file {{ic|/etc/autofs/auto.ftp}} and add a server using the {{ic|ftp://myuser:mypassword@host:port/path}} format:<br />
<br />
servername -fstype=curl,rw,allow_other,nodev,nonempty,noatime :ftp\://myuser\:mypassword\@remoteserver<br />
<br />
{{Note| Your passwords are plainly visible for anyone that can run {{ic|df}} (only for mounted servers) or view the file {{ic|/etc/autofs/auto.ftp}}.}}<br />
If you want slightly more security you can create the file {{ic|~root/.netrc}} and add the passwords there. <br />
Passwords are still plain text, but you can have mode 600, and {{ic|df}} command will not show them (mounted or not).<br />
This method is also less sensitive to special characters (that else must be escaped) in the passwords. The format is:<br />
<br />
machine remoteserver <br />
login myuser<br />
password mypassword<br />
<br />
The line in {{ic|/etc/autofs/auto.ftp}} looks like this without user and password:<br />
<br />
servername -fstype=curl,allow_other :ftp\://remoteserver<br />
<br />
Create the file {{ic|/sbin/mount.curl}} with this code:<br />
<br />
{{hc|/sbin/mount.curl|<nowiki><br />
#! /bin/sh<br />
curlftpfs $1 $2 -o $5,disable_eprt<br />
</nowiki>}}<br />
<br />
Create the file {{ic|/sbin/umount.curl}} with this code:<br />
<br />
{{hc|/sbin/umount.curl|<nowiki><br />
#! /bin/sh<br />
fusermount -u $1<br />
</nowiki>}}<br />
<br />
Set the permissions for both files:<br />
<br />
# chmod 755 /sbin/mount.curl<br />
# chmod 755 /sbin/umount.curl<br />
<br />
After a restart your new FTP server should be accessible through {{ic|/media/ftp/servername}}.<br />
<br />
==== Remote SSH ====<br />
<br />
{{Accuracy|1=All the ''ssh*'' commands should be executed as the same user, as before [https://wiki.archlinux.org/index.php?title=Autofs&diff=prev&oldid=318335 this edit]. It should not matter if it is root or unprivileged.}}<br />
<br />
These are basic instructions to access a remote filesystem over [[SSH]] with AutoFS. <br />
<br />
{{Note|Password-less authentication may be convenient but also has security implications. See [[Using SSH Keys|SSH keypair]] for more details}}<br />
<br />
Install the {{Pkg|sshfs}} package.<br />
<br />
Load the {{ic|fuse}} module:<br />
<br />
# modprobe fuse<br />
<br />
Create a {{ic|/etc/modules-load.d/fuse.conf}} file containg {{ic|fuse}} to load it on each system boot if you have not one yet.<br />
<br />
Install {{Pkg|openssh}}.<br />
<br />
Generate an [[Using SSH Keys|SSH keypair]]:<br />
$ ssh-keygen<br />
<br />
When the generator ask for a passphrase, just press {{ic|ENTER}}. Using SSH keys without a passphrase is less secure, yet running AutoFS together with passphrases poses some additional difficulties which are not (yet) covered in this article. <br />
<br />
Next, copy the public key to the remote SSH server:<br />
$ ssh-copy-id username@remotehost<br />
<br />
'''As root''', see that you can login to the remote server without entering a password:<br />
# ssh username@remotehost<br />
<br />
{{Note|This will add the remote server to root's list of {{ic|known_hosts}}. Hosts can be also be manually added to {{ic|/etc/ssh/ssh_known_hosts}}.}}<br />
<br />
Create a new entry for SSH servers in {{ic|/etc/autofs/auto.master}}:<br />
/media/ssh /etc/autofs/auto.ssh --timeout=60<br />
<br />
Create the file {{ic|/etc/autofs/auto.ssh}} and add an SSH server:<br />
{{hc|/etc/autofs/auto.ssh|2=<br />
servername -fstype=fuse,rw,allow_other,IdentityFile=/home/username/.ssh/id_rsa :sshfs\#username@host\:/<br />
}}<br />
<br />
After a restart your SSH server should be accessible through {{ic|/media/ssh/servername}}.<br />
<br />
== MTP ==<br />
<br />
Media Transfer Protocol ([[MTP]]) is used in some Android devices.<br />
<br />
Install the {{Pkg|mtpfs}} package.<br />
<br />
Create a new entry for MTP Device in {{ic|/etc/autofs/auto.misc}}:<br />
android -fstype=fuse,allow_other,umask=000 :mtpfs<br />
<br />
== Troubleshooting and tweaks ==<br />
<br />
This section contains a few solutions for common issues with AutoFS.<br />
<br />
=== Using NIS ===<br />
<br />
Version 5.0.5 of AutoFS has more advanced support for [[NIS]]. To use AutoFS together with NIS, add {{ic|yp:}} in front of the template names in {{ic|/etc/autofs/auto.master}}:<br />
<br />
/home yp:auto_home --timeout=60 <br />
/sbtn yp:auto_sbtn --timeout=60<br />
+auto.master<br />
<br />
On earlier versions of NIS (before 5.0.4), you should add {{ic|nis}} to {{ic|/etc/nsswitch.conf}}:<br />
automount: files nis<br />
<br />
=== Optional parameters ===<br />
<br />
You can set parameters like {{ic|timeout}} systemwide for all AutoFS media in {{ic|/etc/default/autofs}}:<br />
<br />
* Open the {{ic|/etc/default/autofs}} file and edit the {{ic|OPTIONS}} line:<br />
OPTIONS='--timeout=5'<br />
<br />
* To enable logging (default is no logging at all), uncomment and add {{ic|--verbose}} to the {{ic|OPTIONS}} line in {{ic|/etc/default/autofs}} e.g.:<br />
OPTIONS='--verbose --timeout=5'<br />
<br />
After restarting the {{ic|autofs}} daemon, verbose output is visible in {{ic|systemctl status}} or in {{ic|journalctl}}.<br />
<br />
=== Identify multiple devices ===<br />
<br />
If you use multiple USB drives/sticks and want to easily tell them apart, you can use AutoFS to set up the mount points and [[Udev]] to create distinct names for your USB drives. See [[udev#Setting static device names]] for instructions on setting up Udev rules.<br />
<br />
=== AutoFS permissions ===<br />
<br />
If AutoFS is not working for you, make sure that the permissions of the templates files are correct, otherwise AutoFS will not start. This may happen if you backed up your configuration files in a manner which did not preserve file modes. Here are what the modes should be on the configuration files:<br />
<br />
*0644 - /etc/autofs/auto.master<br />
*0644 - /etc/autofs/auto.media<br />
*0644 - /etc/autofs/auto.misc<br />
*0644 - /etc/conf.d/autofs<br />
<br />
In general, scripts (like previous {{ic|auto.net}}) should have executable ({{ic|chmod a+x filename}}) bits set and lists of mounts should not.<br />
<br />
If you are getting errors in {{ic|/var/log/daemon.log}} similar to this, you have a permissions problem:<br />
<br />
May 7 19:44:16 peterix automount[15218]: lookup(program): lookup for petr failed<br />
May 7 19:44:16 peterix automount[15218]: failed to mount /media/cifs/petr<br />
<br />
=== fusermount problems ===<br />
With certain versions of util-linux, you may not be able to unmount a fuse file system drive mounted by autofs, even if you use the "user=" option. See the discussion here:<br />
http://fuse.996288.n3.nabble.com/Cannot-umount-as-non-root-user-anymore-tp689p697.html<br />
<br />
== Alternatives to AutoFS ==<br />
<br />
* [[Systemd]] can automount filesystems upon demand; see [[Fstab#Automount_with_systemd|here]] for the description and the article on [[Sshfs#On_demand|sshfs]] for an example.<br />
* [[Thunar Volume Manager]] is an automount system for users of the [[Thunar]] file manager.<br />
* [[PCManFM]] is a lightweight file manager with built-in support for accessing remote shares<br />
* [[Udisks]] is a minimalistic automatic disk mounting service<br />
<br />
== See also ==<br />
<br />
* FTP and SFTP usage with AutoFS is based on this Gentoo Wiki article: https://web.archive.org/web/20130414074212/http://en.gentoo-wiki.com/wiki/Mounting_SFTP_and_FTP_shares<br />
* More information on SSH can be found on the [[SSH]] and [[Using SSH Keys]] pages of this wiki.</div>X33ahttps://wiki.archlinux.org/index.php?title=Firefox/Privacy&diff=382325Firefox/Privacy2015-07-16T05:03:08Z<p>X33a: /* uBlock */ The two uBlocks aren't comparable</p>
<hr />
<div>[[Category:Web Browser]]<br />
{{Related articles start}}<br />
{{Related|Firefox}}<br />
{{Related|Tor}}<br />
{{Related|Browser Plugins}}<br />
{{Related|Firefox tweaks}}<br />
{{Related|Speed-up Firefox using tmpfs}}<br />
{{Related articles end}}<br />
<br />
This article overviews some useful extensions which enhance security and privacy while using the [[Firefox]] web browser.<br />
<br />
==HTTPS Everywhere==<br />
<br />
[https://www.eff.org/https-everywhere HTTPS Everywhere] is an extension which encrypts your communication with a website. It forces a connection over HTTPS instead of HTTP wherever possible.<br />
<br />
HTTPS Everywhere will be automatically configured and enabled upon restarting Firefox. For information on how to set up your own rules for different websites please visit [https://www.eff.org/https-everywhere/rulesets the official website].<br />
<br />
{{Note|HTTPS Everywhere does not magically enable HTTPS for every site on the internet. The site needs to support HTTPS and HTTPS Everywhere should have a ruleset configured for that site.}}<br />
<br />
==uBlock==<br />
<br />
uBlock (previously μBlock) is a lightweight, efficient blocker which is easy on memory and the CPU. It comes with several filter lists ready to use out-of-the-box (including EasyList, Peter Lowe's, several malware filter lists). <br />
<br />
The lead developer forked the project and created uBlock Origin. As of now, most of the development is being done on uBlock Origin and the codebases are deviating substantially.<br />
<br />
uBlock: [https://github.com/chrisaljoudi/uBlock Github]; [https://addons.mozilla.org/en-US/firefox/addon/ublock/ Firefox Add-ons].<br />
<br />
uBlock Origin: [https://github.com/gorhill/uBlock Github]; [https://addons.mozilla.org/en-US/firefox/addon/ublock-origin/ Firefox Add-ons].<br />
<br />
==Adblock Plus==<br />
<br />
[https://adblockplus.org/en/ Adblock Plus] can be used to stop intrusive advertisments but it can also be configured to block websites from tracking you.<br />
<br />
Once installed visit the [https://easylist.adblockplus.org/en/ Easy List website] and add the EasyList and EasyPrivacy lists to your Adblock Plus filter subscriptions. This is done by simply clicking any of the "Add [filter] to Adblock Plus" on the webpage. This will bring up the add filter prompt. Review the details and click "Add Subscription".<br />
<br />
EasyList is the primary subscription that removes adverts from English webpages, including unwanted frames, images and objects.<br />
<br />
EasyPrivacy is a supplementary subscription for EasyList which removes all forms of tracking from the internet, including web bugs, tracking scripts and information collectors.<br />
<br />
== Privacy Badger ==<br />
<br />
[https://www.eff.org/privacybadger Privacy Badger] is an extension that monitors third-party trackers loaded with web content. It blocks trackers once they appear on different sites. It does not block advertisements in the first place, but since a lot of ads are served based on tracking information these are blocked as well. For more information on the mechanism, see its [https://www.eff.org/privacybadger#faq-How-is-Privacy-Badger-different-to-Disconnect,-Adblock-Plus,-Ghostery,-and-other-blocking-extensions? FAQ].<br />
<br />
==Disconnect==<br />
<br />
Disconnect is a open source project aimed at stopping 2,000 third-party sites from tracking a user. It encrypts data sent to popular sites and claims to loads web pages 27 percent faster. Disconnect shows its users, in real time, how many tracking attempts from Google, Twitter, Facebook, and more are stopped. It categorizes tracking attempts into advertising, analytical, social, and content, which makes it easy to monitor how one is being tracked.<br />
<br />
Disconnect can also stop side-jacking, which utilizes stolen cookies to steal personal data. It is easy to use and well supported. It can be added to Firefox at the [https://disconnect.me/ official website].<br />
<br />
{{Note|Firefox gained a feature based on the Disconnect list. See [[Firefox tweaks#Enable firefox optional tracking protection]].}}<br />
<br />
==Ghostery==<br />
<br />
[https://www.ghostery.com/ Ghostery] is similar to Disconnect, but is a proprietary project to track businesses which employ the use of website trackers. From the website:<br />
<br />
''Ghostery tracks over 1,000 trackers and gives you a roll-call of the ad networks, behavioural data providers, web publishers, and other companies interested in your activity.<br />
<br />
Ghostery can be installed from the [https://www.ghostery.com/download official website]. Once installed Ghostery can be configured from:<br />
chrome://ghostery/content/options.html<br />
<br />
Or by selecting preferences from the Add-ons Manager in Firefox which will bring you to the configuration page. <br />
<br />
Alternatively you can configure Ghostery through the included wizard:<br />
chrome://ghostery/content/wizard.html<br />
<br />
From the configuration page you can configure what 3rd party elements(3pes) Ghostery should block. When navigating the categories you can click on the individual profiles for more information about that specific company. You can also choose to clear Flash and Silverlight cookies on exit. Also, you can enable the cookie protection feature which prevents selected websites from setting cookies in your browser.<br />
<br />
==NoScript==<br />
<br />
[http://noscript.net/ NoScript] is an extension which disables JavaScript, Java, Flash and other plugins on any website not specifically whitelisted by the user. This extension will protect you from exploitation of security vulnerabilities by not letting anything but trusted sites (e.g: your bank, webmail) serve you executable content.<br />
<br />
Once installed you can configure settings for NoScript by either clicking its icon on the toolbar or right clicking a page and navigating to NoScript. You will then have the option to enable/disable scripts for the current page, as well as any third party scripts that the page is linking to. Alternatively you can choose to enable scripts temporarily for that session only.<br />
<br />
For more detailed configuration see the [http://noscript.net/faq NoScript FAQ].<br />
<br />
==Cookie Monster==<br />
<br />
[https://addons.mozilla.org/en-US/firefox/addon/cookie-monster/ Cookie Monster] is a similar extension to NoScript but will the goal of managing cookies.<br />
<br />
From the preferences for Cookie Monster select "Block All Cookies". Once this is done, just as with NoScript, you can enable the use of cookies for specific pages from either the Cookie Monster icon on the toolbar or by right clicking the page and navigating to Cookie Monster. You have the option to accept cookies from the website in question or alternatively to only temporarily allow cookies for the current session.<br />
<br />
==RefControl==<br />
<br />
[http://www.stardrifter.org/refcontrol/ RefControl] is an extension to control what gets sent as the HTTP Referer. Once installed RefControl can be configured so that no referer gets sent when navigating to a new webpage. This prevents the server from knowing which website you originated from.<br />
<br />
To do this open RefControl's preferences and change the setting for "Default for sites not listed:" to <Block>.<br />
<br />
== RequestPolicy ==<br />
<br />
[https://www.requestpolicy.com/ RequestPolicy] is an extension for Mozilla browsers which lets you have control over cross-site requests. The latest development version lets you blacklist or whitelist requests by default. Disabling unnecessary cross-site requests leads to better privacy, safety and faster browsing.<br />
<br />
For more information on cross-site requests and RequestPolicy visit [https://www.requestpolicy.com/faq.html here].</div>X33ahttps://wiki.archlinux.org/index.php?title=Bash&diff=380766Bash2015-07-03T10:57:58Z<p>X33a: /* Shell exits even if ignoreeof set */ elaborate</p>
<hr />
<div>[[Category:Command shells]]<br />
[[de:Bash]]<br />
[[es:Bashrc]]<br />
[[it:Bash]]<br />
[[ja:Bash]]<br />
[[nl:Bashrc]]<br />
[[ru:Bash]]<br />
[[zh-CN:Bash]]<br />
{{Related articles start}}<br />
{{Related|Bash/Functions}}<br />
{{Related|Environment variables}}<br />
{{Related|Readline}}<br />
{{Related|Color Bash Prompt}}<br />
{{Related|Fortune}}<br />
{{Related|Pkgfile}}<br />
{{Related articles end}}<br />
'''Bash''' (Bourne-again Shell) is a [[command-line shell]]/programming language by the [[GNU Project]]. Its name is a homaging reference to its predecessor: the long-deprecated Bourne shell. Bash can be run on most UNIX-like operating systems, including GNU/Linux.<br />
<br />
== Invocation ==<br />
<br />
{{Poor writing|Some duplication left, cryptic explanations}}<br />
<br />
{{Expansion|Expand on non-interactive shells, see [[Talk:Bash#Return in non interactive mode]]}}<br />
<br />
Bash behaviour can be altered depending on how it is invoked. Some descriptions of different modes follow.<br />
<br />
If Bash is spawned by {{ic|login}} in a tty, by an [[SSH]] daemon, or similar means, it is considered a '''login shell'''. This mode can also be engaged using the {{ic|-l}} or {{ic|--login}} command line options.<br />
<br />
Bash is considered an '''interactive shell''' if it is started neither with the {{ic|-c}} option nor any non-option arguments, and whose standard input and error are connected to terminals.<br />
<br />
=== Legacy mode ===<br />
<br />
In Arch {{ic|/bin/sh}} (which used to be the Bourne shell executable) is symlinked to {{ic|/bin/bash}}. If Bash is invoked with the name {{ic|sh}}, it tries to mimic the startup behavior of historical versions of {{ic|sh}}, including POSIX compability.<br />
<br />
A login shell run in legacy mode sources {{ic|/etc/profile}}, then {{ic|~/.profile}}.<br />
<br />
=== Configuration files ===<br />
<br />
{| class="wikitable"<br />
! File<br />
! When file commands are read and executed (''sourced'')<br />
|-<br />
| {{ic|/etc/profile}}<br />
| An ''interactive'' shell that is also a ''login'' shell (for example, from {{ic|/usr/bin/login}}). Sources application settings in {{ic|/etc/profile.d/*.sh}}, and {{ic|/etc/bash.bashrc}}.<br />
|-<br />
| {{ic|/etc/bash.bashrc}}<br />
| An interactive shell (for example, a [[terminal emulator]]). Depends on the {{ic|1=-DSYS_BASHRC="/etc/bash.bashrc"}} compilation flag. Sources {{ic|/usr/share/bash-completion/bash_completion}}.<br />
|-<br />
| {{ic|~/.bash_profile}}<br />
| An interactive shell that is also a login shell. Per-user, after {{ic|/etc/profile}}. If this file does not exist, {{ic|~/.bash_login}} and {{ic|~/.profile}} are checked in that order. The skeleton file {{ic|/etc/skel/.bash_profile}} also sources {{ic|~/.bashrc}}.<br />
|-<br />
| {{ic|~/.bashrc}}<br />
| An interactive shell. Per-user, after {{ic|/etc/bash.bashrc}}.<br />
|-<br />
| {{ic|~/.bash_logout}}<br />
| After exit of a login shell.<br />
|}<br />
<br />
In short, all interactive shells source {{ic|/etc/bash.bashrc}} and {{ic|~/.bashrc}}, while interactive ''login'' shells also source {{ic|/etc/profile}} and {{ic|~/.bash_profile}}.<br />
<br />
{{Note|While interactive, non-login shells do ''not'' source {{ic|~/.bash_profile}}, they still inherit the environment from their parent process (which may be a login shell). See [http://mywiki.wooledge.org/ProcessManagement#On_processes.2C_environments_and_inheritance] for details.}}<br />
<br />
See the ''INVOCATION'' section of {{ic|man 1 bash}} or [http://www.gnu.org/software/bash/manual/bash.html#Bash-Startup-Files] for the complete sequence.<br />
<br />
=== Shell and environment variables ===<br />
<br />
{{Merge|#Configuration files|Duplication}}<br />
<br />
The behavior of Bash and programs run by it can be influenced by a number of environment variables. [[Environment variables]] are used to store useful values such as command search directories, or which browser to use. When a new shell or script is launched it inherits its parent's variables, thus starting with an internal set of shell variables[http://www.kingcomputerservices.com/unix_101/understanding_unix_shells_and_environment_variables.htm ].<br />
<br />
These shell variables in Bash can be exported in order to become environment variables:<br />
<br />
VARIABLE=content<br />
export VARIABLE<br />
<br />
or with a shortcut<br />
<br />
export VARIABLE=content<br />
<br />
Environment variables are conventionally placed in {{ic|~/.profile}} or {{ic|/etc/profile}} so that all bourne-compatible shells can use them.<br />
<br />
See [[Environment variables]] for more general information.<br />
<br />
== Command line ==<br />
<br />
Bash command line is managed by the separate library called [[Readline]]. Readline provides a lot of shortcuts for interacting with the command line i.e. moving back and forth on the word basis, deleting words etc. It is also Readline's responsibility to manage [[Readline#History|history]] of input commands. Last, but not least, it allows you to create [[Readline#Macros|macros]].<br />
<br />
=== Tab completion ===<br />
<br />
[[Wikipedia:Command-line_completion|Tab completion]] is the option to auto-complete partial typed commands by pressing {{ic|Tab}} twice (enabled by default).<br />
<br />
==== Single-tab ability ====<br />
<br />
For single press {{ic|Tab}} results for when a partial or no completion is possible:<br />
<br />
{{hc|~/.inputrc|<br />
set show-all-if-ambiguous on<br />
}}<br />
<br />
Alternatively, for results when no completion is possible:<br />
<br />
{{hc|~/.inputrc|<br />
set show-all-if-unmodified on<br />
}}<br />
<br />
==== Additional programs and options ====<br />
<br />
Bash has native support for for tab completion of: commands, filenames, and variables. This functionality can be extended with the package {{Pkg|bash-completion}}; it extends its functionality by adding a subset of tab completions to popular commands and their options. With {{Pkg|bash-completion}} know that normal completions (such as {{ic|$ ls file.*<tab><tab>}}) will behave different; however, they can be re-enabled with {{ic|$ compopt -o bashdefault <prog>}} (see [https://bbs.archlinux.org/viewtopic.php?id=128471] and [https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html] for more detail). Also for older systems {{Pkg|bash-completion}} may not be resourcefully convenient.<br />
<br />
==== Additional programs and options manually ====<br />
<br />
For basic completion use lines in the form of {{ic|complete -cf your_command}} (these will conflict with the {{Pkg|bash-completion}} settings):<br />
<br />
{{hc|~/.bashrc|<br />
complete -cf sudo<br />
complete -cf man<br />
}}<br />
<br />
=== History completion ===<br />
<br />
History completion bound to arrow keys (down, up) (see: [[Readline#History]] and [https://www.gnu.org/software/bash/manual/html_node/Readline-Init-File-Syntax.html Readline Init File Syntax]):<br />
<br />
{{hc|~/.bashrc|<br />
bind '"\e[A": history-search-backward'<br />
bind '"\e[B": history-search-forward'<br />
}}<br />
<br />
or:<br />
<br />
{{hc|~/.inputrc|<br />
"\e[A": history-search-backward<br />
"\e[B": history-search-forward<br />
}}<br />
<br />
=== Fast word movement with Ctrl ===<br />
<br />
Bash allows to quickly move between words with {{ic|Ctrl+Left}} and {{ic|Ctrl+Right}}.<br />
<br />
{{hc|~/.inputrc|<br />
"\e[1;5C": forward-word<br />
"\e[1;5D": backward-word<br />
"\e[5C": forward-word<br />
"\e[5D": backward-word<br />
"\e\e[C": forward-word<br />
"\e\e[D": backward-word<br />
}}<br />
<br />
=== Mimic Zsh run-help ability ===<br />
<br />
Zsh can invoke the manual for the written command pushing {{ic|Alt+h}}.<br />
A similar behaviour is obtained in Bash by appending this line in your {{ic|inputrc}} file:<br />
{{hc|/etc/inputrc|<br />
"\eh": "\C-a\eb\ed\C-y\e#man \C-y\C-m\C-p\C-p\C-a\C-d\C-e"<br />
}}<br />
<br />
== Aliases ==<br />
<br />
[[Wikipedia:Alias_(command)|alias]] is a command, which enables a replacement of a word with another string. It is often used for abbreviating a system command, or for adding default arguments to a regularly used command. <br />
<br />
Personal aliases are preferably stored in {{ic|~/.bashrc}}, and system-wide aliases (which affect all users) belong in {{ic|/etc/bash.bashrc}}. See [https://gist.github.com/anonymous/a9055e30f97bd19645c2] and [[Pacman tips#Shortcuts]] for example aliases.<br />
<br />
For functions, see [[Bash/Functions]].<br />
<br />
== Tips and tricks ==<br />
<br />
=== Prompt customization ===<br />
<br />
{{Expansion|Mention {{ic|PS2}} to {{ic|PS4}}[http://www.cyberciti.biz/tips/howto-linux-unix-bash-shell-setup-prompt.html]}}<br />
{{Merge|Color Bash Prompt}}<br />
<br />
The Bash prompt is governed by the variable {{ic|$PS1}}. To colorize the Bash prompt, use:<br />
{{hc|~/.bashrc|2=<br />
#PS1='[\u@\h \W]\$ ' # To leave the default one<br />
#DO NOT USE RAW ESCAPES, USE TPUT<br />
reset=$(tput sgr0)<br />
red=$(tput setaf 1)<br />
blue=$(tput setaf 4)<br />
green=$(tput setaf 2)<br />
<br />
PS1='\[$red\]\u\[$reset\] \[$blue\]\w\[$reset\] \[$red\]\$ \[$reset\]\[$green\] '<br />
}}<br />
This {{ic|$PS1}} is useful for a root Bash prompt, with red designation and green console text. The {{ic|\[}} and {{ic|\[}} should wrap non-printing characters sequences to avoid wrong estimation of PS1 size which leads to display issues when navigating through history and editing the command line. For more info, see: [[Color Bash Prompt]].<br />
<br />
==== Customize title ====<br />
<br />
The {{ic|$PROMPT_COMMAND}} variable allows you to execute a command before the prompt. For example, this will change the title to your full current working directory:<br />
<br />
{{hc|~/.bashrc|<nowiki><br />
export PROMPT_COMMAND='echo -ne "\033]0;$PWD\007"'<br />
</nowiki>}}<br />
<br />
This will change your title to the last command run, and make sure your history file is always up-to-date:<br />
{{hc|~/.bashrc|<nowiki><br />
export HISTCONTROL=ignoreboth<br />
export HISTIGNORE='history*'<br />
export PROMPT_COMMAND='history -a;echo -en "\e]2;";history 1|sed "s/^[ \t]*[0-9]\{1,\} //g";echo -en "\e\\";'<br />
</nowiki>}}<br />
<br />
=== Command-not-found (AUR) ===<br />
<br />
[[pkgfile]] includes a "command not found" hook that will automatically search the official repositories, when entering an unrecognized command.<br />
An alternative "command not found" hook is provided by {{AUR|command-not-found}}. Usage example:<br />
<br />
{{hc|$ abiword|<br />
The command 'abiword' is been provided by the following packages:<br />
'''abiword''' (2.8.6-7) from extra<br />
[ abiword ]<br />
'''abiword''' (2.8.6-7) from staging<br />
[ abiword ]<br />
'''abiword''' (2.8.6-7) from testing<br />
[ abiword ]<br />
}}<br />
<br />
To load it automatically:<br />
<br />
{{hc|''~/.bashrc'' or ''~/.zshrc''|<br />
[ -r /etc/profile.d/cnf.sh ] && . /etc/profile.d/cnf.sh<br />
}}<br />
<br />
=== Disable Ctrl+z in terminal ===<br />
<br />
You can disable the {{ic|Ctrl+z}} feature (pauses/closes your application) by wrapping your command like this:<br />
<br />
#!/bin/bash<br />
trap "" 20<br />
''adom''<br />
<br />
Now when you accidentally press {{ic|Ctrl+z}} in {{AUR|adom}} instead of {{ic|Shift+z}} nothing will happen because {{ic|Ctrl+z}} will be ignored.<br />
<br />
=== Clear the screen after logging out ===<br />
<br />
To clear the screen after logging out on a virtual terminal:<br />
{{hc|~/.bash_logout|<br />
clear<br />
reset<br />
}}<br />
<br />
=== ASCII historical calendar ===<br />
<br />
To install [http://www.openbsd.org/cgi-bin/man.cgi?query=calendar&sektion=1 calendar] files in your {{ic|~/.calendar}} directory you will need the {{Pkg|rpmextract}} package installed. Then from your home directory, run the following:<br />
<br />
$ mkdir -p ~/.calendar<br />
$ curl -o calendar.rpm ftp://ftp.univie.ac.at/systems/linux/fedora/epel/5/x86_64/calendar-1.25-4.el5.x86_64.rpm<br />
$ rpm2cpio calendar.rpm | bsdtar -C ~/.calendar --strip-components=4 -xf - ./usr/share/c*<br />
<br />
This will then print out the calendar items:<br />
<br />
$ sed -n "/$(date +%m\\/%d\\\|%b\*\ %d)/p" $(find ~/.calendar /usr/share/calendar -maxdepth 1 -type f -name 'c*' 2>/dev/null);<br />
<br />
=== Auto "cd" when entering just a path ===<br />
<br />
Bash can automatically prepend {{ic|cd }} when entering just a path in the shell. For example:<br />
{{hc|$ /etc|<br />
bash: /etc: Is a directory<br />
}}<br />
<br />
But after:<br />
{{hc|~/.bashrc|<br />
shopt -s autocd<br />
}}<br />
<br />
You get:<br />
[user@host ~] $ /etc<br />
cd /etc<br />
[user@host etc]<br />
<br />
== Troubleshooting ==<br />
<br />
=== Line wrap on window resize ===<br />
<br />
When resizing a [[terminal emulator]], Bash may not receive the resize signal. This will cause typed text to not wrap correctly and overlap the prompt. The {{ic|checkwinsize}} shell option checks the window size after each command and, if necessary, updates the values of {{ic|LINES}} and {{ic|COLUMNS}}.<br />
<br />
{{hc|~/.bashrc|<br />
shopt -s checkwinsize<br />
}}<br />
<br />
=== Shell exits even if ignoreeof set ===<br />
<br />
If you have set the {{ic|ignoreeof}} option and you find that repeatedly hitting {{ic|ctrl-d}} causes the shell to exit, it is because this option only allows 10 consecutive invocations of this keybinding (or 10 consecutive EOF characters, to be precise), before exiting the shell.<br />
<br />
To allow higher values, you have to use the IGNOREEOF variable.<br />
<br />
For example:<br />
export IGNOREEOF=100<br />
<br />
== See also ==<br />
<br />
* [https://www.gnu.org/software/bash/manual/bashref.html Bash Reference]<br />
* [https://www.gnu.org/software/bash/manual/bash.html Bash manual page]<br />
* [https://www.gnu.org/software/bash/manual/html_node/Readline-Init-File-Syntax.html Readline Init File Syntax]<br />
* [http://www.aosabook.org/en/bash.html The Bourne-Again Shell] - The third chapter of ''The Architecture of Open Source Applications''<br />
* [http://shellcheck.net Shellcheck] - Check bash scripts for common errors<br />
<br />
=== Tutorials ===<br />
<br />
* [http://mywiki.wooledge.org/BashGuide BashGuide on Greg's Wiki]<br />
* [http://mywiki.wooledge.org/BashFAQ BashFAQ on Greg's Wiki]<br />
* [http://wiki.bash-hackers.org/doku.php Bash Hackers Wiki]<br />
* [http://tldp.org/LDP/abs/html/ Advanced Bash Scripting Guide]<br />
* [http://www.ibm.com/developerworks/linux/library/l-bash.html Bash Scripting by Example]<br />
* [http://www.grymoire.com/Unix/Quote.html Quote Tutorial]<br />
* [http://linuxtutorial.todolistme.net Introduction to Bash]<br />
<br />
=== Community ===<br />
<br />
* [irc://irc.freenode.net#bash An active and friendly IRC channel for Bash]<br />
* [http://bashscripts.org Bashscripts.org]<br />
<br />
=== Examples ===<br />
<br />
* [http://tldp.org/HOWTO/Xterm-Title-4.html How to change the title of an xterm]</div>X33ahttps://wiki.archlinux.org/index.php?title=Bash&diff=380763Bash2015-07-03T10:49:46Z<p>X33a: /* Troubleshooting */ added a section about ignoreeof usage</p>
<hr />
<div>[[Category:Command shells]]<br />
[[de:Bash]]<br />
[[es:Bashrc]]<br />
[[it:Bash]]<br />
[[ja:Bash]]<br />
[[nl:Bashrc]]<br />
[[ru:Bash]]<br />
[[zh-CN:Bash]]<br />
{{Related articles start}}<br />
{{Related|Bash/Functions}}<br />
{{Related|Environment variables}}<br />
{{Related|Readline}}<br />
{{Related|Color Bash Prompt}}<br />
{{Related|Fortune}}<br />
{{Related|Pkgfile}}<br />
{{Related articles end}}<br />
'''Bash''' (Bourne-again Shell) is a [[command-line shell]]/programming language by the [[GNU Project]]. Its name is a homaging reference to its predecessor: the long-deprecated Bourne shell. Bash can be run on most UNIX-like operating systems, including GNU/Linux.<br />
<br />
== Invocation ==<br />
<br />
{{Poor writing|Some duplication left, cryptic explanations}}<br />
<br />
{{Expansion|Expand on non-interactive shells, see [[Talk:Bash#Return in non interactive mode]]}}<br />
<br />
Bash behaviour can be altered depending on how it is invoked. Some descriptions of different modes follow.<br />
<br />
If Bash is spawned by {{ic|login}} in a tty, by an [[SSH]] daemon, or similar means, it is considered a '''login shell'''. This mode can also be engaged using the {{ic|-l}} or {{ic|--login}} command line options.<br />
<br />
Bash is considered an '''interactive shell''' if it is started neither with the {{ic|-c}} option nor any non-option arguments, and whose standard input and error are connected to terminals.<br />
<br />
=== Legacy mode ===<br />
<br />
In Arch {{ic|/bin/sh}} (which used to be the Bourne shell executable) is symlinked to {{ic|/bin/bash}}. If Bash is invoked with the name {{ic|sh}}, it tries to mimic the startup behavior of historical versions of {{ic|sh}}, including POSIX compability.<br />
<br />
A login shell run in legacy mode sources {{ic|/etc/profile}}, then {{ic|~/.profile}}.<br />
<br />
=== Configuration files ===<br />
<br />
{| class="wikitable"<br />
! File<br />
! When file commands are read and executed (''sourced'')<br />
|-<br />
| {{ic|/etc/profile}}<br />
| An ''interactive'' shell that is also a ''login'' shell (for example, from {{ic|/usr/bin/login}}). Sources application settings in {{ic|/etc/profile.d/*.sh}}, and {{ic|/etc/bash.bashrc}}.<br />
|-<br />
| {{ic|/etc/bash.bashrc}}<br />
| An interactive shell (for example, a [[terminal emulator]]). Depends on the {{ic|1=-DSYS_BASHRC="/etc/bash.bashrc"}} compilation flag. Sources {{ic|/usr/share/bash-completion/bash_completion}}.<br />
|-<br />
| {{ic|~/.bash_profile}}<br />
| An interactive shell that is also a login shell. Per-user, after {{ic|/etc/profile}}. If this file does not exist, {{ic|~/.bash_login}} and {{ic|~/.profile}} are checked in that order. The skeleton file {{ic|/etc/skel/.bash_profile}} also sources {{ic|~/.bashrc}}.<br />
|-<br />
| {{ic|~/.bashrc}}<br />
| An interactive shell. Per-user, after {{ic|/etc/bash.bashrc}}.<br />
|-<br />
| {{ic|~/.bash_logout}}<br />
| After exit of a login shell.<br />
|}<br />
<br />
In short, all interactive shells source {{ic|/etc/bash.bashrc}} and {{ic|~/.bashrc}}, while interactive ''login'' shells also source {{ic|/etc/profile}} and {{ic|~/.bash_profile}}.<br />
<br />
{{Note|While interactive, non-login shells do ''not'' source {{ic|~/.bash_profile}}, they still inherit the environment from their parent process (which may be a login shell). See [http://mywiki.wooledge.org/ProcessManagement#On_processes.2C_environments_and_inheritance] for details.}}<br />
<br />
See the ''INVOCATION'' section of {{ic|man 1 bash}} or [http://www.gnu.org/software/bash/manual/bash.html#Bash-Startup-Files] for the complete sequence.<br />
<br />
=== Shell and environment variables ===<br />
<br />
{{Merge|#Configuration files|Duplication}}<br />
<br />
The behavior of Bash and programs run by it can be influenced by a number of environment variables. [[Environment variables]] are used to store useful values such as command search directories, or which browser to use. When a new shell or script is launched it inherits its parent's variables, thus starting with an internal set of shell variables[http://www.kingcomputerservices.com/unix_101/understanding_unix_shells_and_environment_variables.htm ].<br />
<br />
These shell variables in Bash can be exported in order to become environment variables:<br />
<br />
VARIABLE=content<br />
export VARIABLE<br />
<br />
or with a shortcut<br />
<br />
export VARIABLE=content<br />
<br />
Environment variables are conventionally placed in {{ic|~/.profile}} or {{ic|/etc/profile}} so that all bourne-compatible shells can use them.<br />
<br />
See [[Environment variables]] for more general information.<br />
<br />
== Command line ==<br />
<br />
Bash command line is managed by the separate library called [[Readline]]. Readline provides a lot of shortcuts for interacting with the command line i.e. moving back and forth on the word basis, deleting words etc. It is also Readline's responsibility to manage [[Readline#History|history]] of input commands. Last, but not least, it allows you to create [[Readline#Macros|macros]].<br />
<br />
=== Tab completion ===<br />
<br />
[[Wikipedia:Command-line_completion|Tab completion]] is the option to auto-complete partial typed commands by pressing {{ic|Tab}} twice (enabled by default).<br />
<br />
==== Single-tab ability ====<br />
<br />
For single press {{ic|Tab}} results for when a partial or no completion is possible:<br />
<br />
{{hc|~/.inputrc|<br />
set show-all-if-ambiguous on<br />
}}<br />
<br />
Alternatively, for results when no completion is possible:<br />
<br />
{{hc|~/.inputrc|<br />
set show-all-if-unmodified on<br />
}}<br />
<br />
==== Additional programs and options ====<br />
<br />
Bash has native support for for tab completion of: commands, filenames, and variables. This functionality can be extended with the package {{Pkg|bash-completion}}; it extends its functionality by adding a subset of tab completions to popular commands and their options. With {{Pkg|bash-completion}} know that normal completions (such as {{ic|$ ls file.*<tab><tab>}}) will behave different; however, they can be re-enabled with {{ic|$ compopt -o bashdefault <prog>}} (see [https://bbs.archlinux.org/viewtopic.php?id=128471] and [https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html] for more detail). Also for older systems {{Pkg|bash-completion}} may not be resourcefully convenient.<br />
<br />
==== Additional programs and options manually ====<br />
<br />
For basic completion use lines in the form of {{ic|complete -cf your_command}} (these will conflict with the {{Pkg|bash-completion}} settings):<br />
<br />
{{hc|~/.bashrc|<br />
complete -cf sudo<br />
complete -cf man<br />
}}<br />
<br />
=== History completion ===<br />
<br />
History completion bound to arrow keys (down, up) (see: [[Readline#History]] and [https://www.gnu.org/software/bash/manual/html_node/Readline-Init-File-Syntax.html Readline Init File Syntax]):<br />
<br />
{{hc|~/.bashrc|<br />
bind '"\e[A": history-search-backward'<br />
bind '"\e[B": history-search-forward'<br />
}}<br />
<br />
or:<br />
<br />
{{hc|~/.inputrc|<br />
"\e[A": history-search-backward<br />
"\e[B": history-search-forward<br />
}}<br />
<br />
=== Fast word movement with Ctrl ===<br />
<br />
Bash allows to quickly move between words with {{ic|Ctrl+Left}} and {{ic|Ctrl+Right}}.<br />
<br />
{{hc|~/.inputrc|<br />
"\e[1;5C": forward-word<br />
"\e[1;5D": backward-word<br />
"\e[5C": forward-word<br />
"\e[5D": backward-word<br />
"\e\e[C": forward-word<br />
"\e\e[D": backward-word<br />
}}<br />
<br />
=== Mimic Zsh run-help ability ===<br />
<br />
Zsh can invoke the manual for the written command pushing {{ic|Alt+h}}.<br />
A similar behaviour is obtained in Bash by appending this line in your {{ic|inputrc}} file:<br />
{{hc|/etc/inputrc|<br />
"\eh": "\C-a\eb\ed\C-y\e#man \C-y\C-m\C-p\C-p\C-a\C-d\C-e"<br />
}}<br />
<br />
== Aliases ==<br />
<br />
[[Wikipedia:Alias_(command)|alias]] is a command, which enables a replacement of a word with another string. It is often used for abbreviating a system command, or for adding default arguments to a regularly used command. <br />
<br />
Personal aliases are preferably stored in {{ic|~/.bashrc}}, and system-wide aliases (which affect all users) belong in {{ic|/etc/bash.bashrc}}. See [https://gist.github.com/anonymous/a9055e30f97bd19645c2] and [[Pacman tips#Shortcuts]] for example aliases.<br />
<br />
For functions, see [[Bash/Functions]].<br />
<br />
== Tips and tricks ==<br />
<br />
=== Prompt customization ===<br />
<br />
{{Expansion|Mention {{ic|PS2}} to {{ic|PS4}}[http://www.cyberciti.biz/tips/howto-linux-unix-bash-shell-setup-prompt.html]}}<br />
{{Merge|Color Bash Prompt}}<br />
<br />
The Bash prompt is governed by the variable {{ic|$PS1}}. To colorize the Bash prompt, use:<br />
{{hc|~/.bashrc|2=<br />
#PS1='[\u@\h \W]\$ ' # To leave the default one<br />
#DO NOT USE RAW ESCAPES, USE TPUT<br />
reset=$(tput sgr0)<br />
red=$(tput setaf 1)<br />
blue=$(tput setaf 4)<br />
green=$(tput setaf 2)<br />
<br />
PS1='\[$red\]\u\[$reset\] \[$blue\]\w\[$reset\] \[$red\]\$ \[$reset\]\[$green\] '<br />
}}<br />
This {{ic|$PS1}} is useful for a root Bash prompt, with red designation and green console text. The {{ic|\[}} and {{ic|\[}} should wrap non-printing characters sequences to avoid wrong estimation of PS1 size which leads to display issues when navigating through history and editing the command line. For more info, see: [[Color Bash Prompt]].<br />
<br />
==== Customize title ====<br />
<br />
The {{ic|$PROMPT_COMMAND}} variable allows you to execute a command before the prompt. For example, this will change the title to your full current working directory:<br />
<br />
{{hc|~/.bashrc|<nowiki><br />
export PROMPT_COMMAND='echo -ne "\033]0;$PWD\007"'<br />
</nowiki>}}<br />
<br />
This will change your title to the last command run, and make sure your history file is always up-to-date:<br />
{{hc|~/.bashrc|<nowiki><br />
export HISTCONTROL=ignoreboth<br />
export HISTIGNORE='history*'<br />
export PROMPT_COMMAND='history -a;echo -en "\e]2;";history 1|sed "s/^[ \t]*[0-9]\{1,\} //g";echo -en "\e\\";'<br />
</nowiki>}}<br />
<br />
=== Command-not-found (AUR) ===<br />
<br />
[[pkgfile]] includes a "command not found" hook that will automatically search the official repositories, when entering an unrecognized command.<br />
An alternative "command not found" hook is provided by {{AUR|command-not-found}}. Usage example:<br />
<br />
{{hc|$ abiword|<br />
The command 'abiword' is been provided by the following packages:<br />
'''abiword''' (2.8.6-7) from extra<br />
[ abiword ]<br />
'''abiword''' (2.8.6-7) from staging<br />
[ abiword ]<br />
'''abiword''' (2.8.6-7) from testing<br />
[ abiword ]<br />
}}<br />
<br />
To load it automatically:<br />
<br />
{{hc|''~/.bashrc'' or ''~/.zshrc''|<br />
[ -r /etc/profile.d/cnf.sh ] && . /etc/profile.d/cnf.sh<br />
}}<br />
<br />
=== Disable Ctrl+z in terminal ===<br />
<br />
You can disable the {{ic|Ctrl+z}} feature (pauses/closes your application) by wrapping your command like this:<br />
<br />
#!/bin/bash<br />
trap "" 20<br />
''adom''<br />
<br />
Now when you accidentally press {{ic|Ctrl+z}} in {{AUR|adom}} instead of {{ic|Shift+z}} nothing will happen because {{ic|Ctrl+z}} will be ignored.<br />
<br />
=== Clear the screen after logging out ===<br />
<br />
To clear the screen after logging out on a virtual terminal:<br />
{{hc|~/.bash_logout|<br />
clear<br />
reset<br />
}}<br />
<br />
=== ASCII historical calendar ===<br />
<br />
To install [http://www.openbsd.org/cgi-bin/man.cgi?query=calendar&sektion=1 calendar] files in your {{ic|~/.calendar}} directory you will need the {{Pkg|rpmextract}} package installed. Then from your home directory, run the following:<br />
<br />
$ mkdir -p ~/.calendar<br />
$ curl -o calendar.rpm ftp://ftp.univie.ac.at/systems/linux/fedora/epel/5/x86_64/calendar-1.25-4.el5.x86_64.rpm<br />
$ rpm2cpio calendar.rpm | bsdtar -C ~/.calendar --strip-components=4 -xf - ./usr/share/c*<br />
<br />
This will then print out the calendar items:<br />
<br />
$ sed -n "/$(date +%m\\/%d\\\|%b\*\ %d)/p" $(find ~/.calendar /usr/share/calendar -maxdepth 1 -type f -name 'c*' 2>/dev/null);<br />
<br />
=== Auto "cd" when entering just a path ===<br />
<br />
Bash can automatically prepend {{ic|cd }} when entering just a path in the shell. For example:<br />
{{hc|$ /etc|<br />
bash: /etc: Is a directory<br />
}}<br />
<br />
But after:<br />
{{hc|~/.bashrc|<br />
shopt -s autocd<br />
}}<br />
<br />
You get:<br />
[user@host ~] $ /etc<br />
cd /etc<br />
[user@host etc]<br />
<br />
== Troubleshooting ==<br />
<br />
=== Line wrap on window resize ===<br />
<br />
When resizing a [[terminal emulator]], Bash may not receive the resize signal. This will cause typed text to not wrap correctly and overlap the prompt. The {{ic|checkwinsize}} shell option checks the window size after each command and, if necessary, updates the values of {{ic|LINES}} and {{ic|COLUMNS}}.<br />
<br />
{{hc|~/.bashrc|<br />
shopt -s checkwinsize<br />
}}<br />
<br />
=== Shell exits even if ignoreeof set ===<br />
<br />
If you have set the {{ic|ignoreeof}} option and you find that repeatedly hitting {{ic|ctrl-d}} causes the shell to exit, it is because this option only allows 10 consecutive invocations of this keybinding before exiting the shell.<br />
<br />
To allow higher values, you have to use the IGNOREEOF variable.<br />
<br />
For example:<br />
export IGNOREEOF=100<br />
<br />
== See also ==<br />
<br />
* [https://www.gnu.org/software/bash/manual/bashref.html Bash Reference]<br />
* [https://www.gnu.org/software/bash/manual/bash.html Bash manual page]<br />
* [https://www.gnu.org/software/bash/manual/html_node/Readline-Init-File-Syntax.html Readline Init File Syntax]<br />
* [http://www.aosabook.org/en/bash.html The Bourne-Again Shell] - The third chapter of ''The Architecture of Open Source Applications''<br />
* [http://shellcheck.net Shellcheck] - Check bash scripts for common errors<br />
<br />
=== Tutorials ===<br />
<br />
* [http://mywiki.wooledge.org/BashGuide BashGuide on Greg's Wiki]<br />
* [http://mywiki.wooledge.org/BashFAQ BashFAQ on Greg's Wiki]<br />
* [http://wiki.bash-hackers.org/doku.php Bash Hackers Wiki]<br />
* [http://tldp.org/LDP/abs/html/ Advanced Bash Scripting Guide]<br />
* [http://www.ibm.com/developerworks/linux/library/l-bash.html Bash Scripting by Example]<br />
* [http://www.grymoire.com/Unix/Quote.html Quote Tutorial]<br />
* [http://linuxtutorial.todolistme.net Introduction to Bash]<br />
<br />
=== Community ===<br />
<br />
* [irc://irc.freenode.net#bash An active and friendly IRC channel for Bash]<br />
* [http://bashscripts.org Bashscripts.org]<br />
<br />
=== Examples ===<br />
<br />
* [http://tldp.org/HOWTO/Xterm-Title-4.html How to change the title of an xterm]</div>X33ahttps://wiki.archlinux.org/index.php?title=Mirrors&diff=371083Mirrors2015-04-25T12:27:29Z<p>X33a: /* Enabling a specific mirror */ ftp.archlinux.org is no more (https://lists.archlinux.org/pipermail/aur-general/2015-February/030268.html)</p>
<hr />
<div>[[Category:About Arch]]<br />
[[Category:Package management]]<br />
[[ar:Mirrors]]<br />
[[es:Mirrors]]<br />
[[fr:Miroirs]]<br />
[[it:Mirrors]]<br />
[[ja:ミラー]]<br />
[[ru:Mirrors]]<br />
[[zh-CN:Mirrors]]<br />
{{Related articles start}}<br />
{{Related|Mirroring}}<br />
{{Related|pacman}}<br />
{{Related|reflector}}<br />
{{Related articles end}}<br />
<br />
This page is a guide to selecting and configuring your mirrors, and a listing of current available mirrors.<br />
<br />
== Enabling a specific mirror ==<br />
<br />
To enable mirrors, edit {{ic|/etc/pacman.d/mirrorlist}} and locate your geographic region. Uncomment mirrors you would like to use.<br />
<br />
Example:<br />
<br />
# Any<br />
# Server = <nowiki>ftp://mirrors.kernel.org/archlinux/$repo/os/$arch</nowiki><br />
'''Server = <nowiki>http://mirrors.kernel.org/archlinux/$repo/os/$arch</nowiki>'''<br />
<br />
See [[#Mirror status]] and [[#List by speed]] for tools that help choosing mirrors.<br />
<br />
{{Tip|<br />
* Uncomment 5 favorite mirrors and place them at the top of the mirrorlist file. That way it's easy to find them and move them around if the first mirror on the list has problems. It also makes merging mirrorlist updates easier.<br />
* HTTP mirrors are faster than FTP, because of something called [[Wikipedia:HTTP persistent connection|persistent HTTP connection]]: with FTP, ''pacman'' has to establish a new connection to server each time it requests to download next package, resulting in a brief pause.}}<br />
<br />
It is also possible to specify mirrors in {{ic|/etc/pacman.conf}}. For the ''[core]'' repository, the default setup is:<br />
[core]<br />
Include = /etc/pacman.d/mirrorlist<br />
<br />
To use the ''HostEurope'' mirror as a default mirror, add it before the {{ic|Include}} line:<br />
[core]<br />
'''Server = <nowiki>ftp://ftp.hosteurope.de/mirror/ftp.archlinux.org/core/os/$arch</nowiki>'''<br />
Include = /etc/pacman.d/mirrorlist<br />
<br />
pacman will now try to connect to this mirror first. Proceed to do the same for ''[testing]'', ''[extra]'', and ''[community]'', if applicable.<br />
<br />
{{Note|If mirrors have been stated directly in {{ic|pacman.conf}}, remember to use the same mirror for all repositories. Otherwise packages that are incompatible to each other may be installed, like linux from ''[core]'' and an older kernel module from ''[extra]''.}}<br />
<br />
=== Force pacman to refresh the package lists ===<br />
<br />
After creating/editing {{ic|/etc/pacman.d/mirrorlist}}, (manually or by using {{ic|rankmirrors}}) issue the following command:<br />
# pacman -Syyu<br />
<br />
{{Tip|Passing two {{ic|--refresh}} or {{ic|-y}} flags forces pacman to refresh all package lists even if they are considered to be up to date. Issuing {{ic|pacman -Syyu}} ''whenever changing to a new mirror'' is good practice and will avoid possible issues.}}<br />
<br />
== Mirror status ==<br />
<br />
Check the status of the Arch mirrors and how updated they are by visiting https://www.archlinux.org/mirrors/status/.<br />
<br />
You can generate an up to date mirrorlist [https://www.archlinux.org/mirrorlist/ here], automate the process with a [[#Script to download from Mirrorlist Generator|script]], or install [[Reflector]], a utility that generates a mirrorlist using Mirrorcheck's list; you can also manually check how up-to-date a mirror is by:<br />
#picking a server and browsing to "extra/os/";<br />
#accessing https://www.archlinux.org/ in another browser tab or window; and<br />
#comparing the last-modified date of the {{ic|i686}} directory on the mirror to the ''[extra]'' date on the homepage, in the ''Package Repositories'' box to the right.<br />
<br />
== Sorting mirrors ==<br />
<br />
When downloading packages pacman uses the mirrors in the order they are in {{ic|/etc/pacman.d/mirrorlist}}. If not using {{Pkg|reflector}}, which has the ability to sort mirrors by both how updated they are and their speed, follow this demonstration of manual mirror sorting.<br />
<br />
{{Note|This does not apply to [[Improve pacman performance#Using_powerpill-light | powerpill-light]], which connects to many servers simultaneously to increase the overall download speed. The speed of individual connections becomes less relevant, and powerpill-light can be configured to require minimum speeds per connection.}}<br />
<br />
=== List by speed ===<br />
<br />
Take full advantage of using the fastest local mirror, which can be determined via the included Bash script, {{ic|/usr/bin/rankmirrors}}.<br />
<br />
Back up the existing {{ic|/etc/pacman.d/mirrorlist}}:<br />
<br />
# cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.backup<br />
<br />
Edit {{ic|/etc/pacman.d/mirrorlist.backup}} and uncomment mirrors for testing with {{ic|rankmirrors}}.<br />
<br />
Optionally run the following {{ic|sed}} line to uncomment every mirror:<br />
<br />
# sed -i 's/^#Server/Server/' /etc/pacman.d/mirrorlist.backup<br />
<br />
Finally, rank the mirrors. Operand {{ic|-n 6}} means only output the 6 fastest mirrors:<br />
<br />
# rankmirrors -n 6 /etc/pacman.d/mirrorlist.backup > /etc/pacman.d/mirrorlist<br />
<br />
Run {{ic|rankmirrors -h}} for a list of all the available options.<br />
<br />
===Combined listing by speed and status===<br />
It is not a good idea to just use the fastest mirrors, since the fastest mirrors might be out of date. The preferred way would be to use [[#List by speed]], then sorting those 6 fastest mirrors by their [[#Mirror status]].<br />
<br />
Simply visit either one or both [[#Mirror status]] links and sort them by the ones that are more up to date. Move the more up to date mirrors to the top of {{ic|/etc/pacman.d/mirrorlist}} and if the mirrors are way out of date simply do not use those; repeat the process leaving out the outdated mirrors. So this ends up with a total of 6 mirrors that are sorted by speed and status, leaving out outdated mirrors.<br />
<br />
When having mirror issues the above should be repeated. Or repeat once in a while even if not having mirror problems, to keep {{ic|/etc/pacman.d/mirrorlist}} up to date.<br />
<br />
=== Script to download from Mirrorlist Generator ===<br />
<br />
The [https://www.archlinux.org/mirrorlist/ Pacman Mirrorlist Generator] ranks mirrors based on geography, availability, and tiering. A script is available that can backup the previous mirrorlist then install a Mirrorlist Generator version. To install it use the AUR package {{AUR|armrr-git}} or download it with {{ic|curl -O https://raw.githubusercontent.com/Gen2ly/armrr/master/armrr}}. Run {{ic|armrr [*country code]}} or just {{ic|armrr}} for a country code prompt. Type {{ic|armrr -h,--help}} for more details.<br />
<br />
=== Using Reflector ===<br />
<br />
Alternatively, you can use [[Reflector]] to automatically retrieve the latest mirrorlist from the [https://www.archlinux.org/mirrors/status/ MirrorStatus] page, filter the most up-to-date mirrors, sort them by speed and overwrite the file {{ic|/etc/pacman.d/mirrorlist}}.<br />
<br />
=== Choosing a local mirror ===<br />
<br />
The simple way is to edit the mirrorlist file by placing a local mirror at the top of the list. pacman will then use this mirror for preference.<br />
<br />
Alternatively {{ic|/etc/pacman.conf}} can be edited by placing a local mirror before the line sourcing the mirrorlist file, i.e. where it says "add your preferred servers here". It is safer if you use the same server for each repository.<br />
<br />
=== List mirrors only for a specific country ===<br />
<br />
Can be useful to automate update of the mirror list only for a specific countries instead of making a speed test each time. Assumed that {{ic|mirrorlist.pacnew}} exist, the file creates after installation of the {{Pkg|pacman-mirrorlist}} update.<br />
<br />
{{bc|<nowiki>Cnt="China";<br />
awk -v GG=$Cnt '{if(match($0,GG) != "0")AA="1";if(AA == "1"){if( length($2) != "0" )print substr($0,2) ;else AA="0"} }' \<br />
/etc/pacman.d/mirrorlist.pacnew</nowiki>}}<br />
<br />
== Official mirrors ==<br />
<br />
The official Arch Linux mirror list is available from the {{pkg|pacman-mirrorlist}} package. To get an even more up-to-date list of mirrors, use the [https://www.archlinux.org/mirrorlist/ Pacman Mirror List Generator] page on the main site.<br />
<br />
In the unlikely scenario that you are without any configured mirrors and {{ic|pacman-mirrorlist}} is not installed, run the following command:<br />
# wget -O /etc/pacman.d/mirrorlist <nowiki>https://www.archlinux.org/mirrorlist/all/</nowiki><br />
<br />
Be sure to uncomment a preferred mirror as described above, then:<br />
# pacman -Syyu pacman-mirrorlist<br />
<br />
If you want your mirror to be added to the official list, file a feature request. In the meantime, add it to the [[#Unofficial mirrors]] list at the end of this page.<br />
<br />
If you get an error stating that the {{ic|$arch}} variable is used but not defined, add the following to your {{ic|/etc/pacman.conf}}:<br />
Architecture = x86_64<br />
<br />
{{Note|You can also use the values {{ic|auto}} and {{ic|i686}} for the {{ic|Architecture}} variable.}}<br />
<br />
=== IPv6-ready mirrors ===<br />
<br />
The [https://www.archlinux.org/mirrorlist/?country=all&protocol=http&ip_version=6 pacman mirror list generator] can also be used to find a list of current IPv6 mirrors.<br />
<br />
== Unofficial mirrors ==<br />
<br />
These mirrors are ''not'' listed in {{ic|/etc/pacman.d/mirrorlist}}.<br />
<br />
=== Global ===<br />
<br />
* http://sourceforge.net/projects/archlinux/files/ - ''ISO files only; Does not have any releases since 2006. Use it only if for getting older ISOs.''<br />
<br />
=== TOR Network ===<br />
<br />
*http://cz2jqg7pj2hqanw7.onion/archlinux<br />
*ftp://mirror:mirror@cz2jqg7pj2hqanw7.onion/archlinux<br />
*http://rstpevyo7zx47bld.onion/archlinux<br />
<br />
=== Austria ===<br />
<br />
*http://gd.tuwien.ac.at/opsys/linux/archlinux/ - ''Vienna University of Technology''<br />
*ftp://gd.tuwien.ac.at/opsys/linux/archlinux/<br />
<br />
=== Bulgaria ===<br />
<br />
*http://mirror.telepoint.bg/archlinux/<br />
*ftp://mirror.telepoint.bg/archlinux/<br />
<br />
=== China ===<br />
<br />
'''Telecom'''<br />
*http://mirror.bit.edu.cn/archlinux/ - ''Beijing Institute of Technology''<br />
*ftp://mirror.bjtu.edu.cn/archlinux/<br />
*rsync://mirror.bjtu.edu.cn/archlinux/<br />
*http://mirrors.aliyun.com/archlinux/ - ''Alibaba''<br />
<br />
'''Unicom'''<br />
*http://mirrors.sohu.com/archlinux/<br />
*http://mirrors.yun-idc.com/archlinux/<br />
<br />
'''Cernet'''<br />
*http://ftp.sjtu.edu.cn/archlinux/ - ''Shanghai Jiaotong University''<br />
*http://mirrors.4.tuna.tsinghua.edu.cn/archlinux/ ''(ipv4 only)''<br />
*http://mirrors.6.tuna.tsinghua.edu.cn/archlinux/ ''(ipv6 only)''<br />
*http://mirror.lzu.edu.cn/archlinux/ - ''Lanzhou University''<br />
<br />
=== France ===<br />
<br />
*http://delta.archlinux.fr/ - ''With Delta package support. Needs xdelta3 package from extra to run.''<br />
*http://mirror.soa1.org/archlinux<br />
*ftp://mirror:mirror@mirror.soa1.org/archlinux<br />
<br />
=== Germany ===<br />
<br />
*http://ftp.uni-erlangen.de/mirrors/archlinux/<br />
*ftp://ftp.uni-erlangen.de/mirrors/archlinux/<br />
*http://ftp.u-tx.net/archlinux/<br />
*ftp://ftp.u-tx.net/archlinux/<br />
*http://mirror.michael-eckert.net/archlinux/<br />
*http://linux.rz.rub.de/archlinux/<br />
*http://mirror.k42.ch/archlinux/<br />
<br />
=== Hong Kong ===<br />
<br />
*http://hk.mirrors.linaxe.net/archlinux/<br />
<br />
=== India ===<br />
<br />
*http://ftp.iitm.ac.in/archlinux/<br />
*ftp://ftp.iitm.ac.in/archlinux/<br />
<br />
=== Indonesia ===<br />
<br />
*http://mirror.kavalinux.com/archlinux/ - ''only from Indonesia''<br />
*http://kambing.ui.ac.id/archlinux/<br />
*http://repo.ukdw.ac.id/archlinux/<br />
<br />
=== Iran ===<br />
<br />
*http://mirror.yazd.ac.ir/arch/<br />
<br />
=== Italy ===<br />
<br />
*http://mi.mirror.garr.it/mirrors/archlinux/<br />
<br />
=== Japan ===<br />
<br />
*http://ftp.nara.wide.ad.jp/pub/Linux/archlinux/ - ''NAra Institute of Science and Technology''<br />
*http://ftp.kddilabs.jp/Linux/packages/archlinux/<br />
*http://srv2.ftp.ne.jp/Linux/packages/archlinux/<br />
<br />
=== Kazakhstan ===<br />
<br />
*http://archlinux.kz/<br />
*http://mirror.neolabs.kz/archlinux/<br />
*http://mirror-kt.neolabs.kz/archlinux/<br />
<br />
=== Malaysia ===<br />
<br />
*http://mirror.oscc.org.my/archlinux/<br />
*http://mirrors.inetutils.net/archlinux/ - ''ISO and Core''<br />
<br />
=== New Zealand ===<br />
<br />
*http://mirror.ihug.co.nz/archlinux/<br />
*http://mirror.ece.auckland.ac.nz/archlinux/ ''NZ only''<br />
<br />
=== Poland ===<br />
<br />
*ftp://ftp.icm.edu.pl/pub/Linux/dist/archlinux/ - ICM UW<br />
*http://ftp.icm.edu.pl/pub/Linux/dist/archlinux/ - ICM UW<br />
*rsync://ftp.icm.edu.pl/pub/Linux/dist/archlinux/ - ICM UW<br />
<br />
=== Russia ===<br />
<br />
*http://hatred.homelinux.net/archlinux/ - ''Vladivostok, without iso, with <sub>[http://hatred.homelinux.net/wiki/proekty:3spy:start 3SPY]</sub> project repos and [http://hatred.homelinux.net/archlinux/mingw32/os/i686 '''mingw32'''] repo''<br />
*http://mirrors.krasinfo.ru/archlinux/ - ''Krasnoyarsk, Classica-Service Ltd''<br />
*http://mirror.yandex.ru/archlinux/ - ''Moscow, [http://www.yandex.ru/ Yandex] LLC''<br />
<br />
=== Singapore ===<br />
<br />
*http://mirror.nus.edu.sg/archlinux/<br />
<br />
=== South Africa ===<br />
<br />
*http://ftp.leg.uct.ac.za/pub/linux/arch/ - ''University of Cape Town''<br />
*ftp://ftp.leg.uct.ac.za/pub/linux/arch/<br />
*http://mirror.ufs.ac.za/archlinux/ - ''University of the Free State''<br />
*ftp://mirror.ufs.ac.za/os/linux/distros/archlinux/<br />
*http://ftp.wa.co.za/pub/archlinux/ - ''Web Africa Networks''<br />
*ftp://ftp.wa.co.za/pub/archlinux/<br />
*http://archlinux.mirror.ac.za - ''TENET - Tertiary Education and Research Network of South Africa''<br />
*ftp://archlinux.mirror.ac.za<br />
<br />
=== South Korea ===<br />
<br />
*http://mirror.star4u.org/archlinux/<br />
*http://ftp2.lecl.net/pub/archlinux<br />
<br />
=== United States ===<br />
<br />
* http://archlinux.linuxfreedom.com - ''Contains numerous ISO images but does not contain the ISO dated 2011.08.19''<br />
* http://mirror.clarkson.edu/archlinux/<br />
* http://mirror.pointysoftware.net/archlinux/<br />
* http://il.mirrors.linaxe.net/archlinux/ - ''Server location - Chicago, IL''<br />
<br />
=== Viet Nam ===<br />
<br />
'''FPT TELECOM'''<br />
*http://mirror-fpt-telecom.fpt.net/archlinux/<br />
<br />
== See also ==<br />
<br />
* [http://wiki.gotux.net/code/bash/mirup MirUp] &ndash; pacman mirrorlist downloader/checker {{Dead link|2015|04|02}}</div>X33ahttps://wiki.archlinux.org/index.php?title=Systemd/Timers&diff=362518Systemd/Timers2015-02-24T06:11:50Z<p>X33a: /* Caveats */ Verbosity isn't the right word to use in this context</p>
<hr />
<div>{{Lowercase title}}<br />
[[Category:Daemons and system services]]<br />
[[Category:Boot process]]<br />
[[fr:Systemd/cron]]<br />
[[ja:Systemd/Timers]]<br />
[[zh-CN:Systemd/Timers]]<br />
{{Related articles start}}<br />
{{Related|systemd}}<br />
{{Related|systemd/User}}<br />
{{Related|systemd/Services}}<br />
{{Related|systemd FAQ}}<br />
{{Related|cron}}<br />
{{Related articles end}}<br />
Timers are [[systemd]] unit files whose name ends in {{ic|.timer}} that control {{ic|.service}} files or events. Timers have the ability to be an alternate to [[cron]] (read [[#As a cron replacement]]). Timers have built-in support for calendar time events, monotonic time events, and have the ability to run asynchronously.<br />
<br />
== Timer units ==<br />
<br />
Timers are ''systemd'' unit files with a suffix of {{ic|.timer}}. Timers are like other [[systemd#Writing unit files|unit configuration files]] and are loaded from the same paths but include a {{ic|[Timer]}} section. The {{ic|[Timer]}} section defines when and how the timer activates. Timers are defined as one of two types:<br />
<br />
* '''Monotonic timers''' activate after a time span relative to a varying starting point. There are number of different monotonic timers but all have the form of: {{ic|1=On''Type''Sec=}}. {{ic|OnBootSec}} and {{ic|OnActiveSec}} are common monotonic timers.<br />
* '''Realtime timers''' (a.k.a. wallclock timers) activate on a calendar event (like cronjobs). The option {{ic|1=OnCalendar=}} is used to define them.<br />
<br />
For a full explanation of timer options, see the {{ic|systemd.timer(5)}} [[man page]]. The argument syntax for calendar events and time spans is defined on the {{ic|systemd.time(7)}} [[man page]].<br />
<br />
== Service unit ==<br />
<br />
For each {{ic|.timer}} file, a matching {{ic|.service}} file exists (e.g. {{ic|foo.timer}} and {{ic|foo.service}}). The {{ic|.timer}} file activates and controls the {{ic|.service}} file. The {{ic|.service}} does not require an {{ic|[Install]}} section as it is the ''timer'' units that are enabled. If necessary, it is possible to control a differently-named unit using the {{ic|1=Unit=}} option in the timer's {{ic|[Timer]}} section.<br />
<br />
== Management ==<br />
<br />
To use a ''timer'' unit [[enable]] and start it like any other unit (remember to add the {{ic|.timer}} suffix). To view all started timers, run:<br />
<br />
{{hc|$ systemctl list-timers|<br />
NEXT LEFT LAST PASSED UNIT ACTIVATES<br />
Thu 2014-07-10 19:37:03 CEST 11h left Wed 2014-07-09 19:37:03 CEST 12h ago systemd-tmpfiles-clean.timer systemd-tmpfiles-clean.service<br />
Fri 2014-07-11 00:00:00 CEST 15h left Thu 2014-07-10 00:00:13 CEST 8h ago logrotate.timer logrotate.service<br />
}}<br />
<br />
{{Note|<br />
* The status of a service started by a timer will likely be inactive unless it is currently being triggered.<br />
* If a timer gets out of sync, it may help to delete its {{ic|stamp-*}} file in {{ic|/var/lib/systemd/timers}}. These are zero length files which mark the last time each timer was run. If deleted, they will be reconstructed on the next start of their timer.}}<br />
<br />
== Example ==<br />
<br />
No changes to service unit files are needed to schedule them with a timer. The following example schedules {{ic|foo.service}} to be run with a corresponding timer called {{ic|foo.timer}}. <br />
<br />
=== Monotonic timer ===<br />
<br />
A timer which will start 15 minutes after boot and again every week while the system is running.<br />
<br />
{{hc|/etc/systemd/system/foo.timer|<nowiki><br />
[Unit]<br />
Description=Run foo weekly and on boot<br />
<br />
[Timer]<br />
OnBootSec=15min<br />
OnUnitActiveSec=1w <br />
<br />
[Install]<br />
WantedBy=timers.target<br />
</nowiki>}}<br />
<br />
=== Realtime timer ===<br />
<br />
A timer which starts once a week (at 12:00am on Monday). It starts immediately if it missed the last start time (option {{ic||1=Persistent=true}}), for example due to the system being powered off: <br />
<br />
{{hc|/etc/systemd/system/foo.timer|<nowiki><br />
[Unit]<br />
Description=Run foo weekly<br />
<br />
[Timer]<br />
OnCalendar=weekly<br />
Persistent=true <br />
<br />
[Install]<br />
WantedBy=timers.target</nowiki>}}<br />
<br />
{{Tip|Special event expressions like {{ic|daily}} and {{ic|weekly}} refer to ''specific start times'' and thus any timers sharing such calendar events will start simultaneously. Timers sharing start events can cause poor system performance if the timers' services compete for system resources. Consider manually staggering such timers using specific events e.g. {{ic|1=OnCalendar=Wed, 23:15}}. See [[#Caveats]].}}<br />
<br />
== As a cron replacement ==<br />
<br />
Although [[cron]] is arguably the most well-known job scheduler, ''systemd'' timers can be an alternative.<br />
<br />
=== Benefits ===<br />
<br />
The main benefits of using timers come from each job having its own ''systemd'' service. Some of these benefits are:<br />
<br />
* Jobs can be easily started independently of their timers. This simplifies debugging.<br />
* Each job can be configured to run in a specific environment (see the {{ic|systemd.exec(5)}} [[man page]]).<br />
* Jobs can be attached to [[cgroups]].<br />
* Jobs can be set up to depend on other ''systemd'' units.<br />
* Jobs are logged in the ''systemd'' journal for easy debugging.<br />
<br />
=== Caveats ===<br />
<br />
Some things that are easy to do with cron are difficult or impossible to do with timer units alone.<br />
<br />
* Complexity: to set up a timed job with ''systemd'' you create two files and run a couple {{ic|systemctl}} commands. Compare that to adding a single line to a crontab. <br />
* Emails: there is no built-in equivalent to cron's {{ic|MAILTO}} for sending emails on job failure. See the next section for an example of setting up an equivalent using {{ic|1=OnFailure=}}.<br />
* Random delay: there is no built-in equivalent to cron's {{ic|RANDOM_DELAY}} for randomly spreading timers out across a given interval (see [https://bugs.freedesktop.org/show_bug.cgi?id=82084 bug report], [https://wiki.archlinux.org/index.php?title=Talk:Systemd/Timers&oldid=356408#Parallelization_section_is_confusing test results]). Services which you do not want to run concurrently must have their timers manually set to minimize overlap.<br />
<br />
:{{note|The {{ic|AccuracySec}} option is '''not''' useful for randomly staggering timers since it "is synchronized between all local timers units" ({{ic|systemd.timer(5)}}). In other words, {{ic|AccuracySec}} shifts all timer activation times by the same amount. For example, all {{ic|1=OnCalendar=daily}} timer units with {{ic|1=AccuracySec=15m}} will trigger the associated services at the same point in time between 00:00 and 00:15.}}<br />
<br />
=== MAILTO ===<br />
<br />
You can set up systemd to send an e-mail when a unit fails - much like Cron does with {{ic|MAILTO}}. First you need two files: an executable for sending the mail and a ''.service'' for starting the executable. For this example, the executable is just a shell script using {{ic|sendmail}}:<br />
<br />
{{hc|/usr/local/bin/systemd-email|<nowiki>#!/bin/bash<br />
<br />
/usr/bin/sendmail -t <<ERRMAIL<br />
To: $1<br />
From: systemd <root@$HOSTNAME><br />
Subject: $2<br />
Content-Transfer-Encoding: 8bit<br />
Content-Type: text/plain; charset=UTF-8<br />
<br />
$(systemctl status --full "$2")<br />
ERRMAIL</nowiki>}}<br />
<br />
Whatever executable you use, it should probably take at least two arguments as this shell script does: the address to send to and the unit file to get the status of. The ''.service'' we create will pass these arguments:<br />
<br />
{{hc|/etc/systemd/system/status-email-user1@.service|<nowiki>[Unit]<br />
Description=status email for %I to user1<br />
<br />
[Service]<br />
Type=oneshot<br />
ExecStart=/usr/local/bin/systemd-email user1@mailhost %i<br />
User=nobody<br />
Group=systemd-journal<br />
</nowiki>}}<br />
<br />
First notice that the unit to send email about is an instance parameter, so this one service can be used to send email for many other units. However the recipient is hard-coded (since unit templates can only take a single parameter) so you will need to create multiple services if you want to send emails to different sets of recipients. At this point you should test the service to verify that you can receive the emails:<br />
<br />
{{bc|# systemctl start status-email-user1@dbus.service}}<br />
<br />
Then simply add {{ic|1=OnFailure=status-email-user1@%n.service}} to the {{ic|[Unit]}} section of any unit you want emails for. {{ic|%n}} passes the unit's name to the template.<br />
<br />
=== Using a crontab ===<br />
<br />
Several of the caveats can be worked around by installing a package that parses a traditional crontab to configure the timers. {{aur|systemd-crontab-generator}} and {{aur|systemd-cron}} from the [[AUR]] are two such packages. These can provide the missing {{ic|MAILTO}} and {{ic|RANDOM_DELAY}} features.<br />
<br />
If you like crontabs just because they provide a unified view of all scheduled jobs, {{ic|systemctl}} can provide this. See [[#Management]].<br />
<br />
== See also ==<br />
<br />
* [http://www.freedesktop.org/software/systemd/man/systemd.timer.html systemd.timer man page] on freedesktop.org<br />
* [https://fedoraproject.org/wiki/Features/SystemdCalendarTimers Fedora Project wiki page] on ''systemd'' calendar timers<br />
* [https://wiki.gentoo.org/wiki/Systemd#Timer_services Gentoo wiki section] on ''systemd'' timer services<br />
* {{App|systemd-crontab-generator|tool to generate timers/services from crontab and anacrontab files|https://github.com/kstep/systemd-crontab-generator|{{Aur|systemd-crontab-generator}}}}<br />
* {{App|systemd-cron|provides systemd units to run cron scripts; using ''systemd-crontab-generator'' to convert crontabs|https://github.com/systemd-cron/systemd-cron|{{Aur|systemd-cron}}}}</div>X33ahttps://wiki.archlinux.org/index.php?title=Reset_lost_root_password&diff=360529Reset lost root password2015-02-13T06:54:50Z<p>X33a: </p>
<hr />
<div>[[Category:System recovery]]<br />
[[Category:Security]]<br />
[[ar:Password Recovery]]<br />
[[it:Password Recovery]]<br />
[[ja:Password Recovery]]<br />
[[ru:Password Recovery]]<br />
[[zh-cn:Password Recovery]]<br />
This guide will show you how to reset a forgotten root password. Several methods are listed to help you accomplish this.<br />
<br />
{{Warning|An attacker could use the methods mentioned below to break into your system. No matter how secure the operating system is or how good passwords are, having physical access amounts to loading an alternate OS and exposing your data, unless you use [[Disk encryption|disk encryption]].}}<br />
<br />
== Using a LiveCD ==<br />
<br />
With a LiveCD a couple methods are available: change root and use the {{Ic|passwd}} command, or erase the password field entry directly editing the password file. Any Linux capable LiveCD can be used, albeit to change root it must match your installed architecture type. Here we only describe how to reset your password with chroot, since manual editing the password file is significantly more risky.<br />
<br />
=== Change root ===<br />
<br />
# Boot the LiveCD and [[mount]] the root partition of your main system.<br />
# Enter the [[chroot]] session.<br />
# Use the {{ic|passwd}} command to set the new password (you won't be prompted for an old one).<br />
# Exit chroot session.<br />
# Unmount the root partition.<br />
# Reboot, and enter your new password. If you can't remember it, go to step 1.<br />
<br />
== Using GRUB to invoke bash ==<br />
<br />
# Select the appropriate boot entry in the GRUB menu and press {{ic|e}} to edit the line.<br />
# Select the kernel line and press {{ic|e}} again to edit it.<br />
# Append {{Ic|1=init=/bin/bash}} at the end of line.<br />
# Press {{ic|b}} to boot (this change is only temporary and will not be saved to your menu.lst). After booting you will be at the bash prompt.<br />
# Your root file system is mounted as readonly now, so remount it as read/write {{ic|mount -n -o remount,rw /}}.<br />
# Use the {{ic|passwd}} command to create a new root password.<br />
# Reboot and do not lose your password again!<br />
<br />
{{Note|Some keyboards may not be loaded properly by the init system with this method and you will not be able to type anything at the bash prompt. If this is the case, you will have to use another method.}}<br />
<br />
== See also ==<br />
<br />
* [http://www.howtoforge.com/how-to-reset-a-forgotten-root-password-with-knoppix-p2 this guide] for an example.</div>X33ahttps://wiki.archlinux.org/index.php?title=Btrfs&diff=353563Btrfs2014-12-27T09:57:46Z<p>X33a: /* Copy-On-Write (CoW) */ fix double usage of word</p>
<hr />
<div>[[Category:File systems]]<br />
[[ja:Btrfs]]<br />
[[zh-CN:Btrfs]]<br />
{{Related articles start}}<br />
{{Related|File systems}}<br />
{{Related|Btrfs - Tips and tricks}}<br />
{{Related|Mkinitcpio-btrfs}}<br />
{{Related articles end}}<br />
<br />
From [[Wikipedia:Btrfs]]<br />
<br />
:''Btrfs (B-tree file system, variously pronounced: "Butter F S", "Better F S", "B-tree F S", or simply "Bee Tee Arr Eff Ess") is a GPL-licensed experimental copy-on-write file system for Linux. Development began at Oracle Corporation in 2007.''<br />
<br />
From [https://btrfs.wiki.kernel.org/index.php/Main_Page Btrfs Wiki]<br />
<br />
:''Btrfs is a new copy on write (CoW) filesystem for Linux aimed at implementing advanced features while focusing on fault tolerance, repair and easy administration. Jointly developed at Oracle, Red Hat, Fujitsu, Intel, SUSE, STRATO and many others, Btrfs is licensed under the GPL and open for contribution from anyone.''<br />
<br />
{{Warning|<br />
* Btrfs has some features that are considered experimental. See the Btrfs Wiki's [https://btrfs.wiki.kernel.org/index.php/Main_Page#Stability_status Stability status,] [https://btrfs.wiki.kernel.org/index.php/FAQ#Is_btrfs_stable.3F Is Btrfs stable,] and [https://btrfs.wiki.kernel.org/index.php/Getting_started Getting started] for more detailed information.<br />
* Beware of the [[#Limitations|limitations]].<br />
}}<br />
<br />
== Installation ==<br />
<br />
Btrfs is included in the default kernel and its tools ({{Pkg|btrfs-progs}}) are available in the official repositories. [[GRUB]], [[mkinitcpio]], and [[Syslinux]] have support for Btrfs and require no additional configuration.<br />
<br />
=== Additional packages ===<br />
<br />
* {{Pkg|btrfs-progs}} includes ''btrfsck'', a tool that can fix errors on Btrfs filesystems.<br />
* {{AUR|mkinitcpio-btrfs}} enables roll-back abilities.<br />
* {{AUR|btrfs-progs-git}} for nightly<br />
<br />
{{Tip|See [https://btrfs.wiki.kernel.org/index.php/Getting_started Btrfs Wiki Getting Started] for suggestions regarding running Btrfs effectively.}}<br />
<br />
== General administration of Btrfs ==<br />
<br />
=== Creating a new file system ===<br />
<br />
A Btrfs file system can either be newly created or have one converted.<br />
<br />
To format a partition do:<br />
<br />
# mkfs.btrfs -L ''mylabel'' /dev/''partition''<br />
<br />
{{Note|1=As of [https://git.kernel.org/cgit/linux/kernel/git/mason/btrfs-progs.git/commit/?id=c652e4efb8e2dd76ef1627d8cd649c6af5905902 this] commit (November 2013), Btrfs default blocksize is 16KB.}}<br />
<br />
To use a larger blocksize for data/meta data, specify a value for the leafsize via the {{ic|-l}} switch as shown in this example using 16KB blocks:<br />
<br />
# mkfs.btrfs -L ''mylabel'' -l 16k /dev/''partition''<br />
<br />
Multiple devices can be entered to create a RAID. Supported RAID levels include RAID 0, RAID 1, RAID 10, RAID 5 and RAID 6. By default the metadata is mirrored and data is striped. See [https://btrfs.wiki.kernel.org/index.php/Using_Btrfs_with_Multiple_Devices Using Btrfs with Multiple Devices] for more information about how to create a Btrfs RAID volume.<br />
<br />
# mkfs.btrfs [''options''] /dev/''part1'' /dev/''part2''<br />
<br />
=== Convert from Ext3/4 ===<br />
<br />
Boot from an install CD, then convert by doing:<br />
<br />
# btrfs-convert /dev/''partition''<br />
<br />
Mount the partion and test the conversion by checking the files. Be sure to change the {{ic|/etc/fstab}} to reflect the change ('''type''' to {{ic|btrfs}} and '''fs_passno''' [the last field] to {{ic|0}} as Btrfs does not do a file system check on boot). Also note that the UUID of the partition will have changed, so update fstab accordingly when using UUIDs. {{ic|chroot}} into the system and rebuild the GRUB menu list (see [[Install from Existing Linux]] and [[GRUB]] articles). If converting a root filesystem, while still chrooted run {{ic|mkinitcpio -p linux}} to regenerate the initramfs or the system will not successfully boot.<br />
<br />
To complete, delete the sub-volume saved image is on, and finally [[#Balance|balance]] the file system to reclaim the space.<br />
<br />
# btrfs subvolume delete /ext2_saved<br />
<br />
=== Mount options ===<br />
<br />
{{Warning|Specific mount options can disable safety features and increase the risk of complete file system corruption.}}<br />
<br />
See [https://btrfs.wiki.kernel.org/index.php/Mount_options Btrfs Wiki Mount options] and [https://btrfs.wiki.kernel.org/index.php/Gotchas Btrfs Wiki Gotchas] for more information.<br />
<br />
In addition to configurations that can be made during or after file system creation, the various mount options for Btrfs can drastically change its performance characteristics.<br />
<br />
As this is a file system that is still in active development. Changes and regressions should be expected. See links in the [[#See also]] section for some benchmarks.<br />
<br />
==== Examples ====<br />
<br />
* '''Linux 3.15'''<br />
** Btrfs on a SSD for system installation and an emphasis on maximizing performance.<br />
*:{{bc|1=noatime,discard,ssd,autodefrag,compress=lzo,space_cache}}<br />
** Btrfs on a HDD for archival purposes with an emphasis on maximizing space.<br />
*: {{bc|1=noatime,autodefrag,compress-force=lzo,space_cache}}<br />
<br />
=== Displaying used/free space ===<br />
<br />
General linux userspace tools such as {{ic|/usr/bin/df}} will inaccurately report free space on a Btrfs partition since it does not take into account space allocated for and used by the metadata. It is recommended to use {{ic|/usr/bin/btrfs}} to query a btrfs partition. Below is an illustration of this effect, first querying using {{ic|df -h}}, and then using {{ic|btrfs filesystem df}}:<br />
<br />
{{hc|$ df -h /|<br />
Filesystem Size Used Avail Use% Mounted on<br />
/dev/sda3 119G 3.0G 116G 3% /<br />
}}<br />
<br />
{{hc|$ btrfs filesystem df /|2=<br />
Data: total=3.01GB, used=2.73GB<br />
System: total=4.00MB, used=16.00KB<br />
Metadata: total=1.01GB, used=181.83MB<br />
}}<br />
<br />
Notice that {{ic|df -h}} reports 3.0GB used but {{ic|btrfs filesystem df}} reports 2.73GB for the data. This is due to the way Btrfs allocates space into the pool. The true disk usage is the sum of all three 'used' values which is inferior to 3.0GB as reported by {{ic|df -h}}.<br />
<br />
{{Note|1=If you see an entry of type {{ic|unknown}} in the output of {{ic|btrfs filesystem df}} at kernel >= 3.15, this is a display bug. As of [http://thread.gmane.org/gmane.comp.file-systems.btrfs/34419 this patch], the entry means GlobalReserve, which is kind of a buffer for changes not yet flushed. This entry is displayed as {{ic|unknown, single}} in RAID setups and is not possible to re-balance.}}<br />
<br />
Another useful command to show a less verbose readout of used space is {{ic|btrfs filesystem show}}:<br />
<br />
{{hc|# btrfs filesystem show /dev/sda3|<br />
failed to open /dev/sr0: No medium found<br />
Label: 'arch64' uuid: 02ad2ea2-be12-2233-8765-9e0a48e9303a<br />
Total devices 1 FS bytes used 2.91GB<br />
devid 1 size 118.95GB used 4.02GB path /dev/sda2<br />
<br />
Btrfs v0.20-rc1-358-g194aa4a-dirty<br />
}}<br />
<br />
== Limitations ==<br />
<br />
A few limitations should be known before trying.<br />
<br />
=== Encryption ===<br />
<br />
Btrfs has no built-in encryption support (this may come in future); users can encrypt the partition before running {{ic|mkfs.btrfs}}. See [[dm-crypt]]. <br />
<br />
Existing Btrfs file system, can use something like [[EncFS]] or [[TrueCrypt]], though perhaps without some of Btrfs' features.<br />
<br />
=== Swap file ===<br />
<br />
Btrfs does not support [[Swap#Swap_file|swap files]]. This is due to swap files requiring a function that Btrfs doesn't have for possibility of file system corruption [https://btrfs.wiki.kernel.org/index.php/FAQ#Does_btrfs_support_swap_files.3F]. A swap file can be mounted on a loop device with poorer performance but will not be able to hibernate. Install the package {{Pkg|systemd-swap}} from the [[official repositories]] to automate this.<br />
<br />
=== Linux-rt kernel ===<br />
<br />
As of version 3.14.12_rt9, the [[Kernel#-rt|linux-rt]] kernel does not boot with the Btrfs file system. This is due to the slow development of the ''rt'' patchset.<br />
<br />
== Features ==<br />
<br />
Various features are available and can be adjusted.<br />
<br />
=== Copy-On-Write (CoW) ===<br />
<br />
The resolution at which data are written to the filesystem is dictated by Btrfs itself and by system-wide settings. Btrfs defaults to a 30 seconds checkpoint interval in which new data are committed to the filesystem. This is tuneable using mount options (see below)<br />
<br />
System-wide settings also affect commit intervals. They include the files under {{ic|/proc/sys/vm/*}} and are out-of-scope of this wiki article. The kernel documentation for them resides in {{ic|Documentation/sysctl/vm.txt}}.<br />
<br />
CoW comes with some advantages, but can negatively affect performance with large files that have small random writes. It is recommended to disable CoW for database files and virtual machine images. <br />
<br />
One can disable CoW for the entire block device by mounting it with {{ic|nodatacow}} option. However, this will disable CoW for the entire file system.<br />
<br />
{{Note|{{ic|nodatacow}} will only affect newly created file. CoW may still happen for existing file.}}<br />
<br />
To disable CoW for single files/directories do:<br />
<br />
$ chattr +C ''/dir/file''<br />
<br />
{{Note|From chattr man page: For btrfs, the 'C' flag should be set on new or empty files. If it is set on a file which already has data blocks, it is undefined when the blocks assigned to the file will be fully stable. If the 'C' flag is set on a directory, it will have no effect on the directory, but new files created in that directory will have the No_COW attribute.}}<br />
<br />
{{Tip|In accordance with the note above, you can use the following trick to disable CoW on existing files in a directory:<br />
$ mv ''/path/to/dir'' ''/path/to/dir''_old<br />
$ mkdir ''/path/to/dir''<br />
$ chattr +C ''/path/to/dir''<br />
$ cp -a ''/path/to/dir''_old/* ''/path/to/dir''<br />
$ rm -rf ''/path/to/dir''_old<br />
Make sure that the data are not used during this process. Also note that {{ic|mv}} or {{ic|cp --reflink}} as described below will not work.<br />
}}<br />
<br />
Likewise, to save space by forcing CoW when copying files use:<br />
<br />
$ cp --reflink ''source'' ''dest'' <br />
<br />
As {{ic|''dest''}} file is changed, only those blocks that are changed from source will be written to the disk. One might consider aliasing ''cp'' to {{ic|1=cp --reflink=auto}}.<br />
<br />
=== Multi-device filesystem and RAID feature ===<br />
<br />
See [https://btrfs.wiki.kernel.org/index.php/Using_Btrfs_with_Multiple_Devices Using Btrfs with Multiple Devices] for suggestions.<br />
<br />
==== Multi-device filesystem ====<br />
<br />
When creating a ''btrfs'' filesystem, one can pass many partitions or disk devices to ''mkfs.btrfs''. The filesystem will be created across these devices. One can '''"'''pool'''"''' this way, multiple partitions or devices to get a big ''btrfs'' filesystem.<br />
<br />
One can also add or remove device from an existing btrfs filesystem (caution is mandatory).<br />
<br />
==== RAID features ====<br />
<br />
{{Warning|Parity RAID (RAID 5 and RAID 6) are not currently complete, and have significant problems with recovery from the loss of a device. They should not be used for anything other than testing purposes.}}<br />
<br />
When creating multi-device filesystem, one can also specify to use RAID0, RAID1, RAID10, RAID5 or RAID6 across the devices comprising the filesystem. RAID levels can be applied independently to data and meta data. By default, meta data is duplicated on single volumes or RAID1 on multi-disk sets.<br />
<br />
btrfs works in block-pairs for raid0, raid1, and raid10. This means:<br />
<br />
raid0 - block-pair striped across 2 devices<br />
<br />
raid1 - block-pair written to 2 devices<br />
<br />
The raid level can be changed while the disks are online using the {{ic|btrfs balance}} command:<br />
<br />
# btrfs balance -m convert=RAIDLEVEL -d convert=RAIDLEVEL /path/to/mount<br />
<br />
For 2 disk sets, this matches raid levels as defined in md-raid (mdadm). For 3+ disk-sets, the result is entirely different than md-raid. <br />
<br />
For example:<br />
* Three 1TB disks in an md based raid1 yields a {{ic|/dev/md0}} with 1TB free space and the ability to safely lose 2 disks without losing data.<br />
* Three 1TB disks in a Btrfs volume with data=raid1 will allow the storage of approximately 1.5TB of data before reporting full. Only 1 disk can safely be lost without losing data.<br />
<br />
Btrfs uses a round-robin scheme to decide how block-pairs are spread among disks. As of Linux 3.0, a quasi-round-robin scheme is used which prefers larger disks when distributing block pairs. This allows raid0 and raid1 to take advantage of most (and sometimes all) space in a disk set made of multiple disks. For example, a set consisting of a 1TB disk and 2 500GB disks with data=raid1 will place a copy of every block on the 1TB disk and alternate (round-robin) placing blocks on each of the 500GB disks. Full space utilization will be made. A set made from a 1TB disk, a 750GB disk, and a 500GB disk will work the same, but the filesystem will report full with 250GB unusable on the 750GB disk. To always take advantage of the full space (even in the last example), use data=single. (data=single is akin to JBOD defined by some raid controllers) See [https://btrfs.wiki.kernel.org/index.php/FAQ#How_much_space_do_I_get_with_unequal_devices_in_RAID-1_mode.3F the BTRFS FAQ] for more info.<br />
<br />
=== Sub-volumes ===<br />
<br />
See the following links for more details:<br />
* [https://btrfs.wiki.kernel.org/index.php/SysadminGuide#Subvolumes Btrfs Wiki SysadminGuide#Subvolumes]<br />
* [https://btrfs.wiki.kernel.org/index.php/Getting_started#Basic_Filesystem_Commands Btrfs Wiki Getting started#Basic Filessystem Commands]<br />
* [https://btrfs.wiki.kernel.org/index.php/Trees Btrfs Wiki Trees] <br />
<br />
==== Creating sub-volumes ====<br />
<br />
To create a sub-volume:<br />
<br />
# btrfs subvolume create ''subvolume-name''<br />
<br />
==== Listing sub-volumes ====<br />
<br />
To see a list of current sub-volumes:<br />
<br />
# btrfs subvolume list -p .<br />
<br />
==== Setting a default sub-volume ====<br />
<br />
{{Warning|Changing the default subvolume with btrfs subvolume default will make the top level of the filesystem inaccessible, except by use of the {{ic|1=subvolid=0}} mount option. Reference: [https://btrfs.wiki.kernel.org/index.php/SysadminGuide Btrfs Wiki Sysadmin Guide].}}<br />
<br />
The default sub-volume is mounted if no {{ic|1=subvol=}} mount option is provided.<br />
<br />
# btrfs subvolume set-default ''subvolume-id'' /.<br />
<br />
'''Example:'''<br />
<br />
{{hc|# btrfs subvolume list .|<br />
ID 258 gen 9512 top level 5 path root_subvolume<br />
ID 259 gen 9512 top level 258 path home<br />
ID 260 gen 9512 top level 258 path var<br />
ID 261 gen 9512 top level 258 path usr<br />
}}<br />
<br />
# btrfs subvolume set-default 258 .<br />
<br />
'''Reset:'''<br />
<br />
# btrfs subvolume set-default 0 .<br />
<br />
==== Snapshots ====<br />
<br />
See [https://btrfs.wiki.kernel.org/index.php/SysadminGuide#Snapshots Btrfs Wiki SysadminGuide#Snapshots] for details.<br />
<br />
To create a snapshot:<br />
<br />
# btrfs subvolume snapshot ''source'' [''dest''/]''name''<br />
<br />
Snapshots are not recursive. Every sub-volume inside sub-volume will be an empty directory inside the snapshot.<br />
<br />
==== Installing with root on btrfs subvolume ====<br />
<br />
{{Moveto||Does not fit into [[#Features]] section, maybe we should start new one...}}<br />
<br />
{{Accuracy|Setting {{ic|rootvol}} as the default subvolume (see [[#Setting a default sub-volume]]) would be much simpler, for both installation and booting.}}<br />
<br />
{{Warning|When using legacy BIOS booting, syslinux is not capable of booting from a btrfs subvolume with the following setup, one must always use GRUB. (It is possible with a different, more complicated btrfs subvolume setup, that is out of the scope of this section.)}}<br />
<br />
For increased flexibility, install the system into a dedicated sub-volume.<br />
Set up a btrfs filesystem as to your liking and mount it to /mnt. The following mkfs command is given as an example.<br />
<br />
# mkfs.btrfs /dev/sda1 <br />
# mount /dev/sda1 /mnt<br />
<br />
Create a subvolume for root, where rootvol is an arbitrary name. If you wish, create additional subvolumes at this step, for example to accommodate /home.<br />
<br />
# cd /mnt<br />
# btrfs subvolume create rootvol<br />
# cd /<br />
# umount /mnt<br />
<br />
Mount the subvolume.<br />
<br />
# mount -o subvol=rootvol /dev/sda1 /mnt<br />
<br />
From here continue the installation process from the pacstrap step, as per the [[Installation guide]] or [[Beginners' guide]].<br />
<br />
Additional considerations:<br />
* In /etc/fstab, the mount option subvol="subvolume-name" has to be specified, and the fsck setting in the last field has to be 0.<br />
* In the kernel boot parameters, use: {{ic|1=rootflags=subvol=''subvolume-name''}}. It is still necessary to add the standard root parameter with {{ic| 1=root=/dev/sda1}}.<br />
* It is advisable to add '''crc32c''' (or '''crc32c-intel''' for Intel machines) to the modules array in {{ic|/etc/mkinitcpio.conf}}<br />
<br />
{{Note|Child sub-volumes are automatically mounted by Btrfs when the parent sub-volume is mounted.}}<br />
<br />
=== Defragmentation ===<br />
<br />
Btrfs supports online defragmentation. To defragment the metadata of the root folder do:<br />
<br />
# btrfs filesystem defragment /<br />
<br />
This ''will not'' defragment the entire file system. For more information read [https://btrfs.wiki.kernel.org/index.php/Problem_FAQ#Defragmenting_a_directory_doesn.27t_work this page] on the btrfs wiki.<br />
<br />
To defragment the entire file system verbosely:<br />
<br />
# btrfs filesystem defragment -r -v /<br />
<br />
{{Note|The command above will defragment only file data. To defragment directory metadata for every directory in the file system, run this command: {{bc|# find / -xdev -type d -print -exec btrfs filesystem defragment '{}' \;}}}}<br />
<br />
=== Compression ===<br />
<br />
Btrfs supports transparent compression, which means every file on the partition is automatically compressed. This not only reduces the size of those files, but also [http://www.phoronix.com/scan.php?page=article&item=btrfs_compress_2635&num=1 improves performance], in particular if using the [http://www.phoronix.com/scan.php?page=article&item=btrfs_lzo_2638&num=1 lzo algorithm], in some specific use cases (e.g. single thread with heavy file IO), while obviously harming performance on other cases (e.g. multithreaded and/or cpu intensive tasks with large file IO).<br />
<br />
Compression is enabled using the {{ic|1=compress=zlib}} or {{ic|1=compress=lzo}} mount options. Only files created or modified after the mount option is added will be compressed. However, it can be applied quite easily to existing files (e.g. after a conversion from ext3/4) using the {{ic|btrfs filesystem defragment -c''alg''}} command, where {{ic|''alg''}} is either {{ic|zlib}} or {{ic|lzo}}. In order to re-compress the whole file system with {{ic|lzo}}, run the following command:<br />
<br />
# btrfs filesystem defragment -r -v -clzo /<br />
<br />
{{Tip|Compression can also be enabled per-file without using the {{ic|compress}} mount option; simply apply {{ic|chattr +c}} to the file. When applied to directories, it will cause new files to be automatically compressed as they come.}}<br />
<br />
When installing Arch to an empty Btrfs partition, set the {{ic|compress}} option after [[Beginners' guide#Prepare_the_storage_drive|preparing the storage drive]]. Simply switch to another terminal ({{ic|Ctrl+Alt+''number''}}), and run the following command:<br />
<br />
# mount -o remount,compress=lzo /mnt/target<br />
<br />
After the installation is finished, add {{ic|1=compress=lzo}} to the mount options of the root file system in [[fstab]].<br />
<br />
=== Checkpoint interval ===<br />
<br />
Starting with Linux 3.12, users are able to change the checkpoint interval from the default 30 s to any value by appending the {{ic|commit}} mount option in {{ic|/etc/fstab}} for the btrfs partition.<br />
<br />
LABEL=arch64 / btrfs defaults,noatime,ssd,compress=lzo,commit=120 0 0<br />
<br />
=== Partitioning ===<br />
<br />
Btrfs can occupy an entire data storage device and replace the [[MBR]] or [[GPT]] partitioning schemes. One can use [[Btrfs#Sub-volumes|subvolumes]] to simulate partitions. There are some limitations to this approach in single disk setups:<br />
<br />
* Cannot use different [[File systems|file systems]] for different [[fstab|mount points]].<br />
* Cannot use [[Swap|swap area]] as Btrfs does not support [[Swap#Swap_file|swap files]] and there is no place to create [[Swap#Swap_partition|swap partition]].<br />
* Cannot use [[UEFI]] to boot.<br />
<br />
To overwrite the existing partition table with Btrfs, run the following command:<br />
<br />
# mkfs.btrfs /dev/sd''X''<br />
<br />
Do not specify {{ic|/dev/sda''X''}} or it will format an existing partition instead of replacing the entire partitioning scheme.<br />
<br />
Install the [[Bootloaders|boot loader]] in a like fashion to installing it for a data storage device with a [[MBR|Master Boot Record]]. For example:<br />
<br />
# grub-install --recheck /dev/sd''X''<br />
<br />
for [[Grub#Install_to_440-byte_MBR_boot_code_region|GRUB]].<br />
<br />
{{Warning|Using the {{ic|btrfs filesystem set-default}} command to change the default sub-volume from anything other than the top level (ID 0) may break Grub. See [[Btrfs#Setting a default sub-volume]] to reset.}}<br />
<br />
=== Scrub ===<br />
<br />
See [https://btrfs.wiki.kernel.org/index.php/Glossary Btrfs Wiki Glossary].<br />
<br />
# btrfs scrub start /<br />
# btrfs scrub status /<br />
<br />
{{Warning|The running scrub process will prevent the system from suspending, see [http://comments.gmane.org/gmane.comp.file-systems.btrfs/33106 this thread] for details.}}<br />
<br />
If running the scrub as a systemd service, use {{ic|1=Type=forking}}. Alternatively, you can pass the "-B" flag to btrfs scrub start to run it in the foreground and use the default Type value.<br />
<br />
=== Balance ===<br />
<br />
See [https://btrfs.wiki.kernel.org/index.php/FAQ#What_does_.22balance.22_do.3F Upstream FAQ page].<br />
<br />
Since {{Pkg|btrfs-progs}}-3.12 ''balancing'' is a background process - see {{ic|man 8 btrfs}} for full description.<br />
<br />
# btrfs balance start /<br />
# btrfs balance status /<br />
<br />
== Troubleshooting ==<br />
<br />
=== GRUB ===<br />
<br />
==== Partition offset ====<br />
<br />
{{Note|1=The offset problem may happen when you try to embed {{ic|core.img}} into a partitioned disk. It means that [https://wiki.archlinux.org/index.php?title=Talk:Btrfs&diff=319474&oldid=292530 it is OK] to embed grub's {{ic|corg.img}} into a Btrfs pool on a partitionless disk (e.g. {{ic|/dev/sd''X''}}) directly.}}<br />
<br />
[[GRUB]] can boot Btrfs partitions however the module may be larger than other [[file systems]]. And the {{ic|core.img}} file made by {{ic|grub-install}} may not fit in the first 63 sectors (31.5KiB) of the drive between the MBR and the first partition. Up-to-date partitioning tools such as {{ic|fdisk}} and {{ic|gdisk}} avoid this issue by offsetting the first partition by roughly 1MiB or 2MiB.<br />
<br />
==== Missing root ====<br />
<br />
Users experiencing the following: {{ic|1=error no such device: root}} when booting from a RAID style setup then edit /usr/share/grub/grub-mkconfig_lib and remove both quotes from the line {{ic|1=echo " search --no-floppy --fs-uuid --set=root ${hints} ${fs_uuid}"}}. Regenerate the config for grub and the system should boot without an error.<br />
<br />
=== BTRFS: open_ctree failed ===<br />
<br />
As of November 2014 there seems to be a bug in [[systemd]] or [[mkinitcpio]] causing the following error on systems with multi-device Btrfs filesystem using the {{ic|btrfs}} hook in {{ic|mkinitcpio.conf}}:<br />
<br />
{{bc|<nowiki><br />
BTRFS: open_ctree failed<br />
mount: wrong fs type, bad option, bad superblock on /dev/sdb2, missing codepage or helper program, or other error<br />
<br />
In some cases useful info is found in syslog - try dmesg|tail or so.<br />
<br />
You are now being dropped into an emergency shell.<br />
</nowiki>}}<br />
<br />
A workaround is to remove {{ic|btrfs}} from the {{ic|HOOKS}} array in {{ic|/etc/mkinitcpio.conf}} and instead adding {{ic|btrfs}} to the {{ic|MODULES}} array. Then regenerate the initramfs with {{ic|mkinitcpio -p linux}} (adjust the preset if needed) and reboot.<br />
<br />
See the [https://bbs.archlinux.org/viewtopic.php?id=189845 original forums thread] and {{Bug|42884}} for further information and discussion.<br />
<br />
== See also ==<br />
<br />
* '''Official site'''<br />
** [https://btrfs.wiki.kernel.org/ Btrfs Wiki]<br />
** [https://btrfs.wiki.kernel.org/index.php/Glossary Btrfs Wiki Glossary]<br />
* '''Official FAQs'''<br />
** [https://btrfs.wiki.kernel.org/index.php/FAQ Btrfs Wiki FAQ]<br />
** [https://btrfs.wiki.kernel.org/index.php/Problem_FAQ Btrfs Wiki Problem FAQ]<br />
* '''Btrfs pull requests'''<br />
** [http://lkml.indiana.edu/hypermail/linux/kernel/1401.3/03045.html 3.14]<br />
** [http://lkml.indiana.edu/hypermail/linux/kernel/1311.1/03526.html 3.13]<br />
** [http://lkml.indiana.edu/hypermail/linux/kernel/1309.1/02981.html 3.12]<br />
** [http://lkml.indiana.edu/hypermail/linux/kernel/1305.1/01064.html 3.11]<br />
* '''Performance related'''<br />
** [http://superuser.com/questions/432188/should-i-put-my-multi-device-btrfs-filesystem-on-disk-partitions-or-raw-devices Btrfs on raw disks?]<br />
** [http://comments.gmane.org/gmane.comp.file-systems.btrfs/19440 Varying leafsize and nodesize in Btrfs]<br />
** [http://comments.gmane.org/gmane.comp.file-systems.btrfs/15646 Btrfs support for efficient SSD operation (data blocks alignment)]<br />
** [https://btrfs.wiki.kernel.org/index.php/FAQ#Is_Btrfs_optimized_for_SSD.3F Is Btrfs optimized for SSDs?]<br />
** '''Phoronix mount option benchmarking'''<br />
*** [http://www.phoronix.com/scan.php?page=article&item=linux_314_btrfs Linux 3.14]<br />
*** [http://www.phoronix.com/scan.php?page=article&item=linux_btrfs_311&num=1 Linux 3.11]<br />
*** [http://www.phoronix.com/scan.php?page=news_item&px=MTM0OTU Linux 3.9]<br />
*** [http://www.phoronix.com/scan.php?page=article&item=btrfs_linux37_mounts&num=1 Linux 3.7]<br />
*** [http://www.phoronix.com/scan.php?page=article&item=linux_btrfs_options&num=1 Linux 3.2]<br />
** [http://blog.erdemagaoglu.com/post/4605524309/lzo-vs-snappy-vs-lzf-vs-zlib-a-comparison-of Lzo vs. zLib]<br />
* '''Miscellaneous'''<br />
** [http://www.funtoo.org/wiki/BTRFS_Fun Funtoo Wiki Btrfs Fun]<br />
** [http://www.phoronix.com/scan.php?page=news_item&px=MTA0ODU Avi Miller presenting Btrfs] at SCALE 10x, January 2012.<br />
** [http://www.phoronix.com/scan.php?page=news_item&px=MTA4Mzc Summary of Chris Mason's talk] from LFCS 2012<br />
** [http://git.kernel.org/?p&#61;linux/kernel/git/torvalds/linux-2.6.git;a&#61;commit;h&#61;35054394c4b3cecd52577c2662c84da1f3e73525 Btrfs: stop providing a bmap operation to avoid swapfile corruptions] 2009-01-21<br />
** [http://marc.merlins.org/perso/btrfs/post_2014-03-22_Btrfs-Tips_-Doing-Fast-Incremental-Backups-With-Btrfs-Send-and-Receive.html Doing Fast Incremental Backups With Btrfs Send and Receive]</div>X33ahttps://wiki.archlinux.org/index.php?title=Media_Transfer_Protocol&diff=344583Media Transfer Protocol2014-11-14T10:26:49Z<p>X33a: /* Microsoft Windows on VirtualBox */ remove superfluous link</p>
<hr />
<div>[[Category:Sound]]<br />
[[ja:MTP]]<br />
[[zh-CN:MTP]]<br />
[[Wikipedia:MTP|MTP]], or the ''Media Transfer Protocol'', is a USB device class which is used by many mobile phones (e.g. Android 3+ devices) and media players (e.g. Creative Zen).<br />
<br />
== Installation ==<br />
<br />
MTP support is provided by [http://libmtp.sourceforge.net/ libmtp], [[pacman|installable]] with the {{Pkg|libmtp}} package from the [[official repositories]].<br />
<br />
To view the contents of your Android device's storage via MTP in your file manager, install the corresponding plugin:<br />
<br />
* For file managers that use [[GVFS]] ([[GNOME Files]], Xfce's [[Thunar]]), install {{Pkg|gvfs-mtp}} for MTP or {{Pkg|gvfs-gphoto2}} for PTP support.<br />
* For file managers that use KIO (KDE's Dolphin), install {{Pkg|kio-mtp}} (PTP support is included by default).<br />
<br />
After installing the required package, your device should show up in your file manager automatically, and can be accessed via an URL such as {{ic|mtp://[usb:002,013]/}}.<br />
<br />
{{Note|If you have a newer Android device that does not support UMS (USB Mass Storage) and you find {{Pkg|mtpfs}} extremely slow or not working properly, you can install {{AUR|jmtpfs}} from the AUR.}}<br />
<br />
== Usage ==<br />
<br />
{{Note|Don't forget to unlock your phone (screen unlock) before connecting, otherwise you will get error messages.}}<br />
After installation, you have several MTP tools available.<br />
Upon connecting your MTP device, you use:<br />
# mtp-detect<br />
to see if your MTP device is detected. If you get errors about permission, remember that you need to be in the uucp group to access the USB system in general.<br />
<br />
To connect to your MTP device, you use:<br />
# mtp-connect<br />
<br />
If connection is successful, there are several switch options to use in conjunction with {{ic|mtp-connect}} to access data on the device.<br />
<br />
There are also several stand alone commands you can use to access your MTP device such as,<br />
{{Warning | Some commands may be harmful to your MTP device!!! }}<br />
<br />
mtp-albumart mtp-emptyfolders mtp-getplaylist mtp-reset mtp-trexist<br />
mtp-albums mtp-files mtp-hotplug mtp-sendfile<br />
mtp-connect mtp-folders mtp-newfolder mtp-sendtr<br />
mtp-delfile mtp-format mtp-newplaylist mtp-thumb<br />
mtp-detect mtp-getfile mtp-playlists mtp-tracks<br />
<br />
If you see a message like:<br />
<br />
Device 0 (VID=XXXX and PID=XXXX) is UNKNOWN.<br />
Please report this VID/PID and the device model to the libmtp development team<br />
<br />
You should check whether your device has been already in this list: [Supported devices list[http://sourceforge.net/p/libmtp/code/ci/HEAD/tree/src/music-players.h]]<br />
If it is not, you should report it to the development team. If it already is, your libmtp might be slightly outdated. To allow it to be properly used by libmtp, you can add your device to:<br />
/usr/lib/udev/rules.d/69-libmtp.rules<br />
<br />
== Using media players ==<br />
<br />
You can also use your MTP device in music players such as Amarok. To do this you may have to edit {{ic|/usr/lib/udev/rules.d/51-android.rules}} (the MTP device used in the following example is a Galaxy Nexus):<br />
To do this run:<br />
$ lsusb<br />
and look for your device, it will be something like:<br />
Bus 003 Device 011: ID 04e8:6860 Samsung Electronics Co., Ltd GT-I9100 Phone [Galaxy S II], GT-P7500 [Galaxy Tab 10.1]<br />
in which case the entry would be:<br />
SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", ATTR{idProduct}=="6860", MODE="0666", OWNER="[username]"<br />
Then, reload udev rules:<br />
# udevadm control --reload<br />
<br />
{{Note|After installing MTP you may have to reboot for your device to be recognised}}<br />
<br />
== mtpfs ==<br />
<br />
{{Warning | The following is likely to not work and you might have to resort to [[Digital_Cameras#libgphoto2|gphoto2]] or a file manager with gvfs support like [[PCManFM]]. }}<br />
<br />
Mtpfs is FUSE filesystem that supports reading and writing from any MTP device. Basically it allows you to mount your device as an external drive.<br />
<br />
Mtpfs can be installed with the packge {{Pkg|mtpfs}}, available from the [[official repositories]].<br />
* First edit your {{ic|/etc/fuse.conf}} and uncomment the following line:<br />
user_allow_other<br />
<br />
* To mount your device <br />
$ mtpfs -o allow_other /media/YOURMOUNTPOINT<br />
* To unmount your device<br />
$ fusermount -u /media/YOURMOUNTPOINT<br />
* To unmount your device as root<br />
# umount /media/YOURMOUNTPOINT<br />
<br />
Also, you can put them into your ~/.bashrc:<br />
alias android-connect="mtpfs -o allow_other /media/YOURMOUNTPOINT"<br />
alias android-disconnect="fusermount -u /media/YOURMOUNTPOINT"<br />
Or, with sudo <br />
alias android-disconnect="sudo umount -u /media/YOURMOUNTPOINT"<br />
{{Note|if you want not be asked for password when using sudo, please refer to [[USB storage devices]]}}<br />
<br />
== jmtpfs ==<br />
<br />
[http://research.jacquette.com/jmtpfs-exchanging-files-between-android-devices-and-linux/ jmtpfs] is a FUSE and libmtp based filesystem for accessing MTP (Media Transfer Protocol) devices. It was specifically designed for exchanging files between Linux systems and newer Android devices that support MTP but not USB Mass Storage.<br />
jmtpfs is available as {{AUR|jmtpfs}} in the [[AUR]].<br />
<br />
Use this commands to mount your device:<br />
$ jmtpfs ~/mtp<br />
<br />
And this command to unmount it:<br />
$ fusermount -u ~/mtp<br />
<br />
== go-mtpfs ==<br />
<br />
{{Note|Go-mtpfs gives a better performance while writing files to some devices than mtpfs/jmtpfs. Try it if you have slow speeds.}}<br />
{{Note|Mounting with Go-mtpfs fails if external SD Card is present. If you have also external SD Card please remove it and then try mounting again.}}<br />
<br />
If the above instructions do not show any positive results one should try {{AUR|go-mtpfs-git}} from the [[AUR]].<br />
The following has been tested on a Samsung Galaxy Nexus GSM, Asus/Google Nexus 7 (2012 1st gen model), Samsung Galaxy S 3 mini and Google Nexus 4. (This is the only mtp software which worked for me on Nexus 4. Settings are usb debugging enabled, connected as media device.)<br />
<br />
If you want do it simpler, install {{Pkg|go}}, {{Pkg|libmtp}} and {{Pkg|git}} from the [[official repositories]]. After that install {{AUR|go-mtpfs-git}} from the [[AUR]].<br />
<br />
As in the section above install {{Pkg|android-udev}} which will provide you with "/usr/lib/udev/rules.d/51-android.rules" edit it to apply to <br />
your vendorID and productID, which you can see after running mtp-detect. To the end of the line add with a comma OWNER="yourusername". Save the file.<br />
<br />
* Add yourself to the "fuse" group:<br />
gpasswd -a [user] fuse<br />
<br />
* If the group "fuse" does not exist create it with:<br />
groupadd fuse<br />
<br />
Logout or reboot to apply these changes. <br />
<br />
* To create a mount point called "Android" issue the following commands:<br />
mkdir Android<br />
<br />
* To mount your phone use:<br />
go-mtpfs Android<br />
<br />
* To unmount your phone:<br />
fusermount -u Android<br />
<br />
You can create a .bashrc alias as in the example above for easier use.<br />
<br />
== simple-mtpfs ==<br />
<br />
This is another FUSE filesystem for MTP devices. You may find this to be more reliable than {{Pkg|mtpfs}}. {{AUR|simple-mtpfs}} is available in the AUR or can be built from source. Do not run the following commands as root.<br />
<br />
To list MTP devices run<br />
<br />
$ simple-mtpfs --list-devices<br />
<br />
To mount a MTP devices (in this example device 0) run<br />
<br />
$ simple-mtpfs /path/to/your/mount/point<br />
<br />
To un mount run<br />
<br />
$ fusermount -u /path/to/your/mount/point<br />
<br />
== gvfs-mtp troubleshooting ==<br />
<br />
{{Merge|udev}}<br />
<br />
If you have installed the {{Pkg|gvfs-mtp}} package, and your device doesn't show up in the file manager, you might need to write a udev rule in order to auto-mount the device.<br />
<br />
Plug your device and get the vendor-id and product-id,respectively:<br />
<br />
$ lsusb<br />
Bus 001 Device 007: ID 0421:0661 Nokia Mobile Phones Lumia 920<br />
(...)<br />
<br />
The two numbers after ID are ''vendorId'' : ''productID''<br />
<br />
Then make a udev rule, e.g.<br />
<br />
# nano /usr/lib/udev/rules.d/51-android.rules<br />
<br />
and type this rule:<br />
<br />
ATTR{idVendor}=="YOUR VENDOR ID HERE", ATTR{idProduct}=="YOUR PRODUCT ID HERE", SYMLINK+="libmtp", MODE="660", ENV{ID_MTP_DEVICE}="1"<br />
<br />
Reload the udev rules.<br />
<br />
# udevadm control --reload<br />
<br />
And reboot the system. Now file managers (like Thunar) should be able to automount the MTP Device. [https://bbs.archlinux.org/viewtopic.php?id=180719]<br />
<br />
== kio-mtp troubleshooting ==<br />
<br />
If you are not able to use the action "Open with File Manager", you may work around this problem by editing the file /usr/share/apps/solid/actions/solid_mtp.desktop<br />
<br />
Change the line<br />
Exec=kioclient exec mtp:udi=%i/<br />
To<br />
Exec=dolphin "mtp:/"<br />
<br />
== Workarounds for Android ==<br />
<br />
{{Deletion|1=This section has nothing to do with MTP; it was initially added with [https://wiki.archlinux.org/index.php?title=MTP&diff=prev&oldid=235286] and progressively expanded over time.}}<br />
<br />
=== AirDroid ===<br />
<br />
AirDroid is an Android app to access files from your web browser.<br />
<br />
=== FTP ===<br />
<br />
You run a local FTP server on Arch and connect to it from your phone. There are many FTP clients available for Android.<br />
<br />
Alternatively you can run FTP Server on your phone and connect to it from Arch.<br />
<br />
See [[List of applications/Internet#FTP]].<br />
<br />
=== SSH Server ===<br />
<br />
There are many SSH servers available for Android, it allows you to transfer files using {{ic|scp}} command. See also [[SSH]].<br />
<br />
=== Samba ===<br />
<br />
See [[Samba]]. Might require ROOT access on your phone.<br />
<br />
=== ADB ===<br />
<br />
ADB (Android Debug Bridge) is a part of the Android SDK. Install {{Aur|android-sdk-platform-tools}} from [[AUR]]. It can be used to push and pull files from your device. See [[Android#Connecting to a real device - Android Debug Bridge (ADB)]].<br />
<br />
* To push a file to the device use<br />
$ adb push ''<what-to-copy>'' ''<where-to-place>''<br />
<br />
* To pull a file<br />
$ adb pull ''<what-to-pull>'' ''<where-to-place>''<br />
<br />
=== Microsoft Windows on VirtualBox ===<br />
<br />
For this you need to install {{Pkg|virtualbox}} from official repositories and {{Aur|virtualbox-ext-oracle}} from [[AUR]] on your host. Then install VirtualBox Guest Additions on your guest OS. After that go to your ''VM Settings -> USB'' and turn on ''Enable USB Controller''.<br />
<br />
Now you are able to pass your MTP device to Windows on your virtual machine through ''Devices -> USB Devices''. Don't forget to set a shared directory for VM too.<br />
<br />
See [[VirtualBox]].</div>X33ahttps://wiki.archlinux.org/index.php?title=Disk_cloning&diff=339104Disk cloning2014-10-07T05:09:51Z<p>X33a: </p>
<hr />
<div>[[Category:Data compression and archiving]]<br />
[[Category:System recovery]]<br />
[[it:Disk Cloning]]<br />
[[ru:Disk cloning]]<br />
[[tr:Disk_klonlama]]<br />
[[zh-cn:Disk cloning]]<br />
Disk cloning is the process of making an image of a partition or an entire hard drive. This can be useful for copying the drive to other computers and for [[Backup|backup]] and [[File recovery|recovery]] purposes.<br />
<br />
==Using dd==<br />
The dd command is a simple, yet versatile and powerful tool. It can be used to copy from source to destination, block-by-block, regardless of their filesystem types or operating systems. A convenient method is to use dd from a live environment, as in a livecd.<br />
{{Warning|As with any command of this type, you should be very cautious when using it; it can destroy data. Remember the order of input file <nowiki>(if=) and output file (of=) and do not reverse them! Always ensure that the destination drive or partition (of=) is of equal or greater size than the source (if=).</nowiki>}}<br />
===Cloning a partition===<br />
From physical disk /dev/sda, partition 1, to physical disk /dev/sdb, partition 1.<br />
dd if=/dev/sda1 of=/dev/sdb1 bs=4096 conv=notrunc,noerror,sync<br />
If output file '''''of''''' (sdb1 in the example) does not exist, dd will start at the beginning of the disk and create it. <br />
<br />
===Cloning an entire hard disk===<br />
From physical disk /dev/sda to physical disk /dev/sdb<br />
dd if=/dev/sda of=/dev/sdb bs=4096 conv=notrunc,noerror,sync<br />
This will clone the entire drive, including MBR (and therefore bootloader), all partitions, UUIDs, and data.<br />
*''notrunc'' or 'do not truncate' maintains data integrity by instructing dd not to truncate any data. <br />
*''noerror'' instructs dd to continue operation, ignoring all read errors. Default behavior for dd is to halt at any error. <br />
*''sync'' writes zeroes for read errors, so data offsets stay in sync.<br />
*''bs=4096'' sets the block size to 4k, an optimal size for hard disk read/write efficiency and therefore, cloning speed.<br />
{{Note|To regain unique UUIDs, use "tune2fs /dev/sdbX -U random" on every partitions. (works for ext* file systems only) }}<br />
{{Note|Partition table changes from dd are not be registered by the kernel. To notify of changes without rebooting, use a utility like partprobe (part of GNU parted).}}<br />
<br />
===Backing up the MBR===<br />
<br />
The MBR is stored in the the first 512 bytes of the disk. It consist of 3 parts:<br />
#The first 446 bytes contain the boot loader.<br />
#The next 64 bytes contain the partition table (4 entries of 16 bytes each, one entry for each primary partition).<br />
#The last 2 bytes contain an identifier<br />
<br />
To save the MBR into the file "mbr.img":<br />
# dd if=/dev/hda of=/mnt/sda1/mbr.img bs=512 count=1<br />
<br />
To restore (be careful : this could destroy your existing partition table and with it access to all data on the disk):<br />
# dd if=/mnt/sda1/mbr.img of=/dev/hda<br />
<br />
If you only want to restore the boot loader, but not the primary partition table entries, just restore the first 446 bytes of the MBR: <br />
# dd if=/mnt/sda1/mbr.img of=/dev/hda bs=446 count=1<br />
<br />
To restore only the partition table, one must use <br />
# dd if=/mnt/sda1/mbr.img of=/dev/hda bs=1 skip=446 count=64<br />
<br />
You can also get the MBR from a full dd disk image.<br />
#dd if=/path/to/disk.img of=/mnt/sda1/mbr.img bs=512 count=1<br />
<br />
===Create disk image===<br />
1. Boot from a liveCD or liveUSB.<br />
<br />
2. Make sure no partitions are mounted from the source hard drive.<br />
<br />
3. Mount the external HD<br />
<br />
4. Backup the drive. <br />
# dd if=/dev/hda conv=sync,noerror bs=64K | gzip -c > /mnt/sda1/hda.img.gz<br />
<br />
If necessary (e.g. when the format of the external HD is FAT32) split the disk image in volumes (see also split man pages).<br />
<br />
# dd if=/dev/hda conv=sync,noerror bs=64K | gzip -c | split -a3 -v2G - /mnt/sda1/hda.img.gz<br />
<br />
5. Save extra information about the drive geometry necessary in order to interpret the partition table stored within the image. The most important of which is the cylinder size. <br />
# fdisk -l /dev/hda > /mnt/sda1/hda_fdisk.info<br />
<br />
{{Note|1=You may wish to use a block size (bs=) that is equal to the amount of cache on the HD you are backing up. For example, bs=8192K works for an 8MB cache. The 64K mentioned in this article is better than the default bs=512 bytes, but it will run faster with a larger bs=.}}<br />
<br />
===Restore system===<br />
<br />
To restore your system:<br />
# gunzip -c /mnt/sda1/hda.img.gz | dd of=/dev/hda<br />
<br />
or<br />
# cat /mnt/sda1/hda.img.gz* | gunzip -c | dd of=/dev/hda<br />
when the image has been split in volumes.<br />
<br />
=== Examples with compression ===<br />
<br />
When you need to create the hard drive or a single partition compressed backup image file you must use compression tools which can do backup from a ''stdout'' and the ''dd'' command. Those compressed files cannot be mounted by the ''mount'' command but are useful to know how to create and restore them.<br />
<br />
==== 7zip ====<br />
<br />
Install the {{Pkg|p7zip}} package from the [[official repositories]].<br />
This backup example will split the ''dd'' command output in the files by up to the 100 megabyte each:<br />
dd if=/dev/sdXY | 7z a -v100m -t7z -si image-file.7z<br />
Restore with 7zip:<br />
7z x -so image-file.7z | dd of=/dev/sdXY<br />
{{Note|7zip can split only the ''7z'' compression type files}}<br />
<br />
==== Zip ====<br />
<br />
Install the {{Pkg|zip}} package from the [[official repositories]], which contains ''zipsplit'' among other utilities for the management of zip archives.<br />
It will create a file with "-" name inside the image-file.zip file which will contain data from the ''dd'' command output. To make a raw output of the file you can use the {{ic|-cp}} option with ''unzip'' in stdout for the ''dd'' command.<br />
Backup:<br />
dd if=/dev/sdXY | zip --compression-method bzip2 image-file.zip - <br />
Restore:<br />
unzip -cp image-file.zip | dd of=/dev/sdXY<br />
The ''zip'' tool cannot split files on the fly but you can use the {{ic|zipsplit}} utility on an already created file.<br />
<br />
See also {{ic|man zip}} for more information.<br />
<br />
==== Rar ====<br />
<br />
Install the {{Aur|rar}} package from the [[AUR]].<br />
{{Warning| The ''rar'' examples were made based on the manuals, please confirm!}}<br />
This should do a backup and split the creating file on the fly in by up to 150 megabyte files each.<br />
dd if=/dev/sdXY | rar a -v150m -siimage-file.rar<br />
This should restore<br />
unrar x -p image-file.rar | dd of=/dev/sdXY<br />
or you can use the ''rar'' instead of the {{Pkg|unrar}} utility. The unrar utility is available in the official repositories and can be installed with {{ic|pacman -S unrar}}.<br />
<br />
==== Bzip2 ====<br />
<br />
Creation by using the ''dd'' is more safe and use to be error free:<br />
{{hc|<nowiki>dd if=/dev/sdXY | bzip2 -f5 > compressedfile.bzip2</nowiki>|<br />
937016+0 records in<br />
937016+0 records out<br />
479752192 bytes (480 MB) copied, 94.7002 s, 5.1 MB/s<br />
}}<br />
<br />
And a safe way of restoring with combination of the ''dd'':<br />
$ bunzip2 -dc compressedfile.bzip2 | dd of=/dev/sdXY<br />
or<br />
$ bzcat compressedfile.bzip2 | dd of=/dev/sdXY<br />
{{Warning|Never ever use the {{ic|bzip2 -kdc imgage.bzip2 > /dev/sdXY}} and {{ic|bzip2 -kc /dev/sdXY > imgage.bzip2}} methods for serious backup of partitions and disks. The errors might be due the end of the device or partition and the restore process gives also errors due the truncated end.<br />
}}<br />
<br />
==Using cp==<br />
The cp program can be used to clone a disk, one partition at a time. An advantage to using cp is that the filesystem type of the destination partition(s) may be the same or different than the source. For safety, perform the process from a live environment.<br />
{{Note|This method should not be considered in the same category as disk cloning on the level at which dd operates. Also, it has been reported that even with the '''-a''' flag, some extended attributes may not be copied. For better results, rsync or tar should be used.}}<br />
The basic procedure from a live environment will be:<br />
* Create the new destination partition(s) using fdisk, cfdisk or other tools available in the live environment.<br />
* Create a filesystem on each of the newly created partitions. Example:<br />
mkfs -t ext3 /dev/sdb1<br />
* Mount the source and destination partitions. Example:<br />
mount -t ext3 /dev/sda1 /mnt/source<br />
mount -t ext3 /dev/sdb1 /mnt/destination<br />
* Copy the files from the source partition to the destination <br />
cp -a /mnt/source/* /mnt/destination<br />
'''-a''': preserve all attributes , never follow symbolic links and copy recursively <br />
* Change the mount points of the newly cloned partitions in /etc/fstab accordingly<br />
* Finally, install the GRUB bootloader if necessary. (See [[GRUB]])<br />
<br />
==Disk cloning software==<br />
===Disk cloning in Arch===<br />
<br />
* [[Partclone|Partclone]] provides utilities to save and restore used blocks on a partition and supports ext2, ext3, ext4, hfs+, reiserfs, reiser4, btrfs, vmfs3, vmfs5, xfs, jfs, ufs, ntfs, fat(12/16/32) and exfat. Optionally, a ncurses interface can be used. Partclone is available in the community repository.<br />
* [http://www.partimage.org/ Partimage], an ncurses program, is available in the community repos. Partimage does not currently support ext4 or btrfs filesystems. NTFS is experimental.<br />
<br />
===Disk cloning outside of Arch===<br />
If you wish to backup or propagate your Arch install root, you are probably better off booting into something else and clone the partition from there. Some suggestions:<br />
<br />
* [http://partedmagic.com/doku.php?id=start PartedMagic] has a very nice live cd/usb with PartImage and other recovery tools.<br />
* [http://www.mondorescue.org/ Mindi] is a linux distribution specifically for disk clone backup. It comes with its own cloning program, Mondo Rescue.<br />
* [[wikipedia:Acronis_True_Image|Acronis True Image]] is a commercial disk cloner for Windows. It allows you to create a live (from within Windows), so you do not need a working Windows install on the actual machine to use it. After regitratinon of the Acronis software on their website, you will be able to download a Linux based Live cd and/or plugins for BartPE for creation of the Windows based live cd.<br />
* [http://www.fsarchiver.org/Main_Page FSArchiver] allows you to save the contents of a file system to a compressed archive file. Can be found on the [http://www.sysresccd.org/Main_Page System Rescue CD].<br />
* [http://clonezilla.org/ Clonezilla] is an enhanced partition imager which can also restore entire disks as well as partitions.<br />
* [http://redobackup.org/ Redo Backup and Recovery ] is a Live CD featuring a graphical front-end to partclone.<br />
<br />
==External Links==<br />
* [[Wikipedia:List of disk cloning software]]<br />
* [https://bbs.archlinux.org/viewtopic.php?id=4329 Arch Linux forum thread]</div>X33ahttps://wiki.archlinux.org/index.php?title=Xrandr&diff=334570Xrandr2014-09-10T04:41:27Z<p>X33a: /* Adding undetected resolutions */ typo</p>
<hr />
<div>{{Lowercase title}}<br />
[[Category:X Server]]<br />
[[zh-CN:Xrandr]]<br />
{{Related articles start}}<br />
{{Related|Xorg}}<br />
{{Related|Multihead}}<br />
{{Related articles end}}<br />
<br />
''xrandr'' is an official configuration utility to the [[Wikipedia:RandR|RandR]] [[Wikipedia:X Window System|X Window System]] extension. It can be used to set the size, orientation or reflection of the outputs for a screen. For configuring multiple monitors see the [[Multihead]] page.<br />
<br />
== Installation ==<br />
<br />
[[pacman|Install]] the {{Pkg|xorg-xrandr}} package from the [[official repositories]]. Alternatively, a graphical front end such as {{Pkg|arandr}} or {{Pkg|lxrandr}} can be used instead.<br />
== Testing configuration ==<br />
<br />
When run without any option, ''xrandr'' shows the names of different outputs available on the system ({{ic|LVDS}}, {{ic|VGA-0}}, etc.) and resolutions available on each:<br />
<br />
{{hc|xrandr|<br />
Screen 0: minimum 320 x 200, current 1440 x 900, maximum 8192 x 8192<br />
VGA disconnected (normal left inverted right x axis y axis)<br />
LVDS connected (normal left inverted right x axis y axis)<br />
1440x900 59.9*+<br />
1280x854 59.9 <br />
1280x800 59.8 <br />
...<br />
}}<br />
<br />
You can use ''xrandr'' to set different resolution (must be present in the above list) on some output:<br />
<br />
$ xrandr --output LVDS --mode 1280x800<br />
<br />
When multiple refresh rates are present in the list ('''not''' in the example above), it may be changed by the {{ic|--rate}} option, either at the same time or independently. For example:<br />
<br />
$ xrandr --output LVDS --mode 1280x800 --rate 75<br />
<br />
The {{ic|--auto}} option will turn the specified output on if it is off and set the preferred (maximum) resolution:<br />
<br />
$ xrandr --output LVDS --auto<br />
<br />
It is possible to specify multiple outputs in one command, e.g. to turn off {{ic|LVDS}} and turn on {{ic|HDMI-0}} with preferred resolution:<br />
<br />
$ xrandr --output LVDS --off --output HDMI-0 --auto<br />
<br />
{{Note|<br />
* Changes you make using ''xrandr'' will only last through the current session.<br />
* ''xrandr'' has a lot more capabilities - see {{ic|man xrandr}} for details.<br />
}}<br />
<br />
== Configuration ==<br />
<br />
''xrandr'' is just a simple interface to the RandR extension and has no configuration file. However, there are multiple ways of achieving persistent configuration:<br />
<br />
# The RandR extension can be configured via [[Xorg#Configuration|X configuration files]], see [[Multihead#RandR]] for details. This method provides only static configuration.<br />
# If you need dynamic configuration, you need to execute ''xrandr'' commands each time X server starts. See [[Autostarting#Graphical]] for details. This method has the disadvantage of occurring fairly late in the startup process, thus it will not alter the resolution of the [[display manager]] if you use one.<br />
# Custom scripts calling ''xrandr'' can be bound to events (for example when external monitor is plugged in), see [[acpid]] for details. The [[#Scripts]] section provides you with some example scripts that might be useful for this purpose.<br />
<br />
{{Tip|Both KDM and GDM have startup scripts that are executed when X is initiated. For GDM, these are in {{ic|/etc/gdm/}}, while for KDM this is done at {{ic|/usr/share/config/kdm/Xsetup}}. This method requires root access and mucking around in system config files, but will take effect earlier in the startup process than using xprofile.}}<br />
<br />
=== Scripts ===<br />
<br />
==== Example 1 ====<br />
<br />
This script toggles between external monitor (specified by {{ic|$EXT}}) and default monitor (specified by {{ic|$IN}}), so that only one monitor is active at a time.<br />
<br />
The default monitor (specified by {{ic|$IN}}) should be connected when running the script, which is always true for a laptop.<br />
<br />
{{bc|<nowiki><br />
#!/bin/bash<br />
<br />
IN="LVDS1"<br />
EXT="VGA1"<br />
<br />
if (xrandr | grep "$EXT disconnected"); then<br />
xrandr --output $EXT --off --output $IN --auto<br />
else<br />
xrandr --output $IN --off --output $EXT --auto<br />
fi<br />
</nowiki>}}<br />
<br />
==== Example 2 ====<br />
<br />
This script toggles only external monitor (specified by {{ic|$EXT}}), leaves the default monitor (specified by {{ic|$IN}}) on.<br />
<br />
The default monitor (specified by {{ic|$IN}}) should be connected when running the script, which is always true for a laptop.<br />
<br />
{{bc|<nowiki><br />
#!/bin/bash<br />
<br />
IN="LVDS1"<br />
EXT="VGA1"<br />
<br />
if (xrandr | grep "$EXT disconnected"); then<br />
xrandr --output $IN --auto --output $EXT --off <br />
else<br />
xrandr --output $IN --auto --primary --output $EXT --auto --right-of $IN<br />
fi<br />
</nowiki>}}<br />
<br />
==== Example 3 ====<br />
<br />
This script iterates through connected monitors, selects currently active (primary) monitor, turns next one on and the others off:<br />
<br />
{{bc|<nowiki><br />
# get info from xrandr<br />
connectedOutputs=$(xrandr | grep " connected" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/")<br />
activeOutput=$(xrandr | grep -e " connected [^(]" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/") <br />
connected=$(echo $connectedOutputs | wc -w)<br />
<br />
# initialize variables<br />
execute="xrandr "<br />
default="xrandr "<br />
i=1<br />
switch=0<br />
<br />
for display in $connectedOutputs<br />
do<br />
# build default configuration<br />
if [ $i -eq 1 ]<br />
then<br />
default=$default"--output $display --auto "<br />
else<br />
default=$default"--output $display --off "<br />
fi<br />
<br />
# build "switching" configuration<br />
if [ $switch -eq 1 ]<br />
then<br />
execute=$execute"--output $display --auto "<br />
switch=0<br />
else<br />
execute=$execute"--output $display --off "<br />
fi<br />
<br />
# check whether the next output should be switched on<br />
if [ $display = $activeOutput ]<br />
then<br />
switch=1<br />
fi<br />
<br />
i=$(( $i + 1 ))<br />
done<br />
<br />
# check if the default setup needs to be executed then run it<br />
echo "Resulting Configuration:"<br />
if [ -z "$(echo $execute | grep "auto")" ]<br />
then<br />
echo "Command: $default"<br />
`$default`<br />
else<br />
echo "Command: $execute"<br />
`$execute`<br />
fi<br />
echo -e "\n$(xrandr)"<br />
</nowiki>}}<br />
<br />
==== Example 3a ====<br />
<br />
This script iterates over all xrandr outputs. If anything is connected it tries to figure out the best possible resolution places that right-of the previous display.<br />
<br />
I am using it with {{AUR|srandrd}} in my {{Pkg|i3-wm}} like so ([[#Example 3]] didn't work for me for some reason or other):<br />
<br />
{{hc|~/.xprofile|<br />
srandrd ~/.i3/detect_displays.sh<br />
}}<br />
<br />
{{bc|<nowiki><br />
#!/bin/bash<br />
<br />
XRANDR="xrandr"<br />
CMD="${XRANDR}"<br />
declare -A VOUTS<br />
eval VOUTS=$(${XRANDR}|awk 'BEGIN {printf("(")} /^\S.*connected/{printf("[%s]=%s ", $1, $2)} END{printf(")")}')<br />
declare -A POS<br />
#XPOS=0<br />
#YPOS=0<br />
#POS="${XPOS}x${YPOS}"<br />
<br />
POS=([X]=0 [Y]=0)<br />
<br />
find_mode() {<br />
echo $(${XRANDR} |grep ${1} -A1|awk '{FS="[ x]"} /^\s/{printf("WIDTH=%s\nHEIGHT=%s", $4,$5)}')<br />
}<br />
<br />
xrandr_params_for() {<br />
if [ "${2}" == 'connected' ]<br />
then<br />
eval $(find_mode ${1}) #sets ${WIDTH} and ${HEIGHT}<br />
MODE="${WIDTH}x${HEIGHT}"<br />
CMD="${CMD} --output ${1} --mode ${MODE} --pos ${POS[X]}x${POS[Y]}"<br />
POS[X]=$((${POS[X]}+${WIDTH}))<br />
return 0<br />
else<br />
CMD="${CMD} --output ${1} --off"<br />
return 1<br />
fi<br />
}<br />
<br />
for VOUT in ${!VOUTS[*]}<br />
do<br />
xrandr_params_for ${VOUT} ${VOUTS[${VOUT}]}<br />
done<br />
set -x<br />
${CMD}<br />
set +x<br />
</nowiki>}}<br />
<br />
== Using xrandr with VNC ==<br />
<br />
{{Out of date|the {{ic|-s}} option is for version 1.1}}<br />
{{Poor writing|duplicates [[#Adding undetected resolutions]]}}<br />
<br />
If you are using a VNC server that supports xrandr, you can change the vnc resolution on the fly, for example by running {{ic|xrandr -s 1920x1200}}. ''tigervnc'' is an example of a client that supports xrandr.<br />
<br />
If you run {{ic|xrandr}} from a VNC session, you will get a list of currently configured modes. Each of these modes can be activated with the {{ic|xrandr -s <width>x<height>}} command; however, if the mode you want does not exist in the list, you must first add it. As an example, we will add resolution {{ic|1024x600}}:<br />
<br />
First run {{ic|cvt}} to get the correct modeline for the resolution you want to add:<br />
<br />
{{hc|$ cvt 1024 600|<br />
# 1024x600 59.85 Hz (CVT) hsync: 37.35 kHz; pclk: 49.00 MHz<br />
Modeline "1024x600_60.00" 49.00 1024 1072 1168 1312 600 603 613 624 -hsync +vsync<br />
}}<br />
<br />
Use that modeline output to run the commands below:<br />
<br />
$ xrandr --newmode "1024x600" 49.00 1024 1072 1168 1312 600 603 613 624 -hsync +vsync<br />
$ xrandr --addmode default "1024x600"<br />
<br />
Doing the above will give you the ability to change to {{ic|1024x600}} by running {{ic|xrandr -s 1024x600}}, but it will only last for the current x session. To ensure that you can use the newly added resolution each time you start vncserver, add the above commands to {{ic|~/.vnc/xstartup}}.<br />
<br />
== Troubleshooting ==<br />
<br />
=== Adding undetected resolutions ===<br />
<br />
Due to buggy hardware or drivers, your monitor's correct resolutions may not always be detected by xrandr. For example, the EDID data block queried from the monitor may be incorrect. However, we can add the desired resolutions to xrandr.<br />
<br />
First we run {{ic|gtf}} or {{ic|cvt}} to get the '''Modeline''' for the resolution we want:<br />
<br />
For some LCD screens (samsung 2343NW), the command "cvt -r" (= with reduced blanking) is to be used.<br />
<br />
{{hc|$ cvt 1280 1024|<br />
# 1280x1024 59.89 Hz (CVT 1.31M4) hsync: 63.67 kHz; pclk: 109.00 MHz<br />
Modeline "1280x1024_60.00" 109.00 1280 1368 1496 1712 1024 1027 1034 1063 -hsync +vsync<br />
}}<br />
<br />
{{Note|If the Intel video driver {{pkg|xf86-video-intel}} is used, it may report the desired resolution along with its properties in {{ic|/var/log/Xorg.0.log}} — use that first if it is different from the output of {{ic|gtf}} or {{ic|cvt}}. For instance, the log and its use with xrandr:<br />
[ 45.063] (II) intel(0): clock: 241.5 MHz Image Size: 597 x 336 mm<br />
[ 45.063] (II) intel(0): h_active: 2560 h_sync: 2600 h_sync_end 2632 h_blank_end 2720 h_border: 0<br />
[ 45.063] (II) intel(0): v_active: 1440 v_sync: 1443 v_sync_end 1448 v_blanking: 1481 v_border: 0<br />
<br />
xrandr --newmode "2560x1440" 241.50 2560 2600 2632 2720 1440 1443 1448 1481 -hsync +vsync<br />
}}<br />
<br />
Then we create a new xrandr mode. Note that the Modeline keyword needs to be ommited.<br />
<br />
$ xrandr --newmode "1280x1024_60.00" 109.00 1280 1368 1496 1712 1024 1027 1034 1063 -hsync +vsync<br />
<br />
After creating it we need an extra step to add this new mode to our current output (VGA1). We use just the name of the mode, since the parameters have been set previously.<br />
<br />
$ xrandr --addmode VGA1 1280x1024_60.00<br />
<br />
Now we change the resolution of the screen to the one we just added:<br />
<br />
$ xrandr --output VGA1 --mode 1280x1024_60.00<br />
<br />
Note that these settings only take effect during this session. <br />
<br />
If you are not sure about the resolution you will test, you may add a {{ic|sleep 5}} and a safe resolution command line following, like this : <br />
<br />
$ xrandr --output VGA1 --mode 1280x1024_60.00 && sleep 5 && xrandr --newmode "1024x768-safe" 65.00 1024 1048 1184 1344 768 771 777 806 -HSync -VSync && xrandr --addmode VGA1 1024x768-safe && xrandr --output VGA1 --mode 1024x768-safe<br />
<br />
Also, change {{ic|VGA1}} to correct output name.<br />
<br />
=== Resolution lower than expected ===<br />
<br />
{{Tip|Try [[#Adding undetected resolutions]] first, if it doesn't work, you may try this method.}}<br />
<br />
If you video card is recognized but the resolution is lower than you expect, you may try this.<br />
<br />
Background: ATI X1550 based video card and two LCD monitors DELL 2408(up to 1920x1200) and Samsung 206BW(up to 1680x1050). Upon first login after installation, the resolution default to 1152x864. xrandr does not list any resolution higher than 1152x864. You may want to try editing /etc/X11/xorg.conf, add a section about virtual screen, logout, login and see if this helps. If not then read on.<br />
<br />
Change xorg.conf<br />
{{hc|/etc/X11/xorg.conf|<br />
Section "Screen"<br />
...<br />
SubSection "Display"<br />
Virtual 3600 1200<br />
EndSubSection<br />
EndSection<br />
}}<br />
<br />
About the numbers: DELL on the left and Samsung on the right. So the virtual width is of sum of both LCD width 3600=1920+1680; Height then is figured as the max of them, which is max(1200,1050)=1200. If you put one LCD above the other, use this calculation instead: (max(width1, width2), height1+height2).<br />
<br />
== See also ==<br />
* https://wiki.ubuntu.com/X/Config/Resolution<br />
* [http://wiki.debian.org/XStrikeForce/HowToRandR12 RandR 1.2 tutorial]<br />
* [http://www.thinkwiki.org/wiki/Xorg_RandR_1.2 Xorg RandR 1.2 on ThinkWiki]<br />
* [http://www.x.org/wiki/FAQVideoModes#ObtainingmodelinesfromWindowsprogramPowerStrip FAQVideoModes - more information about modelines]</div>X33ahttps://wiki.archlinux.org/index.php?title=Prosody&diff=333417Prosody2014-09-01T05:57:50Z<p>X33a: /* Components */</p>
<hr />
<div>[[Category:Internet applications]]<br />
[[de:Prosody]]<br />
[http://prosody.im/ Prosody] (pronunciation: [http://www.merriam-webster.com/cgi-bin/audio.pl?prosod05.wav=prosody%27 1], [http://www.merriam-webster.com/cgi-bin/audio.pl?prosod04.wav=prosody%27 2]) is an [http://xmpp.org/ XMPP] server written in the [http://www.lua.org/ Lua] programming language. Prosody is designed to be lightweight and highly extensible. It is licensed under a permissive [http://prosody.im/source/mit MIT license]. Prosody is available for Arch Linux in the Community repository with some optional dependencies available from the [[Arch User Repository]].<br />
<br />
Previous experience with building and installing packages from the AUR and basic knowledge of XMPP will be very helpful when following the guide.<br />
<br />
==Installation==<br />
<br />
[[pacman|Install]] {{Pkg|prosody}} from the official repositories.<br />
<br />
===Optional dependencies===<br />
Prosody has optional depedencies that although not strictly required for its operation, provide useful features. These dependencies may also have to be built and installed from the AUR. If you are unfamiliar with how to build and install packages from the AUR please see [[AUR User Guidelines#Installing packages]].<br />
<br />
; TLS/SSL Support (Recommended)<br />
: Allow Prosody to encrypt streams to prevent eavesdropping.<br>''Requires:'' {{Pkg|lua51-sec}} (Community)<br />
<br />
; MySQL Backend<br />
: Allow Prosody to use a MySQL backend like mariadb for better scaling and performance.<br>''Requires:'' {{Pkg|lua-sql-mysql}} (Community)<br />
<br />
; Better Connection Scaling (Recommended)<br />
: Allow Prosody to use [http://www.monkey.org/~provos/libevent/ libevent] to handle a greater number of simultaneous connections.<br>''Requires:'' {{AUR|lua51-event}} (AUR)<br />
<br />
; Stream Compression<br />
: Allow Prosody to compress client-to-server streams for compatible clients to save bandwidth.<br>''Requires:'' {{Pkg|lua51-zlib}} (Community)<br />
<br />
; Cyrus SASL Support<br />
: Allow Prosody to use the [http://asg.web.cmu.edu/sasl/sasl-library.html Cyrus SASL] library to provide authentication.<br>''Requires:'' {{AUR|lua-cyrussasl}} (AUR)<br />
<br />
==Configuration==<br />
<br />
{{Note|The {{Ic|posix}} module and {{Ic|pidfile}} setting contained in the default configuration file are required for Prosody's proper operation on Arch Linux. Please do not disable or alter them.}}<br />
<br />
The main configuration file is located at {{ic|/etc/prosody/prosody.cfg.lua}}, information on how to configure Prosody can be found in Prosody's [http://prosody.im/doc/configure documentation]. The syntax of the configuration file can be checked after any changes are made by running: <br />
<br />
{{Ic|$ luac -p /etc/prosody/prosody.cfg.lua}}<br />
<br />
No output means the syntax is correct.<br />
<br />
===Logging===<br />
The Arch Linux Prosody package is pre-configured to log to syslog. Thus, by default, Prosody log messages are available in the [[Systemd#Journal|systemd journal]].<br />
<br />
==Operation==<br />
<br />
You can start Prosody through the included Systemd script:<br />
<br />
{{Ic|# systemctl start prosody}}<br />
<br />
To automatically start Prosody at boot execute:<br />
<br />
{{Ic|# systemctl enable prosody}}<br />
<br />
Prosody uses the default XMPP ports, 5222 and 5269, for client-to-server and server-to-server communications respectively. Configure your firewall as necessary.<br />
<br />
You can manipulate Prosody users by using the {{Ic|prosodyctl}} program. To add a user:<br />
<br />
{{Ic|# prosodyctl adduser <JID>}}<br />
<br />
{{Tip|You will likely want to make at least one user an administrator by adding their Jabber ID to the {{Ic|admins}} list in the configuration file.}}<br />
<br />
Issue {{Ic|man prosodyctl}} to see the man page for {{Ic|prosodyctl}}.<br />
<br />
===Security===<br />
====User registration====<br />
Prosody supports XMPP's in-band registration [http://xmpp.org/extensions/xep-0077.html standard], which allows users to register with an XMPP client from within their client and change their passwords. While this is convenient for users it does not allow administrators to moderate the registration of new users. As such, the {{Ic|register}} module is enabled in the default configuration but {{Ic|allow_registration}} is set to {{Ic|false}}. This allows existing users to change their passwords from within their client but does not allow new users to register themselves.<br />
<br />
{{Tip|If you do decide to support new in-band registrations, you will likely find the {{Ic|watchregistrations}} and {{Ic|welcome}} modules useful.}}<br />
<br />
====Stream encryption====<br />
Prosody can utilize TLS certificates to encrypt client-to-server communications (if the proper [[#Optional Dependencies|dependencies]] are installed). See the relevant sections of {{ic|prosody.cfg.lua}} to configure Prosody to utilize these certificates.<br />
<br />
To require encryption for client-to-server communications add the following to your configuration file:<br />
{{hc|/etc/prosody/prosody.cfg.lua|2=<br />
Host "*"<br />
<br />
c2s_require_encryption = true<br />
}}<br />
<br />
Similarly, for server-to-server communications you may do:<br />
{{hc|/etc/prosody/prosody.cfg.lua|2=<br />
Host "*"<br />
<br />
s2s_require_encryption = true<br />
}}<br />
<br />
While requiring client-to-server encryption is generally a good idea, please keep in mind that some popular XMPP services such as Google Talk/Gmail do not support server-to-server encryption.<br />
<br />
===Listing users===<br />
A simple way to see a list of the registered users is<br />
# ls -l /var/lib/prosody/*/accounts/*<br />
<br />
alternatively, you can download the module [http://prosody.im/files/mod_listusers.lua mod_listusers.lua], and use it as<br />
# prosodyctl mod_listusers<br />
<br />
==Removal==<br />
<br />
After normally uninstalling Prosody with pacman, the {{ic|/etc/prosody}} and {{ic|/var/lib/prosody}} directories may be left on your filesystem, and you may want to remove them if you do not plan on reinstalling Prosody.<br />
<br />
==Tips and tricks==<br />
===Components===<br />
Prosody supports XMPP components, which provide extra services to clients. Components are either provided internally by special Prosody modules or externally using the protocol specified in [http://xmpp.org/extensions/xep-0114.html XEP-0114].<br />
<br />
{{Note|Components must use a different hostname from the {{Ic|VirtualHost}} names defined in {{Ic|prosody.cfg.lua}}. Attempting to host a component on the same hostname as a defined {{Ic|VirtualHost}} '''will''' result in errors.}}<br />
<br />
By default, Prosody will listen for external components. If you do not plan to use any external components with Prosody you can disable this behavior by adding the following your configuration:<br />
<br />
{{hc|/etc/prosody/prosody.cfg.lua|2=<br />
component_ports = {}<br />
}}<br />
<br />
====Multi-User Chat====<br />
A common component used with XMPP servers is Multi-User Chat (MUC), which allows conferences between multiple users. MUC is provided as an internal component with Prosody. To enable MUC add the following to your configuration file:<br />
<br />
{{hc|/etc/prosody/prosody.cfg.lua|<br />
Component "conference.example.com" "muc"<br />
}}<br />
<br />
This will enable the MUC component on host {{Ic|conference.example.com}}.<br />
<br />
===Prosody modules===<br />
[http://code.google.com/p/prosody-modules/ Prosody Modules] is a collection of extra modules not distributed with Prosody. These modules are in various states of development from highly experimental to relatively stable. You should consult a given module's wiki page for more information. An example of an extra module is {{Ic|[http://code.google.com/p/prosody-modules/wiki/mod_pastebin pastebin]}}, which when loaded will intercept long messages (for example, log file output) and replace them with a link to a pastebin hosted using Prosody's internal HTTP server (provided by the core module, {{Ic|httpserver}}).<br />
<br />
To use an extra module download its raw file(s) from the source browser (when viewing a file, search for the link "View raw file"). Alternatively and likely easier, use Mercurial to clone the entire repository:<br />
<br />
{{Ic|$ hg clone <nowiki>https://prosody-modules.googlecode.com/hg/ prosody-modules</nowiki>}}<br />
<br />
Now you can copy the module (and any additional files it needs) to Prosody's module directory at {{ic|/usr/lib/prosody/modules}}. To enable the module add it to your {{Ic|modules_enabled}} list in your {{ic|prosody.cfg.lua}} for the host or component you wish to use it for. For example, to use the {{Ic|pastebin}} module on a MUC component:<br />
<br />
{{hc|/etc/prosody/prosody.cfg.lua|2=<br />
Component "conference.example.com" "muc"<br />
modules_enabled = { "pastebin" }<br />
}}<br />
<br />
{{Note|An enforced Prosody convention is that modules are named {{Ic|mod_''foo''.lua}} but simply enabled by adding {{Ic|''foo''}} to the {{Ic|modules_enabled}} list.}}<br />
<br />
===Console===<br />
{{Warning|The console does not require any authentication so any user on a multi-user system can connect and issue commands on the console. Therefore it is '''not''' recommended to enable the {{Ic|console}} module on a multi-user system.}}<br />
<br />
The {{Ic|console}} module provides a telnet console from which administrative operations and queries can be performed. You can connect to the console by issuing:<br />
<br />
{{Ic|$ telnet localhost 5582}}<br />
<br />
You of course need the {{Ic|telnet}} program provided by the {{Ic|inetutils}} package. Use the {{Ic|help}} command in the console to get usage help.<br />
<br />
The console even allows you to execute Lua commands directly on the server by preceding a command with {{Ic|>}}. For example to see if a client connection is compressed:<br />
<br />
{{Ic|> full_sessions["romeo@montague.lit/Resource"].compressed}}<br />
<br />
Will return {{Ic|true}} if the connection is compressed or {{Ic|nil}} if it is not.<br />
<br />
==Troubleshooting==<br />
One of Prosody's primary design principles is to be simple to use and configure. However, issues can still arise (and likely will as is the case with any complex software). If you encounter a problem there are a variety of steps you can take to narrow down the cause:<br />
<br />
* '''Check for known issues'''<br>Look at the [http://prosody.im/doc/release release notes] for your Prosody version to see if your issue is listed as a known issue. Also check the [http://code.google.com/p/lxmppd/issues/list issue tracker] to see if your issue has already been reported.<br />
* '''Check configuration syntax'''<br>Run {{Ic|luac -p /etc/prosody/prosody.cfg.lua}} to check for any syntax errors in your configuration file. If there is no output your syntax is fine.<br />
* '''Check the log'''<br>Errors are only logged if there is a critical problem so always address those issues. If you think you have a very low level issue (like protocol compatibility between clients and servers with Prosody) then you can enable the very verbose debug level logging.<br />
* '''Check permissions'''<br>The Prosody package should add a new {{Ic|prosody}} user and group to your system and set appropriate permissions, but it is always good to double check. Ensure that {{ic|/etc/prosody}} and {{ic|/var/lib/prosody}} are owned by the {{Ic|prosody}} user and that the user has appropriate permissions to read and write to those paths and all contained files.<br />
* '''Check listening ports'''<br>When troubleshooting connection issues make sure that Prosody is actually listening for connections. You may do so by running {{Ic|ss -tul}} and making sure that {{Ic|xmpp-client}} (port 5222) and {{Ic|xmpp-server}} (port 5269) are listed.<br />
* '''Restart'''<br>Like most things, it does not hurt to restart Prosody ({{Ic|systemctl restart prosody}}) to see if it resolves an issue.<br />
<br />
If you are unable to resolve your issue yourself there are a variety of resources you can use to seek help. In order of immediacy with which you will likely receive help:<br />
<br />
# XMPP Conference: {{Ic|prosody@conference.prosody.im}}<br />
# Mailing List: [http://groups.google.co.uk/group/prosody-users Web Interface], [mailto:prosody-users@googlegroups.com Email]<br />
# [https://bbs.archlinux.org/viewforum.php?id=4 Arch Forums] (for package issues)<br />
<br />
==Development==<br />
<br />
Two development packages are maintained for Prosody in the AUR, {{AUR|prosody-devel}} and {{AUR|prosody-hg}}. {{Ic|prosody-devel}} tracks the latest source release of a development version (alpha, beta, release candidate) and will actually be behind the stable version if a final version of the development version is released. {{Ic|prosody-hg}} tracks the [http://www.selenic.com/mercurial/wiki/ Mercurial] repository tip for Prosody and will always contain the latest code as it is checked in. Both packages are built similarly to the stable package.<br />
<br />
==Communication==<br />
* Mailing Lists: [http://groups.google.co.uk/group/prosody-dev prosody-dev], [http://groups.google.co.uk/group/prosody-users prosody-users]<br />
* Conference: {{Ic|prosody@conference.prosody.im}}<br />
* Blog: [http://blog.prosody.im/ Prosodical Thoughts]<br />
<br />
== See also ==<br />
<br />
* [http://prosody.im/doc Official documentation]<br />
* [http://blog.prosody.im/ Prosodical Thoughts] (Blog)<br />
* [http://code.google.com/p/lxmppd/issues/list Issue Tracker]<br />
* [http://prosody.im/source/browse/ Prosody Modules] (Extra Modules)</div>X33ahttps://wiki.archlinux.org/index.php?title=Arch_is_the_best&diff=321425Arch is the best2014-06-24T05:42:52Z<p>X33a: /* Translations */ Proper translation</p>
<hr />
<div>[[Category:About Arch]]<br />
[[Category:Programming language]]<br />
[[ja:Arch_is_the_best]]<br />
The '''Arch is the best''' project is a very sophisticated and exquisite, ego-boosting and mind-blowing (albeit perhaps a bit over-engineered) project which gives proof of Arch's superiority.<br />
<br />
== History ==<br />
<br />
The visionary project was originally devised in April 2008 by long time Arch community member [https://bbs.archlinux.org/profile.php?id=2529 lucke] as a simple shell script which provided irrefutable proof that "Arch is the best". It was announced to the world with a [https://bbs.archlinux.org/viewtopic.php?id=47306 forum post], thus illuminating other people's minds, who immediately started porting it to multiple different languages, both programming and verbal, so that every human being on the planet could fully appreciate and benefit from this revolutionary discovery.<br />
<br />
== Installation ==<br />
<br />
A sample PKGBUILD called {{AUR|archbest-mod1}} has been uploaded to [[AUR]].<br />
<br />
== The code ==<br />
<br />
The "Arch is the best" project is ported to many programming languages.<br />
<br />
'''Ada''' - A systems critical programming language.<br />
with Ada.Text_IO;<br />
use Ada.Text_IO;<br />
procedure ArchIsTheBest is<br />
begin<br />
Put_Line("Arch is the best!");<br />
end HelloWorld;<br />
<br />
'''APL''' - A Programming Language.<br />
'Arch is the best!'<br />
<br />
'''ATS''' - A functional programming language that uses dependent types to improve programs' reliability.<br />
implement main () = println! "Arch is the best!"<br />
<br />
'''Awk''' - A data-driven programming language designed for processing text-based data.<br />
BEGIN {<br />
print "Arch is the best!"<br />
}<br />
<br />
'''Befunge''' - Believed to be the first two-dimensional, ASCII-based, general-purpose (in the sense of "you could plausibly write Hunt the Wumpus in it") programming language.<br />
<v"Arch is the best!"0<br />
<,_@#:<br />
<br />
'''Boo''' - A stablished object oriented statically typed programming language for .NET and Mono with a python inspired syntax and a special focus on metaprogramming through language and compiler extensibility features such as macros and custom compilation pipelines.<br />
print "Arch is the best!"<br />
<br />
'''Bourne shell''' - The original program, should be compatible with any shell.<br />
#!/bin/sh<br />
echo "Arch is the best!"<br />
<br />
<br />
'''Bourne shell (Alternate)''' - Handy for piping the output to your favourite IRC/email/IM client. Should work with any shell.<br />
#!/bin/sh<br />
yes Arch is the best!<br />
<br />
<br />
'''Bourne shell (Dynamically updated)'''<br />
<pre style='overflow:auto'><br />
#!/bin/bash<br />
wget http://wiki.archlinux.org/index.php/Arch_is_the_best -qO-| sed -n ':b;n;s/id="Translations"//;Tb;:d;n;s/id="See_also"//;t;p;bd'|sed '/<i>.*<\/i>/d;s/<[^>]*>//g'|sed 'N;s/\n/: /;N;N;s/\n//g'<br />
</pre><br />
<br />
<br />
'''brainfuck''' - Doesn't the language name explain it?<br />
++>++++++>+++++<+[>[->+<]<->++++++++++<]>>.<[-]>[-<++>]<br />
<----------------.---------------.+++++.<+++[-<++++++++++>]<.<br />
>>+.++++++++++.<<.>>+.------------.---.<<.>>---.<br />
+++.++++++++++++++.+.<<+.[-]++++++++++.<br />
<br />
<br />
'''C''' - Note the three space indenting used in this project, much like that used by other superior beings.<br />
#include <stdio.h><br />
#include <stdlib.h><br />
int main(void) <br />
{<br />
puts("Arch is the best!");<br />
return EXIT_SUCCESS;<br />
}<br />
<br />
<br />
'''C#''' - Intended to be a simple, modern, general-purpose, object-oriented programming language.<br />
using System;<br />
public class ArchIsTheBest<br />
{<br />
static public void Main ()<br />
{<br />
Console.WriteLine ("Arch is the best!");<br />
}<br />
}<br />
<br />
<br />
'''C++''' - Arch == Linux++<br />
#include <iostream><br />
#include <cstdlib><br />
int main ()<br />
{<br />
std::cout << "Arch is the best!" << std::endl;<br />
return EXIT_SUCCESS;<br />
}<br />
<br />
<br />
'''COBOL''' - A simple, lightweight programming language.<br />
IDENTIFICATION DIVISION.<br />
PROGRAM-ID. TheBest.<br />
<br />
PROCEDURE DIVISION.<br />
DISPLAY "Arch is the best!".<br />
STOP RUN.<br />
<br />
<br />
'''CoffeeScript''' - A programming language that transcompiles to JavaScript.<br />
alert 'Arch is the best!'<br />
<br />
<br />
'''Clojure''' - A Lisp dialect that runs on the JVM.<br />
(def translations {"english" "Arch is the best!",<br />
"german" "Arch ist das Beste!",<br />
"australian" "Arch is fair dinkum, mate!",<br />
"h4x0r" "arhc 51 7he be57!",<br />
"spanish" "¡Arch es el mejor!"})<br />
<br />
(defn read-choice []<br />
(println "\nAvailable languages: ")<br />
(doall (map #(println (key %)) translations))<br />
(print "Enter language or Ctrl-c: ") (flush)<br />
(translations (read-line) :badinput))<br />
<br />
(defn arch-is-the-best []<br />
(loop [choice (read-choice)]<br />
(case choice<br />
:badinput (do (print "\nBad input!\n")<br />
(recur (read-choice)))<br />
(do (print "\n" choice "\n")<br />
(recur (read-choice))))))<br />
or<br />
(def translations {"english" "Arch is the best!",<br />
"german" "Arch ist das Beste!",<br />
"australian" "Arch is fair dinkum, mate!",<br />
"h4x0r" "arhc 51 7he be57!",<br />
"spanish" "¡Arch es el mejor!"<br />
"street" "Arch iz da shizzle ma nizzle"})<br />
(while 1<br />
(println "\nPick a language:\n" (map #(key %) translations) "\n language: ")<br />
(println (translations (read-line) "Not a valid language")))<br />
<br />
<br />
or<br />
(prn "Arch is the best!")<br />
<br />
'''Common Lisp''' - Tested on SBCL, feel free to add more of the translations.<br />
#!/usr/bin/sbcl --script<br />
(defparameter *best-list* '((English "Arch is the best!")<br />
(Chinese "Arch, 她出类拔萃!")<br />
(German "Arch ist das Beste!")<br />
(Greek "Το Arch είναι το καλύτερο!")))<br />
(defun aitb ()<br />
(format t "Available languages: ~{~{~@(~a~)~*~}~^, ~}.~%" *best-list*)<br />
(loop for input = (progn (format t "~&Input the desired language, (or 'quit'): ~%")<br />
(force-output)<br />
(read-line))<br />
if (string-equal input "quit")<br />
do (loop-finish)<br />
else<br />
do (let ((language-def<br />
(assoc input *best-list*<br />
:key (lambda (lang) (symbol-name lang))<br />
:test #'string-equal)))<br />
(if language-def<br />
(format t "~&~A~%" (second language-def))<br />
(format t "~&Invalid language.~%"))))<br />
(format t "~&May the Arch be with you!~%"))<br />
(aitb)<br />
<br />
<br />
'''Common Lisp (Alternate)''' - Should run on any implementation (Clisp, Allegro, SBCL...)<br />
(princ "Arch is the best!")<br />
<br />
<br />
'''D''' - A C-style language. The benefits of hindsight, with modern conveniences.<br />
import std.stdio : writeln;<br />
void main()<br />
{<br />
writeln("Arch is the best");<br />
}<br />
<br />
<br />
'''Dart''' - Google's javascript killer<br />
main(){<br />
print('Arch is the best');<br />
}<br />
<br />
'''Emacs Lisp''' - A dialect of the Lisp programming language used by the GNU Emacs and XEmacs text editors <br />
(message "Arch is the best!")<br />
<br />
<br />
'''Erlang''' - A concurrent, garbage-collected programming language and runtime system.<br />
-module(arch).<br />
-export([is_the_best/0]).<br />
is_the_best() -> io:fwrite("Arch is the best!\n").<br />
<br />
Or using message passing between processes<br />
<br />
-module(arch).<br />
-export([ultimate_question/0,the_answer/0]).<br />
the_answer() -><br />
receive<br />
{Client,who_is_the_best} -><br />
Client ! {self(),"Arch is the best!"};<br />
{Client,_} -><br />
Client ! {self(),"Taco Taco Taco!"}<br />
end,<br />
the_answer().<br />
ultimate_question() -><br />
Pid = spawn(arch,the_answer,[]),<br />
Pid ! {self(),who_is_the_best},<br />
receive<br />
{Pid,Response} -> io:format("~s~n",[Response])<br />
end.<br />
<br />
'''F#''' - A strongly-typed, functional-first programming language for writing simple code to solve complex problems.<br />
printfn "Arch is the best!"<br />
<br />
'''Factor''' - High-level stack-based language.<br />
"Arch is the best" print<br />
<br />
'''FIM++''' - A wordy, imperative, dynamically-typed, and interpreted language that can use Java classes.<br />
Dear Princess Celestia: Letter About Arch Linux.<br />
Today I learned:<br />
I wrote "Arch is the best!".<br />
Your faithful student, Twilight Sparkle<br />
<br />
'''Forth''' - Stack-based language.<br />
." Arch is the best" cr -- kiss way<br />
<br />
'''Fortran95'''<br />
program arch<br />
print *,"Arch is the best!"<br />
end program arch<br />
<br />
'''Genie''' - A new programming language, that allows for a more modern programming style while being able to effortlessly create and use GObjects natively. <br />
init<br />
print "Arch is the best"<br />
<br />
<br />
'''Gjs''' - A Javascript binding for GNOME. It's mainly based on Spidermonkey javascript engine and the GObject introspection framework.<br />
#!/usr/bin/env gjs<br />
print ('Arch is the best');<br />
<br />
<br />
'''Go''' - A language created by Google that's a love child between C, C++ and Python.<br />
package main<br />
<br />
import "fmt"<br />
<br />
func main() {<br />
fmt.Println("Arch is the best!")<br />
}<br />
<br />
<br />
'''Haskell''' - The language where IO is easy and unproblematic.<br />
main = putStrLn "Arch is the best!"<br />
<br />
<br />
'''HTML''' - A markup language used to create and define web pages and their content.<br />
<pre><br />
<!DOCTYPE html><br />
<html lang='en'><br />
<head><br />
<title>Arch is the best!</title><br />
</head><br />
<body><br />
<p>Arch is the best!</p><br />
</body><br />
</html><br />
</pre><br />
<br />
'''Io'''<br />
"Arch is the best!" println<br />
<br />
<br />
'''Java''' - An extremely portable language, this will run on pretty much anything, it might even run on your toaster!<br />
public class ArchIsTheBest {<br />
public static void main(String[] args) {<br />
System.out.println("Arch is the best!");<br />
}<br />
}<br />
<br />
<br />
'''JavaScript''' - Also known as ECMAScript, a prototype-based object-oriented scripting language. <br />
console.log('Arch is the best!');<br />
<br />
<br />
'''JavaScript (in a web browser)'''<br />
alert('Arch is the best!');<br />
<br />
<br />
'''LilyPond''' - A powerful music engraving program with an intuitive LaTeX-like input language.<br />
\version "2.12.3"<br />
\include "english.ly"<br />
\header { title = "Arch is the best!" }<br />
\score<br />
{<br />
<<<br />
\relative c' { c4 e g c \bar "||" }<br />
\addlyrics { Arch is the best! }<br />
>><br />
}<br />
<br />
<br />
'''LOLCODE''' - Why not?<br />
HAI<br />
CAN HAS STDIO?<br />
VISIBLE "ARCH IS TEH PWNZ LOL!"<br />
KTHXBYE<br />
<br />
<br />
'''Lua''' - A lightweight, extensible programming language.<br />
print "Arch is the best!"<br />
<br />
'''Morpho''' - Morpho is a multi-paradigm programming language that supports procedural, object-oriented and functional programming. <br />
<br />
writeln("Arch is the best!");<br />
<br />
<br />
'''Nasm(x86_64) (or yasm)''' - Notice that the string is in the .text section, which feels superior<br />
<br />
;nasm -f elf64 arch.asm<br />
;ld -o arch arch.o<br />
;./arch<br />
<br />
section .text<br />
global _start<br />
_start:<br />
mov edx,len<br />
mov ecx,msg<br />
mov ebx,1<br />
mov eax,4<br />
int 0x80<br />
xor ebx,ebx<br />
mov eax,1<br />
int 0x80<br />
msg: db "Arch is the best!",10<br />
len equ $-msg<br />
<br />
<br />
'''Nimrod''' - Portable lightweight programming language.<br />
echo "Arch is the best!"<br />
<br />
<br />
'''Objective-C''' - A reflective, object-oriented programming language that adds Smalltalk-style messaging to the C programming language.<br />
NSLog(@"Arch is the best!");<br />
<br />
<br />
'''OCaml''' - The main implementation of the Caml programming language.<br />
print_endline "Arch is the best!"<br />
<br />
'''Octave''' - High-level interpreted language, primarily intended for numerical computations.<br />
printf("Arch is the best!\n")<br />
<br />
'''Ook!''' - brainfuck, translated to Orangutan<br />
Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook. Ook. Ook! Ook? Ook. Ook? Ook! Ook? Ook! Ook! Ook. Ook? Ook. Ook. Ook? Ook. Ook? Ook! Ook? Ook. Ook! Ook! Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook. Ook? Ook! Ook. Ook? Ook. Ook? Ook! Ook. Ook? Ook. Ook! Ook? Ook! Ook! Ook? Ook! Ook. Ook? Ook! Ook? Ook! Ook! Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook? Ook! Ook? Ook. Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook. Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook? Ook! Ook! Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook? Ook! Ook? Ook. Ook! Ook. Ook. Ook? Ook. Ook? Ook. Ook. Ook! Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook. Ook? Ook. Ook? Ook. Ook! Ook. Ook. Ook? Ook. Ook? Ook. Ook. Ook! Ook. Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook. Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook. Ook? Ook. Ook? Ook. Ook! Ook. Ook. Ook? Ook. Ook? Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook. Ook. Ook. Ook! Ook. Ook? Ook. Ook? Ook. Ook. Ook. Ook! Ook. Ook! Ook? Ook! Ook! Ook? Ook! Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook.<br />
<br />
'''Perl''' - A high-level, general-purpose, interpreted, dynamic programming language.<br />
#!/usr/bin/perl<br />
print "Arch is the best!\n";<br />
<br />
<br />
'''PHP''' - A general-purpose scripting language.<br />
<?php<br />
echo "Arch is the best!\n";<br />
?> <br />
<br />
<br />
'''Pixilang''' - Make me pixels.<br />
print("Arch is the best!",0,0,#1897D1)<br />
frame<br />
<br />
<br />
'''Portable GNU assembler''' - as -o arch.o arch.s && ld -o arch -O0 arch.o<br />
<br />
.section .data<br />
archIsBest: <br />
.ascii "Arch is the best!\n"<br />
archIsBest_len:<br />
.long . - archIsBest<br />
.section .text<br />
.globl _start<br />
_start:<br />
xorl %ebx, %ebx<br />
movl $4, %eax <br />
xorl %ebx, %ebx<br />
incl %ebx <br />
leal archIsBest, %ecx<br />
movl archIsBest_len, %edx <br />
int $0x80 <br />
xorl %eax, %eax<br />
incl %eax<br />
xorl %ebx, %ebx <br />
int $0x80<br />
<br />
<br />
'''Processing''' - An open source programming language and IDE built for the electronic arts and visual design.<br />
println("Arch is the best!");<br />
<br />
<br />
'''Prolog''' - A general purpose logic programming language associated with artificial intelligence and computational linguistics.<br />
format('Arch is the best~n',[]).<br />
<br />
<br />
'''Python''' - A general-purpose high-level programming language.<br />
#!/usr/bin/env python3<br />
print('Arch is the best!')<br />
<br />
<br />
'''QBASIC''' - An interpreter for a variant of the BASIC programming language which is based on QuickBASIC.<br />
PRINT "Arch is the best!"<br />
<br />
<br />
'''R''' - A language for statistical computing (and much more!).<br />
archIsBest <- function() { cat("Arch is the best!\n") }<br />
archIsBest()<br />
<br />
<br />
'''Ruby''' - A dynamic, reflective, general purpose object-oriented programming language.<br />
#!/usr/bin/ruby -w<br />
puts 'Arch is the best!'<br />
<br />
<br />
'''Scala''' - A multi paradigm language that runs on the JVM<br />
object ArchIsBest extends App {<br />
println("Arch is the best!")<br />
} <br />
<br />
<br />
<br />
'''Scheme''' - A dialect of Lisp.<br />
(display "Arch is the best!\n")<br />
or in XunDu style<br />
#!/usr/bin/guile1.8 -s<br />
!#<br />
(define 节 or)<br />
(define 哀 #t)<br />
(define (xi) (display "Arch is the best!\n"))<br />
(节 (xi) 哀 (wen) 顺 (le) 变 (jian) )<br />
<br />
<br />
'''Seed''' - A library and interpreter, dynamically bridging the WebKit JavaScriptCore engine, with the GNOME platform.<br />
#!/usr/bin/env seed<br />
print ('Arch is the best');<br />
<br />
<br />
'''Shoes''' - A Ruby version using Shoes for a GUI<br />
Shoes.app :width => 135, :height => 30 do <br />
para "Arch is the Best!"<br />
end<br />
<br />
<br />
'''SQL''' - Structured Query Language, the query language for relational databases<br />
SELECT 'Arch is the best!';<br />
SELECT 'Arch is the best!' from dual; -- for Oracle DB<br />
<br />
<br />
'''Standard ML''' - A general-purpose, modular, functional programming language with compile-time type checking and type inference.<br />
print "Arch is the best!\n"<br />
<br />
<br />
'''Tcl/Tk''' - A scripting language that is commonly used for rapid prototyping, scripted applications, GUIs and testing.<br />
#!/usr/bin/env tclsh<br />
puts "Arch is the best!"<br />
<br />
<br />
'''Vala''' - "Vala is a new programming language that aims to bring modern programming language features to GNOME developers without imposing any additional runtime requirements and without using a different ABI compared to applications and libraries written in C"<br />
void main(string[] args) {<br />
stdout.printf("\nArch is the best!\n\n");<br />
}<br />
<br />
<br />
''' Wiring (Arduino)''' - Built on Processing, the open source programming language developed at the Massachusetts Institute of Technology.<br />
void setup() <br />
{<br />
Serial.begin(9600); <br />
}<br />
void loop() <br />
{ <br />
Serial.print("Arch is the best!");<br />
}<br />
<br />
<br />
''' X11 ''' - X11 is an architecture independent system for display of graphical user interfaces.<br />
#include <stdio.h><br />
#include <stdlib.h><br />
#include <string.h><br />
<br />
#include <X11/Xlib.h><br />
<br />
int main()<br />
{<br />
Display *d;<br />
Window w;<br />
XEvent e;<br />
int s;<br />
<br />
if (!(d = XOpenDisplay(NULL))) {<br />
fprintf(stderr, "Couldn't open display, but Arch is the best!\n");<br />
exit(1);<br />
}<br />
<br />
s = DefaultScreen(d);<br />
w = XCreateSimpleWindow(d, RootWindow(d,s), 0, 0, 110, 20, 0, <br />
0, WhitePixel(d,s));<br />
XSelectInput(d, w, ExposureMask | KeyPressMask);<br />
XMapWindow(d,w);<br />
<br />
while (1) {<br />
XNextEvent(d, &e);<br />
if (e.type == Expose) {<br />
XDrawString(d, w, DefaultGC(d, s), 5, 15, "Arch is the best!", 17);<br />
}<br />
}<br />
<br />
XCloseDisplay(d);<br />
return 0;<br />
}<br />
<br />
==Translations==<br />
<br />
'''Ancient Chinese'''<br />
阿祺,盡善矣。<br />
<br />
'''Ancient Greek'''<br />
Ἡ Ἀψίς ἄριστη ἐστί!<br />
<br />
'''Arabic'''<br />
ارتش هو الأفضل<br />
<br />
'''Australian'''<br />
Arch is fair dinkum, mate!<br />
<br />
'''Bahasa Indonesia'''<br />
Arch terbaik!<br />
<br />
'''Basque'''<br />
Arch onena da!<br />
<br />
'''Belarusian'''<br />
Арч - самы лепшы!<br />
<br />
'''Bengali'''<br />
আর্চ সবচেয়ে ভালো!<br />
<br />
'''British'''<br />
Arch is simply spiffing.<br />
<br />
'''Bulgarian'''<br />
Арч е най-добрият!<br />
<br />
'''Catalan'''<br />
Arch és el millor!<br />
<br />
'''Chinese (Simplified)'''<br />
Arch 最棒了!<br />
<br />
'''Chinese (Tranditional)'''<br />
狀哉我大 Arch!<br />
<br />
'''Chinese (Taobao Style - 淘宝体)'''<br />
Arch,好评哦,亲!<br />
<br />
'''Czech'''<br />
Arch je nejlepší!<br />
<br />
'''Croatian'''<br />
Arch je najbolji!<br />
<br />
'''Danish'''<br />
Arch er bedst!<br />
<br />
'''Dutch'''<br />
Arch is de beste!<br />
<br />
'''Esperanto'''<br />
Arch plejbonas!<br />
<br />
'''Estonian'''<br />
Arch on parim!<br />
<br />
'''Fikonspråket'''<br />
Firch Arkon fir äkon fist bäkon<br />
<br />
'''Filipino'''<br />
Mabuhay ang Arch!<br />
<br />
'''Finnish'''<br />
Arch on paras!<br />
<br />
'''French'''<br />
Arch est le meilleur!<br />
<br />
'''Galician'''<br />
Arch é o mellor!<br />
<br />
'''German'''<br />
Arch ist das Beste!<br />
<br />
'''Greek (Modern)'''<br />
Το Αρτς είναι το καλύτερο!<br />
<br />
'''Haitian Creole'''<br />
Arch se meye bagay!<br />
<br />
'''Hantec'''<br />
Arch je nejbetélnější!<br />
<br />
'''Hebrew'''<br />
ארצ' זה הכי אחי!<br />
<br />
'''Hindi'''<br />
आर्च सर्वोत्तम है ।<br />
<br />
'''Hungarian'''<br />
Az Arch a legjobb!<br />
<br />
'''Irish'''<br />
Arch é is fearr!<br />
<br />
'''Italian'''<br />
Arch è il migliore!<br />
<br />
'''Japanese'''<br />
Archが一番ですよ!<br />
<br />
'''Kazakh'''<br />
Арч - ең жақсы!<br />
<br />
'''Klingon'''<br />
Arch'pu'ta' 'a'<br />
<br />
'''Latin'''<br />
Arch optimus est!<br />
<br />
'''Latvian'''<br />
Arch ir labākais!<br />
<br />
'''Lithuanian'''<br />
Arch yra geriausias!<br />
<br />
'''Lojban'''<br />
la .artc. xagrai<br />
<br />
'''Malayalam'''<br />
ആർച് ആണ് ഏറ്റവും നല്ലത് <br />
<br />
'''Marathi'''<br />
आर्च सगळ्यात भारी आहे!<br />
<br />
'''Norwegian'''<br />
Arch er best!<br />
<br />
'''Old English'''<br />
Arch biþ betst!<br />
<br />
'''Persian'''<br />
طاق بزرگ است<br />
<br />
'''Pig Latin'''<br />
Archway isway ethay estbay!<br />
<br />
'''Polish'''<br />
Arch jest najlepszy!<br />
<br />
'''Portuguese'''<br />
Arch é o melhor!<br />
<br />
'''Québécois'''<br />
Arch est le plus meilleure du monde!<br />
<br />
'''Romanian'''<br />
Аrch e cel mai bun!<br />
<br />
'''Russian'''<br />
Арч — лучший!<br />
<br />
'''Serbian'''<br />
Arch je najbolji!<br />
<br />
'''Singaporean'''<br />
Arch the best lah!<br />
<br />
'''Slovenian'''<br />
Arch je najboljši!<br />
<br />
'''Spanish (Standard)'''<br />
¡Arch es el mejor!<br />
<br />
'''Spanish (Argentina)'''<br />
Arch es una mazza!!<br />
<br />
'''Spanish (Chile)'''<br />
Arch es bacán<br />
<br />
'''Spanish (Chile, low class)'''<br />
Arch es la raja<br />
<br />
'''Spanish (Chile, marginal)'''<br />
This are writted in IPA because standard spanish not have those sounds<br />
ˈæɹʃ ɛːʰ tɜ.rˈiː.u.lɛ la rˈa.χa ʃʊ.ɹʊ<br />
<br />
'''Spanish (Uruguay)'''<br />
Arch la rompe!<br />
<br />
'''Swedish'''<br />
Arch är bäst!<br />
<br />
'''Turkish'''<br />
Arch en iyisidir!<br />
<br />
'''Tamil'''<br />
ஆர்ச்சே சிறந்தது!<br />
<br />
'''Telugu'''<br />
ఆర్చ్ ఉత్తమమైనది!<br />
<br />
'''Ukrainian'''<br />
Arch є найкращий!<br />
<br />
'''Urdu'''<br />
آرچ سب سے بہتر ہے! <br />
<br />
'''Vietnamese'''<br />
Arch là tốt nhất!<br />
<br />
'''Welsh (Cymraeg)'''<br />
<br />
Emphasis on Arch:<br />
Arch sydd yr orau un!<br />
Arch sydd y gorau un!<br />
<br />
Emphasis on being the best (one):<br />
Yr orau un yw Arch!<br />
Y gorau un yw Arch!<br />
<br />
== Encodings ==<br />
<br />
'''Base64'''<br />
QXJjaCBpcyB0aGUgYmVzdCEK<br />
<br />
'''Binary ASCII'''<br />
0100000101110010011000110110100000100000011010010111001100100000011101000110100001100101001000000110001001100101011100110111010000100001<br />
<br />
'''Braille'''<br />
⠁⠗⠉⠓⠀⠊⠎⠀⠮⠀⠃⠑⠎⠞⠲<br />
<br />
'''Desrever (Reversed)'''<br />
!tseb eht si hcrA<br />
<br />
'''h4x0r'''<br />
Arch 15 7h3 b357!<br />
<br />
'''Hexadecimal ASCII'''<br />
4172636820697320746865206265737421<br />
<br />
'''md5sum'''<br />
2d9092e089d77a8e23f47ba3dfe77027<br />
<br />
'''Morse Code'''<br />
.- .-. -.-. .... .. ... - .... . -... . ... -<br />
<br />
'''ROT13'''<br />
Nepu vf gur orfg!<br />
<br />
'''Upside Down'''<br />
¡ʇsǝq ǝɥʇ s! ɥɔɹ∀<br />
<br />
'''URL Encoded'''<br />
Arch%20is%20the%20best!</div>X33ahttps://wiki.archlinux.org/index.php?title=Nftables&diff=309476Nftables2014-04-09T13:15:39Z<p>X33a: logging to syslog</p>
<hr />
<div>{{DISPLAYTITLE:nftables}}<br />
[[Category:Firewalls]]<br />
[[ja:Nftables]]<br />
{{Related articles start}}<br />
{{Related|Firewalls}}<br />
{{Related|iptables}}<br />
{{Related articles end}}<br />
[http://netfilter.org/projects/nftables/ nftables] is a netfilter project that aims to replace the existing ip-, ip6-, arp-, and ebtables framework. It provides a new packet filtering framework, a new user-space utility (nft), and a compatibility layer for ip- and ip6tables. It uses the existing hooks, connection tracking system, user-space queueing component, and logging subsystem of netfilter.<br />
<br />
The first release is available in Linux 3.13, which is in the ''core'' repository ({{Pkg|linux}}), and nftables (the user-space components) is available in the ''community'' repository ({{Pkg|nftables}}), and on the [[AUR]] in package {{AUR|nftables-git}}.<br />
<br />
{{Expansion|nftables is an entirely new utility, and lacks sufficient documentation on this wiki, as well as elsewhere.}}<br />
<br />
==Overview==<br />
nftables consists of three main components: a kernel implementation, the libnl netlink communication and the nftables user-space front-end. The kernel provides a netlink configuration interface, as well as run-time rule-set evaluation using a small classification language interpreter. libnl contains the low-level functions for communicating with the kernel; the nftables front-end is what the user interacts with.<br />
<br />
==nft==<br />
nftables' user-space utility {{ic|nft}} now performs most of the rule-set evaluation before handing rule-sets to the kernel. Because of this, nftables provides no default tables or chains; although, a user can emulate an iptables-like setup.<br />
<br />
It works in a fashion similar to ifconfig or iproute2. The commands are a long, structured sequence rather than using argument switches like in iptables. For example:<br />
nft add rule ip6 filter input ip saddr ::1 accept<br />
{{ic|add}} is the command. {{ic|rule}} is a subcommand of {{ic|add}}. {{ic|ip6}} is an argument of {{ic|rule}}, telling it to use the ip6 family. {{ic|filter}} and {{ic|input}} are arguments of {{ic|rule}} specifying the table and chain to use, respectively. The rest that follows is a rule definition, which includes matches ({{ic|ip}}), their parameters ({{ic|saddr}}), parameter arguments ({{ic|::1}}), and jumps ({{ic|accept}}).<br />
<br />
The following is an incomplete list of the commands available in nft:<br />
<nowiki><br />
list<br />
tables [family]<br />
table [family] <name><br />
chain [family] <table> <name><br />
<br />
add<br />
table [family] <name><br />
chain [family] <table> <name> [chain definitions]<br />
rule [family] <table> <chain> <rule definition><br />
<br />
table [family] <name> (shortcut for `add table`)<br />
<br />
insert<br />
rule [family] <table> <chain> <rule definition><br />
<br />
delete<br />
table [family] <name><br />
chain [family] <table> <name><br />
rule [family] <table> <handle><br />
<br />
flush<br />
table [family] <name><br />
chain [family] <table> <name></nowiki><br />
{{ic|family}} is optional, but it will default to {{ic|ip}}.<br />
<br />
==Tables==<br />
The purpose of tables is to hold chains. Unlike tables in iptables, there are no built-in tables in nftables. Tables can have one of four families specified, which unifies the various iptables utilities into one:<br />
*ip (iptables)<br />
*ip6 (ip6tables)<br />
*arp (arptables)<br />
*bridge (ebtables)<br />
{{ic|ip}} is the default family.<br />
A fifth family is scheduled for Linux 3.15 that allows for the unification of the ip and ip6 families to make defining rules for both easier.<br />
<br />
===Listing===<br />
You can list the current tables in a family with the {{ic|nft list}} command.<br />
# nft list tables<br />
# nft list tables ip6<br />
<br />
You can list a full table definition by specifying a table name:<br />
# nft list table foo<br />
# nft list table ip6 foo<br />
<br />
===Creation===<br />
Tables can be added via two commands — one just being a shortcut for the other. Here is an example of how to add an ip table called foo and an ip6 table called foo:<br />
# nft add table foo<br />
# nft table ip6 foo<br />
You can have two tables with the same name as long as they are in different families.<br />
<br />
===Deletion===<br />
Tables can only be deleted if there are no chains in them.<br />
# nft delete table foo<br />
# nft delete table ip6 foo<br />
<br />
==Chains==<br />
The purpose of chains is to hold rules. Unlike chains in iptables, there are no built-in chains in nftables. This means that if no chain uses any types or hooks in the netfilter framework, packets that would flow through those chains will not be touched by nftables, unlike iptables.<br />
<br />
===Listing===<br />
You can list the current chains in a chain with the {{ic|nft list}} command, using the same method as listing a table. You can also list rules from an individual chain.<br />
# nft list chain foo bar<br />
# nft list chain ip6 foo bar<br />
These commands will list the {{ic|bar}} chains in the ip and ip6 {{ic|foo}} tables.<br />
<br />
===Creation===<br />
Chains can be added when a table is created in a file definition or one at time via the {{ic|nft add chain}} command.<br />
# nft add chain foo bar<br />
# nft add chain ip6 foo bar<br />
These commands will add a chain called {{ic|bar}} to the ip and ip6 {{ic|foo}} tables.<br />
<br />
====Properties====<br />
Because nftables has no built-in chains, it allows chains to access certain features of the netfilter framework.<br />
# nft add chain filter input { type filter hook input priority 0; }<br />
This command tells nftables to add a chain called {{ic|input}} to the {{ic|filter}} table and defines its type, hook, and priority. These properties essentially replace the built-in tables and chains in iptables.<br />
<br />
=====Types=====<br />
There are three types a chain can have and they correspond to the tables used in iptables:<br />
*filter<br />
*nat<br />
*route (mangle)<br />
<br />
=====Hooks=====<br />
There are five hooks a chain can use and they correspond to the chains used in iptables:<br />
*input<br />
*output<br />
*forward<br />
*prerouting<br />
*postrouting<br />
<br />
=====Priorities=====<br />
{{Note|Priorities do not currently appear to have any effect on which chain sees packets first.}}<br />
{{Note|Since the priority seems to be an unsigned integer, negative priorities will be converted into very high priorities.}}<br />
Priorities tell nftables which chains packets should pass through first. They are integers, and the higher the integer, the higher the priority.<br />
<br />
===Deletion===<br />
Chains can only be deleted if there are no rules in them.<br />
# nft delete chain foo bar<br />
# nft delete chain ip6 foo bar<br />
These commands delete the {{ic|bar}} chains from the ip and ip6 {{ic|foo}} tables.<br />
<br />
==Rules==<br />
The purpose of rules is to identify packets (match) and carry out tasks (jump). Like in iptables, there are various matches and jumps available, though not all of them are feature-complete in nftables.<br />
<br />
===Listing===<br />
You can list the current rules in a table with the {{ic|nft list}} command, using the same method as listing a table. You can also list rules from an individual chain.<br />
# nft list chain foo bar<br />
# nft list chain ip6 foo bar<br />
These commands will list the rules in the {{ic|bar}} chains in the ip and ip6 {{ic|foo}} tables.<br />
<br />
===Creation===<br />
Rules can be added when a table is created in a file definition or one at time via the {{ic|nft add rule}} command.<br />
# nft add rule foo bar ip saddr 127.0.0.1 accept<br />
# nft add rule ip6 foo bar ip saddr ::1 accept<br />
These commands will add a rule to the {{ic|bar}} chains in the ip and ip6 {{ic|foo}} tables that matches an {{ic|ip}} packet when its {{ic|saddr}} (source address) is 127.0.0.1 (IPv4) or ::1 (IPv6) and accepts those packets.<br />
<br />
====Matches====<br />
There are various matches available in nftables and, for the most part, coincide with their iptables counterparts. The most noticeable difference is that there are no generic or implicit matches anymore. A generic match was one that was always available, such as {{ic|--protocol}} or {{ic|--source}}. Implicit matches were protocol-specific, such as {{ic|--sport}} when a packet was determined to be TCP.<br />
<br />
The following is an incomplete list of the matches available:<br />
*meta (meta properties, e.g. interfaces)<br />
*icmp (ICMP protocol)<br />
*icmpv6 (ICMPv6 protocol)<br />
*ip (IP protocol)<br />
*ip6 (IPv6 protocol)<br />
*tcp (TCP protocol)<br />
*udp (UDP protocol)<br />
*sctp (SCTP protocol)<br />
*ct (connection tracking)<br />
<br />
The following is an incomplete list of match arguments:<br />
<nowiki><br />
meta:<br />
oif <output interface INDEX><br />
iif <input interface INDEX><br />
oifname <output interface NAME><br />
iifname <input interface NAME><br />
<br />
(oif and iif accept string arguments and are converted to interface indexes)<br />
(oifname and iifname are more dynamic, but slower because of string matching)<br />
<br />
icmp:<br />
type <icmp type><br />
<br />
icmpv6:<br />
type <icmpv6 type><br />
<br />
ip:<br />
protocol <protocol><br />
daddr <destination address><br />
saddr <source address><br />
<br />
ip6:<br />
daddr <destination address><br />
saddr <source address><br />
<br />
tcp:<br />
dport <destination port><br />
sport <source port><br />
<br />
udp:<br />
dport <destination port><br />
sport <source port><br />
<br />
sctp:<br />
dport <destination port><br />
sport <source port><br />
<br />
ct:<br />
state <new | established | related | invalid></nowiki><br />
<br />
====Jumps====<br />
Jumps work the same as they do in iptables, except multiple jumps can now be used in one rule.<br />
# nft add rule filter input tcp dport 22 log accept<br />
<br />
The following is an incomplete list of jumps:<br />
*accept (accept a packet)<br />
*reject (reject a packet)<br />
*drop (drop a packet)<br />
*snat (perform source NAT on a packet)<br />
*dnat (perform destination NAT on a packet)<br />
*log (log a packet)<br />
*counter (keep a counter on a packet; counters are optional in nftables)<br />
*return (stop traversing the chain)<br />
<br />
===Insertion===<br />
Rules can be prepended to chains with the {{ic|nft insert rule}} command.<br />
# nft insert rule filter input ct state established,related accept<br />
<br />
===Deletion===<br />
Individual rules can only be deleted by their handles. The {{ic|nft --handle list}} command must be used to determine rule handles. Note the {{ic|--handle}} switch, which tells {{ic|nft}} to list handles in its output.<br />
<br />
The following determines the handle for a rule and then deletes it. The {{ic|--number}} argument is useful for viewing some numeric output, like unresolved IP addresses.<br />
{{hc|# nft --handle --numeric list chain filter input|2=<br />
<nowiki><br />
table ip filter {<br />
chain input {<br />
type filter hook input priority 0;<br />
ip saddr 127.0.0.1 accept # handle 10<br />
}<br />
}<br />
</nowiki><br />
}}<br />
# nft delete rule filter input handle 10<br />
<br />
All the chains in a table can be flushed with the {{ic|nft flush table}} command. Individual chains can be flushed using either the {{ic|nft flush chain}} or {{ic|nft delete rule}} commands.<br />
# nft flush table foo<br />
# nft flush chain foo bar<br />
# nft delete rule ip6 foo bar<br />
The first command flushes all of the chains in the ip {{ic|foo}} table. The second flushes the {{ic|bar}} chain in the ip {{ic|foo}} table. The third deletes all of the rules in {{ic|bar}} chain in the ip6 {{ic|foo}} table.<br />
<br />
==File Definitions==<br />
{{Warning|The {{ic|nft -f}} command, despite what the [http://people.netfilter.org/wiki-nftables/index.php/Atomic_rule_replacement netfilter wiki] says, is '''NOT''' atomic. This means you will have a small window between deleting the old tables and when the new ruleset is loaded where all packets will be accepted.}}<br />
{{Note|You must delete all conflicting tables before using the {{ic|nft -f}} command.}}<br />
File definitions can be used by the {{ic|nft -f}} command, which acts like the {{ic|iptables-restore}} command.<br />
{{hc|/etc/nftables/filter.rules|2=<br />
<nowiki><br />
table ip filter {<br />
chain input {<br />
type filter hook input priority 0;<br />
ct state established,related accept<br />
ip saddr 127.0.0.1 accept<br />
tcp dport 22 log accept<br />
reject<br />
}<br />
}<br />
</nowiki><br />
}}<br />
<br />
==Getting Started==<br />
To get an [[iptables]]-like chain set up, you will first need to use the provided IPv4 filter file:<br />
<br />
# nft -f /etc/nftables/ipv4-filter<br />
<br />
To list the resulting chain:<br />
<br />
# nft list table filter<br />
<br />
Drop output to a destination:<br />
<br />
# nft add rule ip filter output ip daddr 1.2.3.4 drop<br />
<br />
Drop packets destined for local port 80:<br />
<br />
# nft add rule ip filter input tcp dport 80 drop<br />
<br />
Delete all rules in a chain:<br />
<br />
# nft delete rule filter output<br />
<br />
==Samples==<br />
===Simple IP/IPv6 Firewall===<br />
{{hc|firewall.rules|2=<br />
<nowiki><br />
# A simple firewall<br />
<br />
table firewall {<br />
chain incoming {<br />
type filter hook input priority 0;<br />
<br />
# established/related connections<br />
ct state {established, related} accept<br />
<br />
# invalid connections<br />
ct state invalid drop<br />
<br />
# loopback interface<br />
iifname lo accept<br />
<br />
# icmp<br />
ip protocol icmp accept<br />
<br />
# open tcp ports: sshd (22), httpd (80)<br />
tcp dport {ssh, http} accept<br />
<br />
# everything else<br />
reject<br />
}<br />
}<br />
<br />
table ip6 firewall {<br />
chain incoming {<br />
type filter hook input priority 0;<br />
<br />
# established/related connections<br />
ct state {established, related} accept<br />
<br />
# invalid connections<br />
ct state invalid drop<br />
<br />
# loopback interface<br />
iifname lo accept<br />
<br />
# icmp<br />
ip6 nexthdr icmpv6 accept<br />
<br />
# open tcp ports: sshd (22), httpd (80)<br />
tcp dport {ssh, http} accept<br />
<br />
# everything else<br />
reject<br />
}<br />
}<br />
</nowiki><br />
}}<br />
<br />
===Limit rate and tcp flags IP/IPv6 Firewall===<br />
{{hc|firewall.2.rules|2=<br />
<nowiki><br />
table firewall {<br />
chain incoming {<br />
type filter hook input priority 0;<br />
<br />
# bad tcp -> avoid network scanning:<br />
tcp flags & (fin|syn) == (fin|syn) drop<br />
tcp flags & (syn|rst) == (syn|rst) drop<br />
tcp flags & (fin|syn|rst|psh|ack|urg) < (fin) drop # == 0 would be better, not supported yet.<br />
tcp flags & (fin|syn|rst|psh|ack|urg) == (fin|psh|urg) drop<br />
<br />
# no ping floods:<br />
ip protocol icmp limit rate 10/second accept<br />
ip protocol icmp drop<br />
<br />
ct state {established, related} accept<br />
ct state invalid drop<br />
<br />
iifname lo accept<br />
<br />
# avoid brute force on ssh:<br />
tcp dport {ssh} limit rate 15/minute accept<br />
<br />
reject<br />
}<br />
}<br />
<br />
table ip6 firewall {<br />
chain incoming {<br />
type filter hook input priority 0;<br />
<br />
# bad tcp:<br />
tcp flags & (fin|syn) == (fin|syn) drop<br />
tcp flags & (syn|rst) == (syn|rst) drop<br />
tcp flags & (fin|syn|rst|psh|ack|urg) < (fin) drop # == 0 would be better, not supported yet.<br />
tcp flags & (fin|syn|rst|psh|ack|urg) == (fin|psh|urg) drop<br />
<br />
# no ping floods:<br />
ip6 nexthdr icmpv6 limit rate 10/second accept<br />
ip6 nexthdr icmpv6 drop<br />
<br />
ct state {established, related} accept<br />
ct state invalid drop<br />
<br />
# loopback interface<br />
iifname lo accept<br />
<br />
# avoid brute force on ssh:<br />
tcp dport {ssh} limit rate 15/minute accept<br />
<br />
reject<br />
}<br />
}<br />
</nowiki><br />
}}<br />
<br />
===Priority-based Atomic Fix===<br />
If priorities ever actually take effect, this may be a workaround for {{ic|nft -f}}'s lack of true atomicness (being able to replace all the current rules with new ones in one go):<br />
{{hc|atomic.rules|2=<br />
table atomic {<br />
chain incoming {<br />
type filter hook input priority 0;<br />
ct state new reject<br />
}<br />
}<br />
<br />
table ip6 atomic {<br />
chain incoming {<br />
type filter hook input priority 0;<br />
ct state new reject<br />
}<br />
}<br />
}}<br />
Set the priority of other chains that hook input to higher than 0. This should block new connections while no other input chains are loaded.<br />
<br />
===Rules Script with Atomic Fix===<br />
Because using {{ic|nft -f}} to reload rulesets is time consuming, it's far easier to script it. This will include an atomic fix not based on priorities. It uses the two rules files from above.<br />
{{hc|firewall.sh|2=<br />
#!/bin/sh<br />
<br />
# Load atomic rules first<br />
nft -f atomic.rules<br />
<br />
# New incoming traffic should now be stopped<br />
<br />
# Get rid of both the ip and ip6 firewall tables<br />
<br />
nft flush table firewall 2>/dev/null<br />
nft delete chain firewall incoming 2>/dev/null<br />
nft delete table firewall 2>/dev/null<br />
<br />
nft flush table ip6 firewall 2>/dev/null<br />
nft delete chain ip6 firewall incoming 2>/dev/null<br />
nft delete table ip6 firewall 2>/dev/null<br />
<br />
# Reload the firewall rules<br />
nft -f firewall.rules<br />
<br />
# Get rid of both the ip and ip6 atomic tables<br />
<br />
nft flush table atomic 2>/dev/null<br />
nft delete chain atomic incoming 2>/dev/null<br />
nft delete table atomic 2>/dev/null<br />
<br />
# New incoming IP traffic should be working<br />
<br />
nft flush table ip6 atomic 2>/dev/null<br />
nft delete chain ip6 atomic incoming 2>/dev/null<br />
nft delete table ip6 atomic 2>/dev/null<br />
<br />
# New incoming IPv6 traffic should be working<br />
}}<br />
This should take anywhere from 100ms to 400ms, which is clearly unacceptable, but the only apparent solution.<br />
<br />
==Loading rules at boot==<br />
<br />
To automatically load rules on system boot, {{AUR|nftables-systemd-git}} can be used.<br />
Further install instructions can be found on the corresponding [https://github.com/devkid/nftables-systemd github page].<br />
<br />
{{Note|While the name suggests that it works only for systemd, it can be adapted for other init systems as well.}}<br />
<br />
==Logging to Syslog==<br />
<br />
For logging to Syslog, the {{ic|xt_LOG}} module needs to be loaded.<br />
<br />
==See also==<br />
* [http://people.netfilter.org/wiki-nftables/index.php/ netfilter nftables wiki]<br />
* [https://lwn.net/Articles/324251/ First release of nftables]<br />
* [https://home.regit.org/netfilter-en/nftables-quick-howto/ nftables quick howto]<br />
* [https://lwn.net/Articles/564095/ The return of nftables]</div>X33ahttps://wiki.archlinux.org/index.php?title=Nftables&diff=308061Nftables2014-04-03T07:26:36Z<p>X33a: loading rules during startup</p>
<hr />
<div>{{DISPLAYTITLE:nftables}}<br />
[[Category:Firewalls]]<br />
[[ja:Nftables]]<br />
{{Related articles start}}<br />
{{Related|Firewalls}}<br />
{{Related|iptables}}<br />
{{Related articles end}}<br />
[http://netfilter.org/projects/nftables/ nftables] is a netfilter project that aims to replace the existing ip-, ip6-, arp-, and ebtables framework. It provides a new packet filtering framework, a new user-space utility (nft), and a compatibility layer for ip- and ip6tables. It uses the existing hooks, connection tracking system, user-space queueing component, and logging subsystem of netfilter.<br />
<br />
The first release is available in Linux 3.13, which is in the ''core'' repository ({{Pkg|linux}}), and nftables (the user-space components) is available in the ''community'' repository ({{Pkg|nftables}}), and on the [[AUR]] in package {{AUR|nftables-git}}.<br />
<br />
{{Expansion|nftables is an entirely new utility, and lacks sufficient documentation on this wiki, as well as elsewhere.}}<br />
<br />
==Overview==<br />
nftables consists of three main components: a kernel implementation, the libnl netlink communication and the nftables user-space front-end. The kernel provides a netlink configuration interface, as well as run-time rule-set evaluation using a small classification language interpreter. libnl contains the low-level functions for communicating with the kernel; the nftables front-end is what the user interacts with.<br />
<br />
==nft==<br />
nftables' user-space utility {{ic|nft}} now performs most of the rule-set evaluation before handing rule-sets to the kernel. Because of this, nftables provides no default tables or chains; although, a user can emulate an iptables-like setup.<br />
<br />
It works in a fashion similar to ifconfig or iproute2. The commands are a long, structured sequence rather than using argument switches like in iptables. For example:<br />
nft add rule ip6 filter input ip saddr ::1 accept<br />
{{ic|add}} is the command. {{ic|rule}} is a subcommand of {{ic|add}}. {{ic|ip6}} is an argument of {{ic|rule}}, telling it to use the ip6 family. {{ic|filter}} and {{ic|input}} are arguments of {{ic|rule}} specifying the table and chain to use, respectively. The rest that follows is a rule definition, which includes matches ({{ic|ip}}), their parameters ({{ic|saddr}}), parameter arguments ({{ic|::1}}), and jumps ({{ic|accept}}).<br />
<br />
The following is an incomplete list of the commands available in nft:<br />
<nowiki><br />
list<br />
tables [family]<br />
table [family] <name><br />
chain [family] <table> <name><br />
<br />
add<br />
table [family] <name><br />
chain [family] <table> <name> [chain definitions]<br />
rule [family] <table> <chain> <rule definition><br />
<br />
table [family] <name> (shortcut for `add table`)<br />
<br />
insert<br />
rule [family] <table> <chain> <rule definition><br />
<br />
delete<br />
table [family] <name><br />
chain [family] <table> <name><br />
rule [family] <table> <handle><br />
<br />
flush<br />
table [family] <name><br />
chain [family] <table> <name></nowiki><br />
{{ic|family}} is optional, but it will default to {{ic|ip}}.<br />
<br />
==Tables==<br />
The purpose of tables is to hold chains. Unlike tables in iptables, there are no built-in tables in nftables. Tables can have one of four families specified, which unifies the various iptables utilities into one:<br />
*ip (iptables)<br />
*ip6 (ip6tables)<br />
*arp (arptables)<br />
*bridge (ebtables)<br />
{{ic|ip}} is the default family.<br />
A fifth family is scheduled for Linux 3.15 that allows for the unification of the ip and ip6 families to make defining rules for both easier.<br />
<br />
===Listing===<br />
You can list the current tables in a family with the {{ic|nft list}} command.<br />
# nft list tables<br />
# nft list tables ip6<br />
<br />
You can list a full table definition by specifying a table name:<br />
# nft list table foo<br />
# nft list table ip6 foo<br />
<br />
===Creation===<br />
Tables can be added via two commands — one just being a shortcut for the other. Here is an example of how to add an ip table called foo and an ip6 table called foo:<br />
# nft add table foo<br />
# nft table ip6 foo<br />
You can have two tables with the same name as long as they are in different families.<br />
<br />
===Deletion===<br />
Tables can only be deleted if there are no chains in them.<br />
# nft delete table foo<br />
# nft delete table ip6 foo<br />
<br />
==Chains==<br />
The purpose of chains is to hold rules. Unlike chains in iptables, there are no built-in chains in nftables. This means that if no chain uses any types or hooks in the netfilter framework, packets that would flow through those chains will not be touched by nftables, unlike iptables.<br />
<br />
===Listing===<br />
You can list the current chains in a chain with the {{ic|nft list}} command, using the same method as listing a table. You can also list rules from an individual chain.<br />
# nft list chain foo bar<br />
# nft list chain ip6 foo bar<br />
These commands will list the {{ic|bar}} chains in the ip and ip6 {{ic|foo}} tables.<br />
<br />
===Creation===<br />
Chains can be added when a table is created in a file definition or one at time via the {{ic|nft add chain}} command.<br />
# nft add chain foo bar<br />
# nft add chain ip6 foo bar<br />
These commands will add a chain called {{ic|bar}} to the ip and ip6 {{ic|foo}} tables.<br />
<br />
====Properties====<br />
Because nftables has no built-in chains, it allows chains to access certain features of the netfilter framework.<br />
# nft add chain filter input { type filter hook input priority 0; }<br />
This command tells nftables to add a chain called {{ic|input}} to the {{ic|filter}} table and defines its type, hook, and priority. These properties essentially replace the built-in tables and chains in iptables.<br />
<br />
=====Types=====<br />
There are three types a chain can have and they correspond to the tables used in iptables:<br />
*filter<br />
*nat<br />
*route (mangle)<br />
<br />
=====Hooks=====<br />
There are five hooks a chain can use and they correspond to the chains used in iptables:<br />
*input<br />
*output<br />
*forward<br />
*prerouting<br />
*postrouting<br />
<br />
=====Priorities=====<br />
{{Note|Priorities do not currently appear to have any effect on which chain sees packets first.}}<br />
{{Note|Since the priority seems to be an unsigned integer, negative priorities will be converted into very high priorities.}}<br />
Priorities tell nftables which chains packets should pass through first. They are integers, and the higher the integer, the higher the priority.<br />
<br />
===Deletion===<br />
Chains can only be deleted if there are no rules in them.<br />
# nft delete chain foo bar<br />
# nft delete chain ip6 foo bar<br />
These commands delete the {{ic|bar}} chains from the ip and ip6 {{ic|foo}} tables.<br />
<br />
==Rules==<br />
The purpose of rules is to identify packets (match) and carry out tasks (jump). Like in iptables, there are various matches and jumps available, though not all of them are feature-complete in nftables.<br />
<br />
===Listing===<br />
You can list the current rules in a table with the {{ic|nft list}} command, using the same method as listing a table. You can also list rules from an individual chain.<br />
# nft list chain foo bar<br />
# nft list chain ip6 foo bar<br />
These commands will list the rules in the {{ic|bar}} chains in the ip and ip6 {{ic|foo}} tables.<br />
<br />
===Creation===<br />
Rules can be added when a table is created in a file definition or one at time via the {{ic|nft add rule}} command.<br />
# nft add rule foo bar ip saddr 127.0.0.1 accept<br />
# nft add rule ip6 foo bar ip saddr ::1 accept<br />
These commands will add a rule to the {{ic|bar}} chains in the ip and ip6 {{ic|foo}} tables that matches an {{ic|ip}} packet when its {{ic|saddr}} (source address) is 127.0.0.1 (IPv4) or ::1 (IPv6) and accepts those packets.<br />
<br />
====Matches====<br />
There are various matches available in nftables and, for the most part, coincide with their iptables counterparts. The most noticeable difference is that there are no generic or implicit matches anymore. A generic match was one that was always available, such as {{ic|--protocol}} or {{ic|--source}}. Implicit matches were protocol-specific, such as {{ic|--sport}} when a packet was determined to be TCP.<br />
<br />
The following is an incomplete list of the matches available:<br />
*meta (meta properties, e.g. interfaces)<br />
*icmp (ICMP protocol)<br />
*icmpv6 (ICMPv6 protocol)<br />
*ip (IP protocol)<br />
*ip6 (IPv6 protocol)<br />
*tcp (TCP protocol)<br />
*udp (UDP protocol)<br />
*sctp (SCTP protocol)<br />
*ct (connection tracking)<br />
<br />
The following is an incomplete list of match arguments:<br />
<nowiki><br />
meta:<br />
oif <output interface INDEX><br />
iif <input interface INDEX><br />
oifname <output interface NAME><br />
iifname <input interface NAME><br />
<br />
(oif and iif accept string arguments and are converted to interface indexes)<br />
(oifname and iifname are more dynamic, but slower because of string matching)<br />
<br />
icmp:<br />
type <icmp type><br />
<br />
icmpv6:<br />
type <icmpv6 type><br />
<br />
ip:<br />
protocol <protocol><br />
daddr <destination address><br />
saddr <source address><br />
<br />
ip6:<br />
daddr <destination address><br />
saddr <source address><br />
<br />
tcp:<br />
dport <destination port><br />
sport <source port><br />
<br />
udp:<br />
dport <destination port><br />
sport <source port><br />
<br />
sctp:<br />
dport <destination port><br />
sport <source port><br />
<br />
ct:<br />
state <new | established | related | invalid></nowiki><br />
<br />
====Jumps====<br />
Jumps work the same as they do in iptables, except multiple jumps can now be used in one rule.<br />
# nft add rule filter input tcp dport 22 log accept<br />
<br />
The following is an incomplete list of jumps:<br />
*accept (accept a packet)<br />
*reject (reject a packet)<br />
*drop (drop a packet)<br />
*snat (perform source NAT on a packet)<br />
*dnat (perform destination NAT on a packet)<br />
*log (log a packet)<br />
*counter (keep a counter on a packet; counters are optional in nftables)<br />
*return (stop traversing the chain)<br />
<br />
===Insertion===<br />
Rules can be prepended to chains with the {{ic|nft insert rule}} command.<br />
# nft insert rule filter input ct state established,related accept<br />
<br />
===Deletion===<br />
Individual rules can only be deleted by their handles. The {{ic|nft --handle list}} command must be used to determine rule handles. Note the {{ic|--handle}} switch, which tells {{ic|nft}} to list handles in its output.<br />
<br />
The following determines the handle for a rule and then deletes it. The {{ic|--number}} argument is useful for viewing some numeric output, like unresolved IP addresses.<br />
{{hc|# nft --handle --numeric list chain filter input|2=<br />
<nowiki><br />
table ip filter {<br />
chain input {<br />
type filter hook input priority 0;<br />
ip saddr 127.0.0.1 accept # handle 10<br />
}<br />
}<br />
</nowiki><br />
}}<br />
# nft delete rule filter input handle 10<br />
<br />
All the chains in a table can be flushed with the {{ic|nft flush table}} command. Individual chains can be flushed using either the {{ic|nft flush chain}} or {{ic|nft delete rule}} commands.<br />
# nft flush table foo<br />
# nft flush chain foo bar<br />
# nft delete rule ip6 foo bar<br />
The first command flushes all of the chains in the ip {{ic|foo}} table. The second flushes the {{ic|bar}} chain in the ip {{ic|foo}} table. The third deletes all of the rules in {{ic|bar}} chain in the ip6 {{ic|foo}} table.<br />
<br />
==File Definitions==<br />
{{Warning|The {{ic|nft -f}} command, despite what the [http://people.netfilter.org/wiki-nftables/index.php/Atomic_rule_replacement netfilter wiki] says, is '''NOT''' atomic. This means you will have a small window between deleting the old tables and when the new ruleset is loaded where all packets will be accepted.}}<br />
{{Note|You must delete all conflicting tables before using the {{ic|nft -f}} command.}}<br />
File definitions can be used by the {{ic|nft -f}} command, which acts like the {{ic|iptables-restore}} command.<br />
{{hc|/etc/nftables/filter.rules|2=<br />
<nowiki><br />
table ip filter {<br />
chain input {<br />
type filter hook input priority 0;<br />
ct state established,related accept<br />
ip saddr 127.0.0.1 accept<br />
tcp dport 22 log accept<br />
reject<br />
}<br />
}<br />
</nowiki><br />
}}<br />
<br />
==Getting Started==<br />
To get an [[iptables]]-like chain set up, you will first need to use the provided IPv4 filter file:<br />
<br />
# nft -f /etc/nftables/ipv4-filter<br />
<br />
To list the resulting chain:<br />
<br />
# nft list table filter<br />
<br />
Drop output to a destination:<br />
<br />
# nft add rule ip filter output ip daddr 1.2.3.4 drop<br />
<br />
Drop packets destined for local port 80:<br />
<br />
# nft add rule ip filter input tcp dport 80 drop<br />
<br />
Delete all rules in a chain:<br />
<br />
# nft delete rule filter output<br />
<br />
==Samples==<br />
===Simple IP/IPv6 Firewall===<br />
{{hc|firewall.rules|2=<br />
<nowiki><br />
# A simple firewall<br />
<br />
table firewall {<br />
chain incoming {<br />
type filter hook input priority 0;<br />
<br />
# established/related connections<br />
ct state {established, related} accept<br />
<br />
# invalid connections<br />
ct state invalid drop<br />
<br />
# loopback interface<br />
iifname lo accept<br />
<br />
# icmp<br />
ip protocol icmp accept<br />
<br />
# open tcp ports: sshd (22), httpd (80)<br />
tcp dport {ssh, http} accept<br />
<br />
# everything else<br />
reject<br />
}<br />
}<br />
<br />
table ip6 firewall {<br />
chain incoming {<br />
type filter hook input priority 0;<br />
<br />
# established/related connections<br />
ct state {established, related} accept<br />
<br />
# invalid connections<br />
ct state invalid drop<br />
<br />
# loopback interface<br />
iifname lo accept<br />
<br />
# icmp<br />
ip6 nexthdr icmpv6 accept<br />
<br />
# open tcp ports: sshd (22), httpd (80)<br />
tcp dport {ssh, http} accept<br />
<br />
# everything else<br />
reject<br />
}<br />
}<br />
</nowiki><br />
}}<br />
<br />
===Limit rate and tcp flags IP/IPv6 Firewall===<br />
{{hc|firewall.2.rules|2=<br />
<nowiki><br />
table firewall {<br />
chain incoming {<br />
type filter hook input priority 0;<br />
<br />
# bad tcp -> avoid network scanning:<br />
tcp flags & (fin|syn) == (fin|syn) drop<br />
tcp flags & (syn|rst) == (syn|rst) drop<br />
tcp flags & (fin|syn|rst|psh|ack|urg) < (fin) drop # == 0 would be better, not supported yet.<br />
tcp flags & (fin|syn|rst|psh|ack|urg) == (fin|psh|urg) drop<br />
<br />
# no ping floods:<br />
ip protocol icmp limit rate 10/second accept<br />
ip protocol icmp drop<br />
<br />
ct state {established, related} accept<br />
ct state invalid drop<br />
<br />
iifname lo accept<br />
<br />
# avoid brute force on ssh:<br />
tcp dport {ssh} limit rate 15/minute accept<br />
<br />
reject<br />
}<br />
}<br />
<br />
table ip6 firewall {<br />
chain incoming {<br />
type filter hook input priority 0;<br />
<br />
# bad tcp:<br />
tcp flags & (fin|syn) == (fin|syn) drop<br />
tcp flags & (syn|rst) == (syn|rst) drop<br />
tcp flags & (fin|syn|rst|psh|ack|urg) < (fin) drop # == 0 would be better, not supported yet.<br />
tcp flags & (fin|syn|rst|psh|ack|urg) == (fin|psh|urg) drop<br />
<br />
# no ping floods:<br />
ip6 nexthdr icmpv6 limit rate 10/second accept<br />
ip6 nexthdr icmpv6 drop<br />
<br />
ct state {established, related} accept<br />
ct state invalid drop<br />
<br />
# loopback interface<br />
iifname lo accept<br />
<br />
# avoid brute force on ssh:<br />
tcp dport {ssh} limit rate 15/minute accept<br />
<br />
reject<br />
}<br />
}<br />
</nowiki><br />
}}<br />
<br />
===Priority-based Atomic Fix===<br />
If priorities ever actually take effect, this may be a workaround for {{ic|nft -f}}'s lack of true atomicness (being able to replace all the current rules with new ones in one go):<br />
{{hc|atomic.rules|2=<br />
table atomic {<br />
chain incoming {<br />
type filter hook input priority 0;<br />
ct state new reject<br />
}<br />
}<br />
<br />
table ip6 atomic {<br />
chain incoming {<br />
type filter hook input priority 0;<br />
ct state new reject<br />
}<br />
}<br />
}}<br />
Set the priority of other chains that hook input to higher than 0. This should block new connections while no other input chains are loaded.<br />
<br />
===Rules Script with Atomic Fix===<br />
Because using {{ic|nft -f}} to reload rulesets is time consuming, it's far easier to script it. This will include an atomic fix not based on priorities. It uses the two rules files from above.<br />
{{hc|firewall.sh|2=<br />
#!/bin/sh<br />
<br />
# Load atomic rules first<br />
nft -f atomic.rules<br />
<br />
# New incoming traffic should now be stopped<br />
<br />
# Get rid of both the ip and ip6 firewall tables<br />
<br />
nft flush table firewall 2>/dev/null<br />
nft delete chain firewall incoming 2>/dev/null<br />
nft delete table firewall 2>/dev/null<br />
<br />
nft flush table ip6 firewall 2>/dev/null<br />
nft delete chain ip6 firewall incoming 2>/dev/null<br />
nft delete table ip6 firewall 2>/dev/null<br />
<br />
# Reload the firewall rules<br />
nft -f firewall.rules<br />
<br />
# Get rid of both the ip and ip6 atomic tables<br />
<br />
nft flush table atomic 2>/dev/null<br />
nft delete chain atomic incoming 2>/dev/null<br />
nft delete table atomic 2>/dev/null<br />
<br />
# New incoming IP traffic should be working<br />
<br />
nft flush table ip6 atomic 2>/dev/null<br />
nft delete chain ip6 atomic incoming 2>/dev/null<br />
nft delete table ip6 atomic 2>/dev/null<br />
<br />
# New incoming IPv6 traffic should be working<br />
}}<br />
This should take anywhere from 100ms to 400ms, which is clearly unacceptable, but the only apparent solution.<br />
<br />
==Loading rules at boot==<br />
<br />
To automatically load rules on system boot, {{AUR|nftables-systemd-git}} can be used.<br />
Further install instructions can be found on the corresponding [https://github.com/devkid/nftables-systemd github page].<br />
<br />
{{Note|While the name suggests that it works only for systemd, it can be adapted for other init systems as well.}}<br />
<br />
==See also==<br />
* [http://people.netfilter.org/wiki-nftables/index.php/ netfilter nftables wiki]<br />
* [https://lwn.net/Articles/324251/ First release of nftables]<br />
* [https://home.regit.org/netfilter-en/nftables-quick-howto/ nftables quick howto]<br />
* [https://lwn.net/Articles/564095/ The return of nftables]</div>X33ahttps://wiki.archlinux.org/index.php?title=Icinga&diff=307510Icinga2014-03-28T13:27:41Z<p>X33a: removed deprecated "article summary" template</p>
<hr />
<div>[[Category:Status monitoring and notification]]<br />
[[Category:Networking]]<br />
<br />
[http://www.icinga.org/ Icinga] is an open source host, service and network monitoring program. It monitors specified hosts and services, alerting you to any developing issues, errors or improvements. This article describes the installation and configuration of Icinga.<br />
<br />
== Installation ==<br />
<br />
Follow [[Web Application Package Guidelines#Install Web Application Package|Install Web Application Package]] <br />
<br />
Before you install the package create the user {{ic|icinga:icinga}} with these commands:<br />
# groupadd -g 667 icinga<br />
# useradd -u 667 -g icinga -G http -d /dev/null -s /bin/false icinga<br />
Install {{AUR|icinga}} from the [[AUR]].<br />
<br />
Users may also want to install {{AUR|nagios-plugins}}.<br />
<br />
== Icinga configuration ==<br />
<br />
Copy the sample config files as root:<br />
<br />
# cd /etc/icinga<br />
# cp cgi.cfg.sample cgi.cfg<br />
# cp resource.cfg.sample resource.cfg<br />
# cp icinga.cfg.sample icinga.cfg<br />
# cp objects/commands.cfg.sample objects/commands.cfg<br />
# cp objects/contacts.cfg.sample objects/contacts.cfg<br />
# cp objects/localhost.cfg.sample objects/localhost.cfg<br />
# cp objects/templates.cfg.sample objects/templates.cfg<br />
# cp objects/timeperiods.cfg.sample objects/timeperiods.cfg<br />
<br />
Edit {{ic|/etc/icinga/resource.cfg}}:<br />
<br />
$USER1$=/usr/share/nagios/libexec<br />
<br />
== Webserver configuration ==<br />
<br />
Create htpasswd.users file with a username and password.<br />
<br />
# htpasswd -c /etc/icinga/htpasswd.users icingaadmin<br />
<br />
If you define another user foo, you need grant access permission to that user. Edit /etc/icinga/cgi.cfg<br />
<br />
authorized_for_system_information=icingaadmin,foo<br />
authorized_...<br />
...<br />
<br />
=== Additional Nginx configuration ===<br />
<br />
Configure Authentication:<br />
<br />
location /icinga/ {<br />
alias /usr/share/webapps/icinga/;<br />
auth_basic "Restricted";<br />
auth_basic_user_file /etc/icinga/htpasswd.users;<br />
}<br />
<br />
Configure CGI:<br />
<br />
location ~ ^/icinga/(.*)\.cgi$ {<br />
root /usr/share/webapps/;<br />
fastcgi_pass unix:/var/run/fcgiwrap.sock;<br />
include fastcgi.conf;<br />
fastcgi_param AUTH_USER $remote_user;<br />
fastcgi_param REMOTE_USER $remote_user;<br />
}<br />
<br />
== Icinga-web ==<br />
<br />
Follow [[Web Application Package Guidelines#Install Web Application Package|Install Web Application Package]] <br />
<br />
Install {{AUR|icinga-web}} from the [[AUR]].<br />
<br />
=== Configure IDOUtils ===<br />
<br />
# cd /etc/icinga<br />
# mv idomod.cfg-sample idomod.cfg<br />
# mv ido2db.cfg-sample ido2db.cfg<br />
<br />
# cd /etc/icinga/modules<br />
# mv idoutils.cfg-sample idoutils.cfg<br />
<br />
! Database Setup<br />
<br />
(Mysql)<br />
$ mysql -u root -p<br />
> CREATE USER 'icinga' IDENTIFIED BY 'icinga';<br />
> CREATE DATABASE icinga;<br />
> GRANT USAGE ON icinga.* TO 'icinga'@'localhost' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0;<br />
> GRANT SELECT , INSERT , UPDATE , DELETE, DROP, CREATE VIEW, INDEX<br />
ON icinga.* TO 'icinga'@'localhost';<br />
> FLUSH PRIVILEGES;<br />
> quit<br />
<br />
$ mysql -u root -p icinga < /usr/share/icinga/idoutils/db/mysql/mysql.sql<br />
<br />
=== Configure web server ===<br />
<br />
Example config files are located at<br />
<br />
/etc/icinga-web/apache.example.conf<br />
/etc/icinga-web/nginx.example.conf<br />
<br />
If you get 503 'Access denied' errors, check in these configuration files to see if you're allowed to visit the page:<br />
Order allow,deny<br />
Allow from all<br />
in sections ''<Directory "/usr/local/icinga-web/lib/ext3/">'' and ''<Directory "/usr/local/icinga-web/pub/">''.<br />
<br />
==== Configure PHP ====<br />
<br />
Edit {{ic|/etc/php.ini}}<br />
<br />
open_basedir = ...:/usr/share/icinga-web:/var/cache/icinga-web:/var/log/icinga<br />
extension=pdo_mysql.so<br />
extension=xsl.so<br />
extension=sockets.so<br />
<br />
==== Configure database ====<br />
<br />
===== MySQL =====<br />
<br />
! Create database and grants.<br />
# mysql -u root -p<br />
> CREATE USER 'icinga_web' IDENTIFIED BY 'icinga_web';<br />
> CREATE DATABASE icinga_web;<br />
> GRANT USAGE ON icinga_web.* TO 'icinga_web'@'localhost' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0;<br />
> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER, INDEX ON icinga_web.* TO 'icinga_web'@'localhost';<br />
> quit<br />
<br />
! Import the schema.<br />
# mysql -u root -p icinga_web < /usr/share/icinga-web/etc/schema/mysql.sql<br />
<br />
=== Finally ===<br />
<br />
! Start IDOUtils<br />
# systemctl start ido2db<br />
<br />
! Start Icinga<br />
# systemctl start icinga<br />
<br />
! Start Mysql<br />
# systemctl start mysqld<br />
<br />
! Start Web Server<br />
# systemctl start httpd or nginx<br />
<br />
! goto http://localhost/icinga-web<br />
> login with 'root' and 'password'<br />
<br />
== Upgrade database ==<br />
<br />
A new version usually requires an upgrade of the database. You find the sql upgrade scripts in:<br />
/usr/share/icinga/idoutils/db/mysql/upgrade<br />
/usr/share/icinga-web/etc/schema/updates/mysql<br />
Commands to upgrade with these scripts are:<br />
# mysql -u root -p icinga < ./mysql-upgrade-1.8.0.sql <br />
# mysql -u root -p icinga_web < ./mysql_v1-7-2_to_v1-8-0.sql<br />
# systemctl --system daemon-reload<br />
# systemctl restart icinga<br />
<br />
== See also ==<br />
<br />
* [http://www.icinga.org/ icinga.org] - Official website<br />
* [http://www.nagiosplugins.org/ Nagios Plugins] - The home of the official plugins <br />
* [[Wikipedia:Icinga|wikipedia.org]] - Wikipedia article<br />
* [http://www.nagiosexchange.org NagiosExchange] - Overview of plugins, addons, mailing lists for Icinga</div>X33ahttps://wiki.archlinux.org/index.php?title=Nftables&diff=303708Nftables2014-03-09T05:15:25Z<p>X33a: /* Deletion */ redundant use of sudo</p>
<hr />
<div>{{DISPLAYTITLE:nftables}}<br />
[[Category:Firewalls]]<br />
[[ja:Nftables]]<br />
{{Related articles start}}<br />
{{Related|Firewalls}}<br />
{{Related|iptables}}<br />
{{Related articles end}}<br />
[http://netfilter.org/projects/nftables/ nftables] is a netfilter project that aims to replace the existing ip-, ip6-, arp-, and ebtables framework. It provides a new packet filtering framework, a new user-space utility (nft), and a compatibility layer for ip- and ip6tables. It uses the existing hooks, connection tracking system, user-space queueing component, and logging subsystem of netfilter.<br />
<br />
The first release is available in Linux 3.13, which is in the ''core'' repository ({{Pkg|linux}}), and nftables (the user-space components) is available in the ''community'' repository ({{Pkg|nftables}}), and on the [[AUR]] in package {{AUR|nftables-git}}.<br />
<br />
{{Expansion|nftables is an entirely new utility, and lacks sufficient documentation on this wiki, as well as elsewhere.}}<br />
<br />
==Overview==<br />
nftables consists of three main components: a kernel implementation, the libnl netlink communication and the nftables user-space front-end. The kernel provides a netlink configuration interface, as well as run-time rule-set evaluation using a small classification language interpreter. libnl contains the low-level functions for communicating with the kernel; the nftables front-end is what the user interacts with.<br />
<br />
==nft==<br />
nftables' user-space utility {{ic|nft}} now performs most of the rule-set evaluation before handing rule-sets to the kernel. Because of this, nftables provides no default tables or chains; although, a user can emulate an iptables-like setup.<br />
<br />
It works in a fashion similar to ifconfig or iproute2. The commands are a long, structured sequence rather than using argument switches like in iptables. For example:<br />
nft add rule ip6 filter input ip saddr ::1 accept<br />
{{ic|add}} is the command. {{ic|rule}} is a subcommand of {{ic|add}}. {{ic|ip6}} is an argument of {{ic|rule}}, telling it to use the ip6 family. {{ic|filter}} and {{ic|input}} are arguments of {{ic|rule}} specifying the table and chain to use, respectively. The rest that follows is a rule definition, which includes matches ({{ic|ip}}), their parameters ({{ic|saddr}}), parameter arguments ({{ic|::1}}), and jumps ({{ic|accept}}).<br />
<br />
The following is an incomplete list of the commands available in nft:<br />
<nowiki><br />
list<br />
tables [family]<br />
table [family] <name><br />
chain [family] <table> <name><br />
<br />
add<br />
table [family] <name><br />
chain [family] <table> <name> [chain definitions]<br />
rule [family] <table> <chain> <rule definition><br />
<br />
table [family] <name> (shortcut for `add table`)<br />
<br />
insert<br />
rule [family] <table> <chain> <rule definition><br />
<br />
delete<br />
table [family] <name><br />
chain [family] <table> <name><br />
rule [family] <table> <handle><br />
<br />
flush<br />
table [family] <name><br />
chain [family] <table> <name></nowiki><br />
{{ic|family}} is optional, but it will default to {{ic|ip}}.<br />
<br />
==Tables==<br />
The purpose of tables is to hold chains. Unlike tables in iptables, there are no built-in tables in nftables. Tables can have one of four families specified, which unifies the various iptables utilities into one:<br />
*ip (iptables)<br />
*ip6 (ip6tables)<br />
*arp (arptables)<br />
*bridge (ebtables)<br />
{{ic|ip}} is the default family.<br />
A fifth family is scheduled for Linux 3.15 that allows for the unification of the ip and ip6 families to make defining rules for both easier.<br />
<br />
===Listing===<br />
You can list the current tables in a family with the {{ic|nft list}} command.<br />
# nft list tables<br />
# nft list tables ip6<br />
<br />
You can list a full table definition by specifying a table name:<br />
# nft list table foo<br />
# nft list table ip6 foo<br />
<br />
===Creation===<br />
Tables can be added via two commands — one just being a shortcut for the other. Here is an example of how to add an ip table called foo and an ip6 table called foo:<br />
# nft add table foo<br />
# nft table ip6 foo<br />
You can have two tables with the same name as long as they are in different families.<br />
<br />
===Deletion===<br />
Tables can only be deleted if there are no chains in them.<br />
# nft delete table foo<br />
# nft delete table ip6 foo<br />
<br />
==Chains==<br />
The purpose of chains is to hold rules. Unlike chains in iptables, there are no built-in chains in nftables. This means that if no chain uses any types or hooks in the netfilter framework, packets that would flow through those chains will not be touched by nftables, unlike iptables.<br />
<br />
===Listing===<br />
You can list the current chains in a chain with the {{ic|nft list}} command, using the same method as listing a table. You can also list rules from an individual chain.<br />
# nft list chain foo bar<br />
# nft list chain ip6 foo bar<br />
These commands will list the {{ic|bar}} chains in the ip and ip6 {{ic|foo}} tables.<br />
<br />
===Creation===<br />
Chains can be added when a table is created in a file definition or one at time via the {{ic|nfc add chain}} command.<br />
# nft add chain foo bar<br />
# nft add chain ip6 foo bar<br />
These commands will add a chain called {{ic|bar}} to the ip and ip6 {{ic|foo}} tables.<br />
<br />
====Properties====<br />
Because nftables has no built-in chains, it allows chains to access certain features of the netfilter framework.<br />
# nft add chain filter input { type filter hook input priority 0; }<br />
This command tells nftables to add a chain called {{ic|input}} to the {{ic|filter}} table and defines its type, hook, and priority. These properties essentially replace the built-in tables and chains in iptables.<br />
<br />
=====Types=====<br />
There are three types a chain can have and they correspond to the tables used in iptables:<br />
*filter<br />
*nat<br />
*route (mangle)<br />
<br />
=====Hooks=====<br />
There are five hooks a chain can use and they correspond to the chains used in iptables:<br />
*input<br />
*output<br />
*forward<br />
*prerouting<br />
*postrouting<br />
<br />
=====Priorities=====<br />
{{Note|Priorities do not currently appear to have any effect on which chain sees packets first.}}<br />
{{Note|Since the priority seems to be an unsigned integer, negative priorities will be converted into very high priorities.}}<br />
Priorities tell nftables which chains packets should pass through first. They are integers, and the higher the integer, the higher the priority.<br />
<br />
===Deletion===<br />
Chains can only be deleted if there are no rules in them.<br />
# nft delete chain foo bar<br />
# nft delete chain ip6 foo bar<br />
These commands delete the {{ic|bar}} chains from the ip and ip6 {{ic|foo}} tables.<br />
<br />
==Rules==<br />
The purpose of rules is to identify packets (match) and carry out tasks (jump). Like in iptables, there are various matches and jumps available, though not all of them are feature-complete in nftables.<br />
<br />
===Listing===<br />
You can list the current rules in a table with the {{ic|nft list}} command, using the same method as listing a table. You can also list rules from an individual chain.<br />
# nft list chain foo bar<br />
# nft list chain ip6 foo bar<br />
These commands will list the rules in the {{ic|bar}} chains in the ip and ip6 {{ic|foo}} tables.<br />
<br />
===Creation===<br />
Rules can be added when a table is created in a file definition or one at time via the {{ic|nfc add rule}} command.<br />
# nft add rule foo bar ip saddr 127.0.0.1 accept<br />
# nft add rule ip6 foo bar ip saddr ::1 accept<br />
These commands will add a rule to the {{ic|bar}} chains in the ip and ip6 {{ic|foo}} tables that matches an {{ic|ip}} packet when its {{ic|saddr}} (source address) is 127.0.0.1 (IPv4) or ::1 (IPv6) and accepts those packets.<br />
<br />
====Matches====<br />
There are various matches available in nftables and, for the most part, coincide with their iptables counterparts. The most noticeable difference is that there are no generic or implicit matches anymore. A generic match was one that was always available, such as {{ic|--protocol}} or {{ic|--source}}. Implicit matches were protocol-specific, such as {{ic|--sport}} when a packet was determined to be TCP.<br />
<br />
The following is an incomplete list of the matches available:<br />
*meta (meta properties, e.g. interfaces)<br />
*icmp (ICMP protocol)<br />
*icmpv6 (ICMPv6 protocol)<br />
*ip (IP protocol)<br />
*ip6 (IPv6 protocol)<br />
*tcp (TCP protocol)<br />
*udp (UDP protocol)<br />
*sctp (SCTP protocol)<br />
*ct (connection tracking)<br />
<br />
The following is an incomplete list of match arguments:<br />
<nowiki><br />
meta:<br />
oif <output interface INDEX><br />
iif <input interface INDEX><br />
oifname <output interface NAME><br />
iifname <input interface NAME><br />
<br />
(oif and iif accept string arguments and are converted to interface indexes)<br />
(oifname and iifname are more dynamic, but slower because of string matching)<br />
<br />
icmp:<br />
type <icmp type><br />
<br />
icmpv6:<br />
type <icmpv6 type><br />
<br />
ip:<br />
protocol <protocol><br />
daddr <destination address><br />
saddr <source address><br />
<br />
ip6:<br />
daddr <destination address><br />
saddr <source address><br />
<br />
tcp:<br />
dport <destination port><br />
sport <source port><br />
<br />
udp:<br />
dport <destination port><br />
sport <source port><br />
<br />
sctp:<br />
dport <destination port><br />
sport <source port><br />
<br />
ct:<br />
state <new | established | related | invalid></nowiki><br />
<br />
====Jumps====<br />
Jumps work the same as they do in iptables, except multiple jumps can now be used in one rule.<br />
# nft add rule filter input tcp dport 22 log accept<br />
<br />
The following is an incomplete list of jumps:<br />
*accept (accept a packet)<br />
*reject (reject a packet)<br />
*drop (drop a packet)<br />
*snat (perform source NAT on a packet)<br />
*dnat (perform destination NAT on a packet)<br />
*log (log a packet)<br />
*counter (keep a counter on a packet; counters are optional in nftables)<br />
*return (stop traversing the chain)<br />
<br />
===Insertion===<br />
Rules can be prepended to chains with the {{ic|nft insert rule}} command.<br />
# nft insert rule filter input ct state established,related accept<br />
<br />
===Deletion===<br />
Individual rules can only be deleted by their handles. The {{ic|nft --handle list}} command must be used to determine rule handles. Note the {{ic|--handle}} switch, which tells {{ic|nft}} to list handles in its output.<br />
<br />
The following determines the handle for a rule and then deletes it. The {{ic|--number}} argument is useful for viewing some numeric output, like unresolved IP addresses.<br />
{{hc|# nft --handle --numeric list chain filter input|2=<br />
<nowiki><br />
table ip filter {<br />
chain input {<br />
type filter hook input priority 0;<br />
ip saddr 127.0.0.1 accept # handle 10<br />
}<br />
}<br />
</nowiki><br />
}}<br />
# nft delete rule filter input handle 10<br />
<br />
All the chains in a table can be flushed with the {{ic|nft flush table}} command. Individual chains can be flushed using either the {{ic|nft flush chain}} or {{ic|nft delete rule}} commands.<br />
# nft flush table foo<br />
# nft flush chain foo bar<br />
# nft delete rule ip6 foo bar<br />
The first command flushes all of the chains in the ip {{ic|foo}} table. The second flushes the {{ic|bar}} chain in the ip {{ic|foo}} table. The third deletes all of the rules in {{ic|bar}} chain in the ip6 {{ic|foo}} table.<br />
<br />
==File Definitions==<br />
{{Warning|The {{ic|nft -f}} command, despite what the [http://people.netfilter.org/wiki-nftables/index.php/Atomic_rule_replacement netfilter wiki] says, is '''NOT''' atomic. This means you will have a small window between deleting the old tables and when the new ruleset is loaded where all packets will be accepted.}}<br />
{{Note|You must delete all conflicting tables before using the {{ic|nft -f}} command.}}<br />
File definitions can be used by the {{ic|nft -f}} command, which acts like the {{ic|iptables-restore}} command.<br />
{{hc|/etc/nftables/filter.rules|2=<br />
<nowiki><br />
table ip filter {<br />
chain input {<br />
type filter hook input priority 0;<br />
ct state established,related accept<br />
ip saddr 127.0.0.1 accept<br />
tcp dport 22 log accept<br />
reject<br />
}<br />
}<br />
</nowiki><br />
}}<br />
<br />
==Getting Started==<br />
To get an [[iptables]]-like chain set up, you will first need to use the provided IPv4 filter file:<br />
<br />
# nft -f /etc/nftables/ipv4-filter<br />
<br />
To list the resulting chain:<br />
<br />
# nft list table filter<br />
<br />
Drop output to a destination:<br />
<br />
# nft add rule ip filter output ip daddr 1.2.3.4 drop<br />
<br />
Drop packets destined for local port 80:<br />
<br />
# nft add rule ip filter input tcp dport 80 drop<br />
<br />
Delete all rules in a chain:<br />
<br />
# nft delete rule filter output<br />
<br />
==Samples==<br />
===Simple IP/IPv6 Firewall===<br />
{{hc|firewall.rules|2=<br />
<nowiki><br />
# A simple firewall<br />
<br />
table firewall {<br />
chain incoming {<br />
type filter hook input priority 0;<br />
<br />
# established/related connections<br />
ct state {established, related} accept<br />
<br />
# invalid connections<br />
ct state invalid drop<br />
<br />
# loopback interface<br />
iifname lo accept<br />
<br />
# icmp<br />
ip protocol icmp accept<br />
<br />
# open tcp ports: sshd (22), httpd (80)<br />
tcp dport {ssh, http} accept<br />
<br />
# everything else<br />
reject<br />
}<br />
}<br />
<br />
table ip6 firewall {<br />
chain incoming {<br />
type filter hook input priority 0;<br />
<br />
# established/related connections<br />
ct state {established, related} accept<br />
<br />
# invalid connections<br />
ct state invalid drop<br />
<br />
# loopback interface<br />
iifname lo accept<br />
<br />
# icmp<br />
ip6 nexthdr icmpv6 accept<br />
<br />
# open tcp ports: sshd (22), httpd (80)<br />
tcp dport {ssh, http} accept<br />
<br />
# everything else<br />
reject<br />
}<br />
}<br />
</nowiki><br />
}}<br />
<br />
===Limit rate and tcp flags IP/IPv6 Firewall===<br />
{{hc|firewall.2.rules|2=<br />
<nowiki><br />
table firewall {<br />
chain incoming {<br />
type filter hook input priority 0;<br />
<br />
# bad tcp -> avoid network scanning:<br />
tcp flags & (fin|syn) == (fin|syn) drop<br />
tcp flags & (syn|rst) == (syn|rst) drop<br />
tcp flags & (fin|syn|rst|psh|ack|urg) < (fin) drop # == 0 would be better, not supported yet.<br />
tcp flags & (fin|syn|rst|psh|ack|urg) == (fin|psh|urg) drop<br />
<br />
# no ping floods:<br />
ip protocol icmp limit rate 10/second accept<br />
ip protocol icmp drop<br />
<br />
ct state {established, related} accept<br />
ct state invalid drop<br />
<br />
iifname lo accept<br />
<br />
# avoid brute force on ssh:<br />
tcp dport {ssh} limit rate 15/minute accept<br />
<br />
reject<br />
}<br />
}<br />
<br />
table ip6 firewall {<br />
chain incoming {<br />
type filter hook input priority 0;<br />
<br />
# bad tcp:<br />
tcp flags & (fin|syn) == (fin|syn) drop<br />
tcp flags & (syn|rst) == (syn|rst) drop<br />
tcp flags & (fin|syn|rst|psh|ack|urg) < (fin) drop # == 0 would be better, not supported yet.<br />
tcp flags & (fin|syn|rst|psh|ack|urg) == (fin|psh|urg) drop<br />
<br />
# no ping floods:<br />
ip6 nexthdr icmpv6 limit rate 10/second accept<br />
ip6 nexthdr icmpv6 drop<br />
<br />
ct state {established, related} accept<br />
ct state invalid drop<br />
<br />
# loopback interface<br />
iifname lo accept<br />
<br />
# avoid brute force on ssh:<br />
tcp dport {ssh} limit rate 15/minute accept<br />
<br />
reject<br />
}<br />
}<br />
</nowiki><br />
}}<br />
<br />
===Priority-based Atomic Fix===<br />
If priorities ever actually take effect, this may be a workaround for {{ic|nft -f}}'s lack of true atomicness (being able to replace all the current rules with new ones in one go):<br />
{{hc|atomic.rules|2=<br />
table atomic {<br />
chain incoming {<br />
type filter hook input priority 0;<br />
ct state new reject<br />
}<br />
}<br />
<br />
table ip6 atomic {<br />
chain incoming {<br />
type filter hook input priority 0;<br />
ct state new reject<br />
}<br />
}<br />
}}<br />
Set the priority of other chains that hook input to higher than 0. This should block new connections while no other input chains are loaded.<br />
<br />
===Rules Script with Atomic Fix===<br />
Because using {{ic|nft -f}} to reload rulesets is time consuming, it's far easier to script it. This will include an atomic fix not based on priorities. It uses the two rules files from above.<br />
{{hc|firewall.sh|2=<br />
#!/bin/sh<br />
<br />
# Load atomic rules first<br />
nft -f atomic.rules<br />
<br />
# New incoming traffic should now be stopped<br />
<br />
# Get rid of both the ip and ip6 firewall tables<br />
<br />
nft flush table firewall 2>/dev/null<br />
nft delete chain firewall incoming 2>/dev/null<br />
nft delete table firewall 2>/dev/null<br />
<br />
nft flush table ip6 firewall 2>/dev/null<br />
nft delete chain ip6 firewall incoming 2>/dev/null<br />
nft delete table ip6 firewall 2>/dev/null<br />
<br />
# Reload the firewall rules<br />
nft -f firewall.rules<br />
<br />
# Get rid of both the ip and ip6 atomic tables<br />
<br />
nft flush table atomic 2>/dev/null<br />
nft delete chain atomic incoming 2>/dev/null<br />
nft delete table atomic 2>/dev/null<br />
<br />
# New incoming IP traffic should be working<br />
<br />
nft flush table ip6 atomic 2>/dev/null<br />
nft delete chain ip6 atomic incoming 2>/dev/null<br />
nft delete table ip6 atomic 2>/dev/null<br />
<br />
# New incoming IPv6 traffic should be working<br />
}}<br />
This should take anywhere from 100ms to 400ms, which is clearly unacceptable, but the only apparent solution.<br />
<br />
==Systemd==<br />
<br />
To automatically load rules on system boot, {{AUR|nftables-systemd-git}} from AUR can be used.<br />
Further install instruction can be found on the corresponding [https://github.com/devkid/nftables-systemd github page]<br />
<br />
==See also==<br />
* [http://people.netfilter.org/wiki-nftables/index.php/ netfilter nftables wiki]<br />
* [https://lwn.net/Articles/324251/ First release of nftables]<br />
* [https://home.regit.org/netfilter-en/nftables-quick-howto/ nftables quick howto]<br />
* [https://lwn.net/Articles/564095/ The return of nftables]</div>X33ahttps://wiki.archlinux.org/index.php?title=Domain_name_resolution&diff=302367Domain name resolution2014-02-28T06:20:30Z<p>X33a: /* Use timeout option to reduce hostname lookup time */ changes to resolv.conf take place immediately</p>
<hr />
<div>[[Category:Domain Name System]]<br />
[[de:Resolv.conf]]<br />
[[es:Resolv.conf]]<br />
[[fr:Resolv.conf]]<br />
[[it:Resolv.conf]]<br />
[[ja:Resolv.conf]]<br />
[[zh-CN:Resolv.conf]]<br />
The configuration file for DNS resolvers is {{ic|/etc/resolv.conf}}. From its [http://www.kernel.org/doc/man-pages/online/pages/man5/resolv.conf.5.html man page]:<br />
:''"The resolver is a set of routines in the C library that provide access to the Internet Domain Name System (DNS). The resolver configuration file contains information that is read by the resolver routines the first time they are invoked by a process. The file is designed to be human readable and contains a list of keywords with values that provide various types of resolver information.''<br />
<br />
:''"On a normally configured system this file should not be necessary. The only name server to be queried will be on the local machine; the domain name is determined from the host name and the domain search path is constructed from the domain name."''<br />
<br />
== DNS in Linux ==<br />
<br />
Your ISP (usually) provides working [[wikipedia:Domain_Name_System|DNS]] servers, and a router may also add an extra DNS server in case you have your own cache server. Switching between DNS servers does not represent a problem for Windows users, because if a DNS server is slow or does not work it will immediately switch to a better one. However, Linux usually takes longer to timeout, which could be the reason why you are getting a delay.<br />
<br />
Use ''dig'' (provided by package {{Pkg|dnsutils}}) before any changes, repeat after making the adjustments in the section below and compare the query time(s):<br />
$ dig www5.yahoo.com<br />
<br />
You can also specify a nameserver:<br />
$ dig @ip.of.name.server www5.yahoo.com<br />
<br />
== Alternative DNS servers ==<br />
<br />
To use alternative DNS servers, edit {{ic|/etc/resolv.conf}} and add them to the top of the file so they are used first, optionally removing or commenting out already listed servers. <br />
<br />
{{Note|<br />
* Changes made to {{ic|/etc/resolv.conf}} take effect immediately.<br />
* Bracket notation must be used for IPv6 addresses in {{ic|/etc/resolv.conf}}.<br />
}}<br />
<br />
=== OpenDNS ===<br />
<br />
[https://opendns.com OpenDNS] provides free alternative nameservers:<br />
<br />
# OpenDNS nameservers<br />
nameserver 208.67.222.222<br />
nameserver 208.67.220.220<br />
<br />
There are also IPv6 servers available:<br />
<br />
nameserver [2620:0:ccc::2]<br />
nameserver [2620:0:ccd::2]<br />
<br />
{{Warning|The OpenDNS servers ALWAYS respond with an IP address for any query, even if the domain or DNS record doesn't exist. This can cause problems when debugging network issues.}} <br />
<br />
==== Fixing problems with Google ====<br />
<br />
OpenDNS hijacks Google-searches by routing all queries through their own servers first. This can be annoying because Google searches may slow down noticeably and it also breaks Google's FeelingLucky feature (e.g., entering digg in your adress bar will open www.digg.com). For the latter, there is a [https://addons.mozilla.org/en-US/firefox/addon/7993 Firefox-addon] that brings back the original behaviour. A more elegant solution is to redirect all queries for Google exclusively to your ISP's DNS Server. This can be done with [[dnsmasq]] (see [[Speeding up DNS with dnsmasq]] for more information).<br />
<br />
=== Google ===<br />
<br />
[https://developers.google.com/speed/public-dns/ Google's nameservers] can be used as an alternative:<br />
<br />
# Google nameservers<br />
nameserver 8.8.8.8<br />
nameserver 8.8.4.4<br />
<br />
There are also IPv6 servers available:<br />
<br />
nameserver [2001:4860:4860::8888]<br />
nameserver [2001:4860:4860::8844]<br />
<br />
=== Comodo ===<br />
[http://securedns.dns.com/ Comodo] provides another IPv4 set, with optional (non-free) web-filtering. Implied in this feature is that the service hijacks the queries like OpenDNS does. <br />
<br />
# Comodo nameservers <br />
nameserver 8.26.56.26 <br />
nameserver 8.20.247.20<br />
<br />
== Preserve DNS settings ==<br />
<br />
[[dhcpcd]], [[netctl]], [[NetworkManager]], and various other processes can overwrite {{ic|/etc/resolv.conf}}. This is usually desirable behavior, but sometimes DNS settings need to be set manually (e.g. when using a static IP address). There are several ways to accomplish this. <br />
*If you are using dhcpcd, see [[#Modify the dhcpcd config]] below.<br />
*If you are using NetworkManager, see [https://bbs.archlinux.org/viewtopic.php?pid=413343#p413343 this thread] on how to prevent it from overriding your {{ic|/etc/resolv.conf}}.<br />
*If you are using [[netctl]] and static IP address assignment, do not use the {{ic|DNS*}} options in your profile, otherwise ''resolvconf'' is called and {{ic|/etc/resolv.conf}} overwritten.<br />
<br />
=== Using openresolv ===<br />
<br />
{{Pkg|openresolv}} provides a utility ''resolvconf'', which is a framework for managing multiple DNS configurations. See {{ic|man 8 resolvconf}} and {{ic|man 5 resolvconf.conf}} for more information.<br />
<br />
The configuration is done in {{ic|/etc/resolvconf.conf}} and running {{ic|resolvconf -u}} will generate {{ic|/etc/resolv.conf}}.<br />
<br />
=== Modify the dhcpcd config ===<br />
<br />
dhcpcd's configuration file may be edited to prevent the dhcpcd daemon from overwriting {{ic|/etc/resolv.conf}}. To do this, add the following to the last section of {{ic|/etc/dhcpcd.conf}}: <br />
<br />
nohook resolv.conf<br />
<br />
Alternatively, you can create a file called {{ic|/etc/resolv.conf.head}} containing your DNS servers. dhcpcd will prepend this file to the beginning of {{ic|/etc/resolv.conf}}.<br />
<br />
=== Write-protect /etc/resolv.conf ===<br />
<br />
Another way to protect your {{ic|/etc/resolv.conf}} from being modified by anything is setting the immutable (write-protection) attribute:<br />
<br />
# chattr +i /etc/resolv.conf<br />
<br />
=== Use timeout option to reduce hostname lookup time ===<br />
<br />
If you are confronted with a very long hostname lookup (may it be in [[pacman]] or while browsing), it often helps to define a small timeout after which an alternative nameserver is used. To do so, put the following in {{ic|/etc/resolv.conf}}.<br />
<br />
options timeout:1<br />
<br />
== See also ==<br />
<br />
*[http://wiki.gotux.net/code:bash:onic OpenNIC Alternative DNS Installer]</div>X33a