{"id":167,"date":"2013-10-20T12:07:00","date_gmt":"2013-10-20T16:07:00","guid":{"rendered":"http:\/\/www.mufljuz.com\/?p=167"},"modified":"2015-06-09T21:16:40","modified_gmt":"2015-06-10T01:16:40","slug":"grub2-on-gentoo","status":"publish","type":"post","link":"https:\/\/www.mufljuz.com\/?p=167","title":{"rendered":"Grub2 on gentoo"},"content":{"rendered":"<p>Grub2 is finally declared as stable in gentoo portage. While optional, migration from grub:0 to grub2 is straightforward.<\/p>\n<p>Installation of grub2 is done in four steps.<\/p>\n<p>First inspect your existing grub.conf file and make sure naming is correct. Grub2 has strict naming requirements and wants kernel images to be named as kernel-${version} or vmlinuz-${version} and an initramfs must be named initramfs-${version}.img, initramfs-genkernel-${version}, initramfs-genkernel-${arch}-${version}, initrd-${version}.img, initrd.img-${version}, initrd-${version}.gz, or initrd-${version}. The kernel filenames must match a corresponding kernel that is available in \/boot. See <a href=\"http:\/\/www.gentoo.org\/doc\/en\/grub2-migration.xml\">gentoo migration guide<\/a>.<\/p>\n<p><code>nano -w \/boot\/grub\/grub.conf<\/code><\/p>\n<pre>default 0\r\ntimeout 5\r\nsplashimage=(hd0,0)\/boot\/grub\/splash.xpm.gz\r\n\r\ntitle GRUB2 Chainload\r\nroot (hd0,0)\r\nkernel \/boot\/grub\/i386-pc\/core.img\r\nboot\r\n\r\ntitle Gentoo Linux 3.10.7-r1\r\nroot (hd0,0)\r\nkernel \/boot\/kernel-3.10.7-gentoo-r1 root=\/dev\/sda2\r\n\r\ntitle Windoz7\r\nmap (hd0,0) (hd1,0)\r\nmap (hd1,0) (hd0,0)\r\nrootnoverify (hd1,0)\r\nmakeactive\r\nchainloader +1<\/pre>\n<p>GRUB2 Chainload section is added in order to allow testing of GRUB2 configuration before adopting it permanently.<\/p>\n<p>Secondly, install grub2 files on your \/boot partition.<br \/>\n<code><br \/>\n# grub2-install --grub-setup=\/bin\/true \/dev\/sda<br \/>\nInstallation finished. No error reported.<br \/>\n<\/code><\/p>\n<p>Thirdly, scan for the existing kernels.<\/p>\n<p>To probe for Windows, grub needs os-prober and ntfs3g packages<br \/>\n<code>emerge -av os-prober ntfs3g<\/code><\/p>\n<p><code><br \/>\n# grub2-mkconfig -o \/boot\/grub\/grub.cfg<br \/>\nGenerating grub.cfg ...<br \/>\nFound linux image: \/boot\/kernel-3.10.7-gentoo-r1<br \/>\nNo volume groups found<br \/>\nFound Windows 7 (loader) on \/dev\/sdb1<br \/>\ndone<br \/>\n<\/code><br \/>\n<code>grub2-mkconfig<\/code> will create <code>\/boot\/grub\/grub.cfg<\/code>. This file is automatically generated using templates from <code>\/etc\/grub.d<\/code> and settings from <code>\/etc\/default\/grub<\/code>. If you intend to use automatic configuration, <code>\/boot\/grub\/grub.cf<\/code>g shouldn&#8217;t be manually modified since it will be overwritten next time you run grub2 config.<br \/>\n<strong>NOTE:<\/strong> grub.cfg can be also manually configured on your own risk.<\/p>\n<p>Finally, test the configuration by rebooting and selecting GRUB2 Chainload. If everything works as supposed to install grub2 and remove the grub:0.<br \/>\n<code><br \/>\nmount \/boot<br \/>\ngrub2-install \/dev\/sda<br \/>\ngrub2-mkconfig -o \/boot\/grub\/grub.cfg<br \/>\nemerge -Ca sys-boot\/grub:0<br \/>\n<\/code><\/p>\n<h2>Upgrading\/modifying kernel<\/h2>\n<p>Whenever you wish to make changes to kernel grub2 has to be reconfigured. Add kernel image to \/boot\/ and run grub2 configuration.<br \/>\n<code><br \/>\ngrub2-mkconfig -o \/boot\/grub\/grub.cfg<br \/>\n<\/code><\/p>\n<p>Chanloading iso image with custom kernel arguments is described at <a href=\"http:\/\/wiki.gentoo.org\/wiki\/GRUB2\" title=\"gentoo wiki\"><\/a>. It involves creating <code>\/etc\/grub.d\/<\/code> rule.<\/p>\n<p><code>nano -w \/etc\/grub.d\/50_isofile<\/code><\/p>\n<pre>\r\n#!\/bin\/sh\r\nexec tail -n +3 $0\r\n\r\nmenuentry \"GRUB4DOS\" {\r\n\tlinux \/grub4dos-0.4.4\/grub.exe --config-file=\/menu.lst\r\n}\r\n\r\nmenuentry \"SYSRESCUECD\" {\r\n\tloopback loop \/sysrecuecd-x86-2.3.1.iso\r\n\tlinux  (loop)\/isolinux\/rescue64 nomodeset vga=791 docache setkmap=fr isoloop=\/sysrecuecd-x86-2.3.1.iso\r\n\tinitrd (loop)\/isolinux\/initram.igz\r\n}\r\n\r\nmenuentry \"STG3-AMD64\" {\r\n\tset cmdline=\"dokeymap looptype=squashfs loop=\/image.squashfs cdroot\"\r\n\tloopback loop \/stg3-amd64-<DATE>.iso\r\n\tlinux  (loop)\/isolinux\/gentoo $cmdline root=\/dev\/ram0 init=\/linuxrc initrd=gentoo.igz\r\n\tinitrd (loop)\/isolinux\/gentoo.igz\r\n}\r\n<\/pre>\n<p>Make this rule file executable.<\/p>\n<h2>Grub2 with raid-1 disk<\/h2>\n<p>Prepare kernel usual way<\/p>\n<pre>\r\ncd \/usr\/src\/linux\r\nmake && make modules_install\r\nmake install\r\n<\/pre>\n<p>To boot from raid, grub2 need additional stuff: add additional parameters to kernel and pass mdadm support via initramfs<br \/>\nnano -w \/etc\/default\/grub<br \/>\nGRUB_CMDLINE_LINUX_DEFAULT=&#8221;domdadm rootfstype=ext4&#8243;<\/p>\n<p>Initframes<\/p>\n<pre>\r\n# emerge genkernel\r\n<\/pre>\n<p>To configure genkernel add your mdadm.conf file to your initrd with the &#8220;MDADM_CONFIG=&#8221; option in \/etc\/genkernel.conf<\/p>\n<pre>\r\nnano -w etc\/genkernel.conf\r\n\r\nMDADM_CONFIG=\"\/etc\/mdadm.conf\"\r\n<\/pre>\n<p>If you need specific support in the initramfs, such as lvm or raid, add in the appropriate options to genkernel. See genkernel &#8211;help for more information, or the next example which enables support for LVM and software raid (mdadm):<\/p>\n<pre>\r\n# genkernel --lvm --mdadm --install initramfs\r\n<\/pre>\n<p>grub2 setup<br \/>\ngrub2-mkconfig -o \/boot\/grub\/grub.cfg<br \/>\ncheck result in \/boot\/grub\/grub.cfg and compare raid device id with<\/p>\n<p>blkid | grep \/dev\/md3<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Grub2 is finally declared as stable in gentoo portage. While optional, migration from grub:0 to grub2 is straightforward. Installation of grub2 is done in four steps. First inspect your existing grub.conf file and make sure naming is correct. Grub2 has strict naming requirements and wants kernel images to be named as kernel-${version} or vmlinuz-${version} and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.mufljuz.com\/index.php?rest_route=\/wp\/v2\/posts\/167"}],"collection":[{"href":"https:\/\/www.mufljuz.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mufljuz.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mufljuz.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mufljuz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=167"}],"version-history":[{"count":21,"href":"https:\/\/www.mufljuz.com\/index.php?rest_route=\/wp\/v2\/posts\/167\/revisions"}],"predecessor-version":[{"id":311,"href":"https:\/\/www.mufljuz.com\/index.php?rest_route=\/wp\/v2\/posts\/167\/revisions\/311"}],"wp:attachment":[{"href":"https:\/\/www.mufljuz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=167"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mufljuz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=167"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mufljuz.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=167"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}