{"id":2770,"date":"2020-02-21T21:17:01","date_gmt":"2020-02-21T18:17:01","guid":{"rendered":"http:\/\/surgery.moscow\/smos\/?p=2770"},"modified":"2020-02-21T21:17:08","modified_gmt":"2020-02-21T18:17:08","slug":"grub-centos","status":"publish","type":"post","link":"https:\/\/surgery.moscow\/smos\/2020\/02\/21\/grub-centos\/","title":{"rendered":"Grub : Centos"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"The_Boot_Menu_is_Automatically_Created\">1. The Boot Menu is Automatically Created<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Do not attempt to manually edit the boot menu because it is automatically created from files within the <strong>\/boot\/<\/strong> directory tree. However you can adjust the <strong>\/etc\/default\/grub<\/strong> file that defines the general settings and the <strong>\/etc\/grub.d\/40_custom<\/strong> file to add specific custom entries. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The content of the <strong>\/etc\/default\/grub<\/strong> file looks like this: <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">GRUB_TIMEOUT=5\nGRUB_DEFAULT=saved\nGRUB_DISABLE_SUBMENU=true\nGRUB_TERMINAL_OUTPUT=\"console\"\nGRUB_CMDLINE_LINUX=\"crashkernel=auto rhgb quiet\"\nGRUB_DISABLE_RECOVERY=\"true\"<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Kernel options that are common to each entry are defined on the <strong>GRUB_CMDLINE_LINUX<\/strong> line. For example, if you like to see the full detailed boot messages, delete <strong>rhgb quiet<\/strong>. If you like to see the standard boot messages, just delete <strong>rhgb<\/strong>. Changes to the setting is made effective by executing the following command: <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[root@host ~]# grub2-mkconfig -o \/boot\/grub2\/grub.cfg\nGenerating grub configuration file ...\nFound linux image: \/boot\/vmlinuz-3.10.0-229.14.1.el7.x86_64\nFound initrd image: \/boot\/initramfs-3.10.0-229.14.1.el7.x86_64.img\nFound linux image: \/boot\/vmlinuz-3.10.0-229.4.2.el7.x86_64\nFound initrd image: \/boot\/initramfs-3.10.0-229.4.2.el7.x86_64.img\nFound linux image: \/boot\/vmlinuz-3.10.0-229.el7.x86_64\nFound initrd image: \/boot\/initramfs-3.10.0-229.el7.x86_64.img\nFound linux image: \/boot\/vmlinuz-0-rescue-605f01abef434fb98dd1309e774b72ba\nFound initrd image: \/boot\/initramfs-0-rescue-605f01abef434fb98dd1309e774b72ba.img\ndone<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">On UEFI-based systems, the command will be <strong>grub2-mkconfig -o \/boot\/efi\/EFI\/centos\/grub.cfg<\/strong> <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"How_to_Define_the_Default_Entries\">2. How to Define the Default Entries<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To list all the menu entries that will be displayed at system boot, issue the following command: <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[root@host ~]# awk -F\\' '$1==\"menuentry \" {print i++ \" : \" $2}' \/etc\/grub2.cfg\n0 : CentOS Linux 7 (Core), with Linux 3.10.0-229.14.1.el7.x86_64\n1 : CentOS Linux 7 (Core), with Linux 3.10.0-229.4.2.el7.x86_64\n2 : CentOS Linux 7 (Core), with Linux 3.10.0-229.el7.x86_64\n3 : CentOS Linux 7 (Core), with Linux 0-rescue-605f01abef434fb98dd1309e774b72ba<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Or alternatively: <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[root@host ~]# grep \"^menuentry\" \/boot\/grub2\/grub.cfg | cut -d \"'\" -f2<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The file name <strong>\/etc\/grub2.cfg<\/strong>\n is a symbolic link to the grub.cfg file, whose location is architecture\n dependent. It is better to use absolute paths when accessing to a file,\n as in the example above, especially when repairing a system. The \ndefault entry is defined by the <strong>GRUB_DEFAULT<\/strong> line in the <strong>\/etc\/default\/grub<\/strong> file. However, if the <strong>GRUB_DEFAULT<\/strong> line is set as <strong>saved<\/strong>, the parameter is stored in the <strong>\/boot\/grub2\/grubenv<\/strong> file. It may be viewed by: <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[root@host ~]# grub2-editenv list\nsaved_entry=CentOS Linux (3.10.0-229.14.1.el7.x86_64) 7 (Core)<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Another useful entry in the <strong>\/etc\/default\/grub<\/strong> file is: <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">GRUB_SAVEDEFAULT=true<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Together with <strong>GRUB_DEFAULT=saved<\/strong>,\n it makes sure that the currently used boot menu entry is automatically \nmarked for the next boot &#8212; useful e.g. on a dual-boot system where \nupdating Windows needs a number of reboots. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong>\/boot\/grub2\/grubenv<\/strong> file cannot be manually edited. Use the following command instead: <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[root@host ~]# grub2-set-default 2\n[root@host ~]# grub2-editenv list\nsaved_entry=2<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Note that the first entry in the output of the awk command, above, is index number 0. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now reboot the system. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"Rescue_Mode_and_Emergency_Mode\">3. Rescue Mode and Emergency Mode<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The &#171;Linux 0-rescue-&#8230;&#187; menu entry is to boot the system in rescue mode. This is equivalent to the single-user mode. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In\n addition, with CentOS 7, an emergency mode is also available. In this \nlatter mode, a shell is provided immediately after systemd has started. \nNo other processes will exist and the root filesystem will be mounted as\n read-only. No other filesystems will be mounted. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To\n boot into emergency mode, enter the setup edit display by typing &#171;e&#187; in\n the grub2 menu. Then add &#171;systemd.unit=emergency.target&#187; to the end of \nthe kernel option. <\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/wiki.centos.org\/moin_static1910\/memodump\/img\/smile.png\" alt=\":-)\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">[If you have a friendly relationship with systemd  you can see what happens in emergency mode by viewing the <strong>\/usr\/lib\/systemd\/system\/emergency.service<\/strong> file.] <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/wiki.centos.org\/HowTos\/Grub2\">https:\/\/wiki.centos.org\/HowTos\/Grub2<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. The Boot Menu is Automatically Created Do not attempt to manually edit the boot menu because it is automatically<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,12,22],"tags":[],"class_list":["post-2770","post","type-post","status-publish","format-standard","hentry","category-computer","category-internet","category-technology"],"_links":{"self":[{"href":"https:\/\/surgery.moscow\/smos\/wp-json\/wp\/v2\/posts\/2770","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/surgery.moscow\/smos\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/surgery.moscow\/smos\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/surgery.moscow\/smos\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/surgery.moscow\/smos\/wp-json\/wp\/v2\/comments?post=2770"}],"version-history":[{"count":1,"href":"https:\/\/surgery.moscow\/smos\/wp-json\/wp\/v2\/posts\/2770\/revisions"}],"predecessor-version":[{"id":2771,"href":"https:\/\/surgery.moscow\/smos\/wp-json\/wp\/v2\/posts\/2770\/revisions\/2771"}],"wp:attachment":[{"href":"https:\/\/surgery.moscow\/smos\/wp-json\/wp\/v2\/media?parent=2770"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/surgery.moscow\/smos\/wp-json\/wp\/v2\/categories?post=2770"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/surgery.moscow\/smos\/wp-json\/wp\/v2\/tags?post=2770"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}