{"id":216,"date":"2022-11-30T10:24:07","date_gmt":"2022-11-30T15:24:07","guid":{"rendered":"https:\/\/daveking.com\/blog\/?p=216"},"modified":"2022-12-01T09:24:45","modified_gmt":"2022-12-01T14:24:45","slug":"debugging-grub-boot-problems","status":"publish","type":"post","link":"https:\/\/daveking.com\/blog\/index.php\/2022\/11\/30\/debugging-grub-boot-problems\/","title":{"rendered":"Debugging Grub Boot Problems"},"content":{"rendered":"\n<p>I just had a remote server lose its grub.cfg file, which caused it to boot to a grub prompt and go no further.  As I was fixing this issue I found some useful commands along the way.  I want to record these here in case I ever need to do this again.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Listing disk contents from grub prompt<\/h3>\n\n\n\n<p>To list the content of a partition do:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">grub&gt; set pager=1\ngrub&gt; ls\n(hd0) (hd0,gpt1) (hd0,gpt2)\ngrub&gt; ls (hd0,gpt2)\/\nlost+found\/ bin\/ boot\/ cdrom\/ dev\/ etc\/ home\/  lib\/\nlib64\/ media\/ mnt\/ opt\/ proc\/ root\/ run\/ sbin\/ \nsrv\/ sys\/ tmp\/ usr\/ var\/\ngrub&gt; cat (hd0,gpt2)\/boot\/grub2\/grub.cfg\n#\n# DO NOT EDIT THIS FILE\n#\n# It is automatically generated by grub2-mkconfig using templates\n# from \/etc\/grub.d and settings from \/etc\/default\/grub\n#\n\n### BEGIN \/etc\/grub.d\/00_header ###\nset pager=1\n...<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Booting from the grub prompt<\/h3>\n\n\n\n<p>Manually entering the boot commands that are in the <code>grub.cfg<\/code> file will boot the system:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">grub> load_video\ngrub> set gfxpayload=keep\ngrub> insmod gzio\ngrub> insmod part_gpt\ngrub> insmod btrfs\ngrub> set root='hd0,gpt2'\ngrub> linuxefi \/boot\/vmlinuz-5.19.8-100.fc35.x86_64 root=UUID=962cdc00-b466-49af-89ec-74f0f41c1429 ro rd.auto  crashkernel=auto vga=normal nomodeset LANG=en_US.UTF-8\ngrub> initrdefi \/boot\/initramfs-5.19.8-100.fc35.x86_64.img\nbrub> boot<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Using chroot in rescue mode recovery<\/h3>\n\n\n\n<p>I could have used the chroot command to configure the disks to allow me to use the grub tools as normal after booting into rescue mode.<\/p>\n\n\n\n<p>To do this mount the system&#8217;s root partition somewhere, and its boot partition if that&#8217;s separate.  Bind mount the rescue system&#8217;s run-time directories into that filesystem as well.  Then chroot to that filesystem:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo mount \/dev\/sda2 \/mnt\n\n$ sudo mkdir \/mnt\/boot               &lt;====  if separate boot partition\n$ sudo mount \/dev\/sdXX \/mnt\/boot     &lt;====\n\n$ sudo mount --bind \/dev \/mnt\/dev\n$ sudo mount --bind \/dev\/pts \/mnt\/dev\/pts\n$ sudo mount --bind \/proc \/mnt\/proc\n$ sudo mount --bind \/sys \/mnt\/sys\n\n$ sudo chroot \/mnt<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Fixing the actual problem<\/h3>\n\n\n\n<p>The problem was that the <code>\/boot\/efi\/EFI\/fedora\/grub.cfg<\/code> file was out of date, pointing at boot image files that no longer existed.  Fedora normally puts grub commands in this copy of the <code>grub.cfg<\/code> file that simply redirect the boot process to the <code>\/boot\/grub2\/grub.cfg<\/code> file, which contains the actual boot menu:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">search --no-floppy --fs-uuid --set=dev 962cdc00-b466-49af-89ec-74f0f41c1429\nset prefix=($dev)\/boot\/grub2\nexport $prefix\nconfigfile $prefix\/grub.cfg<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Some notes I made while restoring the grub boot configuration on a remote Linux server.<\/p>\n","protected":false},"author":1,"featured_media":217,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_editorskit_title_hidden":false,"_editorskit_reading_time":0,"_editorskit_is_block_options_detached":false,"_editorskit_block_options_position":"{}","_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":[7],"tags":[23,3],"class_list":["post-216","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux-administration","tag-howto","tag-linux","eq-blocks"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/daveking.com\/blog\/wp-content\/uploads\/2022\/11\/pc_rescue.jpg?fit=378%2C193&ssl=1","jetpack-related-posts":[],"jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/daveking.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/216","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/daveking.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/daveking.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/daveking.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/daveking.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=216"}],"version-history":[{"count":4,"href":"https:\/\/daveking.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/216\/revisions"}],"predecessor-version":[{"id":226,"href":"https:\/\/daveking.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/216\/revisions\/226"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/daveking.com\/blog\/index.php\/wp-json\/wp\/v2\/media\/217"}],"wp:attachment":[{"href":"https:\/\/daveking.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=216"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/daveking.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=216"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/daveking.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=216"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}