{"id":5647,"date":"2020-01-22T04:52:39","date_gmt":"2020-01-22T04:52:39","guid":{"rendered":"http:\/\/41j.com\/blog\/?p=5647"},"modified":"2020-01-22T04:52:44","modified_gmt":"2020-01-22T04:52:44","slug":"notes-on-fixing-a-broken-gentoo-grub-install","status":"publish","type":"post","link":"https:\/\/41j.com\/blog\/2020\/01\/notes-on-fixing-a-broken-gentoo-grub-install\/","title":{"rendered":"Notes on fixing a broken Gentoo grub install&#8230;"},"content":{"rendered":"\n<p>Last night I switched HDs on my Gentoo laptop. In the process of doing this, I reset the bios&#8230; this was a bad idea, as I had used efibootmgr to setup my UEFI firmware to boot Linux.<\/p>\n\n\n\n<p>Now, at this point the reasonable thing to do is boot from a usb stick, chroot into the Gentoo install and either re-run efibootmgr or install grub&#8230; I didn&#8217;t have a usb stick\/other installation media handy&#8230; I did however have a SSD with Debian installed. My laptop only has 1 SATA bay however (both the Gentoo install and the Debian install are on SATA drives). These notes document what I did, in case I need to do this again in the future&#8230;<\/p>\n\n\n\n<p>So&#8230; I decided to boot into Debian. Create a ramdisk with a working Debian install, chroot to this. Then swap in the Gentoo SSD, chroot to the Gentoo install and install grub. This post documents my notes on this process.<\/p>\n\n\n\n<p>First boot into Debian, then as root create a ramdisk.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">swapoff\nmount -t tmpfs -o size=2048m none \/mnt\/ramdisk<\/pre>\n\n\n\n<p>I probably could have used debbootstrap or something else&#8230; but I decided to copy everything I needed across manually. First I setup the dev,sys and proc directories:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">cd \/mnt\/ramdisk\nmkdir dev\nmkdir sys\nmkdir proc\nmount --rbind \/dev .\/dev\nmount --rbind \/sys .\/sys\nmount --rbind \/proc .\/proc<\/pre>\n\n\n\n<p>Now copy across files needed for a more or less working system:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">cp -r \/etc .\ncp -r \/bin .\ncp -r \/sbin .\nmkdir usr\ncp -r \/usr\/bin .\/usr\ncp -r \/usr\/sbin .\/usr\ncp -r \/lib64 .\ncp -r \/lib .<\/pre>\n\n\n\n<p>In order to setup grub, I also needed the vfat module and 437 codepage modules. It&#8217;s easier to load them now&#8230;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">modprobe vfat\nmodprobe nls_cp437<\/pre>\n\n\n\n<p>Next we pivot_root to use our new ramdisk&#8230; I guess chrooting will work too&#8230;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mkdir \/tmp\/ramdisk\/old_root\npivot_root \/tmp\/ramdisk \/tmp\/ramdisk\/old_root<\/pre>\n\n\n\n<p>You can also chroot into the ramdisk&#8230; but if you exit and re-login you should be in the new root (you might need to restart login&#8230;).<\/p>\n\n\n\n<p>I now pulled out the Debian SATA drive (there&#8217;s probably a way to umount it cleanly&#8230; I didn&#8217;t&#8230; this is bad don&#8217;t do it). And inserted the Gentoo drive.<\/p>\n\n\n\n<p>Mount the gentoo drive somewhere and chroot into it:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mkdir gentoo;mount \/dev\/sdb5 .\/gentoo\ncd gentoo\nmount --rbind \/dev .\/dev\nmount --rbind \/sys .\/sys\nmount --rbind \/proc .\/proc\nchroot gentoo<\/pre>\n\n\n\n<p>Within the gentoo install you should be able to install grub, or do whatever else you want to do.  For me the grub install commands are:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mount \/boot\ngrub-install \/dev\/sda --target=x86_64-efi --efi-directory=\/boot --removable\ngrub-mkconfig -o \/boot\/grub\/grub.cfg<\/pre>\n\n\n\n<p>My laptop (Lenovo x230) doesn&#8217;t boot unless I used &#8211;removable.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Last night I switched HDs on my Gentoo laptop. In the process of doing this, I reset the bios&#8230; this was a bad idea, as I had used efibootmgr to setup my UEFI firmware to boot Linux. Now, at this point the reasonable thing to do is boot from a usb stick, chroot into the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[],"class_list":["post-5647","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1RRoU-1t5","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts\/5647","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/comments?post=5647"}],"version-history":[{"count":1,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts\/5647\/revisions"}],"predecessor-version":[{"id":5648,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts\/5647\/revisions\/5648"}],"wp:attachment":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/media?parent=5647"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/categories?post=5647"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/tags?post=5647"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}