https://wiki.archlinux.org/api.php?action=feedcontributions&user=Mayweed&feedformat=atomArchWiki - User contributions [en]2024-03-29T14:07:38ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=Awesome&diff=246886Awesome2013-02-09T08:49:24Z<p>Mayweed: /* More configuration resources */ Add a link</p>
<hr />
<div>[[Category:Dynamic WMs]]<br />
[[cs:Awesome]]<br />
[[es:Awesome]]<br />
[[fr:Awesome3]]<br />
[[it:Awesome]]<br />
[[ja:Awesome]]<br />
[[ko:Awesome]]<br />
[[ru:Awesome]]<br />
[[sv:Awesome]]<br />
[[zh-CN:Awesome]]<br />
{{Lowercase title}}<br />
<br />
{{Article summary start}}<br />
{{Article summary text|A guide on how to install, use, configure, and customize awesome window manager.}}<br />
{{Article summary end}}<br />
<br />
From the [[Wikipedia:awesome (window manager)|awesome]] website:<br />
<br />
"''[http://awesome.naquadah.org/ awesome] is a highly configurable, next generation framework window manager for X. It is very fast, extensible and licensed under the GNU GPLv2 license.''<br />
<br />
''It is primarly targeted at power users, developers and any people dealing with every day computing tasks and who want to have fine-grained control on its graphical environment.''"<br />
<br />
==Installation==<br />
<br />
Install {{pkg|awesome}} from the [[official repositories]].<br />
<br />
For pre-release versions, an {{aur|awesome-git}} build is in the [[Arch User Repository|AUR]]. These versions are not considered stable and may have a different configuration syntax.<br />
<br />
== Run awesome ==<br />
<br />
=== Without login manager ===<br />
To run awesome without a login manager, simply add {{Ic|exec awesome}} to the startup script of your choice (e.g. ~/.xinitrc.)<br />
<br />
See [[xinitrc]] for details, such as preserving the logind (and/or consolekit) session.<br />
<br />
You can also start awesome as preferred user without even logging in. See [[Start X at Login]].<br />
<br />
=== With login manager ===<br />
To start awesome from a login manager, see [[Display Manager|this article]].<br />
<br />
==Configuration==<br />
Awesome includes some good default settings right out of the box, but sooner or later you'll want to change something. The lua based configuration file is at {{Ic|~/.config/awesome/rc.lua}}.<br />
<br />
===Creating the configuration file===<br />
First, run the following to create the directory needed in the next step:<br />
$ mkdir -p ~/.config/awesome/<br />
<br />
Whenever compiled, awesome will attempt to use whatever custom settings are contained in ~/.config/awesome/rc.lua. This file is not created by default, so we must copy the template file first:<br />
$ cp /etc/xdg/awesome/rc.lua ~/.config/awesome/<br />
<br />
The syntax of the configuration often changes when awesome updates. So, remember to repeate the command above when you get something strange with awesome, or you'd like to modify the configuration.<br />
<br />
For more information about configuring awesome, check out the [http://awesome.naquadah.org/wiki/Awesome_3_configuration configuration page at awesome wiki]<br />
<br />
===More configuration resources===<br />
{{Note|The syntax of awesome configuration changes regularly, so you will likely have to modify any file you download.}}<br />
<br />
Some good examples of rc.lua would be as follows:<br />
<br />
* http://git.sysphere.org/awesome-configs/tree/ - Awesome 3.4 configurations from Adrian C. (anrxc)<br />
* http://pastebin.com/f6e4b064e - Darthlukan's awesome 3.4 configuration. <br />
* http://www.ugolnik.info/downloads/awesome/rc.lua (screen) - Awesome 3 with small titlebar and statusbar.<br />
* https://github.com/setkeh/Awesome - [[User:Setkeh|Setkeh]]'s 3.4 Configuration<br />
* https://github.com/setkeh/Awesome-Laptop-3.5 - [[User:Setkeh|Setkeh]]'s 3.5 Configuration<br />
* User Configuration Files http://awesome.naquadah.org/wiki/User_Configuration_Files<br />
<br />
===Debug rc.lua using Xephyr===<br />
<br />
This is my prefered way to debug rc.lua, without breaking my current desktop. I first copy my rc.lua into a new file, rc.lua.new, and modify it as needed. Then, I run new instance of awesome in Xephyr (allows you to run X nested in another X's client window, supplying rc.lua.new as a config file like this:<br />
<br />
$ Xephyr :1 -ac -br -noreset -screen 1152x720 &<br />
$ DISPLAY=:1.0 awesome -c ~/.config/awesome/rc.lua.new<br />
<br />
Big advantage of this approach is that if I break rc.lua.new, I do not break my current awesome desktop (and possibly crash all my X apps, lose all unsaved things and so on...). Once I'm happy with my new settings, I move rc.lua.new to rc.lua and restart awesome. And I can be sure it will work and restarting with new config won't mess up things.<br />
<br />
As of July 2011, there is also {{aur|awmtt}} which provides the above functionality and more.<br />
<br />
==Themes==<br />
<br />
[http://awesome.naquadah.org/wiki/Beautiful Beautiful] is a lua library that allows you to theme awesome using an external file, it becomes very easy to dynamically change your whole awesome colours and wallpaper without changing your {{ic|rc.lua}}. <br />
<br />
The default theme is at {{ic|/usr/share/awesome/themes/default}}. Copy it to {{ic|~/.config/awesome/themes/default}} and change {{ic|theme_path}} in {{ic|rc.lua}}. <br />
beautiful.init(awful.util.getdir("config") .. "/themes/default/theme.lua")<br />
<br />
More details [http://awesome.naquadah.org/wiki/Beautiful here]<br />
<br />
A few sample [http://awesome.naquadah.org/wiki/Beautiful_themes themes]<br />
<br />
===Setting up your wallpaper===<br />
{{out of date | With version 3.5 Awesome no longer provides a awsetbg command, instead it has a gears module. You can find how to use it in default config}}<br />
Beautiful can handle your wallpaper, thus you do not need to set it up in your {{ic|.xinitrc}} or {{ic|.xsession}} files. This allows you to have a specific wallpaper for each theme. If you take a look at the default theme file you'll see a wallpaper_cmd key, the given command is executed when {{ic|beautiful.init}}("path_to_theme_file") is run. You can put here you own command or remove/comment the key if you do not want Beautiful to interfere with your wallpaper business.<br />
<br />
For instance, if you use {{ic|awsetbg}} to set your wallpaper, you can write in the {{ic|theme.lua}} page that you just selected:<br />
<br />
theme.wallpaper_cmd = { "awsetbg -f .config/awesome/themes/awesome-wallpaper.png" }<br />
<br />
{{Note|For awsetbg to work you need to have a program that can manage desktop backgrounds installed. For example '''[[Feh]]'''.}}<br />
<br />
====Random Background Image====<br />
To rotate the wallpapers randomly, just comment the {{ic|wallpaper_cmd}} line above, and add a script into your {{ic|.xinitrc}} with the codes below:<br />
{{bc|<br />
while true;<br />
do<br />
awsetbg -r <path/to/the/directory/of/your/wallpapers><br />
sleep 15m<br />
done &<br />
}}<br />
<br />
==Tips & Tricks==<br />
Feel free to add any tips or tricks that you would like to pass on to other awesome users.<br />
<br />
===Use awesome as GNOME's window manager===<br />
GNOME has the advantage of being very "ready to use" and integrating. You can set up GNOME to use awesome as the visual interface, but have GNOME work in the background for your pleasure. If you are using GNOME 3, you can simply install the [https://aur.archlinux.org/packages.php?ID=53096 awesome-gnome] package, then when logging in with GDM, choose the session type "Awesome GNOME". See the [http://awesome.naquadah.org/wiki/Quickly_Setting_up_Awesome_with_Gnome awesome wiki] for details.<br />
<br />
===Expose effect like compiz===<br />
<br />
Revelation brings up a view of all your open clients; left-clicking a client pops to the first tag that client is visible on and raises/focuses the client. In addition, the Enter key pops to the currently focused client, and Escape aborts. <br />
<br />
http://awesome.naquadah.org/wiki/Revelation<br />
<br />
===Hide / show wibox in awesome 3===<br />
<br />
To map Modkey-b to hide/show default statusbar on active screen (as default in awesome 2.3), add to your ''globalkeys'' in rc.lua:<br />
<br />
awful.key({ modkey }, "b", function ()<br />
mywibox[mouse.screen].visible = not mywibox[mouse.screen].visible<br />
end),<br />
<br />
===Enable printscreens===<br />
<br />
To enable printscreens in awesome through the PrtScr button you need to have a screen capturing program.<br />
Scrot is a easy to use utility for this purpose and is available in Arch repositories.<br />
<br />
Just type:<br />
# pacman -S scrot<br />
<br />
and install optional dependencies if you feel that you need them.<br />
<br />
Next of we need to get the key name for PrtScr, most often this is named "Print" but one can never be too sure.<br />
<br />
Start up:<br />
# xev<br />
<br />
And press the PrtScr button, the output should be something like:<br />
KeyPress event ....<br />
root 0x25c, subw 0x0, ...<br />
state 0x0, keycode 107 (keysym 0xff61, '''Print'''), same_screen YES,<br />
....<br />
<br />
In my case as you see, the keyname is Print.<br />
<br />
Now to the configuration of awesome!<br />
<br />
Somewhere in your globalkeys array (doesn't matter where) type:<br />
<br />
Lua code:<br />
<br />
awful.key({ }, "Print", function () awful.util.spawn("scrot -e 'mv $f ~/screenshots/ 2>/dev/null'") end),<br />
<br />
Also, this function saves screenshots inside ~/screenshots/, edit this to fit your needs.<br />
<br />
===Dynamic tagging===<br />
<br />
[http://awesome.naquadah.org/wiki/Eminent Eminent] is a small lua library that monkey-patches awful to provide you with effortless and quick wmii-style dynamic tagging. Unlike shifty, eminent does not aim to provide a comprehensive tagging system, but tries to make dynamic tagging as simple as possible. In fact, besides importing the eminent library, you do not have to change your rc.lua at all, eminent does all the work for you.<br />
<br />
[http://awesome.naquadah.org/wiki/Shifty Shifty] is an Awesome 3 extension that implements dynamic tagging. It also implements fine client matching configuration allowing YOU to be the master of YOUR desktop only by setting two simple config variables and some keybindings!<br />
<br />
===Space Invaders===<br />
[http://awesome.naquadah.org/wiki/Space_Invaders Space Invaders] is a demo to show the possibilities of the Awesome Lua API.<br />
<br />
Please note that it is no longer included in the Awesome package since the 3.4-rc1 release.<br />
<br />
===Naughty for popup notification===<br />
See [http://awesome.naquadah.org/wiki/Naughty the awesome wiki page on naughty].<br />
<br />
===Popup Menus===<br />
There's a simple menu by default in awesome3, and customed menus seem very easy now. However, if you're using 2.x awesome, have a look at ''[http://awesome.naquadah.org/wiki/Awful.menu awful.menu]''.<br />
<br />
If you want a freedesktop.org menu, you could take a look at ''[https://github.com/terceiro/awesome-freedesktop awesome-freedesktop]'' .<br />
<br />
An example for awesome3:<br />
{{bc|1=<br />
myawesomemenu = {<br />
{ "lock", "xscreensaver-command -activate" },<br />
{ "manual", terminal .. " -e man awesome" },<br />
{ "edit config", editor_cmd .. " " .. awful.util.getdir("config") .. "/rc.lua" },<br />
{ "restart", awesome.restart },<br />
{ "quit", awesome.quit }<br />
}<br />
<br />
mycommons = {<br />
{ "pidgin", "pidgin" },<br />
{ "OpenOffice", "soffice-dev" },<br />
{ "Graphic", "gimp" }<br />
}<br />
<br />
mymainmenu = awful.menu.new({ items = { <br />
{ "terminal", terminal },<br />
{ "icecat", "icecat" },<br />
{ "Editor", "gvim" },<br />
{ "File Manager", "pcmanfm" },<br />
{ "VirtualBox", "VirtualBox" },<br />
{ "Common App", mycommons, beautiful.awesome_icon },<br />
{ "awesome", myawesomemenu, beautiful.awesome_icon }<br />
}<br />
})<br />
}}<br />
<br />
===More Widgets in awesome===<br />
''Widgets in awesome are objects that you can add to any widget-box (statusbars and titlebars), they can provide various information about your system, and are useful for having access to this information, right from your window manager. Widgets are simple to use and offer a great deal of flexibility.'' -- Source [http://awesome.naquadah.org/wiki/Widgets_in_awesome Awesome Wiki: Widgets].<br />
<br />
There's a widely used widget library called '''Wicked''' (compatible with awesome versions '''prior to 3.4'''), that provides more widgets, like MPD widget, CPU usage, memory usage, etc. For more details see the [http://awesome.naquadah.org/wiki/Wicked Wicked page].<br />
<br />
As a replacement for Wicked in awesome v3.4 check '''[http://awesome.naquadah.org/wiki/Vicious Vicious]''', '''[http://awesome.naquadah.org/wiki/Obvious Obvious]''' and '''[http://awesome.naquadah.org/wiki/Bashets Bashets]'''. If you pick vicious, you should also take a good look at [http://git.sysphere.org/vicious/tree/README vicious documentation].<br />
<br />
===Transparency===<br />
Awesome has support for true transparency through a [[Xorg#Composite | compositing manager]] such as {{Pkg|xcompmgr}}({{AUR|xcompmgr-git}}), compton({{AUR|compton-git}}) or {{AUR|cairo-compmgr-git}}.<br />
<br />
To use xcompmgr, add this to your {{ic|~/.xinitrc}}:<br />
xcompmgr &<br />
See ''man xcompmgr'' or [[xcompmgr]] for more options.<br />
<br />
{{out of date | Awesome 3.5 has come and add_signal API has changed to connect_signal}}<br />
In awesome 3.4, window transparency can be set dynamically using signals. For example, your rc.lua could contain the following:<br />
<br />
client.add_signal("focus", function(c)<br />
c.border_color = beautiful.border_focus<br />
c.opacity = 1<br />
end)<br />
client.add_signal("unfocus", function(c)<br />
c.border_color = beautiful.border_normal<br />
c.opacity = 0.7<br />
end)<br />
'''If you got error messages about add_signal, using connect_signal insteaded.''' <br />
<br />
Note that if you are using conky, you must set it to create its own window instead of using the desktop. To do so, edit ~/.conkyrc to contain:<br />
<br />
own_window yes<br />
own_window_transparent yes<br />
own_window_type desktop<br />
<br />
Otherwise strange behavior may be observed, such as all windows becoming fully transparent. Note also that since conky will be creating a transparent window on your desktop, any actions defined in awesome's rc.lua for the desktop will not work where conky is.<br />
<br />
As of Awesome 3.1, there is built-in pseudo-transparency for wiboxes. To enable it, append 2 hexadecimal digits to the colors in your theme file (~/.config/awesome/themes/default, which is usually a copy of /usr/share/awesome/themes/default), like shown here:<br />
<br />
bg_normal = #000000AA<br />
<br />
where "AA" is the transparency value.<br />
<br />
To change transparency for the actual selected window by pressing Modkey + PageUp/PageDown you can also use tansset-df available through the community package repository and the following modification to your rc.lua:<br />
<br />
globalkeys = awful.util.table.join(<br />
-- your keybindings<br />
[...]<br />
awful.key({ modkey }, "Next", function (c)<br />
awful.util.spawn("transset-df --actual --inc 0.1")<br />
end),<br />
awful.key({ modkey }, "Prior", function (c)<br />
awful.util.spawn("transset-df --actual --dec 0.1")<br />
end),<br />
-- Your other key bindings<br />
[...]<br />
)<br />
<br />
==== ImageMagick ====<br />
You may have problems if you set your wallpaper with imagemagick's ''display'' command, it doesn't work well with xcompmgr. Please note that awsetbg may be using ''display'' if it doesn't have any other options. Installing habak, feh, hsetroot or whatever should fix the problem (''grep -A 1 wpsetters /usr/bin/awsetbg'' to see your options).<br />
<br />
===Autorun programs===<br />
''See also [https://awesome.naquadah.org/wiki/Autostart the Autostart page on the Awesome wiki].''<br />
<br />
awesome doesn't run programs set to autostart by the Freedesktop specification like GNOME or KDE. However, awesome does provide a few functions for starting programs (in addition to the Lua standard library function {{Ic|os.execute}}). To run the same programs on startup as GNOME or KDE, you can install [https://aur.archlinux.org/packages.php?ID=41099 dex] from the [[AUR]] and then run that in your rc.lua:<br />
<br />
os.execute"dex -a -e Awesome"<br />
<br />
If you just want to set up a list of apps for awesome to launch at startup, you can create a table of all the commands you want to spawn and loop through it:<br />
<br />
do<br />
local cmds = <br />
{ <br />
"swiftfox",<br />
"mutt",<br />
"consonance",<br />
"linux-fetion",<br />
"weechat-curses",<br />
--and so on...<br />
}<br />
<br />
for _,i in pairs(cmds) do<br />
awful.util.spawn(i)<br />
end<br />
end<br />
<br />
(You could also run calls to {{Ic|os.execute}} with commands ending in '{{Ic|&}}', but it's probably a better idea to stick to the proper spawn function.)<br />
<br />
To run a program only if it is not currently running, you can spawn it with a shell command that runs the program only if {{Ic|pgrep}} doesn't find a running process with the same name:<br />
function run_once(prg)<br />
awful.util.spawn_with_shell("pgrep -u $USER -x " .. prg .. " || (" .. prg .. ")")<br />
end<br />
<br />
So, for example, to run {{Ic|parcellite}} only if there is not a {{Ic|parcellite}} process already running:<br />
<br />
run_once("parcellite")<br />
<br />
===Passing content to widgets with awesome-client===<br />
<br />
You can easily send text to an awesome widget. Just create a new widget:<br />
{{bc|<nowiki><br />
mywidget = widget({ type = "textbox", name = "mywidget" })<br />
mywidget.text = "initial text"<br />
</nowiki>}}<br />
To update the text from an external source, use awesome-client:<br />
{{bc|<nowiki> <br />
echo -e 'mywidget.text = "new text"' | awesome-client<br />
</nowiki>}}<br />
Don't forget to add the widget to your wibox.<br />
<br />
===Using a different panel with awesome===<br />
<br />
If you like awesome's lightweightness and functionality but do not like the way its default panel looks, you can install a different panel. Just install xfce4-panel by issuing:<br />
{{bc|<br />
sudo pacman -S xfce4-panel<br />
}}<br />
Of course any other panel will do as well. <br />
Then add it to autorun section of your rc.lua (how to do that is written elsewhere on this wiki). You can also comment out the section which creates wiboxes for each screen (starting from "mywibox[s] = awful.wibox({ position = "top", screen = s })" ) but it isn't necessary. Any way do not forget to check your rc.lua for errors by typing <br />
{{bc|<br />
awesome -k rc.lua<br />
}}<br />
Also you should change your "modkey+R" keybinding, in order to start some other application launcher instead of built in awesome. Xfrun4, bashrun, etc. Check the Application launchers section of [[Openbox_Themes_and_Apps#Application_launchers|Openbox]] article for examples. Don't forget to add<br />
{{bc|<nowiki><br />
properties = { floating = true } },<br />
{ rule = { instance = "$yourapplicationlauncher" },<br />
</nowiki>}}<br />
to your rc.lua.<br />
<br />
===Fix Java (GUI appears gray only)===<br />
Guide taken from [https://bbs.archlinux.org/viewtopic.php?pid=450870].<br />
#Install {{Pkg|wmname}} from community<br />
#Run the following command or add it to your {{ic|.xinitrc}}: {{bc|wmname LG3D}}<br />
<br />
{{Note|<br />
If you use a non-reparenting window manager and Java 6, you should uncomment the corresponding line in {{Ic|/etc/profile.d/openjdk6.sh}}<br />
<br />
If you use a non-reparenting window manager and Java 7, you should uncomment the corresponding line in <br />
{{Ic|/etc/profile.d/jre.sh}} <br />
}}<br />
<br />
===Prevent Nautilus from displaying the desktop (Gnome3)===<br />
Run dconf-editor. Navigate to org->gnome->desktop->background and uncheck "draw-background" as well as "show-desktop-icons" for good measure. That's it!<br />
<br />
Another option is moving /usr/bin/nautilus to a new location and replacing it with a script that runs 'nautilus --no-desktop' passing any arguments it receives along.<br />
<br />
#!/bin/sh<br />
/usr/bin/nautilus-real --no-desktop $@<br />
<br />
===Transitioning away from Gnome3===<br />
Run 'gnome-session-properties' and remove programs that you won't be needing anymore (e.g Bluetooth Manager, Login Sounds, etc).<br />
<br />
If you'd like to get rid of GDM, make sure that your rc.conf DAEMONS list includes "dbus" (and "cupsd" if you have a printer). It's advisable to get a different login manager (like [https://wiki.archlinux.org/index.php/SLiM SLiM]), but you can do things manually if you wish. That entails setting up your [https://wiki.archlinux.org/index.php/Udev .xinitrc properly] and installing something like devmon ([https://aur.archlinux.org/packages.php?ID=45842 AUR]).<br />
<br />
If you wan't to keep a few convenient systray applets and your GTK theme, append this to your rc.lua;<br />
function start_daemon(dae)<br />
daeCheck = os.execute("ps -eF | grep -v grep | grep -w " .. dae)<br />
if (daeCheck ~= 0) then<br />
os.execute(dae .. " &")<br />
end<br />
end<br />
<br />
procs = {"gnome-settings-daemon", "nm-applet", "kupfer", "gnome-sound-applet", "gnome-power-manager"}<br />
for k = 1, #procs do<br />
start_daemon(procs[k])<br />
end<br />
<br />
===Prevent the mouse scroll wheel from changing tags===<br />
In your rc.lua, change the Mouse Bindings section to the following;<br />
-- {{{ Mouse bindings<br />
root.buttons(awful.util.table.join(<br />
awful.button({ }, 3, function () mymainmenu:toggle() end)))<br />
-- }}}<br />
<br />
==Troubleshooting==<br />
<br />
===LibreOffice===<br />
If you encounter UI problems with libreoffice install libreoffice-gnome.<br />
<br />
===Mod4 key===<br />
<br />
The Mod4 is by default the '''Win key'''. If it's not mapped by default, for some reason, you can check the keycode of your Mod4 key with<br />
<br />
$ xev<br />
<br />
It should be 115 for the left one. Then add this to your ~/.xinitrc<br />
<br />
xmodmap -e "keycode 115 = Super_L" -e "add mod4 = Super_L"<br />
exec awesome<br />
<br />
The problem in this case is that some xorg installations recognize keycode 115, but incorrectly as the 'Select' key. The above command explictly remaps keycode 115 to the correct 'Super_L' key.<br />
<br />
====Mod4 key vs. IBM ThinkPad users====<br />
<br />
IBM ThinkPads do not come equipped with a Window key (although Lenovo have changed this tradition on their ThinkPads). As of writing, the Alt key is not used in command combinations by the default rc.lua (refer to the Awesome wiki for a table of commands), which allows it be used as a replacement for the Super/Mod4/Win key. To do this, edit your rc.lua and replace:<br />
<br />
modkey = "Mod4"<br />
<br />
by:<br />
<br />
modkey = "Mod1"<br />
<br />
Note: Awesome does a have a few commands that make use of Mod4 plus a single letter. Changing Mod4 to Mod1/Alt could cause overlaps for some key combinations. The small amount of instances where this happens can be changed in the rc.lua file.<br />
<br />
If you do not like to change the awesome standards, you might like to remap a key. For instance the caps lock key is rather useless (for me) adding the following contents to ~/.Xmodmap <br />
<br />
clear lock <br />
add mod4 = Caps_Lock<br />
<br />
and [[Extra Keyboard Keys in Xorg#Step 2: Testing|(re)load]] the file.<br />
This will change the caps lock key into the mod4 key and works nicely with the standard awesome settings. In addition, if needed, it provides the mod4 key to other X-programs as well.<br />
<br />
Not confirmed, but if recent updates of xorg related packages break mentioned remapping the second line can be replaced by (tested on a DasKeyboard with no left Super key):<br />
<br />
keysym Caps_Lock = Super_L Caps_Lock<br />
<br />
===Eclipse: cannot resize/move main window===<br />
If you get stuck and cannot move or resize the main window (using mod4 + left/right mouse button) edit the workbench.xml and set fullscreen/maximized to false (if set) and reduce the width and height to numbers smaller than your single screen desktop area.<br />
{{Note|workbench.xml can be found in: <eclipse_workspace>/.metadata/.plugins/org.eclipse.ui.workbench/ and the line to edit is <window height&#61;"xx" maximized&#61;"true" width&#61;"xx" x&#61;"xx" y&#61;"xx">.}}<br />
<br />
===YouTube: fullscreen appears in background===<br />
[https://bbs.archlinux.org/viewtopic.php?pid=1085494#p1085494] If YouTube videos appear underneath your web browser when in fullscreen mode, add this to your rc.lua<br />
<br />
{ rule = { instance = "plugin-container" },<br />
properties = { floating = true } },<br />
<br />
With Chromium add<br />
<br />
{ rule = { instance = "exe" },<br />
properties = { floating = true } },<br />
<br />
===Starting console clients on specific tags===<br />
It does not work when the console application is invoked from a GTK terminal (e.g. LXTerminal). [[URxvt]] is known to work. <br />
<br />
===Redirecting console output to a file===<br />
Some GUI application are very verbose when launched from a terminal. As a consequence, when started from Awesome, they output everything to the TTY from where Awesome was started, which tend to get messy. To remove the garbage output, you have to redirect it. However, the {{ic|awful.util.spawn}} function does not handle pipes and redirections very well as stated in [http://awesome.naquadah.org/wiki/FAQ#How_to_execute_a_shell_command.3F the official FAQ].<br />
<br />
As example, let's redirect [[Luakit]] output to a temporary file:<br />
<br />
awful.key({ modkey, }, "w", function () awful.util.spawn_with_shell("luakit 2>>/tmp/luakit.log") end),<br />
<br />
==External Links==<br />
* http://awesome.naquadah.org/wiki/FAQ - FAQ<br />
* http://www.lua.org/pil/ - Programming in Lua (first edition)<br />
* http://awesome.naquadah.org/ - The official awesome website<br />
* http://awesome.naquadah.org/wiki/Main_Page - the awesome wiki<br />
* http://www.penguinsightings.org/desktop/awesome/ - A review<br />
* http://compsoc.tardis.ed.ac.uk/wiki/AwesomeWM_guide - Awesome guide<br />
* https://bbs.archlinux.org/viewtopic.php?id=88926 - share your awesome!</div>Mayweedhttps://wiki.archlinux.org/index.php?title=Awesome&diff=246885Awesome2013-02-09T08:47:41Z<p>Mayweed: /* More configuration resources */ lien non valide...</p>
<hr />
<div>[[Category:Dynamic WMs]]<br />
[[cs:Awesome]]<br />
[[es:Awesome]]<br />
[[fr:Awesome3]]<br />
[[it:Awesome]]<br />
[[ja:Awesome]]<br />
[[ko:Awesome]]<br />
[[ru:Awesome]]<br />
[[sv:Awesome]]<br />
[[zh-CN:Awesome]]<br />
{{Lowercase title}}<br />
<br />
{{Article summary start}}<br />
{{Article summary text|A guide on how to install, use, configure, and customize awesome window manager.}}<br />
{{Article summary end}}<br />
<br />
From the [[Wikipedia:awesome (window manager)|awesome]] website:<br />
<br />
"''[http://awesome.naquadah.org/ awesome] is a highly configurable, next generation framework window manager for X. It is very fast, extensible and licensed under the GNU GPLv2 license.''<br />
<br />
''It is primarly targeted at power users, developers and any people dealing with every day computing tasks and who want to have fine-grained control on its graphical environment.''"<br />
<br />
==Installation==<br />
<br />
Install {{pkg|awesome}} from the [[official repositories]].<br />
<br />
For pre-release versions, an {{aur|awesome-git}} build is in the [[Arch User Repository|AUR]]. These versions are not considered stable and may have a different configuration syntax.<br />
<br />
== Run awesome ==<br />
<br />
=== Without login manager ===<br />
To run awesome without a login manager, simply add {{Ic|exec awesome}} to the startup script of your choice (e.g. ~/.xinitrc.)<br />
<br />
See [[xinitrc]] for details, such as preserving the logind (and/or consolekit) session.<br />
<br />
You can also start awesome as preferred user without even logging in. See [[Start X at Login]].<br />
<br />
=== With login manager ===<br />
To start awesome from a login manager, see [[Display Manager|this article]].<br />
<br />
==Configuration==<br />
Awesome includes some good default settings right out of the box, but sooner or later you'll want to change something. The lua based configuration file is at {{Ic|~/.config/awesome/rc.lua}}.<br />
<br />
===Creating the configuration file===<br />
First, run the following to create the directory needed in the next step:<br />
$ mkdir -p ~/.config/awesome/<br />
<br />
Whenever compiled, awesome will attempt to use whatever custom settings are contained in ~/.config/awesome/rc.lua. This file is not created by default, so we must copy the template file first:<br />
$ cp /etc/xdg/awesome/rc.lua ~/.config/awesome/<br />
<br />
The syntax of the configuration often changes when awesome updates. So, remember to repeate the command above when you get something strange with awesome, or you'd like to modify the configuration.<br />
<br />
For more information about configuring awesome, check out the [http://awesome.naquadah.org/wiki/Awesome_3_configuration configuration page at awesome wiki]<br />
<br />
===More configuration resources===<br />
{{Note|The syntax of awesome configuration changes regularly, so you will likely have to modify any file you download.}}<br />
<br />
Some good examples of rc.lua would be as follows:<br />
<br />
* http://git.sysphere.org/awesome-configs/tree/ - Awesome 3.4 configurations from Adrian C. (anrxc)<br />
* http://pastebin.com/f6e4b064e - Darthlukan's awesome 3.4 configuration. <br />
* http://www.ugolnik.info/downloads/awesome/rc.lua (screen) - Awesome 3 with small titlebar and statusbar.<br />
* https://github.com/setkeh/Awesome - [[User:Setkeh|Setkeh]]'s 3.4 Configuration<br />
* User Configuration Files http://awesome.naquadah.org/wiki/User_Configuration_Files<br />
<br />
===Debug rc.lua using Xephyr===<br />
<br />
This is my prefered way to debug rc.lua, without breaking my current desktop. I first copy my rc.lua into a new file, rc.lua.new, and modify it as needed. Then, I run new instance of awesome in Xephyr (allows you to run X nested in another X's client window, supplying rc.lua.new as a config file like this:<br />
<br />
$ Xephyr :1 -ac -br -noreset -screen 1152x720 &<br />
$ DISPLAY=:1.0 awesome -c ~/.config/awesome/rc.lua.new<br />
<br />
Big advantage of this approach is that if I break rc.lua.new, I do not break my current awesome desktop (and possibly crash all my X apps, lose all unsaved things and so on...). Once I'm happy with my new settings, I move rc.lua.new to rc.lua and restart awesome. And I can be sure it will work and restarting with new config won't mess up things.<br />
<br />
As of July 2011, there is also {{aur|awmtt}} which provides the above functionality and more.<br />
<br />
==Themes==<br />
<br />
[http://awesome.naquadah.org/wiki/Beautiful Beautiful] is a lua library that allows you to theme awesome using an external file, it becomes very easy to dynamically change your whole awesome colours and wallpaper without changing your {{ic|rc.lua}}. <br />
<br />
The default theme is at {{ic|/usr/share/awesome/themes/default}}. Copy it to {{ic|~/.config/awesome/themes/default}} and change {{ic|theme_path}} in {{ic|rc.lua}}. <br />
beautiful.init(awful.util.getdir("config") .. "/themes/default/theme.lua")<br />
<br />
More details [http://awesome.naquadah.org/wiki/Beautiful here]<br />
<br />
A few sample [http://awesome.naquadah.org/wiki/Beautiful_themes themes]<br />
<br />
===Setting up your wallpaper===<br />
{{out of date | With version 3.5 Awesome no longer provides a awsetbg command, instead it has a gears module. You can find how to use it in default config}}<br />
Beautiful can handle your wallpaper, thus you do not need to set it up in your {{ic|.xinitrc}} or {{ic|.xsession}} files. This allows you to have a specific wallpaper for each theme. If you take a look at the default theme file you'll see a wallpaper_cmd key, the given command is executed when {{ic|beautiful.init}}("path_to_theme_file") is run. You can put here you own command or remove/comment the key if you do not want Beautiful to interfere with your wallpaper business.<br />
<br />
For instance, if you use {{ic|awsetbg}} to set your wallpaper, you can write in the {{ic|theme.lua}} page that you just selected:<br />
<br />
theme.wallpaper_cmd = { "awsetbg -f .config/awesome/themes/awesome-wallpaper.png" }<br />
<br />
{{Note|For awsetbg to work you need to have a program that can manage desktop backgrounds installed. For example '''[[Feh]]'''.}}<br />
<br />
====Random Background Image====<br />
To rotate the wallpapers randomly, just comment the {{ic|wallpaper_cmd}} line above, and add a script into your {{ic|.xinitrc}} with the codes below:<br />
{{bc|<br />
while true;<br />
do<br />
awsetbg -r <path/to/the/directory/of/your/wallpapers><br />
sleep 15m<br />
done &<br />
}}<br />
<br />
==Tips & Tricks==<br />
Feel free to add any tips or tricks that you would like to pass on to other awesome users.<br />
<br />
===Use awesome as GNOME's window manager===<br />
GNOME has the advantage of being very "ready to use" and integrating. You can set up GNOME to use awesome as the visual interface, but have GNOME work in the background for your pleasure. If you are using GNOME 3, you can simply install the [https://aur.archlinux.org/packages.php?ID=53096 awesome-gnome] package, then when logging in with GDM, choose the session type "Awesome GNOME". See the [http://awesome.naquadah.org/wiki/Quickly_Setting_up_Awesome_with_Gnome awesome wiki] for details.<br />
<br />
===Expose effect like compiz===<br />
<br />
Revelation brings up a view of all your open clients; left-clicking a client pops to the first tag that client is visible on and raises/focuses the client. In addition, the Enter key pops to the currently focused client, and Escape aborts. <br />
<br />
http://awesome.naquadah.org/wiki/Revelation<br />
<br />
===Hide / show wibox in awesome 3===<br />
<br />
To map Modkey-b to hide/show default statusbar on active screen (as default in awesome 2.3), add to your ''globalkeys'' in rc.lua:<br />
<br />
awful.key({ modkey }, "b", function ()<br />
mywibox[mouse.screen].visible = not mywibox[mouse.screen].visible<br />
end),<br />
<br />
===Enable printscreens===<br />
<br />
To enable printscreens in awesome through the PrtScr button you need to have a screen capturing program.<br />
Scrot is a easy to use utility for this purpose and is available in Arch repositories.<br />
<br />
Just type:<br />
# pacman -S scrot<br />
<br />
and install optional dependencies if you feel that you need them.<br />
<br />
Next of we need to get the key name for PrtScr, most often this is named "Print" but one can never be too sure.<br />
<br />
Start up:<br />
# xev<br />
<br />
And press the PrtScr button, the output should be something like:<br />
KeyPress event ....<br />
root 0x25c, subw 0x0, ...<br />
state 0x0, keycode 107 (keysym 0xff61, '''Print'''), same_screen YES,<br />
....<br />
<br />
In my case as you see, the keyname is Print.<br />
<br />
Now to the configuration of awesome!<br />
<br />
Somewhere in your globalkeys array (doesn't matter where) type:<br />
<br />
Lua code:<br />
<br />
awful.key({ }, "Print", function () awful.util.spawn("scrot -e 'mv $f ~/screenshots/ 2>/dev/null'") end),<br />
<br />
Also, this function saves screenshots inside ~/screenshots/, edit this to fit your needs.<br />
<br />
===Dynamic tagging===<br />
<br />
[http://awesome.naquadah.org/wiki/Eminent Eminent] is a small lua library that monkey-patches awful to provide you with effortless and quick wmii-style dynamic tagging. Unlike shifty, eminent does not aim to provide a comprehensive tagging system, but tries to make dynamic tagging as simple as possible. In fact, besides importing the eminent library, you do not have to change your rc.lua at all, eminent does all the work for you.<br />
<br />
[http://awesome.naquadah.org/wiki/Shifty Shifty] is an Awesome 3 extension that implements dynamic tagging. It also implements fine client matching configuration allowing YOU to be the master of YOUR desktop only by setting two simple config variables and some keybindings!<br />
<br />
===Space Invaders===<br />
[http://awesome.naquadah.org/wiki/Space_Invaders Space Invaders] is a demo to show the possibilities of the Awesome Lua API.<br />
<br />
Please note that it is no longer included in the Awesome package since the 3.4-rc1 release.<br />
<br />
===Naughty for popup notification===<br />
See [http://awesome.naquadah.org/wiki/Naughty the awesome wiki page on naughty].<br />
<br />
===Popup Menus===<br />
There's a simple menu by default in awesome3, and customed menus seem very easy now. However, if you're using 2.x awesome, have a look at ''[http://awesome.naquadah.org/wiki/Awful.menu awful.menu]''.<br />
<br />
If you want a freedesktop.org menu, you could take a look at ''[https://github.com/terceiro/awesome-freedesktop awesome-freedesktop]'' .<br />
<br />
An example for awesome3:<br />
{{bc|1=<br />
myawesomemenu = {<br />
{ "lock", "xscreensaver-command -activate" },<br />
{ "manual", terminal .. " -e man awesome" },<br />
{ "edit config", editor_cmd .. " " .. awful.util.getdir("config") .. "/rc.lua" },<br />
{ "restart", awesome.restart },<br />
{ "quit", awesome.quit }<br />
}<br />
<br />
mycommons = {<br />
{ "pidgin", "pidgin" },<br />
{ "OpenOffice", "soffice-dev" },<br />
{ "Graphic", "gimp" }<br />
}<br />
<br />
mymainmenu = awful.menu.new({ items = { <br />
{ "terminal", terminal },<br />
{ "icecat", "icecat" },<br />
{ "Editor", "gvim" },<br />
{ "File Manager", "pcmanfm" },<br />
{ "VirtualBox", "VirtualBox" },<br />
{ "Common App", mycommons, beautiful.awesome_icon },<br />
{ "awesome", myawesomemenu, beautiful.awesome_icon }<br />
}<br />
})<br />
}}<br />
<br />
===More Widgets in awesome===<br />
''Widgets in awesome are objects that you can add to any widget-box (statusbars and titlebars), they can provide various information about your system, and are useful for having access to this information, right from your window manager. Widgets are simple to use and offer a great deal of flexibility.'' -- Source [http://awesome.naquadah.org/wiki/Widgets_in_awesome Awesome Wiki: Widgets].<br />
<br />
There's a widely used widget library called '''Wicked''' (compatible with awesome versions '''prior to 3.4'''), that provides more widgets, like MPD widget, CPU usage, memory usage, etc. For more details see the [http://awesome.naquadah.org/wiki/Wicked Wicked page].<br />
<br />
As a replacement for Wicked in awesome v3.4 check '''[http://awesome.naquadah.org/wiki/Vicious Vicious]''', '''[http://awesome.naquadah.org/wiki/Obvious Obvious]''' and '''[http://awesome.naquadah.org/wiki/Bashets Bashets]'''. If you pick vicious, you should also take a good look at [http://git.sysphere.org/vicious/tree/README vicious documentation].<br />
<br />
===Transparency===<br />
Awesome has support for true transparency through a [[Xorg#Composite | compositing manager]] such as {{Pkg|xcompmgr}}({{AUR|xcompmgr-git}}), compton({{AUR|compton-git}}) or {{AUR|cairo-compmgr-git}}.<br />
<br />
To use xcompmgr, add this to your {{ic|~/.xinitrc}}:<br />
xcompmgr &<br />
See ''man xcompmgr'' or [[xcompmgr]] for more options.<br />
<br />
{{out of date | Awesome 3.5 has come and add_signal API has changed to connect_signal}}<br />
In awesome 3.4, window transparency can be set dynamically using signals. For example, your rc.lua could contain the following:<br />
<br />
client.add_signal("focus", function(c)<br />
c.border_color = beautiful.border_focus<br />
c.opacity = 1<br />
end)<br />
client.add_signal("unfocus", function(c)<br />
c.border_color = beautiful.border_normal<br />
c.opacity = 0.7<br />
end)<br />
'''If you got error messages about add_signal, using connect_signal insteaded.''' <br />
<br />
Note that if you are using conky, you must set it to create its own window instead of using the desktop. To do so, edit ~/.conkyrc to contain:<br />
<br />
own_window yes<br />
own_window_transparent yes<br />
own_window_type desktop<br />
<br />
Otherwise strange behavior may be observed, such as all windows becoming fully transparent. Note also that since conky will be creating a transparent window on your desktop, any actions defined in awesome's rc.lua for the desktop will not work where conky is.<br />
<br />
As of Awesome 3.1, there is built-in pseudo-transparency for wiboxes. To enable it, append 2 hexadecimal digits to the colors in your theme file (~/.config/awesome/themes/default, which is usually a copy of /usr/share/awesome/themes/default), like shown here:<br />
<br />
bg_normal = #000000AA<br />
<br />
where "AA" is the transparency value.<br />
<br />
To change transparency for the actual selected window by pressing Modkey + PageUp/PageDown you can also use tansset-df available through the community package repository and the following modification to your rc.lua:<br />
<br />
globalkeys = awful.util.table.join(<br />
-- your keybindings<br />
[...]<br />
awful.key({ modkey }, "Next", function (c)<br />
awful.util.spawn("transset-df --actual --inc 0.1")<br />
end),<br />
awful.key({ modkey }, "Prior", function (c)<br />
awful.util.spawn("transset-df --actual --dec 0.1")<br />
end),<br />
-- Your other key bindings<br />
[...]<br />
)<br />
<br />
==== ImageMagick ====<br />
You may have problems if you set your wallpaper with imagemagick's ''display'' command, it doesn't work well with xcompmgr. Please note that awsetbg may be using ''display'' if it doesn't have any other options. Installing habak, feh, hsetroot or whatever should fix the problem (''grep -A 1 wpsetters /usr/bin/awsetbg'' to see your options).<br />
<br />
===Autorun programs===<br />
''See also [https://awesome.naquadah.org/wiki/Autostart the Autostart page on the Awesome wiki].''<br />
<br />
awesome doesn't run programs set to autostart by the Freedesktop specification like GNOME or KDE. However, awesome does provide a few functions for starting programs (in addition to the Lua standard library function {{Ic|os.execute}}). To run the same programs on startup as GNOME or KDE, you can install [https://aur.archlinux.org/packages.php?ID=41099 dex] from the [[AUR]] and then run that in your rc.lua:<br />
<br />
os.execute"dex -a -e Awesome"<br />
<br />
If you just want to set up a list of apps for awesome to launch at startup, you can create a table of all the commands you want to spawn and loop through it:<br />
<br />
do<br />
local cmds = <br />
{ <br />
"swiftfox",<br />
"mutt",<br />
"consonance",<br />
"linux-fetion",<br />
"weechat-curses",<br />
--and so on...<br />
}<br />
<br />
for _,i in pairs(cmds) do<br />
awful.util.spawn(i)<br />
end<br />
end<br />
<br />
(You could also run calls to {{Ic|os.execute}} with commands ending in '{{Ic|&}}', but it's probably a better idea to stick to the proper spawn function.)<br />
<br />
To run a program only if it is not currently running, you can spawn it with a shell command that runs the program only if {{Ic|pgrep}} doesn't find a running process with the same name:<br />
function run_once(prg)<br />
awful.util.spawn_with_shell("pgrep -u $USER -x " .. prg .. " || (" .. prg .. ")")<br />
end<br />
<br />
So, for example, to run {{Ic|parcellite}} only if there is not a {{Ic|parcellite}} process already running:<br />
<br />
run_once("parcellite")<br />
<br />
===Passing content to widgets with awesome-client===<br />
<br />
You can easily send text to an awesome widget. Just create a new widget:<br />
{{bc|<nowiki><br />
mywidget = widget({ type = "textbox", name = "mywidget" })<br />
mywidget.text = "initial text"<br />
</nowiki>}}<br />
To update the text from an external source, use awesome-client:<br />
{{bc|<nowiki> <br />
echo -e 'mywidget.text = "new text"' | awesome-client<br />
</nowiki>}}<br />
Don't forget to add the widget to your wibox.<br />
<br />
===Using a different panel with awesome===<br />
<br />
If you like awesome's lightweightness and functionality but do not like the way its default panel looks, you can install a different panel. Just install xfce4-panel by issuing:<br />
{{bc|<br />
sudo pacman -S xfce4-panel<br />
}}<br />
Of course any other panel will do as well. <br />
Then add it to autorun section of your rc.lua (how to do that is written elsewhere on this wiki). You can also comment out the section which creates wiboxes for each screen (starting from "mywibox[s] = awful.wibox({ position = "top", screen = s })" ) but it isn't necessary. Any way do not forget to check your rc.lua for errors by typing <br />
{{bc|<br />
awesome -k rc.lua<br />
}}<br />
Also you should change your "modkey+R" keybinding, in order to start some other application launcher instead of built in awesome. Xfrun4, bashrun, etc. Check the Application launchers section of [[Openbox_Themes_and_Apps#Application_launchers|Openbox]] article for examples. Don't forget to add<br />
{{bc|<nowiki><br />
properties = { floating = true } },<br />
{ rule = { instance = "$yourapplicationlauncher" },<br />
</nowiki>}}<br />
to your rc.lua.<br />
<br />
===Fix Java (GUI appears gray only)===<br />
Guide taken from [https://bbs.archlinux.org/viewtopic.php?pid=450870].<br />
#Install {{Pkg|wmname}} from community<br />
#Run the following command or add it to your {{ic|.xinitrc}}: {{bc|wmname LG3D}}<br />
<br />
{{Note|<br />
If you use a non-reparenting window manager and Java 6, you should uncomment the corresponding line in {{Ic|/etc/profile.d/openjdk6.sh}}<br />
<br />
If you use a non-reparenting window manager and Java 7, you should uncomment the corresponding line in <br />
{{Ic|/etc/profile.d/jre.sh}} <br />
}}<br />
<br />
===Prevent Nautilus from displaying the desktop (Gnome3)===<br />
Run dconf-editor. Navigate to org->gnome->desktop->background and uncheck "draw-background" as well as "show-desktop-icons" for good measure. That's it!<br />
<br />
Another option is moving /usr/bin/nautilus to a new location and replacing it with a script that runs 'nautilus --no-desktop' passing any arguments it receives along.<br />
<br />
#!/bin/sh<br />
/usr/bin/nautilus-real --no-desktop $@<br />
<br />
===Transitioning away from Gnome3===<br />
Run 'gnome-session-properties' and remove programs that you won't be needing anymore (e.g Bluetooth Manager, Login Sounds, etc).<br />
<br />
If you'd like to get rid of GDM, make sure that your rc.conf DAEMONS list includes "dbus" (and "cupsd" if you have a printer). It's advisable to get a different login manager (like [https://wiki.archlinux.org/index.php/SLiM SLiM]), but you can do things manually if you wish. That entails setting up your [https://wiki.archlinux.org/index.php/Udev .xinitrc properly] and installing something like devmon ([https://aur.archlinux.org/packages.php?ID=45842 AUR]).<br />
<br />
If you wan't to keep a few convenient systray applets and your GTK theme, append this to your rc.lua;<br />
function start_daemon(dae)<br />
daeCheck = os.execute("ps -eF | grep -v grep | grep -w " .. dae)<br />
if (daeCheck ~= 0) then<br />
os.execute(dae .. " &")<br />
end<br />
end<br />
<br />
procs = {"gnome-settings-daemon", "nm-applet", "kupfer", "gnome-sound-applet", "gnome-power-manager"}<br />
for k = 1, #procs do<br />
start_daemon(procs[k])<br />
end<br />
<br />
===Prevent the mouse scroll wheel from changing tags===<br />
In your rc.lua, change the Mouse Bindings section to the following;<br />
-- {{{ Mouse bindings<br />
root.buttons(awful.util.table.join(<br />
awful.button({ }, 3, function () mymainmenu:toggle() end)))<br />
-- }}}<br />
<br />
==Troubleshooting==<br />
<br />
===LibreOffice===<br />
If you encounter UI problems with libreoffice install libreoffice-gnome.<br />
<br />
===Mod4 key===<br />
<br />
The Mod4 is by default the '''Win key'''. If it's not mapped by default, for some reason, you can check the keycode of your Mod4 key with<br />
<br />
$ xev<br />
<br />
It should be 115 for the left one. Then add this to your ~/.xinitrc<br />
<br />
xmodmap -e "keycode 115 = Super_L" -e "add mod4 = Super_L"<br />
exec awesome<br />
<br />
The problem in this case is that some xorg installations recognize keycode 115, but incorrectly as the 'Select' key. The above command explictly remaps keycode 115 to the correct 'Super_L' key.<br />
<br />
====Mod4 key vs. IBM ThinkPad users====<br />
<br />
IBM ThinkPads do not come equipped with a Window key (although Lenovo have changed this tradition on their ThinkPads). As of writing, the Alt key is not used in command combinations by the default rc.lua (refer to the Awesome wiki for a table of commands), which allows it be used as a replacement for the Super/Mod4/Win key. To do this, edit your rc.lua and replace:<br />
<br />
modkey = "Mod4"<br />
<br />
by:<br />
<br />
modkey = "Mod1"<br />
<br />
Note: Awesome does a have a few commands that make use of Mod4 plus a single letter. Changing Mod4 to Mod1/Alt could cause overlaps for some key combinations. The small amount of instances where this happens can be changed in the rc.lua file.<br />
<br />
If you do not like to change the awesome standards, you might like to remap a key. For instance the caps lock key is rather useless (for me) adding the following contents to ~/.Xmodmap <br />
<br />
clear lock <br />
add mod4 = Caps_Lock<br />
<br />
and [[Extra Keyboard Keys in Xorg#Step 2: Testing|(re)load]] the file.<br />
This will change the caps lock key into the mod4 key and works nicely with the standard awesome settings. In addition, if needed, it provides the mod4 key to other X-programs as well.<br />
<br />
Not confirmed, but if recent updates of xorg related packages break mentioned remapping the second line can be replaced by (tested on a DasKeyboard with no left Super key):<br />
<br />
keysym Caps_Lock = Super_L Caps_Lock<br />
<br />
===Eclipse: cannot resize/move main window===<br />
If you get stuck and cannot move or resize the main window (using mod4 + left/right mouse button) edit the workbench.xml and set fullscreen/maximized to false (if set) and reduce the width and height to numbers smaller than your single screen desktop area.<br />
{{Note|workbench.xml can be found in: <eclipse_workspace>/.metadata/.plugins/org.eclipse.ui.workbench/ and the line to edit is <window height&#61;"xx" maximized&#61;"true" width&#61;"xx" x&#61;"xx" y&#61;"xx">.}}<br />
<br />
===YouTube: fullscreen appears in background===<br />
[https://bbs.archlinux.org/viewtopic.php?pid=1085494#p1085494] If YouTube videos appear underneath your web browser when in fullscreen mode, add this to your rc.lua<br />
<br />
{ rule = { instance = "plugin-container" },<br />
properties = { floating = true } },<br />
<br />
With Chromium add<br />
<br />
{ rule = { instance = "exe" },<br />
properties = { floating = true } },<br />
<br />
===Starting console clients on specific tags===<br />
It does not work when the console application is invoked from a GTK terminal (e.g. LXTerminal). [[URxvt]] is known to work. <br />
<br />
===Redirecting console output to a file===<br />
Some GUI application are very verbose when launched from a terminal. As a consequence, when started from Awesome, they output everything to the TTY from where Awesome was started, which tend to get messy. To remove the garbage output, you have to redirect it. However, the {{ic|awful.util.spawn}} function does not handle pipes and redirections very well as stated in [http://awesome.naquadah.org/wiki/FAQ#How_to_execute_a_shell_command.3F the official FAQ].<br />
<br />
As example, let's redirect [[Luakit]] output to a temporary file:<br />
<br />
awful.key({ modkey, }, "w", function () awful.util.spawn_with_shell("luakit 2>>/tmp/luakit.log") end),<br />
<br />
==External Links==<br />
* http://awesome.naquadah.org/wiki/FAQ - FAQ<br />
* http://www.lua.org/pil/ - Programming in Lua (first edition)<br />
* http://awesome.naquadah.org/ - The official awesome website<br />
* http://awesome.naquadah.org/wiki/Main_Page - the awesome wiki<br />
* http://www.penguinsightings.org/desktop/awesome/ - A review<br />
* http://compsoc.tardis.ed.ac.uk/wiki/AwesomeWM_guide - Awesome guide<br />
* https://bbs.archlinux.org/viewtopic.php?id=88926 - share your awesome!</div>Mayweedhttps://wiki.archlinux.org/index.php?title=Awesome&diff=246884Awesome2013-02-09T08:31:16Z<p>Mayweed: /* More configuration resources */ lien non valide</p>
<hr />
<div>[[Category:Dynamic WMs]]<br />
[[cs:Awesome]]<br />
[[es:Awesome]]<br />
[[fr:Awesome3]]<br />
[[it:Awesome]]<br />
[[ja:Awesome]]<br />
[[ko:Awesome]]<br />
[[ru:Awesome]]<br />
[[sv:Awesome]]<br />
[[zh-CN:Awesome]]<br />
{{Lowercase title}}<br />
<br />
{{Article summary start}}<br />
{{Article summary text|A guide on how to install, use, configure, and customize awesome window manager.}}<br />
{{Article summary end}}<br />
<br />
From the [[Wikipedia:awesome (window manager)|awesome]] website:<br />
<br />
"''[http://awesome.naquadah.org/ awesome] is a highly configurable, next generation framework window manager for X. It is very fast, extensible and licensed under the GNU GPLv2 license.''<br />
<br />
''It is primarly targeted at power users, developers and any people dealing with every day computing tasks and who want to have fine-grained control on its graphical environment.''"<br />
<br />
==Installation==<br />
<br />
Install {{pkg|awesome}} from the [[official repositories]].<br />
<br />
For pre-release versions, an {{aur|awesome-git}} build is in the [[Arch User Repository|AUR]]. These versions are not considered stable and may have a different configuration syntax.<br />
<br />
== Run awesome ==<br />
<br />
=== Without login manager ===<br />
To run awesome without a login manager, simply add {{Ic|exec awesome}} to the startup script of your choice (e.g. ~/.xinitrc.)<br />
<br />
See [[xinitrc]] for details, such as preserving the logind (and/or consolekit) session.<br />
<br />
You can also start awesome as preferred user without even logging in. See [[Start X at Login]].<br />
<br />
=== With login manager ===<br />
To start awesome from a login manager, see [[Display Manager|this article]].<br />
<br />
==Configuration==<br />
Awesome includes some good default settings right out of the box, but sooner or later you'll want to change something. The lua based configuration file is at {{Ic|~/.config/awesome/rc.lua}}.<br />
<br />
===Creating the configuration file===<br />
First, run the following to create the directory needed in the next step:<br />
$ mkdir -p ~/.config/awesome/<br />
<br />
Whenever compiled, awesome will attempt to use whatever custom settings are contained in ~/.config/awesome/rc.lua. This file is not created by default, so we must copy the template file first:<br />
$ cp /etc/xdg/awesome/rc.lua ~/.config/awesome/<br />
<br />
The syntax of the configuration often changes when awesome updates. So, remember to repeate the command above when you get something strange with awesome, or you'd like to modify the configuration.<br />
<br />
For more information about configuring awesome, check out the [http://awesome.naquadah.org/wiki/Awesome_3_configuration configuration page at awesome wiki]<br />
<br />
===More configuration resources===<br />
{{Note|The syntax of awesome configuration changes regularly, so you will likely have to modify any file you download.}}<br />
<br />
Some good examples of rc.lua would be as follows:<br />
<br />
* http://git.sysphere.org/awesome-configs/tree/ - Awesome 3.4 configurations from Adrian C. (anrxc)<br />
* http://pastebin.com/f6e4b064e - Darthlukan's awesome 3.4 configuration. <br />
* http://www.ugolnik.info/downloads/awesome/rc.lua (screen) - Awesome 3 with small titlebar and statusbar.<br />
* http://github.com/nblock/config/blob/master/.config/awesome/rc.lua<br />
* https://github.com/setkeh/Awesome - [[User:Setkeh|Setkeh]]'s 3.4 Configuration<br />
* User Configuration Files http://awesome.naquadah.org/wiki/User_Configuration_Files<br />
<br />
===Debug rc.lua using Xephyr===<br />
<br />
This is my prefered way to debug rc.lua, without breaking my current desktop. I first copy my rc.lua into a new file, rc.lua.new, and modify it as needed. Then, I run new instance of awesome in Xephyr (allows you to run X nested in another X's client window, supplying rc.lua.new as a config file like this:<br />
<br />
$ Xephyr :1 -ac -br -noreset -screen 1152x720 &<br />
$ DISPLAY=:1.0 awesome -c ~/.config/awesome/rc.lua.new<br />
<br />
Big advantage of this approach is that if I break rc.lua.new, I do not break my current awesome desktop (and possibly crash all my X apps, lose all unsaved things and so on...). Once I'm happy with my new settings, I move rc.lua.new to rc.lua and restart awesome. And I can be sure it will work and restarting with new config won't mess up things.<br />
<br />
As of July 2011, there is also {{aur|awmtt}} which provides the above functionality and more.<br />
<br />
==Themes==<br />
<br />
[http://awesome.naquadah.org/wiki/Beautiful Beautiful] is a lua library that allows you to theme awesome using an external file, it becomes very easy to dynamically change your whole awesome colours and wallpaper without changing your {{ic|rc.lua}}. <br />
<br />
The default theme is at {{ic|/usr/share/awesome/themes/default}}. Copy it to {{ic|~/.config/awesome/themes/default}} and change {{ic|theme_path}} in {{ic|rc.lua}}. <br />
beautiful.init(awful.util.getdir("config") .. "/themes/default/theme.lua")<br />
<br />
More details [http://awesome.naquadah.org/wiki/Beautiful here]<br />
<br />
A few sample [http://awesome.naquadah.org/wiki/Beautiful_themes themes]<br />
<br />
===Setting up your wallpaper===<br />
{{out of date | With version 3.5 Awesome no longer provides a awsetbg command, instead it has a gears module. You can find how to use it in default config}}<br />
Beautiful can handle your wallpaper, thus you do not need to set it up in your {{ic|.xinitrc}} or {{ic|.xsession}} files. This allows you to have a specific wallpaper for each theme. If you take a look at the default theme file you'll see a wallpaper_cmd key, the given command is executed when {{ic|beautiful.init}}("path_to_theme_file") is run. You can put here you own command or remove/comment the key if you do not want Beautiful to interfere with your wallpaper business.<br />
<br />
For instance, if you use {{ic|awsetbg}} to set your wallpaper, you can write in the {{ic|theme.lua}} page that you just selected:<br />
<br />
theme.wallpaper_cmd = { "awsetbg -f .config/awesome/themes/awesome-wallpaper.png" }<br />
<br />
{{Note|For awsetbg to work you need to have a program that can manage desktop backgrounds installed. For example '''[[Feh]]'''.}}<br />
<br />
====Random Background Image====<br />
To rotate the wallpapers randomly, just comment the {{ic|wallpaper_cmd}} line above, and add a script into your {{ic|.xinitrc}} with the codes below:<br />
{{bc|<br />
while true;<br />
do<br />
awsetbg -r <path/to/the/directory/of/your/wallpapers><br />
sleep 15m<br />
done &<br />
}}<br />
<br />
==Tips & Tricks==<br />
Feel free to add any tips or tricks that you would like to pass on to other awesome users.<br />
<br />
===Use awesome as GNOME's window manager===<br />
GNOME has the advantage of being very "ready to use" and integrating. You can set up GNOME to use awesome as the visual interface, but have GNOME work in the background for your pleasure. If you are using GNOME 3, you can simply install the [https://aur.archlinux.org/packages.php?ID=53096 awesome-gnome] package, then when logging in with GDM, choose the session type "Awesome GNOME". See the [http://awesome.naquadah.org/wiki/Quickly_Setting_up_Awesome_with_Gnome awesome wiki] for details.<br />
<br />
===Expose effect like compiz===<br />
<br />
Revelation brings up a view of all your open clients; left-clicking a client pops to the first tag that client is visible on and raises/focuses the client. In addition, the Enter key pops to the currently focused client, and Escape aborts. <br />
<br />
http://awesome.naquadah.org/wiki/Revelation<br />
<br />
===Hide / show wibox in awesome 3===<br />
<br />
To map Modkey-b to hide/show default statusbar on active screen (as default in awesome 2.3), add to your ''globalkeys'' in rc.lua:<br />
<br />
awful.key({ modkey }, "b", function ()<br />
mywibox[mouse.screen].visible = not mywibox[mouse.screen].visible<br />
end),<br />
<br />
===Enable printscreens===<br />
<br />
To enable printscreens in awesome through the PrtScr button you need to have a screen capturing program.<br />
Scrot is a easy to use utility for this purpose and is available in Arch repositories.<br />
<br />
Just type:<br />
# pacman -S scrot<br />
<br />
and install optional dependencies if you feel that you need them.<br />
<br />
Next of we need to get the key name for PrtScr, most often this is named "Print" but one can never be too sure.<br />
<br />
Start up:<br />
# xev<br />
<br />
And press the PrtScr button, the output should be something like:<br />
KeyPress event ....<br />
root 0x25c, subw 0x0, ...<br />
state 0x0, keycode 107 (keysym 0xff61, '''Print'''), same_screen YES,<br />
....<br />
<br />
In my case as you see, the keyname is Print.<br />
<br />
Now to the configuration of awesome!<br />
<br />
Somewhere in your globalkeys array (doesn't matter where) type:<br />
<br />
Lua code:<br />
<br />
awful.key({ }, "Print", function () awful.util.spawn("scrot -e 'mv $f ~/screenshots/ 2>/dev/null'") end),<br />
<br />
Also, this function saves screenshots inside ~/screenshots/, edit this to fit your needs.<br />
<br />
===Dynamic tagging===<br />
<br />
[http://awesome.naquadah.org/wiki/Eminent Eminent] is a small lua library that monkey-patches awful to provide you with effortless and quick wmii-style dynamic tagging. Unlike shifty, eminent does not aim to provide a comprehensive tagging system, but tries to make dynamic tagging as simple as possible. In fact, besides importing the eminent library, you do not have to change your rc.lua at all, eminent does all the work for you.<br />
<br />
[http://awesome.naquadah.org/wiki/Shifty Shifty] is an Awesome 3 extension that implements dynamic tagging. It also implements fine client matching configuration allowing YOU to be the master of YOUR desktop only by setting two simple config variables and some keybindings!<br />
<br />
===Space Invaders===<br />
[http://awesome.naquadah.org/wiki/Space_Invaders Space Invaders] is a demo to show the possibilities of the Awesome Lua API.<br />
<br />
Please note that it is no longer included in the Awesome package since the 3.4-rc1 release.<br />
<br />
===Naughty for popup notification===<br />
See [http://awesome.naquadah.org/wiki/Naughty the awesome wiki page on naughty].<br />
<br />
===Popup Menus===<br />
There's a simple menu by default in awesome3, and customed menus seem very easy now. However, if you're using 2.x awesome, have a look at ''[http://awesome.naquadah.org/wiki/Awful.menu awful.menu]''.<br />
<br />
If you want a freedesktop.org menu, you could take a look at ''[https://github.com/terceiro/awesome-freedesktop awesome-freedesktop]'' .<br />
<br />
An example for awesome3:<br />
{{bc|1=<br />
myawesomemenu = {<br />
{ "lock", "xscreensaver-command -activate" },<br />
{ "manual", terminal .. " -e man awesome" },<br />
{ "edit config", editor_cmd .. " " .. awful.util.getdir("config") .. "/rc.lua" },<br />
{ "restart", awesome.restart },<br />
{ "quit", awesome.quit }<br />
}<br />
<br />
mycommons = {<br />
{ "pidgin", "pidgin" },<br />
{ "OpenOffice", "soffice-dev" },<br />
{ "Graphic", "gimp" }<br />
}<br />
<br />
mymainmenu = awful.menu.new({ items = { <br />
{ "terminal", terminal },<br />
{ "icecat", "icecat" },<br />
{ "Editor", "gvim" },<br />
{ "File Manager", "pcmanfm" },<br />
{ "VirtualBox", "VirtualBox" },<br />
{ "Common App", mycommons, beautiful.awesome_icon },<br />
{ "awesome", myawesomemenu, beautiful.awesome_icon }<br />
}<br />
})<br />
}}<br />
<br />
===More Widgets in awesome===<br />
''Widgets in awesome are objects that you can add to any widget-box (statusbars and titlebars), they can provide various information about your system, and are useful for having access to this information, right from your window manager. Widgets are simple to use and offer a great deal of flexibility.'' -- Source [http://awesome.naquadah.org/wiki/Widgets_in_awesome Awesome Wiki: Widgets].<br />
<br />
There's a widely used widget library called '''Wicked''' (compatible with awesome versions '''prior to 3.4'''), that provides more widgets, like MPD widget, CPU usage, memory usage, etc. For more details see the [http://awesome.naquadah.org/wiki/Wicked Wicked page].<br />
<br />
As a replacement for Wicked in awesome v3.4 check '''[http://awesome.naquadah.org/wiki/Vicious Vicious]''', '''[http://awesome.naquadah.org/wiki/Obvious Obvious]''' and '''[http://awesome.naquadah.org/wiki/Bashets Bashets]'''. If you pick vicious, you should also take a good look at [http://git.sysphere.org/vicious/tree/README vicious documentation].<br />
<br />
===Transparency===<br />
Awesome has support for true transparency through a [[Xorg#Composite | compositing manager]] such as {{Pkg|xcompmgr}}({{AUR|xcompmgr-git}}), compton({{AUR|compton-git}}) or {{AUR|cairo-compmgr-git}}.<br />
<br />
To use xcompmgr, add this to your {{ic|~/.xinitrc}}:<br />
xcompmgr &<br />
See ''man xcompmgr'' or [[xcompmgr]] for more options.<br />
<br />
{{out of date | Awesome 3.5 has come and add_signal API has changed to connect_signal}}<br />
In awesome 3.4, window transparency can be set dynamically using signals. For example, your rc.lua could contain the following:<br />
<br />
client.add_signal("focus", function(c)<br />
c.border_color = beautiful.border_focus<br />
c.opacity = 1<br />
end)<br />
client.add_signal("unfocus", function(c)<br />
c.border_color = beautiful.border_normal<br />
c.opacity = 0.7<br />
end)<br />
'''If you got error messages about add_signal, using connect_signal insteaded.''' <br />
<br />
Note that if you are using conky, you must set it to create its own window instead of using the desktop. To do so, edit ~/.conkyrc to contain:<br />
<br />
own_window yes<br />
own_window_transparent yes<br />
own_window_type desktop<br />
<br />
Otherwise strange behavior may be observed, such as all windows becoming fully transparent. Note also that since conky will be creating a transparent window on your desktop, any actions defined in awesome's rc.lua for the desktop will not work where conky is.<br />
<br />
As of Awesome 3.1, there is built-in pseudo-transparency for wiboxes. To enable it, append 2 hexadecimal digits to the colors in your theme file (~/.config/awesome/themes/default, which is usually a copy of /usr/share/awesome/themes/default), like shown here:<br />
<br />
bg_normal = #000000AA<br />
<br />
where "AA" is the transparency value.<br />
<br />
To change transparency for the actual selected window by pressing Modkey + PageUp/PageDown you can also use tansset-df available through the community package repository and the following modification to your rc.lua:<br />
<br />
globalkeys = awful.util.table.join(<br />
-- your keybindings<br />
[...]<br />
awful.key({ modkey }, "Next", function (c)<br />
awful.util.spawn("transset-df --actual --inc 0.1")<br />
end),<br />
awful.key({ modkey }, "Prior", function (c)<br />
awful.util.spawn("transset-df --actual --dec 0.1")<br />
end),<br />
-- Your other key bindings<br />
[...]<br />
)<br />
<br />
==== ImageMagick ====<br />
You may have problems if you set your wallpaper with imagemagick's ''display'' command, it doesn't work well with xcompmgr. Please note that awsetbg may be using ''display'' if it doesn't have any other options. Installing habak, feh, hsetroot or whatever should fix the problem (''grep -A 1 wpsetters /usr/bin/awsetbg'' to see your options).<br />
<br />
===Autorun programs===<br />
''See also [https://awesome.naquadah.org/wiki/Autostart the Autostart page on the Awesome wiki].''<br />
<br />
awesome doesn't run programs set to autostart by the Freedesktop specification like GNOME or KDE. However, awesome does provide a few functions for starting programs (in addition to the Lua standard library function {{Ic|os.execute}}). To run the same programs on startup as GNOME or KDE, you can install [https://aur.archlinux.org/packages.php?ID=41099 dex] from the [[AUR]] and then run that in your rc.lua:<br />
<br />
os.execute"dex -a -e Awesome"<br />
<br />
If you just want to set up a list of apps for awesome to launch at startup, you can create a table of all the commands you want to spawn and loop through it:<br />
<br />
do<br />
local cmds = <br />
{ <br />
"swiftfox",<br />
"mutt",<br />
"consonance",<br />
"linux-fetion",<br />
"weechat-curses",<br />
--and so on...<br />
}<br />
<br />
for _,i in pairs(cmds) do<br />
awful.util.spawn(i)<br />
end<br />
end<br />
<br />
(You could also run calls to {{Ic|os.execute}} with commands ending in '{{Ic|&}}', but it's probably a better idea to stick to the proper spawn function.)<br />
<br />
To run a program only if it is not currently running, you can spawn it with a shell command that runs the program only if {{Ic|pgrep}} doesn't find a running process with the same name:<br />
function run_once(prg)<br />
awful.util.spawn_with_shell("pgrep -u $USER -x " .. prg .. " || (" .. prg .. ")")<br />
end<br />
<br />
So, for example, to run {{Ic|parcellite}} only if there is not a {{Ic|parcellite}} process already running:<br />
<br />
run_once("parcellite")<br />
<br />
===Passing content to widgets with awesome-client===<br />
<br />
You can easily send text to an awesome widget. Just create a new widget:<br />
{{bc|<nowiki><br />
mywidget = widget({ type = "textbox", name = "mywidget" })<br />
mywidget.text = "initial text"<br />
</nowiki>}}<br />
To update the text from an external source, use awesome-client:<br />
{{bc|<nowiki> <br />
echo -e 'mywidget.text = "new text"' | awesome-client<br />
</nowiki>}}<br />
Don't forget to add the widget to your wibox.<br />
<br />
===Using a different panel with awesome===<br />
<br />
If you like awesome's lightweightness and functionality but do not like the way its default panel looks, you can install a different panel. Just install xfce4-panel by issuing:<br />
{{bc|<br />
sudo pacman -S xfce4-panel<br />
}}<br />
Of course any other panel will do as well. <br />
Then add it to autorun section of your rc.lua (how to do that is written elsewhere on this wiki). You can also comment out the section which creates wiboxes for each screen (starting from "mywibox[s] = awful.wibox({ position = "top", screen = s })" ) but it isn't necessary. Any way do not forget to check your rc.lua for errors by typing <br />
{{bc|<br />
awesome -k rc.lua<br />
}}<br />
Also you should change your "modkey+R" keybinding, in order to start some other application launcher instead of built in awesome. Xfrun4, bashrun, etc. Check the Application launchers section of [[Openbox_Themes_and_Apps#Application_launchers|Openbox]] article for examples. Don't forget to add<br />
{{bc|<nowiki><br />
properties = { floating = true } },<br />
{ rule = { instance = "$yourapplicationlauncher" },<br />
</nowiki>}}<br />
to your rc.lua.<br />
<br />
===Fix Java (GUI appears gray only)===<br />
Guide taken from [https://bbs.archlinux.org/viewtopic.php?pid=450870].<br />
#Install {{Pkg|wmname}} from community<br />
#Run the following command or add it to your {{ic|.xinitrc}}: {{bc|wmname LG3D}}<br />
<br />
{{Note|<br />
If you use a non-reparenting window manager and Java 6, you should uncomment the corresponding line in {{Ic|/etc/profile.d/openjdk6.sh}}<br />
<br />
If you use a non-reparenting window manager and Java 7, you should uncomment the corresponding line in <br />
{{Ic|/etc/profile.d/jre.sh}} <br />
}}<br />
<br />
===Prevent Nautilus from displaying the desktop (Gnome3)===<br />
Run dconf-editor. Navigate to org->gnome->desktop->background and uncheck "draw-background" as well as "show-desktop-icons" for good measure. That's it!<br />
<br />
Another option is moving /usr/bin/nautilus to a new location and replacing it with a script that runs 'nautilus --no-desktop' passing any arguments it receives along.<br />
<br />
#!/bin/sh<br />
/usr/bin/nautilus-real --no-desktop $@<br />
<br />
===Transitioning away from Gnome3===<br />
Run 'gnome-session-properties' and remove programs that you won't be needing anymore (e.g Bluetooth Manager, Login Sounds, etc).<br />
<br />
If you'd like to get rid of GDM, make sure that your rc.conf DAEMONS list includes "dbus" (and "cupsd" if you have a printer). It's advisable to get a different login manager (like [https://wiki.archlinux.org/index.php/SLiM SLiM]), but you can do things manually if you wish. That entails setting up your [https://wiki.archlinux.org/index.php/Udev .xinitrc properly] and installing something like devmon ([https://aur.archlinux.org/packages.php?ID=45842 AUR]).<br />
<br />
If you wan't to keep a few convenient systray applets and your GTK theme, append this to your rc.lua;<br />
function start_daemon(dae)<br />
daeCheck = os.execute("ps -eF | grep -v grep | grep -w " .. dae)<br />
if (daeCheck ~= 0) then<br />
os.execute(dae .. " &")<br />
end<br />
end<br />
<br />
procs = {"gnome-settings-daemon", "nm-applet", "kupfer", "gnome-sound-applet", "gnome-power-manager"}<br />
for k = 1, #procs do<br />
start_daemon(procs[k])<br />
end<br />
<br />
===Prevent the mouse scroll wheel from changing tags===<br />
In your rc.lua, change the Mouse Bindings section to the following;<br />
-- {{{ Mouse bindings<br />
root.buttons(awful.util.table.join(<br />
awful.button({ }, 3, function () mymainmenu:toggle() end)))<br />
-- }}}<br />
<br />
==Troubleshooting==<br />
<br />
===LibreOffice===<br />
If you encounter UI problems with libreoffice install libreoffice-gnome.<br />
<br />
===Mod4 key===<br />
<br />
The Mod4 is by default the '''Win key'''. If it's not mapped by default, for some reason, you can check the keycode of your Mod4 key with<br />
<br />
$ xev<br />
<br />
It should be 115 for the left one. Then add this to your ~/.xinitrc<br />
<br />
xmodmap -e "keycode 115 = Super_L" -e "add mod4 = Super_L"<br />
exec awesome<br />
<br />
The problem in this case is that some xorg installations recognize keycode 115, but incorrectly as the 'Select' key. The above command explictly remaps keycode 115 to the correct 'Super_L' key.<br />
<br />
====Mod4 key vs. IBM ThinkPad users====<br />
<br />
IBM ThinkPads do not come equipped with a Window key (although Lenovo have changed this tradition on their ThinkPads). As of writing, the Alt key is not used in command combinations by the default rc.lua (refer to the Awesome wiki for a table of commands), which allows it be used as a replacement for the Super/Mod4/Win key. To do this, edit your rc.lua and replace:<br />
<br />
modkey = "Mod4"<br />
<br />
by:<br />
<br />
modkey = "Mod1"<br />
<br />
Note: Awesome does a have a few commands that make use of Mod4 plus a single letter. Changing Mod4 to Mod1/Alt could cause overlaps for some key combinations. The small amount of instances where this happens can be changed in the rc.lua file.<br />
<br />
If you do not like to change the awesome standards, you might like to remap a key. For instance the caps lock key is rather useless (for me) adding the following contents to ~/.Xmodmap <br />
<br />
clear lock <br />
add mod4 = Caps_Lock<br />
<br />
and [[Extra Keyboard Keys in Xorg#Step 2: Testing|(re)load]] the file.<br />
This will change the caps lock key into the mod4 key and works nicely with the standard awesome settings. In addition, if needed, it provides the mod4 key to other X-programs as well.<br />
<br />
Not confirmed, but if recent updates of xorg related packages break mentioned remapping the second line can be replaced by (tested on a DasKeyboard with no left Super key):<br />
<br />
keysym Caps_Lock = Super_L Caps_Lock<br />
<br />
===Eclipse: cannot resize/move main window===<br />
If you get stuck and cannot move or resize the main window (using mod4 + left/right mouse button) edit the workbench.xml and set fullscreen/maximized to false (if set) and reduce the width and height to numbers smaller than your single screen desktop area.<br />
{{Note|workbench.xml can be found in: <eclipse_workspace>/.metadata/.plugins/org.eclipse.ui.workbench/ and the line to edit is <window height&#61;"xx" maximized&#61;"true" width&#61;"xx" x&#61;"xx" y&#61;"xx">.}}<br />
<br />
===YouTube: fullscreen appears in background===<br />
[https://bbs.archlinux.org/viewtopic.php?pid=1085494#p1085494] If YouTube videos appear underneath your web browser when in fullscreen mode, add this to your rc.lua<br />
<br />
{ rule = { instance = "plugin-container" },<br />
properties = { floating = true } },<br />
<br />
With Chromium add<br />
<br />
{ rule = { instance = "exe" },<br />
properties = { floating = true } },<br />
<br />
===Starting console clients on specific tags===<br />
It does not work when the console application is invoked from a GTK terminal (e.g. LXTerminal). [[URxvt]] is known to work. <br />
<br />
===Redirecting console output to a file===<br />
Some GUI application are very verbose when launched from a terminal. As a consequence, when started from Awesome, they output everything to the TTY from where Awesome was started, which tend to get messy. To remove the garbage output, you have to redirect it. However, the {{ic|awful.util.spawn}} function does not handle pipes and redirections very well as stated in [http://awesome.naquadah.org/wiki/FAQ#How_to_execute_a_shell_command.3F the official FAQ].<br />
<br />
As example, let's redirect [[Luakit]] output to a temporary file:<br />
<br />
awful.key({ modkey, }, "w", function () awful.util.spawn_with_shell("luakit 2>>/tmp/luakit.log") end),<br />
<br />
==External Links==<br />
* http://awesome.naquadah.org/wiki/FAQ - FAQ<br />
* http://www.lua.org/pil/ - Programming in Lua (first edition)<br />
* http://awesome.naquadah.org/ - The official awesome website<br />
* http://awesome.naquadah.org/wiki/Main_Page - the awesome wiki<br />
* http://www.penguinsightings.org/desktop/awesome/ - A review<br />
* http://compsoc.tardis.ed.ac.uk/wiki/AwesomeWM_guide - Awesome guide<br />
* https://bbs.archlinux.org/viewtopic.php?id=88926 - share your awesome!</div>Mayweedhttps://wiki.archlinux.org/index.php?title=RTorrent&diff=215454RTorrent2012-07-29T15:14:33Z<p>Mayweed: /* Adding manually trackers to torrents */</p>
<hr />
<div>{{DISPLAYTITLE:rTorrent}}<br />
[[Category:Internet Applications]]<br />
[[es:RTorrent]]<br />
[[ru:RTorrent]]<br />
[[zh-CN:RTorrent]]<br />
[http://libtorrent.rakshasa.no/ rTorrent] is a quick and efficient BitTorrent client that uses the libtorrent library. It is written in C++ and uses the [[Wikipedia:ncurses|ncurses]] programming library, which means it uses a text user interface. When combined with [[GNU Screen]] and [[Secure Shell]], it becomes a convenient remote [[Wikipedia:BitTorrent (protocol)#Operation|BitTorrent client]].<br />
<br />
== Installation ==<br />
[[pacman|Install]] the {{Pkg|rtorrent}} package that is available in the [[Official Repositories|official repositories]].<br />
<br />
Alternatively, install {{AUR|rtorrent-svn}} or {{AUR|rtorrent-extended}} from the [[Arch User Repository|AUR]].<br />
<br />
== Configuration ==<br />
{{note|See the rTorrent wiki article on this subject for more information: [http://libtorrent.rakshasa.no/wiki/RTorrentCommonTasks Common Tasks in rTorrent for Dummies]}}<br />
<br />
Before running rTorrent, find the example configuration file {{ic|/usr/share/doc/rtorrent/rtorrent.rc}} and copy it to {{ic|~/.rtorrent.rc}}:<br />
<br />
$ cp /usr/share/doc/rtorrent/rtorrent.rc ~/.rtorrent.rc<br />
<br />
=== Performance ===<br />
{{note|See the rTorrent wiki article on this subject for more information: [http://libtorrent.rakshasa.no/wiki/RTorrentPerformanceTuning Performance Tuning]}}<br />
<br />
The values for the following options are dependent on the system's hardware and Internet connection speed. To find the optimal values read: [http://torrentfreak.com/optimize-your-BitTorrent-download-speed Optimize Your BitTorrent Download Speed]<br />
{{bc|<nowiki><br />
min_peers = 40<br />
max_peers = 52<br />
<br />
min_peers_seed = 10<br />
max_peers_seed = 52<br />
<br />
max_uploads = 8<br />
<br />
download_rate = 200<br />
upload_rate = 28<br />
</nowiki>}}<br />
<br />
The {{ic|check_hash}} option executes a hash check when a torrent download is complete or rTorrent is started. When starting, it checks for errors in your completed files. <br />
check_hash = yes<br />
<br />
=== Create and manage files ===<br />
The {{ic|directory}} option will determine where your torrent data will be saved. Be sure to enter the absolute path, as rTorrent may not follow relative paths:<br />
directory = /home/[user]/torrents/<br />
<br />
The {{ic|session}} option allows rTorrent to save the progess of your torrents. It is recommended to create a directory called {{ic|.session}} (e.g. {{ic|$ mkdir ~/.session}}).<br />
session = /home/[user]/.session/<br />
<br />
The {{ic|schedule}} option has rTorrent watch a particular directory for new torrent files. Saving a torrent file to this directory will automatically start the download. Remember to create the directory that will be watched (e.g. {{ic|$ mkdir ~/watch}}). Also, be careful when using this option as rTorrent will move the torrent file to your session folder and rename it to its hash value.<br />
schedule = watch_directory,5,5,load_start=/home/[user]/watch/*.torrent<br />
schedule = untied_directory,5,5,stop_untied=<br />
schedule = tied_directory,5,5,start_tied=<br />
<br />
The following {{ic|schedule}} option is intended to stop rTorrent from downloading data when disk space is low.<br />
schedule = low_diskspace,5,60,close_low_diskspace=100M<br />
<br />
=== Port configuration ===<br />
The {{ic|port_range}} option sets which port(s) to use for listening. It is recommended to use a port that is higher than 49152 (see: [[Wikipedia:List of TCP and UDP port numbers|List of port numbers]]). Although, rTorrent allows a range of ports, a single port is recommended.<br />
port_range = 49164-49164<br />
<br />
Additionally, make sure port forwarding is enabled for the proper port(s) (see: [http://portforward.com/english/routers/port_forwarding/routerindex.htm Port Forward Guides]).<br />
<br />
=== Additional settings ===<br />
The {{ic|encryption}} option enables or disables encryption. It is very important to enable this option, not only for yourself, but also for your peers in the torrent swarm. Some users need to obscure their bandwidth usage from their ISP. And it does not hurt to enable it even if you do not need the added security.<br />
encryption = allow_incoming,try_outgoing,enable_retry<br />
{{Wikipedia|BitTorrent Protocol Encryption}}<br />
<br />
This final {{ic|dht}} option enables [[Wikipedia:Distributed hash table|DHT]] support. DHT is common among public trackers and will allow the client to acquire more peers.<br />
{{bc|<nowiki><br />
dht = auto<br />
dht_port = 6881<br />
peer_exchange = yes<br />
</nowiki>}}<br />
<br />
{{note|See the rTorrent wiki article on this subject for more information: [http://libtorrent.rakshasa.no/wiki/RTorrentUsingDHT Using DHT]}}<br />
<br />
== Key bindings ==<br />
<br />
rTorrent relies exclusively on keyboard shortcuts for user input. A quick reference is available in the table below. A complete guide is available on the rTorrent wiki (see: [http://libtorrent.rakshasa.no/wiki/RTorrentUserGuide rTorrent User Guide]).<br />
<br />
{{note|Striking {{keypress|Ctrl-q}} twice in quick succession will make rTorrent shutdown without waiting to send a stop announce to the connected trackers.}}<br />
<br />
{| class="toccolours" border="1" cellpadding="4" cellspacing="0" style="margin:5px;"<br />
|-<br />
!width="75" |Cmd<br />
!Action<br />
|-<br />
|Ctrl-q<br />
|Quit application<br />
|-<br />
|Ctrl-s<br />
|Start download. Runs hash first unless already done.<br />
|-<br />
|Ctrl-d<br />
|Stop an active download or remove a stopped download<br />
|-<br />
|Ctrl-k<br />
|Stop and close the files of an active download.<br />
|-<br />
|Ctrl-r<br />
|Initiate hash check of torrent. Without starting to download/upload.<br />
|-<br />
|Left<br />
|Returns to the previous screen<br />
|-<br />
|Right<br />
|Goes to the next screen<br />
|-<br />
|Backspace/Return<br />
|Adds the specified *.torrent<br />
|-<br />
|<nowiki>a|s|d</nowiki><br />
|<nowiki>Increase global upload throttle about 1|5|50 KB/s</nowiki><br />
|-<br />
|<nowiki>A|S|D</nowiki><br />
|<nowiki>Increase global download throttle about 1|5|50 KB/s</nowiki><br />
|-<br />
|<nowiki>z|x|c</nowiki><br />
|<nowiki>Decrease global upload throttle about 1|5|50 KB/s</nowiki><br />
|-<br />
|<nowiki>Z|X|C</nowiki><br />
|<nowiki>Decrease global download throttle about 1|5|50 KB/s</nowiki><br />
|}<br />
=== Redundant mapping ===<br />
{{Keypress|Ctrl-s}} is often used for terminal control to stop screen output while {{Keypress|Ctrl-q}} is used to start it. These mappings may interfere with rTorrent. Check to see if these terminal options are bound to a mapping:<br />
{{hc|$ stty -a|<nowiki>...<br />
swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V;<br />
...<br />
</nowiki>}}<br />
<br />
To remove the mappings, change the terminal characteristics to undefine the aforementioned special characters (i.e. {{ic|stop}} and {{ic|start}}):<br />
# stty stop undef<br />
# stty start undef<br />
<br />
To remove these mappings automatically at startup you may add the two preceding commands to your {{ic|~/.bashrc}} file.<br />
<br />
== Additional Tips ==<br />
<br />
=== Separate session with Screen ===<br />
[[GNU Screen]] is a wrapper that allows separation between the text program and the shell from which it was launched.<br />
<br />
Screen flow-control interferes with the {{Keypress|Ctrl-q}} mapping (see: [[#Redundant mapping|Redundant mapping]]). To disable it add the following to {{ic|~/.screenrc}}:<br />
defflow off<br />
<br />
An alternative is to escape the command and send it directly to rTorrent. In other words, use {{Keypress|Ctrl-a}} {{Keypress|q}} to quit rTorrent within GNU Screen.<br />
<br />
To automatically start rTorrent within Screen, add the following to the {{ic|~/.screenrc}} configuration file:<br />
screen -t rtorrent rtorrent <br />
<br />
==== Run as a daemon ====<br />
{{note|See the rTorrent wiki article on this subject for more information: [http://libtorrent.rakshasa.no/wiki/RTorrentCommonTasks#StartingrTorrentonSystemStartup Starting rTorrent on System Startup]}}<br />
<br />
Alternatively, GNU Screen and rTorrent can be run together as a [[daemon]] (see also: [https://bbs.archlinux.org/viewtopic.php?id=53395 Arch Linux Forums thread], [https://forums.gentoo.org/viewtopic-t-600362-postdays-0-postorder-asc-start-0.html Gentoo Discussion Forums thread]). <br />
<br />
To use this script with [[tmux]], replace line 9 with {{ic|su - USER -c 'tmux new -s rtorrent -d rtorrent' &> /dev/null}} (see: [https://bbs.archlinux.org/viewtopic.php?id=126718 rTorrent daemon with tmux]).<br />
<br />
With root permissions create the following file:<br />
<br />
{{hc|/etc/rc.d/rtorrent|<nowiki><br />
#!/bin/bash<br />
<br />
. /etc/rc.conf<br />
. /etc/rc.d/functions<br />
<br />
case "$1" in<br />
start)<br />
stat_busy "Starting rtorrent"<br />
su - USER -c 'screen -d -m -S rtorrent rtorrent' &> /dev/null<br />
if [ $? -gt 0 ]; then<br />
stat_fail<br />
else<br />
add_daemon rtorrent<br />
stat_done<br />
fi<br />
;;<br />
stop)<br />
stat_busy "Stopping rtorrent"<br />
killall -w -s 2 /usr/bin/rtorrent &> /dev/null<br />
if [ $? -gt 0 ]; then<br />
stat_fail<br />
else<br />
rm_daemon rtorrent<br />
stat_done<br />
fi<br />
;;<br />
restart)<br />
$0 stop<br />
sleep 1<br />
$0 start<br />
;;<br />
*)<br />
echo "usage: $0 {start|stop|restart}"<br />
esac<br />
exit 0<br />
</nowiki>}}<br />
<br />
Make sure to change USER to the username that will be running rtorrent.<br />
<br />
Make the file executable:<br />
# chmod +x /etc/rc.d/rtorrent<br />
<br />
Creating a {{ic|.rtorrent.rc}} file with relative paths in a user's home directory will break the rc.d script. To run multiple instances of rTorrent with relative paths under different users, replace line 9 in {{ic|/etc/rc.d/rtorrent}} with the following:<br />
su username -c 'cd /home/username && screen -d -m -S rtorrent rtorrent' &> /dev/null<br />
<br />
Alternatively, you can set absolute paths in the configuration file.<br />
<br />
To run the daemon user multiple users create one rc.d script for each user. Then replace line 9 in {{ic|/etc/rc.d/rtorrent}} with the following: <br />
su - username -c 'killall -w -s 2 /usr/bin/rtorrent' &> /dev/null<br />
<br />
To connect to the daemon process on a remote machine use [[Secure Shell|SSH]]:<br />
$ ssh -t rtorrent@192.168.1.10 'screen -r'<br />
<br />
Or if you used [[tmux]] instead of [[screen]]:<br />
$ ssh -t rtorrent@192.168.1.10 'tmux attach -t rtorrent'<br />
<br />
For more information about daemon scripts see: [[Writing rc.d scripts]]<br />
<br />
This script can be found in {{aur|rtorrent-daemon-git}} from AUR.<br />
<br />
Alternate scripts can be found on the [http://www.gentoo-wiki.info/Rtorrent#rtorrent Gentoo Wiki Archives], [http://codesnippets.joyent.com/posts/show/1947 Joyent CodeSnippets] and [http://www.bytetouch.com/blog/linux/how-to-rtorrent-with-screen-on-debian/ ByteTouch].<br />
<br />
=== Pre-allocation ===<br />
The rTorrent package in the community repository lacks pre-allocation. Compiling rTorrent with pre-allocation allows files to be allocated before downloading the torrent. The major benefit is that it limits and avoids fragmentation of the filesystem. However, this introduces a delay during the pre-allocation if the filesystem does not support the fallocate syscall natively.<br />
<br />
Therefore this switch is recommended for xfs, ext4 and btrfs filesystems, which have native fallocate syscall support. They will see no delay during preallocation and no fragmented filesystem. Pre-allocation on others filesystems will cause a delay but will not fragment the files.<br />
<br />
To make pre-allocation available, recompile libtorrent from the [[ABS]] tree with the following new switch:<br />
$ ./configure --prefix=/usr --disable-debug --with-posix-fallocate<br />
<br />
To enable it, add the following to your {{ic|~/rtorrent.rc}}:<br />
{{hc|~/rtorrent.rc|<nowiki><br />
# Preallocate files; reduces defragmentation on filesystems.<br />
system.file_allocate.set = yes<br />
</nowiki>}}<br />
<br />
=== Manage completed files ===<br />
{{note|Currently, this part requires either the svn version of rtorrent/libtorrent or having applied the patch to 0.8.6 that adds 'equal'.}}<br />
<br />
{{note|If you're having trouble with this tip, it's probably easier to follow [http://libtorrent.rakshasa.no/wiki/RTorrentCommonTasks#Movecompletedtorrentstodifferentdirectorydependingonwatchdirectory this]}}<br />
<br />
It is possible to have rtorrent sort completed torrent data to specific folders based on which 'watch' folder you drop the *.torrent into while continuing to seed. Many examples show how to do this with torrents downloaded by rtorrent. The problem is when you try to drop in 100% done torrent data and then have rtorrent check the data and resume, it will not be sorted.<br />
<br />
As a solution, use the following example in your ~/.rtorrent.rc.<br />
Make sure to change the paths.<br />
<br />
{{bc|1=<br />
# location where new torrent data is placed, and where you should place your<br />
# 'complete' data before you place your *.torrent file into the watch folder<br />
directory = /home/user/torrents/incomplete<br />
<br />
# schedule a timer event named 'watch_directory_1':<br />
# 1) triggers 10 seconds after rtorrent starts<br />
# 2) triggers at 10 second intervals thereafter<br />
# 3) Upon trigger, attempt to load (and start) new *.torrent files found in /home/user/torrents/watch/<br />
# 4) set a variable named 'custom1' with the value "/home/user/torrents/complete"<br />
# NOTE: if you do not want it to automatically start the torrent, change 'load_start' to 'load'<br />
schedule = watch_directory_1,10,10,"load_start=/home/user/torrents/watch/*.torrent,d.set_custom1=/home/user/torrents/complete"<br />
<br />
# insert a method with the alias 'checkdirs1'<br />
# 1) returns true if the current path of the torrent data is not equal to the value of custom1<br />
# 2) otherwise, returns false<br />
system.method.insert=checkdirs1,simple,"not=\"$equal={d.get_custom1=,d.get_base_path=}\""<br />
<br />
# insert a method with the alias 'movecheck1'<br />
# 1) returns true if all 3 commands return true ('result of checkdirs1' && 'torrent is 100% done', 'custom1 variable is set')<br />
# 2) otherwise, returns false<br />
system.method.insert=movecheck1,simple,"and={checkdirs1=,d.get_complete=,d.get_custom1=}"<br />
<br />
# insert a method with the alias 'movedir1'<br />
# (a series of commands, separated by ';') <br />
# 1) "set path of torrent to equal the value of custom1";<br />
# 2) "mv -u <current data path> <custom1 path>";<br />
# 3) "clear custom1", "stop the torrent","resume the torrent"<br />
# 4) stop the torrent<br />
# 5) start the torrent (to get the torrent to update the 'base path')<br />
system.method.insert=movedir1,simple,"d.set_directory=$d.get_custom1=;execute=mv,-u,$d.get_base_path=,$d.get_custom1=;d.set_custom1=;d.stop=;d.start="<br />
<br />
# set a key with the name 'move_hashed1' that is triggered by the hash_done event.<br />
# 1) When hashing of a torrent completes, this custom key will be triggered.<br />
# 2) when triggered, execute the 'movecheck1' method and check the return value.<br />
# 3) if the 'movecheck' method returns 'true', execute the 'movedir1' method we inserted above.<br />
# NOTE-0: *Only* data that has had their hash checked manually with ^R [^R = Control r].<br />
# Or on a rtorrent restart[which initiates a hash check]. Will the data move; ~/torrents/incomplete => ~/torrents/complete for example.<br />
# NOTE-1: 'branch' is an 'if' conditional statement: if(movecheck1){movedir1}<br />
system.method.set_key=event.download.hash_done,move_hashed1,"branch={$movecheck1=,movedir1=}"<br />
}}<br />
<br />
You can add additional watch folders and rules should you like to sort your torrents into special folders.<br />
<br />
For example, if you would like the torrents to download in:<br />
/home/user/torrents/incomplete<br />
and then sort the torrent data based on which folder you dropped the *.torrent into:<br />
/home/user/torrents/watch => /home/user/torrents/complete<br />
/home/user/torrents/watch/iso => /home/user/torrents/complete/iso<br />
/home/user/torrents/watch/music => /home/user/torrents/complete/music<br />
<br />
You can have the following in your .rtorrent.rc:<br />
{{bc|1=<br />
directory = /home/user/torrents/incomplete<br />
schedule = watch_directory_1,10,10,"load_start=/home/user/torrents/watch/*.torrent,d.set_custom1=/home/user/torrents/complete"<br />
<br />
schedule = watch_directory_2,10,10,"load_start=/home/user/torrents/watch/iso/*.torrent,d.set_custom1=/home/user/torrents/complete/iso"<br />
<br />
schedule = watch_directory_3,10,10,"load_start=/home/user/torrents/watch/music/*.torrent,d.set_custom1=/home/user/torrents/complete/music"<br />
<br />
system.method.insert=checkdirs1,simple,"not=\"$equal={d.get_custom1=,d.get_base_path=}\""<br />
system.method.insert=movecheck1,simple,"and={checkdirs1=,d.get_complete=,d.get_custom1=}"<br />
system.method.insert=movedir1,simple,"d.set_directory=$d.get_custom1=;execute=mv,-u,$d.get_base_path=,$d.get_custom1=;d.set_custom1=;d.stop=;d.start="<br />
system.method.set_key=event.download.hash_done,move_hashed1,"branch={$movecheck1=,movedir1=}"<br />
}}<br />
<br />
Also see [http://code.google.com/p/pyroscope/ pyroscope] especially the rtcontrol examples. There is an AUR package.<br />
<br />
==== Notification with Google Mail ====<br />
<br />
Cell phone providers allow you to "email" your phone:<br />
{{bc|<nowiki><br />
Verizon: 10digitphonenumber@vtext.com<br />
AT&T: 10digitphonenumber@txt.att.net<br />
Former AT&T customers: 10digitphonenumber@mmode.com<br />
Sprint: 10digitphonenumber@messaging.sprintpcs.com<br />
T-Mobile: 10digitphonenumber@tmomail.net<br />
Nextel: 10digitphonenumber@messaging.nextel.com<br />
Cingular: 10digitphonenumber@cingularme.com<br />
Virgin Mobile: 10digitphonenumber@vmobl.com<br />
Alltel: 10digitphonenumber@alltelmessage.com OR<br />
10digitphonenumber@message.alltel.com<br />
CellularOne: 10digitphonenumber@mobile.celloneusa.com<br />
Omnipoint: 10digitphonenumber@omnipointpcs.com<br />
Qwest: 10digitphonenumber@qwestmp.com<br />
Telus: 10digitphonenumber@msg.telus.com<br />
Rogers Wireless: 10digitphonenumber@pcs.rogers.com<br />
Fido: 10digitphonenumber@fido.ca<br />
Bell Mobility: 10digitphonenumber@txt.bell.ca<br />
Koodo Mobile: 10digitphonenumber@msg.koodomobile.com<br />
MTS: 10digitphonenumber@text.mtsmobility.com<br />
President's Choice: 10digitphonenumber@txt.bell.ca<br />
Sasktel: 10digitphonenumber@sms.sasktel.com<br />
Solo: 10digitphonenumber@txt.bell.ca<br />
</nowiki>}}<br />
<br />
*Install Heirloom's mailx program which is provided by the {{Pkg|heirloom-mailx}} package that is found in the [[Official Repositories|official repositories]].<br />
<br />
*Clear the {{ic|/etc/mail.rc}} file and enter:<br />
<br />
{{Note|Older versions of Heirloom's mailx use {{ic|/etc/nail.rc}}.}}<br />
<br />
{{bc|<nowiki><br />
set sendmail="/usr/bin/mailx"<br />
set smtp=smtp.gmail.com:587<br />
set smtp-use-starttls<br />
set ssl-verify=ignore<br />
set ssl-auth=login<br />
set smtp-auth-user=USERNAME@gmail.com<br />
set smtp-auth-password=PASSWORD<br />
</nowiki>}}<br />
<br />
Now to send the text, we must pipe a message to the mailx program.<br />
*Make a Bash script:<br />
{{hc|/path/to/mail.sh|<nowiki><br />
echo "$@: Done" | mailx 5551234567@vtext.com<br />
</nowiki>}}<br />
Where the $@ is a variable holding all the arguments passed to our script.<br />
<br />
*And finally, add the important {{ic|~/.rtorrent.rc}} line:<br />
system.method.set_key = event.download.finished,notify_me,"execute=/path/to/mail.sh,$d.get_name="<br />
<br />
Breaking it down:<br />
<br />
{{ic|notify_me}} is the command id, which may be used by other commands, it can be just about anything you like, so long as it is unique.<br />
<br />
{{ic|1=execute=}} is the rtorrent command, in this case to execute a shell command.<br />
<br />
{{ic|/path/to/mail.sh}} is the name of our script (or whatever command you want to execute) followed by a comma separated list of all the switches/arguments to be passed.<br />
<br />
{{ic|1=$d.get_name=}} 'd' is an alias to whatever download triggered the command, get_name is a function which returns the name of our download, and the '$' tells rTorrent to replace the command with its output before it calls execute.<br />
<br />
The end result? When that torrent, 'All Live Nudibranches', that we started before leaving for work finishes, we will be texted:<br />
All Live Nudibranches: Done<br />
<br />
=== Displaying active torrents ===<br />
The rtorrent doesn't list the active tab properly by default, add this line to your {{ic|.rtorrent.rc}} to show only active torrents<br />
schedule = filter_active,30,30,"view_filter = active,\"or={d.get_up_rate=,d.get_down_rate=}\""<br />
<br />
Then press {{keypress|9}} in your rTorrent client to see the changes in action.<br />
<br />
=== Adding manually trackers to torrents ===<br />
1. Select torrent to edit from rtorrent console view<br />
<br />
2. Hit Ctrl-X<br />
<br />
3. If you had four trackers type following lines one at a time (always press ^X first) to add four more for example:<br />
<br />
d.tracker.insert="5","udp://tracker.publicbt.com:80"<br />
d.tracker.insert="6","udp://tracker.openbittorrent.com:80"<br />
d.tracker.insert="7","udp://tracker.istole.it:80"<br />
d.tracker.insert="8","udp://tracker.ccc.de:80"<br />
<br />
== Troubleshooting ==<br />
<br />
=== CA certificates ===<br />
To use rTorrent with a tracker that uses HTTPS, do the following as root:<br />
<br />
{{bc|# cd /etc/ssl/certs<br />
<br />
# wget --no-check-certificate https://www.geotrust.com/resources/root_certificates/certificates/Equifax_Secure_Global_eBusiness_CA-1.cer<br />
<br />
# mv Equifax_Secure_Global_eBusiness_CA-1.cer Equifax_Secure_Global_eBusiness_CA-1.pem<br />
<br />
# c_rehash<br />
}}<br />
<br />
And from now on run rTorrent with:<br />
$ rtorrent -o http_capath=/etc/ssl/certs<br />
<br />
If you use GNU Screen, update the {{ic|.screenrc}} configuration file to reflect this change:<br />
$ screen -t rtorrent rtorrent -o http_capath=/etc/ssl/certs<br />
<br />
In rTorrent 0.8.9, set {{ic|<nowiki>network.http.ssl_verify_peer.set=0</nowiki>}} to fix the problem.<sup>[https://bbs.archlinux.org/viewtopic.php?pid=981832#p981832]</sup><br />
<br />
For more information see: [https://bbs.archlinux.org/viewtopic.php?pid=331850 rTorrent Error & CA Certificate] and [https://bbs.archlinux.org/viewtopic.php?id=45800 rTorrent Certificates Problem]<br />
<br />
== Web interface ==<br />
There are numerous web interfaces and front ends for rTorrent including:<br />
* [[WTorrent]] is a web interface to rtorrent programmed in php using Smarty templates and XMLRPC for PHP library.<br />
* [http://code.google.com/p/ntorrent/ nTorrent] is a graphical user interface client to rtorrent (a cli torrent client) written in Java.<br />
* [http://projects.cyla.homeip.net/rtwi/ rTWi] is a simple rTorrent web interface written in PHP.<br />
* [[Rtgui]] is a web based front end for rTorrent written in PHP and uses XML-RPC to communicate with the rTorrent client.<br />
* [http://code.google.com/p/rutorrent/ rutorrent] and [http://forums.rutorrent.org/ Forum] - A web-based front-end with an interface very similar to uTorrent which supports many plugins and advanced features (see also: [https://bbs.archlinux.org/viewtopic.php?pid=897577#p897577 Guide for rTorrent + ruTorrent Installation]).<br />
<br />
{{note|rTorrent is currently built using [http://xmlrpc-c.sourceforge.net/ XML-RPC for C/C++], which is required for some web interfaces (e.g. ruTorrent).}}<br />
<br />
=== XMLRPC interface ===<br />
If you want to use rtorrent with some web interfaces (e.g. rutorrent) you need to add the following line to the configuration file:<br />
scgi_port = localhost:5000<br />
<br />
For more information see: [http://libtorrent.rakshasa.no/wiki/RTorrentXMLRPCGuide Using XMLRPC with rtorrent]<br />
<br />
=== Handling magnet links (opt with firefox) ===<br />
If you wish to have magnet links automatically added to your watch folder, here is a script that will do the trick:<br />
<br />
#!/bin/bash<br />
watch_folder=~/.rtorrent/watch<br />
cd $watch_folder <br />
[[ "$1" =~ xt=urn:btih:([^&/]+) ]] || exit;<br />
echo "d10:magnet-uri${#1}:${1}e" > "meta-${BASH_REMATCH[1]}.torrent"<br />
<br />
(adapted from http://blog.gonzih.org/blog/2012/02/17/how-to-use-magnet-links-with-rtorrent/)<br />
<br />
Save it, for instance as rtorrent-magnet, give it execution permission and place it somewhere under your $PATH, <br />
then in firefox:<br />
<br />
-Type about:config into the Location Bar (address bar) and press Enter.<br />
-Right-click -> New -> Boolean -> Name: network.protocol-handler.expose.magnet -> Value -> false<br />
-Next time you click a magnet link you will be asked which application to open it with, select the script we just created and you'll be done<br />
(http://kb.mozillazine.org/Register_protocol)<br />
<br />
== See also ==<br />
* [[Screen Tips]]<br />
* [[Wikipedia:Comparison of BitTorrent clients|Comparison of BitTorrent clients]] on Wikipedia<br />
* [http://community.rutorrent.org/ rTorrent Community Wiki] - A public place for information on rTorrent and any project related to rTorrent, regarding setup, configuration, operations, and development.<br />
* [http://code.google.com/p/pyroscope/ PyroScope] - A collection of command line tools for rTorrent. It provides commands for creating and modifying torrent files, moving data on completion without having multiple watch folders, and mass-controlling download items via rTorrent's XML-RPC interface: searching, start/stop, deleting items with or without their data, etc. It also offers a documented [[Python]] API.<br />
* [http://wiki.theaveragegeek.com/howto/installing_rtorrent_and_hellanzb_on_centos5_64-bit_vps How-to Install rTorrent and Hellanzb on CentOS 5 64-bit VPS]<br />
* [http://code.google.com/p/pyroscope/wiki/DebianInstallFromSource Installation Guide for rTorrent and Pryoscope on Debian] - A collection of tools for the BitTorrent protocol and especially the rTorrent client<br />
* [http://mktorrent.sourceforge.net/ mktorrent] - A command line application used to generate torrent files, which is available as {{Pkg|mktorrent}} in the [[Official Repositories|official repositories]].<br />
<br />
<br />
'''Forum threads'''<br />
* 2009-03-11 - Arch Linux - [https://bbs.archlinux.org/viewtopic.php?id=67304 HOWTO: rTorrent stats in Conky]</div>Mayweedhttps://wiki.archlinux.org/index.php?title=RTorrent&diff=215453RTorrent2012-07-29T15:09:25Z<p>Mayweed: /* Additional Tips */</p>
<hr />
<div>{{DISPLAYTITLE:rTorrent}}<br />
[[Category:Internet Applications]]<br />
[[es:RTorrent]]<br />
[[ru:RTorrent]]<br />
[[zh-CN:RTorrent]]<br />
[http://libtorrent.rakshasa.no/ rTorrent] is a quick and efficient BitTorrent client that uses the libtorrent library. It is written in C++ and uses the [[Wikipedia:ncurses|ncurses]] programming library, which means it uses a text user interface. When combined with [[GNU Screen]] and [[Secure Shell]], it becomes a convenient remote [[Wikipedia:BitTorrent (protocol)#Operation|BitTorrent client]].<br />
<br />
== Installation ==<br />
[[pacman|Install]] the {{Pkg|rtorrent}} package that is available in the [[Official Repositories|official repositories]].<br />
<br />
Alternatively, install {{AUR|rtorrent-svn}} or {{AUR|rtorrent-extended}} from the [[Arch User Repository|AUR]].<br />
<br />
== Configuration ==<br />
{{note|See the rTorrent wiki article on this subject for more information: [http://libtorrent.rakshasa.no/wiki/RTorrentCommonTasks Common Tasks in rTorrent for Dummies]}}<br />
<br />
Before running rTorrent, find the example configuration file {{ic|/usr/share/doc/rtorrent/rtorrent.rc}} and copy it to {{ic|~/.rtorrent.rc}}:<br />
<br />
$ cp /usr/share/doc/rtorrent/rtorrent.rc ~/.rtorrent.rc<br />
<br />
=== Performance ===<br />
{{note|See the rTorrent wiki article on this subject for more information: [http://libtorrent.rakshasa.no/wiki/RTorrentPerformanceTuning Performance Tuning]}}<br />
<br />
The values for the following options are dependent on the system's hardware and Internet connection speed. To find the optimal values read: [http://torrentfreak.com/optimize-your-BitTorrent-download-speed Optimize Your BitTorrent Download Speed]<br />
{{bc|<nowiki><br />
min_peers = 40<br />
max_peers = 52<br />
<br />
min_peers_seed = 10<br />
max_peers_seed = 52<br />
<br />
max_uploads = 8<br />
<br />
download_rate = 200<br />
upload_rate = 28<br />
</nowiki>}}<br />
<br />
The {{ic|check_hash}} option executes a hash check when a torrent download is complete or rTorrent is started. When starting, it checks for errors in your completed files. <br />
check_hash = yes<br />
<br />
=== Create and manage files ===<br />
The {{ic|directory}} option will determine where your torrent data will be saved. Be sure to enter the absolute path, as rTorrent may not follow relative paths:<br />
directory = /home/[user]/torrents/<br />
<br />
The {{ic|session}} option allows rTorrent to save the progess of your torrents. It is recommended to create a directory called {{ic|.session}} (e.g. {{ic|$ mkdir ~/.session}}).<br />
session = /home/[user]/.session/<br />
<br />
The {{ic|schedule}} option has rTorrent watch a particular directory for new torrent files. Saving a torrent file to this directory will automatically start the download. Remember to create the directory that will be watched (e.g. {{ic|$ mkdir ~/watch}}). Also, be careful when using this option as rTorrent will move the torrent file to your session folder and rename it to its hash value.<br />
schedule = watch_directory,5,5,load_start=/home/[user]/watch/*.torrent<br />
schedule = untied_directory,5,5,stop_untied=<br />
schedule = tied_directory,5,5,start_tied=<br />
<br />
The following {{ic|schedule}} option is intended to stop rTorrent from downloading data when disk space is low.<br />
schedule = low_diskspace,5,60,close_low_diskspace=100M<br />
<br />
=== Port configuration ===<br />
The {{ic|port_range}} option sets which port(s) to use for listening. It is recommended to use a port that is higher than 49152 (see: [[Wikipedia:List of TCP and UDP port numbers|List of port numbers]]). Although, rTorrent allows a range of ports, a single port is recommended.<br />
port_range = 49164-49164<br />
<br />
Additionally, make sure port forwarding is enabled for the proper port(s) (see: [http://portforward.com/english/routers/port_forwarding/routerindex.htm Port Forward Guides]).<br />
<br />
=== Additional settings ===<br />
The {{ic|encryption}} option enables or disables encryption. It is very important to enable this option, not only for yourself, but also for your peers in the torrent swarm. Some users need to obscure their bandwidth usage from their ISP. And it does not hurt to enable it even if you do not need the added security.<br />
encryption = allow_incoming,try_outgoing,enable_retry<br />
{{Wikipedia|BitTorrent Protocol Encryption}}<br />
<br />
This final {{ic|dht}} option enables [[Wikipedia:Distributed hash table|DHT]] support. DHT is common among public trackers and will allow the client to acquire more peers.<br />
{{bc|<nowiki><br />
dht = auto<br />
dht_port = 6881<br />
peer_exchange = yes<br />
</nowiki>}}<br />
<br />
{{note|See the rTorrent wiki article on this subject for more information: [http://libtorrent.rakshasa.no/wiki/RTorrentUsingDHT Using DHT]}}<br />
<br />
== Key bindings ==<br />
<br />
rTorrent relies exclusively on keyboard shortcuts for user input. A quick reference is available in the table below. A complete guide is available on the rTorrent wiki (see: [http://libtorrent.rakshasa.no/wiki/RTorrentUserGuide rTorrent User Guide]).<br />
<br />
{{note|Striking {{keypress|Ctrl-q}} twice in quick succession will make rTorrent shutdown without waiting to send a stop announce to the connected trackers.}}<br />
<br />
{| class="toccolours" border="1" cellpadding="4" cellspacing="0" style="margin:5px;"<br />
|-<br />
!width="75" |Cmd<br />
!Action<br />
|-<br />
|Ctrl-q<br />
|Quit application<br />
|-<br />
|Ctrl-s<br />
|Start download. Runs hash first unless already done.<br />
|-<br />
|Ctrl-d<br />
|Stop an active download or remove a stopped download<br />
|-<br />
|Ctrl-k<br />
|Stop and close the files of an active download.<br />
|-<br />
|Ctrl-r<br />
|Initiate hash check of torrent. Without starting to download/upload.<br />
|-<br />
|Left<br />
|Returns to the previous screen<br />
|-<br />
|Right<br />
|Goes to the next screen<br />
|-<br />
|Backspace/Return<br />
|Adds the specified *.torrent<br />
|-<br />
|<nowiki>a|s|d</nowiki><br />
|<nowiki>Increase global upload throttle about 1|5|50 KB/s</nowiki><br />
|-<br />
|<nowiki>A|S|D</nowiki><br />
|<nowiki>Increase global download throttle about 1|5|50 KB/s</nowiki><br />
|-<br />
|<nowiki>z|x|c</nowiki><br />
|<nowiki>Decrease global upload throttle about 1|5|50 KB/s</nowiki><br />
|-<br />
|<nowiki>Z|X|C</nowiki><br />
|<nowiki>Decrease global download throttle about 1|5|50 KB/s</nowiki><br />
|}<br />
=== Redundant mapping ===<br />
{{Keypress|Ctrl-s}} is often used for terminal control to stop screen output while {{Keypress|Ctrl-q}} is used to start it. These mappings may interfere with rTorrent. Check to see if these terminal options are bound to a mapping:<br />
{{hc|$ stty -a|<nowiki>...<br />
swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V;<br />
...<br />
</nowiki>}}<br />
<br />
To remove the mappings, change the terminal characteristics to undefine the aforementioned special characters (i.e. {{ic|stop}} and {{ic|start}}):<br />
# stty stop undef<br />
# stty start undef<br />
<br />
To remove these mappings automatically at startup you may add the two preceding commands to your {{ic|~/.bashrc}} file.<br />
<br />
== Additional Tips ==<br />
<br />
=== Separate session with Screen ===<br />
[[GNU Screen]] is a wrapper that allows separation between the text program and the shell from which it was launched.<br />
<br />
Screen flow-control interferes with the {{Keypress|Ctrl-q}} mapping (see: [[#Redundant mapping|Redundant mapping]]). To disable it add the following to {{ic|~/.screenrc}}:<br />
defflow off<br />
<br />
An alternative is to escape the command and send it directly to rTorrent. In other words, use {{Keypress|Ctrl-a}} {{Keypress|q}} to quit rTorrent within GNU Screen.<br />
<br />
To automatically start rTorrent within Screen, add the following to the {{ic|~/.screenrc}} configuration file:<br />
screen -t rtorrent rtorrent <br />
<br />
==== Run as a daemon ====<br />
{{note|See the rTorrent wiki article on this subject for more information: [http://libtorrent.rakshasa.no/wiki/RTorrentCommonTasks#StartingrTorrentonSystemStartup Starting rTorrent on System Startup]}}<br />
<br />
Alternatively, GNU Screen and rTorrent can be run together as a [[daemon]] (see also: [https://bbs.archlinux.org/viewtopic.php?id=53395 Arch Linux Forums thread], [https://forums.gentoo.org/viewtopic-t-600362-postdays-0-postorder-asc-start-0.html Gentoo Discussion Forums thread]). <br />
<br />
To use this script with [[tmux]], replace line 9 with {{ic|su - USER -c 'tmux new -s rtorrent -d rtorrent' &> /dev/null}} (see: [https://bbs.archlinux.org/viewtopic.php?id=126718 rTorrent daemon with tmux]).<br />
<br />
With root permissions create the following file:<br />
<br />
{{hc|/etc/rc.d/rtorrent|<nowiki><br />
#!/bin/bash<br />
<br />
. /etc/rc.conf<br />
. /etc/rc.d/functions<br />
<br />
case "$1" in<br />
start)<br />
stat_busy "Starting rtorrent"<br />
su - USER -c 'screen -d -m -S rtorrent rtorrent' &> /dev/null<br />
if [ $? -gt 0 ]; then<br />
stat_fail<br />
else<br />
add_daemon rtorrent<br />
stat_done<br />
fi<br />
;;<br />
stop)<br />
stat_busy "Stopping rtorrent"<br />
killall -w -s 2 /usr/bin/rtorrent &> /dev/null<br />
if [ $? -gt 0 ]; then<br />
stat_fail<br />
else<br />
rm_daemon rtorrent<br />
stat_done<br />
fi<br />
;;<br />
restart)<br />
$0 stop<br />
sleep 1<br />
$0 start<br />
;;<br />
*)<br />
echo "usage: $0 {start|stop|restart}"<br />
esac<br />
exit 0<br />
</nowiki>}}<br />
<br />
Make sure to change USER to the username that will be running rtorrent.<br />
<br />
Make the file executable:<br />
# chmod +x /etc/rc.d/rtorrent<br />
<br />
Creating a {{ic|.rtorrent.rc}} file with relative paths in a user's home directory will break the rc.d script. To run multiple instances of rTorrent with relative paths under different users, replace line 9 in {{ic|/etc/rc.d/rtorrent}} with the following:<br />
su username -c 'cd /home/username && screen -d -m -S rtorrent rtorrent' &> /dev/null<br />
<br />
Alternatively, you can set absolute paths in the configuration file.<br />
<br />
To run the daemon user multiple users create one rc.d script for each user. Then replace line 9 in {{ic|/etc/rc.d/rtorrent}} with the following: <br />
su - username -c 'killall -w -s 2 /usr/bin/rtorrent' &> /dev/null<br />
<br />
To connect to the daemon process on a remote machine use [[Secure Shell|SSH]]:<br />
$ ssh -t rtorrent@192.168.1.10 'screen -r'<br />
<br />
Or if you used [[tmux]] instead of [[screen]]:<br />
$ ssh -t rtorrent@192.168.1.10 'tmux attach -t rtorrent'<br />
<br />
For more information about daemon scripts see: [[Writing rc.d scripts]]<br />
<br />
This script can be found in {{aur|rtorrent-daemon-git}} from AUR.<br />
<br />
Alternate scripts can be found on the [http://www.gentoo-wiki.info/Rtorrent#rtorrent Gentoo Wiki Archives], [http://codesnippets.joyent.com/posts/show/1947 Joyent CodeSnippets] and [http://www.bytetouch.com/blog/linux/how-to-rtorrent-with-screen-on-debian/ ByteTouch].<br />
<br />
=== Pre-allocation ===<br />
The rTorrent package in the community repository lacks pre-allocation. Compiling rTorrent with pre-allocation allows files to be allocated before downloading the torrent. The major benefit is that it limits and avoids fragmentation of the filesystem. However, this introduces a delay during the pre-allocation if the filesystem does not support the fallocate syscall natively.<br />
<br />
Therefore this switch is recommended for xfs, ext4 and btrfs filesystems, which have native fallocate syscall support. They will see no delay during preallocation and no fragmented filesystem. Pre-allocation on others filesystems will cause a delay but will not fragment the files.<br />
<br />
To make pre-allocation available, recompile libtorrent from the [[ABS]] tree with the following new switch:<br />
$ ./configure --prefix=/usr --disable-debug --with-posix-fallocate<br />
<br />
To enable it, add the following to your {{ic|~/rtorrent.rc}}:<br />
{{hc|~/rtorrent.rc|<nowiki><br />
# Preallocate files; reduces defragmentation on filesystems.<br />
system.file_allocate.set = yes<br />
</nowiki>}}<br />
<br />
=== Manage completed files ===<br />
{{note|Currently, this part requires either the svn version of rtorrent/libtorrent or having applied the patch to 0.8.6 that adds 'equal'.}}<br />
<br />
{{note|If you're having trouble with this tip, it's probably easier to follow [http://libtorrent.rakshasa.no/wiki/RTorrentCommonTasks#Movecompletedtorrentstodifferentdirectorydependingonwatchdirectory this]}}<br />
<br />
It is possible to have rtorrent sort completed torrent data to specific folders based on which 'watch' folder you drop the *.torrent into while continuing to seed. Many examples show how to do this with torrents downloaded by rtorrent. The problem is when you try to drop in 100% done torrent data and then have rtorrent check the data and resume, it will not be sorted.<br />
<br />
As a solution, use the following example in your ~/.rtorrent.rc.<br />
Make sure to change the paths.<br />
<br />
{{bc|1=<br />
# location where new torrent data is placed, and where you should place your<br />
# 'complete' data before you place your *.torrent file into the watch folder<br />
directory = /home/user/torrents/incomplete<br />
<br />
# schedule a timer event named 'watch_directory_1':<br />
# 1) triggers 10 seconds after rtorrent starts<br />
# 2) triggers at 10 second intervals thereafter<br />
# 3) Upon trigger, attempt to load (and start) new *.torrent files found in /home/user/torrents/watch/<br />
# 4) set a variable named 'custom1' with the value "/home/user/torrents/complete"<br />
# NOTE: if you do not want it to automatically start the torrent, change 'load_start' to 'load'<br />
schedule = watch_directory_1,10,10,"load_start=/home/user/torrents/watch/*.torrent,d.set_custom1=/home/user/torrents/complete"<br />
<br />
# insert a method with the alias 'checkdirs1'<br />
# 1) returns true if the current path of the torrent data is not equal to the value of custom1<br />
# 2) otherwise, returns false<br />
system.method.insert=checkdirs1,simple,"not=\"$equal={d.get_custom1=,d.get_base_path=}\""<br />
<br />
# insert a method with the alias 'movecheck1'<br />
# 1) returns true if all 3 commands return true ('result of checkdirs1' && 'torrent is 100% done', 'custom1 variable is set')<br />
# 2) otherwise, returns false<br />
system.method.insert=movecheck1,simple,"and={checkdirs1=,d.get_complete=,d.get_custom1=}"<br />
<br />
# insert a method with the alias 'movedir1'<br />
# (a series of commands, separated by ';') <br />
# 1) "set path of torrent to equal the value of custom1";<br />
# 2) "mv -u <current data path> <custom1 path>";<br />
# 3) "clear custom1", "stop the torrent","resume the torrent"<br />
# 4) stop the torrent<br />
# 5) start the torrent (to get the torrent to update the 'base path')<br />
system.method.insert=movedir1,simple,"d.set_directory=$d.get_custom1=;execute=mv,-u,$d.get_base_path=,$d.get_custom1=;d.set_custom1=;d.stop=;d.start="<br />
<br />
# set a key with the name 'move_hashed1' that is triggered by the hash_done event.<br />
# 1) When hashing of a torrent completes, this custom key will be triggered.<br />
# 2) when triggered, execute the 'movecheck1' method and check the return value.<br />
# 3) if the 'movecheck' method returns 'true', execute the 'movedir1' method we inserted above.<br />
# NOTE-0: *Only* data that has had their hash checked manually with ^R [^R = Control r].<br />
# Or on a rtorrent restart[which initiates a hash check]. Will the data move; ~/torrents/incomplete => ~/torrents/complete for example.<br />
# NOTE-1: 'branch' is an 'if' conditional statement: if(movecheck1){movedir1}<br />
system.method.set_key=event.download.hash_done,move_hashed1,"branch={$movecheck1=,movedir1=}"<br />
}}<br />
<br />
You can add additional watch folders and rules should you like to sort your torrents into special folders.<br />
<br />
For example, if you would like the torrents to download in:<br />
/home/user/torrents/incomplete<br />
and then sort the torrent data based on which folder you dropped the *.torrent into:<br />
/home/user/torrents/watch => /home/user/torrents/complete<br />
/home/user/torrents/watch/iso => /home/user/torrents/complete/iso<br />
/home/user/torrents/watch/music => /home/user/torrents/complete/music<br />
<br />
You can have the following in your .rtorrent.rc:<br />
{{bc|1=<br />
directory = /home/user/torrents/incomplete<br />
schedule = watch_directory_1,10,10,"load_start=/home/user/torrents/watch/*.torrent,d.set_custom1=/home/user/torrents/complete"<br />
<br />
schedule = watch_directory_2,10,10,"load_start=/home/user/torrents/watch/iso/*.torrent,d.set_custom1=/home/user/torrents/complete/iso"<br />
<br />
schedule = watch_directory_3,10,10,"load_start=/home/user/torrents/watch/music/*.torrent,d.set_custom1=/home/user/torrents/complete/music"<br />
<br />
system.method.insert=checkdirs1,simple,"not=\"$equal={d.get_custom1=,d.get_base_path=}\""<br />
system.method.insert=movecheck1,simple,"and={checkdirs1=,d.get_complete=,d.get_custom1=}"<br />
system.method.insert=movedir1,simple,"d.set_directory=$d.get_custom1=;execute=mv,-u,$d.get_base_path=,$d.get_custom1=;d.set_custom1=;d.stop=;d.start="<br />
system.method.set_key=event.download.hash_done,move_hashed1,"branch={$movecheck1=,movedir1=}"<br />
}}<br />
<br />
Also see [http://code.google.com/p/pyroscope/ pyroscope] especially the rtcontrol examples. There is an AUR package.<br />
<br />
==== Notification with Google Mail ====<br />
<br />
Cell phone providers allow you to "email" your phone:<br />
{{bc|<nowiki><br />
Verizon: 10digitphonenumber@vtext.com<br />
AT&T: 10digitphonenumber@txt.att.net<br />
Former AT&T customers: 10digitphonenumber@mmode.com<br />
Sprint: 10digitphonenumber@messaging.sprintpcs.com<br />
T-Mobile: 10digitphonenumber@tmomail.net<br />
Nextel: 10digitphonenumber@messaging.nextel.com<br />
Cingular: 10digitphonenumber@cingularme.com<br />
Virgin Mobile: 10digitphonenumber@vmobl.com<br />
Alltel: 10digitphonenumber@alltelmessage.com OR<br />
10digitphonenumber@message.alltel.com<br />
CellularOne: 10digitphonenumber@mobile.celloneusa.com<br />
Omnipoint: 10digitphonenumber@omnipointpcs.com<br />
Qwest: 10digitphonenumber@qwestmp.com<br />
Telus: 10digitphonenumber@msg.telus.com<br />
Rogers Wireless: 10digitphonenumber@pcs.rogers.com<br />
Fido: 10digitphonenumber@fido.ca<br />
Bell Mobility: 10digitphonenumber@txt.bell.ca<br />
Koodo Mobile: 10digitphonenumber@msg.koodomobile.com<br />
MTS: 10digitphonenumber@text.mtsmobility.com<br />
President's Choice: 10digitphonenumber@txt.bell.ca<br />
Sasktel: 10digitphonenumber@sms.sasktel.com<br />
Solo: 10digitphonenumber@txt.bell.ca<br />
</nowiki>}}<br />
<br />
*Install Heirloom's mailx program which is provided by the {{Pkg|heirloom-mailx}} package that is found in the [[Official Repositories|official repositories]].<br />
<br />
*Clear the {{ic|/etc/mail.rc}} file and enter:<br />
<br />
{{Note|Older versions of Heirloom's mailx use {{ic|/etc/nail.rc}}.}}<br />
<br />
{{bc|<nowiki><br />
set sendmail="/usr/bin/mailx"<br />
set smtp=smtp.gmail.com:587<br />
set smtp-use-starttls<br />
set ssl-verify=ignore<br />
set ssl-auth=login<br />
set smtp-auth-user=USERNAME@gmail.com<br />
set smtp-auth-password=PASSWORD<br />
</nowiki>}}<br />
<br />
Now to send the text, we must pipe a message to the mailx program.<br />
*Make a Bash script:<br />
{{hc|/path/to/mail.sh|<nowiki><br />
echo "$@: Done" | mailx 5551234567@vtext.com<br />
</nowiki>}}<br />
Where the $@ is a variable holding all the arguments passed to our script.<br />
<br />
*And finally, add the important {{ic|~/.rtorrent.rc}} line:<br />
system.method.set_key = event.download.finished,notify_me,"execute=/path/to/mail.sh,$d.get_name="<br />
<br />
Breaking it down:<br />
<br />
{{ic|notify_me}} is the command id, which may be used by other commands, it can be just about anything you like, so long as it is unique.<br />
<br />
{{ic|1=execute=}} is the rtorrent command, in this case to execute a shell command.<br />
<br />
{{ic|/path/to/mail.sh}} is the name of our script (or whatever command you want to execute) followed by a comma separated list of all the switches/arguments to be passed.<br />
<br />
{{ic|1=$d.get_name=}} 'd' is an alias to whatever download triggered the command, get_name is a function which returns the name of our download, and the '$' tells rTorrent to replace the command with its output before it calls execute.<br />
<br />
The end result? When that torrent, 'All Live Nudibranches', that we started before leaving for work finishes, we will be texted:<br />
All Live Nudibranches: Done<br />
<br />
=== Displaying active torrents ===<br />
The rtorrent doesn't list the active tab properly by default, add this line to your {{ic|.rtorrent.rc}} to show only active torrents<br />
schedule = filter_active,30,30,"view_filter = active,\"or={d.get_up_rate=,d.get_down_rate=}\""<br />
<br />
Then press {{keypress|9}} in your rTorrent client to see the changes in action.<br />
<br />
=== Adding manually trackers to torrents ===<br />
1. Select torrent to edit from rtorrent console view<br />
<br />
2. Hit Ctrl-X<br />
<br />
3. If you had four trackers type following lines one at a time (always press ^X first) to add four more.<br />
d.tracker.insert="5","udp://tracker.publicbt.com:80"<br />
d.tracker.insert="6","udp://tracker.openbittorrent.com:80"<br />
d.tracker.insert="7","udp://tracker.istole.it:80"<br />
d.tracker.insert="8","udp://tracker.ccc.de:80"<br />
<br />
== Troubleshooting ==<br />
<br />
=== CA certificates ===<br />
To use rTorrent with a tracker that uses HTTPS, do the following as root:<br />
<br />
{{bc|# cd /etc/ssl/certs<br />
<br />
# wget --no-check-certificate https://www.geotrust.com/resources/root_certificates/certificates/Equifax_Secure_Global_eBusiness_CA-1.cer<br />
<br />
# mv Equifax_Secure_Global_eBusiness_CA-1.cer Equifax_Secure_Global_eBusiness_CA-1.pem<br />
<br />
# c_rehash<br />
}}<br />
<br />
And from now on run rTorrent with:<br />
$ rtorrent -o http_capath=/etc/ssl/certs<br />
<br />
If you use GNU Screen, update the {{ic|.screenrc}} configuration file to reflect this change:<br />
$ screen -t rtorrent rtorrent -o http_capath=/etc/ssl/certs<br />
<br />
In rTorrent 0.8.9, set {{ic|<nowiki>network.http.ssl_verify_peer.set=0</nowiki>}} to fix the problem.<sup>[https://bbs.archlinux.org/viewtopic.php?pid=981832#p981832]</sup><br />
<br />
For more information see: [https://bbs.archlinux.org/viewtopic.php?pid=331850 rTorrent Error & CA Certificate] and [https://bbs.archlinux.org/viewtopic.php?id=45800 rTorrent Certificates Problem]<br />
<br />
== Web interface ==<br />
There are numerous web interfaces and front ends for rTorrent including:<br />
* [[WTorrent]] is a web interface to rtorrent programmed in php using Smarty templates and XMLRPC for PHP library.<br />
* [http://code.google.com/p/ntorrent/ nTorrent] is a graphical user interface client to rtorrent (a cli torrent client) written in Java.<br />
* [http://projects.cyla.homeip.net/rtwi/ rTWi] is a simple rTorrent web interface written in PHP.<br />
* [[Rtgui]] is a web based front end for rTorrent written in PHP and uses XML-RPC to communicate with the rTorrent client.<br />
* [http://code.google.com/p/rutorrent/ rutorrent] and [http://forums.rutorrent.org/ Forum] - A web-based front-end with an interface very similar to uTorrent which supports many plugins and advanced features (see also: [https://bbs.archlinux.org/viewtopic.php?pid=897577#p897577 Guide for rTorrent + ruTorrent Installation]).<br />
<br />
{{note|rTorrent is currently built using [http://xmlrpc-c.sourceforge.net/ XML-RPC for C/C++], which is required for some web interfaces (e.g. ruTorrent).}}<br />
<br />
=== XMLRPC interface ===<br />
If you want to use rtorrent with some web interfaces (e.g. rutorrent) you need to add the following line to the configuration file:<br />
scgi_port = localhost:5000<br />
<br />
For more information see: [http://libtorrent.rakshasa.no/wiki/RTorrentXMLRPCGuide Using XMLRPC with rtorrent]<br />
<br />
=== Handling magnet links (opt with firefox) ===<br />
If you wish to have magnet links automatically added to your watch folder, here is a script that will do the trick:<br />
<br />
#!/bin/bash<br />
watch_folder=~/.rtorrent/watch<br />
cd $watch_folder <br />
[[ "$1" =~ xt=urn:btih:([^&/]+) ]] || exit;<br />
echo "d10:magnet-uri${#1}:${1}e" > "meta-${BASH_REMATCH[1]}.torrent"<br />
<br />
(adapted from http://blog.gonzih.org/blog/2012/02/17/how-to-use-magnet-links-with-rtorrent/)<br />
<br />
Save it, for instance as rtorrent-magnet, give it execution permission and place it somewhere under your $PATH, <br />
then in firefox:<br />
<br />
-Type about:config into the Location Bar (address bar) and press Enter.<br />
-Right-click -> New -> Boolean -> Name: network.protocol-handler.expose.magnet -> Value -> false<br />
-Next time you click a magnet link you will be asked which application to open it with, select the script we just created and you'll be done<br />
(http://kb.mozillazine.org/Register_protocol)<br />
<br />
== See also ==<br />
* [[Screen Tips]]<br />
* [[Wikipedia:Comparison of BitTorrent clients|Comparison of BitTorrent clients]] on Wikipedia<br />
* [http://community.rutorrent.org/ rTorrent Community Wiki] - A public place for information on rTorrent and any project related to rTorrent, regarding setup, configuration, operations, and development.<br />
* [http://code.google.com/p/pyroscope/ PyroScope] - A collection of command line tools for rTorrent. It provides commands for creating and modifying torrent files, moving data on completion without having multiple watch folders, and mass-controlling download items via rTorrent's XML-RPC interface: searching, start/stop, deleting items with or without their data, etc. It also offers a documented [[Python]] API.<br />
* [http://wiki.theaveragegeek.com/howto/installing_rtorrent_and_hellanzb_on_centos5_64-bit_vps How-to Install rTorrent and Hellanzb on CentOS 5 64-bit VPS]<br />
* [http://code.google.com/p/pyroscope/wiki/DebianInstallFromSource Installation Guide for rTorrent and Pryoscope on Debian] - A collection of tools for the BitTorrent protocol and especially the rTorrent client<br />
* [http://mktorrent.sourceforge.net/ mktorrent] - A command line application used to generate torrent files, which is available as {{Pkg|mktorrent}} in the [[Official Repositories|official repositories]].<br />
<br />
<br />
'''Forum threads'''<br />
* 2009-03-11 - Arch Linux - [https://bbs.archlinux.org/viewtopic.php?id=67304 HOWTO: rTorrent stats in Conky]</div>Mayweedhttps://wiki.archlinux.org/index.php?title=GRUB&diff=212107GRUB2012-07-06T10:12:47Z<p>Mayweed: /* Install grub-bios package */</p>
<hr />
<div>[[Category:Boot loaders]]<br />
[[cs:GRUB2]]<br />
[[es:GRUB2]]<br />
[[fr:GRUB2]]<br />
[[id:GRUB2]]<br />
[[it:GRUB2]]<br />
[[ru:GRUB2]]<br />
[[tr:GRUB2]]<br />
[[zh-CN:GRUB2]]<br />
[[zh-TW:GRUB2]]<br />
{{Article summary start}}<br />
{{Article summary text|Covers various aspects of the next generation of the GRand Unified Bootloader (GRUB2).}}<br />
{{Article summary heading|Overview}}<br />
{{Article summary text|{{Boot process overview}}}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|Burg}} - Burg is a brand-new boot loader based on GRUB2. It uses a new object format which allows it to be built in a wider range of OS, including Linux, Windows, OS X, Solaris, FreeBSD, etc. It also has a highly configurable menu system which works in both text and graphic mode. <br />
{{Article summary heading|Resources}}<br />
{{Article summary link|GNU GRUB -- GNU Project|http://www.gnu.org/software/grub/}}<br />
{{Article summary end}}<br />
<br />
[http://www.gnu.org/software/grub/ GRUB2] is the next generation of the GRand Unified Bootloader (GRUB). GRUB2 is derived from [http://www.nongnu.org/pupa/ PUPA] which was a research project to investigate the next generation of GRUB. GRUB2 has been rewritten from scratch to clean up everything and provide modularity and portability [http://www.gnu.org/software/grub/grub-faq.en.html#q1].<br />
<br />
In brief, the ''bootloader'' is the first software program that runs when a computer starts. It is responsible for loading and transferring control to the Linux kernel. The kernel, in turn, initializes the rest of the operating system.<br />
<br />
{{Note|The name ''GRUB'' officially refers to version ''2'' of the software, see [http://www.gnu.org/software/grub/]. If you are looking for the article on the legacy version, see [[GRUB Legacy]].}}<br />
<br />
{{Note|From 1.99-6 onwards, GRUB2 supports [[Btrfs]] as root (without a separate {{ic|/boot}} filesystem) compressed with either zlib or LZO.}}<br />
<br />
{{Note|The [[Archboot]] ISO's installer script supports {{Pkg|grub-bios}} and {{Pkg|grub-efi-x86_64}} installation. The official installer script AIF (Arch Installation Framework) does not support GRUB(2) yet.}}<br />
<br />
{{Note|For GRUB2 UEFI info, it is recommended to read the [[UEFI]], [[GPT]] and [[UEFI_Bootloaders]] pages before reading this page.}}<br />
<br />
== Preface ==<br />
<br />
[[GRUB Legacy]] (i.e. version 0.9x) is considered legacy by upstream and is being replaced by GRUB2 and [[Syslinux]] in many distributions. Upstream recommends GRUB2 >=1.99 over GRUB Legacy, even for current GRUB Legacy users.<br />
<br />
=== Notes for current GRUB Legacy users ===<br />
<br />
* There are differences in the commands of GRUB and GRUB2. Familiarize yourself with [http://www.gnu.org/software/grub/manual/grub.html#Commands GRUB2 commands] before proceeding (e.g. "find" has been replaced with "search").<br />
<br />
* GRUB2 is now ''modular'' and no longer requires "stage 1.5". As a result, the bootloader itself is limited -- modules are loaded from the hard drive as needed to expand functionality (e.g. for [[LVM]] or RAID support).<br />
<br />
* Device naming has changed between GRUB and GRUB2. Partitions are numbered from 1 instead of 0 while drives are still numbered from 0, and prefixed with partition-table type. For example, {{ic|/dev/sda1}} would be referred to as {{ic|(hd0,msdos1)}} (for MBR) or {{ic|(hd0,gpt1)}} (for GPT) using GRUB2.<br />
<br />
=== Preliminary Requirements for GRUB2 ===<br />
<br />
==== BIOS systems ====<br />
<br />
===== [[GPT]] specific instructions =====<br />
<br />
GRUB2 in BIOS-GPT configuration requires a BIOS Boot Partition to embed its {{ic|core.img}} in the absence of post-MBR gap in GPT partitioned systems (which is taken over by the GPT Primary Header and Primary Partition table). This partition is used by GRUB2 only in BIOS-GPT setups. No such partition type exists in case of MBR partitioning (at least not for GRUB2). This partition is also not required if the system is UEFI based, as no embedding of bootsectors takes place in that case. Syslinux does not require this partition.<br />
<br />
For a BIOS-GPT configuration, create a 2 MiB partition using cgdisk or GNU Parted with no filesystem. The location of the partition in the partition table does not matter but it should be within the first 2 TiB region of the disk. It is advisable to put it somewhere in the beginning of the disk before the {{ic|/boot}} partition. Set the partition type to "EF02" in cgdisk or {{ic|set <BOOT_PART_NUM> bios_grub on}} in GNU Parted.<br />
<br />
{{Note|This partition should be created before {{ic|grub-install}} or {{ic|grub-setup}} is run or before the '''Install Bootloader''' step of the Archlinux installer (if GRUB2 BIOS is selected as bootloader).}}<br />
<br />
===== [[MBR]] aka msdos partitioning specific instructions =====<br />
<br />
Usually the post-MBR gap (after the 512 byte MBR region and before the start of the 1st partition) in many MBR (or msdos disklabel) partitioned systems is 32 KiB when DOS compatibility cylinder alignment issues are satisfied in the partition table. However a post-MBR gap of about 1 to 2 MiB is recommended to provide sufficient room for embedding GRUB2's {{ic|core.img}} ({{bug|24103}}). It is advisable to use a partitioner which supports 1 MiB partition alignment to obtain this space as well as satisfy other non-512 byte sector issues (which are unrelated to embedding of {{ic|core.img}}).<br />
<br />
If you do not dual-boot with MS Windows (any version) in BIOS systems, it is advisable to switch to GPT partitioning - [[GUID_Partition_Table#Convert_from_MBR_to_GPT]]<br />
<br />
{{Note|Create the 2MiB partition mentioned above BEFORE you convert to GPT. If you do not, gparted will not resize your boot partition to allow its creation, and when you reboot GRUB2 will not know where to look.}}<br />
<br />
==== UEFI systems ====<br />
<br />
===== Create and Mount the UEFI SYSTEM PARTITION =====<br />
<br />
{{Note|It is recommended to read the [[UEFI]], [[GPT]] and [[UEFI_Bootloaders]] pages before reading this part.}}<br />
<br />
Follow [[Unified_Extensible_Firmware_Interface#Create_an_UEFI_System_Partition_in_Linux]] for instructions on creating a UEFI SYSTEM PARTITION. Then mount the UEFI SYSTEM PARTITION at {{ic|/boot/efi}}. If you have mounted the UEFISYS partition in some other mountpoint, replace {{ic|/boot/efi}} in the below instructions with that mountpoint:<br />
<br />
# mkdir -p /boot/efi<br />
# mount -t vfat <UEFISYS_PART_DEVICE> /boot/efi<br />
<br />
Create a <UEFI_SYSTEM_PARTITION>{{ic|/EFI}} directory, if it does not exist:<br />
<br />
# mkdir -p /boot/efi/EFI<br />
<br />
== Installation ==<br />
<br />
=== During Arch Linux installation ===<br />
<br />
* Skip the '''Install Bootloader''' step and exit the installer.<br />
* Configure the network:<br />
# aif -p partial-configure-network<br />
This will bring up a prompt; put in the network interface to use, (e.g., {{ic|eth0}}) and use DHCP for easy configuration.<br />
* If you did not configure the installed system's {{ic|/etc/resolv.conf}} file during installation (for instance, if you plan to let DHCP generate it later), you will need to copy the one generated by AIF when it configured the network:<br />
# cp /etc/resolv.conf /mnt/etc/resolv.conf<br />
* If you run into network issues in the pacman update step below, you may have needed to install the {{Pkg|net-tools}} package.<br />
* Check and see if the {{ic|dm_mod}} module is loaded. If it is not, load it manually:<br />
# lsmod | grep dm_mod<br />
# modprobe dm-mod<br />
{{Note|This is necessary at this point, and cannot be postponed after the chroot. If you try to use modprobe in a chroot environment that has a later kernel version from that of the installing device (at the time of writing, 2.6.33), modprobe will fail. This happens routinely using the Arch "net" installations.}}<br />
* From the installer's live shell, chroot to the installed system:<br />
# mount -o bind /dev /mnt/dev<br />
# mount -t proc /proc /mnt/proc/<br />
# mount -t sysfs /sys /mnt/sys/<br />
# chroot /mnt bash<br />
* Update pacman's database:<br />
# pacman-db-upgrade<br />
* Refresh the package list (with an extra {{ic|-y}} flag to force a refresh of all package lists even if they appear to be up to date):<br />
# pacman -Syy<br />
* Install the GRUB2 package as mentioned in the section [[#From a running Arch Linux]] (Note that the {{ic|dm-mod}} module has already been loaded, no need to do that again).<br />
<br />
=== From a running Arch Linux ===<br />
<br />
==== BIOS systems ====<br />
<br />
===== Backup Important Data =====<br />
<br />
Though a GRUB(2) installation should run smoothly, it is strongly recommended to keep the GRUB-legacy files before installing {{Pkg|grub-bios}}.<br />
<br />
mv /boot/grub /boot/grub-legacy<br />
<br />
Backup the MBR which contains the boot code and partition table (Replace {{ic|/dev/sd'''X'''}} with your actual disk path)<br />
<br />
# dd if=/dev/sdX of=/path/to/backup/mbr_backup bs=512 count=1<br />
<br />
Only 446 bytes of the MBR contain boot code, the next 64 contain the partition table. If you do not want to overwrite your partition table when restoring, it is strongly advise to backup only the MBR boot code:<br />
<br />
# dd if=/dev/sdX of=/path/to/backup/bootcode_backup bs=446 count=1<br />
<br />
If unable to install GRUB2 correctly see [[GRUB2#Restore_GRUB_Legacy]].<br />
<br />
===== Install grub-bios package =====<br />
<br />
The GRUB(2) package can be installed with pacman (and will replace {{Pkg|grub-legacy}} or {{Pkg|grub}}, if it is installed):<br />
<br />
# pacman -S grub2-bios<br />
<br />
{{Note|Simply installing the package won't update the {{ic|/boot/grub/i386-pc/core.img}} file and the GRUB(2) modules in {{ic|/boot/grub/i386-pc}}. You need to update them manually using {{ic|grub-install}} as explained below.}}<br />
<br />
Also load the device-mapper kernel module without which {{ic|grub-probe}} does not reliably detect disks and partitions:<br />
<br />
# modprobe dm-mod<br />
<br />
===== Install grub-bios boot files =====<br />
<br />
There are 3 ways to install GRUB(2) boot files in BIOS booting:<br />
*[[#Install_to_440-byte_MBR_boot_code_region]] (recommended) , <br />
*[[#Install_to_Partition_or_Partitionless_Disk]] (not recommended),<br />
*[[#Generate_core.img_alone]] (safest method, but requires another BIOS bootloader like [[grub-legacy]] or [[syslinux]] to be installed to chainload {{ic|/boot/grub/i386-pc/core.img}}). <br />
<br />
====== Install to 440-byte MBR boot code region ======<br />
<br />
To setup {{ic|grub-bios}} in the 440-byte Master Boot Record boot code region, populate the {{ic|/boot/grub}} directory, generate the {{ic|/boot/grub/i386-pc/core.img}} file, and embed it in the 32 KiB (minimum size - varies depending on partition alignment) post-MBR gap (MBR disks) or in BIOS Boot Partition (GPT disks), run:<br />
<br />
# grub-install --directory=/usr/lib/grub/i386-pc --target=i386-pc --boot-directory=/boot --recheck --debug /dev/sda<br />
# mkdir -p /boot/grub/locale<br />
# cp /usr/share/locale/en@quot/LC_MESSAGES/grub.mo /boot/grub/locale/en.mo<br />
<br />
where {{ic|/dev/sda}} is the destination of the installation (in this case the MBR of the first SATA disk). If you use [[LVM]] for your {{ic|/boot}}, you can install GRUB2 on multiple physical disks. <br />
<br />
The {{ic|--no-floppy}} tells {{ic|grub-bios}} utilities not to search for any floppy devices which reduces the overall execution time of {{ic|grub-install}} on many systems (it will also prevent the issue below from occurring). Otherwise you get an error that looks like this:<br />
<br />
grub-probe: error: Cannot get the real path of '/dev/fd0'<br />
Auto-detection of a filesystem module failed.<br />
Please specify the module with the option '--modules' explicitly.<br />
<br />
{{Note|{{ic|--no-floppy}} has been removed from {{ic|grub-install}} in 2.00~beta2 upstream release, and replaced with {{ic|--allow-floppy}}.}}<br />
<br />
{{Warning|Make sure to check the {{ic|/boot}} directory if you use the latter. Sometimes the {{ic| boot-directory}} parameter creates another {{ic|/boot}} folder inside of {{ic|/boot}}. A wrong install would look like: {{ic|/boot/boot/grub/}}.}}<br />
<br />
====== Install to Partition or Partitionless Disk ======<br />
<br />
{{Note|{{ic|grub-bios}} (any version - including upstream Bazaar repo) does not encourage installation to a partition boot sector or a partitionless disk like GRUB Legacy or syslinux does. This kind of setup is prone to breakage, especially during updates, and is not supported by Arch devs.}}<br />
<br />
To set up {{ic|grub-bios}} to a partition boot sector, to a partitionless disk (also called superfloppy) or to a floppy disk, run (using for example {{ic|/dev/sdaX}} as the {{ic|/boot}} partition):<br />
<br />
# chattr -i /boot/grub/i386-pc/core.img<br />
# grub-install --directory=/usr/lib/grub/i386-pc --target=i386-pc --boot-directory=/boot --recheck --force --debug /dev/sdaX<br />
# mkdir -p /boot/grub/locale<br />
# cp /usr/share/locale/en@quot/LC_MESSAGES/grub.mo /boot/grub/locale/en.mo<br />
# chattr +i /boot/grub/i386-pc/core.img<br />
<br />
You need to use the {{ic|--force}} option to allow usage of blocklists and should not use {{ic|1=--grub-setup=/bin/true}} (which is similar to simply generating {{ic|core.img}}).<br />
<br />
{{ic|grub-install}} will give out warnings like which should give you the idea of what might go wrong with this approach:<br />
<br />
/sbin/grub-setup: warn: Attempting to install GRUB to a partitionless disk or to a partition. This is a BAD idea.<br />
/sbin/grub-setup: warn: Embedding is not possible. GRUB can only be installed in this setup by using blocklists. <br />
However, blocklists are UNRELIABLE and their use is discouraged.<br />
<br />
Without {{ic|--force}} you may get the below error and {{ic|grub-setup}} will not setup its boot code in the partition boot sector:<br />
<br />
/sbin/grub-setup: error: will not proceed with blocklists<br />
<br />
With {{ic|--force}} you should get:<br />
<br />
Installation finished. No error reported.<br />
<br />
The reason why {{ic|grub-setup}} does not by default allow this is because in case of partition or a partitionless disk is that {{ic|grub-bios}} relies on embedded blocklists in the partition bootsector to locate the {{ic|/boot/grub/i386-pc/core.img}} file and the prefix dir {{ic|/boot/grub}}. The sector locations of {{ic|core.img}} may change whenever the filesystem in the partition is being altered (files copied, deleted etc.). For more info see https://bugzilla.redhat.com/show_bug.cgi?id=728742 and https://bugzilla.redhat.com/show_bug.cgi?id=730915.<br />
<br />
The workaround for this is to set the immutable flag on {{ic|/boot/grub/i386-pc/core.img}} (using chattr command as mentioned above) so that the sector locations of the {{ic|core.img}} file in the disk is not altered. The immutable flag on {{ic|/boot/grub/i386-pc/core.img}} needs to be set only if {{ic|grub-bios}} is installed to a partition boot sector or a partitionless disk, not in case of installtion to MBR or simple generation of {{ic|core.img}} without embedding any bootsector (mentioned above).<br />
<br />
====== Generate core.img alone ======<br />
<br />
To populate the {{ic|/boot/grub}} directory and generate a {{ic|/boot/grub/i386-pc/core.img}} file '''without''' embedding any {{ic|grub-bios}} bootsector code in the MBR, post-MBR region, or the partition bootsector, add {{ic|1=--grub-setup=/bin/true}} to {{ic|grub-install}}:<br />
<br />
# grub-install --directory=/usr/lib/grub/i386-pc --target=i386-pc --grub-setup=/bin/true --boot-directory=/boot --recheck --debug /dev/sda<br />
# mkdir -p /boot/grub/locale<br />
# cp /usr/share/locale/en@quot/LC_MESSAGES/grub.mo /boot/grub/locale/en.mo<br />
<br />
You can then chainload GRUB2's {{ic|core.img}} from GRUB Legacy or syslinux as a Linux kernel or a multiboot kernel.<br />
<br />
===== Generate GRUB2 BIOS Config file =====<br />
<br />
Finally, generate a configuration for GRUB2 (this is explained in greater detail in the Configuration section):<br />
<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
{{Note|The file path is {{ic|/boot/grub/grub.cfg}}, NOT {{ic|/boot/grub/i386-pc/grub.cfg}}.}}<br />
<br />
If grub2 complains about "no suitable mode found" while booting, go to [[#Correct_GRUB2_No_Suitable_Mode_Found_Error]].<br />
<br />
If {{ic|grub-mkconfig}} fails, convert your {{ic|/boot/grub/menu.lst}} file to {{ic|/boot/grub/grub.cfg}} using:<br />
<br />
# grub-menulst2cfg /boot/grub/menu.lst /boot/grub/grub.cfg<br />
<br />
For example:<br />
<br />
{{hc|/boot/grub/menu.lst|<nowiki><br />
default=0<br />
timeout=5<br />
<br />
title Arch Linux Stock Kernel<br />
root (hd0,0)<br />
kernel /vmlinuz-linux root=/dev/sda2 ro<br />
initrd /initramfs-linux.img<br />
<br />
title Arch Linux Stock Kernel Fallback<br />
root (hd0,0)<br />
kernel /vmlinuz-linux root=/dev/sda2 ro<br />
initrd /initramfs-linux-fallback.img<br />
</nowiki>}}<br />
<br />
{{hc|/boot/grub/grub.cfg|<nowiki><br />
set default='0'; if [ x"$default" = xsaved ]; then load_env; set default="$saved_entry"; fi<br />
set timeout=5<br />
<br />
menuentry 'Arch Linux Stock Kernel' {<br />
set root='(hd0,1)'; set legacy_hdbias='0'<br />
legacy_kernel '/vmlinuz-linux' '/vmlinuz-linux' 'root=/dev/sda2' 'ro'<br />
legacy_initrd '/initramfs-linux.img' '/initramfs-linux.img'<br />
<br />
}<br />
<br />
menuentry 'Arch Linux Stock Kernel Fallback' {<br />
set root='(hd0,1)'; set legacy_hdbias='0'<br />
legacy_kernel '/vmlinuz-linux' '/vmlinuz-linux' 'root=/dev/sda2' 'ro'<br />
legacy_initrd '/initramfs-linux-fallback.img' '/initramfs-linux-fallback.img'<br />
}<br />
</nowiki>}}<br />
<br />
If you forgot to create a GRUB2 {{ic|/boot/grub/grub.cfg}} config file and simply rebooted into GRUB2 Command Shell, type:<br />
<br />
sh:grub> insmod legacycfg<br />
sh:grub> legacy_configfile ${prefix}/menu.lst<br />
<br />
Boot into Arch and re-create the proper GRUB2 {{ic|/boot/grub/grub.cfg}} config file.<br />
<br />
{{Note|This option works only in BIOS systems, not in UEFI systems.}}<br />
<br />
===== Multiboot in BIOS =====<br />
<br />
====== Boot Microsoft Windows installed in BIOS-MBR mode ======<br />
<br />
{{Note|GRUB2 supports booting {{ic|bootmgr}} directly and chainload of partition boot sector is no longer required to boot Windows in a BIOS-MBR setup.}}<br />
<br />
Find the UUID of the NTFS filesystem of the Windows's SYSTEM PARTITION where the {{ic|bootmgr}} and its files reside. For example, if Windows {{ic|bootmgr}} exists at {{ic|/media/Windows/bootmgr}}:<br />
<br />
# grub-probe --target=fs_uuid /media/Windows/bootmgr<br />
69B235F6749E84CE<br />
<br />
Then, add the below code to {{ic|/etc/grub.d/40_custom}} and regenerate {{ic|grub.cfg}} with {{ic|grub-mkconfig}} as explained above to boot Windows (Vista, 7 or 8) installed in BIOS-MBR mode:<br />
<br />
<pre><br />
#!/bin/sh<br />
menuentry "Microsoft Windows 7 BIOS-MBR" {<br />
insmod part_msdos<br />
insmod ntfs<br />
insmod search_fs_uuid<br />
insmod ntldr <br />
search --fs-uuid --no-floppy --set=root 69B235F6749E84CE<br />
ntldr /bootmgr<br />
}</pre><br />
<br />
For Windows XP:<br />
<br />
menuentry "Microsoft Windows XP" {<br />
insmod part_msdos<br />
insmod ntfs<br />
insmod search_fs_uuid<br />
insmod ntldr <br />
search --fs-uuid --no-floppy --set=root 69B235F6749E84CE<br />
ntldr /ntldr<br />
}<br />
<br />
==== [[UEFI]] systems ====<br />
<br />
{{Note|It is recommended to read the [[UEFI]], [[GPT]] and [[UEFI_Bootloaders]] pages before reading this part.}}<br />
<br />
===== Install grub-uefi package =====<br />
<br />
{{Note|Unless specified as EFI 1.x , EFI and UEFI terms are used interchangeably to denote UEFI 2.x firmware. Also unless stated explicitely, the instructions are general and not Mac specific. Some of them may not work or may be different in Macs. Apple's EFI implementation is neither a EFI 1.x version nor UEFI 2.x version but mixes up both. This kind of firmware does not fall under any one UEFI Specification version and is therefore not a standard UEFI firmware.}}<br />
<br />
GRUB2 UEFI bootloader is available in Arch Linux only from version 1.99~rc1. To install, first [https://wiki.archlinux.org/index.php/Unified_Extensible_Firmware_Interface#Detecting_UEFI_Firmware_Arch Detect which UEFI firmware arch] you have (either x86_64 or i386).<br />
<br />
Depending on that, install the appropriate package<br />
<br />
For 64-bit aka x86_64 UEFI firmware:<br />
# pacman -S grub-efi-x86_64<br />
<br />
For 32-bit aka i386 UEFI firmware:<br />
# pacman -S grub-efi-i386<br />
<br />
{{Note|Simply installing the package won't update the {{ic|grub.efi}} file and the GRUB(2) modules in the UEFI System Partition. You need to do this manually using {{ic|grub-install}} as explained below.}}<br />
<br />
Also load the device-mapper kernel module without which {{ic|grub-probe}} does not reliably detect disks and partitions:<br />
<br />
# modprobe dm-mod<br />
<br />
===== Install grub-uefi boot files =====<br />
<br />
====== Install to UEFI SYSTEM PARTITION ======<br />
<br />
{{Note|The below commands assume you are using {{ic|grub-efi-x86_64}} (for {{ic|grub-efi-i386}} replace {{ic|x86_64}} with {{ic|i386}} in the below commands).}}<br />
<br />
The UEFI system partition will need to be mounted at {{ic|/boot/efi/}} for the GRUB2 install script to detect it:<br />
<br />
# mkdir -p /boot/efi<br />
# mount -t vfat /dev/sdXY /boot/efi<br />
<br />
Install GRUB UEFI application to {{ic|/boot/efi/EFI/arch_grub}} and its modules to {{ic|/boot/grub/x86_64-efi}} (recommended) using:<br />
<br />
# grub-install --directory=/usr/lib/grub/x86_64-efi --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=arch_grub --boot-directory=/boot --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 />
If you want to install grub2 modules and {{ic|grub.cfg}} at the directory {{ic|/boot/efi/EFI/grub}} and the {{ic|grubx64.efi}} application at {{ic|/boot/efi/EFI/arch_grub}} use:<br />
<br />
# grub-install --directory=/usr/lib/grub/x86_64-efi --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=arch_grub --boot-directory=/boot/efi/EFI --recheck --debug<br />
# mkdir -p /boot/efi/EFI/grub/locale<br />
# cp /usr/share/locale/en@quot/LC_MESSAGES/grub.mo /boot/efi/EFI/grub/locale/en.mo<br />
<br />
In this case {{ic|grub-efi-x86_64}} will be installed into {{ic|/boot/grub}}, making the behavior consistent with the BIOS verion of GRUB2, but this is not recommended if you use both {{ic|grub-bios}} and {{ic|grub-efi-x86_64}} in your system, as this will overwrite {{ic|grub-bios }}modules in {{ic|/boot/grub}}.<br />
<br />
The {{ic|--efi-directory}} option mentions the mountpoint of UEFI SYSTEM PARTITION , {{ic|--bootloader-id}} mentions the name of the directory used to store the {{ic|grubx64.efi}} file and {{ic|--boot-directory}} mentions the directory wherein the actual modules will be installed (and into which {{ic|grub.cfg}} should be created).<br />
<br />
The actual paths are:<br />
<br />
<efi-directory>/<EFI or efi>/<bootloader-id>/grubx64.efi<br />
<br />
<boot-directory>/grub/x86_64-efi/<all modules, grub.efi, core.efi, grub.cfg><br />
<br />
{{Note|the {{ic|--bootloader-id}} option does not change {{ic|<boot-directory>/grub}}, i.e. you cannot install the modules to {{ic|<boot-directory>/<bootloader-id>}}, the path is hard-coded to be {{ic|<boot-directory>/grub}}.}}<br />
<br />
In {{ic|<nowiki>--efi-directory=/boot/efi --boot-directory=/boot/efi/EFI --bootloader-id=grub</nowiki>}}:<br />
<br />
<efi-directory>/<EFI or efi>/<bootloader-id> == <boot-directory>/grub == /boot/efi/EFI/grub<br />
<br />
In {{ic|<nowiki>--efi-directory=/boot/efi --boot-directory=/boot/efi/EFI --bootloader-id=arch_grub</nowiki>}}:<br />
<br />
<efi-directory>/<EFI or efi>/<bootloader-id> == /boot/efi/EFI/arch_grub<br />
<boot-directory>/grub == /boot/efi/EFI/grub<br />
<br />
In {{ic|<nowiki>--efi-directory=/boot/efi --boot-directory=/boot --bootloader-id=arch_grub</nowiki>}}:<br />
<br />
<efi-directory>/<EFI or efi>/<bootloader-id> == /boot/efi/EFI/arch_grub<br />
<boot-directory>/grub == /boot/grub<br />
<br />
In {{ic|<nowiki>--efi-directory=/boot/efi --boot-directory=/boot --bootloader-id=grub</nowiki>}}:<br />
<br />
<efi-directory>/<EFI or efi>/<bootloader-id> == /boot/efi/EFI/grub<br />
<boot-directory>/grub == /boot/grub<br />
<br />
The {{ic|<nowiki><efi-directory>/<EFI or efi>/<bootloader-id>/grubx64.efi</nowiki>}} is an exact copy of {{ic|<nowiki><boot-directory>/grub/x86_64-efi/core.efi</nowiki>}}.<br />
<br />
{{Note|In GRUB2 2.00~beta4, the {{ic|grub-install}} option {{ic|--efi-directory}} replaces {{ic|--root-directory}} and the latter is deprecated.}}<br />
{{Note|The options {{ic|--efi-directory}} and {{ic|--bootloader-id}} are specific to GRUB2 UEFI.}}<br />
<br />
In all the cases the UEFI SYSTEM PARTITION should be mounted for {{ic|grub-install}} to install {{ic|grubx64.efi}} in it, which will be launched by the firmware (using the {{ic|efibootmgr}} created boot entry in non-Mac systems).<br />
<br />
If you notice carefully, there is no <device_path> option (Eg: {{ic|/dev/sda}}) at the end of the {{ic|grub-install}} command unlike the case of setting up GRUB2 for BIOS systems. Any <device_path> provided will be ignored by the install script as UEFI bootloaders do not use MBR or Partition boot sectors at all.<br />
<br />
You may now be able to UEFI boot your system by creating a {{ic|grub.cfg}} file by following [[#Generate_GRUB2_UEFI_Config_file]] and [[#Create_GRUB2_entry_in_the_Firmware_Boot_Manager]].<br />
<br />
===== Create GRUB2 entry in the Firmware Boot Manager =====<br />
<br />
====== Non-Mac UEFI systems ======<br />
<br />
{{ic|grub-install}} will ensure that {{ic|/boot/efi/EFI/arch_grub/grubx64.efi}} is launched by default if it detects {{ic|efibootmgr}} and if it is able to access UEFI Runtime Services. Follow [[Unified_Extensible_Firmware_Interface#efibootmgr]] for more info.<br />
<br />
If you have problems running GRUB2 in UEFI mode you can try the following (worked on an ASUS Z68 mainboard):<br />
<br />
# cp /boot/efi/EFI/arch_grub/grubx64.efi /boot/efi/shellx64.efi<br />
<br />
or<br />
<br />
# cp /boot/efi/EFI/arch_grub/grubx64.efi /boot/efi/EFI/shellx64.efi<br />
<br />
or<br />
<br />
# cp /boot/efi/EFI/arch_grub/grubx64.efi /boot/efi/EFI/tools/shellx64.efi<br />
<br />
After this launch the UEFI Shell from the UEFI setup/menu (in ASUS UEFI BIOS, switch to advanced mode, press Exit in the top right corner and choose "Launch EFI shell from filesystem device"). The GRUB2 menu will show up and you can boot into your system. Afterwards you can use efibootmgr to setup a menu entry (see above).<br />
<br />
====== Apple Mac EFI systems ======<br />
<br />
{{Note|TODO: GRUB upstream Bazaar mactel branch http://bzr.savannah.gnu.org/lh/grub/branches/mactel/changes . No further update from grub developers.}}<br />
{{Note|TODO: Experimental "bless" utility for Linux by Fedora developers - {{AUR|mactel-boot}}. Requires more testing.}}<br />
<br />
Use bless command from within Mac OS X to set {{ic|grubx64.efi}} as the default boot option. You can also boot from the Mac OS X install disc and launch a Terminal there if you only have Linux installed. In the Terminal, create a directory and mount the EFI System Partition:<br />
<br />
# cd /Volumes<br />
# mkdir efi<br />
# mount -t msdos /dev/disk0s1 /Volumes/efi<br />
<br />
Then run bless on {{ic|grub.efi}} and on the EFI partition to set them as the default boot options.<br />
<br />
# bless --folder=/Volumes/efi --file=/Volumes/efi/efi/arch_grub/grubx64.efi --setBoot<br />
# bless --mount=/Volumes/efi --file=/Volumes/efi/efi/arch_grub/grubx64.efi --setBoot<br />
<br />
More info at https://help.ubuntu.com/community/UEFIBooting#Apple_Mac_EFI_systems_.28both_EFI_architecture.29.<br />
<br />
===== Generate GRUB2 UEFI Config file =====<br />
<br />
Finally, generate a configuration for GRUB2 (this is explained in greater detail in the Configuration section):<br />
<br />
# grub-mkconfig -o <boot-directory>/grub/grub.cfg<br />
<br />
{{Note|The file path is {{ic|<boot-directory>/grub/grub.cfg}}, NOT {{ic|<boot-directory>/grub/x86_64-efi/grub.cfg}}.}}<br />
<br />
If you used {{ic|<nowiki>--boot-directory=/boot</nowiki>}}:<br />
<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
If you used {{ic|<nowiki>--boot-directory=/boot/efi/EFI</nowiki>}}:<br />
<br />
# grub-mkconfig -o /boot/efi/EFI/grub/grub.cfg<br />
<br />
This is independent of the value of {{ic|--bootloader-id}} option.<br />
<br />
If GRUB2 complains about "no suitable mode found" while booting, try [[#Correct_GRUB2_No_Suitable_Mode_Found_Error]].<br />
<br />
===== Create GRUB2 Standalone UEFI Application =====<br />
<br />
It is possible to create a {{ic|grubx64_standalone.efi}} application which has all the modules embeddded in a memdisk within the uefi application, thus removing the need for having a separate directory populated with all the GRUB2 uefi modules and other related files. This is done using the {{ic|grub-mkstandalone}} command which is included in {{Pkg|grub-common}} >= 1:1.99-6 package.<br />
<br />
The easiest way to do this would be with the install command already mentioned before, but specifying the modules to include. For example:<br />
<br />
# grub-mkstandalone --directory="/usr/lib/grub/x86_64-efi/" --format="x86_64-efi" --compression="xz" \<br />
--output="/boot/efi/EFI/arch_grub/grubx64_standalone.efi" <any extra files you want to include><br />
<br />
The {{ic|grubx64_standalone.efi}} file expects {{ic|grub.cfg}} to be within its $prefix which is {{ic|(memdisk)/boot/grub}}. The memdisk is embedded within the efi app. The {{ic|grub-mkstandlone}} script allow passing files to be included in the memdisk image to be as the arguments to the script (in <any extra files you want to include>).<br />
<br />
If you have the {{ic|grub.cfg}} at {{ic|/home/user/Desktop/grub.cfg}}, then create a temporary {{ic|/home/user/Desktop/boot/grub/}} directory, copy the {{ic|/home/user/Desktop/grub.cfg}} to {{ic|/home/user/Desktop/boot/grub/grub.cfg}}, cd into {{ic|/home/user/Desktop/boot/grub/}} and run:<br />
<br />
# grub-mkstandalone --directory="/usr/lib/grub/x86_64-efi/" --format="x86_64-efi" --compression="xz" \<br />
--output="/boot/efi/EFI/arch_grub/grubx64_standalone.efi" "boot/grub/grub.cfg"<br />
<br />
The reason to cd into {{ic|/home/user/Desktop/boot/grub/}} and to pass the file path as {{ic|boot/grub/grub.cfg}} (notice the lack of a leading slash - boot/ vs /boot/ ) is because {{ic|dir1/dir2/file}} is included as {{ic|(memdisk)/dir1/dir2/file}} by the {{ic|grub-mkstandalone}} script. <br />
<br />
If you pass {{ic|/home/user/Desktop/grub.cfg}} the file will be included as {{ic|(memdisk)/home/user/Desktop/grub.cfg}}. If you pass {{ic|/home/user/Desktop/boot/grub/grub.cfg}} the file will be included as {{ic|(memdisk)/home/user/Desktop/boot/grub/grub.cfg}}. That is the reason for cd'ing into {{ic|/home/user/Desktop/boot/grub/}} and passing {{ic|boot/grub/grub.cfg}}, to includ the file as {{ic|(memdisk)/boot/grub/grub.cfg}}, which is what {{ic|grub.efi}} expects the file to be.<br />
<br />
You need to create an UEFI Boot Manager entry for {{ic|/boot/efi/EFI/arch_grub/grubx64_standalone.efi}} using {{ic|efibootmgr}}. Follow [[#Create GRUB2 entry in the Firmware Boot Manager]].<br />
<br />
===== Multiboot in UEFI =====<br />
<br />
====== Chainload Microsoft Windows x86_64 UEFI-GPT ======<br />
<br />
Find the UUID of the FAT32 filesystem in the UEFI SYSTEM PARTITION where the Windows UEFI Bootloader files reside. For example, if Windows {{ic|bootmgfw.efi}} exists at {{ic|/boot/efi/EFI/Microsoft/Boot/bootmgfw.efi}} (ignore the upper-lower case differences since that is immaterial in FAT filesystem):<br />
<br />
# grub-probe --target=fs_uuid /boot/efi/EFI/Microsoft/Boot/bootmgfw.efi<br />
1ce5-7f28<br />
<br />
# grub-probe --target=hints_string /boot/efi/EFI/Microsoft/Boot/bootmgfw.efi<br />
--hint-bios=hd0,gpt1 --hint-efi=hd0,gpt1 --hint-baremetal=ahci0,gpt1<br />
<br />
Then, add this code to {{ic|/boot/grub/grub.cfg}} OR {{ic|/boot/efi/EFI/grub/grub.cfg}} to chainload Windows x86_64 (Vista SP1+, 7 or 8) installed in UEFI-GPT mode:<br />
<br />
menuentry "Microsoft Windows x86_64 UEFI-GPT" {<br />
insmod part_gpt<br />
insmod fat<br />
insmod search_fs_uuid<br />
insmod chain<br />
search --fs-uuid --no-floppy --set=root --hint-bios=hd0,gpt1 --hint-efi=hd0,gpt1 --hint-baremetal=ahci0,gpt1 1ce5-7f28<br />
chainloader /efi/Microsoft/Boot/bootmgfw.efi<br />
}<br />
<br />
== Configuration ==<br />
<br />
You can also choose to automatically generate or manually edit {{ic|grub.cfg}}.<br />
<br />
{{Note|If GRUB2 was installed with the {{ic|--boot-directory}} option set, the {{ic|grub.cfg}} file must be placed in the same directory as {{ic|grubx64.efi}}. Otherwise, the {{ic|grub.cfg}} file goes in {{ic|/boot/grub/}}, just like in the BIOS version of GRUB2.}}<br />
<br />
{{Note|Here is a quite complete description of how to configure GRUB2: http://members.iinet.net/~herman546/p20/GRUB2%20Configuration%20File%20Commands.html }}<br />
<br />
=== Automatically generating using grub-mkconfig (Recommended) ===<br />
<br />
The GRUB2 {{ic|menu.lst}} equivalent configuration files are {{ic|/etc/default/grub}} and {{ic|/etc/grub.d/*}}. {{ic|grub-mkconfig}} uses these files to generate {{ic|grub.cfg}}. By default the script outputs to stdout. To generate a {{ic|grub.cfg}} file run the command:<br />
<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
{{ic|/etc/grub.d/10_linux}} is set to automatically add menu items for Arch linux that work out of the box, to any generated configuration. Other operating systems may need to be added manually by editing {{ic|/etc/grub.d/40_custom}}<br />
<br />
==== Additional arguments ====<br />
<br />
To pass custom additional arguments to the linux image, you can set the {{ic|GRUB_CMDLINE_LINUX}} variable in {{ic|/etc/default/grub}}. This is analogous to adding commands to the kernel line in legacy GRUB.<br />
<br />
For example, use {{ic|<nowiki>GRUB_CMDLINE_LINUX="resume=/dev/sdaX"</nowiki>}} where {{ic|sda'''X'''}} is your swap partition to enable resume after hibernation.<br />
<br />
You can also use {{ic|<nowiki>GRUB_CMDLINE_LINUX="resume=/dev/disk/by-uuid/${swap_uuid}"</nowiki>}}, where {{ic|${swap_uuid} }} is the [[Persistent_block_device_naming|uuid]] of your swap partition.<br />
<br />
=== Manually creating grub.cfg ===<br />
<br />
{{Warning|Editing this file is strongly ''not'' recommended. The file is generated by the {{ic|grub-mkconfig}} command, and it is best to edit your {{ic|/etc/default/grub}} or one of the scripts in the {{ic|/etc/grub.d}} folder.}}<br />
<br />
A basic GRUB config file uses the following options<br />
* {{ic|(hdX,Y)}} is the partition {{ic|Y}} on disk {{ic|X}}, partition numbers starting at 1, disk numbers starting at 0<br />
* {{ic|1=set default=N}} is the default boot entry that is chosen after timeout for user action<br />
* {{ic|1=set timeout=M}} is the time {{ic|M}} to wait in seconds for a user selection before default is booted<br />
* {{ic|<nowiki>menuentry "title" {entry options}</nowiki>}} is a boot entry titled {{ic|title}}<br />
* {{ic|1=set root=(hdX,Y)}} sets the boot partition, where the kernel and GRUB modules are stored (boot need not be a separate partition, and may simply be a directory under the "root" partition ({{ic|/}})<br />
<br />
An example configuration:<br />
<br />
{{hc<br />
|/boot/grub/grub.cfg<br />
|<nowiki><br />
# Config file for GRUB2 - The GNU GRand Unified Bootloader<br />
# /boot/grub/grub.cfg<br />
<br />
# DEVICE NAME CONVERSIONS<br />
#<br />
# Linux Grub<br />
# -------------------------<br />
# /dev/fd0 (fd0)<br />
# /dev/sda (hd0)<br />
# /dev/sdb2 (hd1,2)<br />
# /dev/sda3 (hd0,3)<br />
#<br />
<br />
# Timeout for menu<br />
set timeout=5<br />
<br />
# Set default boot entry as Entry 0<br />
set default=0<br />
<br />
# (0) Arch Linux<br />
menuentry "Arch Linux" {<br />
set root=(hd0,1)<br />
linux /vmlinuz-linux root=/dev/sda3 ro<br />
initrd /initramfs-linux.img<br />
}<br />
<br />
## (1) Windows<br />
#menuentry "Windows" {<br />
#set root=(hd0,3)<br />
#chainloader +1<br />
#}<br />
</nowiki>}}<br />
<br />
=== Dual-booting ===<br />
<br />
{{Note|If you want GRUB2 to automatically search for other systems, you may wish to install {{Pkg|os-prober}}.}}<br />
<br />
==== Using grub-mkconfig ====<br />
The best way to add other entries is editing the {{ic|/etc/grub.d/40_custom}}. The entries in this file will be automatically added when running {{ic|grub-mkconfig}}.<br />
After adding the new lines, run:<br />
# grub-mkconfig -o /boot/grub/grub.cfg <br />
to generate an updated {{ic|grub.cfg}}.<br />
<br />
===== With GNU/Linux =====<br />
<br />
Assuming that the other distro is on partition {{ic|sda2}}:<br />
<br />
menuentry "Other Linux" {<br />
set root=(hd0,2)<br />
linux /boot/vmlinuz (add other options here as required)<br />
initrd /boot/initrd.img (if the other kernel uses/needs one)<br />
}<br />
<br />
===== With FreeBSD =====<br />
<br />
Requires that FreeBSD is installed on a single partition with UFS. Assuming it is installed on {{ic|sda4}}:<br />
<br />
menuentry "FreeBSD" {<br />
set root=(hd0,4)<br />
chainloader +1<br />
}<br />
<br />
===== With Windows =====<br />
<br />
This assumes that your Windows partition is {{ic|sda3}}.<br />
<br />
# (2) Windows XP<br />
menuentry "Windows XP" {<br />
set root=(hd0,3)<br />
chainloader (hd0,3)+1<br />
}<br />
<br />
If the Windows bootloader is on an entirely different hard drive than GRUB, it may be necessary to trick Windows into believing that it is the first hard drive. This was possible in GRUB Legacy with {{ic|map}} and is now done with {{ic|drivemap}}. Assuming GRUB is on {{ic|hd0}} and Windows is on {{ic|hd2}}, you need to add the following after {{ic|set root}}:<br />
<br />
drivemap -s hd0 hd2<br />
<br />
==== With Windows via EasyBCD and NeoGRUB ====<br />
<br />
Since EasyBCD's NeoGRUB currently does not understand the GRUB2 menu format, chainload to it by replacing the contents of your {{ic|C:\NST\menu.lst}} file with lines similar to the following:<br />
<br />
default 0<br />
timeout 1<br />
<br />
title Chainload into GRUB v2<br />
root (hd0,7)<br />
kernel /boot/grub/i386-pc/core.img<br />
<br />
===Visual Configuration===<br />
<br />
In GRUB2 it is possible, by default, to change the look of the menu. Make sure to initialize, if not done already, GRUB2 graphical terminal, gfxterm, with proper video mode, gfxmode, in GRUB2. This can be seen in the section [[#Correct_GRUB2_No_Suitable_Mode_Found_Error]]. This video mode is passed by GRUB2 to the linux kernel via 'gfxpayload' so any visual configurations need this mode in order to be in effect.<br />
<br />
====Setting the framebuffer resolution ====<br />
<br />
GRUB2 can set the framebuffer for both GRUB2 itself and the kernel. The old {{ic|1=vga=}} way is deprecated. The preferred method is editing {{ic|/etc/default/grub}} as the following sample:<br />
<br />
GRUB_GFXMODE=1024x768x32<br />
GRUB_GFXPAYLOAD_LINUX=keep<br />
<br />
To generate the changes, run: <br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
The {{ic|gfxpayload}} property will make sure the kernel keeps the resolution.<br />
<br />
{{Note|If this example does not work for you try to replace {{ic|1=gfxmode="1024x768x32"}} by {{ic|1=vbemode="0x105"}}. Remember to replace the specified resolution with one suitable for your screen.}}<br />
{{Note|To show all the modes you can use {{ic|1=# hwinfo --framebuffer}} (hwinfo is available in [community]), while at GRUB2 prompt you can use the {{ic|1=vbeinfo}} command.}}<br />
<br />
If this method does not work for you, the deprecated {{ic|1=vga=}} method will still work. Just<br />
add it next to the {{ic|1="GRUB_CMDLINE_LINUX_DEFAULT="}} line in {{ic|/etc/default/grub}}<br />
for eg: {{ic|1="GRUB_CMDLINE_LINUX_DEFAULT="quiet splash vga=792"}} will give you a {{ic|1024x768}} resolution.<br />
<br />
You can choose one of these resolutions: {{ic|640×480}}, {{ic|800×600}}, {{ic|1024×768}}, {{ic|1280×1024}}, {{ic|1600×1200}}<br />
<br />
====915resolution hack ====<br />
<br />
Some times for Intel graphic adapters neither {{ic|1=# hwinfo --framebuffer}} nor {{ic|1=vbeinfo}} will show you the desired resolution. In this case you can use {{ic|915resolution}} hack. This hack will temporarily modify video BIOS and add needed resolution. See [http://915resolution.mango-lang.org/ 915resolution's home page]<br />
<br />
In the following I will proceed with the example for my system. Please adjust the recipe for your needs. First you need to find a video mode which will be modified later. For that, run {{ic|915resolution}} in GRUB2 command shell:<br />
915resolution -l<br />
The output will be something like:<br />
Intel 800/900 Series VBIOS Hack : version 0.5.3<br />
...<br />
Mode 30 : 640x480, 8 bits/pixel<br />
...<br />
Next, our purpose is to overwrite mode 30. (You can choose what ever mode you want.) In the file {{ic|/etc/grub.d/00_header}} just before the {{ic|set gfxmode&#61;${GRUB_GFXMODE}}} line insert:<br />
915resolution 30 1440 900<br />
Here we are overwriting the mode {{ic|30}} with {{ic|1440x900}} resolution. Lastly we need to set {{ic|GRUB_GFXMODE}} as described earlier, regenerate GRUB2 configuration file and reboot to test changes:<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
# reboot<br />
<br />
====Background image and bitmap fonts====<br />
<br />
GRUB2 comes with support for background images and bitmap fonts in {{ic|pf2}} format. The unifont font is included in the {{Pkg|grub-common}} package under the filename {{ic|unicode.pf2}}, or, as only ASCII characters under the name {{ic|ascii.pf2}}. <br />
<br />
Image formats supported include tga, png and jpeg, providing the correct modules are loaded. The maximum supported resolution depends on your hardware.<br />
<br />
Make sure you have set up the proper [https://wiki.archlinux.org/index.php/GRUB2#Setting_the_framebuffer_resolution framebuffer resolution].<br />
<br />
Edit {{ic|/etc/default/grub}} like this:<br />
GRUB_BACKGROUND="/boot/grub/myimage"<br />
#GRUB_THEME="/path/to/gfxtheme"<br />
<br />
{{Note|If you have installed GRUB on a separate partition, {{ic|/boot/grub/myimage}} becomes {{ic|/grub/myimage}}.}}<br />
<br />
To generate the changes and add the information into {{ic|grub.cfg}}, run: <br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
If adding the splash image was successful, the user will see {{ic|"Found background image..."}} in the terminal as the command is executed. <br />
If this phrase is not seen, the image information was probably not incorporated into the {{ic|grub.cfg}} file.<br />
<br />
If the image is not displayed, check:<br />
* The path and the filename in {{ic|/etc/default/grub}} are correct.<br />
* The image is of the proper size and format (tga, png, 8-bit jpg).<br />
* The image was saved in the RGB mode, and is not indexed.<br />
* The console mode is not enabled in {{ic|/etc/default/grub}}.<br />
* The command {{ic|grub-mkconfig}} must be executed to place the background image information into the {{ic|/boot/grub/grub.cfg}} file.<br />
<br />
====Theme====<br />
<br />
Here is an example for configuring Starfield theme which was included in GRUB2 package.<br />
<br />
Edit {{ic|/etc/default/grub}}<br />
GRUB_THEME="/boot/grub/themes/starfield/theme.txt"<br />
<br />
Generate the changes:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
If configuring the theme was successful, you'll see {{ic|Found theme: /boot/grub/themes/starfield/theme.txt}} in the terminal.<br />
Your splash image will usually not displayed when using a theme.<br />
<br />
====Menu colors====<br />
<br />
As in GRUB Legacy (0.9x), you can change the menu colors in GRUB2. The available colors for GRUB2 are at http://www.gnu.org/software/grub/manual/html_node/Theme-file-format.html#Theme-file-format.<br />
Here is an example:<br />
<br />
Edit {{ic|/etc/default/grub}}:<br />
GRUB_COLOR_NORMAL="light-blue/black"<br />
GRUB_COLOR_HIGHLIGHT="light-cyan/blue"<br />
<br />
Generate the changes:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
====Hidden menu====<br />
<br />
One of the unique features of GRUB2 is hiding/skipping the menu and showing it by holding {{keypress|Shift}} when needed. You can also adjust whether you want to see the timeout counter.<br />
<br />
Edit {{ic|/etc/default/grub}} as you wish. Here is an example where the comments from the beginning of the two lines have been removed to enable the feature, the timeout has been set to five seconds and to be shown to the user:<br />
GRUB_HIDDEN_TIMEOUT=5<br />
GRUB_HIDDEN_TIMEOUT_QUIET=false<br />
<br />
and run:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
=== Other Options ===<br />
<br />
==== LVM ====<br />
<br />
If you use [[LVM]] for your {{ic|/boot}}, add the following before menuentry lines:<br />
<br />
insmod lvm<br />
<br />
and specify your root in the menuentry as:<br />
<br />
set root=(''lvm_group_name''-''lvm_logical_boot_partition_name'')<br />
<br />
Example:<br />
<br />
# (0) Arch Linux<br />
menuentry "Arch Linux" {<br />
insmod lvm<br />
set root=(VolumeGroup-lv_boot)<br />
# you can only set following two lines<br />
linux /vmlinuz-linux root=/dev/mapper/VolumeGroup-root ro<br />
initrd /initramfs-linux.img<br />
}<br />
<br />
==== RAID ====<br />
<br />
GRUB2 provides convenient handling of RAID volumes. You need to add {{ic|insmod raid}} which allows you to address the volume natively. For example, {{ic|/dev/md0}} becomes:<br />
set root=(md0)<br />
<br />
whereas a partitioned RAID volume (e.g. {{ic|/dev/md0p1}}) becomes:<br />
set root=(md0,1)<br />
<br />
==== Persistent block device naming ====<br />
You can use UUIDs to detect partitions instead of the "old" {{ic|/dev/sd*}} and {{ic|/dev/hd*}} scheming. It has the advantage of detecting partitions by their unique UUIDs, which is needed by some people booting with complicated partition setups.<br />
<br />
UUIDs are used by default in the recent versions of GRUB2 - there is no downside in it anyway except that you need to re-generate the {{ic|grub.cfg}} file every time you resize or reformat your partitions. Remember this when modifying partitions with Live-CD.<br />
<br />
The recent versions of GRUB2 use UUIDs by default. You can re-enable the use of UUIDS by simply commenting the UUID line (this is also what it looks like by default):<br />
#GRUB_DISABLE_LINUX_UUID=true<br />
you can also just set the value as {{ic|false}} as shown here:<br />
GRUB_DISABLE_LINUX_UUID=false<br />
<br />
Either way, do not forget to generate the changes:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
==== Using Labels ====<br />
<br />
It is possible to use labels, human-readable strings attached to filesystems, by using the {{ic|--label}} option to {{ic|search}}. First of all, label your existing partition:<br />
# tune2fs -L a <LABEL> <PARTITION><br />
<br />
Then, add an entry using labels. An example of this:<br />
<br />
menuentry "Arch Linux, session texte" {<br />
search --label --no-floppy --set=root archroot<br />
linux /boot/vmlinuz-linux root=/dev/disk/by-label/archroot ro<br />
initrd /boot/initramfs-linux.img<br />
}<br />
<br />
==== Recall previous entry ====<br />
<br />
GRUB2 can remember the last entry you booted from and use this as the default entry to boot from next time. This is useful if you have multiple kernels (i.e., the current Arch one and the LTS kernel as a fallback option) or operating systems. To do this, edit {{ic|/etc/default/grub}} and change the setting of {{ic|GRUB_DEFAULT}}:<br />
<br />
GRUB_DEFAULT=saved<br />
<br />
This ensures that GRUB will default to the saved entry. To enable saving the selected entry, add the following line to {{ic|/etc/default/grub}}:<br />
<br />
GRUB_SAVEDEFAULT=true<br />
<br />
{{Note|Manually added menu items, eg Windows in {{ic|/etc/grub.d/40_custom}}, will need {{ic|savedefault}} added. Remember to regenerate your configuration file.}}<br />
<br />
==== Security ====<br />
<br />
If you want to secure GRUB2 so it is not possible for anyone to change boot parameters or use the command line, you can add a user/password combination to GRUB2's configuration files. To do this, run the command {{ic|grub-mkpasswd_pbkdf2}}. Enter a password and confirm it. The output will look like this:<br />
<br />
{{bc|<nowiki><br />
Your PBKDF2 is grub.pbkdf2.sha512.10000.C8ABD3E93C4DFC83138B0C7A3D719BC650E6234310DA069E6FDB0DD4156313DA3D0D9BFFC2846C21D5A2DDA515114CF6378F8A064C94198D0618E70D23717E82.509BFA8A4217EAD0B33C87432524C0B6B64B34FBAD22D3E6E6874D9B101996C5F98AB1746FE7C7199147ECF4ABD8661C222EEEDB7D14A843261FFF2C07B1269A</nowiki>}}Then, add the following to {{ic|/etc/grub.d/00_header}}:<br />
{{bc|<nowiki>cat << EOF<br />
<br />
set superusers="username"<br />
password_pbkdf2 username <password><br />
<br />
EOF</nowiki>}}<br />
where {{ic|<password>}} is the string generated by {{ic|grub-mkpasswd_pbkdf2}}.<br />
<br />
Regenerate your configuration file. Your GRUB2 command line, boot parameters and all boot entries are now protected.<br />
<br />
This can be relaxed and further customized with more users as described in the "Security" part of [https://www.gnu.org/software/grub/manual/grub.html#Security the GRUB manual].<br />
<br />
==== Root Encryption ====<br />
<br />
To let GRUB2 automatically add the kernel parameters for root encryption,<br />
add {{ic|1=cryptdevice=/dev/yourdevice:label}} to {{ic|GRUB_CMDLINE_LINUX}} in {{ic|/etc/defaults/grub}}.<br />
<br />
Example with root mapped to {{ic|/dev/mapper/root}}:<br />
<br />
GRUB_CMDLINE_LINUX="cryptdevice=/dev/sda2:root"<br />
<br />
Also, disable the usage of UUIDs for the rootfs:<br />
<br />
GRUB_DISABLE_LINUX_UUID=true<br />
<br />
Regenerate the configuration.<br />
<br />
=== Booting an ISO Directly From GRUB2 ===<br />
Edit {{ic|/etc/grub.d/40_custom}} to add an entry for the target ISO. When finished, update the GRUB menu as with the usual {{ic|grub-mkconfig -o /boot/grub/grub.cfg}} (as root).<br />
<br />
==== Arch ISO ====<br />
{{Note|Be sure to adjust the {{ic|hdX,Y}} in the third line to point to the correct disk/partition number of the isofile. Also adjust the {{ic|img_dev}} line to match this same location.}}<br />
<br />
menuentry "Archlinux-2011.08.19-netinstall-x86_64.iso" {<br />
set isofile="/archives/archlinux-2011.08.19-netinstall-x86_64.iso"<br />
loopback loop (hd0,7)$isofile<br />
linux (loop)/arch/boot/x86_64/vmlinuz archisolabel=ARCH_201108 img_dev=/dev/sda7 img_loop=$isofile earlymodules=loop<br />
initrd (loop)/arch/boot/x86_64/archiso.img<br />
}<br />
<br />
==== Ubuntu ISO ====<br />
{{Note|Be sure to adjust the {{ic|hdX,Y}} in the third line to point to the correct disk or partition number of the ISO file.}}<br />
<br />
menuentry "ubuntu-12.04-desktop-amd64.iso" {<br />
set isofile="/path/to/ubuntu-12.04-desktop-amd64.iso"<br />
loopback loop (hdX,Y)$isofile<br />
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile quiet noeject noprompt splash --<br />
initrd (loop)/casper/initrd.lz<br />
}<br />
<br />
== Using the command shell ==<br />
<br />
Since the MBR is too small to store all GRUB2 modules, only the menu and a few basic commands reside there. The majority of GRUB2 functionality remains in modules in {{ic|/boot/grub}}, which are inserted as needed. In error conditions (e.g. if the partition layout changes) GRUB2 may fail to boot. When this happens, a command shell may appear.<br />
<br />
GRUB2 offers multiple shells/prompts. If there is a problem reading the menu but the bootloader is able to find the disk, you will likely be dropped to the "normal" shell:<br />
sh:grub><br />
<br />
If there is a more serious problem (e.g. GRUB cannot find required files), you may instead be dropped to the "rescue" shell:<br />
grub rescue><br />
<br />
The rescue shell is a restricted subset of the normal shell, offering much less functionality. If dumped to the rescue shell, first try inserting the "normal" module, then starting the "normal" shell:<br />
grub rescue> set prefix=(hdX,Y)/boot/grub<br />
grub rescue> insmod (hdX,Y)/boot/grub/i386-pc/normal.mod<br />
rescue:grub> normal<br />
<br />
=== Pager support ===<br />
<br />
GRUB2 supports pager for reading commands that provide long output (like the help command). This works only in normal shell mode and not in rescue mode. To enable pager, in GRUB2 command shell type:<br />
sh:grub> set pager=1<br />
<br />
== GUI configuration tools ==<br />
<br />
Following package may be installed from [[AUR]]<br />
* [https://aur.archlinux.org/packages.php?ID=44020 grub-customizer] (requires gettext gksu gtkmm hicolor-icon-theme openssl)<br />
*:Customize the bootloader (GRUB2 or BURG)<br />
* [http://kde-apps.org/content/show.php?content=139643 grub2-editor] (requires kdelibs)<br />
*:A KDE4 control module for configuring the GRUB2 bootloader<br />
* [http://kde-apps.org/content/show.php?content=137886 kcm-grub2] (requires kdelibs python2-qt kdebindings-python)<br />
*:This Kcm module manages the most common settings of Grub2.<br />
* [http://sourceforge.net/projects/startup-manager/ startupmanager] (requires gnome-python imagemagick yelp python2 xorg-xrandr)<br />
*:GUI app for changing the settings of GRUB, GRUB2, Usplash and Splashy<br />
<br />
== parttool or legacy hide/unhide ==<br />
<br />
If you have a Windows 9x paradigm with hidden C:\ disks GRUB Legacy had the hide/unhide feature. In GRUB2 this has been replaced by {{ic|parttool}}. For example, to boot the third C:\ disk of three Windows 9x installations on the CLI enter the CLI and:<br />
parttool hd0,1 hidden+ boot-<br />
parttool hd0,2 hidden+ boot-<br />
parttool hd0,3 hidden- boot+<br />
set root=hd0,3<br />
chainloader +1<br />
boot<br />
<br />
== Using the rescue console ==<br />
<br />
See [[#Using the command shell]] first. If unable to activate the standard shell, one possible solution is to boot using a live CD or some other rescue disk to correct configuration errors and reinstall GRUB. However, such a boot disk is not always available (nor necessary); the rescue console is surprisingly robust.<br />
<br />
The available commands in GRUB rescue include {{ic|insmod}}, {{ic|ls}}, {{ic|set}}, and {{ic|unset}}. This example uses {{ic|set}} and {{ic|insmod}}. {{ic|set}} modifies variables and {{ic|insmod}} inserts new modules to add functionality.<br />
<br />
Before starting, the user must know the location of their {{ic|/boot}} partition (be it a separate partition, or a subdirectory under their root):<br />
grub rescue> set prefix=(hdX,Y)/boot/grub<br />
<br />
where X is the physical drive number and Y is the partition number.<br />
<br />
To expand console capabilities, insert the {{ic|linux}} module:<br />
grub rescue> insmod (hdX,Y)/boot/grub/linux.mod<br />
<br />
{{Note|With a separate boot partition, omit {{ic|/boot}} from the path, (i.e. type {{ic|1=set prefix=(hdX,Y)/grub}} and {{ic|insmod (hdX,Y)/grub/linux.mod}}).}}<br />
<br />
This introduces the {{ic|linux}} and {{ic|initrd}} commands, which should be familiar (see [[#Configuration]]).<br />
<br />
An example, booting Arch Linux:<br />
set root=(hd0,5)<br />
linux /boot/vmlinuz-linux root=/dev/sda5<br />
initrd /boot/initramfs-linux.img<br />
boot<br />
<br />
With a separate boot partition, again change the lines accordingly:<br />
set root=(hd0,5)<br />
linux /vmlinuz-linux root=/dev/sda6<br />
initrd /initramfs-linux.img<br />
boot<br />
<br />
After successfully booting the Arch Linux installation, users can correct {{ic|grub.cfg}} as needed and then reinstall GRUB2.<br />
<br />
to reinstall GRUB2 and fix the problem completely, changing {{ic|/dev/sda}} if needed. See [[#Bootloader installation]] for details.<br />
<br />
== Combining the use of UUID's and basic scripting ==<br />
<br />
If you like the idea of using UUID's to avoid unreliable BIOS mappings or are struggling with GRUB's syntax, here is an example boot menu item that uses UUID's and a small script to direct GRUB to the proper disk partitions for your system. All you need to do is replace the UUID's in the sample with the correct UUID's for your system. The example applies to a system with a boot and root partition. You will obviously need to modify the GRUB configuration if you have additional partitions:<br />
<br />
menuentry "Arch Linux 64" {<br />
# Set the UUIDs for your boot and root partition respectively<br />
set the_boot_uuid=ece0448f-bb08-486d-9864-ac3271bd8d07 <br />
set the_root_uuid=c55da16f-e2af-4603-9e0b-03f5f565ec4a<br />
<br />
# (Note: This may be the same as your boot partition)<br />
<br />
# Get the boot/root devices and set them in the root and grub_boot variables <br />
search --fs-uuid --no-floppy --set=root $the_root_uuid <br />
search --fs-uuid --no-floppy --set=grub_boot $the_boot_uuid<br />
<br />
# Check to see if boot and root are equal.<br />
# If they are, then append /boot to $grub_boot (Since $grub_boot is actually the root partition)<br />
if [ $the_boot_uuid == $the_root_uuid] ; then<br />
set grub_boot=$grub_boot/boot<br />
fi<br />
<br />
# $grub_boot now points to the correct location, so the following will properly find the kernel and initrd<br />
linux ($grub_boot)/vmlinuz-linux root=/dev/disk/by-uuid/$uuid_os_root ro<br />
initrd ($grub_boot)/initramfs-linux.img<br />
}<br />
<br />
== Troubleshooting ==<br />
<br />
Any troubleshooting should be added here.<br />
<br />
=== Enable GRUB2 debug messages ===<br />
<br />
Add:<br />
<br />
set pager=1<br />
set debug=all<br />
<br />
to {{ic|grub.cfg}}.<br />
<br />
=== Correct GRUB2 No Suitable Mode Found Error ===<br />
<br />
If you get this error when booting any menuentry:<br />
<br />
error: no suitable mode found<br />
Booting however<br />
<br />
Then you need to initialize GRUB2 graphical terminal ({{ic|gfxterm}}) with proper video mode ({{ic|gfxmode}}) in GRUB2. This video mode is passed by GRUB2 to the linux kernel via 'gfxpayload'. In case of UEFI systems, if the GRUB2 video mode is not initialized, no kernel boot messages will be shown in the terminal (atleast until KMS kicks in).<br />
<br />
Copy {{ic|/usr/share/grub/unicode.pf2}} to ${GRUB2_PREFIX_DIR} ({{ic|/boot/grub/}} in case of BIOS and UEFI systems). If GRUB2 UEFI was installed with {{ic|1=--boot-directory=/boot/efi/EFI}} set, then the directory is {{ic|/boot/efi/EFI/grub/}}:<br />
<br />
# cp /usr/share/grub/unicode.pf2 ${GRUB2_PREFIX_DIR}<br />
<br />
If {{ic|/usr/share/grub/unicode.pf2}} does not exist, install {{Pkg|bdf-unifont}}, create the {{ic|unifont.pf2}} file and then copy it to {{ic|${GRUB2_PREFIX_DIR<nowiki>}</nowiki>}}:<br />
<br />
# grub-mkfont -o unicode.pf2 /usr/share/fonts/misc/unifont.bdf<br />
<br />
Then, in the {{ic|grub.cfg}} file, add the following lines to enable GRUB2 to pass the video mode correctly to the kernel, without of which you will only get a black screen (no output) but booting (actually) proceeds successfully without any system hang.<br />
<br />
BIOS systems:<br />
<br />
insmod vbe<br />
<br />
UEFI systems:<br />
<br />
insmod efi_gop<br />
insmod efi_uga<br />
<br />
After that add the following code (common to both BIOS and UEFI):<br />
<br />
insmod font<br />
<br />
if loadfont ${prefix}/fonts/unicode.pf2<br />
then<br />
insmod gfxterm<br />
set gfxmode=auto<br />
set gfxpayload=keep<br />
terminal_output gfxterm<br />
fi<br />
<br />
As you can see for gfxterm (graphical terminal) to function properly, {{ic|unicode.pf2}} font file should exist in {{ic|${GRUB2_PREFIX_DIR<nowiki>}</nowiki>}}.<br />
<br />
=== msdos-style error message ===<br />
<br />
grub-setup: warn: This msdos-style partition label has no post-MBR gap; embedding won't be possible!<br />
grub-setup: warn: Embedding is not possible. GRUB can only be installed in this setup by using blocklists.<br />
However, blocklists are UNRELIABLE and its use is discouraged.<br />
grub-setup: error: If you really want blocklists, use --force.<br />
<br />
This error may occur when you try installing GRUB2 in a VMware container. Read more about it [http://bbs.archlinux.org/viewtopic.php?pid=581760#p581760 here]. It happens when the first partition starts just after the MBR (block 63), without the usual space of 1 MiB (2048 blocks) before the first partition. Read [[#MBR_aka_msdos_partitioning_specific_instructions]]<br />
<br />
=== UEFI GRUB2 drops to shell ===<br />
<br />
If GRUB loads but drops you into the rescue shell with no errors, it may be because of a missing or misplaced {{ic|grub.cfg}}. This will happen if GRUB2 UEFI was installed with {{ic|--boot-directory}} and {{ic|grub.cfg}} is missing OR if the partition number of the boot partition changed (which is hard-coded into the {{ic|grubx64.efi}} file).<br />
<br />
=== UEFI GRUB2 not loaded ===<br />
In some cases the EFI may fail to load GRUB correctly. Provided everything is set up correctly, the output of:<br />
efibootmgr -v<br />
might look something like this:<br />
BootCurrent: 0000<br />
Timeout: 3 seconds<br />
BootOrder: 0000,0001,0002<br />
Boot0000* Grub HD(1,800,32000,23532fbb-1bfa-4e46-851a-b494bfe9478c)File(\efi\grub\grub.efi)<br />
Boot0001* Shell HD(1,800,32000,23532fbb-1bfa-4e46-851a-b494bfe9478c)File(\EfiShell.efi)<br />
Boot0002* Festplatte BIOS(2,0,00)P0: SAMSUNG HD204UI<br />
If everything works correctly, the EFI would now automatically load GRUB.<br />
<br />
If the screen only goes black for a second and the next boot option is tried afterwards, according to [https://bbs.archlinux.org/viewtopic.php?pid=981560#p981560 this post], moving GRUB to the partition root can help. The boot option has to be deleted and recreated afterwards. The entry for GRUB should look like this then:<br />
Boot0000* Grub HD(1,800,32000,23532fbb-1bfa-4e46-851a-b494bfe9478c)File(\grub.efi)<br />
<br />
=== Invalid signature ===<br />
If trying to boot Windows results in an "invalid signature" error, e.g. after reconfiguring partitions or adding additional hard drives, (re)move GRUB's device configuration and let it reconfigure:<br />
# mv /boot/grub/device.map /boot/grub/device.map-old<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
{{ic|grub-mkconfig}} should now mention all found boot options, including Windows. If it works, remove {{ic|/boot/grub/device.map-old}}.<br />
<br />
=== Restore GRUB Legacy ===<br />
<br />
* Move GRUB2 files out of the way:<br />
<br />
# mv /boot/grub /boot/grub.nonfunctional<br />
<br />
* Copy GRUB Legacy back to {{ic|/boot}}:<br />
<br />
# cp -af /boot/grub-legacy /boot/grub<br />
<br />
* Replace MBR and next 62 sectors of sda with backed up copy<br />
<br />
{{Warning|This command also restores the partition table, so be careful of overwriting a modified partition table with the old one. It '''will''' mess your system.}}<br />
<br />
# dd if=/path/to/backup/first-sectors of=/dev/sdX bs=512 count=1<br />
<br />
A safer way is to restore only the MBR boot code use:<br />
<br />
# dd if=/path/to/backup/mbr-boot-code of=/dev/sdX bs=446 count=1<br />
<br />
== References ==<br />
<br />
# Official GRUB2 Manual - http://www.gnu.org/software/grub/manual/grub.html<br />
# Ubuntu wiki page for GRUB2 - https://help.ubuntu.com/community/Grub2<br />
# GRUB2 wiki page describing steps to compile for UEFI systems - https://help.ubuntu.com/community/UEFIBooting<br />
# Wikipedia's page on [[Wikipedia:BIOS Boot partition|BIOS Boot partition]]<br />
<br />
== External Links ==<br />
<br />
# [https://github.com/the-ridikulus-rat/My_Shell_Scripts/blob/master/grub/grub_bios.sh A Linux Bash Shell script to compile and install GRUB(2) for BIOS from BZR Source]<br />
# [https://github.com/the-ridikulus-rat/My_Shell_Scripts/blob/master/grub/grub_uefi.sh A Linux Bash Shell script to compile and install GRUB(2) for UEFI from BZR Source]</div>Mayweedhttps://wiki.archlinux.org/index.php?title=Udev&diff=169847Udev2011-11-13T11:25:01Z<p>Mayweed: /* Mixed Up Devices, Sound/Network Cards Changing Order Each Boot */</p>
<hr />
<div>[[Category:Hardware detection and troubleshooting (English)]]<br />
[[Category:Auto-mounting (English)]]<br />
{{i18n|Udev}}<br />
{{Lowercase title}}<br />
<br />
'''udev''' replaces the functionality of both {{Codeline|hotplug}} and {{Codeline|hwdetect}}.<br />
<br />
''"udev is the device manager for the Linux kernel. Primarily, it manages device nodes in {{Filename|/dev}}. It is the successor of devfs and hotplug, which means that it handles the {{Filename|/dev}} directory and all user space actions when adding/removing devices, including firmware load."'' Source: [[Wikipedia:Udev]]<br />
<br />
udev loads kernel modules by utilizing coding parallelism to provide a potential performance advantage versus loading these modules serially. The modules are therefore loaded asynchronously. The inherent disadvantage of this method is that udev does not always load modules in the same order on each boot. If the machine has multiple block devices, this may manifest itself in the form of device nodes changing designations randomly. For example, if the machine has two hard drives, /dev/sda may randomly become /dev/sdb. See below for more info on this.<br />
<br />
==About udev rules==<br />
udev rules written by the administrator go in {{Filename|/etc/udev/rules.d/}}, their file name has to end with {{Filename|.rules}}. The udev rules shipped with various packages are found in {{Filename|/lib/udev/rules.d/}}. If there are two files by the same name under /lib and /etc, the ones in /etc take precedence.<br />
<br />
If you want to learn how to write udev rules see [http://www.reactivated.net/writing_udev_rules.html Writing udev rules].<br />
<br />
To get a list of all the attributes of a device you can use to write rules:<br />
# udevadm info -a -n [device name]<br />
<br />
Replace [device name] with the device present in the system, such as '/dev/sda' or '/dev/ttyUSB0'.<br />
<br />
Udev automatically detects changes to rule files, so changes take effect immediately without requiring udev to be restarted. However, the rules are not re-triggered automatically on already existing devices, so hotpluggable devices, such as USB devices, will probably have to be reconnected for the new rules to take effect.<br />
<br />
== Tips & Tricks ==<br />
=== UDisks ===<br />
Simply install UDisks:<br />
pacman -S udisks<br />
and all your media should be auto mounted in GNOME and KDE SC 4.6. There is no need for any additional rules this way.<br />
As an extra bonus you can remove HAL if you were only using that for auto mounting purposes.<br />
<br />
==== Automounting UDisks Wrappers ====<br />
A UDisks wrapper has the advantage of being very easy to install and needing no (or minimal) configuration. The wrapper will automatically mount things like CDs and flash drives.<br />
<br />
* [http://igurublog.wordpress.com/downloads/script-devmon/ devmon] - devmon ([http://aur.archlinux.org/packages.php?ID=45842 AUR]) is a configuration-less bash wrapper script for udisks which automounts optical discs and removable drives. It can also selectively autostart apps or execute commands after mounting, ignore specified devices and volume labels, and unmount removable drives. <br />
* [[udiskie]] - Written in Python. Allows auto mount and unmount by any user.<br />
* [http://aur.archlinux.org/packages.php?ID=38723 udisksevt] - Written in Haskell. Allows auto mount by any user. Designed to be integrated with [http://aur.archlinux.org/packages.php?ID=32005 traydevice].<br />
* The [http://aur.archlinux.org/packages.php?ID=46572 udisksvm bash script] uses udisks and [http://aur.archlinux.org/packages.php?ID=32005 Traydevice] to automount removable media and to control in GUI, with mouse clicks in systray, the un-mounting and re-mounting of disks or the ejection of optical disks.<br />
<br />
==== UDisks Shell Functions ====<br />
While UDisks includes a simple method of (un)mounting devices via command-line, it can be tiresome to type the commands out each time. These shell functions will generally shorten and ease command-line usage.<br />
<br />
* [https://bbs.archlinux.org/viewtopic.php?id=109307 udisks_functions] - Written for Bash.<br />
* [https://bbs.archlinux.org/viewtopic.php?id=117674 bashmount] - bashmount [http://aur.archlinux.org/packages.php?ID=48524 (AUR)] is a menu-driven bash script with a configuration file that makes it easy to configure and extend.<br />
<br />
=== Auto mounting USB devices ===<br />
{{Note|In the following rules the mount options are defined as {{Codeline|<nowiki>ENV{mount_options}="relatime"</nowiki>}}, see {{Codeline|man mount}} (and possibly {{Codeline|man ntfs-3g}}) for all available options and [[Maximizing Performance#Mount options]] for performance-related options.}}<br />
{{Note|The {{Codeline|users}} mount option will '''not''' allow users to unmount the filesystem.}}<br />
{{Tip|The {{Codeline|noexec}} mount option prevents execution of binaries on the mounted filesystem.}}<br />
<br />
==== Mount under {{Filename|/media}}; use partition label if present ====<br />
The following udev rule set automatically mounts devices/partitions that are represented by /dev/sd* (USB drives, external hard drives and sometimes SD cards). If a partition label is available, it mounts the device to /media/<label> and otherwise to /media/usbhd-sd* (ex: /media/usbhd-sdb1):<br />
{{File|name=/etc/udev/rules.d/11-media-by-label-auto-mount.rules|content=<nowiki><br />
KERNEL!="sd[a-z][0-9]", GOTO="media_by_label_auto_mount_end"<br />
<br />
# Import FS infos<br />
IMPORT{program}="/sbin/blkid -o udev -p %N"<br />
<br />
# Get a label if present, otherwise specify one<br />
ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}"<br />
ENV{ID_FS_LABEL}=="", ENV{dir_name}="usbhd-%k"<br />
<br />
# Global mount options<br />
ACTION=="add", ENV{mount_options}="relatime"<br />
# Filesystem-specific mount options<br />
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},utf8,gid=100,umask=002"<br />
<br />
# Mount the device<br />
ACTION=="add", RUN+="/bin/mkdir -p /media/%E{dir_name}", RUN+="/bin/mount -o $env{mount_options} /dev/%k /media/%E{dir_name}"<br />
<br />
# Clean up after removal<br />
ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l /media/%E{dir_name}", RUN+="/bin/rmdir /media/%E{dir_name}"<br />
<br />
# Exit<br />
LABEL="media_by_label_auto_mount_end"<br />
</nowiki>}}<br />
<br />
==== Mount under {{Filename|/media}}; use partition label if present; supports LUKS encryption ====<br />
Similar to the above rule set, but if the device is a LUKS-encrypted partition it will open an xterm window to ask for the passphrase (provided that xterm is installed). Also see [http://bbs.archlinux.org/viewtopic.php?pid=696239#p696239 this post] and the follow-ups.<br />
<br />
{{Note|You may need to modify the path to cryptsetup, depending on the version installed (e.g., < 1.1.1_rc2-1).}}<br />
<br />
{{File|name=/etc/udev/rules.d/11-media-by-label-auto-mount.rules|content=<nowiki><br />
KERNEL!="sd[a-z]*", GOTO="media_by_label_auto_mount_end"<br />
ACTION=="add", PROGRAM!="/sbin/blkid %N", GOTO="media_by_label_auto_mount_end"<br />
<br />
# Do not mount devices already mounted somewhere else to avoid entries for all your local partitions in /media<br />
ACTION=="add", PROGRAM=="/bin/grep -q ' /dev/%k ' /proc/self/mountinfo", GOTO="media_by_label_auto_mount_end"<br />
<br />
# Open LUKS partition if necessary<br />
PROGRAM=="/sbin/blkid -o value -s TYPE %N", RESULT=="crypto_LUKS", ENV{crypto}="mapper/", ENV{device}="/dev/mapper/%k"<br />
ENV{crypto}=="", ENV{device}="%N"<br />
ACTION=="add", ENV{crypto}!="", PROGRAM=="/usr/bin/xterm -display :0.0 -e 'echo Password for /dev/%k; /sbin/cryptsetup luksOpen %N %k'"<br />
ACTION=="add", ENV{crypto}!="", TEST!="/dev/mapper/%k", GOTO="media_by_label_auto_mount_end"<br />
<br />
# Global mount options<br />
ACTION=="add", ENV{mount_options}="noatime"<br />
# Filesystem-specific mount options<br />
ACTION=="add", PROGRAM=="/sbin/blkid -o value -s TYPE %E{device}", RESULT=="vfat|ntfs", ENV{mount_options}="%E{mount_options},utf8,gid=100,umask=002"<br />
<br />
# Get label if present, otherwise assign one<br />
PROGRAM=="/sbin/blkid -o value -s LABEL %E{device}", ENV{dir_name}="%c"<br />
# Use basename to correctly handle labels such as ../mnt/foo<br />
PROGRAM=="/usr/bin/basename '%E{dir_name}'", ENV{dir_name}="%c"<br />
ENV{dir_name}=="", ENV{dir_name}="usbhd-%k"<br />
<br />
# Mount the device<br />
ACTION=="add", ENV{dir_name}!="", RUN+="/bin/mkdir -p '/media/%E{dir_name}'", RUN+="/bin/mount -o %E{mount_options} /dev/%E{crypto}%k '/media/%E{dir_name}'"<br />
<br />
# Clean up after removal<br />
ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l '/media/%E{dir_name}'"<br />
ACTION=="remove", ENV{crypto}!="", RUN+="/sbin/cryptsetup luksClose %k"<br />
ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/rmdir '/media/%E{dir_name}'"<br />
<br />
# Exit<br />
LABEL="media_by_label_auto_mount_end"<br />
</nowiki>}}<br />
<br />
==== Mount under {{Filename|/media}}; use partition label if present; support user un-mounting ====<br />
This is a variation on the above rule set. It uses pmount (which will need to be installed) instead of mount, allowing a non-root user to unmount udev-mounted devices, and automatically removing the mount point. The required username (here tomk) must be hard-coded in the RUN command, so this rule set may not be suitable for multi-user systems. LUKS support has also been removed from the example, but can be easily reinstated as above. You must edit the /bin/su invocation to run as the correct user for your system. Note that the mount point will remain if the device is mounted and the system, with a persistent /media, is shutdown, since rc.shutdown uses umount, which does not remove the mount point. To avoid having /media contain old mount points, one solution is to mount /media as tmpfs.<br />
{{File|name=/etc/udev/rules.d/11-media-by-label-with-pmount.rules|content=<nowiki><br />
KERNEL!="sd[a-z]*", GOTO="media_by_label_auto_mount_end"<br />
ACTION=="add", PROGRAM!="/sbin/blkid %N", GOTO="media_by_label_auto_mount_end"<br />
<br />
# Get label<br />
PROGRAM=="/sbin/blkid -o value -s LABEL %N", ENV{dir_name}="%c"<br />
# use basename to correctly handle labels such as ../mnt/foo<br />
PROGRAM=="/usr/bin/basename '%E{dir_name}'", ENV{dir_name}="%c"<br />
ENV{dir_name}=="", ENV{dir_name}="usbhd-%k"<br />
<br />
ACTION=="add", ENV{dir_name}!="", RUN+="/bin/su tomk -c '/usr/bin/pmount %N %E{dir_name}'"<br />
ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/su tomk -c '/usr/bin/pumount /media/%E{dir_name}'"<br />
LABEL="media_by_label_auto_mount_end"<br />
</nowiki>}}<br />
<br />
==== Mount under {{Filename|/mnt}}; create symbolic link under {{Filename|/media}} ====<br />
The following rule set does not make use of partition labels; instead it mounts devices as usbhd-sdXY under the /mnt directory (ex: /mnt/usbhd-sdb1) and creates a symbolic link under /media.<br />
{{File|name=/etc/udev/rules.d/11-mnt-auto-mount.rules|content=<nowiki><br />
KERNEL!="sd[a-z][0-9]", GOTO="mnt_auto_mount_end"<br />
<br />
# Global mount options<br />
ACTION=="add", ENV{mount_options}="relatime"<br />
# Filesystem-specific mount options<br />
ACTION=="add", IMPORT{program}="/sbin/blkid -o udev -p %N"<br />
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},utf8,gid=100,umask=002"<br />
<br />
# Mount under /mnt and create the symbolic link in /media <br />
ACTION=="add", RUN+="/bin/mount -o $env{mount_options} /dev/%k /mnt/usbhd-%k", RUN+="/bin/ln -s /mnt/usbhd-%k /media/usbhd-%k"<br />
<br />
# Clean up after removal<br />
ACTION=="remove", RUN+="/bin/rm -f /media/usbhd-%k", RUN+="/bin/umount -l /mnt/usbhd-%k", RUN+="/bin/rmdir /mnt/usbhd-%k"<br />
<br />
# Exit<br />
LABEL="mnt_auto_mount_end"<br />
</nowiki>}}<br />
<br />
==== Mount under {{Filename|/media}} ''only'' if the partition has a label ====<br />
{{File|name=/etc/udev/rules.d/11-media-by-label-only-auto-mount.rules|content=<nowiki><br />
KERNEL!="sd[a-z][0-9]", GOTO="media_by_label_only_auto_mount_end"<br />
<br />
# Import FS infos<br />
IMPORT{program}="/sbin/blkid -o udev -p %N"<br />
ENV{ID_FS_LABEL}=="", GOTO="media_by_label_only_auto_mount_end"<br />
<br />
# Global mount options<br />
ACTION=="add", ENV{mount_options}="relatime"<br />
# Filesystem-specific mount options<br />
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},utf8,gid=100,umask=002"<br />
<br />
# Mount the device<br />
ACTION=="add", RUN+="/bin/mkdir -p /media/$env{ID_FS_LABEL}", RUN+="/bin/mount -o $env{mount_options} /dev/%k /media/$env{ID_FS_LABEL}"<br />
<br />
# Clean up after removal<br />
ACTION=="remove", ENV{ID_FS_LABEL}!="", RUN+="/bin/umount -l /media/$env{ID_FS_LABEL}", RUN+="/bin/rmdir /media/$env{ID_FS_LABEL}"<br />
<br />
# Exit<br />
LABEL="media_by_label_only_auto_mount_end"<br />
</nowiki>}}<br />
<br />
==== Mount under {{Filename|/media}}; use partition label if present; ntfs-3g ====<br />
Yet another example, this time making use of ntfs-3g read/write drivers for NTFS filesystems:<br />
<br />
{{File|name=/etc/udev/rules.d/10-my-media-automount.rules|content=<nowiki><br />
# vim:enc=utf-8:nu:ai:si:et:ts=4:sw=4:ft=udevrules:<br />
#<br />
# /etc/udev/rules.d/10-my-media-automount.rules<br />
<br />
# start at sdb to ignore the system hard drive<br />
KERNEL!="sd[b-z]*", GOTO="my_media_automount_end"<br />
ACTION=="add", PROGRAM!="/sbin/blkid %N", GOTO="my_media_automount_end"<br />
<br />
# import some useful filesystem info as variables<br />
IMPORT{program}="/sbin/blkid -o udev -p %N"<br />
<br />
# get the label if present, otherwise assign one based on device/partition<br />
ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}"<br />
ENV{ID_FS_LABEL}=="", ENV{dir_name}="usbhd-%k"<br />
<br />
# create the dir in /media and symlink it to /mnt<br />
ACTION=="add", RUN+="/bin/mkdir -p '/media/%E{dir_name}'"<br />
<br />
# global mount options<br />
ACTION=="add", ENV{mount_options}="relatime"<br />
# filesystem-specific mount options (777/666 dir/file perms for ntfs/vfat) <br />
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},gid=100,dmask=000,fmask=111,utf8"<br />
<br />
# automount ntfs filesystems using ntfs-3g driver<br />
ACTION=="add", ENV{ID_FS_TYPE}=="ntfs", RUN+="/bin/mount -t ntfs-3g -o %E{mount_options} /dev/%k '/media/%E{dir_name}'"<br />
# automount all other filesystems<br />
ACTION=="add", ENV{ID_FS_TYPE}!="ntfs", RUN+="/bin/mount -t auto -o %E{mount_options} /dev/%k '/media/%E{dir_name}'"<br />
<br />
# clean up after device removal<br />
ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l '/media/%E{dir_name}'", RUN+="/bin/rmdir '/media/%E{dir_name}'"<br />
<br />
# exit<br />
LABEL="my_media_automount_end"<br />
<br />
</nowiki>}}<br />
<br />
==== Mount SD cards ====<br />
The same rules as above can be used to auto-mount SD cards, you just need to replace {{Codeline|sd[a-z][0-9]}} by {{Codeline|mmcblk[0-9]p[0-9]}}:<br />
{{File|name=/etc/udev/rules.d/11-sd-cards-auto-mount.rules|content=<nowiki><br />
KERNEL!="mmcblk[0-9]p[0-9]", GOTO="sd_cards_auto_mount_end"<br />
<br />
# Global mount options<br />
ACTION=="add", ENV{mount_options}="relatime"<br />
# Filesystem specific options<br />
ACTION=="add", IMPORT{program}="/sbin/blkid -o udev -p %N"<br />
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},utf8,gid=100,umask=002"<br />
<br />
ACTION=="add", RUN+="/bin/mkdir -p /media/sd-%k", RUN+="/bin/ln -s /media/sd-%k /mnt/sd-%k", RUN+="/bin/mount -o $env{mount_options} /dev/%k /media/sd-%k"<br />
ACTION=="remove", RUN+="/bin/umount -l /media/sd-%k", RUN+="/bin/rmdir /media/sd-%k"<br />
LABEL="sd_cards_auto_mount_end"<br />
</nowiki>}}<br />
<br />
==== Mount CDs ====<br />
To auto mount a CD a simple [[#Automounting_UDisks_Wrappers|UDisks wrapper]] will get the job done properly.<br />
{{Note|Maybe this should be merged to the Udisks wrapper section.}}<br />
<br />
==== Accessing Firmware Programmers and USB Virtual Comm Devices ====<br />
The following ruleset will allow normal users (within the "users" group) the ability to access the [http://www.ladyada.net/make/usbtinyisp/ USBtinyISP] USB programmer for AVR microcontrollers and a generic (SiLabs [http://www.silabs.com/products/interface/usbtouart CP2102]) USB to UART adapter. Adjust the permissions accordingly. Verified as of 2010-02-11.<br />
<br />
{{File|name=/etc/udev/rules.d/50-embedded_devices.rules|content=<nowiki><br />
# USBtinyISP Programmer rules<br />
SUBSYSTEMS=="usb", ATTRS{idVendor}=="1781", ATTRS{idProduct}=="0c9f", GROUP="users", MODE="0666"<br />
SUBSYSTEMS=="usb", ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="0479", GROUP="users", MODE="0666"<br />
# USBasp Programmer rules http://www.fischl.de/usbasp/<br />
SUBSYSTEMS=="usb", ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="05dc", GROUP="users", MODE="0666"<br />
<br />
# Mdfly.com Generic (SiLabs CP2102) 3.3v/5v USB VComm adapter<br />
SUBSYSTEMS=="usb", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", GROUP="users", MODE="0666"<br />
</nowiki>}}<br />
<br />
=== Execute on USB Insert ===<br />
<br />
See [[Execute_on_usb_insert|execute on usb insert]] article or the [http://igurublog.wordpress.com/downloads/script-devmon/ devmon wrapper script].<br />
<br />
=== Mount internal drives as a normal user ===<br />
<br />
If you want to mount an internal drive in KDE or Gnome (maybe on other Desktop Environments too) as a normal user (without the need to type your superuser password), you just have to create the following file in [[PolicyKit]] Local Authority:<br />
{{File|name=/etc/polkit-1/localauthority/50-local.d/50-filesystem-mount-system-internal.pkla|content=<nowiki><br />
[Mount a system-internal device]<br />
Identity=*<br />
Action=org.freedesktop.udisks.filesystem-mount-system-internal<br />
ResultActive=yes<br />
</nowiki>}}<br />
<br />
=== Mark internal SATA-Ports as eSATA-Ports ===<br />
<br />
If you connected a eSATA bay or an other eSATA adapter the system will still recognize this disk as an internal SATA drive. Gnome and KDE will ask you for your root password all the time. The following rule will mark the specified SATA-Port as an external eSATA-Port. With that, a normal Gnome user can connect their eSATA drives to that port like a USB drive, without any root password and so on.<br />
<br />
{{File|name=/etc/udev/rules.d/10-esata.rules|content=<nowiki><br />
DEVPATH=="/devices/pci0000:00/0000:00:1f.2/host4/*", ENV{UDISKS_SYSTEM_INTERNAL}="0"<br />
</nowiki>}}<br />
<br />
{{Note| The DEVPATH can be found after connection the eSata drive with the following command (replace sdb to your needs):<br />
<br />
# find /sys/devices/ -name sdb<br />
/sys/devices/pci0000:00/0000:00:1f.2/host4/target4:0:0/4:0:0:0/block/sdb<br />
<br />
}}<br />
<br />
==Troubleshooting==<br />
<br />
=== Blacklisting Modules ===<br />
In rare cases, udev can make mistakes and load the wrong modules. To prevent it from doing this, you can blacklist modules. Once blacklisted, udev will never load that module. See [[blacklisting]]. Not at boot-time ''or'' later on when a hotplug event is received (eg, you plug in your USB flash drive).<br />
<br />
=== udevd hangs at boot ===<br />
After migrating to LDAP or updating an LDAP-backed system udevd can hang at boot at the message "Starting UDev Daemon". This is usually caused by udevd trying to look up a name from LDAP but failing, because the network is not up yet. The solution is to ensure that all system group names are present locally.<br />
<br />
Extract the group names referenced in udev rules and the group names actually present on the system:<br />
<br />
# fgrep -r GROUP /etc/udev/rules.d/ /lib/udev/rules.d | perl -nle '/GROUP\s*=\s*"(.*?)"/ && print $1;' | sort | uniq > udev_groups<br />
# cut -f1 -d: /etc/gshadow /etc/group | sort | uniq > present_groups<br />
<br />
To see the differences, do a side-by-side diff:<br />
<br />
# diff -y present_groups udev_groups<br />
...<br />
network <<br />
nobody <<br />
ntp <<br />
optical optical<br />
power | pcscd<br />
rfkill <<br />
root root<br />
scanner scanner<br />
smmsp <<br />
storage storage<br />
...<br />
<br />
In this case, the pcscd group is for some reason not present in the system. Add the missing groups:<br />
<br />
# groupadd pcscd<br />
<br />
Also, make sure local resources are looked up before resorting to LDAP. {{Filename|/etc/nsswitch.conf}} should contain the line<br />
<br />
group: files ldap<br />
<br />
=== Known Problems with Hardware ===<br />
====BusLogic devices can be broken and will cause a freeze during startup====<br />
This is a kernel bug and no fix has been provided yet.<br />
====Some devices, that should be treated as removable, are not====<br />
Create a custom udev rule, setting UDISKS_SYSTEM_INTERNAL=0. For more details, see the manpage of udisks.<br />
<br />
=== Known Problems with Auto-Loading ===<br />
==== CPU frequency modules ====<br />
The current detection method for the various CPU frequency controllers is inadequate, so this has been omitted from the auto-loading process for the time being. To use [[CPU Frequency Scaling]], load the proper module explicitly in your {{Codeline|MODULES}} array in {{Filename|/etc/rc.conf}}. Further reading: [[rc.conf]].<br />
<br />
====Sound Problems or Some Modules Not Loaded Automatically====<br />
Some users have traced this problem to old entries in {{Filename|/etc/modprobe.d/sound.conf}}. Try cleaning that file out and trying again.<br />
{{Note|Since {{Codeline|udev>&#61;171}}, the OSS emulation modules ({{Codeline|snd_seq_oss, snd_pcm_oss, snd_mixer_oss}}) are not automatically loaded by default.}}<br />
<br />
==== Mixed Up Devices, Sound/Network Cards Changing Order Each Boot ====<br />
Because udev loads all modules asynchronously, they are initialized in a different order. This can result in devices randomly switching names. For example, with two network cards, you may notice a switching of designations between {{Codeline|eth0}} and {{Codeline|eth1}}.<br />
<br />
Arch Linux provides the advantage of specifying the module load order by listing the modules in the {{Codeline|MODULES}} array in {{Filename|[[rc.conf]]}}. Modules in this array are loaded before udev begins auto-loading, so you have full control over the load order.<br />
<br />
# Always load 8139too before e100<br />
MODULES=(8139too e100)<br />
<br />
Another method for network card ordering is to use the udev-sanctioned method of statically-naming each interface. Create the following file to bind the MAC address of each of your cards to a certain interface name:<br />
{{File|name=/etc/udev/rules.d/10-network.rules|content=<nowiki><br />
SUBSYSTEM=="net", ATTR{address}=="aa:bb:cc:dd:ee:ff", NAME="lan0"<br />
SUBSYSTEM=="net", ATTR{address}=="ff:ee:dd:cc:bb:aa", NAME="wlan0"<br />
</nowiki>}}<br />
<br />
A couple things to note:<br />
* To get the MAC address of each card, use this command: {{Codeline|<nowiki>udevadm info -a -p /sys/class/net/<yourdevice> | grep address | tr [A-Z] [a-z]</nowiki>}}<br />
* Make sure to use the lower-case hex values in your udev rules. It doesn't like upper-case.<br />
* Some people have problems naming their interfaces after the old style: eth0, eth1, etc. Try something like "lan" or "wlan" if you experience this problem.<br />
<br />
Don't forget to update your {{Filename|/etc/rc.conf}} and other configuration files using the old ethX notation!<br />
<br />
Other methods for setting network interface names are described in the [[Configuring Network#Interface names varying]] wiki entry.<br />
<br />
{{Note|With a recent version of udev, this problem should be solved automatically thanks to the {{Filename|/lib/udev/write_net_rules}} program which runs the {{Filename|75-persistent-net-generator.rules}} script which produces a {{Filename|70-persistent-net.rules}}.}}<br />
<br />
=== Known Problems for Custom Kernel Users ===<br />
==== Udev doesn't start at all ====<br />
Make sure you have a kernel version later than or equal to 2.6.32. Earlier kernels do not have the necessary uevent stuff that udev needs for auto-loading.<br />
<br />
=== IDE CD/DVD-drive support ===<br />
Starting with version 170, udev doesn't support CD-ROM/DVD-ROM drives, which are loaded as traditional IDE drives with the {{Codeline|ide_cd_mod}} module and show up as {{Filename|/dev/hd*}}. The drive remains usable for tools which access the hardware directly, like cdparanoia, but is invisible for higher userspace programs, like KDE.<br />
<br />
A cause for the loading of the ide_cd_mod module prior to others, like sr_mod, could be e.g. that you have for some reason the module piix loaded with your initramfs. In that case you can just replace it with ata_piix in your {{Filename|/etc/mkinitcpio.conf}}.<br />
<br />
=== Optical Drives Have Group ID Set To Disk ===<br />
If the group ID of your optical drive is set to ''disk'' and you want to have it set to ''optical'' you have to create a custom udev rule:<br />
{{File|name=/etc/udev/rules.d|content=# permissions for IDE CD devices<br />
SUBSYSTEMS=="ide", KERNEL=="hd[a-z]", ATTR{removable}=="1", ATTRS{media}=="cdrom*", GROUP="optical"<br />
<br />
# permissions for SCSI CD devices<br />
SUBSYSTEMS=="scsi", KERNEL=="s[rg][0-9]*", ATTRS{type}=="5", GROUP="optical"}}<br />
<br />
==Other Resources==<br />
* [http://www.kernel.org/pub/linux/utils/kernel/hotplug/udev.html Udev Homepage]<br />
* [http://www.linux.com/news/hardware/peripherals/180950-udev An Introduction to Udev]<br />
* [http://vger.kernel.org/vger-lists.html#linux-hotplug Udev mailing list information]</div>Mayweedhttps://wiki.archlinux.org/index.php?title=Udev&diff=169846Udev2011-11-13T11:23:17Z<p>Mayweed: /* Mixed Up Devices, Sound/Network Cards Changing Order Each Boot */</p>
<hr />
<div>[[Category:Hardware detection and troubleshooting (English)]]<br />
[[Category:Auto-mounting (English)]]<br />
{{i18n|Udev}}<br />
{{Lowercase title}}<br />
<br />
'''udev''' replaces the functionality of both {{Codeline|hotplug}} and {{Codeline|hwdetect}}.<br />
<br />
''"udev is the device manager for the Linux kernel. Primarily, it manages device nodes in {{Filename|/dev}}. It is the successor of devfs and hotplug, which means that it handles the {{Filename|/dev}} directory and all user space actions when adding/removing devices, including firmware load."'' Source: [[Wikipedia:Udev]]<br />
<br />
udev loads kernel modules by utilizing coding parallelism to provide a potential performance advantage versus loading these modules serially. The modules are therefore loaded asynchronously. The inherent disadvantage of this method is that udev does not always load modules in the same order on each boot. If the machine has multiple block devices, this may manifest itself in the form of device nodes changing designations randomly. For example, if the machine has two hard drives, /dev/sda may randomly become /dev/sdb. See below for more info on this.<br />
<br />
==About udev rules==<br />
udev rules written by the administrator go in {{Filename|/etc/udev/rules.d/}}, their file name has to end with {{Filename|.rules}}. The udev rules shipped with various packages are found in {{Filename|/lib/udev/rules.d/}}. If there are two files by the same name under /lib and /etc, the ones in /etc take precedence.<br />
<br />
If you want to learn how to write udev rules see [http://www.reactivated.net/writing_udev_rules.html Writing udev rules].<br />
<br />
To get a list of all the attributes of a device you can use to write rules:<br />
# udevadm info -a -n [device name]<br />
<br />
Replace [device name] with the device present in the system, such as '/dev/sda' or '/dev/ttyUSB0'.<br />
<br />
Udev automatically detects changes to rule files, so changes take effect immediately without requiring udev to be restarted. However, the rules are not re-triggered automatically on already existing devices, so hotpluggable devices, such as USB devices, will probably have to be reconnected for the new rules to take effect.<br />
<br />
== Tips & Tricks ==<br />
=== UDisks ===<br />
Simply install UDisks:<br />
pacman -S udisks<br />
and all your media should be auto mounted in GNOME and KDE SC 4.6. There is no need for any additional rules this way.<br />
As an extra bonus you can remove HAL if you were only using that for auto mounting purposes.<br />
<br />
==== Automounting UDisks Wrappers ====<br />
A UDisks wrapper has the advantage of being very easy to install and needing no (or minimal) configuration. The wrapper will automatically mount things like CDs and flash drives.<br />
<br />
* [http://igurublog.wordpress.com/downloads/script-devmon/ devmon] - devmon ([http://aur.archlinux.org/packages.php?ID=45842 AUR]) is a configuration-less bash wrapper script for udisks which automounts optical discs and removable drives. It can also selectively autostart apps or execute commands after mounting, ignore specified devices and volume labels, and unmount removable drives. <br />
* [[udiskie]] - Written in Python. Allows auto mount and unmount by any user.<br />
* [http://aur.archlinux.org/packages.php?ID=38723 udisksevt] - Written in Haskell. Allows auto mount by any user. Designed to be integrated with [http://aur.archlinux.org/packages.php?ID=32005 traydevice].<br />
* The [http://aur.archlinux.org/packages.php?ID=46572 udisksvm bash script] uses udisks and [http://aur.archlinux.org/packages.php?ID=32005 Traydevice] to automount removable media and to control in GUI, with mouse clicks in systray, the un-mounting and re-mounting of disks or the ejection of optical disks.<br />
<br />
==== UDisks Shell Functions ====<br />
While UDisks includes a simple method of (un)mounting devices via command-line, it can be tiresome to type the commands out each time. These shell functions will generally shorten and ease command-line usage.<br />
<br />
* [https://bbs.archlinux.org/viewtopic.php?id=109307 udisks_functions] - Written for Bash.<br />
* [https://bbs.archlinux.org/viewtopic.php?id=117674 bashmount] - bashmount [http://aur.archlinux.org/packages.php?ID=48524 (AUR)] is a menu-driven bash script with a configuration file that makes it easy to configure and extend.<br />
<br />
=== Auto mounting USB devices ===<br />
{{Note|In the following rules the mount options are defined as {{Codeline|<nowiki>ENV{mount_options}="relatime"</nowiki>}}, see {{Codeline|man mount}} (and possibly {{Codeline|man ntfs-3g}}) for all available options and [[Maximizing Performance#Mount options]] for performance-related options.}}<br />
{{Note|The {{Codeline|users}} mount option will '''not''' allow users to unmount the filesystem.}}<br />
{{Tip|The {{Codeline|noexec}} mount option prevents execution of binaries on the mounted filesystem.}}<br />
<br />
==== Mount under {{Filename|/media}}; use partition label if present ====<br />
The following udev rule set automatically mounts devices/partitions that are represented by /dev/sd* (USB drives, external hard drives and sometimes SD cards). If a partition label is available, it mounts the device to /media/<label> and otherwise to /media/usbhd-sd* (ex: /media/usbhd-sdb1):<br />
{{File|name=/etc/udev/rules.d/11-media-by-label-auto-mount.rules|content=<nowiki><br />
KERNEL!="sd[a-z][0-9]", GOTO="media_by_label_auto_mount_end"<br />
<br />
# Import FS infos<br />
IMPORT{program}="/sbin/blkid -o udev -p %N"<br />
<br />
# Get a label if present, otherwise specify one<br />
ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}"<br />
ENV{ID_FS_LABEL}=="", ENV{dir_name}="usbhd-%k"<br />
<br />
# Global mount options<br />
ACTION=="add", ENV{mount_options}="relatime"<br />
# Filesystem-specific mount options<br />
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},utf8,gid=100,umask=002"<br />
<br />
# Mount the device<br />
ACTION=="add", RUN+="/bin/mkdir -p /media/%E{dir_name}", RUN+="/bin/mount -o $env{mount_options} /dev/%k /media/%E{dir_name}"<br />
<br />
# Clean up after removal<br />
ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l /media/%E{dir_name}", RUN+="/bin/rmdir /media/%E{dir_name}"<br />
<br />
# Exit<br />
LABEL="media_by_label_auto_mount_end"<br />
</nowiki>}}<br />
<br />
==== Mount under {{Filename|/media}}; use partition label if present; supports LUKS encryption ====<br />
Similar to the above rule set, but if the device is a LUKS-encrypted partition it will open an xterm window to ask for the passphrase (provided that xterm is installed). Also see [http://bbs.archlinux.org/viewtopic.php?pid=696239#p696239 this post] and the follow-ups.<br />
<br />
{{Note|You may need to modify the path to cryptsetup, depending on the version installed (e.g., < 1.1.1_rc2-1).}}<br />
<br />
{{File|name=/etc/udev/rules.d/11-media-by-label-auto-mount.rules|content=<nowiki><br />
KERNEL!="sd[a-z]*", GOTO="media_by_label_auto_mount_end"<br />
ACTION=="add", PROGRAM!="/sbin/blkid %N", GOTO="media_by_label_auto_mount_end"<br />
<br />
# Do not mount devices already mounted somewhere else to avoid entries for all your local partitions in /media<br />
ACTION=="add", PROGRAM=="/bin/grep -q ' /dev/%k ' /proc/self/mountinfo", GOTO="media_by_label_auto_mount_end"<br />
<br />
# Open LUKS partition if necessary<br />
PROGRAM=="/sbin/blkid -o value -s TYPE %N", RESULT=="crypto_LUKS", ENV{crypto}="mapper/", ENV{device}="/dev/mapper/%k"<br />
ENV{crypto}=="", ENV{device}="%N"<br />
ACTION=="add", ENV{crypto}!="", PROGRAM=="/usr/bin/xterm -display :0.0 -e 'echo Password for /dev/%k; /sbin/cryptsetup luksOpen %N %k'"<br />
ACTION=="add", ENV{crypto}!="", TEST!="/dev/mapper/%k", GOTO="media_by_label_auto_mount_end"<br />
<br />
# Global mount options<br />
ACTION=="add", ENV{mount_options}="noatime"<br />
# Filesystem-specific mount options<br />
ACTION=="add", PROGRAM=="/sbin/blkid -o value -s TYPE %E{device}", RESULT=="vfat|ntfs", ENV{mount_options}="%E{mount_options},utf8,gid=100,umask=002"<br />
<br />
# Get label if present, otherwise assign one<br />
PROGRAM=="/sbin/blkid -o value -s LABEL %E{device}", ENV{dir_name}="%c"<br />
# Use basename to correctly handle labels such as ../mnt/foo<br />
PROGRAM=="/usr/bin/basename '%E{dir_name}'", ENV{dir_name}="%c"<br />
ENV{dir_name}=="", ENV{dir_name}="usbhd-%k"<br />
<br />
# Mount the device<br />
ACTION=="add", ENV{dir_name}!="", RUN+="/bin/mkdir -p '/media/%E{dir_name}'", RUN+="/bin/mount -o %E{mount_options} /dev/%E{crypto}%k '/media/%E{dir_name}'"<br />
<br />
# Clean up after removal<br />
ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l '/media/%E{dir_name}'"<br />
ACTION=="remove", ENV{crypto}!="", RUN+="/sbin/cryptsetup luksClose %k"<br />
ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/rmdir '/media/%E{dir_name}'"<br />
<br />
# Exit<br />
LABEL="media_by_label_auto_mount_end"<br />
</nowiki>}}<br />
<br />
==== Mount under {{Filename|/media}}; use partition label if present; support user un-mounting ====<br />
This is a variation on the above rule set. It uses pmount (which will need to be installed) instead of mount, allowing a non-root user to unmount udev-mounted devices, and automatically removing the mount point. The required username (here tomk) must be hard-coded in the RUN command, so this rule set may not be suitable for multi-user systems. LUKS support has also been removed from the example, but can be easily reinstated as above. You must edit the /bin/su invocation to run as the correct user for your system. Note that the mount point will remain if the device is mounted and the system, with a persistent /media, is shutdown, since rc.shutdown uses umount, which does not remove the mount point. To avoid having /media contain old mount points, one solution is to mount /media as tmpfs.<br />
{{File|name=/etc/udev/rules.d/11-media-by-label-with-pmount.rules|content=<nowiki><br />
KERNEL!="sd[a-z]*", GOTO="media_by_label_auto_mount_end"<br />
ACTION=="add", PROGRAM!="/sbin/blkid %N", GOTO="media_by_label_auto_mount_end"<br />
<br />
# Get label<br />
PROGRAM=="/sbin/blkid -o value -s LABEL %N", ENV{dir_name}="%c"<br />
# use basename to correctly handle labels such as ../mnt/foo<br />
PROGRAM=="/usr/bin/basename '%E{dir_name}'", ENV{dir_name}="%c"<br />
ENV{dir_name}=="", ENV{dir_name}="usbhd-%k"<br />
<br />
ACTION=="add", ENV{dir_name}!="", RUN+="/bin/su tomk -c '/usr/bin/pmount %N %E{dir_name}'"<br />
ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/su tomk -c '/usr/bin/pumount /media/%E{dir_name}'"<br />
LABEL="media_by_label_auto_mount_end"<br />
</nowiki>}}<br />
<br />
==== Mount under {{Filename|/mnt}}; create symbolic link under {{Filename|/media}} ====<br />
The following rule set does not make use of partition labels; instead it mounts devices as usbhd-sdXY under the /mnt directory (ex: /mnt/usbhd-sdb1) and creates a symbolic link under /media.<br />
{{File|name=/etc/udev/rules.d/11-mnt-auto-mount.rules|content=<nowiki><br />
KERNEL!="sd[a-z][0-9]", GOTO="mnt_auto_mount_end"<br />
<br />
# Global mount options<br />
ACTION=="add", ENV{mount_options}="relatime"<br />
# Filesystem-specific mount options<br />
ACTION=="add", IMPORT{program}="/sbin/blkid -o udev -p %N"<br />
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},utf8,gid=100,umask=002"<br />
<br />
# Mount under /mnt and create the symbolic link in /media <br />
ACTION=="add", RUN+="/bin/mount -o $env{mount_options} /dev/%k /mnt/usbhd-%k", RUN+="/bin/ln -s /mnt/usbhd-%k /media/usbhd-%k"<br />
<br />
# Clean up after removal<br />
ACTION=="remove", RUN+="/bin/rm -f /media/usbhd-%k", RUN+="/bin/umount -l /mnt/usbhd-%k", RUN+="/bin/rmdir /mnt/usbhd-%k"<br />
<br />
# Exit<br />
LABEL="mnt_auto_mount_end"<br />
</nowiki>}}<br />
<br />
==== Mount under {{Filename|/media}} ''only'' if the partition has a label ====<br />
{{File|name=/etc/udev/rules.d/11-media-by-label-only-auto-mount.rules|content=<nowiki><br />
KERNEL!="sd[a-z][0-9]", GOTO="media_by_label_only_auto_mount_end"<br />
<br />
# Import FS infos<br />
IMPORT{program}="/sbin/blkid -o udev -p %N"<br />
ENV{ID_FS_LABEL}=="", GOTO="media_by_label_only_auto_mount_end"<br />
<br />
# Global mount options<br />
ACTION=="add", ENV{mount_options}="relatime"<br />
# Filesystem-specific mount options<br />
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},utf8,gid=100,umask=002"<br />
<br />
# Mount the device<br />
ACTION=="add", RUN+="/bin/mkdir -p /media/$env{ID_FS_LABEL}", RUN+="/bin/mount -o $env{mount_options} /dev/%k /media/$env{ID_FS_LABEL}"<br />
<br />
# Clean up after removal<br />
ACTION=="remove", ENV{ID_FS_LABEL}!="", RUN+="/bin/umount -l /media/$env{ID_FS_LABEL}", RUN+="/bin/rmdir /media/$env{ID_FS_LABEL}"<br />
<br />
# Exit<br />
LABEL="media_by_label_only_auto_mount_end"<br />
</nowiki>}}<br />
<br />
==== Mount under {{Filename|/media}}; use partition label if present; ntfs-3g ====<br />
Yet another example, this time making use of ntfs-3g read/write drivers for NTFS filesystems:<br />
<br />
{{File|name=/etc/udev/rules.d/10-my-media-automount.rules|content=<nowiki><br />
# vim:enc=utf-8:nu:ai:si:et:ts=4:sw=4:ft=udevrules:<br />
#<br />
# /etc/udev/rules.d/10-my-media-automount.rules<br />
<br />
# start at sdb to ignore the system hard drive<br />
KERNEL!="sd[b-z]*", GOTO="my_media_automount_end"<br />
ACTION=="add", PROGRAM!="/sbin/blkid %N", GOTO="my_media_automount_end"<br />
<br />
# import some useful filesystem info as variables<br />
IMPORT{program}="/sbin/blkid -o udev -p %N"<br />
<br />
# get the label if present, otherwise assign one based on device/partition<br />
ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}"<br />
ENV{ID_FS_LABEL}=="", ENV{dir_name}="usbhd-%k"<br />
<br />
# create the dir in /media and symlink it to /mnt<br />
ACTION=="add", RUN+="/bin/mkdir -p '/media/%E{dir_name}'"<br />
<br />
# global mount options<br />
ACTION=="add", ENV{mount_options}="relatime"<br />
# filesystem-specific mount options (777/666 dir/file perms for ntfs/vfat) <br />
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},gid=100,dmask=000,fmask=111,utf8"<br />
<br />
# automount ntfs filesystems using ntfs-3g driver<br />
ACTION=="add", ENV{ID_FS_TYPE}=="ntfs", RUN+="/bin/mount -t ntfs-3g -o %E{mount_options} /dev/%k '/media/%E{dir_name}'"<br />
# automount all other filesystems<br />
ACTION=="add", ENV{ID_FS_TYPE}!="ntfs", RUN+="/bin/mount -t auto -o %E{mount_options} /dev/%k '/media/%E{dir_name}'"<br />
<br />
# clean up after device removal<br />
ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l '/media/%E{dir_name}'", RUN+="/bin/rmdir '/media/%E{dir_name}'"<br />
<br />
# exit<br />
LABEL="my_media_automount_end"<br />
<br />
</nowiki>}}<br />
<br />
==== Mount SD cards ====<br />
The same rules as above can be used to auto-mount SD cards, you just need to replace {{Codeline|sd[a-z][0-9]}} by {{Codeline|mmcblk[0-9]p[0-9]}}:<br />
{{File|name=/etc/udev/rules.d/11-sd-cards-auto-mount.rules|content=<nowiki><br />
KERNEL!="mmcblk[0-9]p[0-9]", GOTO="sd_cards_auto_mount_end"<br />
<br />
# Global mount options<br />
ACTION=="add", ENV{mount_options}="relatime"<br />
# Filesystem specific options<br />
ACTION=="add", IMPORT{program}="/sbin/blkid -o udev -p %N"<br />
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},utf8,gid=100,umask=002"<br />
<br />
ACTION=="add", RUN+="/bin/mkdir -p /media/sd-%k", RUN+="/bin/ln -s /media/sd-%k /mnt/sd-%k", RUN+="/bin/mount -o $env{mount_options} /dev/%k /media/sd-%k"<br />
ACTION=="remove", RUN+="/bin/umount -l /media/sd-%k", RUN+="/bin/rmdir /media/sd-%k"<br />
LABEL="sd_cards_auto_mount_end"<br />
</nowiki>}}<br />
<br />
==== Mount CDs ====<br />
To auto mount a CD a simple [[#Automounting_UDisks_Wrappers|UDisks wrapper]] will get the job done properly.<br />
{{Note|Maybe this should be merged to the Udisks wrapper section.}}<br />
<br />
==== Accessing Firmware Programmers and USB Virtual Comm Devices ====<br />
The following ruleset will allow normal users (within the "users" group) the ability to access the [http://www.ladyada.net/make/usbtinyisp/ USBtinyISP] USB programmer for AVR microcontrollers and a generic (SiLabs [http://www.silabs.com/products/interface/usbtouart CP2102]) USB to UART adapter. Adjust the permissions accordingly. Verified as of 2010-02-11.<br />
<br />
{{File|name=/etc/udev/rules.d/50-embedded_devices.rules|content=<nowiki><br />
# USBtinyISP Programmer rules<br />
SUBSYSTEMS=="usb", ATTRS{idVendor}=="1781", ATTRS{idProduct}=="0c9f", GROUP="users", MODE="0666"<br />
SUBSYSTEMS=="usb", ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="0479", GROUP="users", MODE="0666"<br />
# USBasp Programmer rules http://www.fischl.de/usbasp/<br />
SUBSYSTEMS=="usb", ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="05dc", GROUP="users", MODE="0666"<br />
<br />
# Mdfly.com Generic (SiLabs CP2102) 3.3v/5v USB VComm adapter<br />
SUBSYSTEMS=="usb", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", GROUP="users", MODE="0666"<br />
</nowiki>}}<br />
<br />
=== Execute on USB Insert ===<br />
<br />
See [[Execute_on_usb_insert|execute on usb insert]] article or the [http://igurublog.wordpress.com/downloads/script-devmon/ devmon wrapper script].<br />
<br />
=== Mount internal drives as a normal user ===<br />
<br />
If you want to mount an internal drive in KDE or Gnome (maybe on other Desktop Environments too) as a normal user (without the need to type your superuser password), you just have to create the following file in [[PolicyKit]] Local Authority:<br />
{{File|name=/etc/polkit-1/localauthority/50-local.d/50-filesystem-mount-system-internal.pkla|content=<nowiki><br />
[Mount a system-internal device]<br />
Identity=*<br />
Action=org.freedesktop.udisks.filesystem-mount-system-internal<br />
ResultActive=yes<br />
</nowiki>}}<br />
<br />
=== Mark internal SATA-Ports as eSATA-Ports ===<br />
<br />
If you connected a eSATA bay or an other eSATA adapter the system will still recognize this disk as an internal SATA drive. Gnome and KDE will ask you for your root password all the time. The following rule will mark the specified SATA-Port as an external eSATA-Port. With that, a normal Gnome user can connect their eSATA drives to that port like a USB drive, without any root password and so on.<br />
<br />
{{File|name=/etc/udev/rules.d/10-esata.rules|content=<nowiki><br />
DEVPATH=="/devices/pci0000:00/0000:00:1f.2/host4/*", ENV{UDISKS_SYSTEM_INTERNAL}="0"<br />
</nowiki>}}<br />
<br />
{{Note| The DEVPATH can be found after connection the eSata drive with the following command (replace sdb to your needs):<br />
<br />
# find /sys/devices/ -name sdb<br />
/sys/devices/pci0000:00/0000:00:1f.2/host4/target4:0:0/4:0:0:0/block/sdb<br />
<br />
}}<br />
<br />
==Troubleshooting==<br />
<br />
=== Blacklisting Modules ===<br />
In rare cases, udev can make mistakes and load the wrong modules. To prevent it from doing this, you can blacklist modules. Once blacklisted, udev will never load that module. See [[blacklisting]]. Not at boot-time ''or'' later on when a hotplug event is received (eg, you plug in your USB flash drive).<br />
<br />
=== udevd hangs at boot ===<br />
After migrating to LDAP or updating an LDAP-backed system udevd can hang at boot at the message "Starting UDev Daemon". This is usually caused by udevd trying to look up a name from LDAP but failing, because the network is not up yet. The solution is to ensure that all system group names are present locally.<br />
<br />
Extract the group names referenced in udev rules and the group names actually present on the system:<br />
<br />
# fgrep -r GROUP /etc/udev/rules.d/ /lib/udev/rules.d | perl -nle '/GROUP\s*=\s*"(.*?)"/ && print $1;' | sort | uniq > udev_groups<br />
# cut -f1 -d: /etc/gshadow /etc/group | sort | uniq > present_groups<br />
<br />
To see the differences, do a side-by-side diff:<br />
<br />
# diff -y present_groups udev_groups<br />
...<br />
network <<br />
nobody <<br />
ntp <<br />
optical optical<br />
power | pcscd<br />
rfkill <<br />
root root<br />
scanner scanner<br />
smmsp <<br />
storage storage<br />
...<br />
<br />
In this case, the pcscd group is for some reason not present in the system. Add the missing groups:<br />
<br />
# groupadd pcscd<br />
<br />
Also, make sure local resources are looked up before resorting to LDAP. {{Filename|/etc/nsswitch.conf}} should contain the line<br />
<br />
group: files ldap<br />
<br />
=== Known Problems with Hardware ===<br />
====BusLogic devices can be broken and will cause a freeze during startup====<br />
This is a kernel bug and no fix has been provided yet.<br />
====Some devices, that should be treated as removable, are not====<br />
Create a custom udev rule, setting UDISKS_SYSTEM_INTERNAL=0. For more details, see the manpage of udisks.<br />
<br />
=== Known Problems with Auto-Loading ===<br />
==== CPU frequency modules ====<br />
The current detection method for the various CPU frequency controllers is inadequate, so this has been omitted from the auto-loading process for the time being. To use [[CPU Frequency Scaling]], load the proper module explicitly in your {{Codeline|MODULES}} array in {{Filename|/etc/rc.conf}}. Further reading: [[rc.conf]].<br />
<br />
====Sound Problems or Some Modules Not Loaded Automatically====<br />
Some users have traced this problem to old entries in {{Filename|/etc/modprobe.d/sound.conf}}. Try cleaning that file out and trying again.<br />
{{Note|Since {{Codeline|udev>&#61;171}}, the OSS emulation modules ({{Codeline|snd_seq_oss, snd_pcm_oss, snd_mixer_oss}}) are not automatically loaded by default.}}<br />
<br />
==== Mixed Up Devices, Sound/Network Cards Changing Order Each Boot ====<br />
Because udev loads all modules asynchronously, they are initialized in a different order. This can result in devices randomly switching names. For example, with two network cards, you may notice a switching of designations between {{Codeline|eth0}} and {{Codeline|eth1}}.<br />
<br />
Arch Linux provides the advantage of specifying the module load order by listing the modules in the {{Codeline|MODULES}} array in {{Filename|[[rc.conf]]}}. Modules in this array are loaded before udev begins auto-loading, so you have full control over the load order.<br />
<br />
# Always load 8139too before e100<br />
MODULES=(8139too e100)<br />
<br />
Another method for network card ordering is to use the udev-sanctioned method of statically-naming each interface. Create the following file to bind the MAC address of each of your cards to a certain interface name:<br />
{{File|name=/etc/udev/rules.d/10-network.rules|content=<nowiki><br />
SUBSYSTEM=="net", ATTR{address}=="aa:bb:cc:dd:ee:ff", NAME="lan0"<br />
SUBSYSTEM=="net", ATTR{address}=="ff:ee:dd:cc:bb:aa", NAME="wlan0"<br />
</nowiki>}}<br />
<br />
A couple things to note:<br />
* To get the MAC address of each card, use this command: {{Codeline|<nowiki>udevadm info -a -p /sys/class/net/<yourdevice> | grep address | tr [A-Z] [a-z]</nowiki>}}<br />
* Make sure to use the lower-case hex values in your udev rules. It doesn't like upper-case.<br />
* Some people have problems naming their interfaces after the old style: eth0, eth1, etc. Try something like "lan" or "wlan" if you experience this problem.<br />
<br />
Don't forget to update your {{Filename|/etc/rc.conf}} and other configuration files using the old ethX notation!<br />
<br />
Other methods for setting network interface names are described in the [[Configuring Network#Interface names varying]] wiki entry.<br />
<br />
{{Note|With a recent version of udev (>=175), this problem should be solved automatically thanks to the {{Filename|/lib/udev/write_net_rules}} program which runs the {{Filename|75-persistent-net-generator.rules}} script which produces a {{Filename|70-persistent-net.rules}}.}}<br />
<br />
=== Known Problems for Custom Kernel Users ===<br />
==== Udev doesn't start at all ====<br />
Make sure you have a kernel version later than or equal to 2.6.32. Earlier kernels do not have the necessary uevent stuff that udev needs for auto-loading.<br />
<br />
=== IDE CD/DVD-drive support ===<br />
Starting with version 170, udev doesn't support CD-ROM/DVD-ROM drives, which are loaded as traditional IDE drives with the {{Codeline|ide_cd_mod}} module and show up as {{Filename|/dev/hd*}}. The drive remains usable for tools which access the hardware directly, like cdparanoia, but is invisible for higher userspace programs, like KDE.<br />
<br />
A cause for the loading of the ide_cd_mod module prior to others, like sr_mod, could be e.g. that you have for some reason the module piix loaded with your initramfs. In that case you can just replace it with ata_piix in your {{Filename|/etc/mkinitcpio.conf}}.<br />
<br />
=== Optical Drives Have Group ID Set To Disk ===<br />
If the group ID of your optical drive is set to ''disk'' and you want to have it set to ''optical'' you have to create a custom udev rule:<br />
{{File|name=/etc/udev/rules.d|content=# permissions for IDE CD devices<br />
SUBSYSTEMS=="ide", KERNEL=="hd[a-z]", ATTR{removable}=="1", ATTRS{media}=="cdrom*", GROUP="optical"<br />
<br />
# permissions for SCSI CD devices<br />
SUBSYSTEMS=="scsi", KERNEL=="s[rg][0-9]*", ATTRS{type}=="5", GROUP="optical"}}<br />
<br />
==Other Resources==<br />
* [http://www.kernel.org/pub/linux/utils/kernel/hotplug/udev.html Udev Homepage]<br />
* [http://www.linux.com/news/hardware/peripherals/180950-udev An Introduction to Udev]<br />
* [http://vger.kernel.org/vger-lists.html#linux-hotplug Udev mailing list information]</div>Mayweedhttps://wiki.archlinux.org/index.php?title=Udev&diff=169845Udev2011-11-13T11:19:47Z<p>Mayweed: /* Mixed Up Devices, Sound/Network Cards Changing Order Each Boot */</p>
<hr />
<div>[[Category:Hardware detection and troubleshooting (English)]]<br />
[[Category:Auto-mounting (English)]]<br />
{{i18n|Udev}}<br />
{{Lowercase title}}<br />
<br />
'''udev''' replaces the functionality of both {{Codeline|hotplug}} and {{Codeline|hwdetect}}.<br />
<br />
''"udev is the device manager for the Linux kernel. Primarily, it manages device nodes in {{Filename|/dev}}. It is the successor of devfs and hotplug, which means that it handles the {{Filename|/dev}} directory and all user space actions when adding/removing devices, including firmware load."'' Source: [[Wikipedia:Udev]]<br />
<br />
udev loads kernel modules by utilizing coding parallelism to provide a potential performance advantage versus loading these modules serially. The modules are therefore loaded asynchronously. The inherent disadvantage of this method is that udev does not always load modules in the same order on each boot. If the machine has multiple block devices, this may manifest itself in the form of device nodes changing designations randomly. For example, if the machine has two hard drives, /dev/sda may randomly become /dev/sdb. See below for more info on this.<br />
<br />
==About udev rules==<br />
udev rules written by the administrator go in {{Filename|/etc/udev/rules.d/}}, their file name has to end with {{Filename|.rules}}. The udev rules shipped with various packages are found in {{Filename|/lib/udev/rules.d/}}. If there are two files by the same name under /lib and /etc, the ones in /etc take precedence.<br />
<br />
If you want to learn how to write udev rules see [http://www.reactivated.net/writing_udev_rules.html Writing udev rules].<br />
<br />
To get a list of all the attributes of a device you can use to write rules:<br />
# udevadm info -a -n [device name]<br />
<br />
Replace [device name] with the device present in the system, such as '/dev/sda' or '/dev/ttyUSB0'.<br />
<br />
Udev automatically detects changes to rule files, so changes take effect immediately without requiring udev to be restarted. However, the rules are not re-triggered automatically on already existing devices, so hotpluggable devices, such as USB devices, will probably have to be reconnected for the new rules to take effect.<br />
<br />
== Tips & Tricks ==<br />
=== UDisks ===<br />
Simply install UDisks:<br />
pacman -S udisks<br />
and all your media should be auto mounted in GNOME and KDE SC 4.6. There is no need for any additional rules this way.<br />
As an extra bonus you can remove HAL if you were only using that for auto mounting purposes.<br />
<br />
==== Automounting UDisks Wrappers ====<br />
A UDisks wrapper has the advantage of being very easy to install and needing no (or minimal) configuration. The wrapper will automatically mount things like CDs and flash drives.<br />
<br />
* [http://igurublog.wordpress.com/downloads/script-devmon/ devmon] - devmon ([http://aur.archlinux.org/packages.php?ID=45842 AUR]) is a configuration-less bash wrapper script for udisks which automounts optical discs and removable drives. It can also selectively autostart apps or execute commands after mounting, ignore specified devices and volume labels, and unmount removable drives. <br />
* [[udiskie]] - Written in Python. Allows auto mount and unmount by any user.<br />
* [http://aur.archlinux.org/packages.php?ID=38723 udisksevt] - Written in Haskell. Allows auto mount by any user. Designed to be integrated with [http://aur.archlinux.org/packages.php?ID=32005 traydevice].<br />
* The [http://aur.archlinux.org/packages.php?ID=46572 udisksvm bash script] uses udisks and [http://aur.archlinux.org/packages.php?ID=32005 Traydevice] to automount removable media and to control in GUI, with mouse clicks in systray, the un-mounting and re-mounting of disks or the ejection of optical disks.<br />
<br />
==== UDisks Shell Functions ====<br />
While UDisks includes a simple method of (un)mounting devices via command-line, it can be tiresome to type the commands out each time. These shell functions will generally shorten and ease command-line usage.<br />
<br />
* [https://bbs.archlinux.org/viewtopic.php?id=109307 udisks_functions] - Written for Bash.<br />
* [https://bbs.archlinux.org/viewtopic.php?id=117674 bashmount] - bashmount [http://aur.archlinux.org/packages.php?ID=48524 (AUR)] is a menu-driven bash script with a configuration file that makes it easy to configure and extend.<br />
<br />
=== Auto mounting USB devices ===<br />
{{Note|In the following rules the mount options are defined as {{Codeline|<nowiki>ENV{mount_options}="relatime"</nowiki>}}, see {{Codeline|man mount}} (and possibly {{Codeline|man ntfs-3g}}) for all available options and [[Maximizing Performance#Mount options]] for performance-related options.}}<br />
{{Note|The {{Codeline|users}} mount option will '''not''' allow users to unmount the filesystem.}}<br />
{{Tip|The {{Codeline|noexec}} mount option prevents execution of binaries on the mounted filesystem.}}<br />
<br />
==== Mount under {{Filename|/media}}; use partition label if present ====<br />
The following udev rule set automatically mounts devices/partitions that are represented by /dev/sd* (USB drives, external hard drives and sometimes SD cards). If a partition label is available, it mounts the device to /media/<label> and otherwise to /media/usbhd-sd* (ex: /media/usbhd-sdb1):<br />
{{File|name=/etc/udev/rules.d/11-media-by-label-auto-mount.rules|content=<nowiki><br />
KERNEL!="sd[a-z][0-9]", GOTO="media_by_label_auto_mount_end"<br />
<br />
# Import FS infos<br />
IMPORT{program}="/sbin/blkid -o udev -p %N"<br />
<br />
# Get a label if present, otherwise specify one<br />
ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}"<br />
ENV{ID_FS_LABEL}=="", ENV{dir_name}="usbhd-%k"<br />
<br />
# Global mount options<br />
ACTION=="add", ENV{mount_options}="relatime"<br />
# Filesystem-specific mount options<br />
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},utf8,gid=100,umask=002"<br />
<br />
# Mount the device<br />
ACTION=="add", RUN+="/bin/mkdir -p /media/%E{dir_name}", RUN+="/bin/mount -o $env{mount_options} /dev/%k /media/%E{dir_name}"<br />
<br />
# Clean up after removal<br />
ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l /media/%E{dir_name}", RUN+="/bin/rmdir /media/%E{dir_name}"<br />
<br />
# Exit<br />
LABEL="media_by_label_auto_mount_end"<br />
</nowiki>}}<br />
<br />
==== Mount under {{Filename|/media}}; use partition label if present; supports LUKS encryption ====<br />
Similar to the above rule set, but if the device is a LUKS-encrypted partition it will open an xterm window to ask for the passphrase (provided that xterm is installed). Also see [http://bbs.archlinux.org/viewtopic.php?pid=696239#p696239 this post] and the follow-ups.<br />
<br />
{{Note|You may need to modify the path to cryptsetup, depending on the version installed (e.g., < 1.1.1_rc2-1).}}<br />
<br />
{{File|name=/etc/udev/rules.d/11-media-by-label-auto-mount.rules|content=<nowiki><br />
KERNEL!="sd[a-z]*", GOTO="media_by_label_auto_mount_end"<br />
ACTION=="add", PROGRAM!="/sbin/blkid %N", GOTO="media_by_label_auto_mount_end"<br />
<br />
# Do not mount devices already mounted somewhere else to avoid entries for all your local partitions in /media<br />
ACTION=="add", PROGRAM=="/bin/grep -q ' /dev/%k ' /proc/self/mountinfo", GOTO="media_by_label_auto_mount_end"<br />
<br />
# Open LUKS partition if necessary<br />
PROGRAM=="/sbin/blkid -o value -s TYPE %N", RESULT=="crypto_LUKS", ENV{crypto}="mapper/", ENV{device}="/dev/mapper/%k"<br />
ENV{crypto}=="", ENV{device}="%N"<br />
ACTION=="add", ENV{crypto}!="", PROGRAM=="/usr/bin/xterm -display :0.0 -e 'echo Password for /dev/%k; /sbin/cryptsetup luksOpen %N %k'"<br />
ACTION=="add", ENV{crypto}!="", TEST!="/dev/mapper/%k", GOTO="media_by_label_auto_mount_end"<br />
<br />
# Global mount options<br />
ACTION=="add", ENV{mount_options}="noatime"<br />
# Filesystem-specific mount options<br />
ACTION=="add", PROGRAM=="/sbin/blkid -o value -s TYPE %E{device}", RESULT=="vfat|ntfs", ENV{mount_options}="%E{mount_options},utf8,gid=100,umask=002"<br />
<br />
# Get label if present, otherwise assign one<br />
PROGRAM=="/sbin/blkid -o value -s LABEL %E{device}", ENV{dir_name}="%c"<br />
# Use basename to correctly handle labels such as ../mnt/foo<br />
PROGRAM=="/usr/bin/basename '%E{dir_name}'", ENV{dir_name}="%c"<br />
ENV{dir_name}=="", ENV{dir_name}="usbhd-%k"<br />
<br />
# Mount the device<br />
ACTION=="add", ENV{dir_name}!="", RUN+="/bin/mkdir -p '/media/%E{dir_name}'", RUN+="/bin/mount -o %E{mount_options} /dev/%E{crypto}%k '/media/%E{dir_name}'"<br />
<br />
# Clean up after removal<br />
ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l '/media/%E{dir_name}'"<br />
ACTION=="remove", ENV{crypto}!="", RUN+="/sbin/cryptsetup luksClose %k"<br />
ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/rmdir '/media/%E{dir_name}'"<br />
<br />
# Exit<br />
LABEL="media_by_label_auto_mount_end"<br />
</nowiki>}}<br />
<br />
==== Mount under {{Filename|/media}}; use partition label if present; support user un-mounting ====<br />
This is a variation on the above rule set. It uses pmount (which will need to be installed) instead of mount, allowing a non-root user to unmount udev-mounted devices, and automatically removing the mount point. The required username (here tomk) must be hard-coded in the RUN command, so this rule set may not be suitable for multi-user systems. LUKS support has also been removed from the example, but can be easily reinstated as above. You must edit the /bin/su invocation to run as the correct user for your system. Note that the mount point will remain if the device is mounted and the system, with a persistent /media, is shutdown, since rc.shutdown uses umount, which does not remove the mount point. To avoid having /media contain old mount points, one solution is to mount /media as tmpfs.<br />
{{File|name=/etc/udev/rules.d/11-media-by-label-with-pmount.rules|content=<nowiki><br />
KERNEL!="sd[a-z]*", GOTO="media_by_label_auto_mount_end"<br />
ACTION=="add", PROGRAM!="/sbin/blkid %N", GOTO="media_by_label_auto_mount_end"<br />
<br />
# Get label<br />
PROGRAM=="/sbin/blkid -o value -s LABEL %N", ENV{dir_name}="%c"<br />
# use basename to correctly handle labels such as ../mnt/foo<br />
PROGRAM=="/usr/bin/basename '%E{dir_name}'", ENV{dir_name}="%c"<br />
ENV{dir_name}=="", ENV{dir_name}="usbhd-%k"<br />
<br />
ACTION=="add", ENV{dir_name}!="", RUN+="/bin/su tomk -c '/usr/bin/pmount %N %E{dir_name}'"<br />
ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/su tomk -c '/usr/bin/pumount /media/%E{dir_name}'"<br />
LABEL="media_by_label_auto_mount_end"<br />
</nowiki>}}<br />
<br />
==== Mount under {{Filename|/mnt}}; create symbolic link under {{Filename|/media}} ====<br />
The following rule set does not make use of partition labels; instead it mounts devices as usbhd-sdXY under the /mnt directory (ex: /mnt/usbhd-sdb1) and creates a symbolic link under /media.<br />
{{File|name=/etc/udev/rules.d/11-mnt-auto-mount.rules|content=<nowiki><br />
KERNEL!="sd[a-z][0-9]", GOTO="mnt_auto_mount_end"<br />
<br />
# Global mount options<br />
ACTION=="add", ENV{mount_options}="relatime"<br />
# Filesystem-specific mount options<br />
ACTION=="add", IMPORT{program}="/sbin/blkid -o udev -p %N"<br />
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},utf8,gid=100,umask=002"<br />
<br />
# Mount under /mnt and create the symbolic link in /media <br />
ACTION=="add", RUN+="/bin/mount -o $env{mount_options} /dev/%k /mnt/usbhd-%k", RUN+="/bin/ln -s /mnt/usbhd-%k /media/usbhd-%k"<br />
<br />
# Clean up after removal<br />
ACTION=="remove", RUN+="/bin/rm -f /media/usbhd-%k", RUN+="/bin/umount -l /mnt/usbhd-%k", RUN+="/bin/rmdir /mnt/usbhd-%k"<br />
<br />
# Exit<br />
LABEL="mnt_auto_mount_end"<br />
</nowiki>}}<br />
<br />
==== Mount under {{Filename|/media}} ''only'' if the partition has a label ====<br />
{{File|name=/etc/udev/rules.d/11-media-by-label-only-auto-mount.rules|content=<nowiki><br />
KERNEL!="sd[a-z][0-9]", GOTO="media_by_label_only_auto_mount_end"<br />
<br />
# Import FS infos<br />
IMPORT{program}="/sbin/blkid -o udev -p %N"<br />
ENV{ID_FS_LABEL}=="", GOTO="media_by_label_only_auto_mount_end"<br />
<br />
# Global mount options<br />
ACTION=="add", ENV{mount_options}="relatime"<br />
# Filesystem-specific mount options<br />
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},utf8,gid=100,umask=002"<br />
<br />
# Mount the device<br />
ACTION=="add", RUN+="/bin/mkdir -p /media/$env{ID_FS_LABEL}", RUN+="/bin/mount -o $env{mount_options} /dev/%k /media/$env{ID_FS_LABEL}"<br />
<br />
# Clean up after removal<br />
ACTION=="remove", ENV{ID_FS_LABEL}!="", RUN+="/bin/umount -l /media/$env{ID_FS_LABEL}", RUN+="/bin/rmdir /media/$env{ID_FS_LABEL}"<br />
<br />
# Exit<br />
LABEL="media_by_label_only_auto_mount_end"<br />
</nowiki>}}<br />
<br />
==== Mount under {{Filename|/media}}; use partition label if present; ntfs-3g ====<br />
Yet another example, this time making use of ntfs-3g read/write drivers for NTFS filesystems:<br />
<br />
{{File|name=/etc/udev/rules.d/10-my-media-automount.rules|content=<nowiki><br />
# vim:enc=utf-8:nu:ai:si:et:ts=4:sw=4:ft=udevrules:<br />
#<br />
# /etc/udev/rules.d/10-my-media-automount.rules<br />
<br />
# start at sdb to ignore the system hard drive<br />
KERNEL!="sd[b-z]*", GOTO="my_media_automount_end"<br />
ACTION=="add", PROGRAM!="/sbin/blkid %N", GOTO="my_media_automount_end"<br />
<br />
# import some useful filesystem info as variables<br />
IMPORT{program}="/sbin/blkid -o udev -p %N"<br />
<br />
# get the label if present, otherwise assign one based on device/partition<br />
ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}"<br />
ENV{ID_FS_LABEL}=="", ENV{dir_name}="usbhd-%k"<br />
<br />
# create the dir in /media and symlink it to /mnt<br />
ACTION=="add", RUN+="/bin/mkdir -p '/media/%E{dir_name}'"<br />
<br />
# global mount options<br />
ACTION=="add", ENV{mount_options}="relatime"<br />
# filesystem-specific mount options (777/666 dir/file perms for ntfs/vfat) <br />
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},gid=100,dmask=000,fmask=111,utf8"<br />
<br />
# automount ntfs filesystems using ntfs-3g driver<br />
ACTION=="add", ENV{ID_FS_TYPE}=="ntfs", RUN+="/bin/mount -t ntfs-3g -o %E{mount_options} /dev/%k '/media/%E{dir_name}'"<br />
# automount all other filesystems<br />
ACTION=="add", ENV{ID_FS_TYPE}!="ntfs", RUN+="/bin/mount -t auto -o %E{mount_options} /dev/%k '/media/%E{dir_name}'"<br />
<br />
# clean up after device removal<br />
ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l '/media/%E{dir_name}'", RUN+="/bin/rmdir '/media/%E{dir_name}'"<br />
<br />
# exit<br />
LABEL="my_media_automount_end"<br />
<br />
</nowiki>}}<br />
<br />
==== Mount SD cards ====<br />
The same rules as above can be used to auto-mount SD cards, you just need to replace {{Codeline|sd[a-z][0-9]}} by {{Codeline|mmcblk[0-9]p[0-9]}}:<br />
{{File|name=/etc/udev/rules.d/11-sd-cards-auto-mount.rules|content=<nowiki><br />
KERNEL!="mmcblk[0-9]p[0-9]", GOTO="sd_cards_auto_mount_end"<br />
<br />
# Global mount options<br />
ACTION=="add", ENV{mount_options}="relatime"<br />
# Filesystem specific options<br />
ACTION=="add", IMPORT{program}="/sbin/blkid -o udev -p %N"<br />
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},utf8,gid=100,umask=002"<br />
<br />
ACTION=="add", RUN+="/bin/mkdir -p /media/sd-%k", RUN+="/bin/ln -s /media/sd-%k /mnt/sd-%k", RUN+="/bin/mount -o $env{mount_options} /dev/%k /media/sd-%k"<br />
ACTION=="remove", RUN+="/bin/umount -l /media/sd-%k", RUN+="/bin/rmdir /media/sd-%k"<br />
LABEL="sd_cards_auto_mount_end"<br />
</nowiki>}}<br />
<br />
==== Mount CDs ====<br />
To auto mount a CD a simple [[#Automounting_UDisks_Wrappers|UDisks wrapper]] will get the job done properly.<br />
{{Note|Maybe this should be merged to the Udisks wrapper section.}}<br />
<br />
==== Accessing Firmware Programmers and USB Virtual Comm Devices ====<br />
The following ruleset will allow normal users (within the "users" group) the ability to access the [http://www.ladyada.net/make/usbtinyisp/ USBtinyISP] USB programmer for AVR microcontrollers and a generic (SiLabs [http://www.silabs.com/products/interface/usbtouart CP2102]) USB to UART adapter. Adjust the permissions accordingly. Verified as of 2010-02-11.<br />
<br />
{{File|name=/etc/udev/rules.d/50-embedded_devices.rules|content=<nowiki><br />
# USBtinyISP Programmer rules<br />
SUBSYSTEMS=="usb", ATTRS{idVendor}=="1781", ATTRS{idProduct}=="0c9f", GROUP="users", MODE="0666"<br />
SUBSYSTEMS=="usb", ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="0479", GROUP="users", MODE="0666"<br />
# USBasp Programmer rules http://www.fischl.de/usbasp/<br />
SUBSYSTEMS=="usb", ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="05dc", GROUP="users", MODE="0666"<br />
<br />
# Mdfly.com Generic (SiLabs CP2102) 3.3v/5v USB VComm adapter<br />
SUBSYSTEMS=="usb", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", GROUP="users", MODE="0666"<br />
</nowiki>}}<br />
<br />
=== Execute on USB Insert ===<br />
<br />
See [[Execute_on_usb_insert|execute on usb insert]] article or the [http://igurublog.wordpress.com/downloads/script-devmon/ devmon wrapper script].<br />
<br />
=== Mount internal drives as a normal user ===<br />
<br />
If you want to mount an internal drive in KDE or Gnome (maybe on other Desktop Environments too) as a normal user (without the need to type your superuser password), you just have to create the following file in [[PolicyKit]] Local Authority:<br />
{{File|name=/etc/polkit-1/localauthority/50-local.d/50-filesystem-mount-system-internal.pkla|content=<nowiki><br />
[Mount a system-internal device]<br />
Identity=*<br />
Action=org.freedesktop.udisks.filesystem-mount-system-internal<br />
ResultActive=yes<br />
</nowiki>}}<br />
<br />
=== Mark internal SATA-Ports as eSATA-Ports ===<br />
<br />
If you connected a eSATA bay or an other eSATA adapter the system will still recognize this disk as an internal SATA drive. Gnome and KDE will ask you for your root password all the time. The following rule will mark the specified SATA-Port as an external eSATA-Port. With that, a normal Gnome user can connect their eSATA drives to that port like a USB drive, without any root password and so on.<br />
<br />
{{File|name=/etc/udev/rules.d/10-esata.rules|content=<nowiki><br />
DEVPATH=="/devices/pci0000:00/0000:00:1f.2/host4/*", ENV{UDISKS_SYSTEM_INTERNAL}="0"<br />
</nowiki>}}<br />
<br />
{{Note| The DEVPATH can be found after connection the eSata drive with the following command (replace sdb to your needs):<br />
<br />
# find /sys/devices/ -name sdb<br />
/sys/devices/pci0000:00/0000:00:1f.2/host4/target4:0:0/4:0:0:0/block/sdb<br />
<br />
}}<br />
<br />
==Troubleshooting==<br />
<br />
=== Blacklisting Modules ===<br />
In rare cases, udev can make mistakes and load the wrong modules. To prevent it from doing this, you can blacklist modules. Once blacklisted, udev will never load that module. See [[blacklisting]]. Not at boot-time ''or'' later on when a hotplug event is received (eg, you plug in your USB flash drive).<br />
<br />
=== udevd hangs at boot ===<br />
After migrating to LDAP or updating an LDAP-backed system udevd can hang at boot at the message "Starting UDev Daemon". This is usually caused by udevd trying to look up a name from LDAP but failing, because the network is not up yet. The solution is to ensure that all system group names are present locally.<br />
<br />
Extract the group names referenced in udev rules and the group names actually present on the system:<br />
<br />
# fgrep -r GROUP /etc/udev/rules.d/ /lib/udev/rules.d | perl -nle '/GROUP\s*=\s*"(.*?)"/ && print $1;' | sort | uniq > udev_groups<br />
# cut -f1 -d: /etc/gshadow /etc/group | sort | uniq > present_groups<br />
<br />
To see the differences, do a side-by-side diff:<br />
<br />
# diff -y present_groups udev_groups<br />
...<br />
network <<br />
nobody <<br />
ntp <<br />
optical optical<br />
power | pcscd<br />
rfkill <<br />
root root<br />
scanner scanner<br />
smmsp <<br />
storage storage<br />
...<br />
<br />
In this case, the pcscd group is for some reason not present in the system. Add the missing groups:<br />
<br />
# groupadd pcscd<br />
<br />
Also, make sure local resources are looked up before resorting to LDAP. {{Filename|/etc/nsswitch.conf}} should contain the line<br />
<br />
group: files ldap<br />
<br />
=== Known Problems with Hardware ===<br />
====BusLogic devices can be broken and will cause a freeze during startup====<br />
This is a kernel bug and no fix has been provided yet.<br />
====Some devices, that should be treated as removable, are not====<br />
Create a custom udev rule, setting UDISKS_SYSTEM_INTERNAL=0. For more details, see the manpage of udisks.<br />
<br />
=== Known Problems with Auto-Loading ===<br />
==== CPU frequency modules ====<br />
The current detection method for the various CPU frequency controllers is inadequate, so this has been omitted from the auto-loading process for the time being. To use [[CPU Frequency Scaling]], load the proper module explicitly in your {{Codeline|MODULES}} array in {{Filename|/etc/rc.conf}}. Further reading: [[rc.conf]].<br />
<br />
====Sound Problems or Some Modules Not Loaded Automatically====<br />
Some users have traced this problem to old entries in {{Filename|/etc/modprobe.d/sound.conf}}. Try cleaning that file out and trying again.<br />
{{Note|Since {{Codeline|udev>&#61;171}}, the OSS emulation modules ({{Codeline|snd_seq_oss, snd_pcm_oss, snd_mixer_oss}}) are not automatically loaded by default.}}<br />
<br />
==== Mixed Up Devices, Sound/Network Cards Changing Order Each Boot ====<br />
Because udev loads all modules asynchronously, they are initialized in a different order. This can result in devices randomly switching names. For example, with two network cards, you may notice a switching of designations between {{Codeline|eth0}} and {{Codeline|eth1}}.<br />
<br />
Arch Linux provides the advantage of specifying the module load order by listing the modules in the {{Codeline|MODULES}} array in {{Filename|[[rc.conf]]}}. Modules in this array are loaded before udev begins auto-loading, so you have full control over the load order.<br />
<br />
# Always load 8139too before e100<br />
MODULES=(8139too e100)<br />
<br />
Another method for network card ordering is to use the udev-sanctioned method of statically-naming each interface. Create the following file to bind the MAC address of each of your cards to a certain interface name:<br />
{{File|name=/etc/udev/rules.d/10-network.rules|content=<nowiki><br />
SUBSYSTEM=="net", ATTR{address}=="aa:bb:cc:dd:ee:ff", NAME="lan0"<br />
SUBSYSTEM=="net", ATTR{address}=="ff:ee:dd:cc:bb:aa", NAME="wlan0"<br />
</nowiki>}}<br />
<br />
A couple things to note:<br />
* To get the MAC address of each card, use this command: {{Codeline|<nowiki>udevadm info -a -p /sys/class/net/<yourdevice> | grep address | tr [A-Z] [a-z]</nowiki>}}<br />
* Make sure to use the lower-case hex values in your udev rules. It doesn't like upper-case.<br />
* Some people have problems naming their interfaces after the old style: eth0, eth1, etc. Try something like "lan" or "wlan" if you experience this problem.<br />
<br />
Don't forget to update your {{Filename|/etc/rc.conf}} and other configuration files using the old ethX notation!<br />
<br />
Other methods for setting network interface names are described in the [[Configuring Network#Interface names varying]] wiki entry.<br />
<br />
{{Note|With a recent version of udev (>=175), this problem should be solved automatically thanks to the /lib/udev/write_net_rules program which runs the 75-persistent-net-generator.rules script which produces a 70-persistent-net.rules.}}<br />
<br />
=== Known Problems for Custom Kernel Users ===<br />
==== Udev doesn't start at all ====<br />
Make sure you have a kernel version later than or equal to 2.6.32. Earlier kernels do not have the necessary uevent stuff that udev needs for auto-loading.<br />
<br />
=== IDE CD/DVD-drive support ===<br />
Starting with version 170, udev doesn't support CD-ROM/DVD-ROM drives, which are loaded as traditional IDE drives with the {{Codeline|ide_cd_mod}} module and show up as {{Filename|/dev/hd*}}. The drive remains usable for tools which access the hardware directly, like cdparanoia, but is invisible for higher userspace programs, like KDE.<br />
<br />
A cause for the loading of the ide_cd_mod module prior to others, like sr_mod, could be e.g. that you have for some reason the module piix loaded with your initramfs. In that case you can just replace it with ata_piix in your {{Filename|/etc/mkinitcpio.conf}}.<br />
<br />
=== Optical Drives Have Group ID Set To Disk ===<br />
If the group ID of your optical drive is set to ''disk'' and you want to have it set to ''optical'' you have to create a custom udev rule:<br />
{{File|name=/etc/udev/rules.d|content=# permissions for IDE CD devices<br />
SUBSYSTEMS=="ide", KERNEL=="hd[a-z]", ATTR{removable}=="1", ATTRS{media}=="cdrom*", GROUP="optical"<br />
<br />
# permissions for SCSI CD devices<br />
SUBSYSTEMS=="scsi", KERNEL=="s[rg][0-9]*", ATTRS{type}=="5", GROUP="optical"}}<br />
<br />
==Other Resources==<br />
* [http://www.kernel.org/pub/linux/utils/kernel/hotplug/udev.html Udev Homepage]<br />
* [http://www.linux.com/news/hardware/peripherals/180950-udev An Introduction to Udev]<br />
* [http://vger.kernel.org/vger-lists.html#linux-hotplug Udev mailing list information]</div>Mayweedhttps://wiki.archlinux.org/index.php?title=GRUB&diff=168231GRUB2011-10-31T08:51:14Z<p>Mayweed: /* Make a backup of your precious data */</p>
<hr />
<div>[[Category:Boot loaders (English)]]<br />
{{i18n|GRUB2}}<br />
[[fr:GRUB2]]<br />
{{Article summary start}}<br />
{{Article summary text|Covers various aspects of the next generation of the GRand Unified Bootloader (GRUB2).}}<br />
{{Article summary heading|Overview}}<br />
{{Article summary text|{{Boot process overview}}}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|Burg}} - Burg is a brand-new boot loader based on GRUB2. It uses a new object format which allows it to be built in a wider range of OS, including Linux/Windows/OSX/Solaris/FreeBSD, etc. It also has a highly configurable menu system which works in both text and graphic mode. <br />
{{Article summary heading|Resources}}<br />
{{Article summary link|GNU GRUB -- GNU Project|http://www.gnu.org/software/grub/}}<br />
{{Article summary link|GNU GRUB Wiki|http://grub.enbug.org/}}{{Linkrot|2011|09|05}}<br />
{{Article summary end}}<br />
<br />
[http://www.gnu.org/software/grub/ GRUB2] is the next generation of the GRand Unified Bootloader (GRUB). GRUB2 is derived from [http://www.nongnu.org/pupa/ PUPA] which was a research project to investigate the next generation of GRUB. GRUB 2 has been rewritten from scratch to clean up everything and provide modularity and portability [http://www.gnu.org/software/grub/grub-faq.en.html#q1].<br />
<br />
Briefly, the ''bootloader'' is the first software program that runs when a computer starts. It is responsible for loading and transferring control to the Linux kernel. The kernel, in turn, initializes the rest of the operating system.<br />
<br />
== Preface ==<br />
<br />
Although, [[GRUB]] (i.e. version 0.9x) is the de facto standard bootloader of Linux, it is considered 'legacy' by upstream. It is being replaced by GRUB2 in many distributions. Upstream recommends GRUB2 >=1.99~rc2 over grub-legacy, even for current grub-legacy users.<br />
<br />
{{Note|grub2 from 1.99~rc2 and later supports btrfs as root (without a separate /boot filesystem).}}<br />
<br />
=== Notes for current GRUB Legacy users ===<br />
<br />
* There are differences in the commands of GRUB and GRUB2. Familiarize yourself with [http://www.gnu.org/software/grub/manual/grub.html#Commands GRUB2 commands] before proceeding (e.g. "find" has been replaced with "search").<br />
<br />
* GRUB2 is now ''modular'' and no longer requires "stage 1.5". As a result, the bootloader itself is limited -- modules are loaded from the hard drive as needed to expand functionality (e.g. for [[LVM]] or RAID support).<br />
<br />
* Device naming has changed between GRUB and GRUB2. Partitions are numbered from 1 instead of 0 while drives are still numbered from 0, and prefixed with partition-table type. For example, {{Filename|/dev/sda1}} would be referred to as {{Codeline|(hd0,msdos1)}} (for MBR) or {{Codeline|(hd0,gpt1)}} (for GPT) using GRUB2.<br />
<br />
=== Preliminary Requirements for GRUB2 ===<br />
<br />
==== BIOS systems ====<br />
<br />
===== [[GPT]] specific instructions =====<br />
<br />
GRUB2 in BIOS-GPT configuration requires a BIOS Boot Partition to embed its core.img in the absence of post-MBR gap in GPT partitioned systems (which is taken over by the GPT Primary Header and Primary Partition table). This partition is used by GRUB2 only in BIOS-GPT setups. No such partition type exists in case of MBR partitioning (at least not for GRUB2). This partition is also not required if the system is UEFI based, as no embedding of bootsectors takes place in that case. Syslinux does not require this partition.<br />
<br />
For a BIOS-GPT configuration, create a 2 MiB partition using cgdisk or GNU Parted with no filesystem. The location of the partition in the partition table does not matter but it should be within the first 2 TiB region of the disk. It is advisable to put it somewhere in the beginning of the disk before the /boot partition. Set the partition type to "EF02" in cgdisk or {{Codeline|set <BOOT_PART_NUM> bios_grub on}} in GNU Parted.<br />
<br />
{{Note|This partition should be created before grub_bios-install or grub-setup is run or before the '''Install Bootloader''' step of the Archlinux installer (if GRUB2 BIOS is selected as bootloader).}}<br />
<br />
===== [[MBR]] aka msdos partitioning specific instructions =====<br />
<br />
Usually the post-MBR gap (after the 512 byte MBR region and before the start of the 1st partition) in many MBR (or msdos disklabel) partitioned systems is 32 KiB when DOS compatibility cylinder alignment issues are satisfied in the partition table. However a post-MBR gap of about 1 to 2 MiB is recommended to provide sufficient room for embedding grub2's core.img ( https://bugs.archlinux.org/task/24103 ). It is advisable to use a partitioner which supports 1 MiB partition alignment to obtain this space as well as satisfy other non-512 byte sector issues (which are unrelated to embedding of core.img).<br />
<br />
If you do not dual-boot with MS Windows (any version) in BIOS systems, it is advisable to switch to GPT partitioning - [[GUID_Partition_Table#Convert_from_MBR_to_GPT_without_data_loss]]<br />
<br />
{{Note|Create the 2MiB partition mentioned above BEFORE you convert to GPT. If you do not, gparted will not resize your boot partition to allow its creation, and when you reboot grub2 will not know where to look.}}<br />
<br />
==== UEFI systems ====<br />
<br />
===== Create and Mount the UEFI SYSTEM PARTITION =====<br />
<br />
Follow [[Unified_Extensible_Firmware_Interface#Creating_a_UEFI_SYSTEM_PARTITION_in_Linux]] for instructions on creating a UEFI SYSTEM PARTITION. Then mount the UEFI SYSTEM PARTITION at {{Filename|/boot/efi}}. It should be FAT32 formatted and should be >=200 MiB in size. If you have mounted the UEFISYS partition in some other mountpoint, replace {{Filename|/boot/efi}} in the below instructions with that mountpoint:<br />
<br />
# mkdir -p /boot/efi<br />
# mount -t vfat <UEFISYS_PART_DEVICE> /boot/efi<br />
<br />
Create a <UEFI_SYSTEM_PARTITION>/efi directory if it does not exist:<br />
<br />
# mkdir -p /boot/efi/efi<br />
<br />
== Installation ==<br />
<br />
=== During Arch Linux installation ===<br />
<br />
* Skip the '''Install Bootloader''' step and exit the installer.<br />
* Configure the network:<br />
# aif -p partial-configure-network<br />
This will bring up a prompt; put in the network interface to use, (e.g., eth0) and use DHCP for easy configuration.<br />
* If you did not configure the installed system's {{Filename|/etc/resolv.conf}} file during installation (for instance, if you plan to let DHCP generate it later), you will need to copy the one generated by AIF when it configured the network:<br />
# cp /etc/resolv.conf /mnt/etc/resolv.conf<br />
* Load the dm-mod module (you might need grub2-bios; install the package if needed):<br />
# modprobe dm-mod<br />
{{Note|This is necessary at this point, and cannot be postponed after the chroot. If you try to use modprobe in a chroot environment that has a later kernel version from that of the installing device (at the time of writing, 2.6.33), modprobe will fail. This happens routinely using the Arch "net" installations.}}<br />
* From the installer's live shell, chroot to the installed system:<br />
# mount -o bind /dev /mnt/dev<br />
# chroot /mnt bash<br />
* Update pacman's database:<br />
# pacman-db-upgrade<br />
* Refresh the package list (with an extra -y flag to force a refresh of all package lists even if they appear to be up to date):<br />
# pacman -Syy<br />
* Install the GRUB2 package as mentioned in the section [[#From a running Arch Linux]]. Note that the dm-mod module has already been loaded, no need to do that again.<br />
<br />
=== From a running Arch Linux ===<br />
<br />
==== BIOS systems ====<br />
<br />
===== Make a backup of your precious data =====<br />
<br />
In general, a grub installation should run smoothly . Sometimes it could mess up your system. You're strongly advised to make a backup before installing grub2-bios.<br />
<br />
* copy grub modules and configuration<br />
<br />
# cp -a /boot/grub /path/to/backup/<br />
<br />
* backup the MBR and GRUB-Legacy stage 1.5<br />
<br />
# dd if=/dev/sdX of=/path/to/backup/first-sectors bs=512 count=63<br />
<br />
Replace /dev/sdaX with you disk path (mostly /dev/sda).<br />
<br />
{{Note|This command backs up the partition table too. Be careful while restoring if you've changed your partition setup in the meantime}}<br />
<br />
To backup only the MBR boot code use:<br />
<br />
# dd if=/dev/sdX of=/path/to/backup/mbr-boot-code bs=440 count=1<br />
<br />
You could now lightly remove {{Filename|/boot/grub}} with:<br />
<br />
# rm -rf /boot/grub<br />
<br />
and follow the instructions below. You know that if things get nasty, you could reboot your system thanks to an installation media and :<br />
<br />
* move old grub-legacy or grub2 files out of the way<br />
<br />
# mv /boot/grub /boot/grub.nonfunctional<br />
<br />
* copy grub back to /boot<br />
<br />
# cp -a /path/to/backup/grub /boot/<br />
<br />
* replace MBR and next 62 sectors of sda with backed up copy (DANGEROUS!)<br />
<br />
# dd if=/path/to/backup/first-sectors of=/dev/sdX bs=512 count=63<br />
<br />
{{Note|This command also restores the partition table. Be careful.}}<br />
<br />
To restore only the MBR boot code use:<br />
<br />
# dd if=/path/to/backup/mbr-boot-code of=/dev/sdX bs=440 count=1<br />
<br />
===== Before grub_bios-install =====<br />
<br />
The GRUB2 package can be installed with pacman (and will replace {{Package Official|grub}}, if it is installed):<br />
<br />
# pacman -S grub2-bios<br />
<br />
{{Note|Installing grub2-common (a dependency of grub2-bios) 1.99~rc1 or later, may take forever in some systems since the post_install script runs grub-mkconfig and this script does not provide the option <code>--no-floppy</code>. For more details search this option in the article.}}<br />
<br />
{{Note|Simply installing the package won't update the /boot/grub/core.img file and the grub2 modules in /boot/grub . You need to update the core.img file and the grub2 modules manually using grub_bios-install as explained below.}}<br />
<br />
Also load the device-mapper kernel module without which grub-probe does not reliably detect disks and partitions<br />
<br />
# modprobe dm-mod<br />
<br />
===== Run grub_bios-install =====<br />
<br />
There are 3 ways to install grub2 in BIOS booting - [[#Install_to_440-byte_MBR_boot_code_region]] (recommended) , [[#Install_to_Partition_or_Partitionless_Disk]] (not recommended) or [[#Generate_core.img_alone]] (safest method, but requires another BIOS bootloader like [[grub-legacy]] or [[syslinux]] to be installed to chainload {{Filename|/boot/grub/core.img}} ). For all the ways [[#Before_grub_bios-install]] step is needed.<br />
<br />
====== Install to 440-byte MBR boot code region ======<br />
<br />
To setup grub2-bios in the 440-byte Master Boot Record boot code region, populate the {{Filename|/boot/grub}} directory, generate the {{Filename|/boot/grub/core.img}} file, and embed it in the 32 KiB (minimum size - varies depending on partition alignment) post-MBR gap (MBR disks) or in BIOS Boot Partition (GPT disks), run<br />
<br />
# grub_bios-install --boot-directory=/boot --no-floppy --recheck /dev/sda<br />
<br />
where {{Filename|/dev/sda}} is the destination of the installation (in this case the MBR of the first SATA disk). If you use [[LVM]] for your {{Filename|/boot}}, you can install GRUB2 on multiple physical disks. <br />
<br />
The {{Codeline|--no-floppy}} tells grub2-bios utilities not to search for any floppy devices which reduces the overall execution time of grub_bios-install on many systems (it will also prevent the issue below from occuring). Otherwise you get an error like this<br />
<br />
grub-probe: error: Cannot get the real path of '/dev/fd0'<br />
Auto-detection of a filesystem module failed.<br />
Please specify the module with the option '--modules' explicitly.<br />
<br />
Follow [[#Generate_GRUB2_BIOS_Config_file]] or if that fails, convert your {{Filename|/boot/grub/menu.lst}} file to {{Filename|/boot/grub/grub.cfg}} using:<br />
<br />
# grub-menulst2cfg /boot/grub/menu.lst /boot/grub/grub.cfg<br />
<br />
For example:<br />
<br />
{{File|name=/boot/grub/menu.lst|content=<br />
default=0<br />
timeout=5<br />
<br />
title Arch Linux Stock Kernel<br />
root (hd0,0)<br />
kernel /vmlinuz-linux root=/dev/sda2 ro<br />
initrd /initramfs-linux.img<br />
<br />
title Arch Linux Stock Kernel Fallback<br />
root (hd0,0)<br />
kernel /vmlinuz-linux root=/dev/sda2 ro<br />
initrd /initramfs-linux-fallback.img<br />
}}<br />
<br />
{{File|name=/boot/grub/grub.cfg|content=<br />
set default='0'; if [ x"$default" = xsaved ]; then load_env; set default="$saved_entry"; fi<br />
set timeout=5<br />
<br />
menuentry 'Arch Linux Stock Kernel' {<br />
set root='(hd0,1)'; set legacy_hdbias='0'<br />
legacy_kernel '/vmlinuz-linux' '/vmlinuz-linux' 'root=/dev/sda2' 'ro'<br />
legacy_initrd '/initramfs-linux.img' '/initramfs-linux.img'<br />
<br />
}<br />
<br />
menuentry 'Arch Linux Stock Kernel Fallback' {<br />
set root='(hd0,1)'; set legacy_hdbias='0'<br />
legacy_kernel '/vmlinuz-linux' '/vmlinuz-linux' 'root=/dev/sda2' 'ro'<br />
legacy_initrd '/initramfs-linux-fallback.img' '/initramfs-linux-fallback.img'<br />
}<br />
}}<br />
<br />
<br />
If you forgot to create a GRUB2 {{Filename|/boot/grub/grub.cfg}} configfile and simply rebooted into GRUB2 Command Shell, type:<br />
<br />
sh:grub> insmod legacycfg<br />
sh:grub> legacy_configfile ${prefix}/menu.lst<br />
<br />
Boot into Arch and re-create the proper GRUB2 {{Filename|/boot/grub/grub.cfg}} configfile.<br />
<br />
{{Note|This option works only in BIOS systems, not in UEFI systems.}}<br />
<br />
====== Install to Partition or Partitionless Disk ======<br />
<br />
{{Note|grub2-bios (any version - including upstream bzr repo) does not encourage installation to a partition boot sector or a partitionless disk like grub-legacy or syslinux does. Neither do the Arch devs.}}<br />
<br />
To setup grub2-bios to a partition boot sector, to a partitionless disk (also called superfloppy) or to a floppy disk, run (using for example /dev/sda1 as the /boot partition)<br />
<br />
# chattr -i /boot/grub/core.img<br />
# grub_bios-install --boot-directory=/boot --no-floppy --recheck --force /dev/sda1<br />
# chattr +i /boot/grub/core.img<br />
<br />
You need to use the {{Codeline|--force}} option to allow usage of blocklists and should not use <code>--grub-setup=/bin/true</code> (which is similar to simply generating core.img).<br />
<br />
grub_bios-install will give out warnings like which should give you the idea of what might go wrong with this approach.<br />
<br />
/sbin/grub-setup: warn: Attempting to install GRUB to a partitionless disk or to a partition. This is a BAD idea.<br />
/sbin/grub-setup: warn: Embedding is not possible. GRUB can only be installed in this setup by using blocklists. <br />
However, blocklists are UNRELIABLE and their use is discouraged.<br />
<br />
Without {{Codeline|--force}} you may get the below error and grub-setup will not setup its boot code in the partition boot sector.<br />
<br />
/sbin/grub-setup: error: will not proceed with blocklists<br />
<br />
With {{Codeline|--force}} you should get<br />
<br />
Installation finished. No error reported.<br />
<br />
The reason why grub-setup does not by default allow this is because in case of partition or a partitionless disk is that grub2-bios relies on embedded blocklists in the partition bootsector to locate the {{Filename|/boot/grub/core.img}} file and the prefix dir {{Filename|/boot/grub}} . The sector locations of {{Filename|core.img}} may change whenever the filesystem in the partition is being altered (files copied, deleted etc.). For more info see https://bugzilla.redhat.com/show_bug.cgi?id=728742 and https://bugzilla.redhat.com/show_bug.cgi?id=730915 .<br />
<br />
The workaround for this is to set the immutable flag on {{Filename|/boot/grub/core.img}} (using chattr command as mentioned above) so that the sector locations of the {{Filename|core.img}} file in the disk is not altered. The immutable flag on {{Filename|/boot/grub/core.img}} needs to be set only if grub2-bios is installed to a partition boot sector or a partitionless disk, not in case of installtion to MBR or simple generation of {{Filename|core.img}} without embedding any bootsector (mentioned above). <br />
<br />
====== Generate core.img alone ======<br />
<br />
To populate the {{Filename|/boot/grub}} directory and generate a {{Filename|/boot/grub/core.img}} file WITHOUT embedding any grub2-bios bootsector code in the MBR, post-MBR region, or the partition bootsector, add <code>--grub-setup=/bin/true</code> to grub_bios-install:<br />
<br />
# grub_bios-install --grub-setup=/bin/true --boot-directory=/boot --no-floppy --recheck /dev/sda<br />
<br />
You can then chainload grub2's core.img from grub-legacy or syslinux as a Linux kernel or a multiboot kernel.<br />
<br />
===== After grub_bios-install =====<br />
<br />
====== Generate GRUB2 BIOS Config file ======<br />
<br />
Finally, generate a configuration for grub2 (this is explained in greater detail in the Configuration section):<br />
<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
If grub2 complains about "no suitable mode found" while booting, go to [[#Correct_GRUB2_No_Suitable_Mode_Found_Error]] .<br />
<br />
===== Multiboot in BIOS =====<br />
<br />
====== Boot Microsoft Windows installed in BIOS-MBR mode ======<br />
<br />
{{Note|GRUB2 supports booting {{Filename|bootmgr}} directly and chainload of partition boot sector is no longer required to boot Windows in a BIOS-MBR setup.}}<br />
<br />
Find the UUID of the NTFS filesystem of the Windows's SYSTEM PARTITION where the bootmgr and its files reside. For example, if Windows {{Filename|bootmgr}} exists at {{Filename|/media/Windows/bootmgr}}:<br />
<br />
# grub-probe --target=fs_uuid /media/Windows/bootmgr<br />
69B235F6749E84CE<br />
<br />
Then, add the below code to {{Filename|/boot/grub/grub.cfg}} to chainload Windows (Vista, 7 or 8) installed in BIOS-MBR mode :<br />
<br />
menuentry "Microsoft Windows 7 BIOS-MBR" {<br />
insmod part_msdos<br />
insmod ntfs<br />
insmod search_fs_uuid<br />
insmod ntldr <br />
search --fs-uuid --no-floppy --set=root 69B235F6749E84CE<br />
ntldr (${root})/bootmgr<br />
}<br />
<br />
For Windows XP<br />
<br />
menuentry "Microsoft Windows XP" {<br />
insmod part_msdos<br />
insmod ntfs<br />
insmod search_fs_uuid<br />
insmod ntldr <br />
search --fs-uuid --no-floppy --set=root 69B235F6749E84CE<br />
ntldr (${root})/ntldr<br />
}<br />
<br />
==== [[UEFI]] systems ====<br />
<br />
===== Before grub_efi_${UEFI_ARCH}-install =====<br />
<br />
{{Note|Unless specified as EFI 1.x , EFI and UEFI terms are used interchangeably to denote UEFI 2.x firmware. Also unless stated explicitely, the instructions are general and not Mac specific. Some of them may not work or may be different in Macs. Apple's EFI implementation is neither a EFI 1.x version nor UEFI 2.x version but mixes up both. This kind of firmware does not fall under any one UEFI Specification version and is therefore not a standard UEFI firmware.}}<br />
<br />
GRUB2 UEFI bootloader is available in Arch Linux only from version 1.99~rc1 . To install, first [https://wiki.archlinux.org/index.php/Unified_Extensible_Firmware_Interface#Detecting_UEFI_Firmware_Arch Detect which UEFI firmware arch] you have (either x86_64 or i386).<br />
<br />
Depending on that, install the appropriate package<br />
<br />
For 64-bit aka x86_64 UEFI firmware:<br />
# pacman -S grub2-efi-x86_64<br />
<br />
For 32-bit aka i386 UEFI firmware:<br />
# pacman -S grub2-efi-i386<br />
<br />
{{Note|Installing grub2-common (a dependency of grub2-bios) 1.99~rc1 or later, may take forever in some systems since the post_install script runs grub-mkconfig and this script does not provide the option <code>--no-floppy</code>. For more details search this option in the article.}}<br />
<br />
{{Note|Simply installing the package won't update the grub.efi file and the grub2 modules in the UEFI System Partition . You need to update the grub.efi file and the grub2 modules in the UEFI System Partition manually using grub_efi_${UEFI_ARCH}-install as explained below.}}<br />
<br />
Also load the device-mapper kernel module without which grub-probe does not reliably detect disks and partitions<br />
<br />
# modprobe dm-mod<br />
<br />
===== Run grub_efi_${UEFI_ARCH}-install =====<br />
<br />
====== Install to UEFI SYSTEM PARTITION ======<br />
<br />
{{Note|The below commands assume you are using {{Codeline|grub2-efi-x86_64}} (for {{Codeline|grub2-efi-i386}} replace {{Codeline|x86_64}} with {{Codeline|i386}} in the below commands).}}<br />
<br />
# grub_efi_x86_64-install --root-directory=/boot/efi --boot-directory=/boot/efi/efi --bootloader-id=grub --no-floppy --recheck<br />
<br />
The {{Codeline|grub_efi_x86_64-install}} automatically generates a {{Filename|grub.efi}} while setting up the {{Filename|/boot/efi/efi/grub/}} directory.<br />
<br />
If you notice carefully, there is no <device_path> option (Eg: {{Filename|/dev/sda}}) at the end of the {{Codeline|grub_efi_x86_64-install}} command unlike the case of setting up grub2 for BIOS systems. Any <device_path> provided will be ignored by the install script as UEFI bootloaders do not use MBR or Partition boot sectors at all.<br />
<br />
You may now be able to UEFI boot your system by creating a grub.cfg file using grub-mkconfig and copying /boot/efi/efi/grub/grub.efi to /boot/efi/efi/boot/bootx64.efi.<br />
<br />
===== After grub_efi_${UEFI_ARCH}-install =====<br />
<br />
====== Launch GRUB2 as default in non-Mac UEFI systems ======<br />
<br />
{{Note|The below steps will not work if the system has been booted in BIOS mode and will not work if the UEFI processor architecture does not match the kernel one, i.e. x86_64 UEFI + ix86 32-bit Kernel and vice-versa config will not work.}}<br />
<br />
grub_efi_${UEFI_ARCH}-install will ensure {{Filename|/boot/efi/efi/grub/grub.efi}} is launched by default if it detects {{Codeline|efibootmgr}} and if it is able to access UEFI Runtime Services. {{Codeline|efibootmgr}} command will work only if you have booted the system in UEFI mode itself, since it '''requires access to UEFI Runtime Variables''' which are '''available only in UEFI boot mode''' (with "noefi" kernel parameter NOT being used). Initially the user is required to manually launch {{Filename|/boot/efi/efi/grub/grub.efi}} from the firmware itself (using maybe the UEFI Shell) if grub2-efi was installed in BIOS mode. Then {{Codeline|efibootmgr}} should be run to make grub2 as the default entry in the UEFI Boot Manager<br />
<br />
First boot into UEFI mode manually either using the firmware boot menu, UEFI shell, or using any UEFI capable bootable iso (Archboot or Ubuntu non-Mac iso). Use grub probe to determine the device path of your EFI System Partition:<br />
# grub-probe --target=device /boot/efi/efi/grub/grub.efi<br />
<br />
It should give something like {{Filename|/dev/sda1}} (used as example in the remaining steps). Load 'efivars' kernel module:<br />
# modprobe efivars<br />
<br />
If you get '''no such device found''' error for this command, that means you have not booted in UEFI mode or due to some reason the kernel is unable to access UEFI Runtime Variables.<br />
<br />
Verify whether there are files in ''/sys/firmware/efi/vars/'' directory. This directory and its contents are created by "efivars" kernel module and it will exist only if you have booted in UEFI mode without the "noefi" kernel parameter.<br />
<br />
# ls -1 /sys/firmware/efi/vars/<br />
<br />
Sample output (x86_64-UEFI 2.3.1 in x86_64 Kernel:<br />
<br />
# ls -1 /sys/firmware/efi/vars/<br />
Boot0000-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootCurrent-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootOptionSupport-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootOrder-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConIn-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConInDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConOut-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConOutDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ErrOutDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
Lang-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
LangCodes-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
MTC-eb704011-1402-11d3-8e77-00a0c969723b/<br />
MemoryTypeInformation-4c19049f-4137-4dd3-9c10-8b97a83ffdfa/<br />
PlatformLang-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
PlatformLangCodes-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
RTC-378d7b65-8da9-4773-b6e4-a47826a833e1/<br />
del_var<br />
new_var<br />
<br />
If ''/sys/firmware/efi/vars/'' directory is empty or does not exist, then {{Codeline|efibootmgr}} command will not work. If you are unable to make the ISO/CD/DVD/USB boot in UEFI mode try https://gitorious.org/tianocore_uefi_duet_builds/pages/Linux_Windows_BIOS_UEFI_boot_USB .<br />
<br />
If ''/sys/firmware/efi/vars/'' directory (along with the exists then run {{Codeline|efibootmgr}} and reboot:<br />
<br />
# efibootmgr --create --gpt --disk /dev/sda --part 1 --write-signature --label "GRUB2" --loader "\\EFI\\grub\\grub.efi"<br />
<br />
In the above command, {{Filename|/boot/efi/efi/grub/grub/efi}} can be split up as {{Filename|/boot/efi}} and {{Filename|/efi/grub/grub.efi}}, which translates to {{Filename|(/dev/sda)}} -> partition 1 -> {{Filename|\\EFI\\grub\\grub.efi}}. <br />
<br />
FAT32 filesystem is case-insensitive since it does not use UTF-8 encoding by default. In that case the firmware uses capital 'EFI' instead of small 'efi', therefore using {{Filename|\\EFI\\grub\\grub.efi}} or {{Filename|\\efi\\grub\\grub.efi}} does not matter (this will change if the filesystem encoding is UTF-8). UEFI uses backward slash as path separatoir (similar to Windows paths). In the above command "double" backward slashes are used instead of single ones, since a backward slash is used as a escape character by sh shells, the first backward slash escapes the second one so that the path {{Filename|\EFI\grub\grub.efi}} is passed to {{Codeline|efibootmgr}}.<br />
<br />
The 'label' is the name of the menu entry shown in the UEFI boot menu. This name is user's choice and does not affect the booting of the system. More info can be obtained from [http://linux.dell.com/cgi-bin/gitweb/gitweb.cgi?p=efibootmgr.git;a=blob_plain;f=README;hb=HEAD efibootmgr GIT README]<br />
<br />
If you have problems running GRUB2 in UEFI mode you can try the following (worked on an ASUS Z68 mainboard):<br />
<br />
# cp /boot/efi/efi/grub/grub.efi /boot/efi/shellx64.efi<br />
<br />
or<br />
<br />
# cp /boot/efi/efi/grub/grub.efi /boot/efi/efi/shellx64.efi<br />
or<br />
<br />
# cp /boot/efi/efi/grub/grub.efi /boot/efi/efi/shell/shellx64.efi<br />
<br />
After this launch the UEFI Shell from the UEFI setup/menu (in ASUS UEFI BIOS, switch to advanced mode, press Exit in the top right corner and choose "Launch EFI shell from filesystem device"). The grub2 menu will show up and you can boot into your system. Afterwards you can use efibootmgr to setup a menu entry (see above).<br />
<br />
====== Launch GRUB2 as default in Apple Mac EFI systems ======<br />
<br />
{{Note|Using {{Filename|efibootmgr}} in Apple Macs will brick the firmware and may need reflash of the motherboard ROM. There have been bug reports regarding this in Ubuntu/Launchpad bug tracker. Use bless command alone in case of Macs}}<br />
<br />
Use bless command from within Mac OS X to setup {{Filename|grub.efi}} as the default boot option. More info at https://help.ubuntu.com/community/UEFIBooting#Apple_Mac_EFI_systems_.28both_EFI_architecture.29 .<br />
<br />
====== Generate GRUB2 UEFI Config file ======<br />
<br />
Finally, generate a configuration for grub2 (this is explained in greater detail in the Configuration section):<br />
<br />
# grub-mkconfig -o /boot/efi/efi/grub/grub.cfg<br />
<br />
If grub2-uefi complains about "no suitable mode found" while booting, go to [[#Correct_GRUB2_No_Suitable_Mode_Found_Error]] .<br />
<br />
===== Generate a custom GRUB2 UEFI Application =====<br />
<br />
If you want, you can create a custom {{Filename|grub_custom.efi}} app using:<br />
# grub-mkimage -d /usr/lib/grub/x86_64-efi -O x86_64-efi -p "" -o /boot/efi/efi/grub/grub_custom.efi <GRUB2_Modules_to_be_included><br />
<br />
{{Note|The '''-p''' option is important for creating a portable {{Filename|grub_custom.efi}} app.}}<br />
<br />
There is no file-size restriction on {{Filename|grub_custom.efi}} either due to GRUB2 or due to the UEFI firmware. Therefore you can include any number of modules you want.<br />
<br />
A "{{Filename|grub.cfg}}" created for BIOS based GRUB2 will be sufficient for the UEFI GRUB2 as long as all the paths in the config are absolute paths. The {{Filename|grub.cfg}} file should exist in the same directory as {{Filename|grub.efi}} or {{Filename|grub_custom.efi}}.<br />
<br />
The {{Filename|grub.efi}} UEFI application can be launched using the firmware's "Boot Manager", "Boot from file" option or using the [https://wiki.archlinux.org/index.php/UEFI#UEFI_Shell UEFI Shell].<br />
<br />
Alternatively, you can also setup {{Filename|/boot/efi/efi/grub}} directory by copying all the files in {{Filename|/usr/lib/grub/x86_64-efi}} to {{Filename|/boot/efi/efi/grub}} and using the above grub-mkimage command to create a {{Filename|grub_custom.efi}} application. Just make sure you have the required modules embedded in {{Filename|grub_custom.efi}} to enable it to access the EFI SYSTEM PARTITION.<br />
<br />
A basic {{Filename|grub_custom.efi}} can be generated using the following command:<br />
# sudo grub-mkimage -d /usr/lib/grub/x86_64-efi -O x86_64-efi -p "" -o /boot/efi/efi/grub/grub_custom.efi part_gpt fat iso9660 udf normal chain linux \<br />
ls search search_fs_file search_fs_uuid search_label help boot configfile echo efi_gop<br />
<br />
===== Multiboot in UEFI =====<br />
<br />
====== Chainload Microsoft Windows x86_64 UEFI-GPT ======<br />
<br />
Find the UUID of the FAT32 filesystem in the UEFI SYSTEM PARTITION where the Windows UEFI Bootloader files reside. For example, if Windows {{Filename|bootmgfw.efi}} exists at {{Filename|/boot/efi/efi/Microsoft/Boot/bootmgfw.efi}} (ignore the upper-lower case differences since that is immaterial in FAT filesystem):<br />
<br />
# grub-probe --target=fs_uuid /boot/efi/efi/Microsoft/Boot/bootmgfw.efi<br />
1ce5-7f28<br />
<br />
Then, add this code to {{Filename|/boot/efi/efi/grub/grub.cfg}} to chainload Windows x86_64 (Vista SP1+, 7 or 8) installed in UEFI-GPT mode :<br />
<br />
menuentry "Microsoft Windows x86_64 UEFI-GPT" {<br />
insmod part_gpt<br />
insmod fat<br />
insmod search_fs_uuid<br />
insmod chain<br />
search --fs-uuid --no-floppy --set=root 1ce5-7f28<br />
chainloader (${root})/efi/Microsoft/Boot/bootmgfw.efi<br />
}<br />
<br />
== Manual Compilation ==<br />
<br />
=== For BIOS Systems ===<br />
<br />
GRUB2 for BIOS systems should be compiled as follows:<br />
<pre><br />
./autogen.sh<br />
<br />
./configure --with-platform=pc --prefix=/usr<br />
<br />
make<br />
<br />
make install<br />
</pre><br />
<br />
The <code>--with-platform=pc</code> generates grub2 for bios alone irrespective of the firmware of the build system.<br />
<br />
=== For UEFI Systems ===<br />
<br />
First [https://wiki.archlinux.org/index.php/Unified_Extensible_Firmware_Interface#Detecting_UEFI_Firmware_Arch Detect which UEFI Firmware arch] you have and then follow the compile instructions below:<br />
<pre><br />
./autogen.sh<br />
<br />
./configure --with-platform=efi --target=TARGET_UEFI_ARCH --prefix=/usr<br />
<br />
make<br />
<br />
make install<br />
</pre><br />
<br />
The "--target" option denotes the UEFI firmware arch. for which grub2 should be compiled, not the architecture of the linux kernel grub2 may boot. <br />
<br />
It is possible to use UEFI 64-bit firmware + GRUB2 as x86_64-EFI app loading a i686 linux kernel, as long as the kernel does not try to access UEFI Runtime Services. Vice-versa situation is also possible. But a x86_64 UEFI firmware cannot launch GRUB2 i386-efi app (unlike x86_64 Operating Systems), and a i386 UEFI firmware will not launch GRUB2 {{Codeline|x86_64-efi}} app. It is important to compile GRUB2 to match the architecture of the UEFI firmware.<br />
<br />
== Configuration ==<br />
<br />
The configuration files are {{Filename|/etc/default/grub}} and {{Filename|/etc/grub.d/*}}. These files are used to generate the {{Filename|/boot/grub/grub.cfg}} file. You can also choose to manually edit {{Filename|grub.cfg}}.<br />
<br />
=== grub-mkconfig ===<br />
<br />
The grub-mkconfig script can be used to generate a {{Filename|grub.cfg}} file. By default the script outputs to stdout. Note that gettext ― an optional dependency of the GRUB2 package ― is required by the grub-mkconfig script. To generate a {{Filename|grub.cfg}} file run the command:<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
Note that grub-mkconfig probably has your grub directory hardcoded to /boot/grub, which is probably wrong if you're using UEFI. Either mount your efi grub directory at /boot/grub or edit the script.<br />
<br />
=== grub.cfg ===<br />
<br />
A basic grub file uses the following options<br />
* {{Codeline|(hdX,Y)}} is the partition {{Codeline|Y}} on disk {{Codeline|X}}, partition numbers starting at 1, disk numbers starting at 0<br />
* {{Codeline|1=set default=N}} is the default boot entry that is chosen after timeout for user action<br />
* {{Codeline|1=set timeout=M}} is the time {{Codeline|M}} to wait in seconds for a user selection before default is booted<br />
* {{Codeline|<nowiki>menuentry "title" {entry options}</nowiki>}} is a boot entry titled {{Codeline|title}}<br />
* {{Codeline|1=set root=(hdX,Y)}} sets the boot partition, where the kernel and GRUB modules are stored (boot need not be a separate partition, and may simply be a directory under the "root" partition ({{Filename|/}})<br />
<br />
An example configuration:<br />
<br />
{{File<br />
|name=/boot/grub/grub.cfg<br />
|content=<nowiki><br />
# Config file for GRUB2 - The GNU GRand Unified Bootloader<br />
# /boot/grub/grub.cfg<br />
<br />
# DEVICE NAME CONVERSIONS<br />
#<br />
# Linux Grub<br />
# -------------------------<br />
# /dev/fd0 (fd0)<br />
# /dev/sda (hd0)<br />
# /dev/sdb2 (hd1,2)<br />
# /dev/sda3 (hd0,3)<br />
#<br />
<br />
# Timeout for menu<br />
set timeout=5<br />
<br />
# Set default boot entry as Entry 0<br />
set default=0<br />
<br />
# (0) Arch Linux<br />
menuentry "Arch Linux" {<br />
set root=(hd0,1)<br />
linux /vmlinuz-linux root=/dev/sda3 ro<br />
initrd /initramfs-linux.img<br />
}<br />
<br />
## (1) Windows<br />
#menuentry "Windows" {<br />
#set root=(hd0,3)<br />
#chainloader +1<br />
#}<br />
</nowiki>}}<br />
<br />
=== Dual-booting ===<br />
<br />
''NOTE: If you want GRUB2 to automatically search for other systems, for example as in Ubuntu. Then you may need to download {{Package AUR|os-prober}} from the [[AUR]].''<br />
<br />
==== Using grub-mkconfig ====<br />
The best way to add other entries is editing the {{Filename|/etc/grub.d/40_custom}}. The entries in this file will be automatically added when running '''grub-mkconfig'''.<br />
After adding the new lines, run:<br />
# grub-mkconfig -o /boot/grub/grub.cfg <br />
to generate an updated {{Filename|grub.cfg}}.<br />
<br />
===== With GNU/Linux =====<br />
<br />
Assuming that the other distro is on partition {{Filename|sda2}}:<br />
<br />
menuentry "Other Linux" {<br />
set root=(hd0,2)<br />
linux /boot/vmlinuz (add other options here as required)<br />
initrd /boot/initrd.img (if the other kernel uses/needs one)<br />
}<br />
<br />
===== With Windows =====<br />
<br />
This assumes that your Windows partition is {{Filename|sda3}}.<br />
<br />
# (2) Windows XP<br />
menuentry "Windows XP" {<br />
set root=(hd0,3)<br />
chainloader (hd0,3)+1<br />
}<br />
<br />
If the windows bootloader is on an entirely different harddrive than grub, it may be necessary to trick Windows into believing that it is in fact the first harddrive. This was possible in the old grub with {{Codeline|map}} and is now done with {{Codeline|drivemap}}. Assume grub is on {{Filename|hd0}} and windows on {{Filename|hd2}}, you need to add the following after {{Codeline|set root}}:<br />
<br />
drivemap -s hd0 hd2<br />
<br />
==== With Windows via EasyBCD and NeoGRUB ====<br />
<br />
Since EasyBCD's NeoGRUB currently does not understand the GRUB2 menu format, chainload to it by replacing the contents of your {{Filename|C:\NST\menu.lst}} file with lines similar to the following:<br />
<br />
default 0<br />
timeout 1<br />
<br />
title Chainload into GRUB v2<br />
root (hd0,7)<br />
kernel /boot/grub/core.img<br />
<br />
===Visual Configuration===<br />
<br />
In GRUB2 it is possible, by default, to change the look of the menu.<br />
<br />
====Background image and bitmap fonts====<br />
<br />
GRUB2 comes with support for background images and bitmap fonts in pf2 format. The unifont font is included in the grub2 package under the filename {{Filename|unicode.pf2}}, or, as only ascii characters under the name {{Filename|ascii.pf2}}. Image formats supported include tga, png and jpeg, providing the correct modules are loaded. The maximum supported resolution depends on your hardware. There are two ways of setting a {{Filename|tga}} file as background. Two sample configurations are shown below.<br />
<br />
Edit {{Filename|/etc/default/grub}} like this:<br />
GRUB_GFXMODE=1024x768x32<br />
GRUB_GFXPAYLOAD_LINUX=keep<br />
GRUB_BACKGROUND="/boot/grub/archlinux.tga"<br />
#GRUB_THEME="/path/to/gfxtheme"<br />
<br />
(archlinux.tga is a placeholder; put your file name there)<br />
<br />
To generate the changes, run: <br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
{{Note|If this example does not work for you try to replace {{Codeline|1=gfxmode="1024x768x32"}} by {{Codeline|1=vbemode="0x105"}}.}}<br />
{{Note|To show all the modes you can use {{Codeline|1=# hwinfo --framebuffer}} (hwinfo is available in [community]), while at grub2 prompt you can use the {{Codeline|1=vbeinfo}} command.}}<br />
{{Note|If you have installed Grub on a separate partition, {{Filename|/boot/grub/archlinux.tga}} becomes {{Filename|/grub/archlinux.tga}}.}}<br />
<br />
====Menu colors====<br />
<br />
As in Grub (0.9x), you can change the menu colors in Grub2. The available colors for GRUB2 are at http://www.gnu.org/software/grub/manual/html_node/Theme-file-format.html#Theme-file-format . <br />
Here is an example:<br />
<br />
Edit {{Filename|/etc/default/grub}}:<br />
GRUB_COLOR_NORMAL="light-blue/black"<br />
GRUB_COLOR_HIGHLIGHT="light-cyan/blue"<br />
<br />
Generate the changes:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
====Hidden menu====<br />
<br />
One of the unique features of Grub2 is hiding/skipping the menu and showing it by holding "Shift" when needed. You can also adjust whether you want to see the timeout counter.<br />
<br />
Edit {{Filename|/etc/default/grub}} as you wish. Here is an example where the comments from the beginning of the two lines have been removed to enable the feature, the timeout has been set to five seconds and to be shown to the user:<br />
GRUB_HIDDEN_TIMEOUT=5<br />
GRUB_HIDDEN_TIMEOUT_QUIET=false<br />
<br />
and run:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
====Setting the framebuffer resolution ====<br />
<br />
Grub2 can set the framebuffer for both grub2 itself and the kernel. The old ''vga='' way is deprecated. The preferred method is editing {{Filename|/etc/default/grub}} as the following sample:<br />
<br />
GRUB_GFXMODE=1024x768x32<br />
GRUB_GFXPAYLOAD_LINUX=keep<br />
<br />
To generate the changes, run: <br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
The {{Codeline|gfxpayload}} property will make sure the kernel keeps the resolution.<br />
<br />
If this method does not work for you, the deprecated <code>vga=</code> method will still work. Just<br />
add it next to the <code>"GRUB_CMDLINE_LINUX_DEFAULT="</code> line in {{Filename|/etc/default/grub}}<br />
for eg: <code>"GRUB_CMDLINE_LINUX_DEFAULT="quiet splash vga=792"</code> will give you a {{Codeline|1024x768}} resolution.<br />
<br />
You can choose one of these resolutions: {{Codeline|640×480}}, {{Codeline|800×600}}, {{Codeline|1024×768}}, {{Codeline|1280×1024}}, {{Codeline|1600×1200}}<br />
<br />
=== Other Options ===<br />
<br />
==== LVM ====<br />
<br />
If you use [[LVM]] for your {{Filename|/boot}}, add the following before menuentry lines:<br />
<br />
insmod lvm<br />
<br />
and specify your root in the menuentry as:<br />
<br />
set root=(''lvm_group_name''-''lvm_logical_boot_partition_name'')<br />
<br />
Example:<br />
<br />
# (0) Arch Linux<br />
menuentry "Arch Linux" {<br />
insmod lvm<br />
set root=(VolumeGroup-lv_boot)<br />
# you can only set following two lines<br />
linux /vmlinuz-linux root=/dev/mapper/VolumeGroup-root ro<br />
initrd /initramfs-linux.img<br />
}<br />
<br />
==== Raid ====<br />
<br />
Grub2 provides convenient handling of raid-volumes. You need to add:<br />
insmod raid<br />
<br />
which allows you to address the volume natively. E.g. {{Filename|/dev/md0}} becomes:<br />
set root=(md0)<br />
<br />
whereas a partitioned raid-volume (e.g. {{Filename|/dev/md0p1}}) becomes:<br />
set root=(md0,1)<br />
<br />
==== Persistent block device naming ====<br />
You can use UUIDs to detect partitions instead of the "old" {{Filename|/dev/sd*}} and {{Filename|/dev/hd*}} scheming. It has the advantage of detecting partitions by their unique UUIDs, which is needed by some people booting with complicated partition setups.<br />
<br />
UUIDs are used by default in the recent versions of grub2 - there is no downside in it anyway except that you need to re-generate the {{Filename|grub.cfg}} file every time you resize or reformat your partitions. Remember this when modifying partitions with Live-CD.<br />
<br />
The recent versions of grub2 use UUIDs by default. You can re-enable the use of UUIDS by simply commenting the UUID line (this is also what it looks like by default):<br />
#GRUB_DISABLE_LINUX_UUID=true<br />
you can also just set the value as {{Codeline|false}} as shown here:<br />
GRUB_DISABLE_LINUX_UUID=false<br />
<br />
Either way, do not forget to generate the changes:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
==== Using Labels ====<br />
<br />
It is possible to use labels, human-readable strings attached to filesystems, by using the {{Codeline|--label}} option to {{Codeline|search}}. First of all, label your existing partition:<br />
# tune2fs -L a <LABEL> <PARTITION><br />
<br />
Then, add an entry using labels. An example of this:<br />
<br />
menuentry "Arch Linux, session texte" {<br />
search --label --no-floppy --set=root archroot<br />
linux /boot/vmlinuz-linux root=/dev/disk/by-label/archroot ro<br />
initrd /boot/initramfs-linux.img<br />
}<br />
<br />
==== Recall previous entry ====<br />
<br />
Grub2 can remember the last entry you booted from and use this as the default entry to boot from next time. This is useful if you have multiple kernels (i.e., the current Arch one and the LTS kernel as a fallback option) or operating systems. To do this, edit {{Filename|/etc/default/grub}} and change the setting of {{Codeline|GRUB_DEFAULT}}:<br />
<br />
GRUB_DEFAULT=saved<br />
<br />
This ensures that grub will default to the saved entry. To enable saving the selected entry, add the following line to {{Filename|/etc/default/grub}}:<br />
<br />
GRUB_SAVEDEFAULT=true<br />
<br />
Remember to regenerate your configuration file.<br />
<br />
==== Security ====<br />
<br />
If you want to secure GRUB2 so it is not possible for anyone to change boot parameters or use the command line, you can add a user/password combination to GRUB2's configuration files. To do this, run the command {{Codeline|grub-mkpasswd_pbkdf2}}. Enter a password and confirm it. The output will look like this:<br />
<br />
<pre style='overflow:auto'><br />
Your PBKDF2 is grub.pbkdf2.sha512.10000.C8ABD3E93C4DFC83138B0C7A3D719BC650E6234310DA069E6FDB0DD4156313DA3D0D9BFFC2846C21D5A2DDA515114CF6378F8A064C94198D0618E70D23717E82.509BFA8A4217EAD0B33C87432524C0B6B64B34FBAD22D3E6E6874D9B101996C5F98AB1746FE7C7199147ECF4ABD8661C222EEEDB7D14A843261FFF2C07B1269A</pre>Then, add the following to {{Filename|/etc/grub.d/00_header}}:<br />
<pre>cat << EOF<br />
<br />
set superusers="username"<br />
password_pbkdf2 username <password><br />
<br />
EOF</pre><br />
where <password> is the string generated by {{Codeline|grub-mkpasswd_pbkdf2}}.<br />
<br />
Regenerate your configuration file. Your GRUB2 command line and boot parameters are now protected.<br />
<br />
=== Booting an Ubuntu ISO Image from the GRUB2 Screen ===<br />
<br />
Edit {{Filename|/etc/grub.d/40_custom}} to add an entry pointing to an Ubuntu iso:<br />
<br />
menuentry "ubuntu-11.04-desktop-amd64.iso" {<br />
set isofile="/path/to/ubuntu-11.04-desktop-amd64.iso"<br />
loopback loop (hdX,Y)$isofile<br />
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile quiet noeject noprompt splash --<br />
initrd (loop)/casper/initrd.lz<br />
}<br />
<br />
Be sure to adjust the "hdX,Y" in the third line to point to the correct disk/partition number of the isofile. When finished, update grub2's configuration file via:<br />
<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
== Using the command shell ==<br />
<br />
Since the MBR is too small to store all GRUB2 modules, only the menu and a few basic commands reside there. The majority of GRUB2 functionality remains in modules in {{Filename|/boot/grub}}, which are inserted as needed. In error conditions (e.g. if the partition layout changes) GRUB2 may fail to boot. When this happens, a command shell may appear.<br />
<br />
GRUB2 offers multiple shells/prompts. If there is a problem reading the menu but the bootloader is able to find the disk, you will likely be dropped to the "normal" shell:<br />
sh:grub><br />
<br />
If there is a more serious problem (e.g. GRUB cannot find required files), you may instead be dropped to the "rescue" shell:<br />
grub rescue><br />
<br />
The rescue shell is a restricted subset of the normal shell, offering much less functionality. If dumped to the rescue shell, first try inserting the "normal" module, then starting the "normal" shell:<br />
grub rescue> set prefix=(hdX,Y)/boot/grub<br />
grub rescue> insmod (hdX,Y)/boot/grub/normal.mod<br />
rescue:grub> normal<br />
<br />
=== Pager support ===<br />
<br />
GRUB2 supports pager for reading commands that provide long output (like the help command). This works only in normal shell mode and not in rescue mode. To enable pager, in GRUB2 command shell type:<br />
sh:grub> set pager=1<br />
<br />
== GUI configuration tools ==<br />
<br />
Following package may be installed from [[AUR]]<br />
* [http://kde-apps.org/content/show.php?content=139643 grub2-editor] (requires kdelibs)<br />
*:A KDE4 control module for configuring the GRUB2 bootloader<br />
* [http://kde-apps.org/content/show.php?content=137886 kcm-grub2] (requires kdelibs python2-qt kdebindings-python)<br />
*:This Kcm module manages the most common settings of Grub2.<br />
* [http://sourceforge.net/projects/startup-manager/ startupmanager] (requires gnome-python imagemagick yelp python2 xorg-xrandr)<br />
*:GUI app for changing the settings of GRUB, GRUB2, Usplash and Splashy<br />
<br />
== parttool or legacy hide/unhide ==<br />
<br />
If you have a win9x paradigm with hidden C disks GRUB legacy had the hide/unhide feature. In GRUB2 this has been replaced by parttool. For example, to boot the third C disk of three win9x installations on the CLI enter the CLI and:<br />
parttool hd0,1 hidden+ boot-<br />
parttool hd0,2 hidden+ boot-<br />
parttool hd0,3 hidden- boot+<br />
set root=hd0,3<br />
chainloader +1<br />
boot<br />
<br />
== Using the rescue console ==<br />
<br />
See [[#Using the command shell]] first. If unable to activate the standard shell, one possible solution is to boot using a live CD or some other rescue disk to correct configuration errors and reinstall GRUB. However, such a boot disk is not always available (nor necessary); the rescue console is surprisingly robust.<br />
<br />
The available commands in GRUB rescue include "insmod", "ls", "set", and "unset". This example uses "set" and "insmod". "set" modifies variables and "insmod" inserts new modules to add functionality.<br />
<br />
Before starting, the user must know the location of their {{Filename|/boot}} partition (be it a separate partition, or a subdirectory under their root):<br />
grub rescue> set prefix=(hdX,Y)/boot/grub<br />
<br />
where X is the physical drive number and Y is the partition number.<br />
<br />
To expand console capabilities, insert the "linux" module:<br />
grub rescue> insmod (hdX,Y)/boot/grub/linux.mod<br />
<br />
{{Note|With a separate boot partition, omit {{Filename|/boot}} from the path, (i.e. type {{Codeline|1=set prefix=(hdX,Y)/grub}} and {{Codeline|insmod (hdX,Y)/grub/linux.mod}}).}}<br />
<br />
This introduces the "linux" and "initrd" commands, which should be familiar (see [[#Configuration]]).<br />
<br />
An example, booting Arch Linux:<br />
set root=(hd0,5)<br />
linux /boot/vmlinuz-linux root=/dev/sda5<br />
initrd /boot/initramfs-linux.img<br />
boot<br />
<br />
With a separate boot partition, again change the lines accordingly:<br />
set root=(hd0,5)<br />
linux /vmlinuz-linux root=/dev/sda6<br />
initrd /initramfs-linux.img<br />
boot<br />
<br />
After successfully booting the Arch Linux installation, users can correct {{Filename|grub.cfg}} as needed and then run:<br />
# grub-install /dev/sda --no-floppy<br />
<br />
to reinstall GRUB2 and fix the problem completely, changing {{Filename|/dev/sda}} if needed. See [[#Bootloader installation]] for details.<br />
<br />
== Combining the use of UUID's and basic scripting ==<br />
<br />
If you like the idea of using UUID's to avoid unreliable BIOS mappings or are struggling with Grub's syntax, here is an example boot menu item that uses UUID's and a small script to direct Grub to the proper disk partitions for your system. All you need to do is replace the UUID's in the sample with the correct UUID's for your system. (The example applies to a system with a boot and root partition. You will obviously need to modify the Grub configuration if you have additional partitions.)<br />
<br />
menuentry "Arch Linux 64" {<br />
#Enter the UUID of your boot partition (this is where Grub and your kernel reside)<br />
set uuid_grub_boot=ece0448f-bb08-486d-9864-ac3271bd8d07<br />
<br />
#Enter the UUID of the partition containing the root partition of your Arch Linux installation. <br />
set uuid_os_root=c55da16f-e2af-4603-9e0b-03f5f565ec4a<br />
<br />
#(Note: this may be the same as your boot partition)<br />
<br />
#Here we set the Grub "root" variable by locating the UUID of the root partition identified above <br />
search --fs-uuid --no-floppy --set=root $uuid_os_root<br />
<br />
#Here we set a custom variable grub_boot by locating the UUID of the boot partition identified above <br />
search --fs-uuid --no-floppy --set=grub_boot $uuid_grub_boot<br />
<br />
#Here is the magic. We test to see if the boot and root partitions have the same UUID.<br />
#If they do, we append /boot to the $grub_boot variable. For ex. (hd0,1) becomes (hd0,1)/boot.<br />
if [ $uuid_grub_boot == $uuid_os_root ] ; then<br />
set grub_boot=$grub_boot/boot<br />
fi<br />
<br />
# $grub_boot now points to the correct location, so the following will properly find the kernel and initrd<br />
linux ($grub_boot)/vmlinuz-linux root=/dev/disk/by-uuid/$uuid_os_root ro<br />
initrd ($grub_boot)/initramfs-linux.img<br />
}<br />
<br />
== Troubleshooting ==<br />
<br />
Any troubleshooting should be added here.<br />
<br />
=== Enable GRUB2 debug messages ===<br />
<br />
Add<br />
<br />
set pager=1<br />
set debug=all<br />
<br />
to {{Filename|grub.cfg}}.<br />
<br />
=== Correct GRUB2 No Suitable Mode Found Error ===<br />
<br />
If you get this error when booting any menuentry<br />
<br />
error: no suitable mode found<br />
Booting however<br />
<br />
Then you need to initialize grub2 graphical terminal (gfxterm) with proper video mode (gfxmode) in grub2. This video mode is passed by grub2 to the linux kernel via 'gfxpayload'. In case of UEFI systems, if the grub2 video mode is not initialized, no kernel boot messages will be shown in the terminal (atleast until KMS kicks in)<br />
<br />
Copy {{Filename|/usr/share/grub/unicode.pf2}} to ${GRUB2_PREFIX_DIR} ({{Filename|/boot/grub/}} in case of BIOS systems and {{Filename|/boot/efi/efi/grub/}} in case of UEFI systems). <br />
<br />
# cp /usr/share/grub/unicode.pf2 ${GRUB2_PREFIX_DIR}<br />
<br />
If {{Filename|/usr/share/grub/unicode.pf2}} does not exist, install {{Package Official|bdf-unifont}}, create the unifont.pf2 file and then copy it to ${GRUB2_PREFIX_DIR} .<br />
<br />
# grub-mkfont -o unicode.pf2 /usr/share/fonts/misc/unifont.bdf<br />
<br />
Then, in the {{Filename|grub.cfg}} file, add the following lines to enable grub2 to pass the video mode correctly to the kernel, without of which you will only get a black screen (no output) but booting (actually) proceeds successfully without any system hang:<br />
<br />
BIOS systems<br />
<br />
insmod vbe<br />
<br />
UEFI systems<br />
<br />
insmod efi_gop<br />
insmod efi_uga<br />
<br />
After that add the following code (common to both BIOS and UEFI)<br />
<br />
insmod font<br />
<br />
if loadfont ${prefix}/unicode.pf2<br />
then<br />
insmod gfxterm<br />
set gfxmode=auto<br />
set gfxpayload=keep<br />
terminal_output gfxterm<br />
fi<br />
<br />
As you can see for gfxterm (graphical terminal) to function properly, {{Filename|unicode.pf2}} font file should exist in ${GRUB2_PREFIX_DIR}.<br />
<br />
=== msdos-style error message ===<br />
<br />
grub-setup: warn: This msdos-style partition label has no post-MBR gap; embedding won't be possible!<br />
grub-setup: warn: Embedding is not possible. GRUB can only be installed in this setup by using blocklists.<br />
However, blocklists are UNRELIABLE and its use is discouraged.<br />
grub-setup: error: If you really want blocklists, use --force.<br />
<br />
This error may occur when you try installing GRUB2 in a VMware container. Read more about it [http://bbs.archlinux.org/viewtopic.php?pid=581760#p581760 here]. It happens when the first partition starts just after the MBR (block 63), without the usual space of 1 MiB (2048 blocks) before the first partition. Read [[#MBR_aka_msdos_partitioning_specific_instructions]]<br />
<br />
=== UEFI GRUB2 not loaded ===<br />
In some cases the EFI may fail to load grub correctly. Provided everything is set up correctly, the output of<br />
efibootmgr -v<br />
might look something like this:<br />
BootCurrent: 0000<br />
Timeout: 3 seconds<br />
BootOrder: 0000,0001,0002<br />
Boot0000* Grub HD(1,800,32000,23532fbb-1bfa-4e46-851a-b494bfe9478c)File(\efi\grub\grub.efi)<br />
Boot0001* Shell HD(1,800,32000,23532fbb-1bfa-4e46-851a-b494bfe9478c)File(\EfiShell.efi)<br />
Boot0002* Festplatte BIOS(2,0,00)P0: SAMSUNG HD204UI .<br />
If everything works correctly, the EFI would now automatically load grub.<br><br />
If the screen only goes black for a second and the next boot option is tried afterwards, according to [https://bbs.archlinux.org/viewtopic.php?pid=981560#p981560 this post], moving grub to the partition root can help. The boot option has to be deleted and recreated afterwards. The entry for grub should look like this then:<br />
Boot0000* Grub HD(1,800,32000,23532fbb-1bfa-4e46-851a-b494bfe9478c)File(\grub.efi)<br />
<br />
=== Invalid signature ===<br />
If trying to boot windows results in an "invalid signature" error, e.g. after reconfiguring partitions or adding additional hard drives, (re)move grub's device configuration and let it reconfigure.<br />
# mv /boot/grub/device.map /boot/grub/device.map-old<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
Grub-mkconfig should now mention all found boot options including windows. If it works, remove /boot/grub/device.map-old.<br />
<br />
== References ==<br />
<br />
# Official GRUB2 Manual - http://www.gnu.org/software/grub/manual/grub.html<br />
# GRUB2 wiki page describing steps to compile for UEFI systems - https://help.ubuntu.com/community/UEFIBooting - previously http://grub.enbug.org/TestingOnUEFI{{Linkrot|2011|09|05}}<br />
# Wikipedia's page on [http://en.wikipedia.org/wiki/BIOS_Boot_partition BIOS Boot Partition]<br />
<br />
== External Links ==<br />
<br />
# [https://github.com/the-ridikulus-rat/My_Shell_Scripts/blob/master/grub2/grub2_bios.sh A Linux Bash Shell script to compile and install GRUB2 for BIOS from BZR Source]<br />
# [https://github.com/the-ridikulus-rat/My_Shell_Scripts/blob/master/grub2/grub2_uefi.sh A Linux Bash Shell script to compile and install GRUB2 for UEFI from BZR Source]</div>Mayweedhttps://wiki.archlinux.org/index.php?title=GRUB&diff=168230GRUB2011-10-31T08:49:36Z<p>Mayweed: /* Make a backup of your precious data */</p>
<hr />
<div>[[Category:Boot loaders (English)]]<br />
{{i18n|GRUB2}}<br />
[[fr:GRUB2]]<br />
{{Article summary start}}<br />
{{Article summary text|Covers various aspects of the next generation of the GRand Unified Bootloader (GRUB2).}}<br />
{{Article summary heading|Overview}}<br />
{{Article summary text|{{Boot process overview}}}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|Burg}} - Burg is a brand-new boot loader based on GRUB2. It uses a new object format which allows it to be built in a wider range of OS, including Linux/Windows/OSX/Solaris/FreeBSD, etc. It also has a highly configurable menu system which works in both text and graphic mode. <br />
{{Article summary heading|Resources}}<br />
{{Article summary link|GNU GRUB -- GNU Project|http://www.gnu.org/software/grub/}}<br />
{{Article summary link|GNU GRUB Wiki|http://grub.enbug.org/}}{{Linkrot|2011|09|05}}<br />
{{Article summary end}}<br />
<br />
[http://www.gnu.org/software/grub/ GRUB2] is the next generation of the GRand Unified Bootloader (GRUB). GRUB2 is derived from [http://www.nongnu.org/pupa/ PUPA] which was a research project to investigate the next generation of GRUB. GRUB 2 has been rewritten from scratch to clean up everything and provide modularity and portability [http://www.gnu.org/software/grub/grub-faq.en.html#q1].<br />
<br />
Briefly, the ''bootloader'' is the first software program that runs when a computer starts. It is responsible for loading and transferring control to the Linux kernel. The kernel, in turn, initializes the rest of the operating system.<br />
<br />
== Preface ==<br />
<br />
Although, [[GRUB]] (i.e. version 0.9x) is the de facto standard bootloader of Linux, it is considered 'legacy' by upstream. It is being replaced by GRUB2 in many distributions. Upstream recommends GRUB2 >=1.99~rc2 over grub-legacy, even for current grub-legacy users.<br />
<br />
{{Note|grub2 from 1.99~rc2 and later supports btrfs as root (without a separate /boot filesystem).}}<br />
<br />
=== Notes for current GRUB Legacy users ===<br />
<br />
* There are differences in the commands of GRUB and GRUB2. Familiarize yourself with [http://www.gnu.org/software/grub/manual/grub.html#Commands GRUB2 commands] before proceeding (e.g. "find" has been replaced with "search").<br />
<br />
* GRUB2 is now ''modular'' and no longer requires "stage 1.5". As a result, the bootloader itself is limited -- modules are loaded from the hard drive as needed to expand functionality (e.g. for [[LVM]] or RAID support).<br />
<br />
* Device naming has changed between GRUB and GRUB2. Partitions are numbered from 1 instead of 0 while drives are still numbered from 0, and prefixed with partition-table type. For example, {{Filename|/dev/sda1}} would be referred to as {{Codeline|(hd0,msdos1)}} (for MBR) or {{Codeline|(hd0,gpt1)}} (for GPT) using GRUB2.<br />
<br />
=== Preliminary Requirements for GRUB2 ===<br />
<br />
==== BIOS systems ====<br />
<br />
===== [[GPT]] specific instructions =====<br />
<br />
GRUB2 in BIOS-GPT configuration requires a BIOS Boot Partition to embed its core.img in the absence of post-MBR gap in GPT partitioned systems (which is taken over by the GPT Primary Header and Primary Partition table). This partition is used by GRUB2 only in BIOS-GPT setups. No such partition type exists in case of MBR partitioning (at least not for GRUB2). This partition is also not required if the system is UEFI based, as no embedding of bootsectors takes place in that case. Syslinux does not require this partition.<br />
<br />
For a BIOS-GPT configuration, create a 2 MiB partition using cgdisk or GNU Parted with no filesystem. The location of the partition in the partition table does not matter but it should be within the first 2 TiB region of the disk. It is advisable to put it somewhere in the beginning of the disk before the /boot partition. Set the partition type to "EF02" in cgdisk or {{Codeline|set <BOOT_PART_NUM> bios_grub on}} in GNU Parted.<br />
<br />
{{Note|This partition should be created before grub_bios-install or grub-setup is run or before the '''Install Bootloader''' step of the Archlinux installer (if GRUB2 BIOS is selected as bootloader).}}<br />
<br />
===== [[MBR]] aka msdos partitioning specific instructions =====<br />
<br />
Usually the post-MBR gap (after the 512 byte MBR region and before the start of the 1st partition) in many MBR (or msdos disklabel) partitioned systems is 32 KiB when DOS compatibility cylinder alignment issues are satisfied in the partition table. However a post-MBR gap of about 1 to 2 MiB is recommended to provide sufficient room for embedding grub2's core.img ( https://bugs.archlinux.org/task/24103 ). It is advisable to use a partitioner which supports 1 MiB partition alignment to obtain this space as well as satisfy other non-512 byte sector issues (which are unrelated to embedding of core.img).<br />
<br />
If you do not dual-boot with MS Windows (any version) in BIOS systems, it is advisable to switch to GPT partitioning - [[GUID_Partition_Table#Convert_from_MBR_to_GPT_without_data_loss]]<br />
<br />
{{Note|Create the 2MiB partition mentioned above BEFORE you convert to GPT. If you do not, gparted will not resize your boot partition to allow its creation, and when you reboot grub2 will not know where to look.}}<br />
<br />
==== UEFI systems ====<br />
<br />
===== Create and Mount the UEFI SYSTEM PARTITION =====<br />
<br />
Follow [[Unified_Extensible_Firmware_Interface#Creating_a_UEFI_SYSTEM_PARTITION_in_Linux]] for instructions on creating a UEFI SYSTEM PARTITION. Then mount the UEFI SYSTEM PARTITION at {{Filename|/boot/efi}}. It should be FAT32 formatted and should be >=200 MiB in size. If you have mounted the UEFISYS partition in some other mountpoint, replace {{Filename|/boot/efi}} in the below instructions with that mountpoint:<br />
<br />
# mkdir -p /boot/efi<br />
# mount -t vfat <UEFISYS_PART_DEVICE> /boot/efi<br />
<br />
Create a <UEFI_SYSTEM_PARTITION>/efi directory if it does not exist:<br />
<br />
# mkdir -p /boot/efi/efi<br />
<br />
== Installation ==<br />
<br />
=== During Arch Linux installation ===<br />
<br />
* Skip the '''Install Bootloader''' step and exit the installer.<br />
* Configure the network:<br />
# aif -p partial-configure-network<br />
This will bring up a prompt; put in the network interface to use, (e.g., eth0) and use DHCP for easy configuration.<br />
* If you did not configure the installed system's {{Filename|/etc/resolv.conf}} file during installation (for instance, if you plan to let DHCP generate it later), you will need to copy the one generated by AIF when it configured the network:<br />
# cp /etc/resolv.conf /mnt/etc/resolv.conf<br />
* Load the dm-mod module (you might need grub2-bios; install the package if needed):<br />
# modprobe dm-mod<br />
{{Note|This is necessary at this point, and cannot be postponed after the chroot. If you try to use modprobe in a chroot environment that has a later kernel version from that of the installing device (at the time of writing, 2.6.33), modprobe will fail. This happens routinely using the Arch "net" installations.}}<br />
* From the installer's live shell, chroot to the installed system:<br />
# mount -o bind /dev /mnt/dev<br />
# chroot /mnt bash<br />
* Update pacman's database:<br />
# pacman-db-upgrade<br />
* Refresh the package list (with an extra -y flag to force a refresh of all package lists even if they appear to be up to date):<br />
# pacman -Syy<br />
* Install the GRUB2 package as mentioned in the section [[#From a running Arch Linux]]. Note that the dm-mod module has already been loaded, no need to do that again.<br />
<br />
=== From a running Arch Linux ===<br />
<br />
==== BIOS systems ====<br />
<br />
===== Make a backup of your precious data =====<br />
<br />
In general, a grub installation should run smoothly . Sometimes it could mess up your system. You're strongly advised to make a backup before installing grub2-bios.<br />
<br />
* copy grub modules and configuration<br />
<br />
# cp -a /boot/grub /path/to/backup/<br />
<br />
* backup the MBR and GRUB-Legacy stage 1.5<br />
<br />
# dd if=/dev/sdX of=/path/to/backup/first-sectors bs=512 count=63<br />
<br />
Replace /dev/sdaX with you disk path (mostly /dev/sda).<br />
<br />
{{Note|This command backs up the partition table too. Be careful while restoring if you've changed your partition setup}}<br />
<br />
To backup only the MBR boot code use:<br />
<br />
# dd if=/dev/sdX of=/path/to/backup/mbr-boot-code bs=440 count=1<br />
<br />
You could now lightly remove {{Filename|/boot/grub}} with:<br />
<br />
# rm -rf /boot/grub<br />
<br />
and follow the instructions below. You know that if things get nasty, you could reboot your system thanks to an installation media and :<br />
<br />
* move old grub-legacy or grub2 files out of the way<br />
<br />
# mv /boot/grub /boot/grub.nonfunctional<br />
<br />
* copy grub back to /boot<br />
<br />
# cp -a /path/to/backup/grub /boot/<br />
<br />
* replace MBR and next 62 sectors of sda with backed up copy (DANGEROUS!)<br />
<br />
# dd if=/path/to/backup/first-sectors of=/dev/sdX bs=512 count=63<br />
<br />
{{Note|This command also restores the partition table. Be careful.}}<br />
<br />
To restore only the MBR boot code use:<br />
<br />
# dd if=/path/to/backup/mbr-boot-code of=/dev/sdX bs=440 count=1<br />
<br />
===== Before grub_bios-install =====<br />
<br />
The GRUB2 package can be installed with pacman (and will replace {{Package Official|grub}}, if it is installed):<br />
<br />
# pacman -S grub2-bios<br />
<br />
{{Note|Installing grub2-common (a dependency of grub2-bios) 1.99~rc1 or later, may take forever in some systems since the post_install script runs grub-mkconfig and this script does not provide the option <code>--no-floppy</code>. For more details search this option in the article.}}<br />
<br />
{{Note|Simply installing the package won't update the /boot/grub/core.img file and the grub2 modules in /boot/grub . You need to update the core.img file and the grub2 modules manually using grub_bios-install as explained below.}}<br />
<br />
Also load the device-mapper kernel module without which grub-probe does not reliably detect disks and partitions<br />
<br />
# modprobe dm-mod<br />
<br />
===== Run grub_bios-install =====<br />
<br />
There are 3 ways to install grub2 in BIOS booting - [[#Install_to_440-byte_MBR_boot_code_region]] (recommended) , [[#Install_to_Partition_or_Partitionless_Disk]] (not recommended) or [[#Generate_core.img_alone]] (safest method, but requires another BIOS bootloader like [[grub-legacy]] or [[syslinux]] to be installed to chainload {{Filename|/boot/grub/core.img}} ). For all the ways [[#Before_grub_bios-install]] step is needed.<br />
<br />
====== Install to 440-byte MBR boot code region ======<br />
<br />
To setup grub2-bios in the 440-byte Master Boot Record boot code region, populate the {{Filename|/boot/grub}} directory, generate the {{Filename|/boot/grub/core.img}} file, and embed it in the 32 KiB (minimum size - varies depending on partition alignment) post-MBR gap (MBR disks) or in BIOS Boot Partition (GPT disks), run<br />
<br />
# grub_bios-install --boot-directory=/boot --no-floppy --recheck /dev/sda<br />
<br />
where {{Filename|/dev/sda}} is the destination of the installation (in this case the MBR of the first SATA disk). If you use [[LVM]] for your {{Filename|/boot}}, you can install GRUB2 on multiple physical disks. <br />
<br />
The {{Codeline|--no-floppy}} tells grub2-bios utilities not to search for any floppy devices which reduces the overall execution time of grub_bios-install on many systems (it will also prevent the issue below from occuring). Otherwise you get an error like this<br />
<br />
grub-probe: error: Cannot get the real path of '/dev/fd0'<br />
Auto-detection of a filesystem module failed.<br />
Please specify the module with the option '--modules' explicitly.<br />
<br />
Follow [[#Generate_GRUB2_BIOS_Config_file]] or if that fails, convert your {{Filename|/boot/grub/menu.lst}} file to {{Filename|/boot/grub/grub.cfg}} using:<br />
<br />
# grub-menulst2cfg /boot/grub/menu.lst /boot/grub/grub.cfg<br />
<br />
For example:<br />
<br />
{{File|name=/boot/grub/menu.lst|content=<br />
default=0<br />
timeout=5<br />
<br />
title Arch Linux Stock Kernel<br />
root (hd0,0)<br />
kernel /vmlinuz-linux root=/dev/sda2 ro<br />
initrd /initramfs-linux.img<br />
<br />
title Arch Linux Stock Kernel Fallback<br />
root (hd0,0)<br />
kernel /vmlinuz-linux root=/dev/sda2 ro<br />
initrd /initramfs-linux-fallback.img<br />
}}<br />
<br />
{{File|name=/boot/grub/grub.cfg|content=<br />
set default='0'; if [ x"$default" = xsaved ]; then load_env; set default="$saved_entry"; fi<br />
set timeout=5<br />
<br />
menuentry 'Arch Linux Stock Kernel' {<br />
set root='(hd0,1)'; set legacy_hdbias='0'<br />
legacy_kernel '/vmlinuz-linux' '/vmlinuz-linux' 'root=/dev/sda2' 'ro'<br />
legacy_initrd '/initramfs-linux.img' '/initramfs-linux.img'<br />
<br />
}<br />
<br />
menuentry 'Arch Linux Stock Kernel Fallback' {<br />
set root='(hd0,1)'; set legacy_hdbias='0'<br />
legacy_kernel '/vmlinuz-linux' '/vmlinuz-linux' 'root=/dev/sda2' 'ro'<br />
legacy_initrd '/initramfs-linux-fallback.img' '/initramfs-linux-fallback.img'<br />
}<br />
}}<br />
<br />
<br />
If you forgot to create a GRUB2 {{Filename|/boot/grub/grub.cfg}} configfile and simply rebooted into GRUB2 Command Shell, type:<br />
<br />
sh:grub> insmod legacycfg<br />
sh:grub> legacy_configfile ${prefix}/menu.lst<br />
<br />
Boot into Arch and re-create the proper GRUB2 {{Filename|/boot/grub/grub.cfg}} configfile.<br />
<br />
{{Note|This option works only in BIOS systems, not in UEFI systems.}}<br />
<br />
====== Install to Partition or Partitionless Disk ======<br />
<br />
{{Note|grub2-bios (any version - including upstream bzr repo) does not encourage installation to a partition boot sector or a partitionless disk like grub-legacy or syslinux does. Neither do the Arch devs.}}<br />
<br />
To setup grub2-bios to a partition boot sector, to a partitionless disk (also called superfloppy) or to a floppy disk, run (using for example /dev/sda1 as the /boot partition)<br />
<br />
# chattr -i /boot/grub/core.img<br />
# grub_bios-install --boot-directory=/boot --no-floppy --recheck --force /dev/sda1<br />
# chattr +i /boot/grub/core.img<br />
<br />
You need to use the {{Codeline|--force}} option to allow usage of blocklists and should not use <code>--grub-setup=/bin/true</code> (which is similar to simply generating core.img).<br />
<br />
grub_bios-install will give out warnings like which should give you the idea of what might go wrong with this approach.<br />
<br />
/sbin/grub-setup: warn: Attempting to install GRUB to a partitionless disk or to a partition. This is a BAD idea.<br />
/sbin/grub-setup: warn: Embedding is not possible. GRUB can only be installed in this setup by using blocklists. <br />
However, blocklists are UNRELIABLE and their use is discouraged.<br />
<br />
Without {{Codeline|--force}} you may get the below error and grub-setup will not setup its boot code in the partition boot sector.<br />
<br />
/sbin/grub-setup: error: will not proceed with blocklists<br />
<br />
With {{Codeline|--force}} you should get<br />
<br />
Installation finished. No error reported.<br />
<br />
The reason why grub-setup does not by default allow this is because in case of partition or a partitionless disk is that grub2-bios relies on embedded blocklists in the partition bootsector to locate the {{Filename|/boot/grub/core.img}} file and the prefix dir {{Filename|/boot/grub}} . The sector locations of {{Filename|core.img}} may change whenever the filesystem in the partition is being altered (files copied, deleted etc.). For more info see https://bugzilla.redhat.com/show_bug.cgi?id=728742 and https://bugzilla.redhat.com/show_bug.cgi?id=730915 .<br />
<br />
The workaround for this is to set the immutable flag on {{Filename|/boot/grub/core.img}} (using chattr command as mentioned above) so that the sector locations of the {{Filename|core.img}} file in the disk is not altered. The immutable flag on {{Filename|/boot/grub/core.img}} needs to be set only if grub2-bios is installed to a partition boot sector or a partitionless disk, not in case of installtion to MBR or simple generation of {{Filename|core.img}} without embedding any bootsector (mentioned above). <br />
<br />
====== Generate core.img alone ======<br />
<br />
To populate the {{Filename|/boot/grub}} directory and generate a {{Filename|/boot/grub/core.img}} file WITHOUT embedding any grub2-bios bootsector code in the MBR, post-MBR region, or the partition bootsector, add <code>--grub-setup=/bin/true</code> to grub_bios-install:<br />
<br />
# grub_bios-install --grub-setup=/bin/true --boot-directory=/boot --no-floppy --recheck /dev/sda<br />
<br />
You can then chainload grub2's core.img from grub-legacy or syslinux as a Linux kernel or a multiboot kernel.<br />
<br />
===== After grub_bios-install =====<br />
<br />
====== Generate GRUB2 BIOS Config file ======<br />
<br />
Finally, generate a configuration for grub2 (this is explained in greater detail in the Configuration section):<br />
<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
If grub2 complains about "no suitable mode found" while booting, go to [[#Correct_GRUB2_No_Suitable_Mode_Found_Error]] .<br />
<br />
===== Multiboot in BIOS =====<br />
<br />
====== Boot Microsoft Windows installed in BIOS-MBR mode ======<br />
<br />
{{Note|GRUB2 supports booting {{Filename|bootmgr}} directly and chainload of partition boot sector is no longer required to boot Windows in a BIOS-MBR setup.}}<br />
<br />
Find the UUID of the NTFS filesystem of the Windows's SYSTEM PARTITION where the bootmgr and its files reside. For example, if Windows {{Filename|bootmgr}} exists at {{Filename|/media/Windows/bootmgr}}:<br />
<br />
# grub-probe --target=fs_uuid /media/Windows/bootmgr<br />
69B235F6749E84CE<br />
<br />
Then, add the below code to {{Filename|/boot/grub/grub.cfg}} to chainload Windows (Vista, 7 or 8) installed in BIOS-MBR mode :<br />
<br />
menuentry "Microsoft Windows 7 BIOS-MBR" {<br />
insmod part_msdos<br />
insmod ntfs<br />
insmod search_fs_uuid<br />
insmod ntldr <br />
search --fs-uuid --no-floppy --set=root 69B235F6749E84CE<br />
ntldr (${root})/bootmgr<br />
}<br />
<br />
For Windows XP<br />
<br />
menuentry "Microsoft Windows XP" {<br />
insmod part_msdos<br />
insmod ntfs<br />
insmod search_fs_uuid<br />
insmod ntldr <br />
search --fs-uuid --no-floppy --set=root 69B235F6749E84CE<br />
ntldr (${root})/ntldr<br />
}<br />
<br />
==== [[UEFI]] systems ====<br />
<br />
===== Before grub_efi_${UEFI_ARCH}-install =====<br />
<br />
{{Note|Unless specified as EFI 1.x , EFI and UEFI terms are used interchangeably to denote UEFI 2.x firmware. Also unless stated explicitely, the instructions are general and not Mac specific. Some of them may not work or may be different in Macs. Apple's EFI implementation is neither a EFI 1.x version nor UEFI 2.x version but mixes up both. This kind of firmware does not fall under any one UEFI Specification version and is therefore not a standard UEFI firmware.}}<br />
<br />
GRUB2 UEFI bootloader is available in Arch Linux only from version 1.99~rc1 . To install, first [https://wiki.archlinux.org/index.php/Unified_Extensible_Firmware_Interface#Detecting_UEFI_Firmware_Arch Detect which UEFI firmware arch] you have (either x86_64 or i386).<br />
<br />
Depending on that, install the appropriate package<br />
<br />
For 64-bit aka x86_64 UEFI firmware:<br />
# pacman -S grub2-efi-x86_64<br />
<br />
For 32-bit aka i386 UEFI firmware:<br />
# pacman -S grub2-efi-i386<br />
<br />
{{Note|Installing grub2-common (a dependency of grub2-bios) 1.99~rc1 or later, may take forever in some systems since the post_install script runs grub-mkconfig and this script does not provide the option <code>--no-floppy</code>. For more details search this option in the article.}}<br />
<br />
{{Note|Simply installing the package won't update the grub.efi file and the grub2 modules in the UEFI System Partition . You need to update the grub.efi file and the grub2 modules in the UEFI System Partition manually using grub_efi_${UEFI_ARCH}-install as explained below.}}<br />
<br />
Also load the device-mapper kernel module without which grub-probe does not reliably detect disks and partitions<br />
<br />
# modprobe dm-mod<br />
<br />
===== Run grub_efi_${UEFI_ARCH}-install =====<br />
<br />
====== Install to UEFI SYSTEM PARTITION ======<br />
<br />
{{Note|The below commands assume you are using {{Codeline|grub2-efi-x86_64}} (for {{Codeline|grub2-efi-i386}} replace {{Codeline|x86_64}} with {{Codeline|i386}} in the below commands).}}<br />
<br />
# grub_efi_x86_64-install --root-directory=/boot/efi --boot-directory=/boot/efi/efi --bootloader-id=grub --no-floppy --recheck<br />
<br />
The {{Codeline|grub_efi_x86_64-install}} automatically generates a {{Filename|grub.efi}} while setting up the {{Filename|/boot/efi/efi/grub/}} directory.<br />
<br />
If you notice carefully, there is no <device_path> option (Eg: {{Filename|/dev/sda}}) at the end of the {{Codeline|grub_efi_x86_64-install}} command unlike the case of setting up grub2 for BIOS systems. Any <device_path> provided will be ignored by the install script as UEFI bootloaders do not use MBR or Partition boot sectors at all.<br />
<br />
You may now be able to UEFI boot your system by creating a grub.cfg file using grub-mkconfig and copying /boot/efi/efi/grub/grub.efi to /boot/efi/efi/boot/bootx64.efi.<br />
<br />
===== After grub_efi_${UEFI_ARCH}-install =====<br />
<br />
====== Launch GRUB2 as default in non-Mac UEFI systems ======<br />
<br />
{{Note|The below steps will not work if the system has been booted in BIOS mode and will not work if the UEFI processor architecture does not match the kernel one, i.e. x86_64 UEFI + ix86 32-bit Kernel and vice-versa config will not work.}}<br />
<br />
grub_efi_${UEFI_ARCH}-install will ensure {{Filename|/boot/efi/efi/grub/grub.efi}} is launched by default if it detects {{Codeline|efibootmgr}} and if it is able to access UEFI Runtime Services. {{Codeline|efibootmgr}} command will work only if you have booted the system in UEFI mode itself, since it '''requires access to UEFI Runtime Variables''' which are '''available only in UEFI boot mode''' (with "noefi" kernel parameter NOT being used). Initially the user is required to manually launch {{Filename|/boot/efi/efi/grub/grub.efi}} from the firmware itself (using maybe the UEFI Shell) if grub2-efi was installed in BIOS mode. Then {{Codeline|efibootmgr}} should be run to make grub2 as the default entry in the UEFI Boot Manager<br />
<br />
First boot into UEFI mode manually either using the firmware boot menu, UEFI shell, or using any UEFI capable bootable iso (Archboot or Ubuntu non-Mac iso). Use grub probe to determine the device path of your EFI System Partition:<br />
# grub-probe --target=device /boot/efi/efi/grub/grub.efi<br />
<br />
It should give something like {{Filename|/dev/sda1}} (used as example in the remaining steps). Load 'efivars' kernel module:<br />
# modprobe efivars<br />
<br />
If you get '''no such device found''' error for this command, that means you have not booted in UEFI mode or due to some reason the kernel is unable to access UEFI Runtime Variables.<br />
<br />
Verify whether there are files in ''/sys/firmware/efi/vars/'' directory. This directory and its contents are created by "efivars" kernel module and it will exist only if you have booted in UEFI mode without the "noefi" kernel parameter.<br />
<br />
# ls -1 /sys/firmware/efi/vars/<br />
<br />
Sample output (x86_64-UEFI 2.3.1 in x86_64 Kernel:<br />
<br />
# ls -1 /sys/firmware/efi/vars/<br />
Boot0000-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootCurrent-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootOptionSupport-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootOrder-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConIn-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConInDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConOut-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConOutDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ErrOutDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
Lang-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
LangCodes-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
MTC-eb704011-1402-11d3-8e77-00a0c969723b/<br />
MemoryTypeInformation-4c19049f-4137-4dd3-9c10-8b97a83ffdfa/<br />
PlatformLang-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
PlatformLangCodes-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
RTC-378d7b65-8da9-4773-b6e4-a47826a833e1/<br />
del_var<br />
new_var<br />
<br />
If ''/sys/firmware/efi/vars/'' directory is empty or does not exist, then {{Codeline|efibootmgr}} command will not work. If you are unable to make the ISO/CD/DVD/USB boot in UEFI mode try https://gitorious.org/tianocore_uefi_duet_builds/pages/Linux_Windows_BIOS_UEFI_boot_USB .<br />
<br />
If ''/sys/firmware/efi/vars/'' directory (along with the exists then run {{Codeline|efibootmgr}} and reboot:<br />
<br />
# efibootmgr --create --gpt --disk /dev/sda --part 1 --write-signature --label "GRUB2" --loader "\\EFI\\grub\\grub.efi"<br />
<br />
In the above command, {{Filename|/boot/efi/efi/grub/grub/efi}} can be split up as {{Filename|/boot/efi}} and {{Filename|/efi/grub/grub.efi}}, which translates to {{Filename|(/dev/sda)}} -> partition 1 -> {{Filename|\\EFI\\grub\\grub.efi}}. <br />
<br />
FAT32 filesystem is case-insensitive since it does not use UTF-8 encoding by default. In that case the firmware uses capital 'EFI' instead of small 'efi', therefore using {{Filename|\\EFI\\grub\\grub.efi}} or {{Filename|\\efi\\grub\\grub.efi}} does not matter (this will change if the filesystem encoding is UTF-8). UEFI uses backward slash as path separatoir (similar to Windows paths). In the above command "double" backward slashes are used instead of single ones, since a backward slash is used as a escape character by sh shells, the first backward slash escapes the second one so that the path {{Filename|\EFI\grub\grub.efi}} is passed to {{Codeline|efibootmgr}}.<br />
<br />
The 'label' is the name of the menu entry shown in the UEFI boot menu. This name is user's choice and does not affect the booting of the system. More info can be obtained from [http://linux.dell.com/cgi-bin/gitweb/gitweb.cgi?p=efibootmgr.git;a=blob_plain;f=README;hb=HEAD efibootmgr GIT README]<br />
<br />
If you have problems running GRUB2 in UEFI mode you can try the following (worked on an ASUS Z68 mainboard):<br />
<br />
# cp /boot/efi/efi/grub/grub.efi /boot/efi/shellx64.efi<br />
<br />
or<br />
<br />
# cp /boot/efi/efi/grub/grub.efi /boot/efi/efi/shellx64.efi<br />
or<br />
<br />
# cp /boot/efi/efi/grub/grub.efi /boot/efi/efi/shell/shellx64.efi<br />
<br />
After this launch the UEFI Shell from the UEFI setup/menu (in ASUS UEFI BIOS, switch to advanced mode, press Exit in the top right corner and choose "Launch EFI shell from filesystem device"). The grub2 menu will show up and you can boot into your system. Afterwards you can use efibootmgr to setup a menu entry (see above).<br />
<br />
====== Launch GRUB2 as default in Apple Mac EFI systems ======<br />
<br />
{{Note|Using {{Filename|efibootmgr}} in Apple Macs will brick the firmware and may need reflash of the motherboard ROM. There have been bug reports regarding this in Ubuntu/Launchpad bug tracker. Use bless command alone in case of Macs}}<br />
<br />
Use bless command from within Mac OS X to setup {{Filename|grub.efi}} as the default boot option. More info at https://help.ubuntu.com/community/UEFIBooting#Apple_Mac_EFI_systems_.28both_EFI_architecture.29 .<br />
<br />
====== Generate GRUB2 UEFI Config file ======<br />
<br />
Finally, generate a configuration for grub2 (this is explained in greater detail in the Configuration section):<br />
<br />
# grub-mkconfig -o /boot/efi/efi/grub/grub.cfg<br />
<br />
If grub2-uefi complains about "no suitable mode found" while booting, go to [[#Correct_GRUB2_No_Suitable_Mode_Found_Error]] .<br />
<br />
===== Generate a custom GRUB2 UEFI Application =====<br />
<br />
If you want, you can create a custom {{Filename|grub_custom.efi}} app using:<br />
# grub-mkimage -d /usr/lib/grub/x86_64-efi -O x86_64-efi -p "" -o /boot/efi/efi/grub/grub_custom.efi <GRUB2_Modules_to_be_included><br />
<br />
{{Note|The '''-p''' option is important for creating a portable {{Filename|grub_custom.efi}} app.}}<br />
<br />
There is no file-size restriction on {{Filename|grub_custom.efi}} either due to GRUB2 or due to the UEFI firmware. Therefore you can include any number of modules you want.<br />
<br />
A "{{Filename|grub.cfg}}" created for BIOS based GRUB2 will be sufficient for the UEFI GRUB2 as long as all the paths in the config are absolute paths. The {{Filename|grub.cfg}} file should exist in the same directory as {{Filename|grub.efi}} or {{Filename|grub_custom.efi}}.<br />
<br />
The {{Filename|grub.efi}} UEFI application can be launched using the firmware's "Boot Manager", "Boot from file" option or using the [https://wiki.archlinux.org/index.php/UEFI#UEFI_Shell UEFI Shell].<br />
<br />
Alternatively, you can also setup {{Filename|/boot/efi/efi/grub}} directory by copying all the files in {{Filename|/usr/lib/grub/x86_64-efi}} to {{Filename|/boot/efi/efi/grub}} and using the above grub-mkimage command to create a {{Filename|grub_custom.efi}} application. Just make sure you have the required modules embedded in {{Filename|grub_custom.efi}} to enable it to access the EFI SYSTEM PARTITION.<br />
<br />
A basic {{Filename|grub_custom.efi}} can be generated using the following command:<br />
# sudo grub-mkimage -d /usr/lib/grub/x86_64-efi -O x86_64-efi -p "" -o /boot/efi/efi/grub/grub_custom.efi part_gpt fat iso9660 udf normal chain linux \<br />
ls search search_fs_file search_fs_uuid search_label help boot configfile echo efi_gop<br />
<br />
===== Multiboot in UEFI =====<br />
<br />
====== Chainload Microsoft Windows x86_64 UEFI-GPT ======<br />
<br />
Find the UUID of the FAT32 filesystem in the UEFI SYSTEM PARTITION where the Windows UEFI Bootloader files reside. For example, if Windows {{Filename|bootmgfw.efi}} exists at {{Filename|/boot/efi/efi/Microsoft/Boot/bootmgfw.efi}} (ignore the upper-lower case differences since that is immaterial in FAT filesystem):<br />
<br />
# grub-probe --target=fs_uuid /boot/efi/efi/Microsoft/Boot/bootmgfw.efi<br />
1ce5-7f28<br />
<br />
Then, add this code to {{Filename|/boot/efi/efi/grub/grub.cfg}} to chainload Windows x86_64 (Vista SP1+, 7 or 8) installed in UEFI-GPT mode :<br />
<br />
menuentry "Microsoft Windows x86_64 UEFI-GPT" {<br />
insmod part_gpt<br />
insmod fat<br />
insmod search_fs_uuid<br />
insmod chain<br />
search --fs-uuid --no-floppy --set=root 1ce5-7f28<br />
chainloader (${root})/efi/Microsoft/Boot/bootmgfw.efi<br />
}<br />
<br />
== Manual Compilation ==<br />
<br />
=== For BIOS Systems ===<br />
<br />
GRUB2 for BIOS systems should be compiled as follows:<br />
<pre><br />
./autogen.sh<br />
<br />
./configure --with-platform=pc --prefix=/usr<br />
<br />
make<br />
<br />
make install<br />
</pre><br />
<br />
The <code>--with-platform=pc</code> generates grub2 for bios alone irrespective of the firmware of the build system.<br />
<br />
=== For UEFI Systems ===<br />
<br />
First [https://wiki.archlinux.org/index.php/Unified_Extensible_Firmware_Interface#Detecting_UEFI_Firmware_Arch Detect which UEFI Firmware arch] you have and then follow the compile instructions below:<br />
<pre><br />
./autogen.sh<br />
<br />
./configure --with-platform=efi --target=TARGET_UEFI_ARCH --prefix=/usr<br />
<br />
make<br />
<br />
make install<br />
</pre><br />
<br />
The "--target" option denotes the UEFI firmware arch. for which grub2 should be compiled, not the architecture of the linux kernel grub2 may boot. <br />
<br />
It is possible to use UEFI 64-bit firmware + GRUB2 as x86_64-EFI app loading a i686 linux kernel, as long as the kernel does not try to access UEFI Runtime Services. Vice-versa situation is also possible. But a x86_64 UEFI firmware cannot launch GRUB2 i386-efi app (unlike x86_64 Operating Systems), and a i386 UEFI firmware will not launch GRUB2 {{Codeline|x86_64-efi}} app. It is important to compile GRUB2 to match the architecture of the UEFI firmware.<br />
<br />
== Configuration ==<br />
<br />
The configuration files are {{Filename|/etc/default/grub}} and {{Filename|/etc/grub.d/*}}. These files are used to generate the {{Filename|/boot/grub/grub.cfg}} file. You can also choose to manually edit {{Filename|grub.cfg}}.<br />
<br />
=== grub-mkconfig ===<br />
<br />
The grub-mkconfig script can be used to generate a {{Filename|grub.cfg}} file. By default the script outputs to stdout. Note that gettext ― an optional dependency of the GRUB2 package ― is required by the grub-mkconfig script. To generate a {{Filename|grub.cfg}} file run the command:<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
Note that grub-mkconfig probably has your grub directory hardcoded to /boot/grub, which is probably wrong if you're using UEFI. Either mount your efi grub directory at /boot/grub or edit the script.<br />
<br />
=== grub.cfg ===<br />
<br />
A basic grub file uses the following options<br />
* {{Codeline|(hdX,Y)}} is the partition {{Codeline|Y}} on disk {{Codeline|X}}, partition numbers starting at 1, disk numbers starting at 0<br />
* {{Codeline|1=set default=N}} is the default boot entry that is chosen after timeout for user action<br />
* {{Codeline|1=set timeout=M}} is the time {{Codeline|M}} to wait in seconds for a user selection before default is booted<br />
* {{Codeline|<nowiki>menuentry "title" {entry options}</nowiki>}} is a boot entry titled {{Codeline|title}}<br />
* {{Codeline|1=set root=(hdX,Y)}} sets the boot partition, where the kernel and GRUB modules are stored (boot need not be a separate partition, and may simply be a directory under the "root" partition ({{Filename|/}})<br />
<br />
An example configuration:<br />
<br />
{{File<br />
|name=/boot/grub/grub.cfg<br />
|content=<nowiki><br />
# Config file for GRUB2 - The GNU GRand Unified Bootloader<br />
# /boot/grub/grub.cfg<br />
<br />
# DEVICE NAME CONVERSIONS<br />
#<br />
# Linux Grub<br />
# -------------------------<br />
# /dev/fd0 (fd0)<br />
# /dev/sda (hd0)<br />
# /dev/sdb2 (hd1,2)<br />
# /dev/sda3 (hd0,3)<br />
#<br />
<br />
# Timeout for menu<br />
set timeout=5<br />
<br />
# Set default boot entry as Entry 0<br />
set default=0<br />
<br />
# (0) Arch Linux<br />
menuentry "Arch Linux" {<br />
set root=(hd0,1)<br />
linux /vmlinuz-linux root=/dev/sda3 ro<br />
initrd /initramfs-linux.img<br />
}<br />
<br />
## (1) Windows<br />
#menuentry "Windows" {<br />
#set root=(hd0,3)<br />
#chainloader +1<br />
#}<br />
</nowiki>}}<br />
<br />
=== Dual-booting ===<br />
<br />
''NOTE: If you want GRUB2 to automatically search for other systems, for example as in Ubuntu. Then you may need to download {{Package AUR|os-prober}} from the [[AUR]].''<br />
<br />
==== Using grub-mkconfig ====<br />
The best way to add other entries is editing the {{Filename|/etc/grub.d/40_custom}}. The entries in this file will be automatically added when running '''grub-mkconfig'''.<br />
After adding the new lines, run:<br />
# grub-mkconfig -o /boot/grub/grub.cfg <br />
to generate an updated {{Filename|grub.cfg}}.<br />
<br />
===== With GNU/Linux =====<br />
<br />
Assuming that the other distro is on partition {{Filename|sda2}}:<br />
<br />
menuentry "Other Linux" {<br />
set root=(hd0,2)<br />
linux /boot/vmlinuz (add other options here as required)<br />
initrd /boot/initrd.img (if the other kernel uses/needs one)<br />
}<br />
<br />
===== With Windows =====<br />
<br />
This assumes that your Windows partition is {{Filename|sda3}}.<br />
<br />
# (2) Windows XP<br />
menuentry "Windows XP" {<br />
set root=(hd0,3)<br />
chainloader (hd0,3)+1<br />
}<br />
<br />
If the windows bootloader is on an entirely different harddrive than grub, it may be necessary to trick Windows into believing that it is in fact the first harddrive. This was possible in the old grub with {{Codeline|map}} and is now done with {{Codeline|drivemap}}. Assume grub is on {{Filename|hd0}} and windows on {{Filename|hd2}}, you need to add the following after {{Codeline|set root}}:<br />
<br />
drivemap -s hd0 hd2<br />
<br />
==== With Windows via EasyBCD and NeoGRUB ====<br />
<br />
Since EasyBCD's NeoGRUB currently does not understand the GRUB2 menu format, chainload to it by replacing the contents of your {{Filename|C:\NST\menu.lst}} file with lines similar to the following:<br />
<br />
default 0<br />
timeout 1<br />
<br />
title Chainload into GRUB v2<br />
root (hd0,7)<br />
kernel /boot/grub/core.img<br />
<br />
===Visual Configuration===<br />
<br />
In GRUB2 it is possible, by default, to change the look of the menu.<br />
<br />
====Background image and bitmap fonts====<br />
<br />
GRUB2 comes with support for background images and bitmap fonts in pf2 format. The unifont font is included in the grub2 package under the filename {{Filename|unicode.pf2}}, or, as only ascii characters under the name {{Filename|ascii.pf2}}. Image formats supported include tga, png and jpeg, providing the correct modules are loaded. The maximum supported resolution depends on your hardware. There are two ways of setting a {{Filename|tga}} file as background. Two sample configurations are shown below.<br />
<br />
Edit {{Filename|/etc/default/grub}} like this:<br />
GRUB_GFXMODE=1024x768x32<br />
GRUB_GFXPAYLOAD_LINUX=keep<br />
GRUB_BACKGROUND="/boot/grub/archlinux.tga"<br />
#GRUB_THEME="/path/to/gfxtheme"<br />
<br />
(archlinux.tga is a placeholder; put your file name there)<br />
<br />
To generate the changes, run: <br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
{{Note|If this example does not work for you try to replace {{Codeline|1=gfxmode="1024x768x32"}} by {{Codeline|1=vbemode="0x105"}}.}}<br />
{{Note|To show all the modes you can use {{Codeline|1=# hwinfo --framebuffer}} (hwinfo is available in [community]), while at grub2 prompt you can use the {{Codeline|1=vbeinfo}} command.}}<br />
{{Note|If you have installed Grub on a separate partition, {{Filename|/boot/grub/archlinux.tga}} becomes {{Filename|/grub/archlinux.tga}}.}}<br />
<br />
====Menu colors====<br />
<br />
As in Grub (0.9x), you can change the menu colors in Grub2. The available colors for GRUB2 are at http://www.gnu.org/software/grub/manual/html_node/Theme-file-format.html#Theme-file-format . <br />
Here is an example:<br />
<br />
Edit {{Filename|/etc/default/grub}}:<br />
GRUB_COLOR_NORMAL="light-blue/black"<br />
GRUB_COLOR_HIGHLIGHT="light-cyan/blue"<br />
<br />
Generate the changes:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
====Hidden menu====<br />
<br />
One of the unique features of Grub2 is hiding/skipping the menu and showing it by holding "Shift" when needed. You can also adjust whether you want to see the timeout counter.<br />
<br />
Edit {{Filename|/etc/default/grub}} as you wish. Here is an example where the comments from the beginning of the two lines have been removed to enable the feature, the timeout has been set to five seconds and to be shown to the user:<br />
GRUB_HIDDEN_TIMEOUT=5<br />
GRUB_HIDDEN_TIMEOUT_QUIET=false<br />
<br />
and run:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
====Setting the framebuffer resolution ====<br />
<br />
Grub2 can set the framebuffer for both grub2 itself and the kernel. The old ''vga='' way is deprecated. The preferred method is editing {{Filename|/etc/default/grub}} as the following sample:<br />
<br />
GRUB_GFXMODE=1024x768x32<br />
GRUB_GFXPAYLOAD_LINUX=keep<br />
<br />
To generate the changes, run: <br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
The {{Codeline|gfxpayload}} property will make sure the kernel keeps the resolution.<br />
<br />
If this method does not work for you, the deprecated <code>vga=</code> method will still work. Just<br />
add it next to the <code>"GRUB_CMDLINE_LINUX_DEFAULT="</code> line in {{Filename|/etc/default/grub}}<br />
for eg: <code>"GRUB_CMDLINE_LINUX_DEFAULT="quiet splash vga=792"</code> will give you a {{Codeline|1024x768}} resolution.<br />
<br />
You can choose one of these resolutions: {{Codeline|640×480}}, {{Codeline|800×600}}, {{Codeline|1024×768}}, {{Codeline|1280×1024}}, {{Codeline|1600×1200}}<br />
<br />
=== Other Options ===<br />
<br />
==== LVM ====<br />
<br />
If you use [[LVM]] for your {{Filename|/boot}}, add the following before menuentry lines:<br />
<br />
insmod lvm<br />
<br />
and specify your root in the menuentry as:<br />
<br />
set root=(''lvm_group_name''-''lvm_logical_boot_partition_name'')<br />
<br />
Example:<br />
<br />
# (0) Arch Linux<br />
menuentry "Arch Linux" {<br />
insmod lvm<br />
set root=(VolumeGroup-lv_boot)<br />
# you can only set following two lines<br />
linux /vmlinuz-linux root=/dev/mapper/VolumeGroup-root ro<br />
initrd /initramfs-linux.img<br />
}<br />
<br />
==== Raid ====<br />
<br />
Grub2 provides convenient handling of raid-volumes. You need to add:<br />
insmod raid<br />
<br />
which allows you to address the volume natively. E.g. {{Filename|/dev/md0}} becomes:<br />
set root=(md0)<br />
<br />
whereas a partitioned raid-volume (e.g. {{Filename|/dev/md0p1}}) becomes:<br />
set root=(md0,1)<br />
<br />
==== Persistent block device naming ====<br />
You can use UUIDs to detect partitions instead of the "old" {{Filename|/dev/sd*}} and {{Filename|/dev/hd*}} scheming. It has the advantage of detecting partitions by their unique UUIDs, which is needed by some people booting with complicated partition setups.<br />
<br />
UUIDs are used by default in the recent versions of grub2 - there is no downside in it anyway except that you need to re-generate the {{Filename|grub.cfg}} file every time you resize or reformat your partitions. Remember this when modifying partitions with Live-CD.<br />
<br />
The recent versions of grub2 use UUIDs by default. You can re-enable the use of UUIDS by simply commenting the UUID line (this is also what it looks like by default):<br />
#GRUB_DISABLE_LINUX_UUID=true<br />
you can also just set the value as {{Codeline|false}} as shown here:<br />
GRUB_DISABLE_LINUX_UUID=false<br />
<br />
Either way, do not forget to generate the changes:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
==== Using Labels ====<br />
<br />
It is possible to use labels, human-readable strings attached to filesystems, by using the {{Codeline|--label}} option to {{Codeline|search}}. First of all, label your existing partition:<br />
# tune2fs -L a <LABEL> <PARTITION><br />
<br />
Then, add an entry using labels. An example of this:<br />
<br />
menuentry "Arch Linux, session texte" {<br />
search --label --no-floppy --set=root archroot<br />
linux /boot/vmlinuz-linux root=/dev/disk/by-label/archroot ro<br />
initrd /boot/initramfs-linux.img<br />
}<br />
<br />
==== Recall previous entry ====<br />
<br />
Grub2 can remember the last entry you booted from and use this as the default entry to boot from next time. This is useful if you have multiple kernels (i.e., the current Arch one and the LTS kernel as a fallback option) or operating systems. To do this, edit {{Filename|/etc/default/grub}} and change the setting of {{Codeline|GRUB_DEFAULT}}:<br />
<br />
GRUB_DEFAULT=saved<br />
<br />
This ensures that grub will default to the saved entry. To enable saving the selected entry, add the following line to {{Filename|/etc/default/grub}}:<br />
<br />
GRUB_SAVEDEFAULT=true<br />
<br />
Remember to regenerate your configuration file.<br />
<br />
==== Security ====<br />
<br />
If you want to secure GRUB2 so it is not possible for anyone to change boot parameters or use the command line, you can add a user/password combination to GRUB2's configuration files. To do this, run the command {{Codeline|grub-mkpasswd_pbkdf2}}. Enter a password and confirm it. The output will look like this:<br />
<br />
<pre style='overflow:auto'><br />
Your PBKDF2 is grub.pbkdf2.sha512.10000.C8ABD3E93C4DFC83138B0C7A3D719BC650E6234310DA069E6FDB0DD4156313DA3D0D9BFFC2846C21D5A2DDA515114CF6378F8A064C94198D0618E70D23717E82.509BFA8A4217EAD0B33C87432524C0B6B64B34FBAD22D3E6E6874D9B101996C5F98AB1746FE7C7199147ECF4ABD8661C222EEEDB7D14A843261FFF2C07B1269A</pre>Then, add the following to {{Filename|/etc/grub.d/00_header}}:<br />
<pre>cat << EOF<br />
<br />
set superusers="username"<br />
password_pbkdf2 username <password><br />
<br />
EOF</pre><br />
where <password> is the string generated by {{Codeline|grub-mkpasswd_pbkdf2}}.<br />
<br />
Regenerate your configuration file. Your GRUB2 command line and boot parameters are now protected.<br />
<br />
=== Booting an Ubuntu ISO Image from the GRUB2 Screen ===<br />
<br />
Edit {{Filename|/etc/grub.d/40_custom}} to add an entry pointing to an Ubuntu iso:<br />
<br />
menuentry "ubuntu-11.04-desktop-amd64.iso" {<br />
set isofile="/path/to/ubuntu-11.04-desktop-amd64.iso"<br />
loopback loop (hdX,Y)$isofile<br />
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile quiet noeject noprompt splash --<br />
initrd (loop)/casper/initrd.lz<br />
}<br />
<br />
Be sure to adjust the "hdX,Y" in the third line to point to the correct disk/partition number of the isofile. When finished, update grub2's configuration file via:<br />
<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
== Using the command shell ==<br />
<br />
Since the MBR is too small to store all GRUB2 modules, only the menu and a few basic commands reside there. The majority of GRUB2 functionality remains in modules in {{Filename|/boot/grub}}, which are inserted as needed. In error conditions (e.g. if the partition layout changes) GRUB2 may fail to boot. When this happens, a command shell may appear.<br />
<br />
GRUB2 offers multiple shells/prompts. If there is a problem reading the menu but the bootloader is able to find the disk, you will likely be dropped to the "normal" shell:<br />
sh:grub><br />
<br />
If there is a more serious problem (e.g. GRUB cannot find required files), you may instead be dropped to the "rescue" shell:<br />
grub rescue><br />
<br />
The rescue shell is a restricted subset of the normal shell, offering much less functionality. If dumped to the rescue shell, first try inserting the "normal" module, then starting the "normal" shell:<br />
grub rescue> set prefix=(hdX,Y)/boot/grub<br />
grub rescue> insmod (hdX,Y)/boot/grub/normal.mod<br />
rescue:grub> normal<br />
<br />
=== Pager support ===<br />
<br />
GRUB2 supports pager for reading commands that provide long output (like the help command). This works only in normal shell mode and not in rescue mode. To enable pager, in GRUB2 command shell type:<br />
sh:grub> set pager=1<br />
<br />
== GUI configuration tools ==<br />
<br />
Following package may be installed from [[AUR]]<br />
* [http://kde-apps.org/content/show.php?content=139643 grub2-editor] (requires kdelibs)<br />
*:A KDE4 control module for configuring the GRUB2 bootloader<br />
* [http://kde-apps.org/content/show.php?content=137886 kcm-grub2] (requires kdelibs python2-qt kdebindings-python)<br />
*:This Kcm module manages the most common settings of Grub2.<br />
* [http://sourceforge.net/projects/startup-manager/ startupmanager] (requires gnome-python imagemagick yelp python2 xorg-xrandr)<br />
*:GUI app for changing the settings of GRUB, GRUB2, Usplash and Splashy<br />
<br />
== parttool or legacy hide/unhide ==<br />
<br />
If you have a win9x paradigm with hidden C disks GRUB legacy had the hide/unhide feature. In GRUB2 this has been replaced by parttool. For example, to boot the third C disk of three win9x installations on the CLI enter the CLI and:<br />
parttool hd0,1 hidden+ boot-<br />
parttool hd0,2 hidden+ boot-<br />
parttool hd0,3 hidden- boot+<br />
set root=hd0,3<br />
chainloader +1<br />
boot<br />
<br />
== Using the rescue console ==<br />
<br />
See [[#Using the command shell]] first. If unable to activate the standard shell, one possible solution is to boot using a live CD or some other rescue disk to correct configuration errors and reinstall GRUB. However, such a boot disk is not always available (nor necessary); the rescue console is surprisingly robust.<br />
<br />
The available commands in GRUB rescue include "insmod", "ls", "set", and "unset". This example uses "set" and "insmod". "set" modifies variables and "insmod" inserts new modules to add functionality.<br />
<br />
Before starting, the user must know the location of their {{Filename|/boot}} partition (be it a separate partition, or a subdirectory under their root):<br />
grub rescue> set prefix=(hdX,Y)/boot/grub<br />
<br />
where X is the physical drive number and Y is the partition number.<br />
<br />
To expand console capabilities, insert the "linux" module:<br />
grub rescue> insmod (hdX,Y)/boot/grub/linux.mod<br />
<br />
{{Note|With a separate boot partition, omit {{Filename|/boot}} from the path, (i.e. type {{Codeline|1=set prefix=(hdX,Y)/grub}} and {{Codeline|insmod (hdX,Y)/grub/linux.mod}}).}}<br />
<br />
This introduces the "linux" and "initrd" commands, which should be familiar (see [[#Configuration]]).<br />
<br />
An example, booting Arch Linux:<br />
set root=(hd0,5)<br />
linux /boot/vmlinuz-linux root=/dev/sda5<br />
initrd /boot/initramfs-linux.img<br />
boot<br />
<br />
With a separate boot partition, again change the lines accordingly:<br />
set root=(hd0,5)<br />
linux /vmlinuz-linux root=/dev/sda6<br />
initrd /initramfs-linux.img<br />
boot<br />
<br />
After successfully booting the Arch Linux installation, users can correct {{Filename|grub.cfg}} as needed and then run:<br />
# grub-install /dev/sda --no-floppy<br />
<br />
to reinstall GRUB2 and fix the problem completely, changing {{Filename|/dev/sda}} if needed. See [[#Bootloader installation]] for details.<br />
<br />
== Combining the use of UUID's and basic scripting ==<br />
<br />
If you like the idea of using UUID's to avoid unreliable BIOS mappings or are struggling with Grub's syntax, here is an example boot menu item that uses UUID's and a small script to direct Grub to the proper disk partitions for your system. All you need to do is replace the UUID's in the sample with the correct UUID's for your system. (The example applies to a system with a boot and root partition. You will obviously need to modify the Grub configuration if you have additional partitions.)<br />
<br />
menuentry "Arch Linux 64" {<br />
#Enter the UUID of your boot partition (this is where Grub and your kernel reside)<br />
set uuid_grub_boot=ece0448f-bb08-486d-9864-ac3271bd8d07<br />
<br />
#Enter the UUID of the partition containing the root partition of your Arch Linux installation. <br />
set uuid_os_root=c55da16f-e2af-4603-9e0b-03f5f565ec4a<br />
<br />
#(Note: this may be the same as your boot partition)<br />
<br />
#Here we set the Grub "root" variable by locating the UUID of the root partition identified above <br />
search --fs-uuid --no-floppy --set=root $uuid_os_root<br />
<br />
#Here we set a custom variable grub_boot by locating the UUID of the boot partition identified above <br />
search --fs-uuid --no-floppy --set=grub_boot $uuid_grub_boot<br />
<br />
#Here is the magic. We test to see if the boot and root partitions have the same UUID.<br />
#If they do, we append /boot to the $grub_boot variable. For ex. (hd0,1) becomes (hd0,1)/boot.<br />
if [ $uuid_grub_boot == $uuid_os_root ] ; then<br />
set grub_boot=$grub_boot/boot<br />
fi<br />
<br />
# $grub_boot now points to the correct location, so the following will properly find the kernel and initrd<br />
linux ($grub_boot)/vmlinuz-linux root=/dev/disk/by-uuid/$uuid_os_root ro<br />
initrd ($grub_boot)/initramfs-linux.img<br />
}<br />
<br />
== Troubleshooting ==<br />
<br />
Any troubleshooting should be added here.<br />
<br />
=== Enable GRUB2 debug messages ===<br />
<br />
Add<br />
<br />
set pager=1<br />
set debug=all<br />
<br />
to {{Filename|grub.cfg}}.<br />
<br />
=== Correct GRUB2 No Suitable Mode Found Error ===<br />
<br />
If you get this error when booting any menuentry<br />
<br />
error: no suitable mode found<br />
Booting however<br />
<br />
Then you need to initialize grub2 graphical terminal (gfxterm) with proper video mode (gfxmode) in grub2. This video mode is passed by grub2 to the linux kernel via 'gfxpayload'. In case of UEFI systems, if the grub2 video mode is not initialized, no kernel boot messages will be shown in the terminal (atleast until KMS kicks in)<br />
<br />
Copy {{Filename|/usr/share/grub/unicode.pf2}} to ${GRUB2_PREFIX_DIR} ({{Filename|/boot/grub/}} in case of BIOS systems and {{Filename|/boot/efi/efi/grub/}} in case of UEFI systems). <br />
<br />
# cp /usr/share/grub/unicode.pf2 ${GRUB2_PREFIX_DIR}<br />
<br />
If {{Filename|/usr/share/grub/unicode.pf2}} does not exist, install {{Package Official|bdf-unifont}}, create the unifont.pf2 file and then copy it to ${GRUB2_PREFIX_DIR} .<br />
<br />
# grub-mkfont -o unicode.pf2 /usr/share/fonts/misc/unifont.bdf<br />
<br />
Then, in the {{Filename|grub.cfg}} file, add the following lines to enable grub2 to pass the video mode correctly to the kernel, without of which you will only get a black screen (no output) but booting (actually) proceeds successfully without any system hang:<br />
<br />
BIOS systems<br />
<br />
insmod vbe<br />
<br />
UEFI systems<br />
<br />
insmod efi_gop<br />
insmod efi_uga<br />
<br />
After that add the following code (common to both BIOS and UEFI)<br />
<br />
insmod font<br />
<br />
if loadfont ${prefix}/unicode.pf2<br />
then<br />
insmod gfxterm<br />
set gfxmode=auto<br />
set gfxpayload=keep<br />
terminal_output gfxterm<br />
fi<br />
<br />
As you can see for gfxterm (graphical terminal) to function properly, {{Filename|unicode.pf2}} font file should exist in ${GRUB2_PREFIX_DIR}.<br />
<br />
=== msdos-style error message ===<br />
<br />
grub-setup: warn: This msdos-style partition label has no post-MBR gap; embedding won't be possible!<br />
grub-setup: warn: Embedding is not possible. GRUB can only be installed in this setup by using blocklists.<br />
However, blocklists are UNRELIABLE and its use is discouraged.<br />
grub-setup: error: If you really want blocklists, use --force.<br />
<br />
This error may occur when you try installing GRUB2 in a VMware container. Read more about it [http://bbs.archlinux.org/viewtopic.php?pid=581760#p581760 here]. It happens when the first partition starts just after the MBR (block 63), without the usual space of 1 MiB (2048 blocks) before the first partition. Read [[#MBR_aka_msdos_partitioning_specific_instructions]]<br />
<br />
=== UEFI GRUB2 not loaded ===<br />
In some cases the EFI may fail to load grub correctly. Provided everything is set up correctly, the output of<br />
efibootmgr -v<br />
might look something like this:<br />
BootCurrent: 0000<br />
Timeout: 3 seconds<br />
BootOrder: 0000,0001,0002<br />
Boot0000* Grub HD(1,800,32000,23532fbb-1bfa-4e46-851a-b494bfe9478c)File(\efi\grub\grub.efi)<br />
Boot0001* Shell HD(1,800,32000,23532fbb-1bfa-4e46-851a-b494bfe9478c)File(\EfiShell.efi)<br />
Boot0002* Festplatte BIOS(2,0,00)P0: SAMSUNG HD204UI .<br />
If everything works correctly, the EFI would now automatically load grub.<br><br />
If the screen only goes black for a second and the next boot option is tried afterwards, according to [https://bbs.archlinux.org/viewtopic.php?pid=981560#p981560 this post], moving grub to the partition root can help. The boot option has to be deleted and recreated afterwards. The entry for grub should look like this then:<br />
Boot0000* Grub HD(1,800,32000,23532fbb-1bfa-4e46-851a-b494bfe9478c)File(\grub.efi)<br />
<br />
=== Invalid signature ===<br />
If trying to boot windows results in an "invalid signature" error, e.g. after reconfiguring partitions or adding additional hard drives, (re)move grub's device configuration and let it reconfigure.<br />
# mv /boot/grub/device.map /boot/grub/device.map-old<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
Grub-mkconfig should now mention all found boot options including windows. If it works, remove /boot/grub/device.map-old.<br />
<br />
== References ==<br />
<br />
# Official GRUB2 Manual - http://www.gnu.org/software/grub/manual/grub.html<br />
# GRUB2 wiki page describing steps to compile for UEFI systems - https://help.ubuntu.com/community/UEFIBooting - previously http://grub.enbug.org/TestingOnUEFI{{Linkrot|2011|09|05}}<br />
# Wikipedia's page on [http://en.wikipedia.org/wiki/BIOS_Boot_partition BIOS Boot Partition]<br />
<br />
== External Links ==<br />
<br />
# [https://github.com/the-ridikulus-rat/My_Shell_Scripts/blob/master/grub2/grub2_bios.sh A Linux Bash Shell script to compile and install GRUB2 for BIOS from BZR Source]<br />
# [https://github.com/the-ridikulus-rat/My_Shell_Scripts/blob/master/grub2/grub2_uefi.sh A Linux Bash Shell script to compile and install GRUB2 for UEFI from BZR Source]</div>Mayweedhttps://wiki.archlinux.org/index.php?title=GRUB&diff=167970GRUB2011-10-29T18:21:54Z<p>Mayweed: </p>
<hr />
<div>[[Category:Boot loaders (English)]]<br />
{{i18n|GRUB2}}<br />
[[fr:GRUB2]]<br />
{{Article summary start}}<br />
{{Article summary text|Covers various aspects of the next generation of the GRand Unified Bootloader (GRUB2).}}<br />
{{Article summary heading|Overview}}<br />
{{Article summary text|{{Boot process overview}}}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|Burg}} - Burg is a brand-new boot loader based on GRUB2. It uses a new object format which allows it to be built in a wider range of OS, including Linux/Windows/OSX/Solaris/FreeBSD, etc. It also has a highly configurable menu system which works in both text and graphic mode. <br />
{{Article summary heading|Resources}}<br />
{{Article summary link|GNU GRUB -- GNU Project|http://www.gnu.org/software/grub/}}<br />
{{Article summary link|GNU GRUB Wiki|http://grub.enbug.org/}}{{Linkrot|2011|09|05}}<br />
{{Article summary end}}<br />
<br />
[http://www.gnu.org/software/grub/ GRUB2] is the next generation of the GRand Unified Bootloader (GRUB). GRUB2 is derived from [http://www.nongnu.org/pupa/ PUPA] which was a research project to investigate the next generation of GRUB. GRUB 2 has been rewritten from scratch to clean up everything and provide modularity and portability [http://www.gnu.org/software/grub/grub-faq.en.html#q1].<br />
<br />
Briefly, the ''bootloader'' is the first software program that runs when a computer starts. It is responsible for loading and transferring control to the Linux kernel. The kernel, in turn, initializes the rest of the operating system.<br />
<br />
== Preface ==<br />
<br />
Although, [[GRUB]] (i.e. version 0.9x) is the de facto standard bootloader of Linux, it is considered 'legacy' by upstream. It is being replaced by GRUB2 in many distributions. Upstream recommends GRUB2 >=1.99~rc2 over grub-legacy, even for current grub-legacy users.<br />
<br />
{{Note|grub2 from 1.99~rc2 and later supports btrfs as root (without a separate /boot filesystem).}}<br />
<br />
=== Notes for current GRUB users ===<br />
<br />
* There are differences in the commands of GRUB and GRUB2. Familiarize yourself with [http://www.gnu.org/software/grub/manual/grub.html#Commands GRUB2 commands] before proceeding (e.g. "find" has been replaced with "search").<br />
<br />
* GRUB2 is now ''modular'' and no longer requires "stage 1.5". As a result, the bootloader itself is limited -- modules are loaded from the hard drive as needed to expand functionality (e.g. for [[LVM]] or RAID support).<br />
<br />
* Device naming has changed between GRUB and GRUB2. Partitions are numbered from 1 instead of 0 while drives are still numbered from 0, and prefixed with partition-table type. For example, {{Filename|/dev/sda1}} would be referred to as {{Codeline|(hd0,msdos1)}} (for MBR) or {{Codeline|(hd0,gpt1)}} (for GPT) using GRUB2.<br />
<br />
===== Preliminary Considerations for GRUB2 BIOS =====<br />
<br />
====== [[GPT]] specific instructions ======<br />
<br />
GRUB2 in BIOS-GPT configuration requires a BIOS Boot Partition to embed its core.img in the absence of post-MBR gap in GPT partitioned systems (which is taken over by the GPT Primary Header and Primary Partition table). This partition is used by GRUB2 only in BIOS-GPT setups. No such partition type exists in case of MBR partitioning (at least not for GRUB2). This partition is also not required if the system is UEFI based, as no embedding of bootsectors takes place in that case. Syslinux does not require this partition.<br />
<br />
For a BIOS-GPT configuration, create a 2 MiB partition using cgdisk or GNU Parted with no filesystem. The location of the partition in the partition table does not matter but it should be within the first 2 TiB region of the disk. It is advisable to put it somewhere in the beginning of the disk before the /boot partition. Set the partition type to "EF02" in cgdisk or {{Codeline|set <BOOT_PART_NUM> bios_grub on}} in GNU Parted.<br />
<br />
{{Note|This partition should be created before grub_bios-install or grub-setup is run or before the '''Install Bootloader''' step of the Archlinux installer (if GRUB2 is selected as bootloader).}}<br />
<br />
====== [[MBR]] aka msdos partitioning specific instructions ======<br />
<br />
Usually the post-MBR gap (after the 512 byte MBR region and before the start of the 1st partition) in many MBR (or msdos disklabel) partitioned systems is 32 KiB when DOS compatibility cylinder alignment issues are satisfied in the partition table. However a post-MBR gap of about 1 to 2 MiB is recommended to provide sufficient room for embedding grub2's core.img ( https://bugs.archlinux.org/task/24103 ). It is advisable to use a partitioner which supports 1 MiB partition alignment to obtain this space as well as satisfy other non-512 byte sector issues (which are unrelated to embedding of core.img).<br />
<br />
If you do not dual-boot with MS Windows (any version) in BIOS systems, it is advisable to switch to GPT partitioning - [[GUID_Partition_Table#Convert_from_MBR_to_GPT_without_data_loss]]<br />
{{Note|Create the 2MiB partition mentioned above BEFORE you convert to GPT. If you do not, gparted will not resize your boot partition to allow its creation, and when you reboot grub2 will not know where to look.}}<br />
<br />
== Installation ==<br />
<br />
=== During Arch Linux installation ===<br />
<br />
* Skip the '''Install Bootloader''' step and exit the installer.<br />
* Configure the network:<br />
# aif -p partial-configure-network<br />
This will bring up a prompt; put in the network interface to use, (e.g., eth0) and use DHCP for easy configuration.<br />
* If you did not configure the installed system's {{Filename|/etc/resolv.conf}} file during installation (for instance, if you plan to let DHCP generate it later), you will need to copy the one generated by AIF when it configured the network:<br />
# cp /etc/resolv.conf /mnt/etc/resolv.conf<br />
* Load the dm-mod module (you might need grub2-bios; install the package if needed):<br />
# modprobe dm-mod<br />
{{Note|This is necessary at this point, and cannot be postponed after the chroot. If you try to use modprobe in a chroot environment that has a later kernel version from that of the installing device (at the time of writing, 2.6.33), modprobe will fail. This happens routinely using the Arch "net" installations.}}<br />
* From the installer's live shell, chroot to the installed system:<br />
# mount -o bind /dev /mnt/dev<br />
# chroot /mnt bash<br />
* Update pacman's database:<br />
# pacman-db-upgrade<br />
* Refresh the package list (with an extra -y flag to force a refresh of all package lists even if they appear to be up to date):<br />
# pacman -Syy<br />
* Install the GRUB2 package as mentioned in the section [[#From a running Arch Linux]]. Note that the dm-mod module has already been loaded, no need to do that again.<br />
<br />
=== From a running Arch Linux ===<br />
<br />
====Make a backup of your precious data====<br />
In general, a grub installation ran smoothly and you got no problems at all. And sometimes it could simply messed up your system. You're strongly advised to make a backup before even think of grub2.<br />
<br />
*copy grub modules and configuration<br />
# cp -a /boot/grub /path/to/backup/<br />
*backup the MBR and GRUB stage 1.5<br />
# dd if=/dev/sda of=/path/to/backup/first-sectors count=63<br />
<br />
You could now lightly remove {{Filename|/boot/grub}} with:<br />
# rm -rf /boot/grub<br />
<br />
and follow the instructions below.You know that if things get nasty, you could reboot your system thanks to an installation media and :<br />
<br />
*move old grub2 files out of the way<br />
# mv /boot/grub /boot/grub.nonfunctional<br />
*copy grub back to /boot<br />
# cp -a /path/to/backup/grub /boot/<br />
*replace MBR and next 62 sectors of sda with backed up copy (DANGEROUS!)<br />
# dd if=/path/to/backup/first-sectors of=/dev/sda count=63<br />
<br />
<br />
===== grub2-bios-install =====<br />
<br />
The GRUB2 package can be installed with pacman (and will replace {{Package Official|grub}}, if it is installed):<br />
<br />
# pacman -S grub2-bios<br />
<br />
{{Note|Installing grub2-common (a dependency of grub2-bios) 1.99~rc1 or later, may take forever in some systems since the post_install script runs grub-mkconfig and this script does not provide the option <code>--no-floppy</code>. For more details search this option in the article.}}<br />
<br />
{{Note|Simply installing the package won't update the /boot/grub/core.img file and the grub2 modules in /boot/grub . You need to update the core.img file and the grub2 modules manually using grub_bios-install as explained below.}}<br />
<br />
Also load the device-mapper kernel module without which grub-probe does not reliably detect disks and partitions<br />
<br />
# modprobe dm-mod<br />
<br />
<br />
===== Run grub_bios-install =====<br />
<br />
There are 3 ways to install grub2 in BIOS booting - [[#Install_to_440-byte_MBR_boot_code_region]] (recommended) , [[#Install_to_Partition_or_Partitionless_Disk]] (not recommended) or [[#Generate_core.img_alone]] (safest method, but requires another BIOS bootloader like [[grub-legacy]] or [[syslinux]] to be installed to chainload {{Filename|/boot/grub/core.img}} ). For all the ways [[#Before_grub_bios-install]] step is needed.<br />
<br />
====== Install to 440-byte MBR boot code region ======<br />
<br />
To setup grub2-bios in the 440-byte Master Boot Record boot code region, populate the {{Filename|/boot/grub}} directory, generate the {{Filename|/boot/grub/core.img}} file, and embed it in the 32 KiB (minimum size - varies depending on partition alignment) post-MBR gap (MBR disks) or in BIOS Boot Partition (GPT disks), run<br />
<br />
# grub_bios-install --boot-directory=/boot --no-floppy --recheck /dev/sda<br />
<br />
where {{Filename|/dev/sda}} is the destination of the installation (in this case the MBR of the first SATA disk). If you use [[LVM]] for your {{Filename|/boot}}, you can install GRUB2 on multiple physical disks. <br />
<br />
The {{Codeline|--no-floppy}} tells grub2-bios utilities not to search for any floppy devices which reduces the overall execution time of grub_bios-install on many systems (it will also prevent the issue below from occuring). Otherwise you get an error like this<br />
<br />
grub-probe: error: Cannot get the real path of '/dev/fd0'<br />
Auto-detection of a filesystem module failed.<br />
Please specify the module with the option '--modules' explicitly.<br />
<br />
Follow [[#Generate_GRUB2_BIOS_Config_file]] or if that fails, convert your {{Filename|/boot/grub/menu.lst}} file to {{Filename|/boot/grub/grub.cfg}} using:<br />
<br />
# grub-menulst2cfg /boot/grub/menu.lst /boot/grub/grub.cfg<br />
<br />
For example:<br />
<br />
{{File|name=/boot/grub/menu.lst|content=<br />
default=0<br />
timeout=5<br />
<br />
title Arch Linux Stock Kernel<br />
root (hd0,0)<br />
kernel /vmlinuz-linux root=/dev/sda2 ro<br />
initrd /initramfs-linux.img<br />
<br />
title Arch Linux Stock Kernel Fallback<br />
root (hd0,0)<br />
kernel /vmlinuz-linux root=/dev/sda2 ro<br />
initrd /initramfs-linux-fallback.img<br />
}}<br />
<br />
{{File|name=/boot/grub/grub.cfg|content=<br />
set default='0'; if [ x"$default" = xsaved ]; then load_env; set default="$saved_entry"; fi<br />
set timeout=5<br />
<br />
menuentry 'Arch Linux Stock Kernel' {<br />
set root='(hd0,1)'; set legacy_hdbias='0'<br />
legacy_kernel '/vmlinuz-linux' '/vmlinuz-linux' 'root=/dev/sda2' 'ro'<br />
legacy_initrd '/initramfs-linux.img' '/initramfs-linux.img'<br />
<br />
}<br />
<br />
menuentry 'Arch Linux Stock Kernel Fallback' {<br />
set root='(hd0,1)'; set legacy_hdbias='0'<br />
legacy_kernel '/vmlinuz-linux' '/vmlinuz-linux' 'root=/dev/sda2' 'ro'<br />
legacy_initrd '/initramfs-linux-fallback.img' '/initramfs-linux-fallback.img'<br />
}<br />
}}<br />
<br />
<br />
If you forgot to create a GRUB2 {{Filename|/boot/grub/grub.cfg}} configfile and simply rebooted into GRUB2 Command Shell, type:<br />
<br />
sh:grub> insmod legacycfg<br />
sh:grub> legacy_configfile ${prefix}/menu.lst<br />
<br />
Boot into Arch and re-create the proper GRUB2 {{Filename|/boot/grub/grub.cfg}} configfile.<br />
<br />
{{Note|This option works only in BIOS systems, not in UEFI systems.}}<br />
<br />
====== Install to Partition or Partitionless Disk ======<br />
<br />
{{Note|grub2-bios (any version - including upstream bzr repo) does not encourage installation to a partition boot sector or a partitionless disk like grub-legacy or syslinux does. Neither do the Arch devs.}}<br />
<br />
To setup grub2-bios to a partition boot sector, to a partitionless disk (also called superfloppy) or to a floppy disk, run (using for example /dev/sda1 as the /boot partition)<br />
<br />
# chattr -i /boot/grub/core.img<br />
# grub_bios-install --boot-directory=/boot --no-floppy --recheck --force /dev/sda1<br />
# chattr +i /boot/grub/core.img<br />
<br />
You need to use the {{Codeline|--force}} option to allow usage of blocklists and should not use <code>--grub-setup=/bin/true</code> (which is similar to simply generating core.img).<br />
<br />
grub_bios-install will give out warnings like which should give you the idea of what might go wrong with this approach.<br />
<br />
/sbin/grub-setup: warn: Attempting to install GRUB to a partitionless disk or to a partition. This is a BAD idea.<br />
/sbin/grub-setup: warn: Embedding is not possible. GRUB can only be installed in this setup by using blocklists. <br />
However, blocklists are UNRELIABLE and their use is discouraged.<br />
<br />
Without {{Codeline|--force}} you may get the below error and grub-setup will not setup its boot code in the partition boot sector.<br />
<br />
/sbin/grub-setup: error: will not proceed with blocklists<br />
<br />
With {{Codeline|--force}} you should get<br />
<br />
Installation finished. No error reported.<br />
<br />
The reason why grub-setup does not by default allow this is because in case of partition or a partitionless disk is that grub2-bios relies on embedded blocklists in the partition bootsector to locate the {{Filename|/boot/grub/core.img}} file and the prefix dir {{Filename|/boot/grub}} . The sector locations of {{Filename|core.img}} may change whenever the filesystem in the partition is being altered (files copied, deleted etc.). For more info see https://bugzilla.redhat.com/show_bug.cgi?id=728742 and https://bugzilla.redhat.com/show_bug.cgi?id=730915 .<br />
<br />
The workaround for this is to set the immutable flag on {{Filename|/boot/grub/core.img}} (using chattr command as mentioned above) so that the sector locations of the {{Filename|core.img}} file in the disk is not altered. The immutable flag on {{Filename|/boot/grub/core.img}} needs to be set only if grub2-bios is installed to a partition boot sector or a partitionless disk, not in case of installtion to MBR or simple generation of {{Filename|core.img}} without embedding any bootsector (mentioned above). <br />
<br />
====== Generate core.img alone ======<br />
<br />
To populate the {{Filename|/boot/grub}} directory and generate a {{Filename|/boot/grub/core.img}} file WITHOUT embedding any grub2-bios bootsector code in the MBR, post-MBR region, or the partition bootsector, add <code>--grub-setup=/bin/true</code> to grub_bios-install:<br />
<br />
# grub_bios-install --grub-setup=/bin/true --boot-directory=/boot --no-floppy --recheck /dev/sda<br />
<br />
You can then chainload grub2's core.img from grub-legacy or syslinux as a Linux kernel or a multiboot kernel.<br />
<br />
===== After grub_bios-install =====<br />
<br />
====== Generate GRUB2 BIOS Config file ======<br />
<br />
Finally, generate a configuration for grub2 (this is explained in greater detail in the Configuration section):<br />
<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
If grub2 complains about "no suitable mode found" while booting, go to [[#Correct_GRUB2_No_Suitable_Mode_Found_Error]] .<br />
<br />
===== Multiboot in BIOS =====<br />
<br />
====== Boot Microsoft Windows installed in BIOS-MBR mode ======<br />
<br />
{{Note|GRUB2 supports booting {{Filename|bootmgr}} directly and chainload of partition boot sector is no longer required to boot Windows in a BIOS-MBR setup.}}<br />
<br />
Find the UUID of the NTFS filesystem of the Windows's SYSTEM PARTITION where the bootmgr and its files reside. For example, if Windows {{Filename|bootmgr}} exists at {{Filename|/media/Windows/bootmgr}}:<br />
<br />
# grub-probe --target=fs_uuid /media/Windows/bootmgr<br />
69B235F6749E84CE<br />
<br />
Then, add the below code to {{Filename|/boot/grub/grub.cfg}} to chainload Windows (Vista, 7 or 8) installed in BIOS-MBR mode :<br />
<br />
menuentry "Microsoft Windows 7 BIOS-MBR" {<br />
insmod part_msdos<br />
insmod ntfs<br />
insmod search_fs_uuid<br />
insmod ntldr <br />
search --fs-uuid --no-floppy --set=root 69B235F6749E84CE<br />
ntldr (${root})/bootmgr<br />
}<br />
<br />
For Windows XP<br />
<br />
menuentry "Microsoft Windows XP" {<br />
insmod part_msdos<br />
insmod ntfs<br />
insmod search_fs_uuid<br />
insmod ntldr <br />
search --fs-uuid --no-floppy --set=root 69B235F6749E84CE<br />
ntldr (${root})/ntldr<br />
}<br />
<br />
==== [[UEFI]] systems ====<br />
<br />
===== Before grub_efi_${UEFI_ARCH}-install =====<br />
<br />
{{Note|Unless specified as EFI 1.x , EFI and UEFI terms are used interchangeably to denote UEFI 2.x firmware. Also unless stated explicitely, the instructions are general and not Mac specific. Some of them may not work or may be different in Macs. Apple's EFI implementation is neither a EFI 1.x version nor UEFI 2.x version but mixes up both. This kind of firmware does not fall under any one UEFI Specification version and is therefore not a standard UEFI firmware.}}<br />
<br />
GRUB2 UEFI bootloader is available in Arch Linux only from version 1.99~rc1 . To install, first [https://wiki.archlinux.org/index.php/Unified_Extensible_Firmware_Interface#Detecting_UEFI_Firmware_Arch Detect which UEFI firmware arch] you have (either x86_64 or i386).<br />
<br />
Depending on that, install the appropriate package<br />
<br />
For 64-bit aka x86_64 UEFI firmware:<br />
# pacman -S grub2-efi-x86_64<br />
<br />
For 32-bit aka i386 UEFI firmware:<br />
# pacman -S grub2-efi-i386<br />
<br />
{{Note|Installing grub2-common (a dependency of grub2-bios) 1.99~rc1 or later, may take forever in some systems since the post_install script runs grub-mkconfig and this script does not provide the option <code>--no-floppy</code>. For more details search this option in the article.}}<br />
<br />
{{Note|Simply installing the package won't update the grub.efi file and the grub2 modules in the UEFI System Partition . You need to update the grub.efi file and the grub2 modules in the UEFI System Partition manually using grub_efi_${UEFI_ARCH}-install as explained below.}}<br />
<br />
Also load the device-mapper kernel module without which grub-probe does not reliably detect disks and partitions<br />
<br />
# modprobe dm-mod<br />
<br />
===== Install to UEFI SYSTEM PARTITION =====<br />
<br />
====== Mount UEFI SYSTEM PARTITION ======<br />
<br />
Mount the [https://wiki.archlinux.org/index.php/Unified_Extensible_Firmware_Interface#Creating_a_UEFI_SYSTEM_PARTITION_in_Linux UEFI SYSTEM PARTITION] in your system at {{Filename|/boot/efi}}. It should be FAT32 formatted and should be at least 200 MiB in size. If you have mounted the UEFISYS partition in some other mountpoint, replace {{Filename|/boot/efi}} in the below commands with that mountpoint:<br />
<br />
# mkdir -p /boot/efi<br />
# mount -t vfat <UEFISYS_PART_DEVICE> /boot/efi<br />
# mkdir -p /boot/efi/efi<br />
<br />
====== Run grub_efi_${UEFI_ARCH}-install ======<br />
<br />
{{Note|The below commands assume you are using {{Codeline|grub2-efi-x86_64}} (for {{Codeline|grub2-efi-i386}} replace {{Codeline|x86_64}} with {{Codeline|i386}} in the below commands).}}<br />
<br />
# grub_efi_x86_64-install --root-directory=/boot/efi --boot-directory=/boot/efi/efi --bootloader-id=grub --no-floppy --recheck<br />
<br />
The {{Codeline|grub_efi_x86_64-install}} automatically generates a {{Filename|grub.efi}} while setting up the {{Filename|/boot/efi/efi/grub/}} directory.<br />
<br />
If you notice carefully, there is no <device_path> option (Eg: {{Filename|/dev/sda}}) at the end of the {{Codeline|grub_efi_x86_64-install}} command unlike the case of setting up grub2 for BIOS systems. Any <device_path> provided will be ignored by the install script as UEFI bootloaders do not use MBR or Partition boot sectors at all.<br />
<br />
You may now be able to UEFI boot your system by creating a grub.cfg file using grub-mkconfig and copying /boot/efi/efi/grub/grub.efi to /boot/efi/efi/boot/bootx64.efi.<br />
<br />
===== After grub_efi_${UEFI_ARCH}-install =====<br />
<br />
====== Launch GRUB2 as default in non-Mac UEFI systems ======<br />
<br />
{{Note|The below steps will not work if the system has been booted in BIOS mode and will not work if the UEFI processor architecture does not match the kernel one, i.e. x86_64 UEFI + ix86 32-bit Kernel and vice-versa config will not work.}}<br />
<br />
grub_efi_${UEFI_ARCH}-install will ensure {{Filename|/boot/efi/efi/grub/grub.efi}} is launched by default if it detects {{Codeline|efibootmgr}} and if it is able to access UEFI Runtime Services. {{Codeline|efibootmgr}} command will work only if you have booted the system in UEFI mode itself, since it '''requires access to UEFI Runtime Variables''' which are '''available only in UEFI boot mode''' (with "noefi" kernel parameter NOT being used). Initially the user is required to manually launch {{Filename|/boot/efi/efi/grub/grub.efi}} from the firmware itself (using maybe the UEFI Shell) if grub2-efi was installed in BIOS mode. Then {{Codeline|efibootmgr}} should be run to make grub2 as the default entry in the UEFI Boot Manager<br />
<br />
First boot into UEFI mode manually either using the firmware boot menu, UEFI shell, or using any UEFI capable bootable iso (Archboot or Ubuntu non-Mac iso). Use grub probe to determine the device path of your EFI System Partition:<br />
# grub-probe --target=device /boot/efi/efi/grub/grub.efi<br />
<br />
It should give something like {{Filename|/dev/sda1}} (used as example in the remaining steps). Load 'efivars' kernel module:<br />
# modprobe efivars<br />
<br />
If you get '''no such device found''' error for this command, that means you have not booted in UEFI mode or due to some reason the kernel is unable to access UEFI Runtime Variables.<br />
<br />
Verify whether there are files in ''/sys/firmware/efi/vars/'' directory. This directory and its contents are created by "efivars" kernel module and it will exist only if you have booted in UEFI mode without the "noefi" kernel parameter.<br />
<br />
# ls -1 /sys/firmware/efi/vars/<br />
<br />
Sample output (x86_64-UEFI 2.3.1 in x86_64 Kernel:<br />
<br />
# ls -1 /sys/firmware/efi/vars/<br />
Boot0000-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootCurrent-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootOptionSupport-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootOrder-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConIn-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConInDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConOut-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConOutDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ErrOutDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
Lang-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
LangCodes-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
MTC-eb704011-1402-11d3-8e77-00a0c969723b/<br />
MemoryTypeInformation-4c19049f-4137-4dd3-9c10-8b97a83ffdfa/<br />
PlatformLang-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
PlatformLangCodes-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
RTC-378d7b65-8da9-4773-b6e4-a47826a833e1/<br />
del_var<br />
new_var<br />
<br />
If ''/sys/firmware/efi/vars/'' directory is empty or does not exist, then {{Codeline|efibootmgr}} command will not work. If you are unable to make the ISO/CD/DVD/USB boot in UEFI mode try https://gitorious.org/tianocore_uefi_duet_builds/pages/Linux_Windows_BIOS_UEFI_boot_USB .<br />
<br />
If ''/sys/firmware/efi/vars/'' directory (along with the exists then run {{Codeline|efibootmgr}} and reboot:<br />
<br />
# efibootmgr --create --gpt --disk /dev/sda --part 1 --write-signature --label "GRUB2" --loader "\\EFI\\grub\\grub.efi"<br />
<br />
In the above command, {{Filename|/boot/efi/efi/grub/grub/efi}} can be split up as {{Filename|/boot/efi}} and {{Filename|/efi/grub/grub.efi}}, which translates to {{Filename|(/dev/sda)}} -> partition 1 -> {{Filename|\\EFI\\grub\\grub.efi}}. <br />
<br />
FAT32 filesystem is case-insensitive since it does not use UTF-8 encoding by default. In that case the firmware uses capital 'EFI' instead of small 'efi', therefore using {{Filename|\\EFI\\grub\\grub.efi}} or {{Filename|\\efi\\grub\\grub.efi}} does not matter (this will change if the filesystem encoding is UTF-8). UEFI uses backward slash as path separatoir (similar to Windows paths). In the above command "double" backward slashes are used instead of single ones, since a backward slash is used as a escape character by sh shells, the first backward slash escapes the second one so that the path {{Filename|\EFI\grub\grub.efi}} is passed to {{Codeline|efibootmgr}}.<br />
<br />
The 'label' is the name of the menu entry shown in the UEFI boot menu. This name is user's choice and does not affect the booting of the system. More info can be obtained from [http://linux.dell.com/cgi-bin/gitweb/gitweb.cgi?p=efibootmgr.git;a=blob_plain;f=README;hb=HEAD efibootmgr GIT README]<br />
<br />
If you have problems running GRUB2 in UEFI mode you can try the following (worked on an ASUS Z68 mainboard):<br />
<br />
# cp /boot/efi/efi/grub/grub.efi /boot/efi/shellx64.efi<br />
<br />
or<br />
<br />
# cp /boot/efi/efi/grub/grub.efi /boot/efi/efi/shellx64.efi<br />
or<br />
<br />
# cp /boot/efi/efi/grub/grub.efi /boot/efi/efi/shell/shellx64.efi<br />
<br />
After this launch the UEFI Shell from the UEFI setup/menu (in ASUS UEFI BIOS, switch to advanced mode, press Exit in the top right corner and choose "Launch EFI shell from filesystem device"). The grub2 menu will show up and you can boot into your system. Afterwards you can use efibootmgr to setup a menu entry (see above).<br />
<br />
====== Launch GRUB2 as default in Apple Mac EFI systems ======<br />
<br />
{{Note|Using {{Filename|efibootmgr}} in Apple Macs will brick the firmware and may need reflash of the motherboard ROM. There have been bug reports regarding this in Ubuntu/Launchpad bug tracker. Use bless command alone in case of Macs}}<br />
<br />
Use bless command from within Mac OS X to setup {{Filename|grub.efi}} as the default boot option. More info at https://help.ubuntu.com/community/UEFIBooting#Apple_Mac_EFI_systems_.28both_EFI_architecture.29 .<br />
<br />
====== Generate GRUB2 UEFI Config file ======<br />
<br />
Finally, generate a configuration for grub2 (this is explained in greater detail in the Configuration section):<br />
<br />
# grub-mkconfig -o /boot/efi/efi/grub/grub.cfg<br />
<br />
If grub2-uefi complains about "no suitable mode found" while booting, go to [[#Correct_GRUB2_No_Suitable_Mode_Found_Error]] .<br />
<br />
===== Generate a custom GRUB2 UEFI Application =====<br />
<br />
If you want, you can create a custom {{Filename|grub_custom.efi}} app using:<br />
# grub-mkimage -d /usr/lib/grub/x86_64-efi -O x86_64-efi -p "" -o /boot/efi/efi/grub/grub_custom.efi <GRUB2_Modules_to_be_included><br />
<br />
{{Note|The '''-p''' option is important for creating a portable {{Filename|grub_custom.efi}} app.}}<br />
<br />
There is no file-size restriction on {{Filename|grub_custom.efi}} either due to GRUB2 or due to the UEFI firmware. Therefore you can include any number of modules you want.<br />
<br />
A "{{Filename|grub.cfg}}" created for BIOS based GRUB2 will be sufficient for the UEFI GRUB2 as long as all the paths in the config are absolute paths. The {{Filename|grub.cfg}} file should exist in the same directory as {{Filename|grub.efi}} or {{Filename|grub_custom.efi}}.<br />
<br />
The {{Filename|grub.efi}} UEFI application can be launched using the firmware's "Boot Manager", "Boot from file" option or using the [https://wiki.archlinux.org/index.php/UEFI#UEFI_Shell UEFI Shell].<br />
<br />
Alternatively, you can also setup {{Filename|/boot/efi/efi/grub}} directory by copying all the files in {{Filename|/usr/lib/grub/x86_64-efi}} to {{Filename|/boot/efi/efi/grub}} and using the above grub-mkimage command to create a {{Filename|grub_custom.efi}} application. Just make sure you have the required modules embedded in {{Filename|grub_custom.efi}} to enable it to access the EFI SYSTEM PARTITION.<br />
<br />
A basic {{Filename|grub_custom.efi}} can be generated using the following command:<br />
# sudo grub-mkimage -d /usr/lib/grub/x86_64-efi -O x86_64-efi -p "" -o /boot/efi/efi/grub/grub_custom.efi part_gpt fat iso9660 udf normal chain linux \<br />
ls search search_fs_file search_fs_uuid search_label help boot configfile echo efi_gop<br />
<br />
===== Multiboot in UEFI =====<br />
<br />
====== Chainload Microsoft Windows x86_64 UEFI-GPT ======<br />
<br />
Find the UUID of the FAT32 filesystem in the UEFI SYSTEM PARTITION where the Windows UEFI Bootloader files reside. For example, if Windows {{Filename|bootmgfw.efi}} exists at {{Filename|/boot/efi/efi/Microsoft/Boot/bootmgfw.efi}} (ignore the upper-lower case differences since that is immaterial in FAT filesystem):<br />
<br />
# grub-probe --target=fs_uuid /boot/efi/efi/Microsoft/Boot/bootmgfw.efi<br />
1ce5-7f28<br />
<br />
Then, add this code to {{Filename|/boot/efi/efi/grub/grub.cfg}} to chainload Windows x86_64 (Vista SP1+, 7 or 8) installed in UEFI-GPT mode :<br />
<br />
menuentry "Microsoft Windows x86_64 UEFI-GPT" {<br />
insmod part_gpt<br />
insmod fat<br />
insmod search_fs_uuid<br />
insmod chain<br />
search --fs-uuid --no-floppy --set=root 1ce5-7f28<br />
chainloader (${root})/efi/Microsoft/Boot/bootmgfw.efi<br />
}<br />
<br />
== Manual Compilation ==<br />
<br />
=== For BIOS Systems ===<br />
<br />
GRUB2 for BIOS systems should be compiled as follows:<br />
<pre><br />
./autogen.sh<br />
<br />
./configure --with-platform=pc --prefix=/usr<br />
<br />
make<br />
<br />
make install<br />
</pre><br />
<br />
The <code>--with-platform=pc</code> generates grub2 for bios alone irrespective of the firmware of the build system.<br />
<br />
=== For UEFI Systems ===<br />
<br />
First [https://wiki.archlinux.org/index.php/Unified_Extensible_Firmware_Interface#Detecting_UEFI_Firmware_Arch Detect which UEFI Firmware arch] you have and then follow the compile instructions below:<br />
<pre><br />
./autogen.sh<br />
<br />
./configure --with-platform=efi --target=TARGET_UEFI_ARCH --prefix=/usr<br />
<br />
make<br />
<br />
make install<br />
</pre><br />
<br />
The "--target" option denotes the UEFI firmware arch. for which grub2 should be compiled, not the architecture of the linux kernel grub2 may boot. <br />
<br />
It is possible to use UEFI 64-bit firmware + GRUB2 as x86_64-EFI app loading a i686 linux kernel, as long as the kernel does not try to access UEFI Runtime Services. Vice-versa situation is also possible. But a x86_64 UEFI firmware cannot launch GRUB2 i386-efi app (unlike x86_64 Operating Systems), and a i386 UEFI firmware will not launch GRUB2 {{Codeline|x86_64-efi}} app. It is important to compile GRUB2 to match the architecture of the UEFI firmware.<br />
<br />
== Configuration ==<br />
<br />
The configuration files are {{Filename|/etc/default/grub}} and {{Filename|/etc/grub.d/*}}. These files are used to generate the {{Filename|/boot/grub/grub.cfg}} file. You can also choose to manually edit {{Filename|grub.cfg}}.<br />
<br />
=== grub-mkconfig ===<br />
<br />
The grub-mkconfig script can be used to generate a {{Filename|grub.cfg}} file. By default the script outputs to stdout. Note that gettext ― an optional dependency of the GRUB2 package ― is required by the grub-mkconfig script. To generate a {{Filename|grub.cfg}} file run the command:<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
Note that grub-mkconfig probably has your grub directory hardcoded to /boot/grub, which is probably wrong if you're using UEFI. Either mount your efi grub directory at /boot/grub or edit the script.<br />
<br />
=== grub.cfg ===<br />
<br />
A basic grub file uses the following options<br />
* {{Codeline|(hdX,Y)}} is the partition {{Codeline|Y}} on disk {{Codeline|X}}, partition numbers starting at 1, disk numbers starting at 0<br />
* {{Codeline|1=set default=N}} is the default boot entry that is chosen after timeout for user action<br />
* {{Codeline|1=set timeout=M}} is the time {{Codeline|M}} to wait in seconds for a user selection before default is booted<br />
* {{Codeline|<nowiki>menuentry "title" {entry options}</nowiki>}} is a boot entry titled {{Codeline|title}}<br />
* {{Codeline|1=set root=(hdX,Y)}} sets the boot partition, where the kernel and GRUB modules are stored (boot need not be a separate partition, and may simply be a directory under the "root" partition ({{Filename|/}})<br />
<br />
An example configuration:<br />
<br />
{{File<br />
|name=/boot/grub/grub.cfg<br />
|content=<nowiki><br />
# Config file for GRUB2 - The GNU GRand Unified Bootloader<br />
# /boot/grub/grub.cfg<br />
<br />
# DEVICE NAME CONVERSIONS<br />
#<br />
# Linux Grub<br />
# -------------------------<br />
# /dev/fd0 (fd0)<br />
# /dev/sda (hd0)<br />
# /dev/sdb2 (hd1,2)<br />
# /dev/sda3 (hd0,3)<br />
#<br />
<br />
# Timeout for menu<br />
set timeout=5<br />
<br />
# Set default boot entry as Entry 0<br />
set default=0<br />
<br />
# (0) Arch Linux<br />
menuentry "Arch Linux" {<br />
set root=(hd0,1)<br />
linux /vmlinuz-linux root=/dev/sda3 ro<br />
initrd /initramfs-linux.img<br />
}<br />
<br />
## (1) Windows<br />
#menuentry "Windows" {<br />
#set root=(hd0,3)<br />
#chainloader +1<br />
#}<br />
</nowiki>}}<br />
<br />
=== Dual-booting ===<br />
<br />
''NOTE: If you want GRUB2 to automatically search for other systems, for example as in Ubuntu. Then you may need to download {{Package AUR|os-prober}} from the [[AUR]].''<br />
<br />
==== Using grub-mkconfig ====<br />
The best way to add other entries is editing the {{Filename|/etc/grub.d/40_custom}}. The entries in this file will be automatically added when running '''grub-mkconfig'''.<br />
After adding the new lines, run:<br />
# grub-mkconfig -o /boot/grub/grub.cfg <br />
to generate an updated {{Filename|grub.cfg}}.<br />
<br />
===== With GNU/Linux =====<br />
<br />
Assuming that the other distro is on partition {{Filename|sda2}}:<br />
<br />
menuentry "Other Linux" {<br />
set root=(hd0,2)<br />
linux /boot/vmlinuz (add other options here as required)<br />
initrd /boot/initrd.img (if the other kernel uses/needs one)<br />
}<br />
<br />
===== With Windows =====<br />
<br />
This assumes that your Windows partition is {{Filename|sda3}}.<br />
<br />
# (2) Windows XP<br />
menuentry "Windows XP" {<br />
set root=(hd0,3)<br />
chainloader (hd0,3)+1<br />
}<br />
<br />
If the windows bootloader is on an entirely different harddrive than grub, it may be necessary to trick Windows into believing that it is in fact the first harddrive. This was possible in the old grub with {{Codeline|map}} and is now done with {{Codeline|drivemap}}. Assume grub is on {{Filename|hd0}} and windows on {{Filename|hd2}}, you need to add the following after {{Codeline|set root}}:<br />
<br />
drivemap -s hd0 hd2<br />
<br />
==== With Windows via EasyBCD and NeoGRUB ====<br />
<br />
Since EasyBCD's NeoGRUB currently does not understand the GRUB2 menu format, chainload to it by replacing the contents of your {{Filename|C:\NST\menu.lst}} file with lines similar to the following:<br />
<br />
default 0<br />
timeout 1<br />
<br />
title Chainload into GRUB v2<br />
root (hd0,7)<br />
kernel /boot/grub/core.img<br />
<br />
===Visual Configuration===<br />
<br />
In GRUB2 it is possible, by default, to change the look of the menu.<br />
<br />
====Background image and bitmap fonts====<br />
<br />
GRUB2 comes with support for background images and bitmap fonts in pf2 format. The unifont font is included in the grub2 package under the filename {{Filename|unicode.pf2}}, or, as only ascii characters under the name {{Filename|ascii.pf2}}. Image formats supported include tga, png and jpeg, providing the correct modules are loaded. The maximum supported resolution depends on your hardware. There are two ways of setting a {{Filename|tga}} file as background. Two sample configurations are shown below.<br />
<br />
Edit {{Filename|/etc/default/grub}} like this:<br />
GRUB_GFXMODE=1024x768x32<br />
GRUB_GFXPAYLOAD_LINUX=keep<br />
GRUB_BACKGROUND="/boot/grub/archlinux.tga"<br />
#GRUB_THEME="/path/to/gfxtheme"<br />
<br />
(archlinux.tga is a placeholder; put your file name there)<br />
<br />
To generate the changes, run: <br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
{{Note|If this example does not work for you try to replace {{Codeline|1=gfxmode="1024x768x32"}} by {{Codeline|1=vbemode="0x105"}}.}}<br />
{{Note|To show all the modes you can use {{Codeline|1=# hwinfo --framebuffer}} (hwinfo is available in [community]), while at grub2 prompt you can use the {{Codeline|1=vbeinfo}} command.}}<br />
{{Note|If you have installed Grub on a separate partition, {{Filename|/boot/grub/archlinux.tga}} becomes {{Filename|/grub/archlinux.tga}}.}}<br />
<br />
====Menu colors====<br />
<br />
As in Grub (0.9x), you can change the menu colors in Grub2. The available colors for GRUB2 are at http://www.gnu.org/software/grub/manual/html_node/Theme-file-format.html#Theme-file-format . <br />
Here is an example:<br />
<br />
Edit {{Filename|/etc/default/grub}}:<br />
GRUB_COLOR_NORMAL="light-blue/black"<br />
GRUB_COLOR_HIGHLIGHT="light-cyan/blue"<br />
<br />
Generate the changes:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
====Hidden menu====<br />
<br />
One of the unique features of Grub2 is hiding/skipping the menu and showing it by holding "Shift" when needed. You can also adjust whether you want to see the timeout counter.<br />
<br />
Edit {{Filename|/etc/default/grub}} as you wish. Here is an example where the comments from the beginning of the two lines have been removed to enable the feature, the timeout has been set to five seconds and to be shown to the user:<br />
GRUB_HIDDEN_TIMEOUT=5<br />
GRUB_HIDDEN_TIMEOUT_QUIET=false<br />
<br />
and run:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
====Setting the framebuffer resolution ====<br />
<br />
Grub2 can set the framebuffer for both grub2 itself and the kernel. The old ''vga='' way is deprecated. The preferred method is editing {{Filename|/etc/default/grub}} as the following sample:<br />
<br />
GRUB_GFXMODE=1024x768x32<br />
GRUB_GFXPAYLOAD_LINUX=keep<br />
<br />
To generate the changes, run: <br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
The {{Codeline|gfxpayload}} property will make sure the kernel keeps the resolution.<br />
<br />
If this method does not work for you, the deprecated <code>vga=</code> method will still work. Just<br />
add it next to the <code>"GRUB_CMDLINE_LINUX_DEFAULT="</code> line in {{Filename|/etc/default/grub}}<br />
for eg: <code>"GRUB_CMDLINE_LINUX_DEFAULT="quiet splash vga=792"</code> will give you a {{Codeline|1024x768}} resolution.<br />
<br />
You can choose one of these resolutions: {{Codeline|640×480}}, {{Codeline|800×600}}, {{Codeline|1024×768}}, {{Codeline|1280×1024}}, {{Codeline|1600×1200}}<br />
<br />
=== Other Options ===<br />
<br />
==== LVM ====<br />
<br />
If you use [[LVM]] for your {{Filename|/boot}}, add the following before menuentry lines:<br />
<br />
insmod lvm<br />
<br />
and specify your root in the menuentry as:<br />
<br />
set root=(''lvm_group_name''-''lvm_logical_boot_partition_name'')<br />
<br />
Example:<br />
<br />
# (0) Arch Linux<br />
menuentry "Arch Linux" {<br />
insmod lvm<br />
set root=(VolumeGroup-lv_boot)<br />
# you can only set following two lines<br />
linux /vmlinuz-linux root=/dev/mapper/VolumeGroup-root ro<br />
initrd /initramfs-linux.img<br />
}<br />
<br />
==== Raid ====<br />
<br />
Grub2 provides convenient handling of raid-volumes. You need to add:<br />
insmod raid<br />
<br />
which allows you to address the volume natively. E.g. {{Filename|/dev/md0}} becomes:<br />
set root=(md0)<br />
<br />
whereas a partitioned raid-volume (e.g. {{Filename|/dev/md0p1}}) becomes:<br />
set root=(md0,1)<br />
<br />
==== Persistent block device naming ====<br />
You can use UUIDs to detect partitions instead of the "old" {{Filename|/dev/sd*}} and {{Filename|/dev/hd*}} scheming. It has the advantage of detecting partitions by their unique UUIDs, which is needed by some people booting with complicated partition setups.<br />
<br />
UUIDs are used by default in the recent versions of grub2 - there is no downside in it anyway except that you need to re-generate the {{Filename|grub.cfg}} file every time you resize or reformat your partitions. Remember this when modifying partitions with Live-CD.<br />
<br />
The recent versions of grub2 use UUIDs by default. You can re-enable the use of UUIDS by simply commenting the UUID line (this is also what it looks like by default):<br />
#GRUB_DISABLE_LINUX_UUID=true<br />
you can also just set the value as {{Codeline|false}} as shown here:<br />
GRUB_DISABLE_LINUX_UUID=false<br />
<br />
Either way, do not forget to generate the changes:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
==== Using Labels ====<br />
<br />
It is possible to use labels, human-readable strings attached to filesystems, by using the {{Codeline|--label}} option to {{Codeline|search}}. First of all, label your existing partition:<br />
# tune2fs -L a <LABEL> <PARTITION><br />
<br />
Then, add an entry using labels. An example of this:<br />
<br />
menuentry "Arch Linux, session texte" {<br />
search --label --no-floppy --set=root archroot<br />
linux /boot/vmlinuz-linux root=/dev/disk/by-label/archroot ro<br />
initrd /boot/initramfs-linux.img<br />
}<br />
<br />
==== Recall previous entry ====<br />
<br />
Grub2 can remember the last entry you booted from and use this as the default entry to boot from next time. This is useful if you have multiple kernels (i.e., the current Arch one and the LTS kernel as a fallback option) or operating systems. To do this, edit {{Filename|/etc/default/grub}} and change the setting of {{Codeline|GRUB_DEFAULT}}:<br />
<br />
GRUB_DEFAULT=saved<br />
<br />
This ensures that grub will default to the saved entry. To enable saving the selected entry, add the following line to {{Filename|/etc/default/grub}}:<br />
<br />
GRUB_SAVEDEFAULT=true<br />
<br />
Remember to regenerate your configuration file.<br />
<br />
==== Security ====<br />
<br />
If you want to secure GRUB2 so it is not possible for anyone to change boot parameters or use the command line, you can add a user/password combination to GRUB2's configuration files. To do this, run the command {{Codeline|grub-mkpasswd_pbkdf2}}. Enter a password and confirm it. The output will look like this:<br />
<br />
<pre style='overflow:auto'><br />
Your PBKDF2 is grub.pbkdf2.sha512.10000.C8ABD3E93C4DFC83138B0C7A3D719BC650E6234310DA069E6FDB0DD4156313DA3D0D9BFFC2846C21D5A2DDA515114CF6378F8A064C94198D0618E70D23717E82.509BFA8A4217EAD0B33C87432524C0B6B64B34FBAD22D3E6E6874D9B101996C5F98AB1746FE7C7199147ECF4ABD8661C222EEEDB7D14A843261FFF2C07B1269A</pre>Then, add the following to {{Filename|/etc/grub.d/00_header}}:<br />
<pre>cat << EOF<br />
<br />
set superusers="username"<br />
password_pbkdf2 username <password><br />
<br />
EOF</pre><br />
where <password> is the string generated by {{Codeline|grub-mkpasswd_pbkdf2}}.<br />
<br />
Regenerate your configuration file. Your GRUB2 command line and boot parameters are now protected.<br />
<br />
=== Booting an Ubuntu ISO Image from the GRUB2 Screen ===<br />
<br />
Edit {{Filename|/etc/grub.d/40_custom}} to add an entry pointing to an Ubuntu iso:<br />
<br />
menuentry "ubuntu-11.04-desktop-amd64.iso" {<br />
set isofile="/path/to/ubuntu-11.04-desktop-amd64.iso"<br />
loopback loop (hdX,Y)$isofile<br />
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile quiet noeject noprompt splash --<br />
initrd (loop)/casper/initrd.lz<br />
}<br />
<br />
Be sure to adjust the "hdX,Y" in the third line to point to the correct disk/partition number of the isofile. When finished, update grub2's configuration file via:<br />
<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
== Using the command shell ==<br />
<br />
Since the MBR is too small to store all GRUB2 modules, only the menu and a few basic commands reside there. The majority of GRUB2 functionality remains in modules in {{Filename|/boot/grub}}, which are inserted as needed. In error conditions (e.g. if the partition layout changes) GRUB2 may fail to boot. When this happens, a command shell may appear.<br />
<br />
GRUB2 offers multiple shells/prompts. If there is a problem reading the menu but the bootloader is able to find the disk, you will likely be dropped to the "normal" shell:<br />
sh:grub><br />
<br />
If there is a more serious problem (e.g. GRUB cannot find required files), you may instead be dropped to the "rescue" shell:<br />
grub rescue><br />
<br />
The rescue shell is a restricted subset of the normal shell, offering much less functionality. If dumped to the rescue shell, first try inserting the "normal" module, then starting the "normal" shell:<br />
grub rescue> set prefix=(hdX,Y)/boot/grub<br />
grub rescue> insmod (hdX,Y)/boot/grub/normal.mod<br />
rescue:grub> normal<br />
<br />
=== Pager support ===<br />
<br />
GRUB2 supports pager for reading commands that provide long output (like the help command). This works only in normal shell mode and not in rescue mode. To enable pager, in GRUB2 command shell type:<br />
sh:grub> set pager=1<br />
<br />
== GUI configuration tools ==<br />
<br />
Following package may be installed from [[AUR]]<br />
* [http://kde-apps.org/content/show.php?content=139643 grub2-editor] (requires kdelibs)<br />
*:A KDE4 control module for configuring the GRUB2 bootloader<br />
* [http://kde-apps.org/content/show.php?content=137886 kcm-grub2] (requires kdelibs python2-qt kdebindings-python)<br />
*:This Kcm module manages the most common settings of Grub2.<br />
* [http://sourceforge.net/projects/startup-manager/ startupmanager] (requires gnome-python imagemagick yelp python2 xorg-xrandr)<br />
*:GUI app for changing the settings of GRUB, GRUB2, Usplash and Splashy<br />
<br />
== parttool or legacy hide/unhide ==<br />
<br />
If you have a win9x paradigm with hidden C disks GRUB legacy had the hide/unhide feature. In GRUB2 this has been replaced by parttool. For example, to boot the third C disk of three win9x installations on the CLI enter the CLI and:<br />
parttool hd0,1 hidden+ boot-<br />
parttool hd0,2 hidden+ boot-<br />
parttool hd0,3 hidden- boot+<br />
set root=hd0,3<br />
chainloader +1<br />
boot<br />
<br />
== Using the rescue console ==<br />
<br />
See [[#Using the command shell]] first. If unable to activate the standard shell, one possible solution is to boot using a live CD or some other rescue disk to correct configuration errors and reinstall GRUB. However, such a boot disk is not always available (nor necessary); the rescue console is surprisingly robust.<br />
<br />
The available commands in GRUB rescue include "insmod", "ls", "set", and "unset". This example uses "set" and "insmod". "set" modifies variables and "insmod" inserts new modules to add functionality.<br />
<br />
Before starting, the user must know the location of their {{Filename|/boot}} partition (be it a separate partition, or a subdirectory under their root):<br />
grub rescue> set prefix=(hdX,Y)/boot/grub<br />
<br />
where X is the physical drive number and Y is the partition number.<br />
<br />
To expand console capabilities, insert the "linux" module:<br />
grub rescue> insmod (hdX,Y)/boot/grub/linux.mod<br />
<br />
{{Note|With a separate boot partition, omit {{Filename|/boot}} from the path, (i.e. type {{Codeline|1=set prefix=(hdX,Y)/grub}} and {{Codeline|insmod (hdX,Y)/grub/linux.mod}}).}}<br />
<br />
This introduces the "linux" and "initrd" commands, which should be familiar (see [[#Configuration]]).<br />
<br />
An example, booting Arch Linux:<br />
set root=(hd0,5)<br />
linux /boot/vmlinuz-linux root=/dev/sda5<br />
initrd /boot/initramfs-linux.img<br />
boot<br />
<br />
With a separate boot partition, again change the lines accordingly:<br />
set root=(hd0,5)<br />
linux /vmlinuz-linux root=/dev/sda6<br />
initrd /initramfs-linux.img<br />
boot<br />
<br />
After successfully booting the Arch Linux installation, users can correct {{Filename|grub.cfg}} as needed and then run:<br />
# grub-install /dev/sda --no-floppy<br />
<br />
to reinstall GRUB2 and fix the problem completely, changing {{Filename|/dev/sda}} if needed. See [[#Bootloader installation]] for details.<br />
<br />
== Combining the use of UUID's and basic scripting ==<br />
<br />
If you like the idea of using UUID's to avoid unreliable BIOS mappings or are struggling with Grub's syntax, here is an example boot menu item that uses UUID's and a small script to direct Grub to the proper disk partitions for your system. All you need to do is replace the UUID's in the sample with the correct UUID's for your system. (The example applies to a system with a boot and root partition. You will obviously need to modify the Grub configuration if you have additional partitions.)<br />
<br />
menuentry "Arch Linux 64" {<br />
#Enter the UUID of your boot partition (this is where Grub and your kernel reside)<br />
set uuid_grub_boot=ece0448f-bb08-486d-9864-ac3271bd8d07<br />
<br />
#Enter the UUID of the partition containing the root partition of your Arch Linux installation. <br />
set uuid_os_root=c55da16f-e2af-4603-9e0b-03f5f565ec4a<br />
<br />
#(Note: this may be the same as your boot partition)<br />
<br />
#Here we set the Grub "root" variable by locating the UUID of the root partition identified above <br />
search --fs-uuid --no-floppy --set=root $uuid_os_root<br />
<br />
#Here we set a custom variable grub_boot by locating the UUID of the boot partition identified above <br />
search --fs-uuid --no-floppy --set=grub_boot $uuid_grub_boot<br />
<br />
#Here is the magic. We test to see if the boot and root partitions have the same UUID.<br />
#If they do, we append /boot to the $grub_boot variable. For ex. (hd0,1) becomes (hd0,1)/boot.<br />
if [ $uuid_grub_boot == $uuid_os_root ] ; then<br />
set grub_boot=$grub_boot/boot<br />
fi<br />
<br />
# $grub_boot now points to the correct location, so the following will properly find the kernel and initrd<br />
linux ($grub_boot)/vmlinuz-linux root=/dev/disk/by-uuid/$uuid_os_root ro<br />
initrd ($grub_boot)/initramfs-linux.img<br />
}<br />
<br />
== Troubleshooting ==<br />
<br />
Any troubleshooting should be added here.<br />
<br />
=== Enable GRUB2 debug messages ===<br />
<br />
Add<br />
<br />
set pager=1<br />
set debug=all<br />
<br />
to {{Filename|grub.cfg}}.<br />
<br />
=== Correct GRUB2 No Suitable Mode Found Error ===<br />
<br />
If you get this error when booting any menuentry<br />
<br />
error: no suitable mode found<br />
Booting however<br />
<br />
Then you need to initialize grub2 graphical terminal (gfxterm) with proper video mode (gfxmode) in grub2. This video mode is passed by grub2 to the linux kernel via 'gfxpayload'. In case of UEFI systems, if the grub2 video mode is not initialized, no kernel boot messages will be shown in the terminal (atleast until KMS kicks in)<br />
<br />
Copy {{Filename|/usr/share/grub/unicode.pf2}} to ${GRUB2_PREFIX_DIR} ({{Filename|/boot/grub/}} in case of BIOS systems and {{Filename|/boot/efi/efi/grub/}} in case of UEFI systems). <br />
<br />
# cp /usr/share/grub/unicode.pf2 ${GRUB2_PREFIX_DIR}<br />
<br />
If {{Filename|/usr/share/grub/unicode.pf2}} does not exist, install {{Package Official|bdf-unifont}}, create the unifont.pf2 file and then copy it to ${GRUB2_PREFIX_DIR} .<br />
<br />
# grub-mkfont -o unicode.pf2 /usr/share/fonts/misc/unifont.bdf<br />
<br />
Then, in the {{Filename|grub.cfg}} file, add the following lines to enable grub2 to pass the video mode correctly to the kernel, without of which you will only get a black screen (no output) but booting (actually) proceeds successfully without any system hang:<br />
<br />
BIOS systems<br />
<br />
insmod vbe<br />
<br />
UEFI systems<br />
<br />
insmod efi_gop<br />
insmod efi_uga<br />
<br />
After that add the following code (common to both BIOS and UEFI)<br />
<br />
insmod font<br />
<br />
if loadfont ${prefix}/unicode.pf2<br />
then<br />
insmod gfxterm<br />
set gfxmode=auto<br />
set gfxpayload=keep<br />
terminal_output gfxterm<br />
fi<br />
<br />
As you can see for gfxterm (graphical terminal) to function properly, {{Filename|unicode.pf2}} font file should exist in ${GRUB2_PREFIX_DIR}.<br />
<br />
=== msdos-style error message ===<br />
<br />
grub-setup: warn: This msdos-style partition label has no post-MBR gap; embedding won't be possible!<br />
grub-setup: warn: Embedding is not possible. GRUB can only be installed in this setup by using blocklists.<br />
However, blocklists are UNRELIABLE and its use is discouraged.<br />
grub-setup: error: If you really want blocklists, use --force.<br />
<br />
This error may occur when you try installing GRUB2 in a VMware container. Read more about it [http://bbs.archlinux.org/viewtopic.php?pid=581760#p581760 here]. It happens when the first partition starts just after the MBR (block 63), without the usual space of 1 MiB (2048 blocks) before the first partition. Read [[#MBR_aka_msdos_partitioning_specific_instructions]]<br />
<br />
=== UEFI GRUB2 not loaded ===<br />
In some cases the EFI may fail to load grub correctly. Provided everything is set up correctly, the output of<br />
efibootmgr -v<br />
might look something like this:<br />
BootCurrent: 0000<br />
Timeout: 3 seconds<br />
BootOrder: 0000,0001,0002<br />
Boot0000* Grub HD(1,800,32000,23532fbb-1bfa-4e46-851a-b494bfe9478c)File(\efi\grub\grub.efi)<br />
Boot0001* Shell HD(1,800,32000,23532fbb-1bfa-4e46-851a-b494bfe9478c)File(\EfiShell.efi)<br />
Boot0002* Festplatte BIOS(2,0,00)P0: SAMSUNG HD204UI .<br />
If everything works correctly, the EFI would now automatically load grub.<br><br />
If the screen only goes black for a second and the next boot option is tried afterwards, according to [https://bbs.archlinux.org/viewtopic.php?pid=981560#p981560 this post], moving grub to the partition root can help. The boot option has to be deleted and recreated afterwards. The entry for grub should look like this then:<br />
Boot0000* Grub HD(1,800,32000,23532fbb-1bfa-4e46-851a-b494bfe9478c)File(\grub.efi)<br />
<br />
=== Invalid signature ===<br />
If trying to boot windows results in an "invalid signature" error, e.g. after reconfiguring partitions or adding additional hard drives, (re)move grub's device configuration and let it reconfigure.<br />
# mv /boot/grub/device.map /boot/grub/device.map-old<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
Grub-mkconfig should now mention all found boot options including windows. If it works, remove /boot/grub/device.map-old.<br />
<br />
== References ==<br />
<br />
# Official GRUB2 Manual - http://www.gnu.org/software/grub/manual/grub.html<br />
# GRUB2 wiki page describing steps to compile for UEFI systems - https://help.ubuntu.com/community/UEFIBooting - previously http://grub.enbug.org/TestingOnUEFI{{Linkrot|2011|09|05}}<br />
# Wikipedia's page on [http://en.wikipedia.org/wiki/BIOS_Boot_partition BIOS Boot Partition]<br />
<br />
== External Links ==<br />
<br />
# [https://github.com/the-ridikulus-rat/My_Shell_Scripts/blob/master/grub2/grub2_bios.sh A Linux Bash Shell script to compile and install GRUB2 for BIOS from BZR Source]<br />
# [https://github.com/the-ridikulus-rat/My_Shell_Scripts/blob/master/grub2/grub2_uefi.sh A Linux Bash Shell script to compile and install GRUB2 for UEFI from BZR Source]</div>Mayweedhttps://wiki.archlinux.org/index.php?title=GRUB&diff=167968GRUB2011-10-29T18:19:49Z<p>Mayweed: </p>
<hr />
<div>[[Category:Boot loaders (English)]]<br />
{{i18n|GRUB2}}<br />
[[fr:GRUB2]]<br />
{{Article summary start}}<br />
{{Article summary text|Covers various aspects of the next generation of the GRand Unified Bootloader (GRUB2).}}<br />
{{Article summary heading|Overview}}<br />
{{Article summary text|{{Boot process overview}}}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|Burg}} - Burg is a brand-new boot loader based on GRUB2. It uses a new object format which allows it to be built in a wider range of OS, including Linux/Windows/OSX/Solaris/FreeBSD, etc. It also has a highly configurable menu system which works in both text and graphic mode. <br />
{{Article summary heading|Resources}}<br />
{{Article summary link|GNU GRUB -- GNU Project|http://www.gnu.org/software/grub/}}<br />
{{Article summary link|GNU GRUB Wiki|http://grub.enbug.org/}}{{Linkrot|2011|09|05}}<br />
{{Article summary end}}<br />
<br />
[http://www.gnu.org/software/grub/ GRUB2] is the next generation of the GRand Unified Bootloader (GRUB). GRUB2 is derived from [http://www.nongnu.org/pupa/ PUPA] which was a research project to investigate the next generation of GRUB. GRUB 2 has been rewritten from scratch to clean up everything and provide modularity and portability [http://www.gnu.org/software/grub/grub-faq.en.html#q1].<br />
<br />
Briefly, the ''bootloader'' is the first software program that runs when a computer starts. It is responsible for loading and transferring control to the Linux kernel. The kernel, in turn, initializes the rest of the operating system.<br />
<br />
== Preface ==<br />
<br />
Although, [[GRUB]] (i.e. version 0.9x) is the de facto standard bootloader of Linux, it is considered 'legacy' by upstream. It is being replaced by GRUB2 in many distributions. Upstream recommends GRUB2 >=1.99~rc2 over grub-legacy, even for current grub-legacy users.<br />
<br />
{{Note|grub2 from 1.99~rc2 and later supports btrfs as root (without a separate /boot filesystem).}}<br />
<br />
=== Notes for current GRUB users ===<br />
<br />
* There are differences in the commands of GRUB and GRUB2. Familiarize yourself with [http://www.gnu.org/software/grub/manual/grub.html#Commands GRUB2 commands] before proceeding (e.g. "find" has been replaced with "search").<br />
<br />
* GRUB2 is now ''modular'' and no longer requires "stage 1.5". As a result, the bootloader itself is limited -- modules are loaded from the hard drive as needed to expand functionality (e.g. for [[LVM]] or RAID support).<br />
<br />
* Device naming has changed between GRUB and GRUB2. Partitions are numbered from 1 instead of 0 while drives are still numbered from 0, and prefixed with partition-table type. For example, {{Filename|/dev/sda1}} would be referred to as {{Codeline|(hd0,msdos1)}} (for MBR) or {{Codeline|(hd0,gpt1)}} (for GPT) using GRUB2.<br />
<br />
===== Preliminary Considerations for GRUB2 BIOS =====<br />
<br />
====== [[GPT]] specific instructions ======<br />
<br />
GRUB2 in BIOS-GPT configuration requires a BIOS Boot Partition to embed its core.img in the absence of post-MBR gap in GPT partitioned systems (which is taken over by the GPT Primary Header and Primary Partition table). This partition is used by GRUB2 only in BIOS-GPT setups. No such partition type exists in case of MBR partitioning (at least not for GRUB2). This partition is also not required if the system is UEFI based, as no embedding of bootsectors takes place in that case. Syslinux does not require this partition.<br />
<br />
For a BIOS-GPT configuration, create a 2 MiB partition using cgdisk or GNU Parted with no filesystem. The location of the partition in the partition table does not matter but it should be within the first 2 TiB region of the disk. It is advisable to put it somewhere in the beginning of the disk before the /boot partition. Set the partition type to "EF02" in cgdisk or {{Codeline|set <BOOT_PART_NUM> bios_grub on}} in GNU Parted.<br />
<br />
{{Note|This partition should be created before grub_bios-install or grub-setup is run or before the '''Install Bootloader''' step of the Archlinux installer (if GRUB2 is selected as bootloader).}}<br />
<br />
====== [[MBR]] aka msdos partitioning specific instructions ======<br />
<br />
Usually the post-MBR gap (after the 512 byte MBR region and before the start of the 1st partition) in many MBR (or msdos disklabel) partitioned systems is 32 KiB when DOS compatibility cylinder alignment issues are satisfied in the partition table. However a post-MBR gap of about 1 to 2 MiB is recommended to provide sufficient room for embedding grub2's core.img ( https://bugs.archlinux.org/task/24103 ). It is advisable to use a partitioner which supports 1 MiB partition alignment to obtain this space as well as satisfy other non-512 byte sector issues (which are unrelated to embedding of core.img).<br />
<br />
If you do not dual-boot with MS Windows (any version) in BIOS systems, it is advisable to switch to GPT partitioning - [[GUID_Partition_Table#Convert_from_MBR_to_GPT_without_data_loss]]<br />
{{Note|Create the 2MiB partition mentioned above BEFORE you convert to GPT. If you do not, gparted will not resize your boot partition to allow its creation, and when you reboot grub2 will not know where to look.}}<br />
<br />
== Installation ==<br />
<br />
=== During Arch Linux installation ===<br />
<br />
* Skip the '''Install Bootloader''' step and exit the installer.<br />
* Configure the network:<br />
# aif -p partial-configure-network<br />
This will bring up a prompt; put in the network interface to use, (e.g., eth0) and use DHCP for easy configuration.<br />
* If you did not configure the installed system's {{Filename|/etc/resolv.conf}} file during installation (for instance, if you plan to let DHCP generate it later), you will need to copy the one generated by AIF when it configured the network:<br />
# cp /etc/resolv.conf /mnt/etc/resolv.conf<br />
* Load the dm-mod module (you might need grub2-bios; install the package if needed):<br />
# modprobe dm-mod<br />
{{Note|This is necessary at this point, and cannot be postponed after the chroot. If you try to use modprobe in a chroot environment that has a later kernel version from that of the installing device (at the time of writing, 2.6.33), modprobe will fail. This happens routinely using the Arch "net" installations.}}<br />
* From the installer's live shell, chroot to the installed system:<br />
# mount -o bind /dev /mnt/dev<br />
# chroot /mnt bash<br />
* Update pacman's database:<br />
# pacman-db-upgrade<br />
* Refresh the package list (with an extra -y flag to force a refresh of all package lists even if they appear to be up to date):<br />
# pacman -Syy<br />
* Install the GRUB2 package as mentioned in the section [[#From a running Arch Linux]]. Note that the dm-mod module has already been loaded, no need to do that again.<br />
<br />
=== From a running Arch Linux ===<br />
<br />
====Make a backup of your precious data====<br />
In general, a grub installation ran smoothly and you got no problems at all. And sometimes it could simply messed up your system. You're strongly advised to make a backup before even think of grub2.<br />
<br />
*copy grub modules and configuration<br />
# cp -a /boot/grub /path/to/backup/<br />
*backup the MBR and GRUB stage 1.5<br />
# dd if=/dev/sda of=/path/to/backup/first-sectors count=63<br />
<br />
You could now lightly remove {{Filename|/boot/grub}} with:<br />
# rm -rf /boot/grub<br />
<br />
and follow the instructions below.You know that if things get nasty, you could reboot your system thanks to an installation media and :<br />
<br />
*move old grub2 files out of the way<br />
# mv /boot/grub /boot/grub.nonfunctional<br />
*copy grub back to /boot<br />
# cp -a /path/to/backup/grub /boot/<br />
*replace MBR and next 62 sectors of sda with backed up copy (DANGEROUS!)<br />
# dd if=/path/to/backup/first-sectors of=/dev/sda count=63<br />
<br />
<br />
===== grub2-bios-install =====<br />
<br />
The GRUB2 package can be installed with pacman (and will replace {{Package Official|grub}}, if it is installed):<br />
<br />
# pacman -S grub2-bios<br />
<br />
{{Note|Installing grub2-common (a dependency of grub2-bios) 1.99~rc1 or later, may take forever in some systems since the post_install script runs grub-mkconfig and this script does not provide the option <code>--no-floppy</code>. For more details search this option in the article.}}<br />
<br />
{{Note|Simply installing the package won't update the /boot/grub/core.img file and the grub2 modules in /boot/grub . You need to update the core.img file and the grub2 modules manually using grub_bios-install as explained below.}}<br />
<br />
Also load the device-mapper kernel module without which grub-probe does not reliably detect disks and partitions<br />
<br />
# modprobe dm-mod<br />
<br />
<br />
===== Run grub_bios-install =====<br />
<br />
There are 3 ways to install grub2 in BIOS booting - [[#Install_to_440-byte_MBR_boot_code_region]] (recommended) , [[#Install_to_Partition_or_Partitionless_Disk]] (not recommended) or [[#Generate_core.img_alone]] (safest method, but requires another BIOS bootloader like [[grub-legacy]] or [[syslinux]] to be installed to chainload {{Filename|/boot/grub/core.img}} ). For all the ways [[#Before_grub_bios-install]] step is needed.<br />
<br />
====== Install to 440-byte MBR boot code region ======<br />
<br />
To setup grub2-bios in the 440-byte Master Boot Record boot code region, populate the {{Filename|/boot/grub}} directory, generate the {{Filename|/boot/grub/core.img}} file, and embed it in the 32 KiB (minimum size - varies depending on partition alignment) post-MBR gap (MBR disks) or in BIOS Boot Partition (GPT disks), run<br />
<br />
# grub_bios-install --boot-directory=/boot --no-floppy --recheck /dev/sda<br />
<br />
where {{Filename|/dev/sda}} is the destination of the installation (in this case the MBR of the first SATA disk). If you use [[LVM]] for your {{Filename|/boot}}, you can install GRUB2 on multiple physical disks. <br />
<br />
The {{Codeline|--no-floppy}} tells grub2-bios utilities not to search for any floppy devices which reduces the overall execution time of grub_bios-install on many systems (it will also prevent the issue below from occuring). Otherwise you get an error like this<br />
<br />
grub-probe: error: Cannot get the real path of '/dev/fd0'<br />
Auto-detection of a filesystem module failed.<br />
Please specify the module with the option '--modules' explicitly.<br />
<br />
Follow [[#Generate_GRUB2_BIOS_Config_file]] or if that fails, convert your {{Filename|/boot/grub/menu.lst}} file to {{Filename|/boot/grub/grub.cfg}} using:<br />
<br />
# grub-menulst2cfg /boot/grub/menu.lst /boot/grub/grub.cfg<br />
<br />
For example:<br />
<br />
{{File|name=/boot/grub/menu.lst|content=<br />
default=0<br />
timeout=5<br />
<br />
title Arch Linux Stock Kernel<br />
root (hd0,0)<br />
kernel /vmlinuz-linux root=/dev/sda2 ro<br />
initrd /initramfs-linux.img<br />
<br />
title Arch Linux Stock Kernel Fallback<br />
root (hd0,0)<br />
kernel /vmlinuz-linux root=/dev/sda2 ro<br />
initrd /initramfs-linux-fallback.img<br />
}}<br />
<br />
{{File|name=/boot/grub/grub.cfg|content=<br />
set default='0'; if [ x"$default" = xsaved ]; then load_env; set default="$saved_entry"; fi<br />
set timeout=5<br />
<br />
menuentry 'Arch Linux Stock Kernel' {<br />
set root='(hd0,1)'; set legacy_hdbias='0'<br />
legacy_kernel '/vmlinuz-linux' '/vmlinuz-linux' 'root=/dev/sda2' 'ro'<br />
legacy_initrd '/initramfs-linux.img' '/initramfs-linux.img'<br />
<br />
}<br />
<br />
menuentry 'Arch Linux Stock Kernel Fallback' {<br />
set root='(hd0,1)'; set legacy_hdbias='0'<br />
legacy_kernel '/vmlinuz-linux' '/vmlinuz-linux' 'root=/dev/sda2' 'ro'<br />
legacy_initrd '/initramfs-linux-fallback.img' '/initramfs-linux-fallback.img'<br />
}<br />
}}<br />
<br />
<br />
* If you forgot to create a GRUB2 {{Filename|/boot/grub/grub.cfg}} configfile and simply rebooted into GRUB2 Command Shell, type:<br />
<br />
sh:grub> insmod legacycfg<br />
sh:grub> legacy_configfile ${prefix}/menu.lst<br />
<br />
Boot into Arch and re-create the proper GRUB2 {{Filename|/boot/grub/grub.cfg}} configfile.<br />
<br />
{{Note|This option works only in BIOS systems, not in UEFI systems.}}<br />
<br />
====== Install to Partition or Partitionless Disk ======<br />
<br />
{{Note|grub2-bios (any version - including upstream bzr repo) does not encourage installation to a partition boot sector or a partitionless disk like grub-legacy or syslinux does. Neither do the Arch devs.}}<br />
<br />
To setup grub2-bios to a partition boot sector, to a partitionless disk (also called superfloppy) or to a floppy disk, run (using for example /dev/sda1 as the /boot partition)<br />
<br />
# chattr -i /boot/grub/core.img<br />
# grub_bios-install --boot-directory=/boot --no-floppy --recheck --force /dev/sda1<br />
# chattr +i /boot/grub/core.img<br />
<br />
You need to use the {{Codeline|--force}} option to allow usage of blocklists and should not use <code>--grub-setup=/bin/true</code> (which is similar to simply generating core.img).<br />
<br />
grub_bios-install will give out warnings like which should give you the idea of what might go wrong with this approach.<br />
<br />
/sbin/grub-setup: warn: Attempting to install GRUB to a partitionless disk or to a partition. This is a BAD idea.<br />
/sbin/grub-setup: warn: Embedding is not possible. GRUB can only be installed in this setup by using blocklists. <br />
However, blocklists are UNRELIABLE and their use is discouraged.<br />
<br />
Without {{Codeline|--force}} you may get the below error and grub-setup will not setup its boot code in the partition boot sector.<br />
<br />
/sbin/grub-setup: error: will not proceed with blocklists<br />
<br />
With {{Codeline|--force}} you should get<br />
<br />
Installation finished. No error reported.<br />
<br />
The reason why grub-setup does not by default allow this is because in case of partition or a partitionless disk is that grub2-bios relies on embedded blocklists in the partition bootsector to locate the {{Filename|/boot/grub/core.img}} file and the prefix dir {{Filename|/boot/grub}} . The sector locations of {{Filename|core.img}} may change whenever the filesystem in the partition is being altered (files copied, deleted etc.). For more info see https://bugzilla.redhat.com/show_bug.cgi?id=728742 and https://bugzilla.redhat.com/show_bug.cgi?id=730915 .<br />
<br />
The workaround for this is to set the immutable flag on {{Filename|/boot/grub/core.img}} (using chattr command as mentioned above) so that the sector locations of the {{Filename|core.img}} file in the disk is not altered. The immutable flag on {{Filename|/boot/grub/core.img}} needs to be set only if grub2-bios is installed to a partition boot sector or a partitionless disk, not in case of installtion to MBR or simple generation of {{Filename|core.img}} without embedding any bootsector (mentioned above). <br />
<br />
====== Generate core.img alone ======<br />
<br />
To populate the {{Filename|/boot/grub}} directory and generate a {{Filename|/boot/grub/core.img}} file WITHOUT embedding any grub2-bios bootsector code in the MBR, post-MBR region, or the partition bootsector, add <code>--grub-setup=/bin/true</code> to grub_bios-install:<br />
<br />
# grub_bios-install --grub-setup=/bin/true --boot-directory=/boot --no-floppy --recheck /dev/sda<br />
<br />
You can then chainload grub2's core.img from grub-legacy or syslinux as a Linux kernel or a multiboot kernel.<br />
<br />
===== After grub_bios-install =====<br />
<br />
====== Generate GRUB2 BIOS Config file ======<br />
<br />
Finally, generate a configuration for grub2 (this is explained in greater detail in the Configuration section):<br />
<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
If grub2 complains about "no suitable mode found" while booting, go to [[#Correct_GRUB2_No_Suitable_Mode_Found_Error]] .<br />
<br />
===== Multiboot in BIOS =====<br />
<br />
====== Boot Microsoft Windows installed in BIOS-MBR mode ======<br />
<br />
{{Note|GRUB2 supports booting {{Filename|bootmgr}} directly and chainload of partition boot sector is no longer required to boot Windows in a BIOS-MBR setup.}}<br />
<br />
Find the UUID of the NTFS filesystem of the Windows's SYSTEM PARTITION where the bootmgr and its files reside. For example, if Windows {{Filename|bootmgr}} exists at {{Filename|/media/Windows/bootmgr}}:<br />
<br />
# grub-probe --target=fs_uuid /media/Windows/bootmgr<br />
69B235F6749E84CE<br />
<br />
Then, add the below code to {{Filename|/boot/grub/grub.cfg}} to chainload Windows (Vista, 7 or 8) installed in BIOS-MBR mode :<br />
<br />
menuentry "Microsoft Windows 7 BIOS-MBR" {<br />
insmod part_msdos<br />
insmod ntfs<br />
insmod search_fs_uuid<br />
insmod ntldr <br />
search --fs-uuid --no-floppy --set=root 69B235F6749E84CE<br />
ntldr (${root})/bootmgr<br />
}<br />
<br />
For Windows XP<br />
<br />
menuentry "Microsoft Windows XP" {<br />
insmod part_msdos<br />
insmod ntfs<br />
insmod search_fs_uuid<br />
insmod ntldr <br />
search --fs-uuid --no-floppy --set=root 69B235F6749E84CE<br />
ntldr (${root})/ntldr<br />
}<br />
<br />
==== [[UEFI]] systems ====<br />
<br />
===== Before grub_efi_${UEFI_ARCH}-install =====<br />
<br />
{{Note|Unless specified as EFI 1.x , EFI and UEFI terms are used interchangeably to denote UEFI 2.x firmware. Also unless stated explicitely, the instructions are general and not Mac specific. Some of them may not work or may be different in Macs. Apple's EFI implementation is neither a EFI 1.x version nor UEFI 2.x version but mixes up both. This kind of firmware does not fall under any one UEFI Specification version and is therefore not a standard UEFI firmware.}}<br />
<br />
GRUB2 UEFI bootloader is available in Arch Linux only from version 1.99~rc1 . To install, first [https://wiki.archlinux.org/index.php/Unified_Extensible_Firmware_Interface#Detecting_UEFI_Firmware_Arch Detect which UEFI firmware arch] you have (either x86_64 or i386).<br />
<br />
Depending on that, install the appropriate package<br />
<br />
For 64-bit aka x86_64 UEFI firmware:<br />
# pacman -S grub2-efi-x86_64<br />
<br />
For 32-bit aka i386 UEFI firmware:<br />
# pacman -S grub2-efi-i386<br />
<br />
{{Note|Installing grub2-common (a dependency of grub2-bios) 1.99~rc1 or later, may take forever in some systems since the post_install script runs grub-mkconfig and this script does not provide the option <code>--no-floppy</code>. For more details search this option in the article.}}<br />
<br />
{{Note|Simply installing the package won't update the grub.efi file and the grub2 modules in the UEFI System Partition . You need to update the grub.efi file and the grub2 modules in the UEFI System Partition manually using grub_efi_${UEFI_ARCH}-install as explained below.}}<br />
<br />
Also load the device-mapper kernel module without which grub-probe does not reliably detect disks and partitions<br />
<br />
# modprobe dm-mod<br />
<br />
===== Install to UEFI SYSTEM PARTITION =====<br />
<br />
====== Mount UEFI SYSTEM PARTITION ======<br />
<br />
Mount the [https://wiki.archlinux.org/index.php/Unified_Extensible_Firmware_Interface#Creating_a_UEFI_SYSTEM_PARTITION_in_Linux UEFI SYSTEM PARTITION] in your system at {{Filename|/boot/efi}}. It should be FAT32 formatted and should be at least 200 MiB in size. If you have mounted the UEFISYS partition in some other mountpoint, replace {{Filename|/boot/efi}} in the below commands with that mountpoint:<br />
<br />
# mkdir -p /boot/efi<br />
# mount -t vfat <UEFISYS_PART_DEVICE> /boot/efi<br />
# mkdir -p /boot/efi/efi<br />
<br />
====== Run grub_efi_${UEFI_ARCH}-install ======<br />
<br />
{{Note|The below commands assume you are using {{Codeline|grub2-efi-x86_64}} (for {{Codeline|grub2-efi-i386}} replace {{Codeline|x86_64}} with {{Codeline|i386}} in the below commands).}}<br />
<br />
# grub_efi_x86_64-install --root-directory=/boot/efi --boot-directory=/boot/efi/efi --bootloader-id=grub --no-floppy --recheck<br />
<br />
The {{Codeline|grub_efi_x86_64-install}} automatically generates a {{Filename|grub.efi}} while setting up the {{Filename|/boot/efi/efi/grub/}} directory.<br />
<br />
If you notice carefully, there is no <device_path> option (Eg: {{Filename|/dev/sda}}) at the end of the {{Codeline|grub_efi_x86_64-install}} command unlike the case of setting up grub2 for BIOS systems. Any <device_path> provided will be ignored by the install script as UEFI bootloaders do not use MBR or Partition boot sectors at all.<br />
<br />
You may now be able to UEFI boot your system by creating a grub.cfg file using grub-mkconfig and copying /boot/efi/efi/grub/grub.efi to /boot/efi/efi/boot/bootx64.efi.<br />
<br />
===== After grub_efi_${UEFI_ARCH}-install =====<br />
<br />
====== Launch GRUB2 as default in non-Mac UEFI systems ======<br />
<br />
{{Note|The below steps will not work if the system has been booted in BIOS mode and will not work if the UEFI processor architecture does not match the kernel one, i.e. x86_64 UEFI + ix86 32-bit Kernel and vice-versa config will not work.}}<br />
<br />
grub_efi_${UEFI_ARCH}-install will ensure {{Filename|/boot/efi/efi/grub/grub.efi}} is launched by default if it detects {{Codeline|efibootmgr}} and if it is able to access UEFI Runtime Services. {{Codeline|efibootmgr}} command will work only if you have booted the system in UEFI mode itself, since it '''requires access to UEFI Runtime Variables''' which are '''available only in UEFI boot mode''' (with "noefi" kernel parameter NOT being used). Initially the user is required to manually launch {{Filename|/boot/efi/efi/grub/grub.efi}} from the firmware itself (using maybe the UEFI Shell) if grub2-efi was installed in BIOS mode. Then {{Codeline|efibootmgr}} should be run to make grub2 as the default entry in the UEFI Boot Manager<br />
<br />
First boot into UEFI mode manually either using the firmware boot menu, UEFI shell, or using any UEFI capable bootable iso (Archboot or Ubuntu non-Mac iso). Use grub probe to determine the device path of your EFI System Partition:<br />
# grub-probe --target=device /boot/efi/efi/grub/grub.efi<br />
<br />
It should give something like {{Filename|/dev/sda1}} (used as example in the remaining steps). Load 'efivars' kernel module:<br />
# modprobe efivars<br />
<br />
If you get '''no such device found''' error for this command, that means you have not booted in UEFI mode or due to some reason the kernel is unable to access UEFI Runtime Variables.<br />
<br />
Verify whether there are files in ''/sys/firmware/efi/vars/'' directory. This directory and its contents are created by "efivars" kernel module and it will exist only if you have booted in UEFI mode without the "noefi" kernel parameter.<br />
<br />
# ls -1 /sys/firmware/efi/vars/<br />
<br />
Sample output (x86_64-UEFI 2.3.1 in x86_64 Kernel:<br />
<br />
# ls -1 /sys/firmware/efi/vars/<br />
Boot0000-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootCurrent-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootOptionSupport-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootOrder-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConIn-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConInDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConOut-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConOutDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ErrOutDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
Lang-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
LangCodes-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
MTC-eb704011-1402-11d3-8e77-00a0c969723b/<br />
MemoryTypeInformation-4c19049f-4137-4dd3-9c10-8b97a83ffdfa/<br />
PlatformLang-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
PlatformLangCodes-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
RTC-378d7b65-8da9-4773-b6e4-a47826a833e1/<br />
del_var<br />
new_var<br />
<br />
If ''/sys/firmware/efi/vars/'' directory is empty or does not exist, then {{Codeline|efibootmgr}} command will not work. If you are unable to make the ISO/CD/DVD/USB boot in UEFI mode try https://gitorious.org/tianocore_uefi_duet_builds/pages/Linux_Windows_BIOS_UEFI_boot_USB .<br />
<br />
If ''/sys/firmware/efi/vars/'' directory (along with the exists then run {{Codeline|efibootmgr}} and reboot:<br />
<br />
# efibootmgr --create --gpt --disk /dev/sda --part 1 --write-signature --label "GRUB2" --loader "\\EFI\\grub\\grub.efi"<br />
<br />
In the above command, {{Filename|/boot/efi/efi/grub/grub/efi}} can be split up as {{Filename|/boot/efi}} and {{Filename|/efi/grub/grub.efi}}, which translates to {{Filename|(/dev/sda)}} -> partition 1 -> {{Filename|\\EFI\\grub\\grub.efi}}. <br />
<br />
FAT32 filesystem is case-insensitive since it does not use UTF-8 encoding by default. In that case the firmware uses capital 'EFI' instead of small 'efi', therefore using {{Filename|\\EFI\\grub\\grub.efi}} or {{Filename|\\efi\\grub\\grub.efi}} does not matter (this will change if the filesystem encoding is UTF-8). UEFI uses backward slash as path separatoir (similar to Windows paths). In the above command "double" backward slashes are used instead of single ones, since a backward slash is used as a escape character by sh shells, the first backward slash escapes the second one so that the path {{Filename|\EFI\grub\grub.efi}} is passed to {{Codeline|efibootmgr}}.<br />
<br />
The 'label' is the name of the menu entry shown in the UEFI boot menu. This name is user's choice and does not affect the booting of the system. More info can be obtained from [http://linux.dell.com/cgi-bin/gitweb/gitweb.cgi?p=efibootmgr.git;a=blob_plain;f=README;hb=HEAD efibootmgr GIT README]<br />
<br />
If you have problems running GRUB2 in UEFI mode you can try the following (worked on an ASUS Z68 mainboard):<br />
<br />
# cp /boot/efi/efi/grub/grub.efi /boot/efi/shellx64.efi<br />
<br />
or<br />
<br />
# cp /boot/efi/efi/grub/grub.efi /boot/efi/efi/shellx64.efi<br />
or<br />
<br />
# cp /boot/efi/efi/grub/grub.efi /boot/efi/efi/shell/shellx64.efi<br />
<br />
After this launch the UEFI Shell from the UEFI setup/menu (in ASUS UEFI BIOS, switch to advanced mode, press Exit in the top right corner and choose "Launch EFI shell from filesystem device"). The grub2 menu will show up and you can boot into your system. Afterwards you can use efibootmgr to setup a menu entry (see above).<br />
<br />
====== Launch GRUB2 as default in Apple Mac EFI systems ======<br />
<br />
{{Note|Using {{Filename|efibootmgr}} in Apple Macs will brick the firmware and may need reflash of the motherboard ROM. There have been bug reports regarding this in Ubuntu/Launchpad bug tracker. Use bless command alone in case of Macs}}<br />
<br />
Use bless command from within Mac OS X to setup {{Filename|grub.efi}} as the default boot option. More info at https://help.ubuntu.com/community/UEFIBooting#Apple_Mac_EFI_systems_.28both_EFI_architecture.29 .<br />
<br />
====== Generate GRUB2 UEFI Config file ======<br />
<br />
Finally, generate a configuration for grub2 (this is explained in greater detail in the Configuration section):<br />
<br />
# grub-mkconfig -o /boot/efi/efi/grub/grub.cfg<br />
<br />
If grub2-uefi complains about "no suitable mode found" while booting, go to [[#Correct_GRUB2_No_Suitable_Mode_Found_Error]] .<br />
<br />
===== Generate a custom GRUB2 UEFI Application =====<br />
<br />
If you want, you can create a custom {{Filename|grub_custom.efi}} app using:<br />
# grub-mkimage -d /usr/lib/grub/x86_64-efi -O x86_64-efi -p "" -o /boot/efi/efi/grub/grub_custom.efi <GRUB2_Modules_to_be_included><br />
<br />
{{Note|The '''-p''' option is important for creating a portable {{Filename|grub_custom.efi}} app.}}<br />
<br />
There is no file-size restriction on {{Filename|grub_custom.efi}} either due to GRUB2 or due to the UEFI firmware. Therefore you can include any number of modules you want.<br />
<br />
A "{{Filename|grub.cfg}}" created for BIOS based GRUB2 will be sufficient for the UEFI GRUB2 as long as all the paths in the config are absolute paths. The {{Filename|grub.cfg}} file should exist in the same directory as {{Filename|grub.efi}} or {{Filename|grub_custom.efi}}.<br />
<br />
The {{Filename|grub.efi}} UEFI application can be launched using the firmware's "Boot Manager", "Boot from file" option or using the [https://wiki.archlinux.org/index.php/UEFI#UEFI_Shell UEFI Shell].<br />
<br />
Alternatively, you can also setup {{Filename|/boot/efi/efi/grub}} directory by copying all the files in {{Filename|/usr/lib/grub/x86_64-efi}} to {{Filename|/boot/efi/efi/grub}} and using the above grub-mkimage command to create a {{Filename|grub_custom.efi}} application. Just make sure you have the required modules embedded in {{Filename|grub_custom.efi}} to enable it to access the EFI SYSTEM PARTITION.<br />
<br />
A basic {{Filename|grub_custom.efi}} can be generated using the following command:<br />
# sudo grub-mkimage -d /usr/lib/grub/x86_64-efi -O x86_64-efi -p "" -o /boot/efi/efi/grub/grub_custom.efi part_gpt fat iso9660 udf normal chain linux \<br />
ls search search_fs_file search_fs_uuid search_label help boot configfile echo efi_gop<br />
<br />
===== Multiboot in UEFI =====<br />
<br />
====== Chainload Microsoft Windows x86_64 UEFI-GPT ======<br />
<br />
Find the UUID of the FAT32 filesystem in the UEFI SYSTEM PARTITION where the Windows UEFI Bootloader files reside. For example, if Windows {{Filename|bootmgfw.efi}} exists at {{Filename|/boot/efi/efi/Microsoft/Boot/bootmgfw.efi}} (ignore the upper-lower case differences since that is immaterial in FAT filesystem):<br />
<br />
# grub-probe --target=fs_uuid /boot/efi/efi/Microsoft/Boot/bootmgfw.efi<br />
1ce5-7f28<br />
<br />
Then, add this code to {{Filename|/boot/efi/efi/grub/grub.cfg}} to chainload Windows x86_64 (Vista SP1+, 7 or 8) installed in UEFI-GPT mode :<br />
<br />
menuentry "Microsoft Windows x86_64 UEFI-GPT" {<br />
insmod part_gpt<br />
insmod fat<br />
insmod search_fs_uuid<br />
insmod chain<br />
search --fs-uuid --no-floppy --set=root 1ce5-7f28<br />
chainloader (${root})/efi/Microsoft/Boot/bootmgfw.efi<br />
}<br />
<br />
== Manual Compilation ==<br />
<br />
=== For BIOS Systems ===<br />
<br />
GRUB2 for BIOS systems should be compiled as follows:<br />
<pre><br />
./autogen.sh<br />
<br />
./configure --with-platform=pc --prefix=/usr<br />
<br />
make<br />
<br />
make install<br />
</pre><br />
<br />
The <code>--with-platform=pc</code> generates grub2 for bios alone irrespective of the firmware of the build system.<br />
<br />
=== For UEFI Systems ===<br />
<br />
First [https://wiki.archlinux.org/index.php/Unified_Extensible_Firmware_Interface#Detecting_UEFI_Firmware_Arch Detect which UEFI Firmware arch] you have and then follow the compile instructions below:<br />
<pre><br />
./autogen.sh<br />
<br />
./configure --with-platform=efi --target=TARGET_UEFI_ARCH --prefix=/usr<br />
<br />
make<br />
<br />
make install<br />
</pre><br />
<br />
The "--target" option denotes the UEFI firmware arch. for which grub2 should be compiled, not the architecture of the linux kernel grub2 may boot. <br />
<br />
It is possible to use UEFI 64-bit firmware + GRUB2 as x86_64-EFI app loading a i686 linux kernel, as long as the kernel does not try to access UEFI Runtime Services. Vice-versa situation is also possible. But a x86_64 UEFI firmware cannot launch GRUB2 i386-efi app (unlike x86_64 Operating Systems), and a i386 UEFI firmware will not launch GRUB2 {{Codeline|x86_64-efi}} app. It is important to compile GRUB2 to match the architecture of the UEFI firmware.<br />
<br />
== Configuration ==<br />
<br />
The configuration files are {{Filename|/etc/default/grub}} and {{Filename|/etc/grub.d/*}}. These files are used to generate the {{Filename|/boot/grub/grub.cfg}} file. You can also choose to manually edit {{Filename|grub.cfg}}.<br />
<br />
=== grub-mkconfig ===<br />
<br />
The grub-mkconfig script can be used to generate a {{Filename|grub.cfg}} file. By default the script outputs to stdout. Note that gettext ― an optional dependency of the GRUB2 package ― is required by the grub-mkconfig script. To generate a {{Filename|grub.cfg}} file run the command:<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
Note that grub-mkconfig probably has your grub directory hardcoded to /boot/grub, which is probably wrong if you're using UEFI. Either mount your efi grub directory at /boot/grub or edit the script.<br />
<br />
=== grub.cfg ===<br />
<br />
A basic grub file uses the following options<br />
* {{Codeline|(hdX,Y)}} is the partition {{Codeline|Y}} on disk {{Codeline|X}}, partition numbers starting at 1, disk numbers starting at 0<br />
* {{Codeline|1=set default=N}} is the default boot entry that is chosen after timeout for user action<br />
* {{Codeline|1=set timeout=M}} is the time {{Codeline|M}} to wait in seconds for a user selection before default is booted<br />
* {{Codeline|<nowiki>menuentry "title" {entry options}</nowiki>}} is a boot entry titled {{Codeline|title}}<br />
* {{Codeline|1=set root=(hdX,Y)}} sets the boot partition, where the kernel and GRUB modules are stored (boot need not be a separate partition, and may simply be a directory under the "root" partition ({{Filename|/}})<br />
<br />
An example configuration:<br />
<br />
{{File<br />
|name=/boot/grub/grub.cfg<br />
|content=<nowiki><br />
# Config file for GRUB2 - The GNU GRand Unified Bootloader<br />
# /boot/grub/grub.cfg<br />
<br />
# DEVICE NAME CONVERSIONS<br />
#<br />
# Linux Grub<br />
# -------------------------<br />
# /dev/fd0 (fd0)<br />
# /dev/sda (hd0)<br />
# /dev/sdb2 (hd1,2)<br />
# /dev/sda3 (hd0,3)<br />
#<br />
<br />
# Timeout for menu<br />
set timeout=5<br />
<br />
# Set default boot entry as Entry 0<br />
set default=0<br />
<br />
# (0) Arch Linux<br />
menuentry "Arch Linux" {<br />
set root=(hd0,1)<br />
linux /vmlinuz-linux root=/dev/sda3 ro<br />
initrd /initramfs-linux.img<br />
}<br />
<br />
## (1) Windows<br />
#menuentry "Windows" {<br />
#set root=(hd0,3)<br />
#chainloader +1<br />
#}<br />
</nowiki>}}<br />
<br />
=== Dual-booting ===<br />
<br />
''NOTE: If you want GRUB2 to automatically search for other systems, for example as in Ubuntu. Then you may need to download {{Package AUR|os-prober}} from the [[AUR]].''<br />
<br />
==== Using grub-mkconfig ====<br />
The best way to add other entries is editing the {{Filename|/etc/grub.d/40_custom}}. The entries in this file will be automatically added when running '''grub-mkconfig'''.<br />
After adding the new lines, run:<br />
# grub-mkconfig -o /boot/grub/grub.cfg <br />
to generate an updated {{Filename|grub.cfg}}.<br />
<br />
===== With GNU/Linux =====<br />
<br />
Assuming that the other distro is on partition {{Filename|sda2}}:<br />
<br />
menuentry "Other Linux" {<br />
set root=(hd0,2)<br />
linux /boot/vmlinuz (add other options here as required)<br />
initrd /boot/initrd.img (if the other kernel uses/needs one)<br />
}<br />
<br />
===== With Windows =====<br />
<br />
This assumes that your Windows partition is {{Filename|sda3}}.<br />
<br />
# (2) Windows XP<br />
menuentry "Windows XP" {<br />
set root=(hd0,3)<br />
chainloader (hd0,3)+1<br />
}<br />
<br />
If the windows bootloader is on an entirely different harddrive than grub, it may be necessary to trick Windows into believing that it is in fact the first harddrive. This was possible in the old grub with {{Codeline|map}} and is now done with {{Codeline|drivemap}}. Assume grub is on {{Filename|hd0}} and windows on {{Filename|hd2}}, you need to add the following after {{Codeline|set root}}:<br />
<br />
drivemap -s hd0 hd2<br />
<br />
==== With Windows via EasyBCD and NeoGRUB ====<br />
<br />
Since EasyBCD's NeoGRUB currently does not understand the GRUB2 menu format, chainload to it by replacing the contents of your {{Filename|C:\NST\menu.lst}} file with lines similar to the following:<br />
<br />
default 0<br />
timeout 1<br />
<br />
title Chainload into GRUB v2<br />
root (hd0,7)<br />
kernel /boot/grub/core.img<br />
<br />
===Visual Configuration===<br />
<br />
In GRUB2 it is possible, by default, to change the look of the menu.<br />
<br />
====Background image and bitmap fonts====<br />
<br />
GRUB2 comes with support for background images and bitmap fonts in pf2 format. The unifont font is included in the grub2 package under the filename {{Filename|unicode.pf2}}, or, as only ascii characters under the name {{Filename|ascii.pf2}}. Image formats supported include tga, png and jpeg, providing the correct modules are loaded. The maximum supported resolution depends on your hardware. There are two ways of setting a {{Filename|tga}} file as background. Two sample configurations are shown below.<br />
<br />
Edit {{Filename|/etc/default/grub}} like this:<br />
GRUB_GFXMODE=1024x768x32<br />
GRUB_GFXPAYLOAD_LINUX=keep<br />
GRUB_BACKGROUND="/boot/grub/archlinux.tga"<br />
#GRUB_THEME="/path/to/gfxtheme"<br />
<br />
(archlinux.tga is a placeholder; put your file name there)<br />
<br />
To generate the changes, run: <br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
{{Note|If this example does not work for you try to replace {{Codeline|1=gfxmode="1024x768x32"}} by {{Codeline|1=vbemode="0x105"}}.}}<br />
{{Note|To show all the modes you can use {{Codeline|1=# hwinfo --framebuffer}} (hwinfo is available in [community]), while at grub2 prompt you can use the {{Codeline|1=vbeinfo}} command.}}<br />
{{Note|If you have installed Grub on a separate partition, {{Filename|/boot/grub/archlinux.tga}} becomes {{Filename|/grub/archlinux.tga}}.}}<br />
<br />
====Menu colors====<br />
<br />
As in Grub (0.9x), you can change the menu colors in Grub2. The available colors for GRUB2 are at http://www.gnu.org/software/grub/manual/html_node/Theme-file-format.html#Theme-file-format . <br />
Here is an example:<br />
<br />
Edit {{Filename|/etc/default/grub}}:<br />
GRUB_COLOR_NORMAL="light-blue/black"<br />
GRUB_COLOR_HIGHLIGHT="light-cyan/blue"<br />
<br />
Generate the changes:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
====Hidden menu====<br />
<br />
One of the unique features of Grub2 is hiding/skipping the menu and showing it by holding "Shift" when needed. You can also adjust whether you want to see the timeout counter.<br />
<br />
Edit {{Filename|/etc/default/grub}} as you wish. Here is an example where the comments from the beginning of the two lines have been removed to enable the feature, the timeout has been set to five seconds and to be shown to the user:<br />
GRUB_HIDDEN_TIMEOUT=5<br />
GRUB_HIDDEN_TIMEOUT_QUIET=false<br />
<br />
and run:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
====Setting the framebuffer resolution ====<br />
<br />
Grub2 can set the framebuffer for both grub2 itself and the kernel. The old ''vga='' way is deprecated. The preferred method is editing {{Filename|/etc/default/grub}} as the following sample:<br />
<br />
GRUB_GFXMODE=1024x768x32<br />
GRUB_GFXPAYLOAD_LINUX=keep<br />
<br />
To generate the changes, run: <br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
The {{Codeline|gfxpayload}} property will make sure the kernel keeps the resolution.<br />
<br />
If this method does not work for you, the deprecated <code>vga=</code> method will still work. Just<br />
add it next to the <code>"GRUB_CMDLINE_LINUX_DEFAULT="</code> line in {{Filename|/etc/default/grub}}<br />
for eg: <code>"GRUB_CMDLINE_LINUX_DEFAULT="quiet splash vga=792"</code> will give you a {{Codeline|1024x768}} resolution.<br />
<br />
You can choose one of these resolutions: {{Codeline|640×480}}, {{Codeline|800×600}}, {{Codeline|1024×768}}, {{Codeline|1280×1024}}, {{Codeline|1600×1200}}<br />
<br />
=== Other Options ===<br />
<br />
==== LVM ====<br />
<br />
If you use [[LVM]] for your {{Filename|/boot}}, add the following before menuentry lines:<br />
<br />
insmod lvm<br />
<br />
and specify your root in the menuentry as:<br />
<br />
set root=(''lvm_group_name''-''lvm_logical_boot_partition_name'')<br />
<br />
Example:<br />
<br />
# (0) Arch Linux<br />
menuentry "Arch Linux" {<br />
insmod lvm<br />
set root=(VolumeGroup-lv_boot)<br />
# you can only set following two lines<br />
linux /vmlinuz-linux root=/dev/mapper/VolumeGroup-root ro<br />
initrd /initramfs-linux.img<br />
}<br />
<br />
==== Raid ====<br />
<br />
Grub2 provides convenient handling of raid-volumes. You need to add:<br />
insmod raid<br />
<br />
which allows you to address the volume natively. E.g. {{Filename|/dev/md0}} becomes:<br />
set root=(md0)<br />
<br />
whereas a partitioned raid-volume (e.g. {{Filename|/dev/md0p1}}) becomes:<br />
set root=(md0,1)<br />
<br />
==== Persistent block device naming ====<br />
You can use UUIDs to detect partitions instead of the "old" {{Filename|/dev/sd*}} and {{Filename|/dev/hd*}} scheming. It has the advantage of detecting partitions by their unique UUIDs, which is needed by some people booting with complicated partition setups.<br />
<br />
UUIDs are used by default in the recent versions of grub2 - there is no downside in it anyway except that you need to re-generate the {{Filename|grub.cfg}} file every time you resize or reformat your partitions. Remember this when modifying partitions with Live-CD.<br />
<br />
The recent versions of grub2 use UUIDs by default. You can re-enable the use of UUIDS by simply commenting the UUID line (this is also what it looks like by default):<br />
#GRUB_DISABLE_LINUX_UUID=true<br />
you can also just set the value as {{Codeline|false}} as shown here:<br />
GRUB_DISABLE_LINUX_UUID=false<br />
<br />
Either way, do not forget to generate the changes:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
==== Using Labels ====<br />
<br />
It is possible to use labels, human-readable strings attached to filesystems, by using the {{Codeline|--label}} option to {{Codeline|search}}. First of all, label your existing partition:<br />
# tune2fs -L a <LABEL> <PARTITION><br />
<br />
Then, add an entry using labels. An example of this:<br />
<br />
menuentry "Arch Linux, session texte" {<br />
search --label --no-floppy --set=root archroot<br />
linux /boot/vmlinuz-linux root=/dev/disk/by-label/archroot ro<br />
initrd /boot/initramfs-linux.img<br />
}<br />
<br />
==== Recall previous entry ====<br />
<br />
Grub2 can remember the last entry you booted from and use this as the default entry to boot from next time. This is useful if you have multiple kernels (i.e., the current Arch one and the LTS kernel as a fallback option) or operating systems. To do this, edit {{Filename|/etc/default/grub}} and change the setting of {{Codeline|GRUB_DEFAULT}}:<br />
<br />
GRUB_DEFAULT=saved<br />
<br />
This ensures that grub will default to the saved entry. To enable saving the selected entry, add the following line to {{Filename|/etc/default/grub}}:<br />
<br />
GRUB_SAVEDEFAULT=true<br />
<br />
Remember to regenerate your configuration file.<br />
<br />
==== Security ====<br />
<br />
If you want to secure GRUB2 so it is not possible for anyone to change boot parameters or use the command line, you can add a user/password combination to GRUB2's configuration files. To do this, run the command {{Codeline|grub-mkpasswd_pbkdf2}}. Enter a password and confirm it. The output will look like this:<br />
<br />
<pre style='overflow:auto'><br />
Your PBKDF2 is grub.pbkdf2.sha512.10000.C8ABD3E93C4DFC83138B0C7A3D719BC650E6234310DA069E6FDB0DD4156313DA3D0D9BFFC2846C21D5A2DDA515114CF6378F8A064C94198D0618E70D23717E82.509BFA8A4217EAD0B33C87432524C0B6B64B34FBAD22D3E6E6874D9B101996C5F98AB1746FE7C7199147ECF4ABD8661C222EEEDB7D14A843261FFF2C07B1269A</pre>Then, add the following to {{Filename|/etc/grub.d/00_header}}:<br />
<pre>cat << EOF<br />
<br />
set superusers="username"<br />
password_pbkdf2 username <password><br />
<br />
EOF</pre><br />
where <password> is the string generated by {{Codeline|grub-mkpasswd_pbkdf2}}.<br />
<br />
Regenerate your configuration file. Your GRUB2 command line and boot parameters are now protected.<br />
<br />
=== Booting an Ubuntu ISO Image from the GRUB2 Screen ===<br />
<br />
Edit {{Filename|/etc/grub.d/40_custom}} to add an entry pointing to an Ubuntu iso:<br />
<br />
menuentry "ubuntu-11.04-desktop-amd64.iso" {<br />
set isofile="/path/to/ubuntu-11.04-desktop-amd64.iso"<br />
loopback loop (hdX,Y)$isofile<br />
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile quiet noeject noprompt splash --<br />
initrd (loop)/casper/initrd.lz<br />
}<br />
<br />
Be sure to adjust the "hdX,Y" in the third line to point to the correct disk/partition number of the isofile. When finished, update grub2's configuration file via:<br />
<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
== Using the command shell ==<br />
<br />
Since the MBR is too small to store all GRUB2 modules, only the menu and a few basic commands reside there. The majority of GRUB2 functionality remains in modules in {{Filename|/boot/grub}}, which are inserted as needed. In error conditions (e.g. if the partition layout changes) GRUB2 may fail to boot. When this happens, a command shell may appear.<br />
<br />
GRUB2 offers multiple shells/prompts. If there is a problem reading the menu but the bootloader is able to find the disk, you will likely be dropped to the "normal" shell:<br />
sh:grub><br />
<br />
If there is a more serious problem (e.g. GRUB cannot find required files), you may instead be dropped to the "rescue" shell:<br />
grub rescue><br />
<br />
The rescue shell is a restricted subset of the normal shell, offering much less functionality. If dumped to the rescue shell, first try inserting the "normal" module, then starting the "normal" shell:<br />
grub rescue> set prefix=(hdX,Y)/boot/grub<br />
grub rescue> insmod (hdX,Y)/boot/grub/normal.mod<br />
rescue:grub> normal<br />
<br />
=== Pager support ===<br />
<br />
GRUB2 supports pager for reading commands that provide long output (like the help command). This works only in normal shell mode and not in rescue mode. To enable pager, in GRUB2 command shell type:<br />
sh:grub> set pager=1<br />
<br />
== GUI configuration tools ==<br />
<br />
Following package may be installed from [[AUR]]<br />
* [http://kde-apps.org/content/show.php?content=139643 grub2-editor] (requires kdelibs)<br />
*:A KDE4 control module for configuring the GRUB2 bootloader<br />
* [http://kde-apps.org/content/show.php?content=137886 kcm-grub2] (requires kdelibs python2-qt kdebindings-python)<br />
*:This Kcm module manages the most common settings of Grub2.<br />
* [http://sourceforge.net/projects/startup-manager/ startupmanager] (requires gnome-python imagemagick yelp python2 xorg-xrandr)<br />
*:GUI app for changing the settings of GRUB, GRUB2, Usplash and Splashy<br />
<br />
== parttool or legacy hide/unhide ==<br />
<br />
If you have a win9x paradigm with hidden C disks GRUB legacy had the hide/unhide feature. In GRUB2 this has been replaced by parttool. For example, to boot the third C disk of three win9x installations on the CLI enter the CLI and:<br />
parttool hd0,1 hidden+ boot-<br />
parttool hd0,2 hidden+ boot-<br />
parttool hd0,3 hidden- boot+<br />
set root=hd0,3<br />
chainloader +1<br />
boot<br />
<br />
== Using the rescue console ==<br />
<br />
See [[#Using the command shell]] first. If unable to activate the standard shell, one possible solution is to boot using a live CD or some other rescue disk to correct configuration errors and reinstall GRUB. However, such a boot disk is not always available (nor necessary); the rescue console is surprisingly robust.<br />
<br />
The available commands in GRUB rescue include "insmod", "ls", "set", and "unset". This example uses "set" and "insmod". "set" modifies variables and "insmod" inserts new modules to add functionality.<br />
<br />
Before starting, the user must know the location of their {{Filename|/boot}} partition (be it a separate partition, or a subdirectory under their root):<br />
grub rescue> set prefix=(hdX,Y)/boot/grub<br />
<br />
where X is the physical drive number and Y is the partition number.<br />
<br />
To expand console capabilities, insert the "linux" module:<br />
grub rescue> insmod (hdX,Y)/boot/grub/linux.mod<br />
<br />
{{Note|With a separate boot partition, omit {{Filename|/boot}} from the path, (i.e. type {{Codeline|1=set prefix=(hdX,Y)/grub}} and {{Codeline|insmod (hdX,Y)/grub/linux.mod}}).}}<br />
<br />
This introduces the "linux" and "initrd" commands, which should be familiar (see [[#Configuration]]).<br />
<br />
An example, booting Arch Linux:<br />
set root=(hd0,5)<br />
linux /boot/vmlinuz-linux root=/dev/sda5<br />
initrd /boot/initramfs-linux.img<br />
boot<br />
<br />
With a separate boot partition, again change the lines accordingly:<br />
set root=(hd0,5)<br />
linux /vmlinuz-linux root=/dev/sda6<br />
initrd /initramfs-linux.img<br />
boot<br />
<br />
After successfully booting the Arch Linux installation, users can correct {{Filename|grub.cfg}} as needed and then run:<br />
# grub-install /dev/sda --no-floppy<br />
<br />
to reinstall GRUB2 and fix the problem completely, changing {{Filename|/dev/sda}} if needed. See [[#Bootloader installation]] for details.<br />
<br />
== Combining the use of UUID's and basic scripting ==<br />
<br />
If you like the idea of using UUID's to avoid unreliable BIOS mappings or are struggling with Grub's syntax, here is an example boot menu item that uses UUID's and a small script to direct Grub to the proper disk partitions for your system. All you need to do is replace the UUID's in the sample with the correct UUID's for your system. (The example applies to a system with a boot and root partition. You will obviously need to modify the Grub configuration if you have additional partitions.)<br />
<br />
menuentry "Arch Linux 64" {<br />
#Enter the UUID of your boot partition (this is where Grub and your kernel reside)<br />
set uuid_grub_boot=ece0448f-bb08-486d-9864-ac3271bd8d07<br />
<br />
#Enter the UUID of the partition containing the root partition of your Arch Linux installation. <br />
set uuid_os_root=c55da16f-e2af-4603-9e0b-03f5f565ec4a<br />
<br />
#(Note: this may be the same as your boot partition)<br />
<br />
#Here we set the Grub "root" variable by locating the UUID of the root partition identified above <br />
search --fs-uuid --no-floppy --set=root $uuid_os_root<br />
<br />
#Here we set a custom variable grub_boot by locating the UUID of the boot partition identified above <br />
search --fs-uuid --no-floppy --set=grub_boot $uuid_grub_boot<br />
<br />
#Here is the magic. We test to see if the boot and root partitions have the same UUID.<br />
#If they do, we append /boot to the $grub_boot variable. For ex. (hd0,1) becomes (hd0,1)/boot.<br />
if [ $uuid_grub_boot == $uuid_os_root ] ; then<br />
set grub_boot=$grub_boot/boot<br />
fi<br />
<br />
# $grub_boot now points to the correct location, so the following will properly find the kernel and initrd<br />
linux ($grub_boot)/vmlinuz-linux root=/dev/disk/by-uuid/$uuid_os_root ro<br />
initrd ($grub_boot)/initramfs-linux.img<br />
}<br />
<br />
== Troubleshooting ==<br />
<br />
Any troubleshooting should be added here.<br />
<br />
=== Enable GRUB2 debug messages ===<br />
<br />
Add<br />
<br />
set pager=1<br />
set debug=all<br />
<br />
to {{Filename|grub.cfg}}.<br />
<br />
=== Correct GRUB2 No Suitable Mode Found Error ===<br />
<br />
If you get this error when booting any menuentry<br />
<br />
error: no suitable mode found<br />
Booting however<br />
<br />
Then you need to initialize grub2 graphical terminal (gfxterm) with proper video mode (gfxmode) in grub2. This video mode is passed by grub2 to the linux kernel via 'gfxpayload'. In case of UEFI systems, if the grub2 video mode is not initialized, no kernel boot messages will be shown in the terminal (atleast until KMS kicks in)<br />
<br />
Copy {{Filename|/usr/share/grub/unicode.pf2}} to ${GRUB2_PREFIX_DIR} ({{Filename|/boot/grub/}} in case of BIOS systems and {{Filename|/boot/efi/efi/grub/}} in case of UEFI systems). <br />
<br />
# cp /usr/share/grub/unicode.pf2 ${GRUB2_PREFIX_DIR}<br />
<br />
If {{Filename|/usr/share/grub/unicode.pf2}} does not exist, install {{Package Official|bdf-unifont}}, create the unifont.pf2 file and then copy it to ${GRUB2_PREFIX_DIR} .<br />
<br />
# grub-mkfont -o unicode.pf2 /usr/share/fonts/misc/unifont.bdf<br />
<br />
Then, in the {{Filename|grub.cfg}} file, add the following lines to enable grub2 to pass the video mode correctly to the kernel, without of which you will only get a black screen (no output) but booting (actually) proceeds successfully without any system hang:<br />
<br />
BIOS systems<br />
<br />
insmod vbe<br />
<br />
UEFI systems<br />
<br />
insmod efi_gop<br />
insmod efi_uga<br />
<br />
After that add the following code (common to both BIOS and UEFI)<br />
<br />
insmod font<br />
<br />
if loadfont ${prefix}/unicode.pf2<br />
then<br />
insmod gfxterm<br />
set gfxmode=auto<br />
set gfxpayload=keep<br />
terminal_output gfxterm<br />
fi<br />
<br />
As you can see for gfxterm (graphical terminal) to function properly, {{Filename|unicode.pf2}} font file should exist in ${GRUB2_PREFIX_DIR}.<br />
<br />
=== msdos-style error message ===<br />
<br />
grub-setup: warn: This msdos-style partition label has no post-MBR gap; embedding won't be possible!<br />
grub-setup: warn: Embedding is not possible. GRUB can only be installed in this setup by using blocklists.<br />
However, blocklists are UNRELIABLE and its use is discouraged.<br />
grub-setup: error: If you really want blocklists, use --force.<br />
<br />
This error may occur when you try installing GRUB2 in a VMware container. Read more about it [http://bbs.archlinux.org/viewtopic.php?pid=581760#p581760 here]. It happens when the first partition starts just after the MBR (block 63), without the usual space of 1 MiB (2048 blocks) before the first partition. Read [[#MBR_aka_msdos_partitioning_specific_instructions]]<br />
<br />
=== UEFI GRUB2 not loaded ===<br />
In some cases the EFI may fail to load grub correctly. Provided everything is set up correctly, the output of<br />
efibootmgr -v<br />
might look something like this:<br />
BootCurrent: 0000<br />
Timeout: 3 seconds<br />
BootOrder: 0000,0001,0002<br />
Boot0000* Grub HD(1,800,32000,23532fbb-1bfa-4e46-851a-b494bfe9478c)File(\efi\grub\grub.efi)<br />
Boot0001* Shell HD(1,800,32000,23532fbb-1bfa-4e46-851a-b494bfe9478c)File(\EfiShell.efi)<br />
Boot0002* Festplatte BIOS(2,0,00)P0: SAMSUNG HD204UI .<br />
If everything works correctly, the EFI would now automatically load grub.<br><br />
If the screen only goes black for a second and the next boot option is tried afterwards, according to [https://bbs.archlinux.org/viewtopic.php?pid=981560#p981560 this post], moving grub to the partition root can help. The boot option has to be deleted and recreated afterwards. The entry for grub should look like this then:<br />
Boot0000* Grub HD(1,800,32000,23532fbb-1bfa-4e46-851a-b494bfe9478c)File(\grub.efi)<br />
<br />
=== Invalid signature ===<br />
If trying to boot windows results in an "invalid signature" error, e.g. after reconfiguring partitions or adding additional hard drives, (re)move grub's device configuration and let it reconfigure.<br />
# mv /boot/grub/device.map /boot/grub/device.map-old<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
Grub-mkconfig should now mention all found boot options including windows. If it works, remove /boot/grub/device.map-old.<br />
<br />
== References ==<br />
<br />
# Official GRUB2 Manual - http://www.gnu.org/software/grub/manual/grub.html<br />
# GRUB2 wiki page describing steps to compile for UEFI systems - https://help.ubuntu.com/community/UEFIBooting - previously http://grub.enbug.org/TestingOnUEFI{{Linkrot|2011|09|05}}<br />
# Wikipedia's page on [http://en.wikipedia.org/wiki/BIOS_Boot_partition BIOS Boot Partition]<br />
<br />
== External Links ==<br />
<br />
# [https://github.com/the-ridikulus-rat/My_Shell_Scripts/blob/master/grub2/grub2_bios.sh A Linux Bash Shell script to compile and install GRUB2 for BIOS from BZR Source]<br />
# [https://github.com/the-ridikulus-rat/My_Shell_Scripts/blob/master/grub2/grub2_uefi.sh A Linux Bash Shell script to compile and install GRUB2 for UEFI from BZR Source]</div>Mayweedhttps://wiki.archlinux.org/index.php?title=GRUB&diff=167967GRUB2011-10-29T18:17:57Z<p>Mayweed: </p>
<hr />
<div>[[Category:Boot loaders (English)]]<br />
{{i18n|GRUB2}}<br />
[[fr:GRUB2]]<br />
{{Article summary start}}<br />
{{Article summary text|Covers various aspects of the next generation of the GRand Unified Bootloader (GRUB2).}}<br />
{{Article summary heading|Overview}}<br />
{{Article summary text|{{Boot process overview}}}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|Burg}} - Burg is a brand-new boot loader based on GRUB2. It uses a new object format which allows it to be built in a wider range of OS, including Linux/Windows/OSX/Solaris/FreeBSD, etc. It also has a highly configurable menu system which works in both text and graphic mode. <br />
{{Article summary heading|Resources}}<br />
{{Article summary link|GNU GRUB -- GNU Project|http://www.gnu.org/software/grub/}}<br />
{{Article summary link|GNU GRUB Wiki|http://grub.enbug.org/}}{{Linkrot|2011|09|05}}<br />
{{Article summary end}}<br />
<br />
[http://www.gnu.org/software/grub/ GRUB2] is the next generation of the GRand Unified Bootloader (GRUB). GRUB2 is derived from [http://www.nongnu.org/pupa/ PUPA] which was a research project to investigate the next generation of GRUB. GRUB 2 has been rewritten from scratch to clean up everything and provide modularity and portability [http://www.gnu.org/software/grub/grub-faq.en.html#q1].<br />
<br />
Briefly, the ''bootloader'' is the first software program that runs when a computer starts. It is responsible for loading and transferring control to the Linux kernel. The kernel, in turn, initializes the rest of the operating system.<br />
<br />
== Preface ==<br />
<br />
Although, [[GRUB]] (i.e. version 0.9x) is the de facto standard bootloader of Linux, it is considered 'legacy' by upstream. It is being replaced by GRUB2 in many distributions. Upstream recommends GRUB2 >=1.99~rc2 over grub-legacy, even for current grub-legacy users.<br />
<br />
{{Note|grub2 from 1.99~rc2 and later supports btrfs as root (without a separate /boot filesystem).}}<br />
<br />
=== Notes for current GRUB users ===<br />
<br />
* There are differences in the commands of GRUB and GRUB2. Familiarize yourself with [http://www.gnu.org/software/grub/manual/grub.html#Commands GRUB2 commands] before proceeding (e.g. "find" has been replaced with "search").<br />
<br />
* GRUB2 is now ''modular'' and no longer requires "stage 1.5". As a result, the bootloader itself is limited -- modules are loaded from the hard drive as needed to expand functionality (e.g. for [[LVM]] or RAID support).<br />
<br />
* Device naming has changed between GRUB and GRUB2. Partitions are numbered from 1 instead of 0 while drives are still numbered from 0, and prefixed with partition-table type. For example, {{Filename|/dev/sda1}} would be referred to as {{Codeline|(hd0,msdos1)}} (for MBR) or {{Codeline|(hd0,gpt1)}} (for GPT) using GRUB2.<br />
<br />
===== Preliminary Considerations for GRUB2 BIOS =====<br />
<br />
====== [[GPT]] specific instructions ======<br />
<br />
GRUB2 in BIOS-GPT configuration requires a BIOS Boot Partition to embed its core.img in the absence of post-MBR gap in GPT partitioned systems (which is taken over by the GPT Primary Header and Primary Partition table). This partition is used by GRUB2 only in BIOS-GPT setups. No such partition type exists in case of MBR partitioning (at least not for GRUB2). This partition is also not required if the system is UEFI based, as no embedding of bootsectors takes place in that case. Syslinux does not require this partition.<br />
<br />
For a BIOS-GPT configuration, create a 2 MiB partition using cgdisk or GNU Parted with no filesystem. The location of the partition in the partition table does not matter but it should be within the first 2 TiB region of the disk. It is advisable to put it somewhere in the beginning of the disk before the /boot partition. Set the partition type to "EF02" in cgdisk or {{Codeline|set <BOOT_PART_NUM> bios_grub on}} in GNU Parted.<br />
<br />
{{Note|This partition should be created before grub_bios-install or grub-setup is run or before the '''Install Bootloader''' step of the Archlinux installer (if GRUB2 is selected as bootloader).}}<br />
<br />
====== [[MBR]] aka msdos partitioning specific instructions ======<br />
<br />
Usually the post-MBR gap (after the 512 byte MBR region and before the start of the 1st partition) in many MBR (or msdos disklabel) partitioned systems is 32 KiB when DOS compatibility cylinder alignment issues are satisfied in the partition table. However a post-MBR gap of about 1 to 2 MiB is recommended to provide sufficient room for embedding grub2's core.img ( https://bugs.archlinux.org/task/24103 ). It is advisable to use a partitioner which supports 1 MiB partition alignment to obtain this space as well as satisfy other non-512 byte sector issues (which are unrelated to embedding of core.img).<br />
<br />
If you do not dual-boot with MS Windows (any version) in BIOS systems, it is advisable to switch to GPT partitioning - [[GUID_Partition_Table#Convert_from_MBR_to_GPT_without_data_loss]]<br />
{{Note|Create the 2MiB partition mentioned above BEFORE you convert to GPT. If you do not, gparted will not resize your boot partition to allow its creation, and when you reboot grub2 will not know where to look.}}<br />
<br />
== Installation ==<br />
<br />
=== During Arch Linux installation ===<br />
<br />
* Skip the '''Install Bootloader''' step and exit the installer.<br />
* Configure the network:<br />
# aif -p partial-configure-network<br />
This will bring up a prompt; put in the network interface to use, (e.g., eth0) and use DHCP for easy configuration.<br />
* If you did not configure the installed system's {{Filename|/etc/resolv.conf}} file during installation (for instance, if you plan to let DHCP generate it later), you will need to copy the one generated by AIF when it configured the network:<br />
# cp /etc/resolv.conf /mnt/etc/resolv.conf<br />
* Load the dm-mod module (you might need grub2-bios; install the package if needed):<br />
# modprobe dm-mod<br />
{{Note|This is necessary at this point, and cannot be postponed after the chroot. If you try to use modprobe in a chroot environment that has a later kernel version from that of the installing device (at the time of writing, 2.6.33), modprobe will fail. This happens routinely using the Arch "net" installations.}}<br />
* From the installer's live shell, chroot to the installed system:<br />
# mount -o bind /dev /mnt/dev<br />
# chroot /mnt bash<br />
* Update pacman's database:<br />
# pacman-db-upgrade<br />
* Refresh the package list (with an extra -y flag to force a refresh of all package lists even if they appear to be up to date):<br />
# pacman -Syy<br />
* Install the GRUB2 package as mentioned in the section [[#From a running Arch Linux]]. Note that the dm-mod module has already been loaded, no need to do that again.<br />
<br />
=== From a running Arch Linux ===<br />
<br />
====Make a backup of your precious data====<br />
In general, a grub installation ran smoothly and you got no problems at all. And sometimes it could simply messed up your system. You're strongly advised to make a backup before even think of grub2.<br />
<br />
*copy grub modules and configuration<br />
# cp -a /boot/grub /path/to/backup/<br />
*backup the MBR and GRUB stage 1.5<br />
# dd if=/dev/sda of=/path/to/backup/first-sectors count=63<br />
<br />
You could now lightly remove {{Filename|/boot/grub}} with:<br />
# rm -rf /boot/grub<br />
<br />
and follow the instructions below.You know that if things get nasty, you could reboot your system thanks to an installation media and :<br />
<br />
*move old grub2 files out of the way<br />
# mv /boot/grub /boot/grub.nonfunctional<br />
*copy grub back to /boot<br />
# cp -a /path/to/backup/grub /boot/<br />
*replace MBR and next 62 sectors of sda with backed up copy (DANGEROUS!)<br />
# dd if=/path/to/backup/first-sectors of=/dev/sda count=63<br />
<br />
<br />
===== grub2-bios-install =====<br />
<br />
The GRUB2 package can be installed with pacman (and will replace {{Package Official|grub}}, if it is installed):<br />
<br />
# pacman -S grub2-bios<br />
<br />
{{Note|Installing grub2-common (a dependency of grub2-bios) 1.99~rc1 or later, may take forever in some systems since the post_install script runs grub-mkconfig and this script does not provide the option <code>--no-floppy</code>. For more details search this option in the article.}}<br />
<br />
{{Note|Simply installing the package won't update the /boot/grub/core.img file and the grub2 modules in /boot/grub . You need to update the core.img file and the grub2 modules manually using grub_bios-install as explained below.}}<br />
<br />
Also load the device-mapper kernel module without which grub-probe does not reliably detect disks and partitions<br />
<br />
# modprobe dm-mod<br />
<br />
<br />
===== Run grub_bios-install =====<br />
<br />
There are 3 ways to install grub2 in BIOS booting - [[#Install_to_440-byte_MBR_boot_code_region]] (recommended) , [[#Install_to_Partition_or_Partitionless_Disk]] (not recommended) or [[#Generate_core.img_alone]] (safest method, but requires another BIOS bootloader like [[grub-legacy]] or [[syslinux]] to be installed to chainload {{Filename|/boot/grub/core.img}} ). For all the ways [[#Before_grub_bios-install]] step is needed.<br />
<br />
====== Install to 440-byte MBR boot code region ======<br />
<br />
To setup grub2-bios in the 440-byte Master Boot Record boot code region, populate the {{Filename|/boot/grub}} directory, generate the {{Filename|/boot/grub/core.img}} file, and embed it in the 32 KiB (minimum size - varies depending on partition alignment) post-MBR gap (MBR disks) or in BIOS Boot Partition (GPT disks), run<br />
<br />
# grub_bios-install --boot-directory=/boot --no-floppy --recheck /dev/sda<br />
<br />
where {{Filename|/dev/sda}} is the destination of the installation (in this case the MBR of the first SATA disk). If you use [[LVM]] for your {{Filename|/boot}}, you can install GRUB2 on multiple physical disks. <br />
<br />
The {{Codeline|--no-floppy}} tells grub2-bios utilities not to search for any floppy devices which reduces the overall execution time of grub_bios-install on many systems (it will also prevent the issue below from occuring). Otherwise you get an error like this<br />
<br />
grub-probe: error: Cannot get the real path of '/dev/fd0'<br />
Auto-detection of a filesystem module failed.<br />
Please specify the module with the option '--modules' explicitly.<br />
<br />
Then:<br />
<br />
* Follow [[#Generate_GRUB2_BIOS_Config_file]] or if that fails, convert your {{Filename|/boot/grub/menu.lst}} file to {{Filename|/boot/grub/grub.cfg}} using:<br />
<br />
# grub-menulst2cfg /boot/grub/menu.lst /boot/grub/grub.cfg<br />
<br />
For example:<br />
<br />
{{File|name=/boot/grub/menu.lst|content=<br />
default=0<br />
timeout=5<br />
<br />
title Arch Linux Stock Kernel<br />
root (hd0,0)<br />
kernel /vmlinuz-linux root=/dev/sda2 ro<br />
initrd /initramfs-linux.img<br />
<br />
title Arch Linux Stock Kernel Fallback<br />
root (hd0,0)<br />
kernel /vmlinuz-linux root=/dev/sda2 ro<br />
initrd /initramfs-linux-fallback.img<br />
}}<br />
<br />
{{File|name=/boot/grub/grub.cfg|content=<br />
set default='0'; if [ x"$default" = xsaved ]; then load_env; set default="$saved_entry"; fi<br />
set timeout=5<br />
<br />
menuentry 'Arch Linux Stock Kernel' {<br />
set root='(hd0,1)'; set legacy_hdbias='0'<br />
legacy_kernel '/vmlinuz-linux' '/vmlinuz-linux' 'root=/dev/sda2' 'ro'<br />
legacy_initrd '/initramfs-linux.img' '/initramfs-linux.img'<br />
<br />
}<br />
<br />
menuentry 'Arch Linux Stock Kernel Fallback' {<br />
set root='(hd0,1)'; set legacy_hdbias='0'<br />
legacy_kernel '/vmlinuz-linux' '/vmlinuz-linux' 'root=/dev/sda2' 'ro'<br />
legacy_initrd '/initramfs-linux-fallback.img' '/initramfs-linux-fallback.img'<br />
}<br />
}}<br />
<br />
<br />
* If you forgot to create a GRUB2 {{Filename|/boot/grub/grub.cfg}} configfile and simply rebooted into GRUB2 Command Shell, type:<br />
<br />
sh:grub> insmod legacycfg<br />
sh:grub> legacy_configfile ${prefix}/menu.lst<br />
<br />
Boot into Arch and re-create the proper GRUB2 {{Filename|/boot/grub/grub.cfg}} configfile.<br />
<br />
{{Note|This option works only in BIOS systems, not in UEFI systems.}}<br />
<br />
====== Install to Partition or Partitionless Disk ======<br />
<br />
{{Note|grub2-bios (any version - including upstream bzr repo) does not encourage installation to a partition boot sector or a partitionless disk like grub-legacy or syslinux does. Neither do the Arch devs.}}<br />
<br />
To setup grub2-bios to a partition boot sector, to a partitionless disk (also called superfloppy) or to a floppy disk, run (using for example /dev/sda1 as the /boot partition)<br />
<br />
# chattr -i /boot/grub/core.img<br />
# grub_bios-install --boot-directory=/boot --no-floppy --recheck --force /dev/sda1<br />
# chattr +i /boot/grub/core.img<br />
<br />
You need to use the {{Codeline|--force}} option to allow usage of blocklists and should not use <code>--grub-setup=/bin/true</code> (which is similar to simply generating core.img).<br />
<br />
grub_bios-install will give out warnings like which should give you the idea of what might go wrong with this approach.<br />
<br />
/sbin/grub-setup: warn: Attempting to install GRUB to a partitionless disk or to a partition. This is a BAD idea.<br />
/sbin/grub-setup: warn: Embedding is not possible. GRUB can only be installed in this setup by using blocklists. <br />
However, blocklists are UNRELIABLE and their use is discouraged.<br />
<br />
Without {{Codeline|--force}} you may get the below error and grub-setup will not setup its boot code in the partition boot sector.<br />
<br />
/sbin/grub-setup: error: will not proceed with blocklists<br />
<br />
With {{Codeline|--force}} you should get<br />
<br />
Installation finished. No error reported.<br />
<br />
The reason why grub-setup does not by default allow this is because in case of partition or a partitionless disk is that grub2-bios relies on embedded blocklists in the partition bootsector to locate the {{Filename|/boot/grub/core.img}} file and the prefix dir {{Filename|/boot/grub}} . The sector locations of {{Filename|core.img}} may change whenever the filesystem in the partition is being altered (files copied, deleted etc.). For more info see https://bugzilla.redhat.com/show_bug.cgi?id=728742 and https://bugzilla.redhat.com/show_bug.cgi?id=730915 .<br />
<br />
The workaround for this is to set the immutable flag on {{Filename|/boot/grub/core.img}} (using chattr command as mentioned above) so that the sector locations of the {{Filename|core.img}} file in the disk is not altered. The immutable flag on {{Filename|/boot/grub/core.img}} needs to be set only if grub2-bios is installed to a partition boot sector or a partitionless disk, not in case of installtion to MBR or simple generation of {{Filename|core.img}} without embedding any bootsector (mentioned above). <br />
<br />
====== Generate core.img alone ======<br />
<br />
To populate the {{Filename|/boot/grub}} directory and generate a {{Filename|/boot/grub/core.img}} file WITHOUT embedding any grub2-bios bootsector code in the MBR, post-MBR region, or the partition bootsector, add <code>--grub-setup=/bin/true</code> to grub_bios-install:<br />
<br />
# grub_bios-install --grub-setup=/bin/true --boot-directory=/boot --no-floppy --recheck /dev/sda<br />
<br />
You can then chainload grub2's core.img from grub-legacy or syslinux as a Linux kernel or a multiboot kernel.<br />
<br />
===== After grub_bios-install =====<br />
<br />
====== Generate GRUB2 BIOS Config file ======<br />
<br />
Finally, generate a configuration for grub2 (this is explained in greater detail in the Configuration section):<br />
<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
If grub2 complains about "no suitable mode found" while booting, go to [[#Correct_GRUB2_No_Suitable_Mode_Found_Error]] .<br />
<br />
===== Multiboot in BIOS =====<br />
<br />
====== Boot Microsoft Windows installed in BIOS-MBR mode ======<br />
<br />
{{Note|GRUB2 supports booting {{Filename|bootmgr}} directly and chainload of partition boot sector is no longer required to boot Windows in a BIOS-MBR setup.}}<br />
<br />
Find the UUID of the NTFS filesystem of the Windows's SYSTEM PARTITION where the bootmgr and its files reside. For example, if Windows {{Filename|bootmgr}} exists at {{Filename|/media/Windows/bootmgr}}:<br />
<br />
# grub-probe --target=fs_uuid /media/Windows/bootmgr<br />
69B235F6749E84CE<br />
<br />
Then, add the below code to {{Filename|/boot/grub/grub.cfg}} to chainload Windows (Vista, 7 or 8) installed in BIOS-MBR mode :<br />
<br />
menuentry "Microsoft Windows 7 BIOS-MBR" {<br />
insmod part_msdos<br />
insmod ntfs<br />
insmod search_fs_uuid<br />
insmod ntldr <br />
search --fs-uuid --no-floppy --set=root 69B235F6749E84CE<br />
ntldr (${root})/bootmgr<br />
}<br />
<br />
For Windows XP<br />
<br />
menuentry "Microsoft Windows XP" {<br />
insmod part_msdos<br />
insmod ntfs<br />
insmod search_fs_uuid<br />
insmod ntldr <br />
search --fs-uuid --no-floppy --set=root 69B235F6749E84CE<br />
ntldr (${root})/ntldr<br />
}<br />
<br />
==== [[UEFI]] systems ====<br />
<br />
===== Before grub_efi_${UEFI_ARCH}-install =====<br />
<br />
{{Note|Unless specified as EFI 1.x , EFI and UEFI terms are used interchangeably to denote UEFI 2.x firmware. Also unless stated explicitely, the instructions are general and not Mac specific. Some of them may not work or may be different in Macs. Apple's EFI implementation is neither a EFI 1.x version nor UEFI 2.x version but mixes up both. This kind of firmware does not fall under any one UEFI Specification version and is therefore not a standard UEFI firmware.}}<br />
<br />
GRUB2 UEFI bootloader is available in Arch Linux only from version 1.99~rc1 . To install, first [https://wiki.archlinux.org/index.php/Unified_Extensible_Firmware_Interface#Detecting_UEFI_Firmware_Arch Detect which UEFI firmware arch] you have (either x86_64 or i386).<br />
<br />
Depending on that, install the appropriate package<br />
<br />
For 64-bit aka x86_64 UEFI firmware:<br />
# pacman -S grub2-efi-x86_64<br />
<br />
For 32-bit aka i386 UEFI firmware:<br />
# pacman -S grub2-efi-i386<br />
<br />
{{Note|Installing grub2-common (a dependency of grub2-bios) 1.99~rc1 or later, may take forever in some systems since the post_install script runs grub-mkconfig and this script does not provide the option <code>--no-floppy</code>. For more details search this option in the article.}}<br />
<br />
{{Note|Simply installing the package won't update the grub.efi file and the grub2 modules in the UEFI System Partition . You need to update the grub.efi file and the grub2 modules in the UEFI System Partition manually using grub_efi_${UEFI_ARCH}-install as explained below.}}<br />
<br />
Also load the device-mapper kernel module without which grub-probe does not reliably detect disks and partitions<br />
<br />
# modprobe dm-mod<br />
<br />
===== Install to UEFI SYSTEM PARTITION =====<br />
<br />
====== Mount UEFI SYSTEM PARTITION ======<br />
<br />
Mount the [https://wiki.archlinux.org/index.php/Unified_Extensible_Firmware_Interface#Creating_a_UEFI_SYSTEM_PARTITION_in_Linux UEFI SYSTEM PARTITION] in your system at {{Filename|/boot/efi}}. It should be FAT32 formatted and should be at least 200 MiB in size. If you have mounted the UEFISYS partition in some other mountpoint, replace {{Filename|/boot/efi}} in the below commands with that mountpoint:<br />
<br />
# mkdir -p /boot/efi<br />
# mount -t vfat <UEFISYS_PART_DEVICE> /boot/efi<br />
# mkdir -p /boot/efi/efi<br />
<br />
====== Run grub_efi_${UEFI_ARCH}-install ======<br />
<br />
{{Note|The below commands assume you are using {{Codeline|grub2-efi-x86_64}} (for {{Codeline|grub2-efi-i386}} replace {{Codeline|x86_64}} with {{Codeline|i386}} in the below commands).}}<br />
<br />
# grub_efi_x86_64-install --root-directory=/boot/efi --boot-directory=/boot/efi/efi --bootloader-id=grub --no-floppy --recheck<br />
<br />
The {{Codeline|grub_efi_x86_64-install}} automatically generates a {{Filename|grub.efi}} while setting up the {{Filename|/boot/efi/efi/grub/}} directory.<br />
<br />
If you notice carefully, there is no <device_path> option (Eg: {{Filename|/dev/sda}}) at the end of the {{Codeline|grub_efi_x86_64-install}} command unlike the case of setting up grub2 for BIOS systems. Any <device_path> provided will be ignored by the install script as UEFI bootloaders do not use MBR or Partition boot sectors at all.<br />
<br />
You may now be able to UEFI boot your system by creating a grub.cfg file using grub-mkconfig and copying /boot/efi/efi/grub/grub.efi to /boot/efi/efi/boot/bootx64.efi.<br />
<br />
===== After grub_efi_${UEFI_ARCH}-install =====<br />
<br />
====== Launch GRUB2 as default in non-Mac UEFI systems ======<br />
<br />
{{Note|The below steps will not work if the system has been booted in BIOS mode and will not work if the UEFI processor architecture does not match the kernel one, i.e. x86_64 UEFI + ix86 32-bit Kernel and vice-versa config will not work.}}<br />
<br />
grub_efi_${UEFI_ARCH}-install will ensure {{Filename|/boot/efi/efi/grub/grub.efi}} is launched by default if it detects {{Codeline|efibootmgr}} and if it is able to access UEFI Runtime Services. {{Codeline|efibootmgr}} command will work only if you have booted the system in UEFI mode itself, since it '''requires access to UEFI Runtime Variables''' which are '''available only in UEFI boot mode''' (with "noefi" kernel parameter NOT being used). Initially the user is required to manually launch {{Filename|/boot/efi/efi/grub/grub.efi}} from the firmware itself (using maybe the UEFI Shell) if grub2-efi was installed in BIOS mode. Then {{Codeline|efibootmgr}} should be run to make grub2 as the default entry in the UEFI Boot Manager<br />
<br />
First boot into UEFI mode manually either using the firmware boot menu, UEFI shell, or using any UEFI capable bootable iso (Archboot or Ubuntu non-Mac iso). Use grub probe to determine the device path of your EFI System Partition:<br />
# grub-probe --target=device /boot/efi/efi/grub/grub.efi<br />
<br />
It should give something like {{Filename|/dev/sda1}} (used as example in the remaining steps). Load 'efivars' kernel module:<br />
# modprobe efivars<br />
<br />
If you get '''no such device found''' error for this command, that means you have not booted in UEFI mode or due to some reason the kernel is unable to access UEFI Runtime Variables.<br />
<br />
Verify whether there are files in ''/sys/firmware/efi/vars/'' directory. This directory and its contents are created by "efivars" kernel module and it will exist only if you have booted in UEFI mode without the "noefi" kernel parameter.<br />
<br />
# ls -1 /sys/firmware/efi/vars/<br />
<br />
Sample output (x86_64-UEFI 2.3.1 in x86_64 Kernel:<br />
<br />
# ls -1 /sys/firmware/efi/vars/<br />
Boot0000-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootCurrent-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootOptionSupport-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootOrder-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConIn-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConInDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConOut-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConOutDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ErrOutDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
Lang-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
LangCodes-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
MTC-eb704011-1402-11d3-8e77-00a0c969723b/<br />
MemoryTypeInformation-4c19049f-4137-4dd3-9c10-8b97a83ffdfa/<br />
PlatformLang-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
PlatformLangCodes-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
RTC-378d7b65-8da9-4773-b6e4-a47826a833e1/<br />
del_var<br />
new_var<br />
<br />
If ''/sys/firmware/efi/vars/'' directory is empty or does not exist, then {{Codeline|efibootmgr}} command will not work. If you are unable to make the ISO/CD/DVD/USB boot in UEFI mode try https://gitorious.org/tianocore_uefi_duet_builds/pages/Linux_Windows_BIOS_UEFI_boot_USB .<br />
<br />
If ''/sys/firmware/efi/vars/'' directory (along with the exists then run {{Codeline|efibootmgr}} and reboot:<br />
<br />
# efibootmgr --create --gpt --disk /dev/sda --part 1 --write-signature --label "GRUB2" --loader "\\EFI\\grub\\grub.efi"<br />
<br />
In the above command, {{Filename|/boot/efi/efi/grub/grub/efi}} can be split up as {{Filename|/boot/efi}} and {{Filename|/efi/grub/grub.efi}}, which translates to {{Filename|(/dev/sda)}} -> partition 1 -> {{Filename|\\EFI\\grub\\grub.efi}}. <br />
<br />
FAT32 filesystem is case-insensitive since it does not use UTF-8 encoding by default. In that case the firmware uses capital 'EFI' instead of small 'efi', therefore using {{Filename|\\EFI\\grub\\grub.efi}} or {{Filename|\\efi\\grub\\grub.efi}} does not matter (this will change if the filesystem encoding is UTF-8). UEFI uses backward slash as path separatoir (similar to Windows paths). In the above command "double" backward slashes are used instead of single ones, since a backward slash is used as a escape character by sh shells, the first backward slash escapes the second one so that the path {{Filename|\EFI\grub\grub.efi}} is passed to {{Codeline|efibootmgr}}.<br />
<br />
The 'label' is the name of the menu entry shown in the UEFI boot menu. This name is user's choice and does not affect the booting of the system. More info can be obtained from [http://linux.dell.com/cgi-bin/gitweb/gitweb.cgi?p=efibootmgr.git;a=blob_plain;f=README;hb=HEAD efibootmgr GIT README]<br />
<br />
If you have problems running GRUB2 in UEFI mode you can try the following (worked on an ASUS Z68 mainboard):<br />
<br />
# cp /boot/efi/efi/grub/grub.efi /boot/efi/shellx64.efi<br />
<br />
or<br />
<br />
# cp /boot/efi/efi/grub/grub.efi /boot/efi/efi/shellx64.efi<br />
or<br />
<br />
# cp /boot/efi/efi/grub/grub.efi /boot/efi/efi/shell/shellx64.efi<br />
<br />
After this launch the UEFI Shell from the UEFI setup/menu (in ASUS UEFI BIOS, switch to advanced mode, press Exit in the top right corner and choose "Launch EFI shell from filesystem device"). The grub2 menu will show up and you can boot into your system. Afterwards you can use efibootmgr to setup a menu entry (see above).<br />
<br />
====== Launch GRUB2 as default in Apple Mac EFI systems ======<br />
<br />
{{Note|Using {{Filename|efibootmgr}} in Apple Macs will brick the firmware and may need reflash of the motherboard ROM. There have been bug reports regarding this in Ubuntu/Launchpad bug tracker. Use bless command alone in case of Macs}}<br />
<br />
Use bless command from within Mac OS X to setup {{Filename|grub.efi}} as the default boot option. More info at https://help.ubuntu.com/community/UEFIBooting#Apple_Mac_EFI_systems_.28both_EFI_architecture.29 .<br />
<br />
====== Generate GRUB2 UEFI Config file ======<br />
<br />
Finally, generate a configuration for grub2 (this is explained in greater detail in the Configuration section):<br />
<br />
# grub-mkconfig -o /boot/efi/efi/grub/grub.cfg<br />
<br />
If grub2-uefi complains about "no suitable mode found" while booting, go to [[#Correct_GRUB2_No_Suitable_Mode_Found_Error]] .<br />
<br />
===== Generate a custom GRUB2 UEFI Application =====<br />
<br />
If you want, you can create a custom {{Filename|grub_custom.efi}} app using:<br />
# grub-mkimage -d /usr/lib/grub/x86_64-efi -O x86_64-efi -p "" -o /boot/efi/efi/grub/grub_custom.efi <GRUB2_Modules_to_be_included><br />
<br />
{{Note|The '''-p''' option is important for creating a portable {{Filename|grub_custom.efi}} app.}}<br />
<br />
There is no file-size restriction on {{Filename|grub_custom.efi}} either due to GRUB2 or due to the UEFI firmware. Therefore you can include any number of modules you want.<br />
<br />
A "{{Filename|grub.cfg}}" created for BIOS based GRUB2 will be sufficient for the UEFI GRUB2 as long as all the paths in the config are absolute paths. The {{Filename|grub.cfg}} file should exist in the same directory as {{Filename|grub.efi}} or {{Filename|grub_custom.efi}}.<br />
<br />
The {{Filename|grub.efi}} UEFI application can be launched using the firmware's "Boot Manager", "Boot from file" option or using the [https://wiki.archlinux.org/index.php/UEFI#UEFI_Shell UEFI Shell].<br />
<br />
Alternatively, you can also setup {{Filename|/boot/efi/efi/grub}} directory by copying all the files in {{Filename|/usr/lib/grub/x86_64-efi}} to {{Filename|/boot/efi/efi/grub}} and using the above grub-mkimage command to create a {{Filename|grub_custom.efi}} application. Just make sure you have the required modules embedded in {{Filename|grub_custom.efi}} to enable it to access the EFI SYSTEM PARTITION.<br />
<br />
A basic {{Filename|grub_custom.efi}} can be generated using the following command:<br />
# sudo grub-mkimage -d /usr/lib/grub/x86_64-efi -O x86_64-efi -p "" -o /boot/efi/efi/grub/grub_custom.efi part_gpt fat iso9660 udf normal chain linux \<br />
ls search search_fs_file search_fs_uuid search_label help boot configfile echo efi_gop<br />
<br />
===== Multiboot in UEFI =====<br />
<br />
====== Chainload Microsoft Windows x86_64 UEFI-GPT ======<br />
<br />
Find the UUID of the FAT32 filesystem in the UEFI SYSTEM PARTITION where the Windows UEFI Bootloader files reside. For example, if Windows {{Filename|bootmgfw.efi}} exists at {{Filename|/boot/efi/efi/Microsoft/Boot/bootmgfw.efi}} (ignore the upper-lower case differences since that is immaterial in FAT filesystem):<br />
<br />
# grub-probe --target=fs_uuid /boot/efi/efi/Microsoft/Boot/bootmgfw.efi<br />
1ce5-7f28<br />
<br />
Then, add this code to {{Filename|/boot/efi/efi/grub/grub.cfg}} to chainload Windows x86_64 (Vista SP1+, 7 or 8) installed in UEFI-GPT mode :<br />
<br />
menuentry "Microsoft Windows x86_64 UEFI-GPT" {<br />
insmod part_gpt<br />
insmod fat<br />
insmod search_fs_uuid<br />
insmod chain<br />
search --fs-uuid --no-floppy --set=root 1ce5-7f28<br />
chainloader (${root})/efi/Microsoft/Boot/bootmgfw.efi<br />
}<br />
<br />
== Manual Compilation ==<br />
<br />
=== For BIOS Systems ===<br />
<br />
GRUB2 for BIOS systems should be compiled as follows:<br />
<pre><br />
./autogen.sh<br />
<br />
./configure --with-platform=pc --prefix=/usr<br />
<br />
make<br />
<br />
make install<br />
</pre><br />
<br />
The <code>--with-platform=pc</code> generates grub2 for bios alone irrespective of the firmware of the build system.<br />
<br />
=== For UEFI Systems ===<br />
<br />
First [https://wiki.archlinux.org/index.php/Unified_Extensible_Firmware_Interface#Detecting_UEFI_Firmware_Arch Detect which UEFI Firmware arch] you have and then follow the compile instructions below:<br />
<pre><br />
./autogen.sh<br />
<br />
./configure --with-platform=efi --target=TARGET_UEFI_ARCH --prefix=/usr<br />
<br />
make<br />
<br />
make install<br />
</pre><br />
<br />
The "--target" option denotes the UEFI firmware arch. for which grub2 should be compiled, not the architecture of the linux kernel grub2 may boot. <br />
<br />
It is possible to use UEFI 64-bit firmware + GRUB2 as x86_64-EFI app loading a i686 linux kernel, as long as the kernel does not try to access UEFI Runtime Services. Vice-versa situation is also possible. But a x86_64 UEFI firmware cannot launch GRUB2 i386-efi app (unlike x86_64 Operating Systems), and a i386 UEFI firmware will not launch GRUB2 {{Codeline|x86_64-efi}} app. It is important to compile GRUB2 to match the architecture of the UEFI firmware.<br />
<br />
== Configuration ==<br />
<br />
The configuration files are {{Filename|/etc/default/grub}} and {{Filename|/etc/grub.d/*}}. These files are used to generate the {{Filename|/boot/grub/grub.cfg}} file. You can also choose to manually edit {{Filename|grub.cfg}}.<br />
<br />
=== grub-mkconfig ===<br />
<br />
The grub-mkconfig script can be used to generate a {{Filename|grub.cfg}} file. By default the script outputs to stdout. Note that gettext ― an optional dependency of the GRUB2 package ― is required by the grub-mkconfig script. To generate a {{Filename|grub.cfg}} file run the command:<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
Note that grub-mkconfig probably has your grub directory hardcoded to /boot/grub, which is probably wrong if you're using UEFI. Either mount your efi grub directory at /boot/grub or edit the script.<br />
<br />
=== grub.cfg ===<br />
<br />
A basic grub file uses the following options<br />
* {{Codeline|(hdX,Y)}} is the partition {{Codeline|Y}} on disk {{Codeline|X}}, partition numbers starting at 1, disk numbers starting at 0<br />
* {{Codeline|1=set default=N}} is the default boot entry that is chosen after timeout for user action<br />
* {{Codeline|1=set timeout=M}} is the time {{Codeline|M}} to wait in seconds for a user selection before default is booted<br />
* {{Codeline|<nowiki>menuentry "title" {entry options}</nowiki>}} is a boot entry titled {{Codeline|title}}<br />
* {{Codeline|1=set root=(hdX,Y)}} sets the boot partition, where the kernel and GRUB modules are stored (boot need not be a separate partition, and may simply be a directory under the "root" partition ({{Filename|/}})<br />
<br />
An example configuration:<br />
<br />
{{File<br />
|name=/boot/grub/grub.cfg<br />
|content=<nowiki><br />
# Config file for GRUB2 - The GNU GRand Unified Bootloader<br />
# /boot/grub/grub.cfg<br />
<br />
# DEVICE NAME CONVERSIONS<br />
#<br />
# Linux Grub<br />
# -------------------------<br />
# /dev/fd0 (fd0)<br />
# /dev/sda (hd0)<br />
# /dev/sdb2 (hd1,2)<br />
# /dev/sda3 (hd0,3)<br />
#<br />
<br />
# Timeout for menu<br />
set timeout=5<br />
<br />
# Set default boot entry as Entry 0<br />
set default=0<br />
<br />
# (0) Arch Linux<br />
menuentry "Arch Linux" {<br />
set root=(hd0,1)<br />
linux /vmlinuz-linux root=/dev/sda3 ro<br />
initrd /initramfs-linux.img<br />
}<br />
<br />
## (1) Windows<br />
#menuentry "Windows" {<br />
#set root=(hd0,3)<br />
#chainloader +1<br />
#}<br />
</nowiki>}}<br />
<br />
=== Dual-booting ===<br />
<br />
''NOTE: If you want GRUB2 to automatically search for other systems, for example as in Ubuntu. Then you may need to download {{Package AUR|os-prober}} from the [[AUR]].''<br />
<br />
==== Using grub-mkconfig ====<br />
The best way to add other entries is editing the {{Filename|/etc/grub.d/40_custom}}. The entries in this file will be automatically added when running '''grub-mkconfig'''.<br />
After adding the new lines, run:<br />
# grub-mkconfig -o /boot/grub/grub.cfg <br />
to generate an updated {{Filename|grub.cfg}}.<br />
<br />
===== With GNU/Linux =====<br />
<br />
Assuming that the other distro is on partition {{Filename|sda2}}:<br />
<br />
menuentry "Other Linux" {<br />
set root=(hd0,2)<br />
linux /boot/vmlinuz (add other options here as required)<br />
initrd /boot/initrd.img (if the other kernel uses/needs one)<br />
}<br />
<br />
===== With Windows =====<br />
<br />
This assumes that your Windows partition is {{Filename|sda3}}.<br />
<br />
# (2) Windows XP<br />
menuentry "Windows XP" {<br />
set root=(hd0,3)<br />
chainloader (hd0,3)+1<br />
}<br />
<br />
If the windows bootloader is on an entirely different harddrive than grub, it may be necessary to trick Windows into believing that it is in fact the first harddrive. This was possible in the old grub with {{Codeline|map}} and is now done with {{Codeline|drivemap}}. Assume grub is on {{Filename|hd0}} and windows on {{Filename|hd2}}, you need to add the following after {{Codeline|set root}}:<br />
<br />
drivemap -s hd0 hd2<br />
<br />
==== With Windows via EasyBCD and NeoGRUB ====<br />
<br />
Since EasyBCD's NeoGRUB currently does not understand the GRUB2 menu format, chainload to it by replacing the contents of your {{Filename|C:\NST\menu.lst}} file with lines similar to the following:<br />
<br />
default 0<br />
timeout 1<br />
<br />
title Chainload into GRUB v2<br />
root (hd0,7)<br />
kernel /boot/grub/core.img<br />
<br />
===Visual Configuration===<br />
<br />
In GRUB2 it is possible, by default, to change the look of the menu.<br />
<br />
====Background image and bitmap fonts====<br />
<br />
GRUB2 comes with support for background images and bitmap fonts in pf2 format. The unifont font is included in the grub2 package under the filename {{Filename|unicode.pf2}}, or, as only ascii characters under the name {{Filename|ascii.pf2}}. Image formats supported include tga, png and jpeg, providing the correct modules are loaded. The maximum supported resolution depends on your hardware. There are two ways of setting a {{Filename|tga}} file as background. Two sample configurations are shown below.<br />
<br />
Edit {{Filename|/etc/default/grub}} like this:<br />
GRUB_GFXMODE=1024x768x32<br />
GRUB_GFXPAYLOAD_LINUX=keep<br />
GRUB_BACKGROUND="/boot/grub/archlinux.tga"<br />
#GRUB_THEME="/path/to/gfxtheme"<br />
<br />
(archlinux.tga is a placeholder; put your file name there)<br />
<br />
To generate the changes, run: <br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
{{Note|If this example does not work for you try to replace {{Codeline|1=gfxmode="1024x768x32"}} by {{Codeline|1=vbemode="0x105"}}.}}<br />
{{Note|To show all the modes you can use {{Codeline|1=# hwinfo --framebuffer}} (hwinfo is available in [community]), while at grub2 prompt you can use the {{Codeline|1=vbeinfo}} command.}}<br />
{{Note|If you have installed Grub on a separate partition, {{Filename|/boot/grub/archlinux.tga}} becomes {{Filename|/grub/archlinux.tga}}.}}<br />
<br />
====Menu colors====<br />
<br />
As in Grub (0.9x), you can change the menu colors in Grub2. The available colors for GRUB2 are at http://www.gnu.org/software/grub/manual/html_node/Theme-file-format.html#Theme-file-format . <br />
Here is an example:<br />
<br />
Edit {{Filename|/etc/default/grub}}:<br />
GRUB_COLOR_NORMAL="light-blue/black"<br />
GRUB_COLOR_HIGHLIGHT="light-cyan/blue"<br />
<br />
Generate the changes:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
====Hidden menu====<br />
<br />
One of the unique features of Grub2 is hiding/skipping the menu and showing it by holding "Shift" when needed. You can also adjust whether you want to see the timeout counter.<br />
<br />
Edit {{Filename|/etc/default/grub}} as you wish. Here is an example where the comments from the beginning of the two lines have been removed to enable the feature, the timeout has been set to five seconds and to be shown to the user:<br />
GRUB_HIDDEN_TIMEOUT=5<br />
GRUB_HIDDEN_TIMEOUT_QUIET=false<br />
<br />
and run:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
====Setting the framebuffer resolution ====<br />
<br />
Grub2 can set the framebuffer for both grub2 itself and the kernel. The old ''vga='' way is deprecated. The preferred method is editing {{Filename|/etc/default/grub}} as the following sample:<br />
<br />
GRUB_GFXMODE=1024x768x32<br />
GRUB_GFXPAYLOAD_LINUX=keep<br />
<br />
To generate the changes, run: <br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
The {{Codeline|gfxpayload}} property will make sure the kernel keeps the resolution.<br />
<br />
If this method does not work for you, the deprecated <code>vga=</code> method will still work. Just<br />
add it next to the <code>"GRUB_CMDLINE_LINUX_DEFAULT="</code> line in {{Filename|/etc/default/grub}}<br />
for eg: <code>"GRUB_CMDLINE_LINUX_DEFAULT="quiet splash vga=792"</code> will give you a {{Codeline|1024x768}} resolution.<br />
<br />
You can choose one of these resolutions: {{Codeline|640×480}}, {{Codeline|800×600}}, {{Codeline|1024×768}}, {{Codeline|1280×1024}}, {{Codeline|1600×1200}}<br />
<br />
=== Other Options ===<br />
<br />
==== LVM ====<br />
<br />
If you use [[LVM]] for your {{Filename|/boot}}, add the following before menuentry lines:<br />
<br />
insmod lvm<br />
<br />
and specify your root in the menuentry as:<br />
<br />
set root=(''lvm_group_name''-''lvm_logical_boot_partition_name'')<br />
<br />
Example:<br />
<br />
# (0) Arch Linux<br />
menuentry "Arch Linux" {<br />
insmod lvm<br />
set root=(VolumeGroup-lv_boot)<br />
# you can only set following two lines<br />
linux /vmlinuz-linux root=/dev/mapper/VolumeGroup-root ro<br />
initrd /initramfs-linux.img<br />
}<br />
<br />
==== Raid ====<br />
<br />
Grub2 provides convenient handling of raid-volumes. You need to add:<br />
insmod raid<br />
<br />
which allows you to address the volume natively. E.g. {{Filename|/dev/md0}} becomes:<br />
set root=(md0)<br />
<br />
whereas a partitioned raid-volume (e.g. {{Filename|/dev/md0p1}}) becomes:<br />
set root=(md0,1)<br />
<br />
==== Persistent block device naming ====<br />
You can use UUIDs to detect partitions instead of the "old" {{Filename|/dev/sd*}} and {{Filename|/dev/hd*}} scheming. It has the advantage of detecting partitions by their unique UUIDs, which is needed by some people booting with complicated partition setups.<br />
<br />
UUIDs are used by default in the recent versions of grub2 - there is no downside in it anyway except that you need to re-generate the {{Filename|grub.cfg}} file every time you resize or reformat your partitions. Remember this when modifying partitions with Live-CD.<br />
<br />
The recent versions of grub2 use UUIDs by default. You can re-enable the use of UUIDS by simply commenting the UUID line (this is also what it looks like by default):<br />
#GRUB_DISABLE_LINUX_UUID=true<br />
you can also just set the value as {{Codeline|false}} as shown here:<br />
GRUB_DISABLE_LINUX_UUID=false<br />
<br />
Either way, do not forget to generate the changes:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
==== Using Labels ====<br />
<br />
It is possible to use labels, human-readable strings attached to filesystems, by using the {{Codeline|--label}} option to {{Codeline|search}}. First of all, label your existing partition:<br />
# tune2fs -L a <LABEL> <PARTITION><br />
<br />
Then, add an entry using labels. An example of this:<br />
<br />
menuentry "Arch Linux, session texte" {<br />
search --label --no-floppy --set=root archroot<br />
linux /boot/vmlinuz-linux root=/dev/disk/by-label/archroot ro<br />
initrd /boot/initramfs-linux.img<br />
}<br />
<br />
==== Recall previous entry ====<br />
<br />
Grub2 can remember the last entry you booted from and use this as the default entry to boot from next time. This is useful if you have multiple kernels (i.e., the current Arch one and the LTS kernel as a fallback option) or operating systems. To do this, edit {{Filename|/etc/default/grub}} and change the setting of {{Codeline|GRUB_DEFAULT}}:<br />
<br />
GRUB_DEFAULT=saved<br />
<br />
This ensures that grub will default to the saved entry. To enable saving the selected entry, add the following line to {{Filename|/etc/default/grub}}:<br />
<br />
GRUB_SAVEDEFAULT=true<br />
<br />
Remember to regenerate your configuration file.<br />
<br />
==== Security ====<br />
<br />
If you want to secure GRUB2 so it is not possible for anyone to change boot parameters or use the command line, you can add a user/password combination to GRUB2's configuration files. To do this, run the command {{Codeline|grub-mkpasswd_pbkdf2}}. Enter a password and confirm it. The output will look like this:<br />
<br />
<pre style='overflow:auto'><br />
Your PBKDF2 is grub.pbkdf2.sha512.10000.C8ABD3E93C4DFC83138B0C7A3D719BC650E6234310DA069E6FDB0DD4156313DA3D0D9BFFC2846C21D5A2DDA515114CF6378F8A064C94198D0618E70D23717E82.509BFA8A4217EAD0B33C87432524C0B6B64B34FBAD22D3E6E6874D9B101996C5F98AB1746FE7C7199147ECF4ABD8661C222EEEDB7D14A843261FFF2C07B1269A</pre>Then, add the following to {{Filename|/etc/grub.d/00_header}}:<br />
<pre>cat << EOF<br />
<br />
set superusers="username"<br />
password_pbkdf2 username <password><br />
<br />
EOF</pre><br />
where <password> is the string generated by {{Codeline|grub-mkpasswd_pbkdf2}}.<br />
<br />
Regenerate your configuration file. Your GRUB2 command line and boot parameters are now protected.<br />
<br />
=== Booting an Ubuntu ISO Image from the GRUB2 Screen ===<br />
<br />
Edit {{Filename|/etc/grub.d/40_custom}} to add an entry pointing to an Ubuntu iso:<br />
<br />
menuentry "ubuntu-11.04-desktop-amd64.iso" {<br />
set isofile="/path/to/ubuntu-11.04-desktop-amd64.iso"<br />
loopback loop (hdX,Y)$isofile<br />
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile quiet noeject noprompt splash --<br />
initrd (loop)/casper/initrd.lz<br />
}<br />
<br />
Be sure to adjust the "hdX,Y" in the third line to point to the correct disk/partition number of the isofile. When finished, update grub2's configuration file via:<br />
<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
== Using the command shell ==<br />
<br />
Since the MBR is too small to store all GRUB2 modules, only the menu and a few basic commands reside there. The majority of GRUB2 functionality remains in modules in {{Filename|/boot/grub}}, which are inserted as needed. In error conditions (e.g. if the partition layout changes) GRUB2 may fail to boot. When this happens, a command shell may appear.<br />
<br />
GRUB2 offers multiple shells/prompts. If there is a problem reading the menu but the bootloader is able to find the disk, you will likely be dropped to the "normal" shell:<br />
sh:grub><br />
<br />
If there is a more serious problem (e.g. GRUB cannot find required files), you may instead be dropped to the "rescue" shell:<br />
grub rescue><br />
<br />
The rescue shell is a restricted subset of the normal shell, offering much less functionality. If dumped to the rescue shell, first try inserting the "normal" module, then starting the "normal" shell:<br />
grub rescue> set prefix=(hdX,Y)/boot/grub<br />
grub rescue> insmod (hdX,Y)/boot/grub/normal.mod<br />
rescue:grub> normal<br />
<br />
=== Pager support ===<br />
<br />
GRUB2 supports pager for reading commands that provide long output (like the help command). This works only in normal shell mode and not in rescue mode. To enable pager, in GRUB2 command shell type:<br />
sh:grub> set pager=1<br />
<br />
== GUI configuration tools ==<br />
<br />
Following package may be installed from [[AUR]]<br />
* [http://kde-apps.org/content/show.php?content=139643 grub2-editor] (requires kdelibs)<br />
*:A KDE4 control module for configuring the GRUB2 bootloader<br />
* [http://kde-apps.org/content/show.php?content=137886 kcm-grub2] (requires kdelibs python2-qt kdebindings-python)<br />
*:This Kcm module manages the most common settings of Grub2.<br />
* [http://sourceforge.net/projects/startup-manager/ startupmanager] (requires gnome-python imagemagick yelp python2 xorg-xrandr)<br />
*:GUI app for changing the settings of GRUB, GRUB2, Usplash and Splashy<br />
<br />
== parttool or legacy hide/unhide ==<br />
<br />
If you have a win9x paradigm with hidden C disks GRUB legacy had the hide/unhide feature. In GRUB2 this has been replaced by parttool. For example, to boot the third C disk of three win9x installations on the CLI enter the CLI and:<br />
parttool hd0,1 hidden+ boot-<br />
parttool hd0,2 hidden+ boot-<br />
parttool hd0,3 hidden- boot+<br />
set root=hd0,3<br />
chainloader +1<br />
boot<br />
<br />
== Using the rescue console ==<br />
<br />
See [[#Using the command shell]] first. If unable to activate the standard shell, one possible solution is to boot using a live CD or some other rescue disk to correct configuration errors and reinstall GRUB. However, such a boot disk is not always available (nor necessary); the rescue console is surprisingly robust.<br />
<br />
The available commands in GRUB rescue include "insmod", "ls", "set", and "unset". This example uses "set" and "insmod". "set" modifies variables and "insmod" inserts new modules to add functionality.<br />
<br />
Before starting, the user must know the location of their {{Filename|/boot}} partition (be it a separate partition, or a subdirectory under their root):<br />
grub rescue> set prefix=(hdX,Y)/boot/grub<br />
<br />
where X is the physical drive number and Y is the partition number.<br />
<br />
To expand console capabilities, insert the "linux" module:<br />
grub rescue> insmod (hdX,Y)/boot/grub/linux.mod<br />
<br />
{{Note|With a separate boot partition, omit {{Filename|/boot}} from the path, (i.e. type {{Codeline|1=set prefix=(hdX,Y)/grub}} and {{Codeline|insmod (hdX,Y)/grub/linux.mod}}).}}<br />
<br />
This introduces the "linux" and "initrd" commands, which should be familiar (see [[#Configuration]]).<br />
<br />
An example, booting Arch Linux:<br />
set root=(hd0,5)<br />
linux /boot/vmlinuz-linux root=/dev/sda5<br />
initrd /boot/initramfs-linux.img<br />
boot<br />
<br />
With a separate boot partition, again change the lines accordingly:<br />
set root=(hd0,5)<br />
linux /vmlinuz-linux root=/dev/sda6<br />
initrd /initramfs-linux.img<br />
boot<br />
<br />
After successfully booting the Arch Linux installation, users can correct {{Filename|grub.cfg}} as needed and then run:<br />
# grub-install /dev/sda --no-floppy<br />
<br />
to reinstall GRUB2 and fix the problem completely, changing {{Filename|/dev/sda}} if needed. See [[#Bootloader installation]] for details.<br />
<br />
== Combining the use of UUID's and basic scripting ==<br />
<br />
If you like the idea of using UUID's to avoid unreliable BIOS mappings or are struggling with Grub's syntax, here is an example boot menu item that uses UUID's and a small script to direct Grub to the proper disk partitions for your system. All you need to do is replace the UUID's in the sample with the correct UUID's for your system. (The example applies to a system with a boot and root partition. You will obviously need to modify the Grub configuration if you have additional partitions.)<br />
<br />
menuentry "Arch Linux 64" {<br />
#Enter the UUID of your boot partition (this is where Grub and your kernel reside)<br />
set uuid_grub_boot=ece0448f-bb08-486d-9864-ac3271bd8d07<br />
<br />
#Enter the UUID of the partition containing the root partition of your Arch Linux installation. <br />
set uuid_os_root=c55da16f-e2af-4603-9e0b-03f5f565ec4a<br />
<br />
#(Note: this may be the same as your boot partition)<br />
<br />
#Here we set the Grub "root" variable by locating the UUID of the root partition identified above <br />
search --fs-uuid --no-floppy --set=root $uuid_os_root<br />
<br />
#Here we set a custom variable grub_boot by locating the UUID of the boot partition identified above <br />
search --fs-uuid --no-floppy --set=grub_boot $uuid_grub_boot<br />
<br />
#Here is the magic. We test to see if the boot and root partitions have the same UUID.<br />
#If they do, we append /boot to the $grub_boot variable. For ex. (hd0,1) becomes (hd0,1)/boot.<br />
if [ $uuid_grub_boot == $uuid_os_root ] ; then<br />
set grub_boot=$grub_boot/boot<br />
fi<br />
<br />
# $grub_boot now points to the correct location, so the following will properly find the kernel and initrd<br />
linux ($grub_boot)/vmlinuz-linux root=/dev/disk/by-uuid/$uuid_os_root ro<br />
initrd ($grub_boot)/initramfs-linux.img<br />
}<br />
<br />
== Troubleshooting ==<br />
<br />
Any troubleshooting should be added here.<br />
<br />
=== Enable GRUB2 debug messages ===<br />
<br />
Add<br />
<br />
set pager=1<br />
set debug=all<br />
<br />
to {{Filename|grub.cfg}}.<br />
<br />
=== Correct GRUB2 No Suitable Mode Found Error ===<br />
<br />
If you get this error when booting any menuentry<br />
<br />
error: no suitable mode found<br />
Booting however<br />
<br />
Then you need to initialize grub2 graphical terminal (gfxterm) with proper video mode (gfxmode) in grub2. This video mode is passed by grub2 to the linux kernel via 'gfxpayload'. In case of UEFI systems, if the grub2 video mode is not initialized, no kernel boot messages will be shown in the terminal (atleast until KMS kicks in)<br />
<br />
Copy {{Filename|/usr/share/grub/unicode.pf2}} to ${GRUB2_PREFIX_DIR} ({{Filename|/boot/grub/}} in case of BIOS systems and {{Filename|/boot/efi/efi/grub/}} in case of UEFI systems). <br />
<br />
# cp /usr/share/grub/unicode.pf2 ${GRUB2_PREFIX_DIR}<br />
<br />
If {{Filename|/usr/share/grub/unicode.pf2}} does not exist, install {{Package Official|bdf-unifont}}, create the unifont.pf2 file and then copy it to ${GRUB2_PREFIX_DIR} .<br />
<br />
# grub-mkfont -o unicode.pf2 /usr/share/fonts/misc/unifont.bdf<br />
<br />
Then, in the {{Filename|grub.cfg}} file, add the following lines to enable grub2 to pass the video mode correctly to the kernel, without of which you will only get a black screen (no output) but booting (actually) proceeds successfully without any system hang:<br />
<br />
BIOS systems<br />
<br />
insmod vbe<br />
<br />
UEFI systems<br />
<br />
insmod efi_gop<br />
insmod efi_uga<br />
<br />
After that add the following code (common to both BIOS and UEFI)<br />
<br />
insmod font<br />
<br />
if loadfont ${prefix}/unicode.pf2<br />
then<br />
insmod gfxterm<br />
set gfxmode=auto<br />
set gfxpayload=keep<br />
terminal_output gfxterm<br />
fi<br />
<br />
As you can see for gfxterm (graphical terminal) to function properly, {{Filename|unicode.pf2}} font file should exist in ${GRUB2_PREFIX_DIR}.<br />
<br />
=== msdos-style error message ===<br />
<br />
grub-setup: warn: This msdos-style partition label has no post-MBR gap; embedding won't be possible!<br />
grub-setup: warn: Embedding is not possible. GRUB can only be installed in this setup by using blocklists.<br />
However, blocklists are UNRELIABLE and its use is discouraged.<br />
grub-setup: error: If you really want blocklists, use --force.<br />
<br />
This error may occur when you try installing GRUB2 in a VMware container. Read more about it [http://bbs.archlinux.org/viewtopic.php?pid=581760#p581760 here]. It happens when the first partition starts just after the MBR (block 63), without the usual space of 1 MiB (2048 blocks) before the first partition. Read [[#MBR_aka_msdos_partitioning_specific_instructions]]<br />
<br />
=== UEFI GRUB2 not loaded ===<br />
In some cases the EFI may fail to load grub correctly. Provided everything is set up correctly, the output of<br />
efibootmgr -v<br />
might look something like this:<br />
BootCurrent: 0000<br />
Timeout: 3 seconds<br />
BootOrder: 0000,0001,0002<br />
Boot0000* Grub HD(1,800,32000,23532fbb-1bfa-4e46-851a-b494bfe9478c)File(\efi\grub\grub.efi)<br />
Boot0001* Shell HD(1,800,32000,23532fbb-1bfa-4e46-851a-b494bfe9478c)File(\EfiShell.efi)<br />
Boot0002* Festplatte BIOS(2,0,00)P0: SAMSUNG HD204UI .<br />
If everything works correctly, the EFI would now automatically load grub.<br><br />
If the screen only goes black for a second and the next boot option is tried afterwards, according to [https://bbs.archlinux.org/viewtopic.php?pid=981560#p981560 this post], moving grub to the partition root can help. The boot option has to be deleted and recreated afterwards. The entry for grub should look like this then:<br />
Boot0000* Grub HD(1,800,32000,23532fbb-1bfa-4e46-851a-b494bfe9478c)File(\grub.efi)<br />
<br />
=== Invalid signature ===<br />
If trying to boot windows results in an "invalid signature" error, e.g. after reconfiguring partitions or adding additional hard drives, (re)move grub's device configuration and let it reconfigure.<br />
# mv /boot/grub/device.map /boot/grub/device.map-old<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
Grub-mkconfig should now mention all found boot options including windows. If it works, remove /boot/grub/device.map-old.<br />
<br />
== References ==<br />
<br />
# Official GRUB2 Manual - http://www.gnu.org/software/grub/manual/grub.html<br />
# GRUB2 wiki page describing steps to compile for UEFI systems - https://help.ubuntu.com/community/UEFIBooting - previously http://grub.enbug.org/TestingOnUEFI{{Linkrot|2011|09|05}}<br />
# Wikipedia's page on [http://en.wikipedia.org/wiki/BIOS_Boot_partition BIOS Boot Partition]<br />
<br />
== External Links ==<br />
<br />
# [https://github.com/the-ridikulus-rat/My_Shell_Scripts/blob/master/grub2/grub2_bios.sh A Linux Bash Shell script to compile and install GRUB2 for BIOS from BZR Source]<br />
# [https://github.com/the-ridikulus-rat/My_Shell_Scripts/blob/master/grub2/grub2_uefi.sh A Linux Bash Shell script to compile and install GRUB2 for UEFI from BZR Source]</div>Mayweedhttps://wiki.archlinux.org/index.php?title=GRUB&diff=167966GRUB2011-10-29T18:15:12Z<p>Mayweed: if you install grub2-bios before rm, it won't crush the old files. Pain in the ass to delete afterwards...Preliminary is preliminary...(first!)</p>
<hr />
<div>[[Category:Boot loaders (English)]]<br />
{{i18n|GRUB2}}<br />
[[fr:GRUB2]]<br />
{{Article summary start}}<br />
{{Article summary text|Covers various aspects of the next generation of the GRand Unified Bootloader (GRUB2).}}<br />
{{Article summary heading|Overview}}<br />
{{Article summary text|{{Boot process overview}}}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|Burg}} - Burg is a brand-new boot loader based on GRUB2. It uses a new object format which allows it to be built in a wider range of OS, including Linux/Windows/OSX/Solaris/FreeBSD, etc. It also has a highly configurable menu system which works in both text and graphic mode. <br />
{{Article summary heading|Resources}}<br />
{{Article summary link|GNU GRUB -- GNU Project|http://www.gnu.org/software/grub/}}<br />
{{Article summary link|GNU GRUB Wiki|http://grub.enbug.org/}}{{Linkrot|2011|09|05}}<br />
{{Article summary end}}<br />
<br />
[http://www.gnu.org/software/grub/ GRUB2] is the next generation of the GRand Unified Bootloader (GRUB). GRUB2 is derived from [http://www.nongnu.org/pupa/ PUPA] which was a research project to investigate the next generation of GRUB. GRUB 2 has been rewritten from scratch to clean up everything and provide modularity and portability [http://www.gnu.org/software/grub/grub-faq.en.html#q1].<br />
<br />
Briefly, the ''bootloader'' is the first software program that runs when a computer starts. It is responsible for loading and transferring control to the Linux kernel. The kernel, in turn, initializes the rest of the operating system.<br />
<br />
== Preface ==<br />
<br />
Although, [[GRUB]] (i.e. version 0.9x) is the de facto standard bootloader of Linux, it is considered 'legacy' by upstream. It is being replaced by GRUB2 in many distributions. Upstream recommends GRUB2 >=1.99~rc2 over grub-legacy, even for current grub-legacy users.<br />
<br />
{{Note|grub2 from 1.99~rc2 and later supports btrfs as root (without a separate /boot filesystem).}}<br />
<br />
=== Notes for current GRUB users ===<br />
<br />
* There are differences in the commands of GRUB and GRUB2. Familiarize yourself with [http://www.gnu.org/software/grub/manual/grub.html#Commands GRUB2 commands] before proceeding (e.g. "find" has been replaced with "search").<br />
<br />
* GRUB2 is now ''modular'' and no longer requires "stage 1.5". As a result, the bootloader itself is limited -- modules are loaded from the hard drive as needed to expand functionality (e.g. for [[LVM]] or RAID support).<br />
<br />
* Device naming has changed between GRUB and GRUB2. Partitions are numbered from 1 instead of 0 while drives are still numbered from 0, and prefixed with partition-table type. For example, {{Filename|/dev/sda1}} would be referred to as {{Codeline|(hd0,msdos1)}} (for MBR) or {{Codeline|(hd0,gpt1)}} (for GPT) using GRUB2.<br />
<br />
===== Preliminary Considerations for GRUB2 BIOS =====<br />
<br />
====== [[GPT]] specific instructions ======<br />
<br />
GRUB2 in BIOS-GPT configuration requires a BIOS Boot Partition to embed its core.img in the absence of post-MBR gap in GPT partitioned systems (which is taken over by the GPT Primary Header and Primary Partition table). This partition is used by GRUB2 only in BIOS-GPT setups. No such partition type exists in case of MBR partitioning (at least not for GRUB2). This partition is also not required if the system is UEFI based, as no embedding of bootsectors takes place in that case. Syslinux does not require this partition.<br />
<br />
For a BIOS-GPT configuration, create a 2 MiB partition using cgdisk or GNU Parted with no filesystem. The location of the partition in the partition table does not matter but it should be within the first 2 TiB region of the disk. It is advisable to put it somewhere in the beginning of the disk before the /boot partition. Set the partition type to "EF02" in cgdisk or {{Codeline|set <BOOT_PART_NUM> bios_grub on}} in GNU Parted.<br />
<br />
{{Note|This partition should be created before grub_bios-install or grub-setup is run or before the '''Install Bootloader''' step of the Archlinux installer (if GRUB2 is selected as bootloader).}}<br />
<br />
====== [[MBR]] aka msdos partitioning specific instructions ======<br />
<br />
Usually the post-MBR gap (after the 512 byte MBR region and before the start of the 1st partition) in many MBR (or msdos disklabel) partitioned systems is 32 KiB when DOS compatibility cylinder alignment issues are satisfied in the partition table. However a post-MBR gap of about 1 to 2 MiB is recommended to provide sufficient room for embedding grub2's core.img ( https://bugs.archlinux.org/task/24103 ). It is advisable to use a partitioner which supports 1 MiB partition alignment to obtain this space as well as satisfy other non-512 byte sector issues (which are unrelated to embedding of core.img).<br />
<br />
If you do not dual-boot with MS Windows (any version) in BIOS systems, it is advisable to switch to GPT partitioning - [[GUID_Partition_Table#Convert_from_MBR_to_GPT_without_data_loss]]<br />
{{Note|Create the 2MiB partition mentioned above BEFORE you convert to GPT. If you do not, gparted will not resize your boot partition to allow its creation, and when you reboot grub2 will not know where to look.}}<br />
<br />
== Installation ==<br />
<br />
=== During Arch Linux installation ===<br />
<br />
* Skip the '''Install Bootloader''' step and exit the installer.<br />
* Configure the network:<br />
# aif -p partial-configure-network<br />
This will bring up a prompt; put in the network interface to use, (e.g., eth0) and use DHCP for easy configuration.<br />
* If you did not configure the installed system's {{Filename|/etc/resolv.conf}} file during installation (for instance, if you plan to let DHCP generate it later), you will need to copy the one generated by AIF when it configured the network:<br />
# cp /etc/resolv.conf /mnt/etc/resolv.conf<br />
* Load the dm-mod module (you might need grub2-bios; install the package if needed):<br />
# modprobe dm-mod<br />
{{Note|This is necessary at this point, and cannot be postponed after the chroot. If you try to use modprobe in a chroot environment that has a later kernel version from that of the installing device (at the time of writing, 2.6.33), modprobe will fail. This happens routinely using the Arch "net" installations.}}<br />
* From the installer's live shell, chroot to the installed system:<br />
# mount -o bind /dev /mnt/dev<br />
# chroot /mnt bash<br />
* Update pacman's database:<br />
# pacman-db-upgrade<br />
* Refresh the package list (with an extra -y flag to force a refresh of all package lists even if they appear to be up to date):<br />
# pacman -Syy<br />
* Install the GRUB2 package as mentioned in the section [[#From a running Arch Linux]]. Note that the dm-mod module has already been loaded, no need to do that again.<br />
<br />
=== From a running Arch Linux ===<br />
<br />
====Make a backup of your precious data====<br />
In general, a grub installation ran smoothly and you got no problems at all. And sometimes it could simply messed up your system. You're strongly advised to make a backup before even think of grub2.<br />
<br />
*copy grub modules and configuration<br />
# cp -a /boot/grub /path/to/backup/<br />
*backup the MBR and GRUB stage 1.5<br />
# dd if=/dev/sda of=/path/to/backup/first-sectors count=63<br />
<br />
You could now lightly remove /boot/grub and follow the instructions below.You know that if things get nasty, you could reboot your system thanks to an installation media and :<br />
<br />
*move old grub2 files out of the way<br />
# mv /boot/grub /boot/grub.nonfunctional<br />
*copy grub back to /boot<br />
# cp -a /path/to/backup/grub /boot/<br />
*replace MBR and next 62 sectors of sda with backed up copy (DANGEROUS!)<br />
# dd if=/path/to/backup/first-sectors of=/dev/sda count=63<br />
* Delete all the files from {{Filename|/boot/grub}}<br />
# rm -rf /boot/grub<br />
<br />
===== grub2-bios-install =====<br />
<br />
The GRUB2 package can be installed with pacman (and will replace {{Package Official|grub}}, if it is installed):<br />
<br />
# pacman -S grub2-bios<br />
<br />
{{Note|Installing grub2-common (a dependency of grub2-bios) 1.99~rc1 or later, may take forever in some systems since the post_install script runs grub-mkconfig and this script does not provide the option <code>--no-floppy</code>. For more details search this option in the article.}}<br />
<br />
{{Note|Simply installing the package won't update the /boot/grub/core.img file and the grub2 modules in /boot/grub . You need to update the core.img file and the grub2 modules manually using grub_bios-install as explained below.}}<br />
<br />
Also load the device-mapper kernel module without which grub-probe does not reliably detect disks and partitions<br />
<br />
# modprobe dm-mod<br />
<br />
<br />
===== Run grub_bios-install =====<br />
<br />
There are 3 ways to install grub2 in BIOS booting - [[#Install_to_440-byte_MBR_boot_code_region]] (recommended) , [[#Install_to_Partition_or_Partitionless_Disk]] (not recommended) or [[#Generate_core.img_alone]] (safest method, but requires another BIOS bootloader like [[grub-legacy]] or [[syslinux]] to be installed to chainload {{Filename|/boot/grub/core.img}} ). For all the ways [[#Before_grub_bios-install]] step is needed.<br />
<br />
====== Install to 440-byte MBR boot code region ======<br />
<br />
To setup grub2-bios in the 440-byte Master Boot Record boot code region, populate the {{Filename|/boot/grub}} directory, generate the {{Filename|/boot/grub/core.img}} file, and embed it in the 32 KiB (minimum size - varies depending on partition alignment) post-MBR gap (MBR disks) or in BIOS Boot Partition (GPT disks), run<br />
<br />
# grub_bios-install --boot-directory=/boot --no-floppy --recheck /dev/sda<br />
<br />
where {{Filename|/dev/sda}} is the destination of the installation (in this case the MBR of the first SATA disk). If you use [[LVM]] for your {{Filename|/boot}}, you can install GRUB2 on multiple physical disks. <br />
<br />
The {{Codeline|--no-floppy}} tells grub2-bios utilities not to search for any floppy devices which reduces the overall execution time of grub_bios-install on many systems (it will also prevent the issue below from occuring). Otherwise you get an error like this<br />
<br />
grub-probe: error: Cannot get the real path of '/dev/fd0'<br />
Auto-detection of a filesystem module failed.<br />
Please specify the module with the option '--modules' explicitly.<br />
<br />
Then:<br />
<br />
* Follow [[#Generate_GRUB2_BIOS_Config_file]] or if that fails, convert your {{Filename|/boot/grub/menu.lst}} file to {{Filename|/boot/grub/grub.cfg}} using:<br />
<br />
# grub-menulst2cfg /boot/grub/menu.lst /boot/grub/grub.cfg<br />
<br />
For example:<br />
<br />
{{File|name=/boot/grub/menu.lst|content=<br />
default=0<br />
timeout=5<br />
<br />
title Arch Linux Stock Kernel<br />
root (hd0,0)<br />
kernel /vmlinuz-linux root=/dev/sda2 ro<br />
initrd /initramfs-linux.img<br />
<br />
title Arch Linux Stock Kernel Fallback<br />
root (hd0,0)<br />
kernel /vmlinuz-linux root=/dev/sda2 ro<br />
initrd /initramfs-linux-fallback.img<br />
}}<br />
<br />
{{File|name=/boot/grub/grub.cfg|content=<br />
set default='0'; if [ x"$default" = xsaved ]; then load_env; set default="$saved_entry"; fi<br />
set timeout=5<br />
<br />
menuentry 'Arch Linux Stock Kernel' {<br />
set root='(hd0,1)'; set legacy_hdbias='0'<br />
legacy_kernel '/vmlinuz-linux' '/vmlinuz-linux' 'root=/dev/sda2' 'ro'<br />
legacy_initrd '/initramfs-linux.img' '/initramfs-linux.img'<br />
<br />
}<br />
<br />
menuentry 'Arch Linux Stock Kernel Fallback' {<br />
set root='(hd0,1)'; set legacy_hdbias='0'<br />
legacy_kernel '/vmlinuz-linux' '/vmlinuz-linux' 'root=/dev/sda2' 'ro'<br />
legacy_initrd '/initramfs-linux-fallback.img' '/initramfs-linux-fallback.img'<br />
}<br />
}}<br />
<br />
<br />
* If you forgot to create a GRUB2 {{Filename|/boot/grub/grub.cfg}} configfile and simply rebooted into GRUB2 Command Shell, type:<br />
<br />
sh:grub> insmod legacycfg<br />
sh:grub> legacy_configfile ${prefix}/menu.lst<br />
<br />
Boot into Arch and re-create the proper GRUB2 {{Filename|/boot/grub/grub.cfg}} configfile.<br />
<br />
{{Note|This option works only in BIOS systems, not in UEFI systems.}}<br />
<br />
====== Install to Partition or Partitionless Disk ======<br />
<br />
{{Note|grub2-bios (any version - including upstream bzr repo) does not encourage installation to a partition boot sector or a partitionless disk like grub-legacy or syslinux does. Neither do the Arch devs.}}<br />
<br />
To setup grub2-bios to a partition boot sector, to a partitionless disk (also called superfloppy) or to a floppy disk, run (using for example /dev/sda1 as the /boot partition)<br />
<br />
# chattr -i /boot/grub/core.img<br />
# grub_bios-install --boot-directory=/boot --no-floppy --recheck --force /dev/sda1<br />
# chattr +i /boot/grub/core.img<br />
<br />
You need to use the {{Codeline|--force}} option to allow usage of blocklists and should not use <code>--grub-setup=/bin/true</code> (which is similar to simply generating core.img).<br />
<br />
grub_bios-install will give out warnings like which should give you the idea of what might go wrong with this approach.<br />
<br />
/sbin/grub-setup: warn: Attempting to install GRUB to a partitionless disk or to a partition. This is a BAD idea.<br />
/sbin/grub-setup: warn: Embedding is not possible. GRUB can only be installed in this setup by using blocklists. <br />
However, blocklists are UNRELIABLE and their use is discouraged.<br />
<br />
Without {{Codeline|--force}} you may get the below error and grub-setup will not setup its boot code in the partition boot sector.<br />
<br />
/sbin/grub-setup: error: will not proceed with blocklists<br />
<br />
With {{Codeline|--force}} you should get<br />
<br />
Installation finished. No error reported.<br />
<br />
The reason why grub-setup does not by default allow this is because in case of partition or a partitionless disk is that grub2-bios relies on embedded blocklists in the partition bootsector to locate the {{Filename|/boot/grub/core.img}} file and the prefix dir {{Filename|/boot/grub}} . The sector locations of {{Filename|core.img}} may change whenever the filesystem in the partition is being altered (files copied, deleted etc.). For more info see https://bugzilla.redhat.com/show_bug.cgi?id=728742 and https://bugzilla.redhat.com/show_bug.cgi?id=730915 .<br />
<br />
The workaround for this is to set the immutable flag on {{Filename|/boot/grub/core.img}} (using chattr command as mentioned above) so that the sector locations of the {{Filename|core.img}} file in the disk is not altered. The immutable flag on {{Filename|/boot/grub/core.img}} needs to be set only if grub2-bios is installed to a partition boot sector or a partitionless disk, not in case of installtion to MBR or simple generation of {{Filename|core.img}} without embedding any bootsector (mentioned above). <br />
<br />
====== Generate core.img alone ======<br />
<br />
To populate the {{Filename|/boot/grub}} directory and generate a {{Filename|/boot/grub/core.img}} file WITHOUT embedding any grub2-bios bootsector code in the MBR, post-MBR region, or the partition bootsector, add <code>--grub-setup=/bin/true</code> to grub_bios-install:<br />
<br />
# grub_bios-install --grub-setup=/bin/true --boot-directory=/boot --no-floppy --recheck /dev/sda<br />
<br />
You can then chainload grub2's core.img from grub-legacy or syslinux as a Linux kernel or a multiboot kernel.<br />
<br />
===== After grub_bios-install =====<br />
<br />
====== Generate GRUB2 BIOS Config file ======<br />
<br />
Finally, generate a configuration for grub2 (this is explained in greater detail in the Configuration section):<br />
<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
If grub2 complains about "no suitable mode found" while booting, go to [[#Correct_GRUB2_No_Suitable_Mode_Found_Error]] .<br />
<br />
===== Multiboot in BIOS =====<br />
<br />
====== Boot Microsoft Windows installed in BIOS-MBR mode ======<br />
<br />
{{Note|GRUB2 supports booting {{Filename|bootmgr}} directly and chainload of partition boot sector is no longer required to boot Windows in a BIOS-MBR setup.}}<br />
<br />
Find the UUID of the NTFS filesystem of the Windows's SYSTEM PARTITION where the bootmgr and its files reside. For example, if Windows {{Filename|bootmgr}} exists at {{Filename|/media/Windows/bootmgr}}:<br />
<br />
# grub-probe --target=fs_uuid /media/Windows/bootmgr<br />
69B235F6749E84CE<br />
<br />
Then, add the below code to {{Filename|/boot/grub/grub.cfg}} to chainload Windows (Vista, 7 or 8) installed in BIOS-MBR mode :<br />
<br />
menuentry "Microsoft Windows 7 BIOS-MBR" {<br />
insmod part_msdos<br />
insmod ntfs<br />
insmod search_fs_uuid<br />
insmod ntldr <br />
search --fs-uuid --no-floppy --set=root 69B235F6749E84CE<br />
ntldr (${root})/bootmgr<br />
}<br />
<br />
For Windows XP<br />
<br />
menuentry "Microsoft Windows XP" {<br />
insmod part_msdos<br />
insmod ntfs<br />
insmod search_fs_uuid<br />
insmod ntldr <br />
search --fs-uuid --no-floppy --set=root 69B235F6749E84CE<br />
ntldr (${root})/ntldr<br />
}<br />
<br />
==== [[UEFI]] systems ====<br />
<br />
===== Before grub_efi_${UEFI_ARCH}-install =====<br />
<br />
{{Note|Unless specified as EFI 1.x , EFI and UEFI terms are used interchangeably to denote UEFI 2.x firmware. Also unless stated explicitely, the instructions are general and not Mac specific. Some of them may not work or may be different in Macs. Apple's EFI implementation is neither a EFI 1.x version nor UEFI 2.x version but mixes up both. This kind of firmware does not fall under any one UEFI Specification version and is therefore not a standard UEFI firmware.}}<br />
<br />
GRUB2 UEFI bootloader is available in Arch Linux only from version 1.99~rc1 . To install, first [https://wiki.archlinux.org/index.php/Unified_Extensible_Firmware_Interface#Detecting_UEFI_Firmware_Arch Detect which UEFI firmware arch] you have (either x86_64 or i386).<br />
<br />
Depending on that, install the appropriate package<br />
<br />
For 64-bit aka x86_64 UEFI firmware:<br />
# pacman -S grub2-efi-x86_64<br />
<br />
For 32-bit aka i386 UEFI firmware:<br />
# pacman -S grub2-efi-i386<br />
<br />
{{Note|Installing grub2-common (a dependency of grub2-bios) 1.99~rc1 or later, may take forever in some systems since the post_install script runs grub-mkconfig and this script does not provide the option <code>--no-floppy</code>. For more details search this option in the article.}}<br />
<br />
{{Note|Simply installing the package won't update the grub.efi file and the grub2 modules in the UEFI System Partition . You need to update the grub.efi file and the grub2 modules in the UEFI System Partition manually using grub_efi_${UEFI_ARCH}-install as explained below.}}<br />
<br />
Also load the device-mapper kernel module without which grub-probe does not reliably detect disks and partitions<br />
<br />
# modprobe dm-mod<br />
<br />
===== Install to UEFI SYSTEM PARTITION =====<br />
<br />
====== Mount UEFI SYSTEM PARTITION ======<br />
<br />
Mount the [https://wiki.archlinux.org/index.php/Unified_Extensible_Firmware_Interface#Creating_a_UEFI_SYSTEM_PARTITION_in_Linux UEFI SYSTEM PARTITION] in your system at {{Filename|/boot/efi}}. It should be FAT32 formatted and should be at least 200 MiB in size. If you have mounted the UEFISYS partition in some other mountpoint, replace {{Filename|/boot/efi}} in the below commands with that mountpoint:<br />
<br />
# mkdir -p /boot/efi<br />
# mount -t vfat <UEFISYS_PART_DEVICE> /boot/efi<br />
# mkdir -p /boot/efi/efi<br />
<br />
====== Run grub_efi_${UEFI_ARCH}-install ======<br />
<br />
{{Note|The below commands assume you are using {{Codeline|grub2-efi-x86_64}} (for {{Codeline|grub2-efi-i386}} replace {{Codeline|x86_64}} with {{Codeline|i386}} in the below commands).}}<br />
<br />
# grub_efi_x86_64-install --root-directory=/boot/efi --boot-directory=/boot/efi/efi --bootloader-id=grub --no-floppy --recheck<br />
<br />
The {{Codeline|grub_efi_x86_64-install}} automatically generates a {{Filename|grub.efi}} while setting up the {{Filename|/boot/efi/efi/grub/}} directory.<br />
<br />
If you notice carefully, there is no <device_path> option (Eg: {{Filename|/dev/sda}}) at the end of the {{Codeline|grub_efi_x86_64-install}} command unlike the case of setting up grub2 for BIOS systems. Any <device_path> provided will be ignored by the install script as UEFI bootloaders do not use MBR or Partition boot sectors at all.<br />
<br />
You may now be able to UEFI boot your system by creating a grub.cfg file using grub-mkconfig and copying /boot/efi/efi/grub/grub.efi to /boot/efi/efi/boot/bootx64.efi.<br />
<br />
===== After grub_efi_${UEFI_ARCH}-install =====<br />
<br />
====== Launch GRUB2 as default in non-Mac UEFI systems ======<br />
<br />
{{Note|The below steps will not work if the system has been booted in BIOS mode and will not work if the UEFI processor architecture does not match the kernel one, i.e. x86_64 UEFI + ix86 32-bit Kernel and vice-versa config will not work.}}<br />
<br />
grub_efi_${UEFI_ARCH}-install will ensure {{Filename|/boot/efi/efi/grub/grub.efi}} is launched by default if it detects {{Codeline|efibootmgr}} and if it is able to access UEFI Runtime Services. {{Codeline|efibootmgr}} command will work only if you have booted the system in UEFI mode itself, since it '''requires access to UEFI Runtime Variables''' which are '''available only in UEFI boot mode''' (with "noefi" kernel parameter NOT being used). Initially the user is required to manually launch {{Filename|/boot/efi/efi/grub/grub.efi}} from the firmware itself (using maybe the UEFI Shell) if grub2-efi was installed in BIOS mode. Then {{Codeline|efibootmgr}} should be run to make grub2 as the default entry in the UEFI Boot Manager<br />
<br />
First boot into UEFI mode manually either using the firmware boot menu, UEFI shell, or using any UEFI capable bootable iso (Archboot or Ubuntu non-Mac iso). Use grub probe to determine the device path of your EFI System Partition:<br />
# grub-probe --target=device /boot/efi/efi/grub/grub.efi<br />
<br />
It should give something like {{Filename|/dev/sda1}} (used as example in the remaining steps). Load 'efivars' kernel module:<br />
# modprobe efivars<br />
<br />
If you get '''no such device found''' error for this command, that means you have not booted in UEFI mode or due to some reason the kernel is unable to access UEFI Runtime Variables.<br />
<br />
Verify whether there are files in ''/sys/firmware/efi/vars/'' directory. This directory and its contents are created by "efivars" kernel module and it will exist only if you have booted in UEFI mode without the "noefi" kernel parameter.<br />
<br />
# ls -1 /sys/firmware/efi/vars/<br />
<br />
Sample output (x86_64-UEFI 2.3.1 in x86_64 Kernel:<br />
<br />
# ls -1 /sys/firmware/efi/vars/<br />
Boot0000-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootCurrent-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootOptionSupport-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootOrder-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConIn-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConInDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConOut-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConOutDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ErrOutDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
Lang-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
LangCodes-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
MTC-eb704011-1402-11d3-8e77-00a0c969723b/<br />
MemoryTypeInformation-4c19049f-4137-4dd3-9c10-8b97a83ffdfa/<br />
PlatformLang-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
PlatformLangCodes-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
RTC-378d7b65-8da9-4773-b6e4-a47826a833e1/<br />
del_var<br />
new_var<br />
<br />
If ''/sys/firmware/efi/vars/'' directory is empty or does not exist, then {{Codeline|efibootmgr}} command will not work. If you are unable to make the ISO/CD/DVD/USB boot in UEFI mode try https://gitorious.org/tianocore_uefi_duet_builds/pages/Linux_Windows_BIOS_UEFI_boot_USB .<br />
<br />
If ''/sys/firmware/efi/vars/'' directory (along with the exists then run {{Codeline|efibootmgr}} and reboot:<br />
<br />
# efibootmgr --create --gpt --disk /dev/sda --part 1 --write-signature --label "GRUB2" --loader "\\EFI\\grub\\grub.efi"<br />
<br />
In the above command, {{Filename|/boot/efi/efi/grub/grub/efi}} can be split up as {{Filename|/boot/efi}} and {{Filename|/efi/grub/grub.efi}}, which translates to {{Filename|(/dev/sda)}} -> partition 1 -> {{Filename|\\EFI\\grub\\grub.efi}}. <br />
<br />
FAT32 filesystem is case-insensitive since it does not use UTF-8 encoding by default. In that case the firmware uses capital 'EFI' instead of small 'efi', therefore using {{Filename|\\EFI\\grub\\grub.efi}} or {{Filename|\\efi\\grub\\grub.efi}} does not matter (this will change if the filesystem encoding is UTF-8). UEFI uses backward slash as path separatoir (similar to Windows paths). In the above command "double" backward slashes are used instead of single ones, since a backward slash is used as a escape character by sh shells, the first backward slash escapes the second one so that the path {{Filename|\EFI\grub\grub.efi}} is passed to {{Codeline|efibootmgr}}.<br />
<br />
The 'label' is the name of the menu entry shown in the UEFI boot menu. This name is user's choice and does not affect the booting of the system. More info can be obtained from [http://linux.dell.com/cgi-bin/gitweb/gitweb.cgi?p=efibootmgr.git;a=blob_plain;f=README;hb=HEAD efibootmgr GIT README]<br />
<br />
If you have problems running GRUB2 in UEFI mode you can try the following (worked on an ASUS Z68 mainboard):<br />
<br />
# cp /boot/efi/efi/grub/grub.efi /boot/efi/shellx64.efi<br />
<br />
or<br />
<br />
# cp /boot/efi/efi/grub/grub.efi /boot/efi/efi/shellx64.efi<br />
or<br />
<br />
# cp /boot/efi/efi/grub/grub.efi /boot/efi/efi/shell/shellx64.efi<br />
<br />
After this launch the UEFI Shell from the UEFI setup/menu (in ASUS UEFI BIOS, switch to advanced mode, press Exit in the top right corner and choose "Launch EFI shell from filesystem device"). The grub2 menu will show up and you can boot into your system. Afterwards you can use efibootmgr to setup a menu entry (see above).<br />
<br />
====== Launch GRUB2 as default in Apple Mac EFI systems ======<br />
<br />
{{Note|Using {{Filename|efibootmgr}} in Apple Macs will brick the firmware and may need reflash of the motherboard ROM. There have been bug reports regarding this in Ubuntu/Launchpad bug tracker. Use bless command alone in case of Macs}}<br />
<br />
Use bless command from within Mac OS X to setup {{Filename|grub.efi}} as the default boot option. More info at https://help.ubuntu.com/community/UEFIBooting#Apple_Mac_EFI_systems_.28both_EFI_architecture.29 .<br />
<br />
====== Generate GRUB2 UEFI Config file ======<br />
<br />
Finally, generate a configuration for grub2 (this is explained in greater detail in the Configuration section):<br />
<br />
# grub-mkconfig -o /boot/efi/efi/grub/grub.cfg<br />
<br />
If grub2-uefi complains about "no suitable mode found" while booting, go to [[#Correct_GRUB2_No_Suitable_Mode_Found_Error]] .<br />
<br />
===== Generate a custom GRUB2 UEFI Application =====<br />
<br />
If you want, you can create a custom {{Filename|grub_custom.efi}} app using:<br />
# grub-mkimage -d /usr/lib/grub/x86_64-efi -O x86_64-efi -p "" -o /boot/efi/efi/grub/grub_custom.efi <GRUB2_Modules_to_be_included><br />
<br />
{{Note|The '''-p''' option is important for creating a portable {{Filename|grub_custom.efi}} app.}}<br />
<br />
There is no file-size restriction on {{Filename|grub_custom.efi}} either due to GRUB2 or due to the UEFI firmware. Therefore you can include any number of modules you want.<br />
<br />
A "{{Filename|grub.cfg}}" created for BIOS based GRUB2 will be sufficient for the UEFI GRUB2 as long as all the paths in the config are absolute paths. The {{Filename|grub.cfg}} file should exist in the same directory as {{Filename|grub.efi}} or {{Filename|grub_custom.efi}}.<br />
<br />
The {{Filename|grub.efi}} UEFI application can be launched using the firmware's "Boot Manager", "Boot from file" option or using the [https://wiki.archlinux.org/index.php/UEFI#UEFI_Shell UEFI Shell].<br />
<br />
Alternatively, you can also setup {{Filename|/boot/efi/efi/grub}} directory by copying all the files in {{Filename|/usr/lib/grub/x86_64-efi}} to {{Filename|/boot/efi/efi/grub}} and using the above grub-mkimage command to create a {{Filename|grub_custom.efi}} application. Just make sure you have the required modules embedded in {{Filename|grub_custom.efi}} to enable it to access the EFI SYSTEM PARTITION.<br />
<br />
A basic {{Filename|grub_custom.efi}} can be generated using the following command:<br />
# sudo grub-mkimage -d /usr/lib/grub/x86_64-efi -O x86_64-efi -p "" -o /boot/efi/efi/grub/grub_custom.efi part_gpt fat iso9660 udf normal chain linux \<br />
ls search search_fs_file search_fs_uuid search_label help boot configfile echo efi_gop<br />
<br />
===== Multiboot in UEFI =====<br />
<br />
====== Chainload Microsoft Windows x86_64 UEFI-GPT ======<br />
<br />
Find the UUID of the FAT32 filesystem in the UEFI SYSTEM PARTITION where the Windows UEFI Bootloader files reside. For example, if Windows {{Filename|bootmgfw.efi}} exists at {{Filename|/boot/efi/efi/Microsoft/Boot/bootmgfw.efi}} (ignore the upper-lower case differences since that is immaterial in FAT filesystem):<br />
<br />
# grub-probe --target=fs_uuid /boot/efi/efi/Microsoft/Boot/bootmgfw.efi<br />
1ce5-7f28<br />
<br />
Then, add this code to {{Filename|/boot/efi/efi/grub/grub.cfg}} to chainload Windows x86_64 (Vista SP1+, 7 or 8) installed in UEFI-GPT mode :<br />
<br />
menuentry "Microsoft Windows x86_64 UEFI-GPT" {<br />
insmod part_gpt<br />
insmod fat<br />
insmod search_fs_uuid<br />
insmod chain<br />
search --fs-uuid --no-floppy --set=root 1ce5-7f28<br />
chainloader (${root})/efi/Microsoft/Boot/bootmgfw.efi<br />
}<br />
<br />
== Manual Compilation ==<br />
<br />
=== For BIOS Systems ===<br />
<br />
GRUB2 for BIOS systems should be compiled as follows:<br />
<pre><br />
./autogen.sh<br />
<br />
./configure --with-platform=pc --prefix=/usr<br />
<br />
make<br />
<br />
make install<br />
</pre><br />
<br />
The <code>--with-platform=pc</code> generates grub2 for bios alone irrespective of the firmware of the build system.<br />
<br />
=== For UEFI Systems ===<br />
<br />
First [https://wiki.archlinux.org/index.php/Unified_Extensible_Firmware_Interface#Detecting_UEFI_Firmware_Arch Detect which UEFI Firmware arch] you have and then follow the compile instructions below:<br />
<pre><br />
./autogen.sh<br />
<br />
./configure --with-platform=efi --target=TARGET_UEFI_ARCH --prefix=/usr<br />
<br />
make<br />
<br />
make install<br />
</pre><br />
<br />
The "--target" option denotes the UEFI firmware arch. for which grub2 should be compiled, not the architecture of the linux kernel grub2 may boot. <br />
<br />
It is possible to use UEFI 64-bit firmware + GRUB2 as x86_64-EFI app loading a i686 linux kernel, as long as the kernel does not try to access UEFI Runtime Services. Vice-versa situation is also possible. But a x86_64 UEFI firmware cannot launch GRUB2 i386-efi app (unlike x86_64 Operating Systems), and a i386 UEFI firmware will not launch GRUB2 {{Codeline|x86_64-efi}} app. It is important to compile GRUB2 to match the architecture of the UEFI firmware.<br />
<br />
== Configuration ==<br />
<br />
The configuration files are {{Filename|/etc/default/grub}} and {{Filename|/etc/grub.d/*}}. These files are used to generate the {{Filename|/boot/grub/grub.cfg}} file. You can also choose to manually edit {{Filename|grub.cfg}}.<br />
<br />
=== grub-mkconfig ===<br />
<br />
The grub-mkconfig script can be used to generate a {{Filename|grub.cfg}} file. By default the script outputs to stdout. Note that gettext ― an optional dependency of the GRUB2 package ― is required by the grub-mkconfig script. To generate a {{Filename|grub.cfg}} file run the command:<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
Note that grub-mkconfig probably has your grub directory hardcoded to /boot/grub, which is probably wrong if you're using UEFI. Either mount your efi grub directory at /boot/grub or edit the script.<br />
<br />
=== grub.cfg ===<br />
<br />
A basic grub file uses the following options<br />
* {{Codeline|(hdX,Y)}} is the partition {{Codeline|Y}} on disk {{Codeline|X}}, partition numbers starting at 1, disk numbers starting at 0<br />
* {{Codeline|1=set default=N}} is the default boot entry that is chosen after timeout for user action<br />
* {{Codeline|1=set timeout=M}} is the time {{Codeline|M}} to wait in seconds for a user selection before default is booted<br />
* {{Codeline|<nowiki>menuentry "title" {entry options}</nowiki>}} is a boot entry titled {{Codeline|title}}<br />
* {{Codeline|1=set root=(hdX,Y)}} sets the boot partition, where the kernel and GRUB modules are stored (boot need not be a separate partition, and may simply be a directory under the "root" partition ({{Filename|/}})<br />
<br />
An example configuration:<br />
<br />
{{File<br />
|name=/boot/grub/grub.cfg<br />
|content=<nowiki><br />
# Config file for GRUB2 - The GNU GRand Unified Bootloader<br />
# /boot/grub/grub.cfg<br />
<br />
# DEVICE NAME CONVERSIONS<br />
#<br />
# Linux Grub<br />
# -------------------------<br />
# /dev/fd0 (fd0)<br />
# /dev/sda (hd0)<br />
# /dev/sdb2 (hd1,2)<br />
# /dev/sda3 (hd0,3)<br />
#<br />
<br />
# Timeout for menu<br />
set timeout=5<br />
<br />
# Set default boot entry as Entry 0<br />
set default=0<br />
<br />
# (0) Arch Linux<br />
menuentry "Arch Linux" {<br />
set root=(hd0,1)<br />
linux /vmlinuz-linux root=/dev/sda3 ro<br />
initrd /initramfs-linux.img<br />
}<br />
<br />
## (1) Windows<br />
#menuentry "Windows" {<br />
#set root=(hd0,3)<br />
#chainloader +1<br />
#}<br />
</nowiki>}}<br />
<br />
=== Dual-booting ===<br />
<br />
''NOTE: If you want GRUB2 to automatically search for other systems, for example as in Ubuntu. Then you may need to download {{Package AUR|os-prober}} from the [[AUR]].''<br />
<br />
==== Using grub-mkconfig ====<br />
The best way to add other entries is editing the {{Filename|/etc/grub.d/40_custom}}. The entries in this file will be automatically added when running '''grub-mkconfig'''.<br />
After adding the new lines, run:<br />
# grub-mkconfig -o /boot/grub/grub.cfg <br />
to generate an updated {{Filename|grub.cfg}}.<br />
<br />
===== With GNU/Linux =====<br />
<br />
Assuming that the other distro is on partition {{Filename|sda2}}:<br />
<br />
menuentry "Other Linux" {<br />
set root=(hd0,2)<br />
linux /boot/vmlinuz (add other options here as required)<br />
initrd /boot/initrd.img (if the other kernel uses/needs one)<br />
}<br />
<br />
===== With Windows =====<br />
<br />
This assumes that your Windows partition is {{Filename|sda3}}.<br />
<br />
# (2) Windows XP<br />
menuentry "Windows XP" {<br />
set root=(hd0,3)<br />
chainloader (hd0,3)+1<br />
}<br />
<br />
If the windows bootloader is on an entirely different harddrive than grub, it may be necessary to trick Windows into believing that it is in fact the first harddrive. This was possible in the old grub with {{Codeline|map}} and is now done with {{Codeline|drivemap}}. Assume grub is on {{Filename|hd0}} and windows on {{Filename|hd2}}, you need to add the following after {{Codeline|set root}}:<br />
<br />
drivemap -s hd0 hd2<br />
<br />
==== With Windows via EasyBCD and NeoGRUB ====<br />
<br />
Since EasyBCD's NeoGRUB currently does not understand the GRUB2 menu format, chainload to it by replacing the contents of your {{Filename|C:\NST\menu.lst}} file with lines similar to the following:<br />
<br />
default 0<br />
timeout 1<br />
<br />
title Chainload into GRUB v2<br />
root (hd0,7)<br />
kernel /boot/grub/core.img<br />
<br />
===Visual Configuration===<br />
<br />
In GRUB2 it is possible, by default, to change the look of the menu.<br />
<br />
====Background image and bitmap fonts====<br />
<br />
GRUB2 comes with support for background images and bitmap fonts in pf2 format. The unifont font is included in the grub2 package under the filename {{Filename|unicode.pf2}}, or, as only ascii characters under the name {{Filename|ascii.pf2}}. Image formats supported include tga, png and jpeg, providing the correct modules are loaded. The maximum supported resolution depends on your hardware. There are two ways of setting a {{Filename|tga}} file as background. Two sample configurations are shown below.<br />
<br />
Edit {{Filename|/etc/default/grub}} like this:<br />
GRUB_GFXMODE=1024x768x32<br />
GRUB_GFXPAYLOAD_LINUX=keep<br />
GRUB_BACKGROUND="/boot/grub/archlinux.tga"<br />
#GRUB_THEME="/path/to/gfxtheme"<br />
<br />
(archlinux.tga is a placeholder; put your file name there)<br />
<br />
To generate the changes, run: <br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
{{Note|If this example does not work for you try to replace {{Codeline|1=gfxmode="1024x768x32"}} by {{Codeline|1=vbemode="0x105"}}.}}<br />
{{Note|To show all the modes you can use {{Codeline|1=# hwinfo --framebuffer}} (hwinfo is available in [community]), while at grub2 prompt you can use the {{Codeline|1=vbeinfo}} command.}}<br />
{{Note|If you have installed Grub on a separate partition, {{Filename|/boot/grub/archlinux.tga}} becomes {{Filename|/grub/archlinux.tga}}.}}<br />
<br />
====Menu colors====<br />
<br />
As in Grub (0.9x), you can change the menu colors in Grub2. The available colors for GRUB2 are at http://www.gnu.org/software/grub/manual/html_node/Theme-file-format.html#Theme-file-format . <br />
Here is an example:<br />
<br />
Edit {{Filename|/etc/default/grub}}:<br />
GRUB_COLOR_NORMAL="light-blue/black"<br />
GRUB_COLOR_HIGHLIGHT="light-cyan/blue"<br />
<br />
Generate the changes:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
====Hidden menu====<br />
<br />
One of the unique features of Grub2 is hiding/skipping the menu and showing it by holding "Shift" when needed. You can also adjust whether you want to see the timeout counter.<br />
<br />
Edit {{Filename|/etc/default/grub}} as you wish. Here is an example where the comments from the beginning of the two lines have been removed to enable the feature, the timeout has been set to five seconds and to be shown to the user:<br />
GRUB_HIDDEN_TIMEOUT=5<br />
GRUB_HIDDEN_TIMEOUT_QUIET=false<br />
<br />
and run:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
====Setting the framebuffer resolution ====<br />
<br />
Grub2 can set the framebuffer for both grub2 itself and the kernel. The old ''vga='' way is deprecated. The preferred method is editing {{Filename|/etc/default/grub}} as the following sample:<br />
<br />
GRUB_GFXMODE=1024x768x32<br />
GRUB_GFXPAYLOAD_LINUX=keep<br />
<br />
To generate the changes, run: <br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
The {{Codeline|gfxpayload}} property will make sure the kernel keeps the resolution.<br />
<br />
If this method does not work for you, the deprecated <code>vga=</code> method will still work. Just<br />
add it next to the <code>"GRUB_CMDLINE_LINUX_DEFAULT="</code> line in {{Filename|/etc/default/grub}}<br />
for eg: <code>"GRUB_CMDLINE_LINUX_DEFAULT="quiet splash vga=792"</code> will give you a {{Codeline|1024x768}} resolution.<br />
<br />
You can choose one of these resolutions: {{Codeline|640×480}}, {{Codeline|800×600}}, {{Codeline|1024×768}}, {{Codeline|1280×1024}}, {{Codeline|1600×1200}}<br />
<br />
=== Other Options ===<br />
<br />
==== LVM ====<br />
<br />
If you use [[LVM]] for your {{Filename|/boot}}, add the following before menuentry lines:<br />
<br />
insmod lvm<br />
<br />
and specify your root in the menuentry as:<br />
<br />
set root=(''lvm_group_name''-''lvm_logical_boot_partition_name'')<br />
<br />
Example:<br />
<br />
# (0) Arch Linux<br />
menuentry "Arch Linux" {<br />
insmod lvm<br />
set root=(VolumeGroup-lv_boot)<br />
# you can only set following two lines<br />
linux /vmlinuz-linux root=/dev/mapper/VolumeGroup-root ro<br />
initrd /initramfs-linux.img<br />
}<br />
<br />
==== Raid ====<br />
<br />
Grub2 provides convenient handling of raid-volumes. You need to add:<br />
insmod raid<br />
<br />
which allows you to address the volume natively. E.g. {{Filename|/dev/md0}} becomes:<br />
set root=(md0)<br />
<br />
whereas a partitioned raid-volume (e.g. {{Filename|/dev/md0p1}}) becomes:<br />
set root=(md0,1)<br />
<br />
==== Persistent block device naming ====<br />
You can use UUIDs to detect partitions instead of the "old" {{Filename|/dev/sd*}} and {{Filename|/dev/hd*}} scheming. It has the advantage of detecting partitions by their unique UUIDs, which is needed by some people booting with complicated partition setups.<br />
<br />
UUIDs are used by default in the recent versions of grub2 - there is no downside in it anyway except that you need to re-generate the {{Filename|grub.cfg}} file every time you resize or reformat your partitions. Remember this when modifying partitions with Live-CD.<br />
<br />
The recent versions of grub2 use UUIDs by default. You can re-enable the use of UUIDS by simply commenting the UUID line (this is also what it looks like by default):<br />
#GRUB_DISABLE_LINUX_UUID=true<br />
you can also just set the value as {{Codeline|false}} as shown here:<br />
GRUB_DISABLE_LINUX_UUID=false<br />
<br />
Either way, do not forget to generate the changes:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
==== Using Labels ====<br />
<br />
It is possible to use labels, human-readable strings attached to filesystems, by using the {{Codeline|--label}} option to {{Codeline|search}}. First of all, label your existing partition:<br />
# tune2fs -L a <LABEL> <PARTITION><br />
<br />
Then, add an entry using labels. An example of this:<br />
<br />
menuentry "Arch Linux, session texte" {<br />
search --label --no-floppy --set=root archroot<br />
linux /boot/vmlinuz-linux root=/dev/disk/by-label/archroot ro<br />
initrd /boot/initramfs-linux.img<br />
}<br />
<br />
==== Recall previous entry ====<br />
<br />
Grub2 can remember the last entry you booted from and use this as the default entry to boot from next time. This is useful if you have multiple kernels (i.e., the current Arch one and the LTS kernel as a fallback option) or operating systems. To do this, edit {{Filename|/etc/default/grub}} and change the setting of {{Codeline|GRUB_DEFAULT}}:<br />
<br />
GRUB_DEFAULT=saved<br />
<br />
This ensures that grub will default to the saved entry. To enable saving the selected entry, add the following line to {{Filename|/etc/default/grub}}:<br />
<br />
GRUB_SAVEDEFAULT=true<br />
<br />
Remember to regenerate your configuration file.<br />
<br />
==== Security ====<br />
<br />
If you want to secure GRUB2 so it is not possible for anyone to change boot parameters or use the command line, you can add a user/password combination to GRUB2's configuration files. To do this, run the command {{Codeline|grub-mkpasswd_pbkdf2}}. Enter a password and confirm it. The output will look like this:<br />
<br />
<pre style='overflow:auto'><br />
Your PBKDF2 is grub.pbkdf2.sha512.10000.C8ABD3E93C4DFC83138B0C7A3D719BC650E6234310DA069E6FDB0DD4156313DA3D0D9BFFC2846C21D5A2DDA515114CF6378F8A064C94198D0618E70D23717E82.509BFA8A4217EAD0B33C87432524C0B6B64B34FBAD22D3E6E6874D9B101996C5F98AB1746FE7C7199147ECF4ABD8661C222EEEDB7D14A843261FFF2C07B1269A</pre>Then, add the following to {{Filename|/etc/grub.d/00_header}}:<br />
<pre>cat << EOF<br />
<br />
set superusers="username"<br />
password_pbkdf2 username <password><br />
<br />
EOF</pre><br />
where <password> is the string generated by {{Codeline|grub-mkpasswd_pbkdf2}}.<br />
<br />
Regenerate your configuration file. Your GRUB2 command line and boot parameters are now protected.<br />
<br />
=== Booting an Ubuntu ISO Image from the GRUB2 Screen ===<br />
<br />
Edit {{Filename|/etc/grub.d/40_custom}} to add an entry pointing to an Ubuntu iso:<br />
<br />
menuentry "ubuntu-11.04-desktop-amd64.iso" {<br />
set isofile="/path/to/ubuntu-11.04-desktop-amd64.iso"<br />
loopback loop (hdX,Y)$isofile<br />
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile quiet noeject noprompt splash --<br />
initrd (loop)/casper/initrd.lz<br />
}<br />
<br />
Be sure to adjust the "hdX,Y" in the third line to point to the correct disk/partition number of the isofile. When finished, update grub2's configuration file via:<br />
<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
== Using the command shell ==<br />
<br />
Since the MBR is too small to store all GRUB2 modules, only the menu and a few basic commands reside there. The majority of GRUB2 functionality remains in modules in {{Filename|/boot/grub}}, which are inserted as needed. In error conditions (e.g. if the partition layout changes) GRUB2 may fail to boot. When this happens, a command shell may appear.<br />
<br />
GRUB2 offers multiple shells/prompts. If there is a problem reading the menu but the bootloader is able to find the disk, you will likely be dropped to the "normal" shell:<br />
sh:grub><br />
<br />
If there is a more serious problem (e.g. GRUB cannot find required files), you may instead be dropped to the "rescue" shell:<br />
grub rescue><br />
<br />
The rescue shell is a restricted subset of the normal shell, offering much less functionality. If dumped to the rescue shell, first try inserting the "normal" module, then starting the "normal" shell:<br />
grub rescue> set prefix=(hdX,Y)/boot/grub<br />
grub rescue> insmod (hdX,Y)/boot/grub/normal.mod<br />
rescue:grub> normal<br />
<br />
=== Pager support ===<br />
<br />
GRUB2 supports pager for reading commands that provide long output (like the help command). This works only in normal shell mode and not in rescue mode. To enable pager, in GRUB2 command shell type:<br />
sh:grub> set pager=1<br />
<br />
== GUI configuration tools ==<br />
<br />
Following package may be installed from [[AUR]]<br />
* [http://kde-apps.org/content/show.php?content=139643 grub2-editor] (requires kdelibs)<br />
*:A KDE4 control module for configuring the GRUB2 bootloader<br />
* [http://kde-apps.org/content/show.php?content=137886 kcm-grub2] (requires kdelibs python2-qt kdebindings-python)<br />
*:This Kcm module manages the most common settings of Grub2.<br />
* [http://sourceforge.net/projects/startup-manager/ startupmanager] (requires gnome-python imagemagick yelp python2 xorg-xrandr)<br />
*:GUI app for changing the settings of GRUB, GRUB2, Usplash and Splashy<br />
<br />
== parttool or legacy hide/unhide ==<br />
<br />
If you have a win9x paradigm with hidden C disks GRUB legacy had the hide/unhide feature. In GRUB2 this has been replaced by parttool. For example, to boot the third C disk of three win9x installations on the CLI enter the CLI and:<br />
parttool hd0,1 hidden+ boot-<br />
parttool hd0,2 hidden+ boot-<br />
parttool hd0,3 hidden- boot+<br />
set root=hd0,3<br />
chainloader +1<br />
boot<br />
<br />
== Using the rescue console ==<br />
<br />
See [[#Using the command shell]] first. If unable to activate the standard shell, one possible solution is to boot using a live CD or some other rescue disk to correct configuration errors and reinstall GRUB. However, such a boot disk is not always available (nor necessary); the rescue console is surprisingly robust.<br />
<br />
The available commands in GRUB rescue include "insmod", "ls", "set", and "unset". This example uses "set" and "insmod". "set" modifies variables and "insmod" inserts new modules to add functionality.<br />
<br />
Before starting, the user must know the location of their {{Filename|/boot}} partition (be it a separate partition, or a subdirectory under their root):<br />
grub rescue> set prefix=(hdX,Y)/boot/grub<br />
<br />
where X is the physical drive number and Y is the partition number.<br />
<br />
To expand console capabilities, insert the "linux" module:<br />
grub rescue> insmod (hdX,Y)/boot/grub/linux.mod<br />
<br />
{{Note|With a separate boot partition, omit {{Filename|/boot}} from the path, (i.e. type {{Codeline|1=set prefix=(hdX,Y)/grub}} and {{Codeline|insmod (hdX,Y)/grub/linux.mod}}).}}<br />
<br />
This introduces the "linux" and "initrd" commands, which should be familiar (see [[#Configuration]]).<br />
<br />
An example, booting Arch Linux:<br />
set root=(hd0,5)<br />
linux /boot/vmlinuz-linux root=/dev/sda5<br />
initrd /boot/initramfs-linux.img<br />
boot<br />
<br />
With a separate boot partition, again change the lines accordingly:<br />
set root=(hd0,5)<br />
linux /vmlinuz-linux root=/dev/sda6<br />
initrd /initramfs-linux.img<br />
boot<br />
<br />
After successfully booting the Arch Linux installation, users can correct {{Filename|grub.cfg}} as needed and then run:<br />
# grub-install /dev/sda --no-floppy<br />
<br />
to reinstall GRUB2 and fix the problem completely, changing {{Filename|/dev/sda}} if needed. See [[#Bootloader installation]] for details.<br />
<br />
== Combining the use of UUID's and basic scripting ==<br />
<br />
If you like the idea of using UUID's to avoid unreliable BIOS mappings or are struggling with Grub's syntax, here is an example boot menu item that uses UUID's and a small script to direct Grub to the proper disk partitions for your system. All you need to do is replace the UUID's in the sample with the correct UUID's for your system. (The example applies to a system with a boot and root partition. You will obviously need to modify the Grub configuration if you have additional partitions.)<br />
<br />
menuentry "Arch Linux 64" {<br />
#Enter the UUID of your boot partition (this is where Grub and your kernel reside)<br />
set uuid_grub_boot=ece0448f-bb08-486d-9864-ac3271bd8d07<br />
<br />
#Enter the UUID of the partition containing the root partition of your Arch Linux installation. <br />
set uuid_os_root=c55da16f-e2af-4603-9e0b-03f5f565ec4a<br />
<br />
#(Note: this may be the same as your boot partition)<br />
<br />
#Here we set the Grub "root" variable by locating the UUID of the root partition identified above <br />
search --fs-uuid --no-floppy --set=root $uuid_os_root<br />
<br />
#Here we set a custom variable grub_boot by locating the UUID of the boot partition identified above <br />
search --fs-uuid --no-floppy --set=grub_boot $uuid_grub_boot<br />
<br />
#Here is the magic. We test to see if the boot and root partitions have the same UUID.<br />
#If they do, we append /boot to the $grub_boot variable. For ex. (hd0,1) becomes (hd0,1)/boot.<br />
if [ $uuid_grub_boot == $uuid_os_root ] ; then<br />
set grub_boot=$grub_boot/boot<br />
fi<br />
<br />
# $grub_boot now points to the correct location, so the following will properly find the kernel and initrd<br />
linux ($grub_boot)/vmlinuz-linux root=/dev/disk/by-uuid/$uuid_os_root ro<br />
initrd ($grub_boot)/initramfs-linux.img<br />
}<br />
<br />
== Troubleshooting ==<br />
<br />
Any troubleshooting should be added here.<br />
<br />
=== Enable GRUB2 debug messages ===<br />
<br />
Add<br />
<br />
set pager=1<br />
set debug=all<br />
<br />
to {{Filename|grub.cfg}}.<br />
<br />
=== Correct GRUB2 No Suitable Mode Found Error ===<br />
<br />
If you get this error when booting any menuentry<br />
<br />
error: no suitable mode found<br />
Booting however<br />
<br />
Then you need to initialize grub2 graphical terminal (gfxterm) with proper video mode (gfxmode) in grub2. This video mode is passed by grub2 to the linux kernel via 'gfxpayload'. In case of UEFI systems, if the grub2 video mode is not initialized, no kernel boot messages will be shown in the terminal (atleast until KMS kicks in)<br />
<br />
Copy {{Filename|/usr/share/grub/unicode.pf2}} to ${GRUB2_PREFIX_DIR} ({{Filename|/boot/grub/}} in case of BIOS systems and {{Filename|/boot/efi/efi/grub/}} in case of UEFI systems). <br />
<br />
# cp /usr/share/grub/unicode.pf2 ${GRUB2_PREFIX_DIR}<br />
<br />
If {{Filename|/usr/share/grub/unicode.pf2}} does not exist, install {{Package Official|bdf-unifont}}, create the unifont.pf2 file and then copy it to ${GRUB2_PREFIX_DIR} .<br />
<br />
# grub-mkfont -o unicode.pf2 /usr/share/fonts/misc/unifont.bdf<br />
<br />
Then, in the {{Filename|grub.cfg}} file, add the following lines to enable grub2 to pass the video mode correctly to the kernel, without of which you will only get a black screen (no output) but booting (actually) proceeds successfully without any system hang:<br />
<br />
BIOS systems<br />
<br />
insmod vbe<br />
<br />
UEFI systems<br />
<br />
insmod efi_gop<br />
insmod efi_uga<br />
<br />
After that add the following code (common to both BIOS and UEFI)<br />
<br />
insmod font<br />
<br />
if loadfont ${prefix}/unicode.pf2<br />
then<br />
insmod gfxterm<br />
set gfxmode=auto<br />
set gfxpayload=keep<br />
terminal_output gfxterm<br />
fi<br />
<br />
As you can see for gfxterm (graphical terminal) to function properly, {{Filename|unicode.pf2}} font file should exist in ${GRUB2_PREFIX_DIR}.<br />
<br />
=== msdos-style error message ===<br />
<br />
grub-setup: warn: This msdos-style partition label has no post-MBR gap; embedding won't be possible!<br />
grub-setup: warn: Embedding is not possible. GRUB can only be installed in this setup by using blocklists.<br />
However, blocklists are UNRELIABLE and its use is discouraged.<br />
grub-setup: error: If you really want blocklists, use --force.<br />
<br />
This error may occur when you try installing GRUB2 in a VMware container. Read more about it [http://bbs.archlinux.org/viewtopic.php?pid=581760#p581760 here]. It happens when the first partition starts just after the MBR (block 63), without the usual space of 1 MiB (2048 blocks) before the first partition. Read [[#MBR_aka_msdos_partitioning_specific_instructions]]<br />
<br />
=== UEFI GRUB2 not loaded ===<br />
In some cases the EFI may fail to load grub correctly. Provided everything is set up correctly, the output of<br />
efibootmgr -v<br />
might look something like this:<br />
BootCurrent: 0000<br />
Timeout: 3 seconds<br />
BootOrder: 0000,0001,0002<br />
Boot0000* Grub HD(1,800,32000,23532fbb-1bfa-4e46-851a-b494bfe9478c)File(\efi\grub\grub.efi)<br />
Boot0001* Shell HD(1,800,32000,23532fbb-1bfa-4e46-851a-b494bfe9478c)File(\EfiShell.efi)<br />
Boot0002* Festplatte BIOS(2,0,00)P0: SAMSUNG HD204UI .<br />
If everything works correctly, the EFI would now automatically load grub.<br><br />
If the screen only goes black for a second and the next boot option is tried afterwards, according to [https://bbs.archlinux.org/viewtopic.php?pid=981560#p981560 this post], moving grub to the partition root can help. The boot option has to be deleted and recreated afterwards. The entry for grub should look like this then:<br />
Boot0000* Grub HD(1,800,32000,23532fbb-1bfa-4e46-851a-b494bfe9478c)File(\grub.efi)<br />
<br />
=== Invalid signature ===<br />
If trying to boot windows results in an "invalid signature" error, e.g. after reconfiguring partitions or adding additional hard drives, (re)move grub's device configuration and let it reconfigure.<br />
# mv /boot/grub/device.map /boot/grub/device.map-old<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
Grub-mkconfig should now mention all found boot options including windows. If it works, remove /boot/grub/device.map-old.<br />
<br />
== References ==<br />
<br />
# Official GRUB2 Manual - http://www.gnu.org/software/grub/manual/grub.html<br />
# GRUB2 wiki page describing steps to compile for UEFI systems - https://help.ubuntu.com/community/UEFIBooting - previously http://grub.enbug.org/TestingOnUEFI{{Linkrot|2011|09|05}}<br />
# Wikipedia's page on [http://en.wikipedia.org/wiki/BIOS_Boot_partition BIOS Boot Partition]<br />
<br />
== External Links ==<br />
<br />
# [https://github.com/the-ridikulus-rat/My_Shell_Scripts/blob/master/grub2/grub2_bios.sh A Linux Bash Shell script to compile and install GRUB2 for BIOS from BZR Source]<br />
# [https://github.com/the-ridikulus-rat/My_Shell_Scripts/blob/master/grub2/grub2_uefi.sh A Linux Bash Shell script to compile and install GRUB2 for UEFI from BZR Source]</div>Mayweedhttps://wiki.archlinux.org/index.php?title=GRUB&diff=167962GRUB2011-10-29T17:32:08Z<p>Mayweed: </p>
<hr />
<div>[[Category:Boot loaders (English)]]<br />
{{i18n|GRUB2}}<br />
[[fr:GRUB2]]<br />
{{Article summary start}}<br />
{{Article summary text|Covers various aspects of the next generation of the GRand Unified Bootloader (GRUB2).}}<br />
{{Article summary heading|Overview}}<br />
{{Article summary text|{{Boot process overview}}}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|Burg}} - Burg is a brand-new boot loader based on GRUB2. It uses a new object format which allows it to be built in a wider range of OS, including Linux/Windows/OSX/Solaris/FreeBSD, etc. It also has a highly configurable menu system which works in both text and graphic mode. <br />
{{Article summary heading|Resources}}<br />
{{Article summary link|GNU GRUB -- GNU Project|http://www.gnu.org/software/grub/}}<br />
{{Article summary link|GNU GRUB Wiki|http://grub.enbug.org/}}{{Linkrot|2011|09|05}}<br />
{{Article summary end}}<br />
<br />
[http://www.gnu.org/software/grub/ GRUB2] is the next generation of the GRand Unified Bootloader (GRUB). GRUB2 is derived from [http://www.nongnu.org/pupa/ PUPA] which was a research project to investigate the next generation of GRUB. GRUB 2 has been rewritten from scratch to clean up everything and provide modularity and portability [http://www.gnu.org/software/grub/grub-faq.en.html#q1].<br />
<br />
Briefly, the ''bootloader'' is the first software program that runs when a computer starts. It is responsible for loading and transferring control to the Linux kernel. The kernel, in turn, initializes the rest of the operating system.<br />
<br />
== Preface ==<br />
<br />
Although, [[GRUB]] (i.e. version 0.9x) is the de facto standard bootloader of Linux, it is considered 'legacy' by upstream. It is being replaced by GRUB2 in many distributions. Upstream recommends GRUB2 >=1.99~rc2 over grub-legacy, even for current grub-legacy users.<br />
<br />
{{Note|grub2 from 1.99~rc2 and later supports btrfs as root (without a separate /boot filesystem).}}<br />
<br />
=== Notes for current GRUB users ===<br />
<br />
* There are differences in the commands of GRUB and GRUB2. Familiarize yourself with [http://www.gnu.org/software/grub/manual/grub.html#Commands GRUB2 commands] before proceeding (e.g. "find" has been replaced with "search").<br />
<br />
* GRUB2 is now ''modular'' and no longer requires "stage 1.5". As a result, the bootloader itself is limited -- modules are loaded from the hard drive as needed to expand functionality (e.g. for [[LVM]] or RAID support).<br />
<br />
* Device naming has changed between GRUB and GRUB2. Partitions are numbered from 1 instead of 0 while drives are still numbered from 0, and prefixed with partition-table type. For example, {{Filename|/dev/sda1}} would be referred to as {{Codeline|(hd0,msdos1)}} (for MBR) or {{Codeline|(hd0,gpt1)}} (for GPT) using GRUB2.<br />
<br />
== Installation ==<br />
<br />
=== During Arch Linux installation ===<br />
<br />
* Skip the '''Install Bootloader''' step and exit the installer.<br />
* Configure the network:<br />
# aif -p partial-configure-network<br />
This will bring up a prompt; put in the network interface to use, (e.g., eth0) and use DHCP for easy configuration.<br />
* If you did not configure the installed system's {{Filename|/etc/resolv.conf}} file during installation (for instance, if you plan to let DHCP generate it later), you will need to copy the one generated by AIF when it configured the network:<br />
# cp /etc/resolv.conf /mnt/etc/resolv.conf<br />
* Load the dm-mod module (you might need grub2-bios; install the package if needed):<br />
# modprobe dm-mod<br />
{{Note|This is necessary at this point, and cannot be postponed after the chroot. If you try to use modprobe in a chroot environment that has a later kernel version from that of the installing device (at the time of writing, 2.6.33), modprobe will fail. This happens routinely using the Arch "net" installations.}}<br />
* From the installer's live shell, chroot to the installed system:<br />
# mount -o bind /dev /mnt/dev<br />
# chroot /mnt bash<br />
* Update pacman's database:<br />
# pacman-db-upgrade<br />
* Refresh the package list (with an extra -y flag to force a refresh of all package lists even if they appear to be up to date):<br />
# pacman -Syy<br />
* Install the GRUB2 package as mentioned in the section [[#From a running Arch Linux]]. Note that the dm-mod module has already been loaded, no need to do that again.<br />
<br />
=== From a running Arch Linux ===<br />
<br />
====Make a backup of your precious data====<br />
In general, a grub installation ran smoothly and you got no problems at all. And sometimes it could simply messed up your system. You're strongly advised to make a backup before even think of grub2.<br />
<br />
*copy grub modules and configuration<br />
# cp -a /boot/grub /path/to/backup/<br />
*backup the MBR and GRUB stage 1.5<br />
# dd if=/dev/sda of=/path/to/backup/first-sectors count=63<br />
<br />
You could now lightly remove /boot/grub and follow the instructions below.You know that if things get nasty, you could reboot your system thanks to an installation media and :<br />
<br />
*move old grub2 files out of the way<br />
# mv /boot/grub /boot/grub.nonfunctional<br />
*copy grub back to /boot<br />
# cp -a /path/to/backup/grub /boot/<br />
*replace MBR and next 62 sectors of sda with backed up copy (DANGEROUS!)<br />
# dd if=/path/to/backup/first-sectors of=/dev/sda count=63<br />
<br />
==== BIOS systems ====<br />
<br />
===== Preliminary Considerations for GRUB2 BIOS =====<br />
<br />
====== [[GPT]] specific instructions ======<br />
<br />
GRUB2 in BIOS-GPT configuration requires a BIOS Boot Partition to embed its core.img in the absence of post-MBR gap in GPT partitioned systems (which is taken over by the GPT Primary Header and Primary Partition table). This partition is used by GRUB2 only in BIOS-GPT setups. No such partition type exists in case of MBR partitioning (at least not for GRUB2). This partition is also not required if the system is UEFI based, as no embedding of bootsectors takes place in that case. Syslinux does not require this partition.<br />
<br />
For a BIOS-GPT configuration, create a 2 MiB partition using cgdisk or GNU Parted with no filesystem. The location of the partition in the partition table does not matter but it should be within the first 2 TiB region of the disk. It is advisable to put it somewhere in the beginning of the disk before the /boot partition. Set the partition type to "EF02" in cgdisk or {{Codeline|set <BOOT_PART_NUM> bios_grub on}} in GNU Parted.<br />
<br />
{{Note|This partition should be created before grub_bios-install or grub-setup is run or before the '''Install Bootloader''' step of the Archlinux installer (if GRUB2 is selected as bootloader).}}<br />
<br />
====== [[MBR]] aka msdos partitioning specific instructions ======<br />
<br />
Usually the post-MBR gap (after the 512 byte MBR region and before the start of the 1st partition) in many MBR (or msdos disklabel) partitioned systems is 32 KiB when DOS compatibility cylinder alignment issues are satisfied in the partition table. However a post-MBR gap of about 1 to 2 MiB is recommended to provide sufficient room for embedding grub2's core.img ( https://bugs.archlinux.org/task/24103 ). It is advisable to use a partitioner which supports 1 MiB partition alignment to obtain this space as well as satisfy other non-512 byte sector issues (which are unrelated to embedding of core.img).<br />
<br />
If you do not dual-boot with MS Windows (any version) in BIOS systems, it is advisable to switch to GPT partitioning - [[GUID_Partition_Table#Convert_from_MBR_to_GPT_without_data_loss]]<br />
{{Note|Create the 2MiB partition mentioned above BEFORE you convert to GPT. If you do not, gparted will not resize your boot partition to allow its creation, and when you reboot grub2 will not know where to look.}}<br />
<br />
===== Before grub_bios-install =====<br />
<br />
The GRUB2 package can be installed with pacman (and will replace {{Package Official|grub}}, if it is installed):<br />
<br />
# pacman -S grub2-bios<br />
<br />
{{Note|Installing grub2-common (a dependency of grub2-bios) 1.99~rc1 or later, may take forever in some systems since the post_install script runs grub-mkconfig and this script does not provide the option <code>--no-floppy</code>. For more details search this option in the article.}}<br />
<br />
{{Note|Simply installing the package won't update the /boot/grub/core.img file and the grub2 modules in /boot/grub . You need to update the core.img file and the grub2 modules manually using grub_bios-install as explained below.}}<br />
<br />
Also load the device-mapper kernel module without which grub-probe does not reliably detect disks and partitions<br />
<br />
# modprobe dm-mod<br />
<br />
<br />
===== Run grub_bios-install =====<br />
<br />
There are 3 ways to install grub2 in BIOS booting - [[#Install_to_440-byte_MBR_boot_code_region]] (recommended) , [[#Install_to_Partition_or_Partitionless_Disk]] (not recommended) or [[#Generate_core.img_alone]] (safest method, but requires another BIOS bootloader like [[grub-legacy]] or [[syslinux]] to be installed to chainload {{Filename|/boot/grub/core.img}} ). For all the ways [[#Before_grub_bios-install]] step is needed.<br />
<br />
====== Install to 440-byte MBR boot code region ======<br />
<br />
To setup grub2-bios in the 440-byte Master Boot Record boot code region, populate the {{Filename|/boot/grub}} directory, generate the {{Filename|/boot/grub/core.img}} file, and embed it in the 32 KiB (minimum size - varies depending on partition alignment) post-MBR gap (MBR disks) or in BIOS Boot Partition (GPT disks), run<br />
<br />
# grub_bios-install --boot-directory=/boot --no-floppy --recheck /dev/sda<br />
<br />
where {{Filename|/dev/sda}} is the destination of the installation (in this case the MBR of the first SATA disk). If you use [[LVM]] for your {{Filename|/boot}}, you can install GRUB2 on multiple physical disks. <br />
<br />
The {{Codeline|--no-floppy}} tells grub2-bios utilities not to search for any floppy devices which reduces the overall execution time of grub_bios-install on many systems (it will also prevent the issue below from occuring). Otherwise you get an error like this<br />
<br />
grub-probe: error: Cannot get the real path of '/dev/fd0'<br />
Auto-detection of a filesystem module failed.<br />
Please specify the module with the option '--modules' explicitly.<br />
<br />
Then:<br />
* Delete all the files from {{Filename|/boot/grub}} except {{Filename|/boot/grub/menu.lst}} .<br />
<br />
* Follow the [[#Install_to_440-byte_MBR_boot_code_region]] instructions.<br />
<br />
* Follow [[#Generate_GRUB2_BIOS_Config_file]] or if that fails, convert your {{Filename|/boot/grub/menu.lst}} file to {{Filename|/boot/grub/grub.cfg}} using:<br />
<br />
# grub-menulst2cfg /boot/grub/menu.lst /boot/grub/grub.cfg<br />
<br />
For example:<br />
<br />
{{File|name=/boot/grub/menu.lst|content=<br />
default=0<br />
timeout=5<br />
<br />
title Arch Linux Stock Kernel<br />
root (hd0,0)<br />
kernel /vmlinuz-linux root=/dev/sda2 ro<br />
initrd /initramfs-linux.img<br />
<br />
title Arch Linux Stock Kernel Fallback<br />
root (hd0,0)<br />
kernel /vmlinuz-linux root=/dev/sda2 ro<br />
initrd /initramfs-linux-fallback.img<br />
}}<br />
<br />
{{File|name=/boot/grub/grub.cfg|content=<br />
set default='0'; if [ x"$default" = xsaved ]; then load_env; set default="$saved_entry"; fi<br />
set timeout=5<br />
<br />
menuentry 'Arch Linux Stock Kernel' {<br />
set root='(hd0,1)'; set legacy_hdbias='0'<br />
legacy_kernel '/vmlinuz-linux' '/vmlinuz-linux' 'root=/dev/sda2' 'ro'<br />
legacy_initrd '/initramfs-linux.img' '/initramfs-linux.img'<br />
<br />
}<br />
<br />
menuentry 'Arch Linux Stock Kernel Fallback' {<br />
set root='(hd0,1)'; set legacy_hdbias='0'<br />
legacy_kernel '/vmlinuz-linux' '/vmlinuz-linux' 'root=/dev/sda2' 'ro'<br />
legacy_initrd '/initramfs-linux-fallback.img' '/initramfs-linux-fallback.img'<br />
}<br />
}}<br />
<br />
<br />
* If you forgot to create a GRUB2 {{Filename|/boot/grub/grub.cfg}} configfile and simply rebooted into GRUB2 Command Shell, type:<br />
<br />
sh:grub> insmod legacycfg<br />
sh:grub> legacy_configfile ${prefix}/menu.lst<br />
<br />
Boot into Arch and re-create the proper GRUB2 {{Filename|/boot/grub/grub.cfg}} configfile.<br />
<br />
{{Note|This option works only in BIOS systems, not in UEFI systems.}}<br />
<br />
====== Install to Partition or Partitionless Disk ======<br />
<br />
{{Note|grub2-bios (any version - including upstream bzr repo) does not encourage installation to a partition boot sector or a partitionless disk like grub-legacy or syslinux does. Neither do the Arch devs.}}<br />
<br />
To setup grub2-bios to a partition boot sector, to a partitionless disk (also called superfloppy) or to a floppy disk, run (using for example /dev/sda1 as the /boot partition)<br />
<br />
# chattr -i /boot/grub/core.img<br />
# grub_bios-install --boot-directory=/boot --no-floppy --recheck --force /dev/sda1<br />
# chattr +i /boot/grub/core.img<br />
<br />
You need to use the {{Codeline|--force}} option to allow usage of blocklists and should not use <code>--grub-setup=/bin/true</code> (which is similar to simply generating core.img).<br />
<br />
grub_bios-install will give out warnings like which should give you the idea of what might go wrong with this approach.<br />
<br />
/sbin/grub-setup: warn: Attempting to install GRUB to a partitionless disk or to a partition. This is a BAD idea.<br />
/sbin/grub-setup: warn: Embedding is not possible. GRUB can only be installed in this setup by using blocklists. <br />
However, blocklists are UNRELIABLE and their use is discouraged.<br />
<br />
Without {{Codeline|--force}} you may get the below error and grub-setup will not setup its boot code in the partition boot sector.<br />
<br />
/sbin/grub-setup: error: will not proceed with blocklists<br />
<br />
With {{Codeline|--force}} you should get<br />
<br />
Installation finished. No error reported.<br />
<br />
The reason why grub-setup does not by default allow this is because in case of partition or a partitionless disk is that grub2-bios relies on embedded blocklists in the partition bootsector to locate the {{Filename|/boot/grub/core.img}} file and the prefix dir {{Filename|/boot/grub}} . The sector locations of {{Filename|core.img}} may change whenever the filesystem in the partition is being altered (files copied, deleted etc.). For more info see https://bugzilla.redhat.com/show_bug.cgi?id=728742 and https://bugzilla.redhat.com/show_bug.cgi?id=730915 .<br />
<br />
The workaround for this is to set the immutable flag on {{Filename|/boot/grub/core.img}} (using chattr command as mentioned above) so that the sector locations of the {{Filename|core.img}} file in the disk is not altered. The immutable flag on {{Filename|/boot/grub/core.img}} needs to be set only if grub2-bios is installed to a partition boot sector or a partitionless disk, not in case of installtion to MBR or simple generation of {{Filename|core.img}} without embedding any bootsector (mentioned above). <br />
<br />
====== Generate core.img alone ======<br />
<br />
To populate the {{Filename|/boot/grub}} directory and generate a {{Filename|/boot/grub/core.img}} file WITHOUT embedding any grub2-bios bootsector code in the MBR, post-MBR region, or the partition bootsector, add <code>--grub-setup=/bin/true</code> to grub_bios-install:<br />
<br />
# grub_bios-install --grub-setup=/bin/true --boot-directory=/boot --no-floppy --recheck /dev/sda<br />
<br />
You can then chainload grub2's core.img from grub-legacy or syslinux as a Linux kernel or a multiboot kernel.<br />
<br />
===== After grub_bios-install =====<br />
<br />
====== Generate GRUB2 BIOS Config file ======<br />
<br />
Finally, generate a configuration for grub2 (this is explained in greater detail in the Configuration section):<br />
<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
If grub2 complains about "no suitable mode found" while booting, go to [[#Correct_GRUB2_No_Suitable_Mode_Found_Error]] .<br />
<br />
===== Multiboot in BIOS =====<br />
<br />
====== Boot Microsoft Windows installed in BIOS-MBR mode ======<br />
<br />
{{Note|GRUB2 supports booting {{Filename|bootmgr}} directly and chainload of partition boot sector is no longer required to boot Windows in a BIOS-MBR setup.}}<br />
<br />
Find the UUID of the NTFS filesystem of the Windows's SYSTEM PARTITION where the bootmgr and its files reside. For example, if Windows {{Filename|bootmgr}} exists at {{Filename|/media/Windows/bootmgr}}:<br />
<br />
# grub-probe --target=fs_uuid /media/Windows/bootmgr<br />
69B235F6749E84CE<br />
<br />
Then, add the below code to {{Filename|/boot/grub/grub.cfg}} to chainload Windows (Vista, 7 or 8) installed in BIOS-MBR mode :<br />
<br />
menuentry "Microsoft Windows 7 BIOS-MBR" {<br />
insmod part_msdos<br />
insmod ntfs<br />
insmod search_fs_uuid<br />
insmod ntldr <br />
search --fs-uuid --no-floppy --set=root 69B235F6749E84CE<br />
ntldr (${root})/bootmgr<br />
}<br />
<br />
For Windows XP<br />
<br />
menuentry "Microsoft Windows XP" {<br />
insmod part_msdos<br />
insmod ntfs<br />
insmod search_fs_uuid<br />
insmod ntldr <br />
search --fs-uuid --no-floppy --set=root 69B235F6749E84CE<br />
ntldr (${root})/ntldr<br />
}<br />
<br />
==== [[UEFI]] systems ====<br />
<br />
===== Before grub_efi_${UEFI_ARCH}-install =====<br />
<br />
{{Note|Unless specified as EFI 1.x , EFI and UEFI terms are used interchangeably to denote UEFI 2.x firmware. Also unless stated explicitely, the instructions are general and not Mac specific. Some of them may not work or may be different in Macs. Apple's EFI implementation is neither a EFI 1.x version nor UEFI 2.x version but mixes up both. This kind of firmware does not fall under any one UEFI Specification version and is therefore not a standard UEFI firmware.}}<br />
<br />
GRUB2 UEFI bootloader is available in Arch Linux only from version 1.99~rc1 . To install, first [https://wiki.archlinux.org/index.php/Unified_Extensible_Firmware_Interface#Detecting_UEFI_Firmware_Arch Detect which UEFI firmware arch] you have (either x86_64 or i386).<br />
<br />
Depending on that, install the appropriate package<br />
<br />
For 64-bit aka x86_64 UEFI firmware:<br />
# pacman -S grub2-efi-x86_64<br />
<br />
For 32-bit aka i386 UEFI firmware:<br />
# pacman -S grub2-efi-i386<br />
<br />
{{Note|Installing grub2-common (a dependency of grub2-bios) 1.99~rc1 or later, may take forever in some systems since the post_install script runs grub-mkconfig and this script does not provide the option <code>--no-floppy</code>. For more details search this option in the article.}}<br />
<br />
{{Note|Simply installing the package won't update the grub.efi file and the grub2 modules in the UEFI System Partition . You need to update the grub.efi file and the grub2 modules in the UEFI System Partition manually using grub_efi_${UEFI_ARCH}-install as explained below.}}<br />
<br />
Also load the device-mapper kernel module without which grub-probe does not reliably detect disks and partitions<br />
<br />
# modprobe dm-mod<br />
<br />
===== Install to UEFI SYSTEM PARTITION =====<br />
<br />
====== Mount UEFI SYSTEM PARTITION ======<br />
<br />
Mount the [https://wiki.archlinux.org/index.php/Unified_Extensible_Firmware_Interface#Creating_a_UEFI_SYSTEM_PARTITION_in_Linux UEFI SYSTEM PARTITION] in your system at {{Filename|/boot/efi}}. It should be FAT32 formatted and should be at least 200 MiB in size. If you have mounted the UEFISYS partition in some other mountpoint, replace {{Filename|/boot/efi}} in the below commands with that mountpoint:<br />
<br />
# mkdir -p /boot/efi<br />
# mount -t vfat <UEFISYS_PART_DEVICE> /boot/efi<br />
# mkdir -p /boot/efi/efi<br />
<br />
====== Run grub_efi_${UEFI_ARCH}-install ======<br />
<br />
{{Note|The below commands assume you are using {{Codeline|grub2-efi-x86_64}} (for {{Codeline|grub2-efi-i386}} replace {{Codeline|x86_64}} with {{Codeline|i386}} in the below commands).}}<br />
<br />
# grub_efi_x86_64-install --root-directory=/boot/efi --boot-directory=/boot/efi/efi --bootloader-id=grub --no-floppy --recheck<br />
<br />
The {{Codeline|grub_efi_x86_64-install}} automatically generates a {{Filename|grub.efi}} while setting up the {{Filename|/boot/efi/efi/grub/}} directory.<br />
<br />
If you notice carefully, there is no <device_path> option (Eg: {{Filename|/dev/sda}}) at the end of the {{Codeline|grub_efi_x86_64-install}} command unlike the case of setting up grub2 for BIOS systems. Any <device_path> provided will be ignored by the install script as UEFI bootloaders do not use MBR or Partition boot sectors at all.<br />
<br />
You may now be able to UEFI boot your system by creating a grub.cfg file using grub-mkconfig and copying /boot/efi/efi/grub/grub.efi to /boot/efi/efi/boot/bootx64.efi.<br />
<br />
===== After grub_efi_${UEFI_ARCH}-install =====<br />
<br />
====== Launch GRUB2 as default in non-Mac UEFI systems ======<br />
<br />
{{Note|The below steps will not work if the system has been booted in BIOS mode and will not work if the UEFI processor architecture does not match the kernel one, i.e. x86_64 UEFI + ix86 32-bit Kernel and vice-versa config will not work.}}<br />
<br />
grub_efi_${UEFI_ARCH}-install will ensure {{Filename|/boot/efi/efi/grub/grub.efi}} is launched by default if it detects {{Codeline|efibootmgr}} and if it is able to access UEFI Runtime Services. {{Codeline|efibootmgr}} command will work only if you have booted the system in UEFI mode itself, since it '''requires access to UEFI Runtime Variables''' which are '''available only in UEFI boot mode''' (with "noefi" kernel parameter NOT being used). Initially the user is required to manually launch {{Filename|/boot/efi/efi/grub/grub.efi}} from the firmware itself (using maybe the UEFI Shell) if grub2-efi was installed in BIOS mode. Then {{Codeline|efibootmgr}} should be run to make grub2 as the default entry in the UEFI Boot Manager<br />
<br />
First boot into UEFI mode manually either using the firmware boot menu, UEFI shell, or using any UEFI capable bootable iso (Archboot or Ubuntu non-Mac iso). Use grub probe to determine the device path of your EFI System Partition:<br />
# grub-probe --target=device /boot/efi/efi/grub/grub.efi<br />
<br />
It should give something like {{Filename|/dev/sda1}} (used as example in the remaining steps). Load 'efivars' kernel module:<br />
# modprobe efivars<br />
<br />
If you get '''no such device found''' error for this command, that means you have not booted in UEFI mode or due to some reason the kernel is unable to access UEFI Runtime Variables.<br />
<br />
Verify whether there are files in ''/sys/firmware/efi/vars/'' directory. This directory and its contents are created by "efivars" kernel module and it will exist only if you have booted in UEFI mode without the "noefi" kernel parameter.<br />
<br />
# ls -1 /sys/firmware/efi/vars/<br />
<br />
Sample output (x86_64-UEFI 2.3.1 in x86_64 Kernel:<br />
<br />
# ls -1 /sys/firmware/efi/vars/<br />
Boot0000-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootCurrent-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootOptionSupport-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootOrder-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConIn-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConInDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConOut-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConOutDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ErrOutDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
Lang-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
LangCodes-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
MTC-eb704011-1402-11d3-8e77-00a0c969723b/<br />
MemoryTypeInformation-4c19049f-4137-4dd3-9c10-8b97a83ffdfa/<br />
PlatformLang-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
PlatformLangCodes-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
RTC-378d7b65-8da9-4773-b6e4-a47826a833e1/<br />
del_var<br />
new_var<br />
<br />
If ''/sys/firmware/efi/vars/'' directory is empty or does not exist, then {{Codeline|efibootmgr}} command will not work. If you are unable to make the ISO/CD/DVD/USB boot in UEFI mode try https://gitorious.org/tianocore_uefi_duet_builds/pages/Linux_Windows_BIOS_UEFI_boot_USB .<br />
<br />
If ''/sys/firmware/efi/vars/'' directory (along with the exists then run {{Codeline|efibootmgr}} and reboot:<br />
<br />
# efibootmgr --create --gpt --disk /dev/sda --part 1 --write-signature --label "GRUB2" --loader "\\EFI\\grub\\grub.efi"<br />
<br />
In the above command, {{Filename|/boot/efi/efi/grub/grub/efi}} can be split up as {{Filename|/boot/efi}} and {{Filename|/efi/grub/grub.efi}}, which translates to {{Filename|(/dev/sda)}} -> partition 1 -> {{Filename|\\EFI\\grub\\grub.efi}}. <br />
<br />
FAT32 filesystem is case-insensitive since it does not use UTF-8 encoding by default. In that case the firmware uses capital 'EFI' instead of small 'efi', therefore using {{Filename|\\EFI\\grub\\grub.efi}} or {{Filename|\\efi\\grub\\grub.efi}} does not matter (this will change if the filesystem encoding is UTF-8). UEFI uses backward slash as path separatoir (similar to Windows paths). In the above command "double" backward slashes are used instead of single ones, since a backward slash is used as a escape character by sh shells, the first backward slash escapes the second one so that the path {{Filename|\EFI\grub\grub.efi}} is passed to {{Codeline|efibootmgr}}.<br />
<br />
The 'label' is the name of the menu entry shown in the UEFI boot menu. This name is user's choice and does not affect the booting of the system. More info can be obtained from [http://linux.dell.com/cgi-bin/gitweb/gitweb.cgi?p=efibootmgr.git;a=blob_plain;f=README;hb=HEAD efibootmgr GIT README]<br />
<br />
If you have problems running GRUB2 in UEFI mode you can try the following (worked on an ASUS Z68 mainboard):<br />
<br />
# cp /boot/efi/efi/grub/grub.efi /boot/efi/shellx64.efi<br />
<br />
or<br />
<br />
# cp /boot/efi/efi/grub/grub.efi /boot/efi/efi/shellx64.efi<br />
or<br />
<br />
# cp /boot/efi/efi/grub/grub.efi /boot/efi/efi/shell/shellx64.efi<br />
<br />
After this launch the UEFI Shell from the UEFI setup/menu (in ASUS UEFI BIOS, switch to advanced mode, press Exit in the top right corner and choose "Launch EFI shell from filesystem device"). The grub2 menu will show up and you can boot into your system. Afterwards you can use efibootmgr to setup a menu entry (see above).<br />
<br />
====== Launch GRUB2 as default in Apple Mac EFI systems ======<br />
<br />
{{Note|Using {{Filename|efibootmgr}} in Apple Macs will brick the firmware and may need reflash of the motherboard ROM. There have been bug reports regarding this in Ubuntu/Launchpad bug tracker. Use bless command alone in case of Macs}}<br />
<br />
Use bless command from within Mac OS X to setup {{Filename|grub.efi}} as the default boot option. More info at https://help.ubuntu.com/community/UEFIBooting#Apple_Mac_EFI_systems_.28both_EFI_architecture.29 .<br />
<br />
====== Generate GRUB2 UEFI Config file ======<br />
<br />
Finally, generate a configuration for grub2 (this is explained in greater detail in the Configuration section):<br />
<br />
# grub-mkconfig -o /boot/efi/efi/grub/grub.cfg<br />
<br />
If grub2-uefi complains about "no suitable mode found" while booting, go to [[#Correct_GRUB2_No_Suitable_Mode_Found_Error]] .<br />
<br />
===== Generate a custom GRUB2 UEFI Application =====<br />
<br />
If you want, you can create a custom {{Filename|grub_custom.efi}} app using:<br />
# grub-mkimage -d /usr/lib/grub/x86_64-efi -O x86_64-efi -p "" -o /boot/efi/efi/grub/grub_custom.efi <GRUB2_Modules_to_be_included><br />
<br />
{{Note|The '''-p''' option is important for creating a portable {{Filename|grub_custom.efi}} app.}}<br />
<br />
There is no file-size restriction on {{Filename|grub_custom.efi}} either due to GRUB2 or due to the UEFI firmware. Therefore you can include any number of modules you want.<br />
<br />
A "{{Filename|grub.cfg}}" created for BIOS based GRUB2 will be sufficient for the UEFI GRUB2 as long as all the paths in the config are absolute paths. The {{Filename|grub.cfg}} file should exist in the same directory as {{Filename|grub.efi}} or {{Filename|grub_custom.efi}}.<br />
<br />
The {{Filename|grub.efi}} UEFI application can be launched using the firmware's "Boot Manager", "Boot from file" option or using the [https://wiki.archlinux.org/index.php/UEFI#UEFI_Shell UEFI Shell].<br />
<br />
Alternatively, you can also setup {{Filename|/boot/efi/efi/grub}} directory by copying all the files in {{Filename|/usr/lib/grub/x86_64-efi}} to {{Filename|/boot/efi/efi/grub}} and using the above grub-mkimage command to create a {{Filename|grub_custom.efi}} application. Just make sure you have the required modules embedded in {{Filename|grub_custom.efi}} to enable it to access the EFI SYSTEM PARTITION.<br />
<br />
A basic {{Filename|grub_custom.efi}} can be generated using the following command:<br />
# sudo grub-mkimage -d /usr/lib/grub/x86_64-efi -O x86_64-efi -p "" -o /boot/efi/efi/grub/grub_custom.efi part_gpt fat iso9660 udf normal chain linux \<br />
ls search search_fs_file search_fs_uuid search_label help boot configfile echo efi_gop<br />
<br />
===== Multiboot in UEFI =====<br />
<br />
====== Chainload Microsoft Windows x86_64 UEFI-GPT ======<br />
<br />
Find the UUID of the FAT32 filesystem in the UEFI SYSTEM PARTITION where the Windows UEFI Bootloader files reside. For example, if Windows {{Filename|bootmgfw.efi}} exists at {{Filename|/boot/efi/efi/Microsoft/Boot/bootmgfw.efi}} (ignore the upper-lower case differences since that is immaterial in FAT filesystem):<br />
<br />
# grub-probe --target=fs_uuid /boot/efi/efi/Microsoft/Boot/bootmgfw.efi<br />
1ce5-7f28<br />
<br />
Then, add this code to {{Filename|/boot/efi/efi/grub/grub.cfg}} to chainload Windows x86_64 (Vista SP1+, 7 or 8) installed in UEFI-GPT mode :<br />
<br />
menuentry "Microsoft Windows x86_64 UEFI-GPT" {<br />
insmod part_gpt<br />
insmod fat<br />
insmod search_fs_uuid<br />
insmod chain<br />
search --fs-uuid --no-floppy --set=root 1ce5-7f28<br />
chainloader (${root})/efi/Microsoft/Boot/bootmgfw.efi<br />
}<br />
<br />
== Manual Compilation ==<br />
<br />
=== For BIOS Systems ===<br />
<br />
GRUB2 for BIOS systems should be compiled as follows:<br />
<pre><br />
./autogen.sh<br />
<br />
./configure --with-platform=pc --prefix=/usr<br />
<br />
make<br />
<br />
make install<br />
</pre><br />
<br />
The <code>--with-platform=pc</code> generates grub2 for bios alone irrespective of the firmware of the build system.<br />
<br />
=== For UEFI Systems ===<br />
<br />
First [https://wiki.archlinux.org/index.php/Unified_Extensible_Firmware_Interface#Detecting_UEFI_Firmware_Arch Detect which UEFI Firmware arch] you have and then follow the compile instructions below:<br />
<pre><br />
./autogen.sh<br />
<br />
./configure --with-platform=efi --target=TARGET_UEFI_ARCH --prefix=/usr<br />
<br />
make<br />
<br />
make install<br />
</pre><br />
<br />
The "--target" option denotes the UEFI firmware arch. for which grub2 should be compiled, not the architecture of the linux kernel grub2 may boot. <br />
<br />
It is possible to use UEFI 64-bit firmware + GRUB2 as x86_64-EFI app loading a i686 linux kernel, as long as the kernel does not try to access UEFI Runtime Services. Vice-versa situation is also possible. But a x86_64 UEFI firmware cannot launch GRUB2 i386-efi app (unlike x86_64 Operating Systems), and a i386 UEFI firmware will not launch GRUB2 {{Codeline|x86_64-efi}} app. It is important to compile GRUB2 to match the architecture of the UEFI firmware.<br />
<br />
== Configuration ==<br />
<br />
The configuration files are {{Filename|/etc/default/grub}} and {{Filename|/etc/grub.d/*}}. These files are used to generate the {{Filename|/boot/grub/grub.cfg}} file. You can also choose to manually edit {{Filename|grub.cfg}}.<br />
<br />
=== grub-mkconfig ===<br />
<br />
The grub-mkconfig script can be used to generate a {{Filename|grub.cfg}} file. By default the script outputs to stdout. Note that gettext ― an optional dependency of the GRUB2 package ― is required by the grub-mkconfig script. To generate a {{Filename|grub.cfg}} file run the command:<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
Note that grub-mkconfig probably has your grub directory hardcoded to /boot/grub, which is probably wrong if you're using UEFI. Either mount your efi grub directory at /boot/grub or edit the script.<br />
<br />
=== grub.cfg ===<br />
<br />
A basic grub file uses the following options<br />
* {{Codeline|(hdX,Y)}} is the partition {{Codeline|Y}} on disk {{Codeline|X}}, partition numbers starting at 1, disk numbers starting at 0<br />
* {{Codeline|1=set default=N}} is the default boot entry that is chosen after timeout for user action<br />
* {{Codeline|1=set timeout=M}} is the time {{Codeline|M}} to wait in seconds for a user selection before default is booted<br />
* {{Codeline|<nowiki>menuentry "title" {entry options}</nowiki>}} is a boot entry titled {{Codeline|title}}<br />
* {{Codeline|1=set root=(hdX,Y)}} sets the boot partition, where the kernel and GRUB modules are stored (boot need not be a separate partition, and may simply be a directory under the "root" partition ({{Filename|/}})<br />
<br />
An example configuration:<br />
<br />
{{File<br />
|name=/boot/grub/grub.cfg<br />
|content=<nowiki><br />
# Config file for GRUB2 - The GNU GRand Unified Bootloader<br />
# /boot/grub/grub.cfg<br />
<br />
# DEVICE NAME CONVERSIONS<br />
#<br />
# Linux Grub<br />
# -------------------------<br />
# /dev/fd0 (fd0)<br />
# /dev/sda (hd0)<br />
# /dev/sdb2 (hd1,2)<br />
# /dev/sda3 (hd0,3)<br />
#<br />
<br />
# Timeout for menu<br />
set timeout=5<br />
<br />
# Set default boot entry as Entry 0<br />
set default=0<br />
<br />
# (0) Arch Linux<br />
menuentry "Arch Linux" {<br />
set root=(hd0,1)<br />
linux /vmlinuz-linux root=/dev/sda3 ro<br />
initrd /initramfs-linux.img<br />
}<br />
<br />
## (1) Windows<br />
#menuentry "Windows" {<br />
#set root=(hd0,3)<br />
#chainloader +1<br />
#}<br />
</nowiki>}}<br />
<br />
=== Dual-booting ===<br />
<br />
''NOTE: If you want GRUB2 to automatically search for other systems, for example as in Ubuntu. Then you may need to download {{Package AUR|os-prober}} from the [[AUR]].''<br />
<br />
==== Using grub-mkconfig ====<br />
The best way to add other entries is editing the {{Filename|/etc/grub.d/40_custom}}. The entries in this file will be automatically added when running '''grub-mkconfig'''.<br />
After adding the new lines, run:<br />
# grub-mkconfig -o /boot/grub/grub.cfg <br />
to generate an updated {{Filename|grub.cfg}}.<br />
<br />
===== With GNU/Linux =====<br />
<br />
Assuming that the other distro is on partition {{Filename|sda2}}:<br />
<br />
menuentry "Other Linux" {<br />
set root=(hd0,2)<br />
linux /boot/vmlinuz (add other options here as required)<br />
initrd /boot/initrd.img (if the other kernel uses/needs one)<br />
}<br />
<br />
===== With Windows =====<br />
<br />
This assumes that your Windows partition is {{Filename|sda3}}.<br />
<br />
# (2) Windows XP<br />
menuentry "Windows XP" {<br />
set root=(hd0,3)<br />
chainloader (hd0,3)+1<br />
}<br />
<br />
If the windows bootloader is on an entirely different harddrive than grub, it may be necessary to trick Windows into believing that it is in fact the first harddrive. This was possible in the old grub with {{Codeline|map}} and is now done with {{Codeline|drivemap}}. Assume grub is on {{Filename|hd0}} and windows on {{Filename|hd2}}, you need to add the following after {{Codeline|set root}}:<br />
<br />
drivemap -s hd0 hd2<br />
<br />
==== With Windows via EasyBCD and NeoGRUB ====<br />
<br />
Since EasyBCD's NeoGRUB currently does not understand the GRUB2 menu format, chainload to it by replacing the contents of your {{Filename|C:\NST\menu.lst}} file with lines similar to the following:<br />
<br />
default 0<br />
timeout 1<br />
<br />
title Chainload into GRUB v2<br />
root (hd0,7)<br />
kernel /boot/grub/core.img<br />
<br />
===Visual Configuration===<br />
<br />
In GRUB2 it is possible, by default, to change the look of the menu.<br />
<br />
====Background image and bitmap fonts====<br />
<br />
GRUB2 comes with support for background images and bitmap fonts in pf2 format. The unifont font is included in the grub2 package under the filename {{Filename|unicode.pf2}}, or, as only ascii characters under the name {{Filename|ascii.pf2}}. Image formats supported include tga, png and jpeg, providing the correct modules are loaded. The maximum supported resolution depends on your hardware. There are two ways of setting a {{Filename|tga}} file as background. Two sample configurations are shown below.<br />
<br />
Edit {{Filename|/etc/default/grub}} like this:<br />
GRUB_GFXMODE=1024x768x32<br />
GRUB_GFXPAYLOAD_LINUX=keep<br />
GRUB_BACKGROUND="/boot/grub/archlinux.tga"<br />
#GRUB_THEME="/path/to/gfxtheme"<br />
<br />
(archlinux.tga is a placeholder; put your file name there)<br />
<br />
To generate the changes, run: <br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
{{Note|If this example does not work for you try to replace {{Codeline|1=gfxmode="1024x768x32"}} by {{Codeline|1=vbemode="0x105"}}.}}<br />
{{Note|To show all the modes you can use {{Codeline|1=# hwinfo --framebuffer}} (hwinfo is available in [community]), while at grub2 prompt you can use the {{Codeline|1=vbeinfo}} command.}}<br />
{{Note|If you have installed Grub on a separate partition, {{Filename|/boot/grub/archlinux.tga}} becomes {{Filename|/grub/archlinux.tga}}.}}<br />
<br />
====Menu colors====<br />
<br />
As in Grub (0.9x), you can change the menu colors in Grub2. The available colors for GRUB2 are at http://www.gnu.org/software/grub/manual/html_node/Theme-file-format.html#Theme-file-format . <br />
Here is an example:<br />
<br />
Edit {{Filename|/etc/default/grub}}:<br />
GRUB_COLOR_NORMAL="light-blue/black"<br />
GRUB_COLOR_HIGHLIGHT="light-cyan/blue"<br />
<br />
Generate the changes:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
====Hidden menu====<br />
<br />
One of the unique features of Grub2 is hiding/skipping the menu and showing it by holding "Shift" when needed. You can also adjust whether you want to see the timeout counter.<br />
<br />
Edit {{Filename|/etc/default/grub}} as you wish. Here is an example where the comments from the beginning of the two lines have been removed to enable the feature, the timeout has been set to five seconds and to be shown to the user:<br />
GRUB_HIDDEN_TIMEOUT=5<br />
GRUB_HIDDEN_TIMEOUT_QUIET=false<br />
<br />
and run:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
====Setting the framebuffer resolution ====<br />
<br />
Grub2 can set the framebuffer for both grub2 itself and the kernel. The old ''vga='' way is deprecated. The preferred method is editing {{Filename|/etc/default/grub}} as the following sample:<br />
<br />
GRUB_GFXMODE=1024x768x32<br />
GRUB_GFXPAYLOAD_LINUX=keep<br />
<br />
To generate the changes, run: <br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
The {{Codeline|gfxpayload}} property will make sure the kernel keeps the resolution.<br />
<br />
If this method does not work for you, the deprecated <code>vga=</code> method will still work. Just<br />
add it next to the <code>"GRUB_CMDLINE_LINUX_DEFAULT="</code> line in {{Filename|/etc/default/grub}}<br />
for eg: <code>"GRUB_CMDLINE_LINUX_DEFAULT="quiet splash vga=792"</code> will give you a {{Codeline|1024x768}} resolution.<br />
<br />
You can choose one of these resolutions: {{Codeline|640×480}}, {{Codeline|800×600}}, {{Codeline|1024×768}}, {{Codeline|1280×1024}}, {{Codeline|1600×1200}}<br />
<br />
=== Other Options ===<br />
<br />
==== LVM ====<br />
<br />
If you use [[LVM]] for your {{Filename|/boot}}, add the following before menuentry lines:<br />
<br />
insmod lvm<br />
<br />
and specify your root in the menuentry as:<br />
<br />
set root=(''lvm_group_name''-''lvm_logical_boot_partition_name'')<br />
<br />
Example:<br />
<br />
# (0) Arch Linux<br />
menuentry "Arch Linux" {<br />
insmod lvm<br />
set root=(VolumeGroup-lv_boot)<br />
# you can only set following two lines<br />
linux /vmlinuz-linux root=/dev/mapper/VolumeGroup-root ro<br />
initrd /initramfs-linux.img<br />
}<br />
<br />
==== Raid ====<br />
<br />
Grub2 provides convenient handling of raid-volumes. You need to add:<br />
insmod raid<br />
<br />
which allows you to address the volume natively. E.g. {{Filename|/dev/md0}} becomes:<br />
set root=(md0)<br />
<br />
whereas a partitioned raid-volume (e.g. {{Filename|/dev/md0p1}}) becomes:<br />
set root=(md0,1)<br />
<br />
==== Persistent block device naming ====<br />
You can use UUIDs to detect partitions instead of the "old" {{Filename|/dev/sd*}} and {{Filename|/dev/hd*}} scheming. It has the advantage of detecting partitions by their unique UUIDs, which is needed by some people booting with complicated partition setups.<br />
<br />
UUIDs are used by default in the recent versions of grub2 - there is no downside in it anyway except that you need to re-generate the {{Filename|grub.cfg}} file every time you resize or reformat your partitions. Remember this when modifying partitions with Live-CD.<br />
<br />
The recent versions of grub2 use UUIDs by default. You can re-enable the use of UUIDS by simply commenting the UUID line (this is also what it looks like by default):<br />
#GRUB_DISABLE_LINUX_UUID=true<br />
you can also just set the value as {{Codeline|false}} as shown here:<br />
GRUB_DISABLE_LINUX_UUID=false<br />
<br />
Either way, do not forget to generate the changes:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
==== Using Labels ====<br />
<br />
It is possible to use labels, human-readable strings attached to filesystems, by using the {{Codeline|--label}} option to {{Codeline|search}}. First of all, label your existing partition:<br />
# tune2fs -L a <LABEL> <PARTITION><br />
<br />
Then, add an entry using labels. An example of this:<br />
<br />
menuentry "Arch Linux, session texte" {<br />
search --label --no-floppy --set=root archroot<br />
linux /boot/vmlinuz-linux root=/dev/disk/by-label/archroot ro<br />
initrd /boot/initramfs-linux.img<br />
}<br />
<br />
==== Recall previous entry ====<br />
<br />
Grub2 can remember the last entry you booted from and use this as the default entry to boot from next time. This is useful if you have multiple kernels (i.e., the current Arch one and the LTS kernel as a fallback option) or operating systems. To do this, edit {{Filename|/etc/default/grub}} and change the setting of {{Codeline|GRUB_DEFAULT}}:<br />
<br />
GRUB_DEFAULT=saved<br />
<br />
This ensures that grub will default to the saved entry. To enable saving the selected entry, add the following line to {{Filename|/etc/default/grub}}:<br />
<br />
GRUB_SAVEDEFAULT=true<br />
<br />
Remember to regenerate your configuration file.<br />
<br />
==== Security ====<br />
<br />
If you want to secure GRUB2 so it is not possible for anyone to change boot parameters or use the command line, you can add a user/password combination to GRUB2's configuration files. To do this, run the command {{Codeline|grub-mkpasswd_pbkdf2}}. Enter a password and confirm it. The output will look like this:<br />
<br />
<pre style='overflow:auto'><br />
Your PBKDF2 is grub.pbkdf2.sha512.10000.C8ABD3E93C4DFC83138B0C7A3D719BC650E6234310DA069E6FDB0DD4156313DA3D0D9BFFC2846C21D5A2DDA515114CF6378F8A064C94198D0618E70D23717E82.509BFA8A4217EAD0B33C87432524C0B6B64B34FBAD22D3E6E6874D9B101996C5F98AB1746FE7C7199147ECF4ABD8661C222EEEDB7D14A843261FFF2C07B1269A</pre>Then, add the following to {{Filename|/etc/grub.d/00_header}}:<br />
<pre>cat << EOF<br />
<br />
set superusers="username"<br />
password_pbkdf2 username <password><br />
<br />
EOF</pre><br />
where <password> is the string generated by {{Codeline|grub-mkpasswd_pbkdf2}}.<br />
<br />
Regenerate your configuration file. Your GRUB2 command line and boot parameters are now protected.<br />
<br />
=== Booting an Ubuntu ISO Image from the GRUB2 Screen ===<br />
<br />
Edit {{Filename|/etc/grub.d/40_custom}} to add an entry pointing to an Ubuntu iso:<br />
<br />
menuentry "ubuntu-11.04-desktop-amd64.iso" {<br />
set isofile="/path/to/ubuntu-11.04-desktop-amd64.iso"<br />
loopback loop (hdX,Y)$isofile<br />
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile quiet noeject noprompt splash --<br />
initrd (loop)/casper/initrd.lz<br />
}<br />
<br />
Be sure to adjust the "hdX,Y" in the third line to point to the correct disk/partition number of the isofile. When finished, update grub2's configuration file via:<br />
<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
== Using the command shell ==<br />
<br />
Since the MBR is too small to store all GRUB2 modules, only the menu and a few basic commands reside there. The majority of GRUB2 functionality remains in modules in {{Filename|/boot/grub}}, which are inserted as needed. In error conditions (e.g. if the partition layout changes) GRUB2 may fail to boot. When this happens, a command shell may appear.<br />
<br />
GRUB2 offers multiple shells/prompts. If there is a problem reading the menu but the bootloader is able to find the disk, you will likely be dropped to the "normal" shell:<br />
sh:grub><br />
<br />
If there is a more serious problem (e.g. GRUB cannot find required files), you may instead be dropped to the "rescue" shell:<br />
grub rescue><br />
<br />
The rescue shell is a restricted subset of the normal shell, offering much less functionality. If dumped to the rescue shell, first try inserting the "normal" module, then starting the "normal" shell:<br />
grub rescue> set prefix=(hdX,Y)/boot/grub<br />
grub rescue> insmod (hdX,Y)/boot/grub/normal.mod<br />
rescue:grub> normal<br />
<br />
=== Pager support ===<br />
<br />
GRUB2 supports pager for reading commands that provide long output (like the help command). This works only in normal shell mode and not in rescue mode. To enable pager, in GRUB2 command shell type:<br />
sh:grub> set pager=1<br />
<br />
== GUI configuration tools ==<br />
<br />
Following package may be installed from [[AUR]]<br />
* [http://kde-apps.org/content/show.php?content=139643 grub2-editor] (requires kdelibs)<br />
*:A KDE4 control module for configuring the GRUB2 bootloader<br />
* [http://kde-apps.org/content/show.php?content=137886 kcm-grub2] (requires kdelibs python2-qt kdebindings-python)<br />
*:This Kcm module manages the most common settings of Grub2.<br />
* [http://sourceforge.net/projects/startup-manager/ startupmanager] (requires gnome-python imagemagick yelp python2 xorg-xrandr)<br />
*:GUI app for changing the settings of GRUB, GRUB2, Usplash and Splashy<br />
<br />
== parttool or legacy hide/unhide ==<br />
<br />
If you have a win9x paradigm with hidden C disks GRUB legacy had the hide/unhide feature. In GRUB2 this has been replaced by parttool. For example, to boot the third C disk of three win9x installations on the CLI enter the CLI and:<br />
parttool hd0,1 hidden+ boot-<br />
parttool hd0,2 hidden+ boot-<br />
parttool hd0,3 hidden- boot+<br />
set root=hd0,3<br />
chainloader +1<br />
boot<br />
<br />
== Using the rescue console ==<br />
<br />
See [[#Using the command shell]] first. If unable to activate the standard shell, one possible solution is to boot using a live CD or some other rescue disk to correct configuration errors and reinstall GRUB. However, such a boot disk is not always available (nor necessary); the rescue console is surprisingly robust.<br />
<br />
The available commands in GRUB rescue include "insmod", "ls", "set", and "unset". This example uses "set" and "insmod". "set" modifies variables and "insmod" inserts new modules to add functionality.<br />
<br />
Before starting, the user must know the location of their {{Filename|/boot}} partition (be it a separate partition, or a subdirectory under their root):<br />
grub rescue> set prefix=(hdX,Y)/boot/grub<br />
<br />
where X is the physical drive number and Y is the partition number.<br />
<br />
To expand console capabilities, insert the "linux" module:<br />
grub rescue> insmod (hdX,Y)/boot/grub/linux.mod<br />
<br />
{{Note|With a separate boot partition, omit {{Filename|/boot}} from the path, (i.e. type {{Codeline|1=set prefix=(hdX,Y)/grub}} and {{Codeline|insmod (hdX,Y)/grub/linux.mod}}).}}<br />
<br />
This introduces the "linux" and "initrd" commands, which should be familiar (see [[#Configuration]]).<br />
<br />
An example, booting Arch Linux:<br />
set root=(hd0,5)<br />
linux /boot/vmlinuz-linux root=/dev/sda5<br />
initrd /boot/initramfs-linux.img<br />
boot<br />
<br />
With a separate boot partition, again change the lines accordingly:<br />
set root=(hd0,5)<br />
linux /vmlinuz-linux root=/dev/sda6<br />
initrd /initramfs-linux.img<br />
boot<br />
<br />
After successfully booting the Arch Linux installation, users can correct {{Filename|grub.cfg}} as needed and then run:<br />
# grub-install /dev/sda --no-floppy<br />
<br />
to reinstall GRUB2 and fix the problem completely, changing {{Filename|/dev/sda}} if needed. See [[#Bootloader installation]] for details.<br />
<br />
== Combining the use of UUID's and basic scripting ==<br />
<br />
If you like the idea of using UUID's to avoid unreliable BIOS mappings or are struggling with Grub's syntax, here is an example boot menu item that uses UUID's and a small script to direct Grub to the proper disk partitions for your system. All you need to do is replace the UUID's in the sample with the correct UUID's for your system. (The example applies to a system with a boot and root partition. You will obviously need to modify the Grub configuration if you have additional partitions.)<br />
<br />
menuentry "Arch Linux 64" {<br />
#Enter the UUID of your boot partition (this is where Grub and your kernel reside)<br />
set uuid_grub_boot=ece0448f-bb08-486d-9864-ac3271bd8d07<br />
<br />
#Enter the UUID of the partition containing the root partition of your Arch Linux installation. <br />
set uuid_os_root=c55da16f-e2af-4603-9e0b-03f5f565ec4a<br />
<br />
#(Note: this may be the same as your boot partition)<br />
<br />
#Here we set the Grub "root" variable by locating the UUID of the root partition identified above <br />
search --fs-uuid --no-floppy --set=root $uuid_os_root<br />
<br />
#Here we set a custom variable grub_boot by locating the UUID of the boot partition identified above <br />
search --fs-uuid --no-floppy --set=grub_boot $uuid_grub_boot<br />
<br />
#Here is the magic. We test to see if the boot and root partitions have the same UUID.<br />
#If they do, we append /boot to the $grub_boot variable. For ex. (hd0,1) becomes (hd0,1)/boot.<br />
if [ $uuid_grub_boot == $uuid_os_root ] ; then<br />
set grub_boot=$grub_boot/boot<br />
fi<br />
<br />
# $grub_boot now points to the correct location, so the following will properly find the kernel and initrd<br />
linux ($grub_boot)/vmlinuz-linux root=/dev/disk/by-uuid/$uuid_os_root ro<br />
initrd ($grub_boot)/initramfs-linux.img<br />
}<br />
<br />
== Troubleshooting ==<br />
<br />
Any troubleshooting should be added here.<br />
<br />
=== Enable GRUB2 debug messages ===<br />
<br />
Add<br />
<br />
set pager=1<br />
set debug=all<br />
<br />
to {{Filename|grub.cfg}}.<br />
<br />
=== Correct GRUB2 No Suitable Mode Found Error ===<br />
<br />
If you get this error when booting any menuentry<br />
<br />
error: no suitable mode found<br />
Booting however<br />
<br />
Then you need to initialize grub2 graphical terminal (gfxterm) with proper video mode (gfxmode) in grub2. This video mode is passed by grub2 to the linux kernel via 'gfxpayload'. In case of UEFI systems, if the grub2 video mode is not initialized, no kernel boot messages will be shown in the terminal (atleast until KMS kicks in)<br />
<br />
Copy {{Filename|/usr/share/grub/unicode.pf2}} to ${GRUB2_PREFIX_DIR} ({{Filename|/boot/grub/}} in case of BIOS systems and {{Filename|/boot/efi/efi/grub/}} in case of UEFI systems). <br />
<br />
# cp /usr/share/grub/unicode.pf2 ${GRUB2_PREFIX_DIR}<br />
<br />
If {{Filename|/usr/share/grub/unicode.pf2}} does not exist, install {{Package Official|bdf-unifont}}, create the unifont.pf2 file and then copy it to ${GRUB2_PREFIX_DIR} .<br />
<br />
# grub-mkfont -o unicode.pf2 /usr/share/fonts/misc/unifont.bdf<br />
<br />
Then, in the {{Filename|grub.cfg}} file, add the following lines to enable grub2 to pass the video mode correctly to the kernel, without of which you will only get a black screen (no output) but booting (actually) proceeds successfully without any system hang:<br />
<br />
BIOS systems<br />
<br />
insmod vbe<br />
<br />
UEFI systems<br />
<br />
insmod efi_gop<br />
insmod efi_uga<br />
<br />
After that add the following code (common to both BIOS and UEFI)<br />
<br />
insmod font<br />
<br />
if loadfont ${prefix}/unicode.pf2<br />
then<br />
insmod gfxterm<br />
set gfxmode=auto<br />
set gfxpayload=keep<br />
terminal_output gfxterm<br />
fi<br />
<br />
As you can see for gfxterm (graphical terminal) to function properly, {{Filename|unicode.pf2}} font file should exist in ${GRUB2_PREFIX_DIR}.<br />
<br />
=== msdos-style error message ===<br />
<br />
grub-setup: warn: This msdos-style partition label has no post-MBR gap; embedding won't be possible!<br />
grub-setup: warn: Embedding is not possible. GRUB can only be installed in this setup by using blocklists.<br />
However, blocklists are UNRELIABLE and its use is discouraged.<br />
grub-setup: error: If you really want blocklists, use --force.<br />
<br />
This error may occur when you try installing GRUB2 in a VMware container. Read more about it [http://bbs.archlinux.org/viewtopic.php?pid=581760#p581760 here]. It happens when the first partition starts just after the MBR (block 63), without the usual space of 1 MiB (2048 blocks) before the first partition. Read [[#MBR_aka_msdos_partitioning_specific_instructions]]<br />
<br />
=== UEFI GRUB2 not loaded ===<br />
In some cases the EFI may fail to load grub correctly. Provided everything is set up correctly, the output of<br />
efibootmgr -v<br />
might look something like this:<br />
BootCurrent: 0000<br />
Timeout: 3 seconds<br />
BootOrder: 0000,0001,0002<br />
Boot0000* Grub HD(1,800,32000,23532fbb-1bfa-4e46-851a-b494bfe9478c)File(\efi\grub\grub.efi)<br />
Boot0001* Shell HD(1,800,32000,23532fbb-1bfa-4e46-851a-b494bfe9478c)File(\EfiShell.efi)<br />
Boot0002* Festplatte BIOS(2,0,00)P0: SAMSUNG HD204UI .<br />
If everything works correctly, the EFI would now automatically load grub.<br><br />
If the screen only goes black for a second and the next boot option is tried afterwards, according to [https://bbs.archlinux.org/viewtopic.php?pid=981560#p981560 this post], moving grub to the partition root can help. The boot option has to be deleted and recreated afterwards. The entry for grub should look like this then:<br />
Boot0000* Grub HD(1,800,32000,23532fbb-1bfa-4e46-851a-b494bfe9478c)File(\grub.efi)<br />
<br />
=== Invalid signature ===<br />
If trying to boot windows results in an "invalid signature" error, e.g. after reconfiguring partitions or adding additional hard drives, (re)move grub's device configuration and let it reconfigure.<br />
# mv /boot/grub/device.map /boot/grub/device.map-old<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
Grub-mkconfig should now mention all found boot options including windows. If it works, remove /boot/grub/device.map-old.<br />
<br />
== References ==<br />
<br />
# Official GRUB2 Manual - http://www.gnu.org/software/grub/manual/grub.html<br />
# GRUB2 wiki page describing steps to compile for UEFI systems - https://help.ubuntu.com/community/UEFIBooting - previously http://grub.enbug.org/TestingOnUEFI{{Linkrot|2011|09|05}}<br />
# Wikipedia's page on [http://en.wikipedia.org/wiki/BIOS_Boot_partition BIOS Boot Partition]<br />
<br />
== External Links ==<br />
<br />
# [https://github.com/the-ridikulus-rat/My_Shell_Scripts/blob/master/grub2/grub2_bios.sh A Linux Bash Shell script to compile and install GRUB2 for BIOS from BZR Source]<br />
# [https://github.com/the-ridikulus-rat/My_Shell_Scripts/blob/master/grub2/grub2_uefi.sh A Linux Bash Shell script to compile and install GRUB2 for UEFI from BZR Source]</div>Mayweedhttps://wiki.archlinux.org/index.php?title=GRUB&diff=167961GRUB2011-10-29T17:31:22Z<p>Mayweed: </p>
<hr />
<div>[[Category:Boot loaders (English)]]<br />
{{i18n|GRUB2}}<br />
[[fr:GRUB2]]<br />
{{Article summary start}}<br />
{{Article summary text|Covers various aspects of the next generation of the GRand Unified Bootloader (GRUB2).}}<br />
{{Article summary heading|Overview}}<br />
{{Article summary text|{{Boot process overview}}}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|Burg}} - Burg is a brand-new boot loader based on GRUB2. It uses a new object format which allows it to be built in a wider range of OS, including Linux/Windows/OSX/Solaris/FreeBSD, etc. It also has a highly configurable menu system which works in both text and graphic mode. <br />
{{Article summary heading|Resources}}<br />
{{Article summary link|GNU GRUB -- GNU Project|http://www.gnu.org/software/grub/}}<br />
{{Article summary link|GNU GRUB Wiki|http://grub.enbug.org/}}{{Linkrot|2011|09|05}}<br />
{{Article summary end}}<br />
<br />
[http://www.gnu.org/software/grub/ GRUB2] is the next generation of the GRand Unified Bootloader (GRUB). GRUB2 is derived from [http://www.nongnu.org/pupa/ PUPA] which was a research project to investigate the next generation of GRUB. GRUB 2 has been rewritten from scratch to clean up everything and provide modularity and portability [http://www.gnu.org/software/grub/grub-faq.en.html#q1].<br />
<br />
Briefly, the ''bootloader'' is the first software program that runs when a computer starts. It is responsible for loading and transferring control to the Linux kernel. The kernel, in turn, initializes the rest of the operating system.<br />
<br />
== Preface ==<br />
<br />
Although, [[GRUB]] (i.e. version 0.9x) is the de facto standard bootloader of Linux, it is considered 'legacy' by upstream. It is being replaced by GRUB2 in many distributions. Upstream recommends GRUB2 >=1.99~rc2 over grub-legacy, even for current grub-legacy users.<br />
<br />
{{Note|grub2 from 1.99~rc2 and later supports btrfs as root (without a separate /boot filesystem).}}<br />
<br />
=== Notes for current GRUB users ===<br />
<br />
* There are differences in the commands of GRUB and GRUB2. Familiarize yourself with [http://www.gnu.org/software/grub/manual/grub.html#Commands GRUB2 commands] before proceeding (e.g. "find" has been replaced with "search").<br />
<br />
* GRUB2 is now ''modular'' and no longer requires "stage 1.5". As a result, the bootloader itself is limited -- modules are loaded from the hard drive as needed to expand functionality (e.g. for [[LVM]] or RAID support).<br />
<br />
* Device naming has changed between GRUB and GRUB2. Partitions are numbered from 1 instead of 0 while drives are still numbered from 0, and prefixed with partition-table type. For example, {{Filename|/dev/sda1}} would be referred to as {{Codeline|(hd0,msdos1)}} (for MBR) or {{Codeline|(hd0,gpt1)}} (for GPT) using GRUB2.<br />
<br />
== Installation ==<br />
<br />
=== During Arch Linux installation ===<br />
<br />
* Skip the '''Install Bootloader''' step and exit the installer.<br />
* Configure the network:<br />
# aif -p partial-configure-network<br />
This will bring up a prompt; put in the network interface to use, (e.g., eth0) and use DHCP for easy configuration.<br />
* If you did not configure the installed system's {{Filename|/etc/resolv.conf}} file during installation (for instance, if you plan to let DHCP generate it later), you will need to copy the one generated by AIF when it configured the network:<br />
# cp /etc/resolv.conf /mnt/etc/resolv.conf<br />
* Load the dm-mod module (you might need grub2-bios; install the package if needed):<br />
# modprobe dm-mod<br />
{{Note|This is necessary at this point, and cannot be postponed after the chroot. If you try to use modprobe in a chroot environment that has a later kernel version from that of the installing device (at the time of writing, 2.6.33), modprobe will fail. This happens routinely using the Arch "net" installations.}}<br />
* From the installer's live shell, chroot to the installed system:<br />
# mount -o bind /dev /mnt/dev<br />
# chroot /mnt bash<br />
* Update pacman's database:<br />
# pacman-db-upgrade<br />
* Refresh the package list (with an extra -y flag to force a refresh of all package lists even if they appear to be up to date):<br />
# pacman -Syy<br />
* Install the GRUB2 package as mentioned in the section [[#From a running Arch Linux]]. Note that the dm-mod module has already been loaded, no need to do that again.<br />
<br />
=== From a running Arch Linux ===<br />
<br />
====Make a backup of your precious data====<br />
In general, a grub installation ran smoothly and you got no problems at all. And sometimes it could simply messed up your system. You're strongly advised to make a backup before even think of grub2.<br />
<br />
*copy grub modules and configuration<br />
# cp -a /boot/grub /path/to/backup/<br />
*backup the MBR and GRUB stage 1.5<br />
# dd if=/dev/sda of=/path/to/backup/first-sectors count=63<br />
<br />
You could now lightly remove /boot/grub and follow the instructions below.You know that if things get nasty, you could reboot your system thanks to an installation media and :<br />
<br />
*move old grub2 files out of the way<br />
# mv /boot/grub /boot/grub.nonfunctional<br />
*copy grub back to /boot<br />
# cp -a /path/to/backup/grub /boot/<br />
*replace MBR and next 62 sectors of sda with backed up copy (DANGEROUS!)<br />
# dd if=/path/to/backup/first-sectors of=/dev/sda count=63<br />
<br />
==== BIOS systems ====<br />
<br />
===== Preliminary Considerations for GRUB2 BIOS =====<br />
<br />
====== [[GPT]] specific instructions ======<br />
<br />
GRUB2 in BIOS-GPT configuration requires a BIOS Boot Partition to embed its core.img in the absence of post-MBR gap in GPT partitioned systems (which is taken over by the GPT Primary Header and Primary Partition table). This partition is used by GRUB2 only in BIOS-GPT setups. No such partition type exists in case of MBR partitioning (at least not for GRUB2). This partition is also not required if the system is UEFI based, as no embedding of bootsectors takes place in that case. Syslinux does not require this partition.<br />
<br />
For a BIOS-GPT configuration, create a 2 MiB partition using cgdisk or GNU Parted with no filesystem. The location of the partition in the partition table does not matter but it should be within the first 2 TiB region of the disk. It is advisable to put it somewhere in the beginning of the disk before the /boot partition. Set the partition type to "EF02" in cgdisk or {{Codeline|set <BOOT_PART_NUM> bios_grub on}} in GNU Parted.<br />
<br />
{{Note|This partition should be created before grub_bios-install or grub-setup is run or before the '''Install Bootloader''' step of the Archlinux installer (if GRUB2 is selected as bootloader).}}<br />
<br />
====== [[MBR]] aka msdos partitioning specific instructions ======<br />
<br />
Usually the post-MBR gap (after the 512 byte MBR region and before the start of the 1st partition) in many MBR (or msdos disklabel) partitioned systems is 32 KiB when DOS compatibility cylinder alignment issues are satisfied in the partition table. However a post-MBR gap of about 1 to 2 MiB is recommended to provide sufficient room for embedding grub2's core.img ( https://bugs.archlinux.org/task/24103 ). It is advisable to use a partitioner which supports 1 MiB partition alignment to obtain this space as well as satisfy other non-512 byte sector issues (which are unrelated to embedding of core.img).<br />
<br />
If you do not dual-boot with MS Windows (any version) in BIOS systems, it is advisable to switch to GPT partitioning - [[GUID_Partition_Table#Convert_from_MBR_to_GPT_without_data_loss]]<br />
{{Note|Create the 2MiB partition mentioned above BEFORE you convert to GPT. If you do not, gparted will not resize your boot partition to allow its creation, and when you reboot grub2 will not know where to look.}}<br />
<br />
===== Before grub_bios-install =====<br />
<br />
The GRUB2 package can be installed with pacman (and will replace {{Package Official|grub}}, if it is installed):<br />
<br />
# pacman -S grub2-bios<br />
<br />
{{Note|Installing grub2-common (a dependency of grub2-bios) 1.99~rc1 or later, may take forever in some systems since the post_install script runs grub-mkconfig and this script does not provide the option <code>--no-floppy</code>. For more details search this option in the article.}}<br />
<br />
{{Note|Simply installing the package won't update the /boot/grub/core.img file and the grub2 modules in /boot/grub . You need to update the core.img file and the grub2 modules manually using grub_bios-install as explained below.}}<br />
<br />
Also load the device-mapper kernel module without which grub-probe does not reliably detect disks and partitions<br />
<br />
# modprobe dm-mod<br />
<br />
<br />
===== Run grub_bios-install =====<br />
<br />
There are 3 ways to install grub2 in BIOS booting - [[#Install_to_440-byte_MBR_boot_code_region]] (recommended) , [[#Install_to_Partition_or_Partitionless_Disk]] (not recommended) or [[#Generate_core.img_alone]] (safest method, but requires another BIOS bootloader like [[grub-legacy]] or [[syslinux]] to be installed to chainload {{Filename|/boot/grub/core.img}} ). For all the ways [[#Before_grub_bios-install]] step is needed.<br />
<br />
====== Install to 440-byte MBR boot code region ======<br />
<br />
To setup grub2-bios in the 440-byte Master Boot Record boot code region, populate the {{Filename|/boot/grub}} directory, generate the {{Filename|/boot/grub/core.img}} file, and embed it in the 32 KiB (minimum size - varies depending on partition alignment) post-MBR gap (MBR disks) or in BIOS Boot Partition (GPT disks), run<br />
<br />
# grub_bios-install --boot-directory=/boot --no-floppy --recheck /dev/sda<br />
<br />
where {{Filename|/dev/sda}} is the destination of the installation (in this case the MBR of the first SATA disk). If you use [[LVM]] for your {{Filename|/boot}}, you can install GRUB2 on multiple physical disks. <br />
<br />
The {{Codeline|--no-floppy}} tells grub2-bios utilities not to search for any floppy devices which reduces the overall execution time of grub_bios-install on many systems (it will also prevent the issue below from occuring). Otherwise you get an error like this<br />
<br />
grub-probe: error: Cannot get the real path of '/dev/fd0'<br />
Auto-detection of a filesystem module failed.<br />
Please specify the module with the option '--modules' explicitly.<br />
<br />
Then:<br />
* Delete all the files from {{Filename|/boot/grub}} except {{Filename|/boot/grub/menu.lst}} .<br />
<br />
* Follow the [[#Install_to_440-byte_MBR_boot_code_region]] instructions.<br />
<br />
* Follow [[#Generate_GRUB2_BIOS_Config_file]] or if that fails, convert your {{Filename|/boot/grub/menu.lst}} file to {{Filename|/boot/grub/grub.cfg}} using:<br />
<br />
# grub-menulst2cfg /boot/grub/menu.lst /boot/grub/grub.cfg<br />
<br />
For example:<br />
<br />
{{File|name=/boot/grub/menu.lst|content=<br />
default=0<br />
timeout=5<br />
<br />
title Arch Linux Stock Kernel<br />
root (hd0,0)<br />
kernel /vmlinuz-linux root=/dev/sda2 ro<br />
initrd /initramfs-linux.img<br />
<br />
title Arch Linux Stock Kernel Fallback<br />
root (hd0,0)<br />
kernel /vmlinuz-linux root=/dev/sda2 ro<br />
initrd /initramfs-linux-fallback.img<br />
}}<br />
<br />
{{File|name=/boot/grub/grub.cfg|content=<br />
set default='0'; if [ x"$default" = xsaved ]; then load_env; set default="$saved_entry"; fi<br />
set timeout=5<br />
<br />
menuentry 'Arch Linux Stock Kernel' {<br />
set root='(hd0,1)'; set legacy_hdbias='0'<br />
legacy_kernel '/vmlinuz-linux' '/vmlinuz-linux' 'root=/dev/sda2' 'ro'<br />
legacy_initrd '/initramfs-linux.img' '/initramfs-linux.img'<br />
<br />
}<br />
<br />
menuentry 'Arch Linux Stock Kernel Fallback' {<br />
set root='(hd0,1)'; set legacy_hdbias='0'<br />
legacy_kernel '/vmlinuz-linux' '/vmlinuz-linux' 'root=/dev/sda2' 'ro'<br />
legacy_initrd '/initramfs-linux-fallback.img' '/initramfs-linux-fallback.img'<br />
}<br />
}}<br />
<br />
<br />
* If you forgot to create a GRUB2 {{Filename|/boot/grub/grub.cfg}} configfile and simply rebooted into GRUB2 Command Shell, type:<br />
<br />
sh:grub> insmod legacycfg<br />
sh:grub> legacy_configfile ${prefix}/menu.lst<br />
<br />
Boot into Arch and re-create the proper GRUB2 {{Filename|/boot/grub/grub.cfg}} configfile.<br />
<br />
{{Note|This option works only in BIOS systems, not in UEFI systems.}}<br />
<br />
====== Install to Partition or Partitionless Disk ======<br />
<br />
{{Note|grub2-bios (any version - including upstream bzr repo) does not encourage installation to a partition boot sector or a partitionless disk like grub-legacy or syslinux does. Neither do the Arch devs.}}<br />
<br />
To setup grub2-bios to a partition boot sector, to a partitionless disk (also called superfloppy) or to a floppy disk, run (using for example /dev/sda1 as the /boot partition)<br />
<br />
# chattr -i /boot/grub/core.img<br />
# grub_bios-install --boot-directory=/boot --no-floppy --recheck --force /dev/sda1<br />
# chattr +i /boot/grub/core.img<br />
<br />
You need to use the {{Codeline|--force}} option to allow usage of blocklists and should not use <code>--grub-setup=/bin/true</code> (which is similar to simply generating core.img).<br />
<br />
grub_bios-install will give out warnings like which should give you the idea of what might go wrong with this approach.<br />
<br />
/sbin/grub-setup: warn: Attempting to install GRUB to a partitionless disk or to a partition. This is a BAD idea.<br />
/sbin/grub-setup: warn: Embedding is not possible. GRUB can only be installed in this setup by using blocklists. <br />
However, blocklists are UNRELIABLE and their use is discouraged.<br />
<br />
Without {{Codeline|--force}} you may get the below error and grub-setup will not setup its boot code in the partition boot sector.<br />
<br />
/sbin/grub-setup: error: will not proceed with blocklists<br />
<br />
With {{Codeline|--force}} you should get<br />
<br />
Installation finished. No error reported.<br />
<br />
The reason why grub-setup does not by default allow this is because in case of partition or a partitionless disk is that grub2-bios relies on embedded blocklists in the partition bootsector to locate the {{Filename|/boot/grub/core.img}} file and the prefix dir {{Filename|/boot/grub}} . The sector locations of {{Filename|core.img}} may change whenever the filesystem in the partition is being altered (files copied, deleted etc.). For more info see https://bugzilla.redhat.com/show_bug.cgi?id=728742 and https://bugzilla.redhat.com/show_bug.cgi?id=730915 .<br />
<br />
The workaround for this is to set the immutable flag on {{Filename|/boot/grub/core.img}} (using chattr command as mentioned above) so that the sector locations of the {{Filename|core.img}} file in the disk is not altered. The immutable flag on {{Filename|/boot/grub/core.img}} needs to be set only if grub2-bios is installed to a partition boot sector or a partitionless disk, not in case of installtion to MBR or simple generation of {{Filename|core.img}} without embedding any bootsector (mentioned above). <br />
<br />
====== Generate core.img alone ======<br />
<br />
To populate the {{Filename|/boot/grub}} directory and generate a {{Filename|/boot/grub/core.img}} file WITHOUT embedding any grub2-bios bootsector code in the MBR, post-MBR region, or the partition bootsector, add <code>--grub-setup=/bin/true</code> to grub_bios-install:<br />
<br />
# grub_bios-install --grub-setup=/bin/true --boot-directory=/boot --no-floppy --recheck /dev/sda<br />
<br />
You can then chainload grub2's core.img from grub-legacy or syslinux as a Linux kernel or a multiboot kernel.<br />
<br />
===== After grub_bios-install =====<br />
<br />
====== Generate GRUB2 BIOS Config file ======<br />
<br />
Finally, generate a configuration for grub2 (this is explained in greater detail in the Configuration section):<br />
<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
If grub2 complains about "no suitable mode found" while booting, go to [[#Correct_GRUB2_No_Suitable_Mode_Found_Error]] .<br />
<br />
===== Multiboot in BIOS =====<br />
<br />
====== Boot Microsoft Windows installed in BIOS-MBR mode ======<br />
<br />
{{Note|GRUB2 supports booting {{Filename|bootmgr}} directly and chainload of partition boot sector is no longer required to boot Windows in a BIOS-MBR setup.}}<br />
<br />
Find the UUID of the NTFS filesystem of the Windows's SYSTEM PARTITION where the bootmgr and its files reside. For example, if Windows {{Filename|bootmgr}} exists at {{Filename|/media/Windows/bootmgr}}:<br />
<br />
# grub-probe --target=fs_uuid /media/Windows/bootmgr<br />
69B235F6749E84CE<br />
<br />
Then, add the below code to {{Filename|/boot/grub/grub.cfg}} to chainload Windows (Vista, 7 or 8) installed in BIOS-MBR mode :<br />
<br />
menuentry "Microsoft Windows 7 BIOS-MBR" {<br />
insmod part_msdos<br />
insmod ntfs<br />
insmod search_fs_uuid<br />
insmod ntldr <br />
search --fs-uuid --no-floppy --set=root 69B235F6749E84CE<br />
ntldr (${root})/bootmgr<br />
}<br />
<br />
For Windows XP<br />
<br />
menuentry "Microsoft Windows XP" {<br />
insmod part_msdos<br />
insmod ntfs<br />
insmod search_fs_uuid<br />
insmod ntldr <br />
search --fs-uuid --no-floppy --set=root 69B235F6749E84CE<br />
ntldr (${root})/ntldr<br />
}<br />
<br />
==== [[UEFI]] systems ====<br />
<br />
===== Before grub_efi_${UEFI_ARCH}-install =====<br />
<br />
{{Note|Unless specified as EFI 1.x , EFI and UEFI terms are used interchangeably to denote UEFI 2.x firmware. Also unless stated explicitely, the instructions are general and not Mac specific. Some of them may not work or may be different in Macs. Apple's EFI implementation is neither a EFI 1.x version nor UEFI 2.x version but mixes up both. This kind of firmware does not fall under any one UEFI Specification version and is therefore not a standard UEFI firmware.}}<br />
<br />
GRUB2 UEFI bootloader is available in Arch Linux only from version 1.99~rc1 . To install, first [https://wiki.archlinux.org/index.php/Unified_Extensible_Firmware_Interface#Detecting_UEFI_Firmware_Arch Detect which UEFI firmware arch] you have (either x86_64 or i386).<br />
<br />
Depending on that, install the appropriate package<br />
<br />
For 64-bit aka x86_64 UEFI firmware:<br />
# pacman -S grub2-efi-x86_64<br />
<br />
For 32-bit aka i386 UEFI firmware:<br />
# pacman -S grub2-efi-i386<br />
<br />
{{Note|Installing grub2-common (a dependency of grub2-bios) 1.99~rc1 or later, may take forever in some systems since the post_install script runs grub-mkconfig and this script does not provide the option <code>--no-floppy</code>. For more details search this option in the article.}}<br />
<br />
{{Note|Simply installing the package won't update the grub.efi file and the grub2 modules in the UEFI System Partition . You need to update the grub.efi file and the grub2 modules in the UEFI System Partition manually using grub_efi_${UEFI_ARCH}-install as explained below.}}<br />
<br />
Also load the device-mapper kernel module without which grub-probe does not reliably detect disks and partitions<br />
<br />
# modprobe dm-mod<br />
<br />
===== Install to UEFI SYSTEM PARTITION =====<br />
<br />
====== Mount UEFI SYSTEM PARTITION ======<br />
<br />
Mount the [https://wiki.archlinux.org/index.php/Unified_Extensible_Firmware_Interface#Creating_a_UEFI_SYSTEM_PARTITION_in_Linux UEFI SYSTEM PARTITION] in your system at {{Filename|/boot/efi}}. It should be FAT32 formatted and should be at least 200 MiB in size. If you have mounted the UEFISYS partition in some other mountpoint, replace {{Filename|/boot/efi}} in the below commands with that mountpoint:<br />
<br />
# mkdir -p /boot/efi<br />
# mount -t vfat <UEFISYS_PART_DEVICE> /boot/efi<br />
# mkdir -p /boot/efi/efi<br />
<br />
====== Run grub_efi_${UEFI_ARCH}-install ======<br />
<br />
{{Note|The below commands assume you are using {{Codeline|grub2-efi-x86_64}} (for {{Codeline|grub2-efi-i386}} replace {{Codeline|x86_64}} with {{Codeline|i386}} in the below commands).}}<br />
<br />
# grub_efi_x86_64-install --root-directory=/boot/efi --boot-directory=/boot/efi/efi --bootloader-id=grub --no-floppy --recheck<br />
<br />
The {{Codeline|grub_efi_x86_64-install}} automatically generates a {{Filename|grub.efi}} while setting up the {{Filename|/boot/efi/efi/grub/}} directory.<br />
<br />
If you notice carefully, there is no <device_path> option (Eg: {{Filename|/dev/sda}}) at the end of the {{Codeline|grub_efi_x86_64-install}} command unlike the case of setting up grub2 for BIOS systems. Any <device_path> provided will be ignored by the install script as UEFI bootloaders do not use MBR or Partition boot sectors at all.<br />
<br />
You may now be able to UEFI boot your system by creating a grub.cfg file using grub-mkconfig and copying /boot/efi/efi/grub/grub.efi to /boot/efi/efi/boot/bootx64.efi.<br />
<br />
===== After grub_efi_${UEFI_ARCH}-install =====<br />
<br />
====== Launch GRUB2 as default in non-Mac UEFI systems ======<br />
<br />
{{Note|The below steps will not work if the system has been booted in BIOS mode and will not work if the UEFI processor architecture does not match the kernel one, i.e. x86_64 UEFI + ix86 32-bit Kernel and vice-versa config will not work.}}<br />
<br />
grub_efi_${UEFI_ARCH}-install will ensure {{Filename|/boot/efi/efi/grub/grub.efi}} is launched by default if it detects {{Codeline|efibootmgr}} and if it is able to access UEFI Runtime Services. {{Codeline|efibootmgr}} command will work only if you have booted the system in UEFI mode itself, since it '''requires access to UEFI Runtime Variables''' which are '''available only in UEFI boot mode''' (with "noefi" kernel parameter NOT being used). Initially the user is required to manually launch {{Filename|/boot/efi/efi/grub/grub.efi}} from the firmware itself (using maybe the UEFI Shell) if grub2-efi was installed in BIOS mode. Then {{Codeline|efibootmgr}} should be run to make grub2 as the default entry in the UEFI Boot Manager<br />
<br />
First boot into UEFI mode manually either using the firmware boot menu, UEFI shell, or using any UEFI capable bootable iso (Archboot or Ubuntu non-Mac iso). Use grub probe to determine the device path of your EFI System Partition:<br />
# grub-probe --target=device /boot/efi/efi/grub/grub.efi<br />
<br />
It should give something like {{Filename|/dev/sda1}} (used as example in the remaining steps). Load 'efivars' kernel module:<br />
# modprobe efivars<br />
<br />
If you get '''no such device found''' error for this command, that means you have not booted in UEFI mode or due to some reason the kernel is unable to access UEFI Runtime Variables.<br />
<br />
Verify whether there are files in ''/sys/firmware/efi/vars/'' directory. This directory and its contents are created by "efivars" kernel module and it will exist only if you have booted in UEFI mode without the "noefi" kernel parameter.<br />
<br />
# ls -1 /sys/firmware/efi/vars/<br />
<br />
Sample output (x86_64-UEFI 2.3.1 in x86_64 Kernel:<br />
<br />
# ls -1 /sys/firmware/efi/vars/<br />
Boot0000-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootCurrent-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootOptionSupport-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootOrder-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConIn-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConInDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConOut-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConOutDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ErrOutDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
Lang-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
LangCodes-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
MTC-eb704011-1402-11d3-8e77-00a0c969723b/<br />
MemoryTypeInformation-4c19049f-4137-4dd3-9c10-8b97a83ffdfa/<br />
PlatformLang-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
PlatformLangCodes-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
RTC-378d7b65-8da9-4773-b6e4-a47826a833e1/<br />
del_var<br />
new_var<br />
<br />
If ''/sys/firmware/efi/vars/'' directory is empty or does not exist, then {{Codeline|efibootmgr}} command will not work. If you are unable to make the ISO/CD/DVD/USB boot in UEFI mode try https://gitorious.org/tianocore_uefi_duet_builds/pages/Linux_Windows_BIOS_UEFI_boot_USB .<br />
<br />
If ''/sys/firmware/efi/vars/'' directory (along with the exists then run {{Codeline|efibootmgr}} and reboot:<br />
<br />
# efibootmgr --create --gpt --disk /dev/sda --part 1 --write-signature --label "GRUB2" --loader "\\EFI\\grub\\grub.efi"<br />
<br />
In the above command, {{Filename|/boot/efi/efi/grub/grub/efi}} can be split up as {{Filename|/boot/efi}} and {{Filename|/efi/grub/grub.efi}}, which translates to {{Filename|(/dev/sda)}} -> partition 1 -> {{Filename|\\EFI\\grub\\grub.efi}}. <br />
<br />
FAT32 filesystem is case-insensitive since it does not use UTF-8 encoding by default. In that case the firmware uses capital 'EFI' instead of small 'efi', therefore using {{Filename|\\EFI\\grub\\grub.efi}} or {{Filename|\\efi\\grub\\grub.efi}} does not matter (this will change if the filesystem encoding is UTF-8). UEFI uses backward slash as path separatoir (similar to Windows paths). In the above command "double" backward slashes are used instead of single ones, since a backward slash is used as a escape character by sh shells, the first backward slash escapes the second one so that the path {{Filename|\EFI\grub\grub.efi}} is passed to {{Codeline|efibootmgr}}.<br />
<br />
The 'label' is the name of the menu entry shown in the UEFI boot menu. This name is user's choice and does not affect the booting of the system. More info can be obtained from [http://linux.dell.com/cgi-bin/gitweb/gitweb.cgi?p=efibootmgr.git;a=blob_plain;f=README;hb=HEAD efibootmgr GIT README]<br />
<br />
If you have problems running GRUB2 in UEFI mode you can try the following (worked on an ASUS Z68 mainboard):<br />
<br />
# cp /boot/efi/efi/grub/grub.efi /boot/efi/shellx64.efi<br />
<br />
or<br />
<br />
# cp /boot/efi/efi/grub/grub.efi /boot/efi/efi/shellx64.efi<br />
or<br />
<br />
# cp /boot/efi/efi/grub/grub.efi /boot/efi/efi/shell/shellx64.efi<br />
<br />
After this launch the UEFI Shell from the UEFI setup/menu (in ASUS UEFI BIOS, switch to advanced mode, press Exit in the top right corner and choose "Launch EFI shell from filesystem device"). The grub2 menu will show up and you can boot into your system. Afterwards you can use efibootmgr to setup a menu entry (see above).<br />
<br />
====== Launch GRUB2 as default in Apple Mac EFI systems ======<br />
<br />
{{Note|Using {{Filename|efibootmgr}} in Apple Macs will brick the firmware and may need reflash of the motherboard ROM. There have been bug reports regarding this in Ubuntu/Launchpad bug tracker. Use bless command alone in case of Macs}}<br />
<br />
Use bless command from within Mac OS X to setup {{Filename|grub.efi}} as the default boot option. More info at https://help.ubuntu.com/community/UEFIBooting#Apple_Mac_EFI_systems_.28both_EFI_architecture.29 .<br />
<br />
====== Generate GRUB2 UEFI Config file ======<br />
<br />
Finally, generate a configuration for grub2 (this is explained in greater detail in the Configuration section):<br />
<br />
# grub-mkconfig -o /boot/efi/efi/grub/grub.cfg<br />
<br />
If grub2-uefi complains about "no suitable mode found" while booting, go to [[#Correct_GRUB2_No_Suitable_Mode_Found_Error]] .<br />
<br />
===== Generate a custom GRUB2 UEFI Application =====<br />
<br />
If you want, you can create a custom {{Filename|grub_custom.efi}} app using:<br />
# grub-mkimage -d /usr/lib/grub/x86_64-efi -O x86_64-efi -p "" -o /boot/efi/efi/grub/grub_custom.efi <GRUB2_Modules_to_be_included><br />
<br />
{{Note|The '''-p''' option is important for creating a portable {{Filename|grub_custom.efi}} app.}}<br />
<br />
There is no file-size restriction on {{Filename|grub_custom.efi}} either due to GRUB2 or due to the UEFI firmware. Therefore you can include any number of modules you want.<br />
<br />
A "{{Filename|grub.cfg}}" created for BIOS based GRUB2 will be sufficient for the UEFI GRUB2 as long as all the paths in the config are absolute paths. The {{Filename|grub.cfg}} file should exist in the same directory as {{Filename|grub.efi}} or {{Filename|grub_custom.efi}}.<br />
<br />
The {{Filename|grub.efi}} UEFI application can be launched using the firmware's "Boot Manager", "Boot from file" option or using the [https://wiki.archlinux.org/index.php/UEFI#UEFI_Shell UEFI Shell].<br />
<br />
Alternatively, you can also setup {{Filename|/boot/efi/efi/grub}} directory by copying all the files in {{Filename|/usr/lib/grub/x86_64-efi}} to {{Filename|/boot/efi/efi/grub}} and using the above grub-mkimage command to create a {{Filename|grub_custom.efi}} application. Just make sure you have the required modules embedded in {{Filename|grub_custom.efi}} to enable it to access the EFI SYSTEM PARTITION.<br />
<br />
A basic {{Filename|grub_custom.efi}} can be generated using the following command:<br />
# sudo grub-mkimage -d /usr/lib/grub/x86_64-efi -O x86_64-efi -p "" -o /boot/efi/efi/grub/grub_custom.efi part_gpt fat iso9660 udf normal chain linux \<br />
ls search search_fs_file search_fs_uuid search_label help boot configfile echo efi_gop<br />
<br />
===== Multiboot in UEFI =====<br />
<br />
====== Chainload Microsoft Windows x86_64 UEFI-GPT ======<br />
<br />
Find the UUID of the FAT32 filesystem in the UEFI SYSTEM PARTITION where the Windows UEFI Bootloader files reside. For example, if Windows {{Filename|bootmgfw.efi}} exists at {{Filename|/boot/efi/efi/Microsoft/Boot/bootmgfw.efi}} (ignore the upper-lower case differences since that is immaterial in FAT filesystem):<br />
<br />
# grub-probe --target=fs_uuid /boot/efi/efi/Microsoft/Boot/bootmgfw.efi<br />
1ce5-7f28<br />
<br />
Then, add this code to {{Filename|/boot/efi/efi/grub/grub.cfg}} to chainload Windows x86_64 (Vista SP1+, 7 or 8) installed in UEFI-GPT mode :<br />
<br />
menuentry "Microsoft Windows x86_64 UEFI-GPT" {<br />
insmod part_gpt<br />
insmod fat<br />
insmod search_fs_uuid<br />
insmod chain<br />
search --fs-uuid --no-floppy --set=root 1ce5-7f28<br />
chainloader (${root})/efi/Microsoft/Boot/bootmgfw.efi<br />
}<br />
<br />
== Manual Compilation ==<br />
<br />
=== For BIOS Systems ===<br />
<br />
GRUB2 for BIOS systems should be compiled as follows:<br />
<pre><br />
./autogen.sh<br />
<br />
./configure --with-platform=pc --prefix=/usr<br />
<br />
make<br />
<br />
make install<br />
</pre><br />
<br />
The <code>--with-platform=pc</code> generates grub2 for bios alone irrespective of the firmware of the build system.<br />
<br />
=== For UEFI Systems ===<br />
<br />
First [https://wiki.archlinux.org/index.php/Unified_Extensible_Firmware_Interface#Detecting_UEFI_Firmware_Arch Detect which UEFI Firmware arch] you have and then follow the compile instructions below:<br />
<pre><br />
./autogen.sh<br />
<br />
./configure --with-platform=efi --target=TARGET_UEFI_ARCH --prefix=/usr<br />
<br />
make<br />
<br />
make install<br />
</pre><br />
<br />
The "--target" option denotes the UEFI firmware arch. for which grub2 should be compiled, not the architecture of the linux kernel grub2 may boot. <br />
<br />
It is possible to use UEFI 64-bit firmware + GRUB2 as x86_64-EFI app loading a i686 linux kernel, as long as the kernel does not try to access UEFI Runtime Services. Vice-versa situation is also possible. But a x86_64 UEFI firmware cannot launch GRUB2 i386-efi app (unlike x86_64 Operating Systems), and a i386 UEFI firmware will not launch GRUB2 {{Codeline|x86_64-efi}} app. It is important to compile GRUB2 to match the architecture of the UEFI firmware.<br />
<br />
== Configuration ==<br />
<br />
The configuration files are {{Filename|/etc/default/grub}} and {{Filename|/etc/grub.d/*}}. These files are used to generate the {{Filename|/boot/grub/grub.cfg}} file. You can also choose to manually edit {{Filename|grub.cfg}}.<br />
<br />
=== grub-mkconfig ===<br />
<br />
The grub-mkconfig script can be used to generate a {{Filename|grub.cfg}} file. By default the script outputs to stdout. Note that gettext ― an optional dependency of the GRUB2 package ― is required by the grub-mkconfig script. To generate a {{Filename|grub.cfg}} file run the command:<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
Note that grub-mkconfig probably has your grub directory hardcoded to /boot/grub, which is probably wrong if you're using UEFI. Either mount your efi grub directory at /boot/grub or edit the script.<br />
<br />
=== grub.cfg ===<br />
<br />
A basic grub file uses the following options<br />
* {{Codeline|(hdX,Y)}} is the partition {{Codeline|Y}} on disk {{Codeline|X}}, partition numbers starting at 1, disk numbers starting at 0<br />
* {{Codeline|1=set default=N}} is the default boot entry that is chosen after timeout for user action<br />
* {{Codeline|1=set timeout=M}} is the time {{Codeline|M}} to wait in seconds for a user selection before default is booted<br />
* {{Codeline|<nowiki>menuentry "title" {entry options}</nowiki>}} is a boot entry titled {{Codeline|title}}<br />
* {{Codeline|1=set root=(hdX,Y)}} sets the boot partition, where the kernel and GRUB modules are stored (boot need not be a separate partition, and may simply be a directory under the "root" partition ({{Filename|/}})<br />
<br />
An example configuration:<br />
<br />
{{File<br />
|name=/boot/grub/grub.cfg<br />
|content=<nowiki><br />
# Config file for GRUB2 - The GNU GRand Unified Bootloader<br />
# /boot/grub/grub.cfg<br />
<br />
# DEVICE NAME CONVERSIONS<br />
#<br />
# Linux Grub<br />
# -------------------------<br />
# /dev/fd0 (fd0)<br />
# /dev/sda (hd0)<br />
# /dev/sdb2 (hd1,2)<br />
# /dev/sda3 (hd0,3)<br />
#<br />
<br />
# Timeout for menu<br />
set timeout=5<br />
<br />
# Set default boot entry as Entry 0<br />
set default=0<br />
<br />
# (0) Arch Linux<br />
menuentry "Arch Linux" {<br />
set root=(hd0,1)<br />
linux /vmlinuz-linux root=/dev/sda3 ro<br />
initrd /initramfs-linux.img<br />
}<br />
<br />
## (1) Windows<br />
#menuentry "Windows" {<br />
#set root=(hd0,3)<br />
#chainloader +1<br />
#}<br />
</nowiki>}}<br />
<br />
=== Dual-booting ===<br />
<br />
''NOTE: If you want GRUB2 to automatically search for other systems, for example as in Ubuntu. Then you may need to download {{Package AUR|os-prober}} from the [[AUR]].''<br />
<br />
==== Using grub-mkconfig ====<br />
The best way to add other entries is editing the {{Filename|/etc/grub.d/40_custom}}. The entries in this file will be automatically added when running '''grub-mkconfig'''.<br />
After adding the new lines, run:<br />
# grub-mkconfig -o /boot/grub/grub.cfg <br />
to generate an updated {{Filename|grub.cfg}}.<br />
<br />
===== With GNU/Linux =====<br />
<br />
Assuming that the other distro is on partition {{Filename|sda2}}:<br />
<br />
menuentry "Other Linux" {<br />
set root=(hd0,2)<br />
linux /boot/vmlinuz (add other options here as required)<br />
initrd /boot/initrd.img (if the other kernel uses/needs one)<br />
}<br />
<br />
===== With Windows =====<br />
<br />
This assumes that your Windows partition is {{Filename|sda3}}.<br />
<br />
# (2) Windows XP<br />
menuentry "Windows XP" {<br />
set root=(hd0,3)<br />
chainloader (hd0,3)+1<br />
}<br />
<br />
If the windows bootloader is on an entirely different harddrive than grub, it may be necessary to trick Windows into believing that it is in fact the first harddrive. This was possible in the old grub with {{Codeline|map}} and is now done with {{Codeline|drivemap}}. Assume grub is on {{Filename|hd0}} and windows on {{Filename|hd2}}, you need to add the following after {{Codeline|set root}}:<br />
<br />
drivemap -s hd0 hd2<br />
<br />
==== With Windows via EasyBCD and NeoGRUB ====<br />
<br />
Since EasyBCD's NeoGRUB currently does not understand the GRUB2 menu format, chainload to it by replacing the contents of your {{Filename|C:\NST\menu.lst}} file with lines similar to the following:<br />
<br />
default 0<br />
timeout 1<br />
<br />
title Chainload into GRUB v2<br />
root (hd0,7)<br />
kernel /boot/grub/core.img<br />
<br />
===Visual Configuration===<br />
<br />
In GRUB2 it is possible, by default, to change the look of the menu.<br />
<br />
====Background image and bitmap fonts====<br />
<br />
GRUB2 comes with support for background images and bitmap fonts in pf2 format. The unifont font is included in the grub2 package under the filename {{Filename|unicode.pf2}}, or, as only ascii characters under the name {{Filename|ascii.pf2}}. Image formats supported include tga, png and jpeg, providing the correct modules are loaded. The maximum supported resolution depends on your hardware. There are two ways of setting a {{Filename|tga}} file as background. Two sample configurations are shown below.<br />
<br />
Edit {{Filename|/etc/default/grub}} like this:<br />
GRUB_GFXMODE=1024x768x32<br />
GRUB_GFXPAYLOAD_LINUX=keep<br />
GRUB_BACKGROUND="/boot/grub/archlinux.tga"<br />
#GRUB_THEME="/path/to/gfxtheme"<br />
<br />
(archlinux.tga is a placeholder; put your file name there)<br />
<br />
To generate the changes, run: <br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
{{Note|If this example does not work for you try to replace {{Codeline|1=gfxmode="1024x768x32"}} by {{Codeline|1=vbemode="0x105"}}.}}<br />
{{Note|To show all the modes you can use {{Codeline|1=# hwinfo --framebuffer}} (hwinfo is available in [community]), while at grub2 prompt you can use the {{Codeline|1=vbeinfo}} command.}}<br />
{{Note|If you have installed Grub on a separate partition, {{Filename|/boot/grub/archlinux.tga}} becomes {{Filename|/grub/archlinux.tga}}.}}<br />
<br />
====Menu colors====<br />
<br />
As in Grub (0.9x), you can change the menu colors in Grub2. The available colors for GRUB2 are at http://www.gnu.org/software/grub/manual/html_node/Theme-file-format.html#Theme-file-format . <br />
Here is an example:<br />
<br />
Edit {{Filename|/etc/default/grub}}:<br />
GRUB_COLOR_NORMAL="light-blue/black"<br />
GRUB_COLOR_HIGHLIGHT="light-cyan/blue"<br />
<br />
Generate the changes:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
====Hidden menu====<br />
<br />
One of the unique features of Grub2 is hiding/skipping the menu and showing it by holding "Shift" when needed. You can also adjust whether you want to see the timeout counter.<br />
<br />
Edit {{Filename|/etc/default/grub}} as you wish. Here is an example where the comments from the beginning of the two lines have been removed to enable the feature, the timeout has been set to five seconds and to be shown to the user:<br />
GRUB_HIDDEN_TIMEOUT=5<br />
GRUB_HIDDEN_TIMEOUT_QUIET=false<br />
<br />
and run:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
====Setting the framebuffer resolution ====<br />
<br />
Grub2 can set the framebuffer for both grub2 itself and the kernel. The old ''vga='' way is deprecated. The preferred method is editing {{Filename|/etc/default/grub}} as the following sample:<br />
<br />
GRUB_GFXMODE=1024x768x32<br />
GRUB_GFXPAYLOAD_LINUX=keep<br />
<br />
To generate the changes, run: <br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
The {{Codeline|gfxpayload}} property will make sure the kernel keeps the resolution.<br />
<br />
If this method does not work for you, the deprecated <code>vga=</code> method will still work. Just<br />
add it next to the <code>"GRUB_CMDLINE_LINUX_DEFAULT="</code> line in {{Filename|/etc/default/grub}}<br />
for eg: <code>"GRUB_CMDLINE_LINUX_DEFAULT="quiet splash vga=792"</code> will give you a {{Codeline|1024x768}} resolution.<br />
<br />
You can choose one of these resolutions: {{Codeline|640×480}}, {{Codeline|800×600}}, {{Codeline|1024×768}}, {{Codeline|1280×1024}}, {{Codeline|1600×1200}}<br />
<br />
=== Other Options ===<br />
<br />
==== LVM ====<br />
<br />
If you use [[LVM]] for your {{Filename|/boot}}, add the following before menuentry lines:<br />
<br />
insmod lvm<br />
<br />
and specify your root in the menuentry as:<br />
<br />
set root=(''lvm_group_name''-''lvm_logical_boot_partition_name'')<br />
<br />
Example:<br />
<br />
# (0) Arch Linux<br />
menuentry "Arch Linux" {<br />
insmod lvm<br />
set root=(VolumeGroup-lv_boot)<br />
# you can only set following two lines<br />
linux /vmlinuz-linux root=/dev/mapper/VolumeGroup-root ro<br />
initrd /initramfs-linux.img<br />
}<br />
<br />
==== Raid ====<br />
<br />
Grub2 provides convenient handling of raid-volumes. You need to add:<br />
insmod raid<br />
<br />
which allows you to address the volume natively. E.g. {{Filename|/dev/md0}} becomes:<br />
set root=(md0)<br />
<br />
whereas a partitioned raid-volume (e.g. {{Filename|/dev/md0p1}}) becomes:<br />
set root=(md0,1)<br />
<br />
==== Persistent block device naming ====<br />
You can use UUIDs to detect partitions instead of the "old" {{Filename|/dev/sd*}} and {{Filename|/dev/hd*}} scheming. It has the advantage of detecting partitions by their unique UUIDs, which is needed by some people booting with complicated partition setups.<br />
<br />
UUIDs are used by default in the recent versions of grub2 - there is no downside in it anyway except that you need to re-generate the {{Filename|grub.cfg}} file every time you resize or reformat your partitions. Remember this when modifying partitions with Live-CD.<br />
<br />
The recent versions of grub2 use UUIDs by default. You can re-enable the use of UUIDS by simply commenting the UUID line (this is also what it looks like by default):<br />
#GRUB_DISABLE_LINUX_UUID=true<br />
you can also just set the value as {{Codeline|false}} as shown here:<br />
GRUB_DISABLE_LINUX_UUID=false<br />
<br />
Either way, do not forget to generate the changes:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
==== Using Labels ====<br />
<br />
It is possible to use labels, human-readable strings attached to filesystems, by using the {{Codeline|--label}} option to {{Codeline|search}}. First of all, label your existing partition:<br />
# tune2fs -L a <LABEL> <PARTITION><br />
<br />
Then, add an entry using labels. An example of this:<br />
<br />
menuentry "Arch Linux, session texte" {<br />
search --label --no-floppy --set=root archroot<br />
linux /boot/vmlinuz-linux root=/dev/disk/by-label/archroot ro<br />
initrd /boot/initramfs-linux.img<br />
}<br />
<br />
==== Recall previous entry ====<br />
<br />
Grub2 can remember the last entry you booted from and use this as the default entry to boot from next time. This is useful if you have multiple kernels (i.e., the current Arch one and the LTS kernel as a fallback option) or operating systems. To do this, edit {{Filename|/etc/default/grub}} and change the setting of {{Codeline|GRUB_DEFAULT}}:<br />
<br />
GRUB_DEFAULT=saved<br />
<br />
This ensures that grub will default to the saved entry. To enable saving the selected entry, add the following line to {{Filename|/etc/default/grub}}:<br />
<br />
GRUB_SAVEDEFAULT=true<br />
<br />
Remember to regenerate your configuration file.<br />
<br />
==== Security ====<br />
<br />
If you want to secure GRUB2 so it is not possible for anyone to change boot parameters or use the command line, you can add a user/password combination to GRUB2's configuration files. To do this, run the command {{Codeline|grub-mkpasswd_pbkdf2}}. Enter a password and confirm it. The output will look like this:<br />
<br />
<pre style='overflow:auto'><br />
Your PBKDF2 is grub.pbkdf2.sha512.10000.C8ABD3E93C4DFC83138B0C7A3D719BC650E6234310DA069E6FDB0DD4156313DA3D0D9BFFC2846C21D5A2DDA515114CF6378F8A064C94198D0618E70D23717E82.509BFA8A4217EAD0B33C87432524C0B6B64B34FBAD22D3E6E6874D9B101996C5F98AB1746FE7C7199147ECF4ABD8661C222EEEDB7D14A843261FFF2C07B1269A</pre>Then, add the following to {{Filename|/etc/grub.d/00_header}}:<br />
<pre>cat << EOF<br />
<br />
set superusers="username"<br />
password_pbkdf2 username <password><br />
<br />
EOF</pre><br />
where <password> is the string generated by {{Codeline|grub-mkpasswd_pbkdf2}}.<br />
<br />
Regenerate your configuration file. Your GRUB2 command line and boot parameters are now protected.<br />
<br />
=== Booting an Ubuntu ISO Image from the GRUB2 Screen ===<br />
<br />
Edit {{Filename|/etc/grub.d/40_custom}} to add an entry pointing to an Ubuntu iso:<br />
<br />
menuentry "ubuntu-11.04-desktop-amd64.iso" {<br />
set isofile="/path/to/ubuntu-11.04-desktop-amd64.iso"<br />
loopback loop (hdX,Y)$isofile<br />
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile quiet noeject noprompt splash --<br />
initrd (loop)/casper/initrd.lz<br />
}<br />
<br />
Be sure to adjust the "hdX,Y" in the third line to point to the correct disk/partition number of the isofile. When finished, update grub2's configuration file via:<br />
<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
== Using the command shell ==<br />
<br />
Since the MBR is too small to store all GRUB2 modules, only the menu and a few basic commands reside there. The majority of GRUB2 functionality remains in modules in {{Filename|/boot/grub}}, which are inserted as needed. In error conditions (e.g. if the partition layout changes) GRUB2 may fail to boot. When this happens, a command shell may appear.<br />
<br />
GRUB2 offers multiple shells/prompts. If there is a problem reading the menu but the bootloader is able to find the disk, you will likely be dropped to the "normal" shell:<br />
sh:grub><br />
<br />
If there is a more serious problem (e.g. GRUB cannot find required files), you may instead be dropped to the "rescue" shell:<br />
grub rescue><br />
<br />
The rescue shell is a restricted subset of the normal shell, offering much less functionality. If dumped to the rescue shell, first try inserting the "normal" module, then starting the "normal" shell:<br />
grub rescue> set prefix=(hdX,Y)/boot/grub<br />
grub rescue> insmod (hdX,Y)/boot/grub/normal.mod<br />
rescue:grub> normal<br />
<br />
=== Pager support ===<br />
<br />
GRUB2 supports pager for reading commands that provide long output (like the help command). This works only in normal shell mode and not in rescue mode. To enable pager, in GRUB2 command shell type:<br />
sh:grub> set pager=1<br />
<br />
== GUI configuration tools ==<br />
<br />
Following package may be installed from [[AUR]]<br />
* [http://kde-apps.org/content/show.php?content=139643 grub2-editor] (requires kdelibs)<br />
*:A KDE4 control module for configuring the GRUB2 bootloader<br />
* [http://kde-apps.org/content/show.php?content=137886 kcm-grub2] (requires kdelibs python2-qt kdebindings-python)<br />
*:This Kcm module manages the most common settings of Grub2.<br />
* [http://sourceforge.net/projects/startup-manager/ startupmanager] (requires gnome-python imagemagick yelp python2 xorg-xrandr)<br />
*:GUI app for changing the settings of GRUB, GRUB2, Usplash and Splashy<br />
<br />
== parttool or legacy hide/unhide ==<br />
<br />
If you have a win9x paradigm with hidden C disks GRUB legacy had the hide/unhide feature. In GRUB2 this has been replaced by parttool. For example, to boot the third C disk of three win9x installations on the CLI enter the CLI and:<br />
parttool hd0,1 hidden+ boot-<br />
parttool hd0,2 hidden+ boot-<br />
parttool hd0,3 hidden- boot+<br />
set root=hd0,3<br />
chainloader +1<br />
boot<br />
<br />
== Using the rescue console ==<br />
<br />
See [[#Using the command shell]] first. If unable to activate the standard shell, one possible solution is to boot using a live CD or some other rescue disk to correct configuration errors and reinstall GRUB. However, such a boot disk is not always available (nor necessary); the rescue console is surprisingly robust.<br />
<br />
The available commands in GRUB rescue include "insmod", "ls", "set", and "unset". This example uses "set" and "insmod". "set" modifies variables and "insmod" inserts new modules to add functionality.<br />
<br />
Before starting, the user must know the location of their {{Filename|/boot}} partition (be it a separate partition, or a subdirectory under their root):<br />
grub rescue> set prefix=(hdX,Y)/boot/grub<br />
<br />
where X is the physical drive number and Y is the partition number.<br />
<br />
To expand console capabilities, insert the "linux" module:<br />
grub rescue> insmod (hdX,Y)/boot/grub/linux.mod<br />
<br />
{{Note|With a separate boot partition, omit {{Filename|/boot}} from the path, (i.e. type {{Codeline|1=set prefix=(hdX,Y)/grub}} and {{Codeline|insmod (hdX,Y)/grub/linux.mod}}).}}<br />
<br />
This introduces the "linux" and "initrd" commands, which should be familiar (see [[#Configuration]]).<br />
<br />
An example, booting Arch Linux:<br />
set root=(hd0,5)<br />
linux /boot/vmlinuz-linux root=/dev/sda5<br />
initrd /boot/initramfs-linux.img<br />
boot<br />
<br />
With a separate boot partition, again change the lines accordingly:<br />
set root=(hd0,5)<br />
linux /vmlinuz-linux root=/dev/sda6<br />
initrd /initramfs-linux.img<br />
boot<br />
<br />
After successfully booting the Arch Linux installation, users can correct {{Filename|grub.cfg}} as needed and then run:<br />
# grub-install /dev/sda --no-floppy<br />
<br />
to reinstall GRUB2 and fix the problem completely, changing {{Filename|/dev/sda}} if needed. See [[#Bootloader installation]] for details.<br />
<br />
== Combining the use of UUID's and basic scripting ==<br />
<br />
If you like the idea of using UUID's to avoid unreliable BIOS mappings or are struggling with Grub's syntax, here is an example boot menu item that uses UUID's and a small script to direct Grub to the proper disk partitions for your system. All you need to do is replace the UUID's in the sample with the correct UUID's for your system. (The example applies to a system with a boot and root partition. You will obviously need to modify the Grub configuration if you have additional partitions.)<br />
<br />
menuentry "Arch Linux 64" {<br />
#Enter the UUID of your boot partition (this is where Grub and your kernel reside)<br />
set uuid_grub_boot=ece0448f-bb08-486d-9864-ac3271bd8d07<br />
<br />
#Enter the UUID of the partition containing the root partition of your Arch Linux installation. <br />
set uuid_os_root=c55da16f-e2af-4603-9e0b-03f5f565ec4a<br />
<br />
#(Note: this may be the same as your boot partition)<br />
<br />
#Here we set the Grub "root" variable by locating the UUID of the root partition identified above <br />
search --fs-uuid --no-floppy --set=root $uuid_os_root<br />
<br />
#Here we set a custom variable grub_boot by locating the UUID of the boot partition identified above <br />
search --fs-uuid --no-floppy --set=grub_boot $uuid_grub_boot<br />
<br />
#Here is the magic. We test to see if the boot and root partitions have the same UUID.<br />
#If they do, we append /boot to the $grub_boot variable. For ex. (hd0,1) becomes (hd0,1)/boot.<br />
if [ $uuid_grub_boot == $uuid_os_root ] ; then<br />
set grub_boot=$grub_boot/boot<br />
fi<br />
<br />
# $grub_boot now points to the correct location, so the following will properly find the kernel and initrd<br />
linux ($grub_boot)/vmlinuz-linux root=/dev/disk/by-uuid/$uuid_os_root ro<br />
initrd ($grub_boot)/initramfs-linux.img<br />
}<br />
<br />
== Troubleshooting ==<br />
<br />
Any troubleshooting should be added here.<br />
<br />
=== Enable GRUB2 debug messages ===<br />
<br />
Add<br />
<br />
set pager=1<br />
set debug=all<br />
<br />
to {{Filename|grub.cfg}}.<br />
<br />
=== Correct GRUB2 No Suitable Mode Found Error ===<br />
<br />
If you get this error when booting any menuentry<br />
<br />
error: no suitable mode found<br />
Booting however<br />
<br />
Then you need to initialize grub2 graphical terminal (gfxterm) with proper video mode (gfxmode) in grub2. This video mode is passed by grub2 to the linux kernel via 'gfxpayload'. In case of UEFI systems, if the grub2 video mode is not initialized, no kernel boot messages will be shown in the terminal (atleast until KMS kicks in)<br />
<br />
Copy {{Filename|/usr/share/grub/unicode.pf2}} to ${GRUB2_PREFIX_DIR} ({{Filename|/boot/grub/}} in case of BIOS systems and {{Filename|/boot/efi/efi/grub/}} in case of UEFI systems). <br />
<br />
# cp /usr/share/grub/unicode.pf2 ${GRUB2_PREFIX_DIR}<br />
<br />
If {{Filename|/usr/share/grub/unicode.pf2}} does not exist, install {{Package Official|bdf-unifont}}, create the unifont.pf2 file and then copy it to ${GRUB2_PREFIX_DIR} .<br />
<br />
# grub-mkfont -o unicode.pf2 /usr/share/fonts/misc/unifont.bdf<br />
<br />
Then, in the {{Filename|grub.cfg}} file, add the following lines to enable grub2 to pass the video mode correctly to the kernel, without of which you will only get a black screen (no output) but booting (actually) proceeds successfully without any system hang:<br />
<br />
BIOS systems<br />
<br />
insmod vbe<br />
<br />
UEFI systems<br />
<br />
insmod efi_gop<br />
insmod efi_uga<br />
<br />
After that add the following code (common to both BIOS and UEFI)<br />
<br />
insmod font<br />
<br />
if loadfont ${prefix}/unicode.pf2<br />
then<br />
insmod gfxterm<br />
set gfxmode=auto<br />
set gfxpayload=keep<br />
terminal_output gfxterm<br />
fi<br />
<br />
As you can see for gfxterm (graphical terminal) to function properly, {{Filename|unicode.pf2}} font file should exist in ${GRUB2_PREFIX_DIR}.<br />
<br />
=== msdos-style error message ===<br />
<br />
grub-setup: warn: This msdos-style partition label has no post-MBR gap; embedding won't be possible!<br />
grub-setup: warn: Embedding is not possible. GRUB can only be installed in this setup by using blocklists.<br />
However, blocklists are UNRELIABLE and its use is discouraged.<br />
grub-setup: error: If you really want blocklists, use --force.<br />
<br />
This error may occur when you try installing GRUB2 in a VMware container. Read more about it [http://bbs.archlinux.org/viewtopic.php?pid=581760#p581760 here]. It happens when the first partition starts just after the MBR (block 63), without the usual space of 1 MiB (2048 blocks) before the first partition. Read [[#MBR_aka_msdos_partitioning_specific_instructions]]<br />
<br />
=== UEFI GRUB2 not loaded ===<br />
In some cases the EFI may fail to load grub correctly. Provided everything is set up correctly, the output of<br />
efibootmgr -v<br />
might look something like this:<br />
BootCurrent: 0000<br />
Timeout: 3 seconds<br />
BootOrder: 0000,0001,0002<br />
Boot0000* Grub HD(1,800,32000,23532fbb-1bfa-4e46-851a-b494bfe9478c)File(\efi\grub\grub.efi)<br />
Boot0001* Shell HD(1,800,32000,23532fbb-1bfa-4e46-851a-b494bfe9478c)File(\EfiShell.efi)<br />
Boot0002* Festplatte BIOS(2,0,00)P0: SAMSUNG HD204UI .<br />
If everything works correctly, the EFI would now automatically load grub.<br><br />
If the screen only goes black for a second and the next boot option is tried afterwards, according to [https://bbs.archlinux.org/viewtopic.php?pid=981560#p981560 this post], moving grub to the partition root can help. The boot option has to be deleted and recreated afterwards. The entry for grub should look like this then:<br />
Boot0000* Grub HD(1,800,32000,23532fbb-1bfa-4e46-851a-b494bfe9478c)File(\grub.efi)<br />
<br />
=== Invalid signature ===<br />
If trying to boot windows results in an "invalid signature" error, e.g. after reconfiguring partitions or adding additional hard drives, (re)move grub's device configuration and let it reconfigure.<br />
# mv /boot/grub/device.map /boot/grub/device.map-old<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
Grub-mkconfig should now mention all found boot options including windows. If it works, remove /boot/grub/device.map-old.<br />
<br />
== References ==<br />
<br />
# Official GRUB2 Manual - http://www.gnu.org/software/grub/manual/grub.html<br />
# GRUB2 wiki page describing steps to compile for UEFI systems - https://help.ubuntu.com/community/UEFIBooting - previously http://grub.enbug.org/TestingOnUEFI{{Linkrot|2011|09|05}}<br />
# Wikipedia's page on [http://en.wikipedia.org/wiki/BIOS_Boot_partition BIOS Boot Partition]<br />
<br />
== External Links ==<br />
<br />
# [https://github.com/the-ridikulus-rat/My_Shell_Scripts/blob/master/grub2/grub2_bios.sh A Linux Bash Shell script to compile and install GRUB2 for BIOS from BZR Source]<br />
# [https://github.com/the-ridikulus-rat/My_Shell_Scripts/blob/master/grub2/grub2_uefi.sh A Linux Bash Shell script to compile and install GRUB2 for UEFI from BZR Source]</div>Mayweedhttps://wiki.archlinux.org/index.php?title=GRUB&diff=167960GRUB2011-10-29T17:26:29Z<p>Mayweed: backup procedure add.</p>
<hr />
<div>[[Category:Boot loaders (English)]]<br />
{{i18n|GRUB2}}<br />
[[fr:GRUB2]]<br />
{{Article summary start}}<br />
{{Article summary text|Covers various aspects of the next generation of the GRand Unified Bootloader (GRUB2).}}<br />
{{Article summary heading|Overview}}<br />
{{Article summary text|{{Boot process overview}}}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|Burg}} - Burg is a brand-new boot loader based on GRUB2. It uses a new object format which allows it to be built in a wider range of OS, including Linux/Windows/OSX/Solaris/FreeBSD, etc. It also has a highly configurable menu system which works in both text and graphic mode. <br />
{{Article summary heading|Resources}}<br />
{{Article summary link|GNU GRUB -- GNU Project|http://www.gnu.org/software/grub/}}<br />
{{Article summary link|GNU GRUB Wiki|http://grub.enbug.org/}}{{Linkrot|2011|09|05}}<br />
{{Article summary end}}<br />
<br />
[http://www.gnu.org/software/grub/ GRUB2] is the next generation of the GRand Unified Bootloader (GRUB). GRUB2 is derived from [http://www.nongnu.org/pupa/ PUPA] which was a research project to investigate the next generation of GRUB. GRUB 2 has been rewritten from scratch to clean up everything and provide modularity and portability [http://www.gnu.org/software/grub/grub-faq.en.html#q1].<br />
<br />
Briefly, the ''bootloader'' is the first software program that runs when a computer starts. It is responsible for loading and transferring control to the Linux kernel. The kernel, in turn, initializes the rest of the operating system.<br />
<br />
== Preface ==<br />
<br />
Although, [[GRUB]] (i.e. version 0.9x) is the de facto standard bootloader of Linux, it is considered 'legacy' by upstream. It is being replaced by GRUB2 in many distributions. Upstream recommends GRUB2 >=1.99~rc2 over grub-legacy, even for current grub-legacy users.<br />
<br />
{{Note|grub2 from 1.99~rc2 and later supports btrfs as root (without a separate /boot filesystem).}}<br />
<br />
=== Notes for current GRUB users ===<br />
<br />
* There are differences in the commands of GRUB and GRUB2. Familiarize yourself with [http://www.gnu.org/software/grub/manual/grub.html#Commands GRUB2 commands] before proceeding (e.g. "find" has been replaced with "search").<br />
<br />
* GRUB2 is now ''modular'' and no longer requires "stage 1.5". As a result, the bootloader itself is limited -- modules are loaded from the hard drive as needed to expand functionality (e.g. for [[LVM]] or RAID support).<br />
<br />
* Device naming has changed between GRUB and GRUB2. Partitions are numbered from 1 instead of 0 while drives are still numbered from 0, and prefixed with partition-table type. For example, {{Filename|/dev/sda1}} would be referred to as {{Codeline|(hd0,msdos1)}} (for MBR) or {{Codeline|(hd0,gpt1)}} (for GPT) using GRUB2.<br />
<br />
== Installation ==<br />
<br />
=== During Arch Linux installation ===<br />
<br />
* Skip the '''Install Bootloader''' step and exit the installer.<br />
* Configure the network:<br />
# aif -p partial-configure-network<br />
This will bring up a prompt; put in the network interface to use, (e.g., eth0) and use DHCP for easy configuration.<br />
* If you did not configure the installed system's {{Filename|/etc/resolv.conf}} file during installation (for instance, if you plan to let DHCP generate it later), you will need to copy the one generated by AIF when it configured the network:<br />
# cp /etc/resolv.conf /mnt/etc/resolv.conf<br />
* Load the dm-mod module (you might need grub2-bios; install the package if needed):<br />
# modprobe dm-mod<br />
{{Note|This is necessary at this point, and cannot be postponed after the chroot. If you try to use modprobe in a chroot environment that has a later kernel version from that of the installing device (at the time of writing, 2.6.33), modprobe will fail. This happens routinely using the Arch "net" installations.}}<br />
* From the installer's live shell, chroot to the installed system:<br />
# mount -o bind /dev /mnt/dev<br />
# chroot /mnt bash<br />
* Update pacman's database:<br />
# pacman-db-upgrade<br />
* Refresh the package list (with an extra -y flag to force a refresh of all package lists even if they appear to be up to date):<br />
# pacman -Syy<br />
* Install the GRUB2 package as mentioned in the section [[#From a running Arch Linux]]. Note that the dm-mod module has already been loaded, no need to do that again.<br />
<br />
=== From a running Arch Linux ===<br />
<br />
====Make a backup of your precious data====<br />
In general, a grub installation ran smoothly and you got no problems at all. And sometimes it could simply messed up your system. You're strongly advised to make a backup before even think of grub2.<br />
<br />
# # copy grub modules and configuration<br />
# cp -a /boot/grub /path/to/backup/<br />
# # backup the MBR and GRUB stage 1.5<br />
# dd if=/dev/sda of=/path/to/backup/first-sectors count=63<br />
<br />
You could now lightly remove /boot/grub and follow the instructions below.You know that if things get nasty, you could reboot your system thanks to an installation media and :<br />
<br />
# # move old grub2 files out of the way<br />
# mv /boot/grub /boot/grub.nonfunctional<br />
# # copy grub back to /boot<br />
# cp -a /path/to/backup/grub /boot/<br />
# # replace MBR and next 62 sectors of sda with backed up copy (DANGEROUS!)<br />
# dd if=/path/to/backup/first-sectors of=/dev/sda count=63<br />
<br />
==== BIOS systems ====<br />
<br />
===== Preliminary Considerations for GRUB2 BIOS =====<br />
<br />
====== [[GPT]] specific instructions ======<br />
<br />
GRUB2 in BIOS-GPT configuration requires a BIOS Boot Partition to embed its core.img in the absence of post-MBR gap in GPT partitioned systems (which is taken over by the GPT Primary Header and Primary Partition table). This partition is used by GRUB2 only in BIOS-GPT setups. No such partition type exists in case of MBR partitioning (at least not for GRUB2). This partition is also not required if the system is UEFI based, as no embedding of bootsectors takes place in that case. Syslinux does not require this partition.<br />
<br />
For a BIOS-GPT configuration, create a 2 MiB partition using cgdisk or GNU Parted with no filesystem. The location of the partition in the partition table does not matter but it should be within the first 2 TiB region of the disk. It is advisable to put it somewhere in the beginning of the disk before the /boot partition. Set the partition type to "EF02" in cgdisk or {{Codeline|set <BOOT_PART_NUM> bios_grub on}} in GNU Parted.<br />
<br />
{{Note|This partition should be created before grub_bios-install or grub-setup is run or before the '''Install Bootloader''' step of the Archlinux installer (if GRUB2 is selected as bootloader).}}<br />
<br />
====== [[MBR]] aka msdos partitioning specific instructions ======<br />
<br />
Usually the post-MBR gap (after the 512 byte MBR region and before the start of the 1st partition) in many MBR (or msdos disklabel) partitioned systems is 32 KiB when DOS compatibility cylinder alignment issues are satisfied in the partition table. However a post-MBR gap of about 1 to 2 MiB is recommended to provide sufficient room for embedding grub2's core.img ( https://bugs.archlinux.org/task/24103 ). It is advisable to use a partitioner which supports 1 MiB partition alignment to obtain this space as well as satisfy other non-512 byte sector issues (which are unrelated to embedding of core.img).<br />
<br />
If you do not dual-boot with MS Windows (any version) in BIOS systems, it is advisable to switch to GPT partitioning - [[GUID_Partition_Table#Convert_from_MBR_to_GPT_without_data_loss]]<br />
{{Note|Create the 2MiB partition mentioned above BEFORE you convert to GPT. If you do not, gparted will not resize your boot partition to allow its creation, and when you reboot grub2 will not know where to look.}}<br />
<br />
===== Before grub_bios-install =====<br />
<br />
The GRUB2 package can be installed with pacman (and will replace {{Package Official|grub}}, if it is installed):<br />
<br />
# pacman -S grub2-bios<br />
<br />
{{Note|Installing grub2-common (a dependency of grub2-bios) 1.99~rc1 or later, may take forever in some systems since the post_install script runs grub-mkconfig and this script does not provide the option <code>--no-floppy</code>. For more details search this option in the article.}}<br />
<br />
{{Note|Simply installing the package won't update the /boot/grub/core.img file and the grub2 modules in /boot/grub . You need to update the core.img file and the grub2 modules manually using grub_bios-install as explained below.}}<br />
<br />
Also load the device-mapper kernel module without which grub-probe does not reliably detect disks and partitions<br />
<br />
# modprobe dm-mod<br />
<br />
<br />
===== Run grub_bios-install =====<br />
<br />
There are 3 ways to install grub2 in BIOS booting - [[#Install_to_440-byte_MBR_boot_code_region]] (recommended) , [[#Install_to_Partition_or_Partitionless_Disk]] (not recommended) or [[#Generate_core.img_alone]] (safest method, but requires another BIOS bootloader like [[grub-legacy]] or [[syslinux]] to be installed to chainload {{Filename|/boot/grub/core.img}} ). For all the ways [[#Before_grub_bios-install]] step is needed.<br />
<br />
====== Install to 440-byte MBR boot code region ======<br />
<br />
To setup grub2-bios in the 440-byte Master Boot Record boot code region, populate the {{Filename|/boot/grub}} directory, generate the {{Filename|/boot/grub/core.img}} file, and embed it in the 32 KiB (minimum size - varies depending on partition alignment) post-MBR gap (MBR disks) or in BIOS Boot Partition (GPT disks), run<br />
<br />
# grub_bios-install --boot-directory=/boot --no-floppy --recheck /dev/sda<br />
<br />
where {{Filename|/dev/sda}} is the destination of the installation (in this case the MBR of the first SATA disk). If you use [[LVM]] for your {{Filename|/boot}}, you can install GRUB2 on multiple physical disks. <br />
<br />
The {{Codeline|--no-floppy}} tells grub2-bios utilities not to search for any floppy devices which reduces the overall execution time of grub_bios-install on many systems (it will also prevent the issue below from occuring). Otherwise you get an error like this<br />
<br />
grub-probe: error: Cannot get the real path of '/dev/fd0'<br />
Auto-detection of a filesystem module failed.<br />
Please specify the module with the option '--modules' explicitly.<br />
<br />
Then:<br />
* Delete all the files from {{Filename|/boot/grub}} except {{Filename|/boot/grub/menu.lst}} .<br />
<br />
* Follow the [[#Install_to_440-byte_MBR_boot_code_region]] instructions.<br />
<br />
* Follow [[#Generate_GRUB2_BIOS_Config_file]] or if that fails, convert your {{Filename|/boot/grub/menu.lst}} file to {{Filename|/boot/grub/grub.cfg}} using:<br />
<br />
# grub-menulst2cfg /boot/grub/menu.lst /boot/grub/grub.cfg<br />
<br />
For example:<br />
<br />
{{File|name=/boot/grub/menu.lst|content=<br />
default=0<br />
timeout=5<br />
<br />
title Arch Linux Stock Kernel<br />
root (hd0,0)<br />
kernel /vmlinuz-linux root=/dev/sda2 ro<br />
initrd /initramfs-linux.img<br />
<br />
title Arch Linux Stock Kernel Fallback<br />
root (hd0,0)<br />
kernel /vmlinuz-linux root=/dev/sda2 ro<br />
initrd /initramfs-linux-fallback.img<br />
}}<br />
<br />
{{File|name=/boot/grub/grub.cfg|content=<br />
set default='0'; if [ x"$default" = xsaved ]; then load_env; set default="$saved_entry"; fi<br />
set timeout=5<br />
<br />
menuentry 'Arch Linux Stock Kernel' {<br />
set root='(hd0,1)'; set legacy_hdbias='0'<br />
legacy_kernel '/vmlinuz-linux' '/vmlinuz-linux' 'root=/dev/sda2' 'ro'<br />
legacy_initrd '/initramfs-linux.img' '/initramfs-linux.img'<br />
<br />
}<br />
<br />
menuentry 'Arch Linux Stock Kernel Fallback' {<br />
set root='(hd0,1)'; set legacy_hdbias='0'<br />
legacy_kernel '/vmlinuz-linux' '/vmlinuz-linux' 'root=/dev/sda2' 'ro'<br />
legacy_initrd '/initramfs-linux-fallback.img' '/initramfs-linux-fallback.img'<br />
}<br />
}}<br />
<br />
<br />
* If you forgot to create a GRUB2 {{Filename|/boot/grub/grub.cfg}} configfile and simply rebooted into GRUB2 Command Shell, type:<br />
<br />
sh:grub> insmod legacycfg<br />
sh:grub> legacy_configfile ${prefix}/menu.lst<br />
<br />
Boot into Arch and re-create the proper GRUB2 {{Filename|/boot/grub/grub.cfg}} configfile.<br />
<br />
{{Note|This option works only in BIOS systems, not in UEFI systems.}}<br />
<br />
====== Install to Partition or Partitionless Disk ======<br />
<br />
{{Note|grub2-bios (any version - including upstream bzr repo) does not encourage installation to a partition boot sector or a partitionless disk like grub-legacy or syslinux does. Neither do the Arch devs.}}<br />
<br />
To setup grub2-bios to a partition boot sector, to a partitionless disk (also called superfloppy) or to a floppy disk, run (using for example /dev/sda1 as the /boot partition)<br />
<br />
# chattr -i /boot/grub/core.img<br />
# grub_bios-install --boot-directory=/boot --no-floppy --recheck --force /dev/sda1<br />
# chattr +i /boot/grub/core.img<br />
<br />
You need to use the {{Codeline|--force}} option to allow usage of blocklists and should not use <code>--grub-setup=/bin/true</code> (which is similar to simply generating core.img).<br />
<br />
grub_bios-install will give out warnings like which should give you the idea of what might go wrong with this approach.<br />
<br />
/sbin/grub-setup: warn: Attempting to install GRUB to a partitionless disk or to a partition. This is a BAD idea.<br />
/sbin/grub-setup: warn: Embedding is not possible. GRUB can only be installed in this setup by using blocklists. <br />
However, blocklists are UNRELIABLE and their use is discouraged.<br />
<br />
Without {{Codeline|--force}} you may get the below error and grub-setup will not setup its boot code in the partition boot sector.<br />
<br />
/sbin/grub-setup: error: will not proceed with blocklists<br />
<br />
With {{Codeline|--force}} you should get<br />
<br />
Installation finished. No error reported.<br />
<br />
The reason why grub-setup does not by default allow this is because in case of partition or a partitionless disk is that grub2-bios relies on embedded blocklists in the partition bootsector to locate the {{Filename|/boot/grub/core.img}} file and the prefix dir {{Filename|/boot/grub}} . The sector locations of {{Filename|core.img}} may change whenever the filesystem in the partition is being altered (files copied, deleted etc.). For more info see https://bugzilla.redhat.com/show_bug.cgi?id=728742 and https://bugzilla.redhat.com/show_bug.cgi?id=730915 .<br />
<br />
The workaround for this is to set the immutable flag on {{Filename|/boot/grub/core.img}} (using chattr command as mentioned above) so that the sector locations of the {{Filename|core.img}} file in the disk is not altered. The immutable flag on {{Filename|/boot/grub/core.img}} needs to be set only if grub2-bios is installed to a partition boot sector or a partitionless disk, not in case of installtion to MBR or simple generation of {{Filename|core.img}} without embedding any bootsector (mentioned above). <br />
<br />
====== Generate core.img alone ======<br />
<br />
To populate the {{Filename|/boot/grub}} directory and generate a {{Filename|/boot/grub/core.img}} file WITHOUT embedding any grub2-bios bootsector code in the MBR, post-MBR region, or the partition bootsector, add <code>--grub-setup=/bin/true</code> to grub_bios-install:<br />
<br />
# grub_bios-install --grub-setup=/bin/true --boot-directory=/boot --no-floppy --recheck /dev/sda<br />
<br />
You can then chainload grub2's core.img from grub-legacy or syslinux as a Linux kernel or a multiboot kernel.<br />
<br />
===== After grub_bios-install =====<br />
<br />
====== Generate GRUB2 BIOS Config file ======<br />
<br />
Finally, generate a configuration for grub2 (this is explained in greater detail in the Configuration section):<br />
<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
If grub2 complains about "no suitable mode found" while booting, go to [[#Correct_GRUB2_No_Suitable_Mode_Found_Error]] .<br />
<br />
===== Multiboot in BIOS =====<br />
<br />
====== Boot Microsoft Windows installed in BIOS-MBR mode ======<br />
<br />
{{Note|GRUB2 supports booting {{Filename|bootmgr}} directly and chainload of partition boot sector is no longer required to boot Windows in a BIOS-MBR setup.}}<br />
<br />
Find the UUID of the NTFS filesystem of the Windows's SYSTEM PARTITION where the bootmgr and its files reside. For example, if Windows {{Filename|bootmgr}} exists at {{Filename|/media/Windows/bootmgr}}:<br />
<br />
# grub-probe --target=fs_uuid /media/Windows/bootmgr<br />
69B235F6749E84CE<br />
<br />
Then, add the below code to {{Filename|/boot/grub/grub.cfg}} to chainload Windows (Vista, 7 or 8) installed in BIOS-MBR mode :<br />
<br />
menuentry "Microsoft Windows 7 BIOS-MBR" {<br />
insmod part_msdos<br />
insmod ntfs<br />
insmod search_fs_uuid<br />
insmod ntldr <br />
search --fs-uuid --no-floppy --set=root 69B235F6749E84CE<br />
ntldr (${root})/bootmgr<br />
}<br />
<br />
For Windows XP<br />
<br />
menuentry "Microsoft Windows XP" {<br />
insmod part_msdos<br />
insmod ntfs<br />
insmod search_fs_uuid<br />
insmod ntldr <br />
search --fs-uuid --no-floppy --set=root 69B235F6749E84CE<br />
ntldr (${root})/ntldr<br />
}<br />
<br />
==== [[UEFI]] systems ====<br />
<br />
===== Before grub_efi_${UEFI_ARCH}-install =====<br />
<br />
{{Note|Unless specified as EFI 1.x , EFI and UEFI terms are used interchangeably to denote UEFI 2.x firmware. Also unless stated explicitely, the instructions are general and not Mac specific. Some of them may not work or may be different in Macs. Apple's EFI implementation is neither a EFI 1.x version nor UEFI 2.x version but mixes up both. This kind of firmware does not fall under any one UEFI Specification version and is therefore not a standard UEFI firmware.}}<br />
<br />
GRUB2 UEFI bootloader is available in Arch Linux only from version 1.99~rc1 . To install, first [https://wiki.archlinux.org/index.php/Unified_Extensible_Firmware_Interface#Detecting_UEFI_Firmware_Arch Detect which UEFI firmware arch] you have (either x86_64 or i386).<br />
<br />
Depending on that, install the appropriate package<br />
<br />
For 64-bit aka x86_64 UEFI firmware:<br />
# pacman -S grub2-efi-x86_64<br />
<br />
For 32-bit aka i386 UEFI firmware:<br />
# pacman -S grub2-efi-i386<br />
<br />
{{Note|Installing grub2-common (a dependency of grub2-bios) 1.99~rc1 or later, may take forever in some systems since the post_install script runs grub-mkconfig and this script does not provide the option <code>--no-floppy</code>. For more details search this option in the article.}}<br />
<br />
{{Note|Simply installing the package won't update the grub.efi file and the grub2 modules in the UEFI System Partition . You need to update the grub.efi file and the grub2 modules in the UEFI System Partition manually using grub_efi_${UEFI_ARCH}-install as explained below.}}<br />
<br />
Also load the device-mapper kernel module without which grub-probe does not reliably detect disks and partitions<br />
<br />
# modprobe dm-mod<br />
<br />
===== Install to UEFI SYSTEM PARTITION =====<br />
<br />
====== Mount UEFI SYSTEM PARTITION ======<br />
<br />
Mount the [https://wiki.archlinux.org/index.php/Unified_Extensible_Firmware_Interface#Creating_a_UEFI_SYSTEM_PARTITION_in_Linux UEFI SYSTEM PARTITION] in your system at {{Filename|/boot/efi}}. It should be FAT32 formatted and should be at least 200 MiB in size. If you have mounted the UEFISYS partition in some other mountpoint, replace {{Filename|/boot/efi}} in the below commands with that mountpoint:<br />
<br />
# mkdir -p /boot/efi<br />
# mount -t vfat <UEFISYS_PART_DEVICE> /boot/efi<br />
# mkdir -p /boot/efi/efi<br />
<br />
====== Run grub_efi_${UEFI_ARCH}-install ======<br />
<br />
{{Note|The below commands assume you are using {{Codeline|grub2-efi-x86_64}} (for {{Codeline|grub2-efi-i386}} replace {{Codeline|x86_64}} with {{Codeline|i386}} in the below commands).}}<br />
<br />
# grub_efi_x86_64-install --root-directory=/boot/efi --boot-directory=/boot/efi/efi --bootloader-id=grub --no-floppy --recheck<br />
<br />
The {{Codeline|grub_efi_x86_64-install}} automatically generates a {{Filename|grub.efi}} while setting up the {{Filename|/boot/efi/efi/grub/}} directory.<br />
<br />
If you notice carefully, there is no <device_path> option (Eg: {{Filename|/dev/sda}}) at the end of the {{Codeline|grub_efi_x86_64-install}} command unlike the case of setting up grub2 for BIOS systems. Any <device_path> provided will be ignored by the install script as UEFI bootloaders do not use MBR or Partition boot sectors at all.<br />
<br />
You may now be able to UEFI boot your system by creating a grub.cfg file using grub-mkconfig and copying /boot/efi/efi/grub/grub.efi to /boot/efi/efi/boot/bootx64.efi.<br />
<br />
===== After grub_efi_${UEFI_ARCH}-install =====<br />
<br />
====== Launch GRUB2 as default in non-Mac UEFI systems ======<br />
<br />
{{Note|The below steps will not work if the system has been booted in BIOS mode and will not work if the UEFI processor architecture does not match the kernel one, i.e. x86_64 UEFI + ix86 32-bit Kernel and vice-versa config will not work.}}<br />
<br />
grub_efi_${UEFI_ARCH}-install will ensure {{Filename|/boot/efi/efi/grub/grub.efi}} is launched by default if it detects {{Codeline|efibootmgr}} and if it is able to access UEFI Runtime Services. {{Codeline|efibootmgr}} command will work only if you have booted the system in UEFI mode itself, since it '''requires access to UEFI Runtime Variables''' which are '''available only in UEFI boot mode''' (with "noefi" kernel parameter NOT being used). Initially the user is required to manually launch {{Filename|/boot/efi/efi/grub/grub.efi}} from the firmware itself (using maybe the UEFI Shell) if grub2-efi was installed in BIOS mode. Then {{Codeline|efibootmgr}} should be run to make grub2 as the default entry in the UEFI Boot Manager<br />
<br />
First boot into UEFI mode manually either using the firmware boot menu, UEFI shell, or using any UEFI capable bootable iso (Archboot or Ubuntu non-Mac iso). Use grub probe to determine the device path of your EFI System Partition:<br />
# grub-probe --target=device /boot/efi/efi/grub/grub.efi<br />
<br />
It should give something like {{Filename|/dev/sda1}} (used as example in the remaining steps). Load 'efivars' kernel module:<br />
# modprobe efivars<br />
<br />
If you get '''no such device found''' error for this command, that means you have not booted in UEFI mode or due to some reason the kernel is unable to access UEFI Runtime Variables.<br />
<br />
Verify whether there are files in ''/sys/firmware/efi/vars/'' directory. This directory and its contents are created by "efivars" kernel module and it will exist only if you have booted in UEFI mode without the "noefi" kernel parameter.<br />
<br />
# ls -1 /sys/firmware/efi/vars/<br />
<br />
Sample output (x86_64-UEFI 2.3.1 in x86_64 Kernel:<br />
<br />
# ls -1 /sys/firmware/efi/vars/<br />
Boot0000-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootCurrent-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootOptionSupport-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootOrder-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConIn-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConInDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConOut-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConOutDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ErrOutDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
Lang-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
LangCodes-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
MTC-eb704011-1402-11d3-8e77-00a0c969723b/<br />
MemoryTypeInformation-4c19049f-4137-4dd3-9c10-8b97a83ffdfa/<br />
PlatformLang-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
PlatformLangCodes-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
RTC-378d7b65-8da9-4773-b6e4-a47826a833e1/<br />
del_var<br />
new_var<br />
<br />
If ''/sys/firmware/efi/vars/'' directory is empty or does not exist, then {{Codeline|efibootmgr}} command will not work. If you are unable to make the ISO/CD/DVD/USB boot in UEFI mode try https://gitorious.org/tianocore_uefi_duet_builds/pages/Linux_Windows_BIOS_UEFI_boot_USB .<br />
<br />
If ''/sys/firmware/efi/vars/'' directory (along with the exists then run {{Codeline|efibootmgr}} and reboot:<br />
<br />
# efibootmgr --create --gpt --disk /dev/sda --part 1 --write-signature --label "GRUB2" --loader "\\EFI\\grub\\grub.efi"<br />
<br />
In the above command, {{Filename|/boot/efi/efi/grub/grub/efi}} can be split up as {{Filename|/boot/efi}} and {{Filename|/efi/grub/grub.efi}}, which translates to {{Filename|(/dev/sda)}} -> partition 1 -> {{Filename|\\EFI\\grub\\grub.efi}}. <br />
<br />
FAT32 filesystem is case-insensitive since it does not use UTF-8 encoding by default. In that case the firmware uses capital 'EFI' instead of small 'efi', therefore using {{Filename|\\EFI\\grub\\grub.efi}} or {{Filename|\\efi\\grub\\grub.efi}} does not matter (this will change if the filesystem encoding is UTF-8). UEFI uses backward slash as path separatoir (similar to Windows paths). In the above command "double" backward slashes are used instead of single ones, since a backward slash is used as a escape character by sh shells, the first backward slash escapes the second one so that the path {{Filename|\EFI\grub\grub.efi}} is passed to {{Codeline|efibootmgr}}.<br />
<br />
The 'label' is the name of the menu entry shown in the UEFI boot menu. This name is user's choice and does not affect the booting of the system. More info can be obtained from [http://linux.dell.com/cgi-bin/gitweb/gitweb.cgi?p=efibootmgr.git;a=blob_plain;f=README;hb=HEAD efibootmgr GIT README]<br />
<br />
If you have problems running GRUB2 in UEFI mode you can try the following (worked on an ASUS Z68 mainboard):<br />
<br />
# cp /boot/efi/efi/grub/grub.efi /boot/efi/shellx64.efi<br />
<br />
or<br />
<br />
# cp /boot/efi/efi/grub/grub.efi /boot/efi/efi/shellx64.efi<br />
or<br />
<br />
# cp /boot/efi/efi/grub/grub.efi /boot/efi/efi/shell/shellx64.efi<br />
<br />
After this launch the UEFI Shell from the UEFI setup/menu (in ASUS UEFI BIOS, switch to advanced mode, press Exit in the top right corner and choose "Launch EFI shell from filesystem device"). The grub2 menu will show up and you can boot into your system. Afterwards you can use efibootmgr to setup a menu entry (see above).<br />
<br />
====== Launch GRUB2 as default in Apple Mac EFI systems ======<br />
<br />
{{Note|Using {{Filename|efibootmgr}} in Apple Macs will brick the firmware and may need reflash of the motherboard ROM. There have been bug reports regarding this in Ubuntu/Launchpad bug tracker. Use bless command alone in case of Macs}}<br />
<br />
Use bless command from within Mac OS X to setup {{Filename|grub.efi}} as the default boot option. More info at https://help.ubuntu.com/community/UEFIBooting#Apple_Mac_EFI_systems_.28both_EFI_architecture.29 .<br />
<br />
====== Generate GRUB2 UEFI Config file ======<br />
<br />
Finally, generate a configuration for grub2 (this is explained in greater detail in the Configuration section):<br />
<br />
# grub-mkconfig -o /boot/efi/efi/grub/grub.cfg<br />
<br />
If grub2-uefi complains about "no suitable mode found" while booting, go to [[#Correct_GRUB2_No_Suitable_Mode_Found_Error]] .<br />
<br />
===== Generate a custom GRUB2 UEFI Application =====<br />
<br />
If you want, you can create a custom {{Filename|grub_custom.efi}} app using:<br />
# grub-mkimage -d /usr/lib/grub/x86_64-efi -O x86_64-efi -p "" -o /boot/efi/efi/grub/grub_custom.efi <GRUB2_Modules_to_be_included><br />
<br />
{{Note|The '''-p''' option is important for creating a portable {{Filename|grub_custom.efi}} app.}}<br />
<br />
There is no file-size restriction on {{Filename|grub_custom.efi}} either due to GRUB2 or due to the UEFI firmware. Therefore you can include any number of modules you want.<br />
<br />
A "{{Filename|grub.cfg}}" created for BIOS based GRUB2 will be sufficient for the UEFI GRUB2 as long as all the paths in the config are absolute paths. The {{Filename|grub.cfg}} file should exist in the same directory as {{Filename|grub.efi}} or {{Filename|grub_custom.efi}}.<br />
<br />
The {{Filename|grub.efi}} UEFI application can be launched using the firmware's "Boot Manager", "Boot from file" option or using the [https://wiki.archlinux.org/index.php/UEFI#UEFI_Shell UEFI Shell].<br />
<br />
Alternatively, you can also setup {{Filename|/boot/efi/efi/grub}} directory by copying all the files in {{Filename|/usr/lib/grub/x86_64-efi}} to {{Filename|/boot/efi/efi/grub}} and using the above grub-mkimage command to create a {{Filename|grub_custom.efi}} application. Just make sure you have the required modules embedded in {{Filename|grub_custom.efi}} to enable it to access the EFI SYSTEM PARTITION.<br />
<br />
A basic {{Filename|grub_custom.efi}} can be generated using the following command:<br />
# sudo grub-mkimage -d /usr/lib/grub/x86_64-efi -O x86_64-efi -p "" -o /boot/efi/efi/grub/grub_custom.efi part_gpt fat iso9660 udf normal chain linux \<br />
ls search search_fs_file search_fs_uuid search_label help boot configfile echo efi_gop<br />
<br />
===== Multiboot in UEFI =====<br />
<br />
====== Chainload Microsoft Windows x86_64 UEFI-GPT ======<br />
<br />
Find the UUID of the FAT32 filesystem in the UEFI SYSTEM PARTITION where the Windows UEFI Bootloader files reside. For example, if Windows {{Filename|bootmgfw.efi}} exists at {{Filename|/boot/efi/efi/Microsoft/Boot/bootmgfw.efi}} (ignore the upper-lower case differences since that is immaterial in FAT filesystem):<br />
<br />
# grub-probe --target=fs_uuid /boot/efi/efi/Microsoft/Boot/bootmgfw.efi<br />
1ce5-7f28<br />
<br />
Then, add this code to {{Filename|/boot/efi/efi/grub/grub.cfg}} to chainload Windows x86_64 (Vista SP1+, 7 or 8) installed in UEFI-GPT mode :<br />
<br />
menuentry "Microsoft Windows x86_64 UEFI-GPT" {<br />
insmod part_gpt<br />
insmod fat<br />
insmod search_fs_uuid<br />
insmod chain<br />
search --fs-uuid --no-floppy --set=root 1ce5-7f28<br />
chainloader (${root})/efi/Microsoft/Boot/bootmgfw.efi<br />
}<br />
<br />
== Manual Compilation ==<br />
<br />
=== For BIOS Systems ===<br />
<br />
GRUB2 for BIOS systems should be compiled as follows:<br />
<pre><br />
./autogen.sh<br />
<br />
./configure --with-platform=pc --prefix=/usr<br />
<br />
make<br />
<br />
make install<br />
</pre><br />
<br />
The <code>--with-platform=pc</code> generates grub2 for bios alone irrespective of the firmware of the build system.<br />
<br />
=== For UEFI Systems ===<br />
<br />
First [https://wiki.archlinux.org/index.php/Unified_Extensible_Firmware_Interface#Detecting_UEFI_Firmware_Arch Detect which UEFI Firmware arch] you have and then follow the compile instructions below:<br />
<pre><br />
./autogen.sh<br />
<br />
./configure --with-platform=efi --target=TARGET_UEFI_ARCH --prefix=/usr<br />
<br />
make<br />
<br />
make install<br />
</pre><br />
<br />
The "--target" option denotes the UEFI firmware arch. for which grub2 should be compiled, not the architecture of the linux kernel grub2 may boot. <br />
<br />
It is possible to use UEFI 64-bit firmware + GRUB2 as x86_64-EFI app loading a i686 linux kernel, as long as the kernel does not try to access UEFI Runtime Services. Vice-versa situation is also possible. But a x86_64 UEFI firmware cannot launch GRUB2 i386-efi app (unlike x86_64 Operating Systems), and a i386 UEFI firmware will not launch GRUB2 {{Codeline|x86_64-efi}} app. It is important to compile GRUB2 to match the architecture of the UEFI firmware.<br />
<br />
== Configuration ==<br />
<br />
The configuration files are {{Filename|/etc/default/grub}} and {{Filename|/etc/grub.d/*}}. These files are used to generate the {{Filename|/boot/grub/grub.cfg}} file. You can also choose to manually edit {{Filename|grub.cfg}}.<br />
<br />
=== grub-mkconfig ===<br />
<br />
The grub-mkconfig script can be used to generate a {{Filename|grub.cfg}} file. By default the script outputs to stdout. Note that gettext ― an optional dependency of the GRUB2 package ― is required by the grub-mkconfig script. To generate a {{Filename|grub.cfg}} file run the command:<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
Note that grub-mkconfig probably has your grub directory hardcoded to /boot/grub, which is probably wrong if you're using UEFI. Either mount your efi grub directory at /boot/grub or edit the script.<br />
<br />
=== grub.cfg ===<br />
<br />
A basic grub file uses the following options<br />
* {{Codeline|(hdX,Y)}} is the partition {{Codeline|Y}} on disk {{Codeline|X}}, partition numbers starting at 1, disk numbers starting at 0<br />
* {{Codeline|1=set default=N}} is the default boot entry that is chosen after timeout for user action<br />
* {{Codeline|1=set timeout=M}} is the time {{Codeline|M}} to wait in seconds for a user selection before default is booted<br />
* {{Codeline|<nowiki>menuentry "title" {entry options}</nowiki>}} is a boot entry titled {{Codeline|title}}<br />
* {{Codeline|1=set root=(hdX,Y)}} sets the boot partition, where the kernel and GRUB modules are stored (boot need not be a separate partition, and may simply be a directory under the "root" partition ({{Filename|/}})<br />
<br />
An example configuration:<br />
<br />
{{File<br />
|name=/boot/grub/grub.cfg<br />
|content=<nowiki><br />
# Config file for GRUB2 - The GNU GRand Unified Bootloader<br />
# /boot/grub/grub.cfg<br />
<br />
# DEVICE NAME CONVERSIONS<br />
#<br />
# Linux Grub<br />
# -------------------------<br />
# /dev/fd0 (fd0)<br />
# /dev/sda (hd0)<br />
# /dev/sdb2 (hd1,2)<br />
# /dev/sda3 (hd0,3)<br />
#<br />
<br />
# Timeout for menu<br />
set timeout=5<br />
<br />
# Set default boot entry as Entry 0<br />
set default=0<br />
<br />
# (0) Arch Linux<br />
menuentry "Arch Linux" {<br />
set root=(hd0,1)<br />
linux /vmlinuz-linux root=/dev/sda3 ro<br />
initrd /initramfs-linux.img<br />
}<br />
<br />
## (1) Windows<br />
#menuentry "Windows" {<br />
#set root=(hd0,3)<br />
#chainloader +1<br />
#}<br />
</nowiki>}}<br />
<br />
=== Dual-booting ===<br />
<br />
''NOTE: If you want GRUB2 to automatically search for other systems, for example as in Ubuntu. Then you may need to download {{Package AUR|os-prober}} from the [[AUR]].''<br />
<br />
==== Using grub-mkconfig ====<br />
The best way to add other entries is editing the {{Filename|/etc/grub.d/40_custom}}. The entries in this file will be automatically added when running '''grub-mkconfig'''.<br />
After adding the new lines, run:<br />
# grub-mkconfig -o /boot/grub/grub.cfg <br />
to generate an updated {{Filename|grub.cfg}}.<br />
<br />
===== With GNU/Linux =====<br />
<br />
Assuming that the other distro is on partition {{Filename|sda2}}:<br />
<br />
menuentry "Other Linux" {<br />
set root=(hd0,2)<br />
linux /boot/vmlinuz (add other options here as required)<br />
initrd /boot/initrd.img (if the other kernel uses/needs one)<br />
}<br />
<br />
===== With Windows =====<br />
<br />
This assumes that your Windows partition is {{Filename|sda3}}.<br />
<br />
# (2) Windows XP<br />
menuentry "Windows XP" {<br />
set root=(hd0,3)<br />
chainloader (hd0,3)+1<br />
}<br />
<br />
If the windows bootloader is on an entirely different harddrive than grub, it may be necessary to trick Windows into believing that it is in fact the first harddrive. This was possible in the old grub with {{Codeline|map}} and is now done with {{Codeline|drivemap}}. Assume grub is on {{Filename|hd0}} and windows on {{Filename|hd2}}, you need to add the following after {{Codeline|set root}}:<br />
<br />
drivemap -s hd0 hd2<br />
<br />
==== With Windows via EasyBCD and NeoGRUB ====<br />
<br />
Since EasyBCD's NeoGRUB currently does not understand the GRUB2 menu format, chainload to it by replacing the contents of your {{Filename|C:\NST\menu.lst}} file with lines similar to the following:<br />
<br />
default 0<br />
timeout 1<br />
<br />
title Chainload into GRUB v2<br />
root (hd0,7)<br />
kernel /boot/grub/core.img<br />
<br />
===Visual Configuration===<br />
<br />
In GRUB2 it is possible, by default, to change the look of the menu.<br />
<br />
====Background image and bitmap fonts====<br />
<br />
GRUB2 comes with support for background images and bitmap fonts in pf2 format. The unifont font is included in the grub2 package under the filename {{Filename|unicode.pf2}}, or, as only ascii characters under the name {{Filename|ascii.pf2}}. Image formats supported include tga, png and jpeg, providing the correct modules are loaded. The maximum supported resolution depends on your hardware. There are two ways of setting a {{Filename|tga}} file as background. Two sample configurations are shown below.<br />
<br />
Edit {{Filename|/etc/default/grub}} like this:<br />
GRUB_GFXMODE=1024x768x32<br />
GRUB_GFXPAYLOAD_LINUX=keep<br />
GRUB_BACKGROUND="/boot/grub/archlinux.tga"<br />
#GRUB_THEME="/path/to/gfxtheme"<br />
<br />
(archlinux.tga is a placeholder; put your file name there)<br />
<br />
To generate the changes, run: <br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
{{Note|If this example does not work for you try to replace {{Codeline|1=gfxmode="1024x768x32"}} by {{Codeline|1=vbemode="0x105"}}.}}<br />
{{Note|To show all the modes you can use {{Codeline|1=# hwinfo --framebuffer}} (hwinfo is available in [community]), while at grub2 prompt you can use the {{Codeline|1=vbeinfo}} command.}}<br />
{{Note|If you have installed Grub on a separate partition, {{Filename|/boot/grub/archlinux.tga}} becomes {{Filename|/grub/archlinux.tga}}.}}<br />
<br />
====Menu colors====<br />
<br />
As in Grub (0.9x), you can change the menu colors in Grub2. The available colors for GRUB2 are at http://www.gnu.org/software/grub/manual/html_node/Theme-file-format.html#Theme-file-format . <br />
Here is an example:<br />
<br />
Edit {{Filename|/etc/default/grub}}:<br />
GRUB_COLOR_NORMAL="light-blue/black"<br />
GRUB_COLOR_HIGHLIGHT="light-cyan/blue"<br />
<br />
Generate the changes:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
====Hidden menu====<br />
<br />
One of the unique features of Grub2 is hiding/skipping the menu and showing it by holding "Shift" when needed. You can also adjust whether you want to see the timeout counter.<br />
<br />
Edit {{Filename|/etc/default/grub}} as you wish. Here is an example where the comments from the beginning of the two lines have been removed to enable the feature, the timeout has been set to five seconds and to be shown to the user:<br />
GRUB_HIDDEN_TIMEOUT=5<br />
GRUB_HIDDEN_TIMEOUT_QUIET=false<br />
<br />
and run:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
====Setting the framebuffer resolution ====<br />
<br />
Grub2 can set the framebuffer for both grub2 itself and the kernel. The old ''vga='' way is deprecated. The preferred method is editing {{Filename|/etc/default/grub}} as the following sample:<br />
<br />
GRUB_GFXMODE=1024x768x32<br />
GRUB_GFXPAYLOAD_LINUX=keep<br />
<br />
To generate the changes, run: <br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
The {{Codeline|gfxpayload}} property will make sure the kernel keeps the resolution.<br />
<br />
If this method does not work for you, the deprecated <code>vga=</code> method will still work. Just<br />
add it next to the <code>"GRUB_CMDLINE_LINUX_DEFAULT="</code> line in {{Filename|/etc/default/grub}}<br />
for eg: <code>"GRUB_CMDLINE_LINUX_DEFAULT="quiet splash vga=792"</code> will give you a {{Codeline|1024x768}} resolution.<br />
<br />
You can choose one of these resolutions: {{Codeline|640×480}}, {{Codeline|800×600}}, {{Codeline|1024×768}}, {{Codeline|1280×1024}}, {{Codeline|1600×1200}}<br />
<br />
=== Other Options ===<br />
<br />
==== LVM ====<br />
<br />
If you use [[LVM]] for your {{Filename|/boot}}, add the following before menuentry lines:<br />
<br />
insmod lvm<br />
<br />
and specify your root in the menuentry as:<br />
<br />
set root=(''lvm_group_name''-''lvm_logical_boot_partition_name'')<br />
<br />
Example:<br />
<br />
# (0) Arch Linux<br />
menuentry "Arch Linux" {<br />
insmod lvm<br />
set root=(VolumeGroup-lv_boot)<br />
# you can only set following two lines<br />
linux /vmlinuz-linux root=/dev/mapper/VolumeGroup-root ro<br />
initrd /initramfs-linux.img<br />
}<br />
<br />
==== Raid ====<br />
<br />
Grub2 provides convenient handling of raid-volumes. You need to add:<br />
insmod raid<br />
<br />
which allows you to address the volume natively. E.g. {{Filename|/dev/md0}} becomes:<br />
set root=(md0)<br />
<br />
whereas a partitioned raid-volume (e.g. {{Filename|/dev/md0p1}}) becomes:<br />
set root=(md0,1)<br />
<br />
==== Persistent block device naming ====<br />
You can use UUIDs to detect partitions instead of the "old" {{Filename|/dev/sd*}} and {{Filename|/dev/hd*}} scheming. It has the advantage of detecting partitions by their unique UUIDs, which is needed by some people booting with complicated partition setups.<br />
<br />
UUIDs are used by default in the recent versions of grub2 - there is no downside in it anyway except that you need to re-generate the {{Filename|grub.cfg}} file every time you resize or reformat your partitions. Remember this when modifying partitions with Live-CD.<br />
<br />
The recent versions of grub2 use UUIDs by default. You can re-enable the use of UUIDS by simply commenting the UUID line (this is also what it looks like by default):<br />
#GRUB_DISABLE_LINUX_UUID=true<br />
you can also just set the value as {{Codeline|false}} as shown here:<br />
GRUB_DISABLE_LINUX_UUID=false<br />
<br />
Either way, do not forget to generate the changes:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
==== Using Labels ====<br />
<br />
It is possible to use labels, human-readable strings attached to filesystems, by using the {{Codeline|--label}} option to {{Codeline|search}}. First of all, label your existing partition:<br />
# tune2fs -L a <LABEL> <PARTITION><br />
<br />
Then, add an entry using labels. An example of this:<br />
<br />
menuentry "Arch Linux, session texte" {<br />
search --label --no-floppy --set=root archroot<br />
linux /boot/vmlinuz-linux root=/dev/disk/by-label/archroot ro<br />
initrd /boot/initramfs-linux.img<br />
}<br />
<br />
==== Recall previous entry ====<br />
<br />
Grub2 can remember the last entry you booted from and use this as the default entry to boot from next time. This is useful if you have multiple kernels (i.e., the current Arch one and the LTS kernel as a fallback option) or operating systems. To do this, edit {{Filename|/etc/default/grub}} and change the setting of {{Codeline|GRUB_DEFAULT}}:<br />
<br />
GRUB_DEFAULT=saved<br />
<br />
This ensures that grub will default to the saved entry. To enable saving the selected entry, add the following line to {{Filename|/etc/default/grub}}:<br />
<br />
GRUB_SAVEDEFAULT=true<br />
<br />
Remember to regenerate your configuration file.<br />
<br />
==== Security ====<br />
<br />
If you want to secure GRUB2 so it is not possible for anyone to change boot parameters or use the command line, you can add a user/password combination to GRUB2's configuration files. To do this, run the command {{Codeline|grub-mkpasswd_pbkdf2}}. Enter a password and confirm it. The output will look like this:<br />
<br />
<pre style='overflow:auto'><br />
Your PBKDF2 is grub.pbkdf2.sha512.10000.C8ABD3E93C4DFC83138B0C7A3D719BC650E6234310DA069E6FDB0DD4156313DA3D0D9BFFC2846C21D5A2DDA515114CF6378F8A064C94198D0618E70D23717E82.509BFA8A4217EAD0B33C87432524C0B6B64B34FBAD22D3E6E6874D9B101996C5F98AB1746FE7C7199147ECF4ABD8661C222EEEDB7D14A843261FFF2C07B1269A</pre>Then, add the following to {{Filename|/etc/grub.d/00_header}}:<br />
<pre>cat << EOF<br />
<br />
set superusers="username"<br />
password_pbkdf2 username <password><br />
<br />
EOF</pre><br />
where <password> is the string generated by {{Codeline|grub-mkpasswd_pbkdf2}}.<br />
<br />
Regenerate your configuration file. Your GRUB2 command line and boot parameters are now protected.<br />
<br />
=== Booting an Ubuntu ISO Image from the GRUB2 Screen ===<br />
<br />
Edit {{Filename|/etc/grub.d/40_custom}} to add an entry pointing to an Ubuntu iso:<br />
<br />
menuentry "ubuntu-11.04-desktop-amd64.iso" {<br />
set isofile="/path/to/ubuntu-11.04-desktop-amd64.iso"<br />
loopback loop (hdX,Y)$isofile<br />
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile quiet noeject noprompt splash --<br />
initrd (loop)/casper/initrd.lz<br />
}<br />
<br />
Be sure to adjust the "hdX,Y" in the third line to point to the correct disk/partition number of the isofile. When finished, update grub2's configuration file via:<br />
<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
== Using the command shell ==<br />
<br />
Since the MBR is too small to store all GRUB2 modules, only the menu and a few basic commands reside there. The majority of GRUB2 functionality remains in modules in {{Filename|/boot/grub}}, which are inserted as needed. In error conditions (e.g. if the partition layout changes) GRUB2 may fail to boot. When this happens, a command shell may appear.<br />
<br />
GRUB2 offers multiple shells/prompts. If there is a problem reading the menu but the bootloader is able to find the disk, you will likely be dropped to the "normal" shell:<br />
sh:grub><br />
<br />
If there is a more serious problem (e.g. GRUB cannot find required files), you may instead be dropped to the "rescue" shell:<br />
grub rescue><br />
<br />
The rescue shell is a restricted subset of the normal shell, offering much less functionality. If dumped to the rescue shell, first try inserting the "normal" module, then starting the "normal" shell:<br />
grub rescue> set prefix=(hdX,Y)/boot/grub<br />
grub rescue> insmod (hdX,Y)/boot/grub/normal.mod<br />
rescue:grub> normal<br />
<br />
=== Pager support ===<br />
<br />
GRUB2 supports pager for reading commands that provide long output (like the help command). This works only in normal shell mode and not in rescue mode. To enable pager, in GRUB2 command shell type:<br />
sh:grub> set pager=1<br />
<br />
== GUI configuration tools ==<br />
<br />
Following package may be installed from [[AUR]]<br />
* [http://kde-apps.org/content/show.php?content=139643 grub2-editor] (requires kdelibs)<br />
*:A KDE4 control module for configuring the GRUB2 bootloader<br />
* [http://kde-apps.org/content/show.php?content=137886 kcm-grub2] (requires kdelibs python2-qt kdebindings-python)<br />
*:This Kcm module manages the most common settings of Grub2.<br />
* [http://sourceforge.net/projects/startup-manager/ startupmanager] (requires gnome-python imagemagick yelp python2 xorg-xrandr)<br />
*:GUI app for changing the settings of GRUB, GRUB2, Usplash and Splashy<br />
<br />
== parttool or legacy hide/unhide ==<br />
<br />
If you have a win9x paradigm with hidden C disks GRUB legacy had the hide/unhide feature. In GRUB2 this has been replaced by parttool. For example, to boot the third C disk of three win9x installations on the CLI enter the CLI and:<br />
parttool hd0,1 hidden+ boot-<br />
parttool hd0,2 hidden+ boot-<br />
parttool hd0,3 hidden- boot+<br />
set root=hd0,3<br />
chainloader +1<br />
boot<br />
<br />
== Using the rescue console ==<br />
<br />
See [[#Using the command shell]] first. If unable to activate the standard shell, one possible solution is to boot using a live CD or some other rescue disk to correct configuration errors and reinstall GRUB. However, such a boot disk is not always available (nor necessary); the rescue console is surprisingly robust.<br />
<br />
The available commands in GRUB rescue include "insmod", "ls", "set", and "unset". This example uses "set" and "insmod". "set" modifies variables and "insmod" inserts new modules to add functionality.<br />
<br />
Before starting, the user must know the location of their {{Filename|/boot}} partition (be it a separate partition, or a subdirectory under their root):<br />
grub rescue> set prefix=(hdX,Y)/boot/grub<br />
<br />
where X is the physical drive number and Y is the partition number.<br />
<br />
To expand console capabilities, insert the "linux" module:<br />
grub rescue> insmod (hdX,Y)/boot/grub/linux.mod<br />
<br />
{{Note|With a separate boot partition, omit {{Filename|/boot}} from the path, (i.e. type {{Codeline|1=set prefix=(hdX,Y)/grub}} and {{Codeline|insmod (hdX,Y)/grub/linux.mod}}).}}<br />
<br />
This introduces the "linux" and "initrd" commands, which should be familiar (see [[#Configuration]]).<br />
<br />
An example, booting Arch Linux:<br />
set root=(hd0,5)<br />
linux /boot/vmlinuz-linux root=/dev/sda5<br />
initrd /boot/initramfs-linux.img<br />
boot<br />
<br />
With a separate boot partition, again change the lines accordingly:<br />
set root=(hd0,5)<br />
linux /vmlinuz-linux root=/dev/sda6<br />
initrd /initramfs-linux.img<br />
boot<br />
<br />
After successfully booting the Arch Linux installation, users can correct {{Filename|grub.cfg}} as needed and then run:<br />
# grub-install /dev/sda --no-floppy<br />
<br />
to reinstall GRUB2 and fix the problem completely, changing {{Filename|/dev/sda}} if needed. See [[#Bootloader installation]] for details.<br />
<br />
== Combining the use of UUID's and basic scripting ==<br />
<br />
If you like the idea of using UUID's to avoid unreliable BIOS mappings or are struggling with Grub's syntax, here is an example boot menu item that uses UUID's and a small script to direct Grub to the proper disk partitions for your system. All you need to do is replace the UUID's in the sample with the correct UUID's for your system. (The example applies to a system with a boot and root partition. You will obviously need to modify the Grub configuration if you have additional partitions.)<br />
<br />
menuentry "Arch Linux 64" {<br />
#Enter the UUID of your boot partition (this is where Grub and your kernel reside)<br />
set uuid_grub_boot=ece0448f-bb08-486d-9864-ac3271bd8d07<br />
<br />
#Enter the UUID of the partition containing the root partition of your Arch Linux installation. <br />
set uuid_os_root=c55da16f-e2af-4603-9e0b-03f5f565ec4a<br />
<br />
#(Note: this may be the same as your boot partition)<br />
<br />
#Here we set the Grub "root" variable by locating the UUID of the root partition identified above <br />
search --fs-uuid --no-floppy --set=root $uuid_os_root<br />
<br />
#Here we set a custom variable grub_boot by locating the UUID of the boot partition identified above <br />
search --fs-uuid --no-floppy --set=grub_boot $uuid_grub_boot<br />
<br />
#Here is the magic. We test to see if the boot and root partitions have the same UUID.<br />
#If they do, we append /boot to the $grub_boot variable. For ex. (hd0,1) becomes (hd0,1)/boot.<br />
if [ $uuid_grub_boot == $uuid_os_root ] ; then<br />
set grub_boot=$grub_boot/boot<br />
fi<br />
<br />
# $grub_boot now points to the correct location, so the following will properly find the kernel and initrd<br />
linux ($grub_boot)/vmlinuz-linux root=/dev/disk/by-uuid/$uuid_os_root ro<br />
initrd ($grub_boot)/initramfs-linux.img<br />
}<br />
<br />
== Troubleshooting ==<br />
<br />
Any troubleshooting should be added here.<br />
<br />
=== Enable GRUB2 debug messages ===<br />
<br />
Add<br />
<br />
set pager=1<br />
set debug=all<br />
<br />
to {{Filename|grub.cfg}}.<br />
<br />
=== Correct GRUB2 No Suitable Mode Found Error ===<br />
<br />
If you get this error when booting any menuentry<br />
<br />
error: no suitable mode found<br />
Booting however<br />
<br />
Then you need to initialize grub2 graphical terminal (gfxterm) with proper video mode (gfxmode) in grub2. This video mode is passed by grub2 to the linux kernel via 'gfxpayload'. In case of UEFI systems, if the grub2 video mode is not initialized, no kernel boot messages will be shown in the terminal (atleast until KMS kicks in)<br />
<br />
Copy {{Filename|/usr/share/grub/unicode.pf2}} to ${GRUB2_PREFIX_DIR} ({{Filename|/boot/grub/}} in case of BIOS systems and {{Filename|/boot/efi/efi/grub/}} in case of UEFI systems). <br />
<br />
# cp /usr/share/grub/unicode.pf2 ${GRUB2_PREFIX_DIR}<br />
<br />
If {{Filename|/usr/share/grub/unicode.pf2}} does not exist, install {{Package Official|bdf-unifont}}, create the unifont.pf2 file and then copy it to ${GRUB2_PREFIX_DIR} .<br />
<br />
# grub-mkfont -o unicode.pf2 /usr/share/fonts/misc/unifont.bdf<br />
<br />
Then, in the {{Filename|grub.cfg}} file, add the following lines to enable grub2 to pass the video mode correctly to the kernel, without of which you will only get a black screen (no output) but booting (actually) proceeds successfully without any system hang:<br />
<br />
BIOS systems<br />
<br />
insmod vbe<br />
<br />
UEFI systems<br />
<br />
insmod efi_gop<br />
insmod efi_uga<br />
<br />
After that add the following code (common to both BIOS and UEFI)<br />
<br />
insmod font<br />
<br />
if loadfont ${prefix}/unicode.pf2<br />
then<br />
insmod gfxterm<br />
set gfxmode=auto<br />
set gfxpayload=keep<br />
terminal_output gfxterm<br />
fi<br />
<br />
As you can see for gfxterm (graphical terminal) to function properly, {{Filename|unicode.pf2}} font file should exist in ${GRUB2_PREFIX_DIR}.<br />
<br />
=== msdos-style error message ===<br />
<br />
grub-setup: warn: This msdos-style partition label has no post-MBR gap; embedding won't be possible!<br />
grub-setup: warn: Embedding is not possible. GRUB can only be installed in this setup by using blocklists.<br />
However, blocklists are UNRELIABLE and its use is discouraged.<br />
grub-setup: error: If you really want blocklists, use --force.<br />
<br />
This error may occur when you try installing GRUB2 in a VMware container. Read more about it [http://bbs.archlinux.org/viewtopic.php?pid=581760#p581760 here]. It happens when the first partition starts just after the MBR (block 63), without the usual space of 1 MiB (2048 blocks) before the first partition. Read [[#MBR_aka_msdos_partitioning_specific_instructions]]<br />
<br />
=== UEFI GRUB2 not loaded ===<br />
In some cases the EFI may fail to load grub correctly. Provided everything is set up correctly, the output of<br />
efibootmgr -v<br />
might look something like this:<br />
BootCurrent: 0000<br />
Timeout: 3 seconds<br />
BootOrder: 0000,0001,0002<br />
Boot0000* Grub HD(1,800,32000,23532fbb-1bfa-4e46-851a-b494bfe9478c)File(\efi\grub\grub.efi)<br />
Boot0001* Shell HD(1,800,32000,23532fbb-1bfa-4e46-851a-b494bfe9478c)File(\EfiShell.efi)<br />
Boot0002* Festplatte BIOS(2,0,00)P0: SAMSUNG HD204UI .<br />
If everything works correctly, the EFI would now automatically load grub.<br><br />
If the screen only goes black for a second and the next boot option is tried afterwards, according to [https://bbs.archlinux.org/viewtopic.php?pid=981560#p981560 this post], moving grub to the partition root can help. The boot option has to be deleted and recreated afterwards. The entry for grub should look like this then:<br />
Boot0000* Grub HD(1,800,32000,23532fbb-1bfa-4e46-851a-b494bfe9478c)File(\grub.efi)<br />
<br />
=== Invalid signature ===<br />
If trying to boot windows results in an "invalid signature" error, e.g. after reconfiguring partitions or adding additional hard drives, (re)move grub's device configuration and let it reconfigure.<br />
# mv /boot/grub/device.map /boot/grub/device.map-old<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
Grub-mkconfig should now mention all found boot options including windows. If it works, remove /boot/grub/device.map-old.<br />
<br />
== References ==<br />
<br />
# Official GRUB2 Manual - http://www.gnu.org/software/grub/manual/grub.html<br />
# GRUB2 wiki page describing steps to compile for UEFI systems - https://help.ubuntu.com/community/UEFIBooting - previously http://grub.enbug.org/TestingOnUEFI{{Linkrot|2011|09|05}}<br />
# Wikipedia's page on [http://en.wikipedia.org/wiki/BIOS_Boot_partition BIOS Boot Partition]<br />
<br />
== External Links ==<br />
<br />
# [https://github.com/the-ridikulus-rat/My_Shell_Scripts/blob/master/grub2/grub2_bios.sh A Linux Bash Shell script to compile and install GRUB2 for BIOS from BZR Source]<br />
# [https://github.com/the-ridikulus-rat/My_Shell_Scripts/blob/master/grub2/grub2_uefi.sh A Linux Bash Shell script to compile and install GRUB2 for UEFI from BZR Source]</div>Mayweedhttps://wiki.archlinux.org/index.php?title=GRUB&diff=167954GRUB2011-10-29T17:15:01Z<p>Mayweed: this is not necessary anymore. grub install squeezed those sectors...</p>
<hr />
<div>[[Category:Boot loaders (English)]]<br />
{{i18n|GRUB2}}<br />
[[fr:GRUB2]]<br />
{{Article summary start}}<br />
{{Article summary text|Covers various aspects of the next generation of the GRand Unified Bootloader (GRUB2).}}<br />
{{Article summary heading|Overview}}<br />
{{Article summary text|{{Boot process overview}}}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|Burg}} - Burg is a brand-new boot loader based on GRUB2. It uses a new object format which allows it to be built in a wider range of OS, including Linux/Windows/OSX/Solaris/FreeBSD, etc. It also has a highly configurable menu system which works in both text and graphic mode. <br />
{{Article summary heading|Resources}}<br />
{{Article summary link|GNU GRUB -- GNU Project|http://www.gnu.org/software/grub/}}<br />
{{Article summary link|GNU GRUB Wiki|http://grub.enbug.org/}}{{Linkrot|2011|09|05}}<br />
{{Article summary end}}<br />
<br />
[http://www.gnu.org/software/grub/ GRUB2] is the next generation of the GRand Unified Bootloader (GRUB). GRUB2 is derived from [http://www.nongnu.org/pupa/ PUPA] which was a research project to investigate the next generation of GRUB. GRUB 2 has been rewritten from scratch to clean up everything and provide modularity and portability [http://www.gnu.org/software/grub/grub-faq.en.html#q1].<br />
<br />
Briefly, the ''bootloader'' is the first software program that runs when a computer starts. It is responsible for loading and transferring control to the Linux kernel. The kernel, in turn, initializes the rest of the operating system.<br />
<br />
== Preface ==<br />
<br />
Although, [[GRUB]] (i.e. version 0.9x) is the de facto standard bootloader of Linux, it is considered 'legacy' by upstream. It is being replaced by GRUB2 in many distributions. Upstream recommends GRUB2 >=1.99~rc2 over grub-legacy, even for current grub-legacy users.<br />
<br />
{{Note|grub2 from 1.99~rc2 and later supports btrfs as root (without a separate /boot filesystem).}}<br />
<br />
=== Notes for current GRUB users ===<br />
<br />
* There are differences in the commands of GRUB and GRUB2. Familiarize yourself with [http://www.gnu.org/software/grub/manual/grub.html#Commands GRUB2 commands] before proceeding (e.g. "find" has been replaced with "search").<br />
<br />
* GRUB2 is now ''modular'' and no longer requires "stage 1.5". As a result, the bootloader itself is limited -- modules are loaded from the hard drive as needed to expand functionality (e.g. for [[LVM]] or RAID support).<br />
<br />
* Device naming has changed between GRUB and GRUB2. Partitions are numbered from 1 instead of 0 while drives are still numbered from 0, and prefixed with partition-table type. For example, {{Filename|/dev/sda1}} would be referred to as {{Codeline|(hd0,msdos1)}} (for MBR) or {{Codeline|(hd0,gpt1)}} (for GPT) using GRUB2.<br />
<br />
== Installation ==<br />
<br />
=== During Arch Linux installation ===<br />
<br />
* Skip the '''Install Bootloader''' step and exit the installer.<br />
* Configure the network:<br />
# aif -p partial-configure-network<br />
This will bring up a prompt; put in the network interface to use, (e.g., eth0) and use DHCP for easy configuration.<br />
* If you did not configure the installed system's {{Filename|/etc/resolv.conf}} file during installation (for instance, if you plan to let DHCP generate it later), you will need to copy the one generated by AIF when it configured the network:<br />
# cp /etc/resolv.conf /mnt/etc/resolv.conf<br />
* Load the dm-mod module (you might need grub2-bios; install the package if needed):<br />
# modprobe dm-mod<br />
{{Note|This is necessary at this point, and cannot be postponed after the chroot. If you try to use modprobe in a chroot environment that has a later kernel version from that of the installing device (at the time of writing, 2.6.33), modprobe will fail. This happens routinely using the Arch "net" installations.}}<br />
* From the installer's live shell, chroot to the installed system:<br />
# mount -o bind /dev /mnt/dev<br />
# chroot /mnt bash<br />
* Update pacman's database:<br />
# pacman-db-upgrade<br />
* Refresh the package list (with an extra -y flag to force a refresh of all package lists even if they appear to be up to date):<br />
# pacman -Syy<br />
* Install the GRUB2 package as mentioned in the section [[#From a running Arch Linux]]. Note that the dm-mod module has already been loaded, no need to do that again.<br />
<br />
=== From a running Arch Linux ===<br />
<br />
==== BIOS systems ====<br />
<br />
===== Preliminary Considerations for GRUB2 BIOS =====<br />
<br />
====== [[GPT]] specific instructions ======<br />
<br />
GRUB2 in BIOS-GPT configuration requires a BIOS Boot Partition to embed its core.img in the absence of post-MBR gap in GPT partitioned systems (which is taken over by the GPT Primary Header and Primary Partition table). This partition is used by GRUB2 only in BIOS-GPT setups. No such partition type exists in case of MBR partitioning (at least not for GRUB2). This partition is also not required if the system is UEFI based, as no embedding of bootsectors takes place in that case. Syslinux does not require this partition.<br />
<br />
For a BIOS-GPT configuration, create a 2 MiB partition using cgdisk or GNU Parted with no filesystem. The location of the partition in the partition table does not matter but it should be within the first 2 TiB region of the disk. It is advisable to put it somewhere in the beginning of the disk before the /boot partition. Set the partition type to "EF02" in cgdisk or {{Codeline|set <BOOT_PART_NUM> bios_grub on}} in GNU Parted.<br />
<br />
{{Note|This partition should be created before grub_bios-install or grub-setup is run or before the '''Install Bootloader''' step of the Archlinux installer (if GRUB2 is selected as bootloader).}}<br />
<br />
====== [[MBR]] aka msdos partitioning specific instructions ======<br />
<br />
Usually the post-MBR gap (after the 512 byte MBR region and before the start of the 1st partition) in many MBR (or msdos disklabel) partitioned systems is 32 KiB when DOS compatibility cylinder alignment issues are satisfied in the partition table. However a post-MBR gap of about 1 to 2 MiB is recommended to provide sufficient room for embedding grub2's core.img ( https://bugs.archlinux.org/task/24103 ). It is advisable to use a partitioner which supports 1 MiB partition alignment to obtain this space as well as satisfy other non-512 byte sector issues (which are unrelated to embedding of core.img).<br />
<br />
If you do not dual-boot with MS Windows (any version) in BIOS systems, it is advisable to switch to GPT partitioning - [[GUID_Partition_Table#Convert_from_MBR_to_GPT_without_data_loss]]<br />
{{Note|Create the 2MiB partition mentioned above BEFORE you convert to GPT. If you do not, gparted will not resize your boot partition to allow its creation, and when you reboot grub2 will not know where to look.}}<br />
<br />
===== Before grub_bios-install =====<br />
<br />
The GRUB2 package can be installed with pacman (and will replace {{Package Official|grub}}, if it is installed):<br />
<br />
# pacman -S grub2-bios<br />
<br />
{{Note|Installing grub2-common (a dependency of grub2-bios) 1.99~rc1 or later, may take forever in some systems since the post_install script runs grub-mkconfig and this script does not provide the option <code>--no-floppy</code>. For more details search this option in the article.}}<br />
<br />
{{Note|Simply installing the package won't update the /boot/grub/core.img file and the grub2 modules in /boot/grub . You need to update the core.img file and the grub2 modules manually using grub_bios-install as explained below.}}<br />
<br />
Also load the device-mapper kernel module without which grub-probe does not reliably detect disks and partitions<br />
<br />
# modprobe dm-mod<br />
<br />
<br />
===== Run grub_bios-install =====<br />
<br />
There are 3 ways to install grub2 in BIOS booting - [[#Install_to_440-byte_MBR_boot_code_region]] (recommended) , [[#Install_to_Partition_or_Partitionless_Disk]] (not recommended) or [[#Generate_core.img_alone]] (safest method, but requires another BIOS bootloader like [[grub-legacy]] or [[syslinux]] to be installed to chainload {{Filename|/boot/grub/core.img}} ). For all the ways [[#Before_grub_bios-install]] step is needed.<br />
<br />
====== Install to 440-byte MBR boot code region ======<br />
<br />
To setup grub2-bios in the 440-byte Master Boot Record boot code region, populate the {{Filename|/boot/grub}} directory, generate the {{Filename|/boot/grub/core.img}} file, and embed it in the 32 KiB (minimum size - varies depending on partition alignment) post-MBR gap (MBR disks) or in BIOS Boot Partition (GPT disks), run<br />
<br />
# grub_bios-install --boot-directory=/boot --no-floppy --recheck /dev/sda<br />
<br />
where {{Filename|/dev/sda}} is the destination of the installation (in this case the MBR of the first SATA disk). If you use [[LVM]] for your {{Filename|/boot}}, you can install GRUB2 on multiple physical disks. <br />
<br />
The {{Codeline|--no-floppy}} tells grub2-bios utilities not to search for any floppy devices which reduces the overall execution time of grub_bios-install on many systems (it will also prevent the issue below from occuring). Otherwise you get an error like this<br />
<br />
grub-probe: error: Cannot get the real path of '/dev/fd0'<br />
Auto-detection of a filesystem module failed.<br />
Please specify the module with the option '--modules' explicitly.<br />
<br />
Then:<br />
* Delete all the files from {{Filename|/boot/grub}} except {{Filename|/boot/grub/menu.lst}} .<br />
<br />
* Follow the [[#Install_to_440-byte_MBR_boot_code_region]] instructions.<br />
<br />
* Follow [[#Generate_GRUB2_BIOS_Config_file]] or if that fails, convert your {{Filename|/boot/grub/menu.lst}} file to {{Filename|/boot/grub/grub.cfg}} using:<br />
<br />
# grub-menulst2cfg /boot/grub/menu.lst /boot/grub/grub.cfg<br />
<br />
For example:<br />
<br />
{{File|name=/boot/grub/menu.lst|content=<br />
default=0<br />
timeout=5<br />
<br />
title Arch Linux Stock Kernel<br />
root (hd0,0)<br />
kernel /vmlinuz-linux root=/dev/sda2 ro<br />
initrd /initramfs-linux.img<br />
<br />
title Arch Linux Stock Kernel Fallback<br />
root (hd0,0)<br />
kernel /vmlinuz-linux root=/dev/sda2 ro<br />
initrd /initramfs-linux-fallback.img<br />
}}<br />
<br />
{{File|name=/boot/grub/grub.cfg|content=<br />
set default='0'; if [ x"$default" = xsaved ]; then load_env; set default="$saved_entry"; fi<br />
set timeout=5<br />
<br />
menuentry 'Arch Linux Stock Kernel' {<br />
set root='(hd0,1)'; set legacy_hdbias='0'<br />
legacy_kernel '/vmlinuz-linux' '/vmlinuz-linux' 'root=/dev/sda2' 'ro'<br />
legacy_initrd '/initramfs-linux.img' '/initramfs-linux.img'<br />
<br />
}<br />
<br />
menuentry 'Arch Linux Stock Kernel Fallback' {<br />
set root='(hd0,1)'; set legacy_hdbias='0'<br />
legacy_kernel '/vmlinuz-linux' '/vmlinuz-linux' 'root=/dev/sda2' 'ro'<br />
legacy_initrd '/initramfs-linux-fallback.img' '/initramfs-linux-fallback.img'<br />
}<br />
}}<br />
<br />
<br />
* If you forgot to create a GRUB2 {{Filename|/boot/grub/grub.cfg}} configfile and simply rebooted into GRUB2 Command Shell, type:<br />
<br />
sh:grub> insmod legacycfg<br />
sh:grub> legacy_configfile ${prefix}/menu.lst<br />
<br />
Boot into Arch and re-create the proper GRUB2 {{Filename|/boot/grub/grub.cfg}} configfile.<br />
<br />
{{Note|This option works only in BIOS systems, not in UEFI systems.}}<br />
<br />
====== Install to Partition or Partitionless Disk ======<br />
<br />
{{Note|grub2-bios (any version - including upstream bzr repo) does not encourage installation to a partition boot sector or a partitionless disk like grub-legacy or syslinux does. Neither do the Arch devs.}}<br />
<br />
To setup grub2-bios to a partition boot sector, to a partitionless disk (also called superfloppy) or to a floppy disk, run (using for example /dev/sda1 as the /boot partition)<br />
<br />
# chattr -i /boot/grub/core.img<br />
# grub_bios-install --boot-directory=/boot --no-floppy --recheck --force /dev/sda1<br />
# chattr +i /boot/grub/core.img<br />
<br />
You need to use the {{Codeline|--force}} option to allow usage of blocklists and should not use <code>--grub-setup=/bin/true</code> (which is similar to simply generating core.img).<br />
<br />
grub_bios-install will give out warnings like which should give you the idea of what might go wrong with this approach.<br />
<br />
/sbin/grub-setup: warn: Attempting to install GRUB to a partitionless disk or to a partition. This is a BAD idea.<br />
/sbin/grub-setup: warn: Embedding is not possible. GRUB can only be installed in this setup by using blocklists. <br />
However, blocklists are UNRELIABLE and their use is discouraged.<br />
<br />
Without {{Codeline|--force}} you may get the below error and grub-setup will not setup its boot code in the partition boot sector.<br />
<br />
/sbin/grub-setup: error: will not proceed with blocklists<br />
<br />
With {{Codeline|--force}} you should get<br />
<br />
Installation finished. No error reported.<br />
<br />
The reason why grub-setup does not by default allow this is because in case of partition or a partitionless disk is that grub2-bios relies on embedded blocklists in the partition bootsector to locate the {{Filename|/boot/grub/core.img}} file and the prefix dir {{Filename|/boot/grub}} . The sector locations of {{Filename|core.img}} may change whenever the filesystem in the partition is being altered (files copied, deleted etc.). For more info see https://bugzilla.redhat.com/show_bug.cgi?id=728742 and https://bugzilla.redhat.com/show_bug.cgi?id=730915 .<br />
<br />
The workaround for this is to set the immutable flag on {{Filename|/boot/grub/core.img}} (using chattr command as mentioned above) so that the sector locations of the {{Filename|core.img}} file in the disk is not altered. The immutable flag on {{Filename|/boot/grub/core.img}} needs to be set only if grub2-bios is installed to a partition boot sector or a partitionless disk, not in case of installtion to MBR or simple generation of {{Filename|core.img}} without embedding any bootsector (mentioned above). <br />
<br />
====== Generate core.img alone ======<br />
<br />
To populate the {{Filename|/boot/grub}} directory and generate a {{Filename|/boot/grub/core.img}} file WITHOUT embedding any grub2-bios bootsector code in the MBR, post-MBR region, or the partition bootsector, add <code>--grub-setup=/bin/true</code> to grub_bios-install:<br />
<br />
# grub_bios-install --grub-setup=/bin/true --boot-directory=/boot --no-floppy --recheck /dev/sda<br />
<br />
You can then chainload grub2's core.img from grub-legacy or syslinux as a Linux kernel or a multiboot kernel.<br />
<br />
===== After grub_bios-install =====<br />
<br />
====== Generate GRUB2 BIOS Config file ======<br />
<br />
Finally, generate a configuration for grub2 (this is explained in greater detail in the Configuration section):<br />
<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
If grub2 complains about "no suitable mode found" while booting, go to [[#Correct_GRUB2_No_Suitable_Mode_Found_Error]] .<br />
<br />
===== Multiboot in BIOS =====<br />
<br />
====== Boot Microsoft Windows installed in BIOS-MBR mode ======<br />
<br />
{{Note|GRUB2 supports booting {{Filename|bootmgr}} directly and chainload of partition boot sector is no longer required to boot Windows in a BIOS-MBR setup.}}<br />
<br />
Find the UUID of the NTFS filesystem of the Windows's SYSTEM PARTITION where the bootmgr and its files reside. For example, if Windows {{Filename|bootmgr}} exists at {{Filename|/media/Windows/bootmgr}}:<br />
<br />
# grub-probe --target=fs_uuid /media/Windows/bootmgr<br />
69B235F6749E84CE<br />
<br />
Then, add the below code to {{Filename|/boot/grub/grub.cfg}} to chainload Windows (Vista, 7 or 8) installed in BIOS-MBR mode :<br />
<br />
menuentry "Microsoft Windows 7 BIOS-MBR" {<br />
insmod part_msdos<br />
insmod ntfs<br />
insmod search_fs_uuid<br />
insmod ntldr <br />
search --fs-uuid --no-floppy --set=root 69B235F6749E84CE<br />
ntldr (${root})/bootmgr<br />
}<br />
<br />
For Windows XP<br />
<br />
menuentry "Microsoft Windows XP" {<br />
insmod part_msdos<br />
insmod ntfs<br />
insmod search_fs_uuid<br />
insmod ntldr <br />
search --fs-uuid --no-floppy --set=root 69B235F6749E84CE<br />
ntldr (${root})/ntldr<br />
}<br />
<br />
==== [[UEFI]] systems ====<br />
<br />
===== Before grub_efi_${UEFI_ARCH}-install =====<br />
<br />
{{Note|Unless specified as EFI 1.x , EFI and UEFI terms are used interchangeably to denote UEFI 2.x firmware. Also unless stated explicitely, the instructions are general and not Mac specific. Some of them may not work or may be different in Macs. Apple's EFI implementation is neither a EFI 1.x version nor UEFI 2.x version but mixes up both. This kind of firmware does not fall under any one UEFI Specification version and is therefore not a standard UEFI firmware.}}<br />
<br />
GRUB2 UEFI bootloader is available in Arch Linux only from version 1.99~rc1 . To install, first [https://wiki.archlinux.org/index.php/Unified_Extensible_Firmware_Interface#Detecting_UEFI_Firmware_Arch Detect which UEFI firmware arch] you have (either x86_64 or i386).<br />
<br />
Depending on that, install the appropriate package<br />
<br />
For 64-bit aka x86_64 UEFI firmware:<br />
# pacman -S grub2-efi-x86_64<br />
<br />
For 32-bit aka i386 UEFI firmware:<br />
# pacman -S grub2-efi-i386<br />
<br />
{{Note|Installing grub2-common (a dependency of grub2-bios) 1.99~rc1 or later, may take forever in some systems since the post_install script runs grub-mkconfig and this script does not provide the option <code>--no-floppy</code>. For more details search this option in the article.}}<br />
<br />
{{Note|Simply installing the package won't update the grub.efi file and the grub2 modules in the UEFI System Partition . You need to update the grub.efi file and the grub2 modules in the UEFI System Partition manually using grub_efi_${UEFI_ARCH}-install as explained below.}}<br />
<br />
Also load the device-mapper kernel module without which grub-probe does not reliably detect disks and partitions<br />
<br />
# modprobe dm-mod<br />
<br />
===== Install to UEFI SYSTEM PARTITION =====<br />
<br />
====== Mount UEFI SYSTEM PARTITION ======<br />
<br />
Mount the [https://wiki.archlinux.org/index.php/Unified_Extensible_Firmware_Interface#Creating_a_UEFI_SYSTEM_PARTITION_in_Linux UEFI SYSTEM PARTITION] in your system at {{Filename|/boot/efi}}. It should be FAT32 formatted and should be at least 200 MiB in size. If you have mounted the UEFISYS partition in some other mountpoint, replace {{Filename|/boot/efi}} in the below commands with that mountpoint:<br />
<br />
# mkdir -p /boot/efi<br />
# mount -t vfat <UEFISYS_PART_DEVICE> /boot/efi<br />
# mkdir -p /boot/efi/efi<br />
<br />
====== Run grub_efi_${UEFI_ARCH}-install ======<br />
<br />
{{Note|The below commands assume you are using {{Codeline|grub2-efi-x86_64}} (for {{Codeline|grub2-efi-i386}} replace {{Codeline|x86_64}} with {{Codeline|i386}} in the below commands).}}<br />
<br />
# grub_efi_x86_64-install --root-directory=/boot/efi --boot-directory=/boot/efi/efi --bootloader-id=grub --no-floppy --recheck<br />
<br />
The {{Codeline|grub_efi_x86_64-install}} automatically generates a {{Filename|grub.efi}} while setting up the {{Filename|/boot/efi/efi/grub/}} directory.<br />
<br />
If you notice carefully, there is no <device_path> option (Eg: {{Filename|/dev/sda}}) at the end of the {{Codeline|grub_efi_x86_64-install}} command unlike the case of setting up grub2 for BIOS systems. Any <device_path> provided will be ignored by the install script as UEFI bootloaders do not use MBR or Partition boot sectors at all.<br />
<br />
You may now be able to UEFI boot your system by creating a grub.cfg file using grub-mkconfig and copying /boot/efi/efi/grub/grub.efi to /boot/efi/efi/boot/bootx64.efi.<br />
<br />
===== After grub_efi_${UEFI_ARCH}-install =====<br />
<br />
====== Launch GRUB2 as default in non-Mac UEFI systems ======<br />
<br />
{{Note|The below steps will not work if the system has been booted in BIOS mode and will not work if the UEFI processor architecture does not match the kernel one, i.e. x86_64 UEFI + ix86 32-bit Kernel and vice-versa config will not work.}}<br />
<br />
grub_efi_${UEFI_ARCH}-install will ensure {{Filename|/boot/efi/efi/grub/grub.efi}} is launched by default if it detects {{Codeline|efibootmgr}} and if it is able to access UEFI Runtime Services. {{Codeline|efibootmgr}} command will work only if you have booted the system in UEFI mode itself, since it '''requires access to UEFI Runtime Variables''' which are '''available only in UEFI boot mode''' (with "noefi" kernel parameter NOT being used). Initially the user is required to manually launch {{Filename|/boot/efi/efi/grub/grub.efi}} from the firmware itself (using maybe the UEFI Shell) if grub2-efi was installed in BIOS mode. Then {{Codeline|efibootmgr}} should be run to make grub2 as the default entry in the UEFI Boot Manager<br />
<br />
First boot into UEFI mode manually either using the firmware boot menu, UEFI shell, or using any UEFI capable bootable iso (Archboot or Ubuntu non-Mac iso). Use grub probe to determine the device path of your EFI System Partition:<br />
# grub-probe --target=device /boot/efi/efi/grub/grub.efi<br />
<br />
It should give something like {{Filename|/dev/sda1}} (used as example in the remaining steps). Load 'efivars' kernel module:<br />
# modprobe efivars<br />
<br />
If you get '''no such device found''' error for this command, that means you have not booted in UEFI mode or due to some reason the kernel is unable to access UEFI Runtime Variables.<br />
<br />
Verify whether there are files in ''/sys/firmware/efi/vars/'' directory. This directory and its contents are created by "efivars" kernel module and it will exist only if you have booted in UEFI mode without the "noefi" kernel parameter.<br />
<br />
# ls -1 /sys/firmware/efi/vars/<br />
<br />
Sample output (x86_64-UEFI 2.3.1 in x86_64 Kernel:<br />
<br />
# ls -1 /sys/firmware/efi/vars/<br />
Boot0000-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootCurrent-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootOptionSupport-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
BootOrder-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConIn-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConInDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConOut-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ConOutDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
ErrOutDev-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
Lang-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
LangCodes-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
MTC-eb704011-1402-11d3-8e77-00a0c969723b/<br />
MemoryTypeInformation-4c19049f-4137-4dd3-9c10-8b97a83ffdfa/<br />
PlatformLang-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
PlatformLangCodes-8be4df61-93ca-11d2-aa0d-00e098032b8c/<br />
RTC-378d7b65-8da9-4773-b6e4-a47826a833e1/<br />
del_var<br />
new_var<br />
<br />
If ''/sys/firmware/efi/vars/'' directory is empty or does not exist, then {{Codeline|efibootmgr}} command will not work. If you are unable to make the ISO/CD/DVD/USB boot in UEFI mode try https://gitorious.org/tianocore_uefi_duet_builds/pages/Linux_Windows_BIOS_UEFI_boot_USB .<br />
<br />
If ''/sys/firmware/efi/vars/'' directory (along with the exists then run {{Codeline|efibootmgr}} and reboot:<br />
<br />
# efibootmgr --create --gpt --disk /dev/sda --part 1 --write-signature --label "GRUB2" --loader "\\EFI\\grub\\grub.efi"<br />
<br />
In the above command, {{Filename|/boot/efi/efi/grub/grub/efi}} can be split up as {{Filename|/boot/efi}} and {{Filename|/efi/grub/grub.efi}}, which translates to {{Filename|(/dev/sda)}} -> partition 1 -> {{Filename|\\EFI\\grub\\grub.efi}}. <br />
<br />
FAT32 filesystem is case-insensitive since it does not use UTF-8 encoding by default. In that case the firmware uses capital 'EFI' instead of small 'efi', therefore using {{Filename|\\EFI\\grub\\grub.efi}} or {{Filename|\\efi\\grub\\grub.efi}} does not matter (this will change if the filesystem encoding is UTF-8). UEFI uses backward slash as path separatoir (similar to Windows paths). In the above command "double" backward slashes are used instead of single ones, since a backward slash is used as a escape character by sh shells, the first backward slash escapes the second one so that the path {{Filename|\EFI\grub\grub.efi}} is passed to {{Codeline|efibootmgr}}.<br />
<br />
The 'label' is the name of the menu entry shown in the UEFI boot menu. This name is user's choice and does not affect the booting of the system. More info can be obtained from [http://linux.dell.com/cgi-bin/gitweb/gitweb.cgi?p=efibootmgr.git;a=blob_plain;f=README;hb=HEAD efibootmgr GIT README]<br />
<br />
If you have problems running GRUB2 in UEFI mode you can try the following (worked on an ASUS Z68 mainboard):<br />
<br />
# cp /boot/efi/efi/grub/grub.efi /boot/efi/shellx64.efi<br />
<br />
or<br />
<br />
# cp /boot/efi/efi/grub/grub.efi /boot/efi/efi/shellx64.efi<br />
or<br />
<br />
# cp /boot/efi/efi/grub/grub.efi /boot/efi/efi/shell/shellx64.efi<br />
<br />
After this launch the UEFI Shell from the UEFI setup/menu (in ASUS UEFI BIOS, switch to advanced mode, press Exit in the top right corner and choose "Launch EFI shell from filesystem device"). The grub2 menu will show up and you can boot into your system. Afterwards you can use efibootmgr to setup a menu entry (see above).<br />
<br />
====== Launch GRUB2 as default in Apple Mac EFI systems ======<br />
<br />
{{Note|Using {{Filename|efibootmgr}} in Apple Macs will brick the firmware and may need reflash of the motherboard ROM. There have been bug reports regarding this in Ubuntu/Launchpad bug tracker. Use bless command alone in case of Macs}}<br />
<br />
Use bless command from within Mac OS X to setup {{Filename|grub.efi}} as the default boot option. More info at https://help.ubuntu.com/community/UEFIBooting#Apple_Mac_EFI_systems_.28both_EFI_architecture.29 .<br />
<br />
====== Generate GRUB2 UEFI Config file ======<br />
<br />
Finally, generate a configuration for grub2 (this is explained in greater detail in the Configuration section):<br />
<br />
# grub-mkconfig -o /boot/efi/efi/grub/grub.cfg<br />
<br />
If grub2-uefi complains about "no suitable mode found" while booting, go to [[#Correct_GRUB2_No_Suitable_Mode_Found_Error]] .<br />
<br />
===== Generate a custom GRUB2 UEFI Application =====<br />
<br />
If you want, you can create a custom {{Filename|grub_custom.efi}} app using:<br />
# grub-mkimage -d /usr/lib/grub/x86_64-efi -O x86_64-efi -p "" -o /boot/efi/efi/grub/grub_custom.efi <GRUB2_Modules_to_be_included><br />
<br />
{{Note|The '''-p''' option is important for creating a portable {{Filename|grub_custom.efi}} app.}}<br />
<br />
There is no file-size restriction on {{Filename|grub_custom.efi}} either due to GRUB2 or due to the UEFI firmware. Therefore you can include any number of modules you want.<br />
<br />
A "{{Filename|grub.cfg}}" created for BIOS based GRUB2 will be sufficient for the UEFI GRUB2 as long as all the paths in the config are absolute paths. The {{Filename|grub.cfg}} file should exist in the same directory as {{Filename|grub.efi}} or {{Filename|grub_custom.efi}}.<br />
<br />
The {{Filename|grub.efi}} UEFI application can be launched using the firmware's "Boot Manager", "Boot from file" option or using the [https://wiki.archlinux.org/index.php/UEFI#UEFI_Shell UEFI Shell].<br />
<br />
Alternatively, you can also setup {{Filename|/boot/efi/efi/grub}} directory by copying all the files in {{Filename|/usr/lib/grub/x86_64-efi}} to {{Filename|/boot/efi/efi/grub}} and using the above grub-mkimage command to create a {{Filename|grub_custom.efi}} application. Just make sure you have the required modules embedded in {{Filename|grub_custom.efi}} to enable it to access the EFI SYSTEM PARTITION.<br />
<br />
A basic {{Filename|grub_custom.efi}} can be generated using the following command:<br />
# sudo grub-mkimage -d /usr/lib/grub/x86_64-efi -O x86_64-efi -p "" -o /boot/efi/efi/grub/grub_custom.efi part_gpt fat iso9660 udf normal chain linux \<br />
ls search search_fs_file search_fs_uuid search_label help boot configfile echo efi_gop<br />
<br />
===== Multiboot in UEFI =====<br />
<br />
====== Chainload Microsoft Windows x86_64 UEFI-GPT ======<br />
<br />
Find the UUID of the FAT32 filesystem in the UEFI SYSTEM PARTITION where the Windows UEFI Bootloader files reside. For example, if Windows {{Filename|bootmgfw.efi}} exists at {{Filename|/boot/efi/efi/Microsoft/Boot/bootmgfw.efi}} (ignore the upper-lower case differences since that is immaterial in FAT filesystem):<br />
<br />
# grub-probe --target=fs_uuid /boot/efi/efi/Microsoft/Boot/bootmgfw.efi<br />
1ce5-7f28<br />
<br />
Then, add this code to {{Filename|/boot/efi/efi/grub/grub.cfg}} to chainload Windows x86_64 (Vista SP1+, 7 or 8) installed in UEFI-GPT mode :<br />
<br />
menuentry "Microsoft Windows x86_64 UEFI-GPT" {<br />
insmod part_gpt<br />
insmod fat<br />
insmod search_fs_uuid<br />
insmod chain<br />
search --fs-uuid --no-floppy --set=root 1ce5-7f28<br />
chainloader (${root})/efi/Microsoft/Boot/bootmgfw.efi<br />
}<br />
<br />
== Manual Compilation ==<br />
<br />
=== For BIOS Systems ===<br />
<br />
GRUB2 for BIOS systems should be compiled as follows:<br />
<pre><br />
./autogen.sh<br />
<br />
./configure --with-platform=pc --prefix=/usr<br />
<br />
make<br />
<br />
make install<br />
</pre><br />
<br />
The <code>--with-platform=pc</code> generates grub2 for bios alone irrespective of the firmware of the build system.<br />
<br />
=== For UEFI Systems ===<br />
<br />
First [https://wiki.archlinux.org/index.php/Unified_Extensible_Firmware_Interface#Detecting_UEFI_Firmware_Arch Detect which UEFI Firmware arch] you have and then follow the compile instructions below:<br />
<pre><br />
./autogen.sh<br />
<br />
./configure --with-platform=efi --target=TARGET_UEFI_ARCH --prefix=/usr<br />
<br />
make<br />
<br />
make install<br />
</pre><br />
<br />
The "--target" option denotes the UEFI firmware arch. for which grub2 should be compiled, not the architecture of the linux kernel grub2 may boot. <br />
<br />
It is possible to use UEFI 64-bit firmware + GRUB2 as x86_64-EFI app loading a i686 linux kernel, as long as the kernel does not try to access UEFI Runtime Services. Vice-versa situation is also possible. But a x86_64 UEFI firmware cannot launch GRUB2 i386-efi app (unlike x86_64 Operating Systems), and a i386 UEFI firmware will not launch GRUB2 {{Codeline|x86_64-efi}} app. It is important to compile GRUB2 to match the architecture of the UEFI firmware.<br />
<br />
== Configuration ==<br />
<br />
The configuration files are {{Filename|/etc/default/grub}} and {{Filename|/etc/grub.d/*}}. These files are used to generate the {{Filename|/boot/grub/grub.cfg}} file. You can also choose to manually edit {{Filename|grub.cfg}}.<br />
<br />
=== grub-mkconfig ===<br />
<br />
The grub-mkconfig script can be used to generate a {{Filename|grub.cfg}} file. By default the script outputs to stdout. Note that gettext ― an optional dependency of the GRUB2 package ― is required by the grub-mkconfig script. To generate a {{Filename|grub.cfg}} file run the command:<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
Note that grub-mkconfig probably has your grub directory hardcoded to /boot/grub, which is probably wrong if you're using UEFI. Either mount your efi grub directory at /boot/grub or edit the script.<br />
<br />
=== grub.cfg ===<br />
<br />
A basic grub file uses the following options<br />
* {{Codeline|(hdX,Y)}} is the partition {{Codeline|Y}} on disk {{Codeline|X}}, partition numbers starting at 1, disk numbers starting at 0<br />
* {{Codeline|1=set default=N}} is the default boot entry that is chosen after timeout for user action<br />
* {{Codeline|1=set timeout=M}} is the time {{Codeline|M}} to wait in seconds for a user selection before default is booted<br />
* {{Codeline|<nowiki>menuentry "title" {entry options}</nowiki>}} is a boot entry titled {{Codeline|title}}<br />
* {{Codeline|1=set root=(hdX,Y)}} sets the boot partition, where the kernel and GRUB modules are stored (boot need not be a separate partition, and may simply be a directory under the "root" partition ({{Filename|/}})<br />
<br />
An example configuration:<br />
<br />
{{File<br />
|name=/boot/grub/grub.cfg<br />
|content=<nowiki><br />
# Config file for GRUB2 - The GNU GRand Unified Bootloader<br />
# /boot/grub/grub.cfg<br />
<br />
# DEVICE NAME CONVERSIONS<br />
#<br />
# Linux Grub<br />
# -------------------------<br />
# /dev/fd0 (fd0)<br />
# /dev/sda (hd0)<br />
# /dev/sdb2 (hd1,2)<br />
# /dev/sda3 (hd0,3)<br />
#<br />
<br />
# Timeout for menu<br />
set timeout=5<br />
<br />
# Set default boot entry as Entry 0<br />
set default=0<br />
<br />
# (0) Arch Linux<br />
menuentry "Arch Linux" {<br />
set root=(hd0,1)<br />
linux /vmlinuz-linux root=/dev/sda3 ro<br />
initrd /initramfs-linux.img<br />
}<br />
<br />
## (1) Windows<br />
#menuentry "Windows" {<br />
#set root=(hd0,3)<br />
#chainloader +1<br />
#}<br />
</nowiki>}}<br />
<br />
=== Dual-booting ===<br />
<br />
''NOTE: If you want GRUB2 to automatically search for other systems, for example as in Ubuntu. Then you may need to download {{Package AUR|os-prober}} from the [[AUR]].''<br />
<br />
==== Using grub-mkconfig ====<br />
The best way to add other entries is editing the {{Filename|/etc/grub.d/40_custom}}. The entries in this file will be automatically added when running '''grub-mkconfig'''.<br />
After adding the new lines, run:<br />
# grub-mkconfig -o /boot/grub/grub.cfg <br />
to generate an updated {{Filename|grub.cfg}}.<br />
<br />
===== With GNU/Linux =====<br />
<br />
Assuming that the other distro is on partition {{Filename|sda2}}:<br />
<br />
menuentry "Other Linux" {<br />
set root=(hd0,2)<br />
linux /boot/vmlinuz (add other options here as required)<br />
initrd /boot/initrd.img (if the other kernel uses/needs one)<br />
}<br />
<br />
===== With Windows =====<br />
<br />
This assumes that your Windows partition is {{Filename|sda3}}.<br />
<br />
# (2) Windows XP<br />
menuentry "Windows XP" {<br />
set root=(hd0,3)<br />
chainloader (hd0,3)+1<br />
}<br />
<br />
If the windows bootloader is on an entirely different harddrive than grub, it may be necessary to trick Windows into believing that it is in fact the first harddrive. This was possible in the old grub with {{Codeline|map}} and is now done with {{Codeline|drivemap}}. Assume grub is on {{Filename|hd0}} and windows on {{Filename|hd2}}, you need to add the following after {{Codeline|set root}}:<br />
<br />
drivemap -s hd0 hd2<br />
<br />
==== With Windows via EasyBCD and NeoGRUB ====<br />
<br />
Since EasyBCD's NeoGRUB currently does not understand the GRUB2 menu format, chainload to it by replacing the contents of your {{Filename|C:\NST\menu.lst}} file with lines similar to the following:<br />
<br />
default 0<br />
timeout 1<br />
<br />
title Chainload into GRUB v2<br />
root (hd0,7)<br />
kernel /boot/grub/core.img<br />
<br />
===Visual Configuration===<br />
<br />
In GRUB2 it is possible, by default, to change the look of the menu.<br />
<br />
====Background image and bitmap fonts====<br />
<br />
GRUB2 comes with support for background images and bitmap fonts in pf2 format. The unifont font is included in the grub2 package under the filename {{Filename|unicode.pf2}}, or, as only ascii characters under the name {{Filename|ascii.pf2}}. Image formats supported include tga, png and jpeg, providing the correct modules are loaded. The maximum supported resolution depends on your hardware. There are two ways of setting a {{Filename|tga}} file as background. Two sample configurations are shown below.<br />
<br />
Edit {{Filename|/etc/default/grub}} like this:<br />
GRUB_GFXMODE=1024x768x32<br />
GRUB_GFXPAYLOAD_LINUX=keep<br />
GRUB_BACKGROUND="/boot/grub/archlinux.tga"<br />
#GRUB_THEME="/path/to/gfxtheme"<br />
<br />
(archlinux.tga is a placeholder; put your file name there)<br />
<br />
To generate the changes, run: <br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
{{Note|If this example does not work for you try to replace {{Codeline|1=gfxmode="1024x768x32"}} by {{Codeline|1=vbemode="0x105"}}.}}<br />
{{Note|To show all the modes you can use {{Codeline|1=# hwinfo --framebuffer}} (hwinfo is available in [community]), while at grub2 prompt you can use the {{Codeline|1=vbeinfo}} command.}}<br />
{{Note|If you have installed Grub on a separate partition, {{Filename|/boot/grub/archlinux.tga}} becomes {{Filename|/grub/archlinux.tga}}.}}<br />
<br />
====Menu colors====<br />
<br />
As in Grub (0.9x), you can change the menu colors in Grub2. The available colors for GRUB2 are at http://www.gnu.org/software/grub/manual/html_node/Theme-file-format.html#Theme-file-format . <br />
Here is an example:<br />
<br />
Edit {{Filename|/etc/default/grub}}:<br />
GRUB_COLOR_NORMAL="light-blue/black"<br />
GRUB_COLOR_HIGHLIGHT="light-cyan/blue"<br />
<br />
Generate the changes:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
====Hidden menu====<br />
<br />
One of the unique features of Grub2 is hiding/skipping the menu and showing it by holding "Shift" when needed. You can also adjust whether you want to see the timeout counter.<br />
<br />
Edit {{Filename|/etc/default/grub}} as you wish. Here is an example where the comments from the beginning of the two lines have been removed to enable the feature, the timeout has been set to five seconds and to be shown to the user:<br />
GRUB_HIDDEN_TIMEOUT=5<br />
GRUB_HIDDEN_TIMEOUT_QUIET=false<br />
<br />
and run:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
====Setting the framebuffer resolution ====<br />
<br />
Grub2 can set the framebuffer for both grub2 itself and the kernel. The old ''vga='' way is deprecated. The preferred method is editing {{Filename|/etc/default/grub}} as the following sample:<br />
<br />
GRUB_GFXMODE=1024x768x32<br />
GRUB_GFXPAYLOAD_LINUX=keep<br />
<br />
To generate the changes, run: <br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
The {{Codeline|gfxpayload}} property will make sure the kernel keeps the resolution.<br />
<br />
If this method does not work for you, the deprecated <code>vga=</code> method will still work. Just<br />
add it next to the <code>"GRUB_CMDLINE_LINUX_DEFAULT="</code> line in {{Filename|/etc/default/grub}}<br />
for eg: <code>"GRUB_CMDLINE_LINUX_DEFAULT="quiet splash vga=792"</code> will give you a {{Codeline|1024x768}} resolution.<br />
<br />
You can choose one of these resolutions: {{Codeline|640×480}}, {{Codeline|800×600}}, {{Codeline|1024×768}}, {{Codeline|1280×1024}}, {{Codeline|1600×1200}}<br />
<br />
=== Other Options ===<br />
<br />
==== LVM ====<br />
<br />
If you use [[LVM]] for your {{Filename|/boot}}, add the following before menuentry lines:<br />
<br />
insmod lvm<br />
<br />
and specify your root in the menuentry as:<br />
<br />
set root=(''lvm_group_name''-''lvm_logical_boot_partition_name'')<br />
<br />
Example:<br />
<br />
# (0) Arch Linux<br />
menuentry "Arch Linux" {<br />
insmod lvm<br />
set root=(VolumeGroup-lv_boot)<br />
# you can only set following two lines<br />
linux /vmlinuz-linux root=/dev/mapper/VolumeGroup-root ro<br />
initrd /initramfs-linux.img<br />
}<br />
<br />
==== Raid ====<br />
<br />
Grub2 provides convenient handling of raid-volumes. You need to add:<br />
insmod raid<br />
<br />
which allows you to address the volume natively. E.g. {{Filename|/dev/md0}} becomes:<br />
set root=(md0)<br />
<br />
whereas a partitioned raid-volume (e.g. {{Filename|/dev/md0p1}}) becomes:<br />
set root=(md0,1)<br />
<br />
==== Persistent block device naming ====<br />
You can use UUIDs to detect partitions instead of the "old" {{Filename|/dev/sd*}} and {{Filename|/dev/hd*}} scheming. It has the advantage of detecting partitions by their unique UUIDs, which is needed by some people booting with complicated partition setups.<br />
<br />
UUIDs are used by default in the recent versions of grub2 - there is no downside in it anyway except that you need to re-generate the {{Filename|grub.cfg}} file every time you resize or reformat your partitions. Remember this when modifying partitions with Live-CD.<br />
<br />
The recent versions of grub2 use UUIDs by default. You can re-enable the use of UUIDS by simply commenting the UUID line (this is also what it looks like by default):<br />
#GRUB_DISABLE_LINUX_UUID=true<br />
you can also just set the value as {{Codeline|false}} as shown here:<br />
GRUB_DISABLE_LINUX_UUID=false<br />
<br />
Either way, do not forget to generate the changes:<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
==== Using Labels ====<br />
<br />
It is possible to use labels, human-readable strings attached to filesystems, by using the {{Codeline|--label}} option to {{Codeline|search}}. First of all, label your existing partition:<br />
# tune2fs -L a <LABEL> <PARTITION><br />
<br />
Then, add an entry using labels. An example of this:<br />
<br />
menuentry "Arch Linux, session texte" {<br />
search --label --no-floppy --set=root archroot<br />
linux /boot/vmlinuz-linux root=/dev/disk/by-label/archroot ro<br />
initrd /boot/initramfs-linux.img<br />
}<br />
<br />
==== Recall previous entry ====<br />
<br />
Grub2 can remember the last entry you booted from and use this as the default entry to boot from next time. This is useful if you have multiple kernels (i.e., the current Arch one and the LTS kernel as a fallback option) or operating systems. To do this, edit {{Filename|/etc/default/grub}} and change the setting of {{Codeline|GRUB_DEFAULT}}:<br />
<br />
GRUB_DEFAULT=saved<br />
<br />
This ensures that grub will default to the saved entry. To enable saving the selected entry, add the following line to {{Filename|/etc/default/grub}}:<br />
<br />
GRUB_SAVEDEFAULT=true<br />
<br />
Remember to regenerate your configuration file.<br />
<br />
==== Security ====<br />
<br />
If you want to secure GRUB2 so it is not possible for anyone to change boot parameters or use the command line, you can add a user/password combination to GRUB2's configuration files. To do this, run the command {{Codeline|grub-mkpasswd_pbkdf2}}. Enter a password and confirm it. The output will look like this:<br />
<br />
<pre style='overflow:auto'><br />
Your PBKDF2 is grub.pbkdf2.sha512.10000.C8ABD3E93C4DFC83138B0C7A3D719BC650E6234310DA069E6FDB0DD4156313DA3D0D9BFFC2846C21D5A2DDA515114CF6378F8A064C94198D0618E70D23717E82.509BFA8A4217EAD0B33C87432524C0B6B64B34FBAD22D3E6E6874D9B101996C5F98AB1746FE7C7199147ECF4ABD8661C222EEEDB7D14A843261FFF2C07B1269A</pre>Then, add the following to {{Filename|/etc/grub.d/00_header}}:<br />
<pre>cat << EOF<br />
<br />
set superusers="username"<br />
password_pbkdf2 username <password><br />
<br />
EOF</pre><br />
where <password> is the string generated by {{Codeline|grub-mkpasswd_pbkdf2}}.<br />
<br />
Regenerate your configuration file. Your GRUB2 command line and boot parameters are now protected.<br />
<br />
=== Booting an Ubuntu ISO Image from the GRUB2 Screen ===<br />
<br />
Edit {{Filename|/etc/grub.d/40_custom}} to add an entry pointing to an Ubuntu iso:<br />
<br />
menuentry "ubuntu-11.04-desktop-amd64.iso" {<br />
set isofile="/path/to/ubuntu-11.04-desktop-amd64.iso"<br />
loopback loop (hdX,Y)$isofile<br />
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile quiet noeject noprompt splash --<br />
initrd (loop)/casper/initrd.lz<br />
}<br />
<br />
Be sure to adjust the "hdX,Y" in the third line to point to the correct disk/partition number of the isofile. When finished, update grub2's configuration file via:<br />
<br />
grub-mkconfig -o /boot/grub/grub.cfg<br />
<br />
== Using the command shell ==<br />
<br />
Since the MBR is too small to store all GRUB2 modules, only the menu and a few basic commands reside there. The majority of GRUB2 functionality remains in modules in {{Filename|/boot/grub}}, which are inserted as needed. In error conditions (e.g. if the partition layout changes) GRUB2 may fail to boot. When this happens, a command shell may appear.<br />
<br />
GRUB2 offers multiple shells/prompts. If there is a problem reading the menu but the bootloader is able to find the disk, you will likely be dropped to the "normal" shell:<br />
sh:grub><br />
<br />
If there is a more serious problem (e.g. GRUB cannot find required files), you may instead be dropped to the "rescue" shell:<br />
grub rescue><br />
<br />
The rescue shell is a restricted subset of the normal shell, offering much less functionality. If dumped to the rescue shell, first try inserting the "normal" module, then starting the "normal" shell:<br />
grub rescue> set prefix=(hdX,Y)/boot/grub<br />
grub rescue> insmod (hdX,Y)/boot/grub/normal.mod<br />
rescue:grub> normal<br />
<br />
=== Pager support ===<br />
<br />
GRUB2 supports pager for reading commands that provide long output (like the help command). This works only in normal shell mode and not in rescue mode. To enable pager, in GRUB2 command shell type:<br />
sh:grub> set pager=1<br />
<br />
== GUI configuration tools ==<br />
<br />
Following package may be installed from [[AUR]]<br />
* [http://kde-apps.org/content/show.php?content=139643 grub2-editor] (requires kdelibs)<br />
*:A KDE4 control module for configuring the GRUB2 bootloader<br />
* [http://kde-apps.org/content/show.php?content=137886 kcm-grub2] (requires kdelibs python2-qt kdebindings-python)<br />
*:This Kcm module manages the most common settings of Grub2.<br />
* [http://sourceforge.net/projects/startup-manager/ startupmanager] (requires gnome-python imagemagick yelp python2 xorg-xrandr)<br />
*:GUI app for changing the settings of GRUB, GRUB2, Usplash and Splashy<br />
<br />
== parttool or legacy hide/unhide ==<br />
<br />
If you have a win9x paradigm with hidden C disks GRUB legacy had the hide/unhide feature. In GRUB2 this has been replaced by parttool. For example, to boot the third C disk of three win9x installations on the CLI enter the CLI and:<br />
parttool hd0,1 hidden+ boot-<br />
parttool hd0,2 hidden+ boot-<br />
parttool hd0,3 hidden- boot+<br />
set root=hd0,3<br />
chainloader +1<br />
boot<br />
<br />
== Using the rescue console ==<br />
<br />
See [[#Using the command shell]] first. If unable to activate the standard shell, one possible solution is to boot using a live CD or some other rescue disk to correct configuration errors and reinstall GRUB. However, such a boot disk is not always available (nor necessary); the rescue console is surprisingly robust.<br />
<br />
The available commands in GRUB rescue include "insmod", "ls", "set", and "unset". This example uses "set" and "insmod". "set" modifies variables and "insmod" inserts new modules to add functionality.<br />
<br />
Before starting, the user must know the location of their {{Filename|/boot}} partition (be it a separate partition, or a subdirectory under their root):<br />
grub rescue> set prefix=(hdX,Y)/boot/grub<br />
<br />
where X is the physical drive number and Y is the partition number.<br />
<br />
To expand console capabilities, insert the "linux" module:<br />
grub rescue> insmod (hdX,Y)/boot/grub/linux.mod<br />
<br />
{{Note|With a separate boot partition, omit {{Filename|/boot}} from the path, (i.e. type {{Codeline|1=set prefix=(hdX,Y)/grub}} and {{Codeline|insmod (hdX,Y)/grub/linux.mod}}).}}<br />
<br />
This introduces the "linux" and "initrd" commands, which should be familiar (see [[#Configuration]]).<br />
<br />
An example, booting Arch Linux:<br />
set root=(hd0,5)<br />
linux /boot/vmlinuz-linux root=/dev/sda5<br />
initrd /boot/initramfs-linux.img<br />
boot<br />
<br />
With a separate boot partition, again change the lines accordingly:<br />
set root=(hd0,5)<br />
linux /vmlinuz-linux root=/dev/sda6<br />
initrd /initramfs-linux.img<br />
boot<br />
<br />
After successfully booting the Arch Linux installation, users can correct {{Filename|grub.cfg}} as needed and then run:<br />
# grub-install /dev/sda --no-floppy<br />
<br />
to reinstall GRUB2 and fix the problem completely, changing {{Filename|/dev/sda}} if needed. See [[#Bootloader installation]] for details.<br />
<br />
== Combining the use of UUID's and basic scripting ==<br />
<br />
If you like the idea of using UUID's to avoid unreliable BIOS mappings or are struggling with Grub's syntax, here is an example boot menu item that uses UUID's and a small script to direct Grub to the proper disk partitions for your system. All you need to do is replace the UUID's in the sample with the correct UUID's for your system. (The example applies to a system with a boot and root partition. You will obviously need to modify the Grub configuration if you have additional partitions.)<br />
<br />
menuentry "Arch Linux 64" {<br />
#Enter the UUID of your boot partition (this is where Grub and your kernel reside)<br />
set uuid_grub_boot=ece0448f-bb08-486d-9864-ac3271bd8d07<br />
<br />
#Enter the UUID of the partition containing the root partition of your Arch Linux installation. <br />
set uuid_os_root=c55da16f-e2af-4603-9e0b-03f5f565ec4a<br />
<br />
#(Note: this may be the same as your boot partition)<br />
<br />
#Here we set the Grub "root" variable by locating the UUID of the root partition identified above <br />
search --fs-uuid --no-floppy --set=root $uuid_os_root<br />
<br />
#Here we set a custom variable grub_boot by locating the UUID of the boot partition identified above <br />
search --fs-uuid --no-floppy --set=grub_boot $uuid_grub_boot<br />
<br />
#Here is the magic. We test to see if the boot and root partitions have the same UUID.<br />
#If they do, we append /boot to the $grub_boot variable. For ex. (hd0,1) becomes (hd0,1)/boot.<br />
if [ $uuid_grub_boot == $uuid_os_root ] ; then<br />
set grub_boot=$grub_boot/boot<br />
fi<br />
<br />
# $grub_boot now points to the correct location, so the following will properly find the kernel and initrd<br />
linux ($grub_boot)/vmlinuz-linux root=/dev/disk/by-uuid/$uuid_os_root ro<br />
initrd ($grub_boot)/initramfs-linux.img<br />
}<br />
<br />
== Troubleshooting ==<br />
<br />
Any troubleshooting should be added here.<br />
<br />
=== Enable GRUB2 debug messages ===<br />
<br />
Add<br />
<br />
set pager=1<br />
set debug=all<br />
<br />
to {{Filename|grub.cfg}}.<br />
<br />
=== Correct GRUB2 No Suitable Mode Found Error ===<br />
<br />
If you get this error when booting any menuentry<br />
<br />
error: no suitable mode found<br />
Booting however<br />
<br />
Then you need to initialize grub2 graphical terminal (gfxterm) with proper video mode (gfxmode) in grub2. This video mode is passed by grub2 to the linux kernel via 'gfxpayload'. In case of UEFI systems, if the grub2 video mode is not initialized, no kernel boot messages will be shown in the terminal (atleast until KMS kicks in)<br />
<br />
Copy {{Filename|/usr/share/grub/unicode.pf2}} to ${GRUB2_PREFIX_DIR} ({{Filename|/boot/grub/}} in case of BIOS systems and {{Filename|/boot/efi/efi/grub/}} in case of UEFI systems). <br />
<br />
# cp /usr/share/grub/unicode.pf2 ${GRUB2_PREFIX_DIR}<br />
<br />
If {{Filename|/usr/share/grub/unicode.pf2}} does not exist, install {{Package Official|bdf-unifont}}, create the unifont.pf2 file and then copy it to ${GRUB2_PREFIX_DIR} .<br />
<br />
# grub-mkfont -o unicode.pf2 /usr/share/fonts/misc/unifont.bdf<br />
<br />
Then, in the {{Filename|grub.cfg}} file, add the following lines to enable grub2 to pass the video mode correctly to the kernel, without of which you will only get a black screen (no output) but booting (actually) proceeds successfully without any system hang:<br />
<br />
BIOS systems<br />
<br />
insmod vbe<br />
<br />
UEFI systems<br />
<br />
insmod efi_gop<br />
insmod efi_uga<br />
<br />
After that add the following code (common to both BIOS and UEFI)<br />
<br />
insmod font<br />
<br />
if loadfont ${prefix}/unicode.pf2<br />
then<br />
insmod gfxterm<br />
set gfxmode=auto<br />
set gfxpayload=keep<br />
terminal_output gfxterm<br />
fi<br />
<br />
As you can see for gfxterm (graphical terminal) to function properly, {{Filename|unicode.pf2}} font file should exist in ${GRUB2_PREFIX_DIR}.<br />
<br />
=== msdos-style error message ===<br />
<br />
grub-setup: warn: This msdos-style partition label has no post-MBR gap; embedding won't be possible!<br />
grub-setup: warn: Embedding is not possible. GRUB can only be installed in this setup by using blocklists.<br />
However, blocklists are UNRELIABLE and its use is discouraged.<br />
grub-setup: error: If you really want blocklists, use --force.<br />
<br />
This error may occur when you try installing GRUB2 in a VMware container. Read more about it [http://bbs.archlinux.org/viewtopic.php?pid=581760#p581760 here]. It happens when the first partition starts just after the MBR (block 63), without the usual space of 1 MiB (2048 blocks) before the first partition. Read [[#MBR_aka_msdos_partitioning_specific_instructions]]<br />
<br />
=== UEFI GRUB2 not loaded ===<br />
In some cases the EFI may fail to load grub correctly. Provided everything is set up correctly, the output of<br />
efibootmgr -v<br />
might look something like this:<br />
BootCurrent: 0000<br />
Timeout: 3 seconds<br />
BootOrder: 0000,0001,0002<br />
Boot0000* Grub HD(1,800,32000,23532fbb-1bfa-4e46-851a-b494bfe9478c)File(\efi\grub\grub.efi)<br />
Boot0001* Shell HD(1,800,32000,23532fbb-1bfa-4e46-851a-b494bfe9478c)File(\EfiShell.efi)<br />
Boot0002* Festplatte BIOS(2,0,00)P0: SAMSUNG HD204UI .<br />
If everything works correctly, the EFI would now automatically load grub.<br><br />
If the screen only goes black for a second and the next boot option is tried afterwards, according to [https://bbs.archlinux.org/viewtopic.php?pid=981560#p981560 this post], moving grub to the partition root can help. The boot option has to be deleted and recreated afterwards. The entry for grub should look like this then:<br />
Boot0000* Grub HD(1,800,32000,23532fbb-1bfa-4e46-851a-b494bfe9478c)File(\grub.efi)<br />
<br />
=== Invalid signature ===<br />
If trying to boot windows results in an "invalid signature" error, e.g. after reconfiguring partitions or adding additional hard drives, (re)move grub's device configuration and let it reconfigure.<br />
# mv /boot/grub/device.map /boot/grub/device.map-old<br />
# grub-mkconfig -o /boot/grub/grub.cfg<br />
Grub-mkconfig should now mention all found boot options including windows. If it works, remove /boot/grub/device.map-old.<br />
<br />
== References ==<br />
<br />
# Official GRUB2 Manual - http://www.gnu.org/software/grub/manual/grub.html<br />
# GRUB2 wiki page describing steps to compile for UEFI systems - https://help.ubuntu.com/community/UEFIBooting - previously http://grub.enbug.org/TestingOnUEFI{{Linkrot|2011|09|05}}<br />
# Wikipedia's page on [http://en.wikipedia.org/wiki/BIOS_Boot_partition BIOS Boot Partition]<br />
<br />
== External Links ==<br />
<br />
# [https://github.com/the-ridikulus-rat/My_Shell_Scripts/blob/master/grub2/grub2_bios.sh A Linux Bash Shell script to compile and install GRUB2 for BIOS from BZR Source]<br />
# [https://github.com/the-ridikulus-rat/My_Shell_Scripts/blob/master/grub2/grub2_uefi.sh A Linux Bash Shell script to compile and install GRUB2 for UEFI from BZR Source]</div>Mayweedhttps://wiki.archlinux.org/index.php?title=Dell_Inspiron_Mini_11z&diff=103471Dell Inspiron Mini 11z2010-04-15T12:53:08Z<p>Mayweed: /* Hardware */</p>
<hr />
<div>[[Category:Dell (English)]]<br />
{{i18n|Dell Inspiron Mini 11z}}<br />
<br />
The Dell Inspiron Mini 11z is a netbook from Dell.<br />
<br />
== Hardware ==<br />
<pre><br />
[root@asgard guillaume]$ lspci<br />
00:00.0 Host bridge: Intel Corporation Mobile 4 Series Chipset Memory Controller Hub (rev 07)<br />
00:02.0 VGA compatible controller: Intel Corporation Mobile 4 Series Chipset Integrated Graphics Controller (rev 07)<br />
00:02.1 Display controller: Intel Corporation Mobile 4 Series Chipset Integrated Graphics Controller (rev 07)<br />
00:1a.0 USB Controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #4 (rev 03)<br />
00:1a.1 USB Controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #5 (rev 03)<br />
00:1a.7 USB Controller: Intel Corporation 82801I (ICH9 Family) USB2 EHCI Controller #2 (rev 03)<br />
00:1b.0 Audio device: Intel Corporation 82801I (ICH9 Family) HD Audio Controller (rev 03)<br />
00:1c.0 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 1 (rev 03)<br />
00:1c.1 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 2 (rev 03)<br />
00:1d.0 USB Controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #1 (rev 03)<br />
00:1d.1 USB Controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #2 (rev 03)<br />
00:1d.2 USB Controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #3 (rev 03)<br />
00:1d.7 USB Controller: Intel Corporation 82801I (ICH9 Family) USB2 EHCI Controller #1 (rev 03)<br />
00:1e.0 PCI bridge: Intel Corporation 82801 Mobile PCI Bridge (rev 93)<br />
00:1f.0 ISA bridge: Intel Corporation ICH9M-E LPC Interface Controller (rev 03)<br />
00:1f.2 SATA controller: Intel Corporation ICH9M/M-E SATA AHCI Controller (rev 03)<br />
00:1f.3 SMBus: Intel Corporation 82801I (ICH9 Family) SMBus Controller (rev 03)<br />
02:00.0 Ethernet controller: Atheros Communications Atheros AR8132 / L1c Gigabit Ethernet Adapter (rev c0)<br />
08:00.0 Network controller: Broadcom Corporation BCM4312 802.11b/g (rev 01)<br />
</pre><br />
Normally, all should work out of the box, except the [[Broadcom_BCM4312]] which needs some tweaking. The Network Controller (Atheros) is buggy in the 2009.8 iso packed with a 2.6.30 kernel, so at first nothing is detected at all (in dmesg as of in ifconfig -a). If you're in that case, see : http://bbs.archlinux.org/viewtopic.php?pid=728569 . The bug has been corrected in the kernel, so this thread will become irrelevant with a new iso.<br />
<br />
== Installing ==<br />
Because the netbook has no CD-ROM drive you need to boot from a USB. See the guide [[Install_from_USB_stick]].<br />
<br />
== Xorg ==<br />
Setting up Xorg is easy on the Mini 11z. Just follow the guide for [[Xorg | Xorg]] and hal will do the rest. <br />
<br />
Kernel Mode Setting (KMS) works well on the 11z, allowing the native resolution to work at init level 3, and flickerless switching between the terminal and X sessions. See "Early Start" section in [[Intel]] for more details.<br />
<br />
<br />
== Sound ==<br />
"Just works" with OSS, or ALSA<br />
<br />
== Extras ==<br />
=== Webcam ===<br />
UVC 1.00 compatible - should work out of the box, with the latest kernel (remember to add user to video group). You may use the <code>cheese</code> package to test it.</div>Mayweedhttps://wiki.archlinux.org/index.php?title=Dell_Inspiron_Mini_11z&diff=103470Dell Inspiron Mini 11z2010-04-15T12:51:08Z<p>Mayweed: /* Hardware */</p>
<hr />
<div>[[Category:Dell (English)]]<br />
{{i18n|Dell Inspiron Mini 11z}}<br />
<br />
The Dell Inspiron Mini 11z is a netbook from Dell.<br />
<br />
== Hardware ==<br />
<pre><br />
[root@asgard guillaume]$ lspci<br />
00:00.0 Host bridge: Intel Corporation Mobile 4 Series Chipset Memory Controller Hub (rev 07)<br />
00:02.0 VGA compatible controller: Intel Corporation Mobile 4 Series Chipset Integrated Graphics Controller (rev 07)<br />
00:02.1 Display controller: Intel Corporation Mobile 4 Series Chipset Integrated Graphics Controller (rev 07)<br />
00:1a.0 USB Controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #4 (rev 03)<br />
00:1a.1 USB Controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #5 (rev 03)<br />
00:1a.7 USB Controller: Intel Corporation 82801I (ICH9 Family) USB2 EHCI Controller #2 (rev 03)<br />
00:1b.0 Audio device: Intel Corporation 82801I (ICH9 Family) HD Audio Controller (rev 03)<br />
00:1c.0 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 1 (rev 03)<br />
00:1c.1 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 2 (rev 03)<br />
00:1d.0 USB Controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #1 (rev 03)<br />
00:1d.1 USB Controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #2 (rev 03)<br />
00:1d.2 USB Controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #3 (rev 03)<br />
00:1d.7 USB Controller: Intel Corporation 82801I (ICH9 Family) USB2 EHCI Controller #1 (rev 03)<br />
00:1e.0 PCI bridge: Intel Corporation 82801 Mobile PCI Bridge (rev 93)<br />
00:1f.0 ISA bridge: Intel Corporation ICH9M-E LPC Interface Controller (rev 03)<br />
00:1f.2 SATA controller: Intel Corporation ICH9M/M-E SATA AHCI Controller (rev 03)<br />
00:1f.3 SMBus: Intel Corporation 82801I (ICH9 Family) SMBus Controller (rev 03)<br />
02:00.0 Ethernet controller: Atheros Communications Atheros AR8132 / L1c Gigabit Ethernet Adapter (rev c0)<br />
08:00.0 Network controller: Broadcom Corporation BCM4312 802.11b/g (rev 01)<br />
</pre><br />
Normally, all should work out of the box, except the [[Broadcom_BCM4312]] which needs some tweaking. The Network Controller (Atheros) is buggy in the 2009.8 iso, so at first nothing is detected at all (in dmesg as of in ifconfig -a). If you're in that case, see : http://bbs.archlinux.org/viewtopic.php?pid=728569 . The bug has been corrected in the kernel, so this thread will become irrelevant with a new iso.<br />
<br />
== Installing ==<br />
Because the netbook has no CD-ROM drive you need to boot from a USB. See the guide [[Install_from_USB_stick]].<br />
<br />
== Xorg ==<br />
Setting up Xorg is easy on the Mini 11z. Just follow the guide for [[Xorg | Xorg]] and hal will do the rest. <br />
<br />
Kernel Mode Setting (KMS) works well on the 11z, allowing the native resolution to work at init level 3, and flickerless switching between the terminal and X sessions. See "Early Start" section in [[Intel]] for more details.<br />
<br />
<br />
== Sound ==<br />
"Just works" with OSS, or ALSA<br />
<br />
== Extras ==<br />
=== Webcam ===<br />
UVC 1.00 compatible - should work out of the box, with the latest kernel (remember to add user to video group). You may use the <code>cheese</code> package to test it.</div>Mayweedhttps://wiki.archlinux.org/index.php?title=Ranger&diff=103469Ranger2010-04-15T12:49:04Z<p>Mayweed: moved My New Page to Dell Inspiron Mini 11z:&#32;This page is near complete.</p>
<hr />
<div>#REDIRECT [[Dell Inspiron Mini 11z]]</div>Mayweedhttps://wiki.archlinux.org/index.php?title=Dell_Inspiron_Mini_11z&diff=103468Dell Inspiron Mini 11z2010-04-15T12:49:04Z<p>Mayweed: moved My New Page to Dell Inspiron Mini 11z:&#32;This page is near complete.</p>
<hr />
<div>[[Category:Dell (English)]]<br />
{{i18n|Dell Inspiron Mini 11z}}<br />
<br />
The Dell Inspiron Mini 11z is a netbook from Dell.<br />
<br />
== Hardware ==<br />
<pre><br />
[root@asgard guillaume]$ lspci<br />
00:00.0 Host bridge: Intel Corporation Mobile 4 Series Chipset Memory Controller Hub (rev 07)<br />
00:02.0 VGA compatible controller: Intel Corporation Mobile 4 Series Chipset Integrated Graphics Controller (rev 07)<br />
00:02.1 Display controller: Intel Corporation Mobile 4 Series Chipset Integrated Graphics Controller (rev 07)<br />
00:1a.0 USB Controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #4 (rev 03)<br />
00:1a.1 USB Controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #5 (rev 03)<br />
00:1a.7 USB Controller: Intel Corporation 82801I (ICH9 Family) USB2 EHCI Controller #2 (rev 03)<br />
00:1b.0 Audio device: Intel Corporation 82801I (ICH9 Family) HD Audio Controller (rev 03)<br />
00:1c.0 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 1 (rev 03)<br />
00:1c.1 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 2 (rev 03)<br />
00:1d.0 USB Controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #1 (rev 03)<br />
00:1d.1 USB Controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #2 (rev 03)<br />
00:1d.2 USB Controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #3 (rev 03)<br />
00:1d.7 USB Controller: Intel Corporation 82801I (ICH9 Family) USB2 EHCI Controller #1 (rev 03)<br />
00:1e.0 PCI bridge: Intel Corporation 82801 Mobile PCI Bridge (rev 93)<br />
00:1f.0 ISA bridge: Intel Corporation ICH9M-E LPC Interface Controller (rev 03)<br />
00:1f.2 SATA controller: Intel Corporation ICH9M/M-E SATA AHCI Controller (rev 03)<br />
00:1f.3 SMBus: Intel Corporation 82801I (ICH9 Family) SMBus Controller (rev 03)<br />
02:00.0 Ethernet controller: Atheros Communications Atheros AR8132 / L1c Gigabit Ethernet Adapter (rev c0)<br />
08:00.0 Network controller: Broadcom Corporation BCM4312 802.11b/g (rev 01)<br />
</pre><br />
Normally, all should work out of the box, except the [[Broadcom_BCM4312]] which needs some tweaking. The Network Controller (Atheros) is buggy in the 2009.8 iso, so at first nothing is detected at all (in dmesg as of in ifconfig -a). If you're in that case, see : http://bbs.archlinux.org/viewtopic.php?pid=728569<br />
<br />
== Installing ==<br />
Because the netbook has no CD-ROM drive you need to boot from a USB. See the guide [[Install_from_USB_stick]].<br />
<br />
== Xorg ==<br />
Setting up Xorg is easy on the Mini 11z. Just follow the guide for [[Xorg | Xorg]] and hal will do the rest. <br />
<br />
Kernel Mode Setting (KMS) works well on the 11z, allowing the native resolution to work at init level 3, and flickerless switching between the terminal and X sessions. See "Early Start" section in [[Intel]] for more details.<br />
<br />
<br />
== Sound ==<br />
"Just works" with OSS, or ALSA<br />
<br />
== Extras ==<br />
=== Webcam ===<br />
UVC 1.00 compatible - should work out of the box, with the latest kernel (remember to add user to video group). You may use the <code>cheese</code> package to test it.</div>Mayweedhttps://wiki.archlinux.org/index.php?title=Dell_Inspiron_Mini_11z&diff=103467Dell Inspiron Mini 11z2010-04-15T12:45:04Z<p>Mayweed: </p>
<hr />
<div>[[Category:Dell (English)]]<br />
{{i18n|Dell Inspiron Mini 11z}}<br />
<br />
The Dell Inspiron Mini 11z is a netbook from Dell.<br />
<br />
== Hardware ==<br />
<pre><br />
[root@asgard guillaume]$ lspci<br />
00:00.0 Host bridge: Intel Corporation Mobile 4 Series Chipset Memory Controller Hub (rev 07)<br />
00:02.0 VGA compatible controller: Intel Corporation Mobile 4 Series Chipset Integrated Graphics Controller (rev 07)<br />
00:02.1 Display controller: Intel Corporation Mobile 4 Series Chipset Integrated Graphics Controller (rev 07)<br />
00:1a.0 USB Controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #4 (rev 03)<br />
00:1a.1 USB Controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #5 (rev 03)<br />
00:1a.7 USB Controller: Intel Corporation 82801I (ICH9 Family) USB2 EHCI Controller #2 (rev 03)<br />
00:1b.0 Audio device: Intel Corporation 82801I (ICH9 Family) HD Audio Controller (rev 03)<br />
00:1c.0 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 1 (rev 03)<br />
00:1c.1 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 2 (rev 03)<br />
00:1d.0 USB Controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #1 (rev 03)<br />
00:1d.1 USB Controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #2 (rev 03)<br />
00:1d.2 USB Controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #3 (rev 03)<br />
00:1d.7 USB Controller: Intel Corporation 82801I (ICH9 Family) USB2 EHCI Controller #1 (rev 03)<br />
00:1e.0 PCI bridge: Intel Corporation 82801 Mobile PCI Bridge (rev 93)<br />
00:1f.0 ISA bridge: Intel Corporation ICH9M-E LPC Interface Controller (rev 03)<br />
00:1f.2 SATA controller: Intel Corporation ICH9M/M-E SATA AHCI Controller (rev 03)<br />
00:1f.3 SMBus: Intel Corporation 82801I (ICH9 Family) SMBus Controller (rev 03)<br />
02:00.0 Ethernet controller: Atheros Communications Atheros AR8132 / L1c Gigabit Ethernet Adapter (rev c0)<br />
08:00.0 Network controller: Broadcom Corporation BCM4312 802.11b/g (rev 01)<br />
</pre><br />
Normally, all should work out of the box, except the [[Broadcom_BCM4312]] which needs some tweaking. The Network Controller (Atheros) is buggy in the 2009.8 iso, so at first nothing is detected at all (in dmesg as of in ifconfig -a). If you're in that case, see : http://bbs.archlinux.org/viewtopic.php?pid=728569<br />
<br />
== Installing ==<br />
Because the netbook has no CD-ROM drive you need to boot from a USB. See the guide [[Install_from_USB_stick]].<br />
<br />
== Xorg ==<br />
Setting up Xorg is easy on the Mini 11z. Just follow the guide for [[Xorg | Xorg]] and hal will do the rest. <br />
<br />
Kernel Mode Setting (KMS) works well on the 11z, allowing the native resolution to work at init level 3, and flickerless switching between the terminal and X sessions. See "Early Start" section in [[Intel]] for more details.<br />
<br />
<br />
== Sound ==<br />
"Just works" with OSS, or ALSA<br />
<br />
== Extras ==<br />
=== Webcam ===<br />
UVC 1.00 compatible - should work out of the box, with the latest kernel (remember to add user to video group). You may use the <code>cheese</code> package to test it.</div>Mayweedhttps://wiki.archlinux.org/index.php?title=Dell_Inspiron_Mini_11z&diff=103466Dell Inspiron Mini 11z2010-04-15T12:41:12Z<p>Mayweed: Created page with 'Category:Dell (English) The Dell Inspiron Mini 11z is a netbook from Dell. == Hardware == <pre> [root@asgard guillaume]$ lspci -v 00:00.0 Host bridge: Intel Corporation Mobi…'</p>
<hr />
<div>[[Category:Dell (English)]]<br />
The Dell Inspiron Mini 11z is a netbook from Dell.<br />
<br />
== Hardware ==<br />
<pre><br />
[root@asgard guillaume]$ lspci -v<br />
00:00.0 Host bridge: Intel Corporation Mobile 4 Series Chipset Memory Controller Hub (rev 07)<br />
Subsystem: Dell Device 0409<br />
Flags: bus master, fast devsel, latency 0<br />
Capabilities: [e0] Vendor Specific Information: Len=0a <?><br />
Kernel driver in use: agpgart-intel<br />
Kernel modules: intel-agp<br />
<br />
00:02.0 VGA compatible controller: Intel Corporation Mobile 4 Series Chipset Integrated Graphics Controller (rev 07) (prog-if 00 [VGA controller])<br />
Subsystem: Dell Device 0409<br />
Flags: bus master, fast devsel, latency 0, IRQ 26<br />
Memory at f0000000 (64-bit, non-prefetchable) [size=4M]<br />
Memory at d0000000 (64-bit, prefetchable) [size=256M]<br />
I/O ports at 1800 [size=8]<br />
Expansion ROM at <unassigned> [disabled]<br />
Capabilities: [90] MSI: Enable+ Count=1/1 Maskable- 64bit-<br />
Capabilities: [d0] Power Management version 3<br />
Kernel driver in use: i915<br />
Kernel modules: i915<br />
<br />
00:02.1 Display controller: Intel Corporation Mobile 4 Series Chipset Integrated Graphics Controller (rev 07)<br />
Subsystem: Dell Device 0409<br />
Flags: bus master, fast devsel, latency 0<br />
Memory at f0400000 (64-bit, non-prefetchable) [size=1M]<br />
Capabilities: [d0] Power Management version 3<br />
<br />
00:1a.0 USB Controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #4 (rev 03) (prog-if 00 [UHCI])<br />
Subsystem: Dell Device 0409<br />
Flags: bus master, medium devsel, latency 0, IRQ 16<br />
I/O ports at 1820 [size=32]<br />
Capabilities: [50] PCI Advanced Features<br />
Kernel driver in use: uhci_hcd<br />
Kernel modules: uhci-hcd<br />
<br />
00:1a.1 USB Controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #5 (rev 03) (prog-if 00 [UHCI])<br />
Subsystem: Dell Device 0409<br />
Flags: bus master, medium devsel, latency 0, IRQ 21<br />
I/O ports at 1840 [size=32]<br />
Capabilities: [50] PCI Advanced Features<br />
Kernel driver in use: uhci_hcd<br />
Kernel modules: uhci-hcd<br />
<br />
00:1a.7 USB Controller: Intel Corporation 82801I (ICH9 Family) USB2 EHCI Controller #2 (rev 03) (prog-if 20 [EHCI])<br />
Subsystem: Dell Device 0409<br />
Flags: bus master, medium devsel, latency 0, IRQ 19<br />
Memory at f0904800 (32-bit, non-prefetchable) [size=1K]<br />
Capabilities: [50] Power Management version 2<br />
Capabilities: [58] Debug port: BAR=1 offset=00a0<br />
Capabilities: [98] PCI Advanced Features<br />
Kernel driver in use: ehci_hcd<br />
Kernel modules: ehci-hcd<br />
<br />
00:1b.0 Audio device: Intel Corporation 82801I (ICH9 Family) HD Audio Controller (rev 03)<br />
Subsystem: Dell Device 0409<br />
Flags: bus master, fast devsel, latency 0, IRQ 28<br />
Memory at f0700000 (64-bit, non-prefetchable) [size=16K]<br />
Capabilities: [50] Power Management version 2<br />
Capabilities: [60] MSI: Enable+ Count=1/1 Maskable- 64bit+<br />
Capabilities: [70] Express Root Complex Integrated Endpoint, MSI 00<br />
Capabilities: [100] Virtual Channel<br />
Capabilities: [130] Root Complex Link<br />
Kernel driver in use: HDA Intel<br />
Kernel modules: snd-hda-intel<br />
<br />
00:1c.0 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 1 (rev 03) (prog-if 00 [Normal decode])<br />
Flags: bus master, fast devsel, latency 0<br />
Bus: primary=00, secondary=02, subordinate=02, sec-latency=0<br />
I/O behind bridge: 00002000-00002fff<br />
Memory behind bridge: f0500000-f05fffff<br />
Prefetchable memory behind bridge: 0000000080000000-00000000801fffff<br />
Capabilities: [40] Express Root Port (Slot+), MSI 00<br />
Capabilities: [80] MSI: Enable+ Count=1/1 Maskable- 64bit-<br />
Capabilities: [90] Subsystem: Dell Device 0409<br />
Capabilities: [a0] Power Management version 2<br />
Capabilities: [100] Virtual Channel<br />
Capabilities: [180] Root Complex Link<br />
Kernel driver in use: pcieport<br />
Kernel modules: shpchp<br />
<br />
00:1c.1 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 2 (rev 03) (prog-if 00 [Normal decode])<br />
Flags: bus master, fast devsel, latency 0<br />
Bus: primary=00, secondary=08, subordinate=08, sec-latency=0<br />
I/O behind bridge: 00003000-00003fff<br />
Memory behind bridge: f0600000-f06fffff<br />
Prefetchable memory behind bridge: 0000000080200000-00000000803fffff<br />
Capabilities: [40] Express Root Port (Slot+), MSI 00<br />
Capabilities: [80] MSI: Enable+ Count=1/1 Maskable- 64bit-<br />
Capabilities: [90] Subsystem: Dell Device 0409<br />
Capabilities: [a0] Power Management version 2<br />
Capabilities: [100] Virtual Channel<br />
Capabilities: [180] Root Complex Link<br />
Kernel driver in use: pcieport<br />
Kernel modules: shpchp<br />
<br />
00:1d.0 USB Controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #1 (rev 03) (prog-if 00 [UHCI])<br />
Subsystem: Dell Device 0409<br />
Flags: bus master, medium devsel, latency 0, IRQ 23<br />
I/O ports at 1860 [size=32]<br />
Capabilities: [50] PCI Advanced Features<br />
Kernel driver in use: uhci_hcd<br />
Kernel modules: uhci-hcd<br />
<br />
00:1d.1 USB Controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #2 (rev 03) (prog-if 00 [UHCI])<br />
Subsystem: Dell Device 0409<br />
Flags: bus master, medium devsel, latency 0, IRQ 19<br />
I/O ports at 1880 [size=32]<br />
Capabilities: [50] PCI Advanced Features<br />
Kernel driver in use: uhci_hcd<br />
Kernel modules: uhci-hcd<br />
<br />
00:1d.2 USB Controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #3 (rev 03) (prog-if 00 [UHCI])<br />
Subsystem: Dell Device 0409<br />
Flags: bus master, medium devsel, latency 0, IRQ 18<br />
I/O ports at 18a0 [size=32]<br />
Capabilities: [50] PCI Advanced Features<br />
Kernel driver in use: uhci_hcd<br />
Kernel modules: uhci-hcd<br />
<br />
00:1d.7 USB Controller: Intel Corporation 82801I (ICH9 Family) USB2 EHCI Controller #1 (rev 03) (prog-if 20 [EHCI])<br />
Subsystem: Dell Device 0409<br />
Flags: bus master, medium devsel, latency 0, IRQ 23<br />
Memory at f0904c00 (32-bit, non-prefetchable) [size=1K]<br />
Capabilities: [50] Power Management version 2<br />
Capabilities: [58] Debug port: BAR=1 offset=00a0<br />
Capabilities: [98] PCI Advanced Features<br />
Kernel driver in use: ehci_hcd<br />
Kernel modules: ehci-hcd<br />
<br />
00:1e.0 PCI bridge: Intel Corporation 82801 Mobile PCI Bridge (rev 93) (prog-if 01 [Subtractive decode])<br />
Flags: bus master, fast devsel, latency 0<br />
Bus: primary=00, secondary=26, subordinate=26, sec-latency=0<br />
Capabilities: [50] Subsystem: Dell Device 0409<br />
<br />
00:1f.0 ISA bridge: Intel Corporation ICH9M-E LPC Interface Controller (rev 03)<br />
Subsystem: Dell Device 0409<br />
Flags: bus master, medium devsel, latency 0<br />
Capabilities: [e0] Vendor Specific Information: Len=0c <?><br />
Kernel modules: iTCO_wdt<br />
<br />
00:1f.2 SATA controller: Intel Corporation ICH9M/M-E SATA AHCI Controller (rev 03) (prog-if 01 [AHCI 1.0])<br />
Subsystem: Dell Device 0409<br />
Flags: bus master, 66MHz, medium devsel, latency 0, IRQ 27<br />
I/O ports at 1818 [size=8]<br />
I/O ports at 180c [size=4]<br />
I/O ports at 1810 [size=8]<br />
I/O ports at 1808 [size=4]<br />
I/O ports at 18c0 [size=32]<br />
Memory at f0904000 (32-bit, non-prefetchable) [size=2K]<br />
Capabilities: [80] MSI: Enable+ Count=1/16 Maskable- 64bit-<br />
Capabilities: [70] Power Management version 3<br />
Capabilities: [a8] SATA HBA v1.0<br />
Capabilities: [b0] PCI Advanced Features<br />
Kernel driver in use: ahci<br />
Kernel modules: ahci<br />
<br />
00:1f.3 SMBus: Intel Corporation 82801I (ICH9 Family) SMBus Controller (rev 03)<br />
Subsystem: Dell Device 0409<br />
Flags: medium devsel, IRQ 19<br />
Memory at 80400000 (64-bit, non-prefetchable) [size=256]<br />
I/O ports at 18e0 [size=32]<br />
Kernel modules: i2c-i801<br />
<br />
02:00.0 Ethernet controller: Atheros Communications Atheros AR8132 / L1c Gigabit Ethernet Adapter (rev c0)<br />
Subsystem: Dell Device 0409<br />
Flags: bus master, fast devsel, latency 0, IRQ 16<br />
Memory at f0500000 (64-bit, non-prefetchable) [size=256K]<br />
I/O ports at 2000 [size=128]<br />
Capabilities: [40] Power Management version 3<br />
Capabilities: [48] MSI: Enable- Count=1/1 Maskable- 64bit+<br />
Capabilities: [58] Express Endpoint, MSI 00<br />
Capabilities: [6c] Vital Product Data<br />
Capabilities: [100] Advanced Error Reporting<br />
Capabilities: [180] Device Serial Number ff-bb-27-8e-00-26-b9-ff<br />
Kernel driver in use: atl1c<br />
Kernel modules: atl1c<br />
<br />
08:00.0 Network controller: Broadcom Corporation BCM4312 802.11b/g (rev 01)<br />
Subsystem: Dell Wireless 1397 WLAN Mini-Card<br />
Flags: bus master, fast devsel, latency 0, IRQ 17<br />
Memory at f0600000 (64-bit, non-prefetchable) [size=16K]<br />
Capabilities: [40] Power Management version 3<br />
Capabilities: [58] Vendor Specific Information: Len=78 <?><br />
Capabilities: [e8] MSI: Enable- Count=1/1 Maskable- 64bit+<br />
Capabilities: [d0] Express Endpoint, MSI 00<br />
Capabilities: [100] Advanced Error Reporting<br />
Capabilities: [13c] Virtual Channel<br />
Capabilities: [160] Device Serial Number 35-d9-cb-ff-ff-32-f0-7b<br />
Capabilities: [16c] Power Budgeting <?><br />
Kernel driver in use: wl<br />
Kernel modules: wl, ssb<br />
</pre><br />
Normally, all should work out of the box, except the [[Broadcom_BCM4312]] which needs some tweaking. The Network Controller (Atheros) is buggy in the 2009.8 iso, so at first nothing is detected at all (in dmesg as of in ifconfig -a). If you're in that case, see : http://bbs.archlinux.org/viewtopic.php?pid=728569<br />
<br />
== Installing ==<br />
Because the netbook has no CD-ROM drive you need to boot from a USB. See the guide [[Install_from_USB_stick]].<br />
<br />
== Xorg ==<br />
Setting up Xorg is easy on the Mini 11z. Just follow the guide for [[Xorg | Xorg]] and hal will do the rest. <br />
<br />
Kernel Mode Setting (KMS) works well on the 11z, allowing the native resolution to work at init level 3, and flickerless switching between the terminal and X sessions. See "Early Start" section in [[Intel]] for more details.<br />
<br />
<br />
== Sound ==<br />
"Just works" with OSS, or ALSA<br />
<br />
== Extras ==<br />
=== Webcam ===<br />
UVC 1.00 compatible - should work out of the box, with the latest kernel (remember to add user to video group). You may use the <code>cheese</code> package to test it.</div>Mayweed