{"id":73,"date":"2010-02-12T05:27:52","date_gmt":"2010-02-12T05:27:52","guid":{"rendered":"http:\/\/xbmc\/wordpress\/?p=73"},"modified":"2015-12-03T21:41:28","modified_gmt":"2015-12-04T02:41:28","slug":"restoring-linux-system-from-backup","status":"publish","type":"post","link":"https:\/\/xfloyd.net\/blog\/?p=73","title":{"rendered":"Restoring Linux System from Backup"},"content":{"rendered":"<div class=\"col span_4_of_6\">\n<h3 id=\"terminal\">Terminal Commands<\/h3>\n<p>Mount the partition your Ubuntu Installation is on. If you are not sure which it is, launch <span class=\"box\">GParted<\/span> (included in the Live CD) and find out. It is usually a EXT4 Partition. Replace the XY with the drive letter, and partition number, for example: <span class=\"box\">sudo mount <span class=\"editable\">\/dev\/sda1<\/span> \/mnt<\/span>.<\/p>\n<p><code>sudo mount <span class=\"editable\">\/dev\/sdXY<\/span> \/mnt<\/code><\/p>\n<p>Now bind the directories that grub needs access to to detect other operating systems, like so.<\/p>\n<p><textarea class=\"code resize\">sudo mount &#8211;bind \/dev \/mnt\/dev &amp;&amp;&lt;br \/&gt;<br \/>\nsudo mount &#8211;bind \/dev\/pts \/mnt\/dev\/pts &amp;&amp;&lt;br \/&gt;<br \/>\nsudo mount &#8211;bind \/proc \/mnt\/proc &amp;&amp;&lt;br \/&gt;<br \/>\nsudo mount &#8211;bind \/sys \/mnt\/sys<\/textarea><\/p>\n<p>Now we jump into that using <span class=\"box\">chroot<\/span>.<\/p>\n<p><input class=\"code\" type=\"text\" value=\"sudo chroot \/mnt\" \/><\/p>\n<p>Now install, check, and update grub.<\/p>\n<p>This time you only need to add the drive letter (usually a) to replace X, for example: <span class=\"box\">grub-install <span class=\"editable\">\/dev\/sda<\/span><\/span>, <span class=\"box\">grub-install \u2013recheck <span class=\"editable\">\/dev\/sda<\/span><\/span>.<\/p>\n<p><code>grub-install <span class=\"editable\">\/dev\/sdX<\/span><\/code><br \/>\n<code>grub-install --recheck <span class=\"editable\">\/dev\/sdX<\/span><\/code><br \/>\n<input class=\"code\" type=\"text\" value=\"update-grub\" \/><\/p>\n<p>Now grub is back, all that is left is to exit the chrooted system and unmount everything.<\/p>\n<p><textarea class=\"code resize\">exit &amp;&amp;&lt;br \/&gt;<br \/>\nsudo umount \/mnt\/sys &amp;&amp;&lt;br \/&gt;<br \/>\nsudo umount \/mnt\/proc &amp;&amp;&lt;br \/&gt;<br \/>\nsudo umount \/mnt\/dev\/pts &amp;&amp;&lt;br \/&gt;<br \/>\nsudo umount \/mnt\/dev &amp;&amp;&lt;br \/&gt;<br \/>\nsudo umount \/mnt<\/textarea><\/p>\n<p>Shut down and turn your computer back on, and you will be met with the default Grub2 screen.<\/p>\n<p>You may want to update grub or re-install burg however you like it.<\/p>\n<h3>Congratulations, you have just Repaired\/Restored\/Reinstalled Grub 2 with a Ubuntu Live CD!<\/h3>\n<\/div>\n<p>Type at the command prompt<\/p>\n<dl>\n<dd><strong>tar xvzf file-1.0.tar.gz<\/strong> &#8211; for a gzip compress tar file (.tgz or .tar.gz)<\/dd>\n<dd><strong>tar xvjf file-1.0.tar.bz2<\/strong> &#8211; for a bzip2 compressed tar file (.tbz or .tar.bz2)<\/dd>\n<dd><strong>tar xvf file-1.0.tar<\/strong> &#8211; for uncompressed tar file (.tar)<!--more--><\/dd>\n<\/dl>\n<h1 id=\"firstHeading\">HOWTO: Restore Grub2<\/h1>\n<div id=\"bodyContent\">\n<div id=\"mw-content-text\" dir=\"ltr\" lang=\"en\">\n<p>Let&#8217;s reinstall Grub2 for whatever reason. Maybe you reinstalled Windows and lost Grub2 or you just plain old did something silly and lost Grub2. Remember, in Sabayon we are using Grub2 so it&#8217;s a bit different than Legacy Grub. It&#8217;s still pretty painless though and with about 5 minutes of time you will have your Grub2 reinstalled.<\/p>\n<p>&nbsp;<\/p>\n<h2>Quick Recovery<\/h2>\n<p>As outlined in the\u00a0<a href=\"http:\/\/en.gentoo-wiki.com\/wiki\/Grub2#Recovery\" rel=\"nofollow\">Gentoo Grub2 wiki page &#8211; Recovery section<\/a>\u00a0you can simply reinstall Grub2 to the MBR (Master Boot Record), linking to your original \/boot location.<\/p>\n<p>So, assuming your root partition is located on \/dev\/sda3 and you have a separate \/boot on \/dev\/sda1 you would do the following:<br \/>\n(If you do not have a separate boot partition you do not need to do the second mount.)<\/p>\n<div>\n<pre># mkdir -p \/mnt\/new_linux\/\r\n# mount \/dev\/sda3 \/mnt\/new_linux\r\n# mount \/dev\/sda1 \/mnt\/new_linux\/boot &lt;- IMPORTANT on Ubuntu 12.xx\r\n# grub-install --root-directory=\/mnt\/new_linux \/dev\/sda<\/pre>\n<\/div>\n<p>This tells Grub2 to install itself to the MBR on the \/dev\/sda device linking to the config found in \/mnt\/new_linux\/boot.<br \/>\nYou can then reboot and Grub2 will be back to normal &#8211; there&#8217;s no need to re-create your config (see below) as it should still be undisturbed in your \/boot directory.<\/p>\n<h2>Completely Reinstall and Re-Configure Grub2<\/h2>\n<p>From the article\u00a0<a href=\"http:\/\/en.gentoo-wiki.com\/wiki\/Chroot_from_a_livecd\" rel=\"nofollow\">Chroot from a livecd<\/a>\u00a0in the Gentoo Wiki we can learn how to chroot into our system. So boot up the livedvd or other live disk, and get to a terminal, command line or konsole.<\/p>\n<div>\n<div>Make sure the livedvd you use is for the same architecture as the architecture of the installation on the hard disk, i.e. to chroot to a 64-bit installation (e.g. amd64) you cannot use a 32-bit livedvd (e.g. x86), and vice versa. You will see an error message &#8220;chroot: cannot run command `\/bin\/bash&#8217;: Exec format error&#8221; if you try to chroot from a livedvd of a different architecture.<\/div>\n<\/div>\n<p>First a quick note on mounting filesystems. While it&#8217;s possible to mount filesystems from within the chrooted system, this is not recommended. The reason for this is that the livecd environment won&#8217;t know about these mounted systems, so if they are forgotten about and left mounted, they will not be unmounted properly when the system shuts down, which could cause damage to the filesystems on those mounts.<\/p>\n<p>Mount the root partition (and, if you have \/boot on a separate partition, mount that too) of the installed system. If separate partitions are used for other areas of the system (for example, a separate partition for \/var\/log) then these will also need to be mounted.<\/p>\n<p>In the following example, \/dev\/hda1 is the \/boot partition and \/dev\/hda3 is the root partition. Obviously replace those with the device names for\u00a0<em>your<\/em>\u00a0boot partition (if you have one) and\u00a0<em>your<\/em>\u00a0root partition. If your partition names are of the form \/dev\/<strong>s<\/strong>d&lt;letter&gt;&lt;number&gt; rather than \/dev\/<strong>h<\/strong>d&lt;letter&gt;&lt;number&gt; then obviously use that form instead. Obviously, if you do not have \/boot on a separate partition to \/ (root) then you should omit the mount and umount commands referring to \/boot.<\/p>\n<p>Additionally, mount the \/dev, \/sysfs and \/proc filesystems so that they can be used by the chrooted environment.<\/p>\n<div>\n<pre># mkdir -p \/mnt\/sabayon\/boot\r\n# mount \/dev\/hda3 \/mnt\/sabayon\r\n# mount \/dev\/hda1 \/mnt\/sabayon\/boot\r\n# mount -t proc none \/mnt\/sabayon\/proc\r\n# mount -t sysfs sys \/mnt\/sabayon\/sys\r\n# mount -o bind \/dev \/mnt\/sabayon\/dev<\/pre>\n<\/div>\n<p>So now we are set to enter into our installed system:<\/p>\n<div>\n<pre># chroot \/mnt\/sabayon \/bin\/bash\r\n# env-update\r\n# source \/etc\/profile\r\n# export PS1=\"(chroot) $PS1\"<\/pre>\n<\/div>\n<p>You should then end up with the following prompt:<\/p>\n<div>\n<pre>(chroot) #<\/pre>\n<\/div>\n<p>Grub2 reads the \/etc\/mtab file to ascertain the filesystems that are currently mounted, so \/etc\/mtab must be up-to-date. If you do not have a separate boot partition then update \/etc\/mtab using the following command:<\/p>\n<div>\n<pre>(chroot) # grep -v rootfs \/proc\/mounts &gt; \/etc\/mtab<\/pre>\n<\/div>\n<p>or the following command if you do have a separate boot partition:<\/p>\n<div>\n<pre>(chroot) # cp \/proc\/mounts \/etc\/mtab<\/pre>\n<\/div>\n<p>To install Grub2 with the Grub2 Stage 1 code written to the MBR of hda, use the following command:<\/p>\n<div>\n<pre>(chroot) # grub2-install \/dev\/hda<\/pre>\n<\/div>\n<p>or the following command if you want to install Grub2 with the Grub2 Stage 1 code written to the first sector of a separate boot partition hda1 (i.e. no Grub2 code written to the MBR):<\/p>\n<div>\n<pre>(chroot) # grub-install \/dev\/hda1<\/pre>\n<\/div>\n<p>It should do its thing and it should tell you it has finished installing it.<br \/>\ngrub2-install does not create\/recreate the grub.cfg file (the equivalent to Grub Legacy&#8217;s grub.conf\/menu.lst file), so use the following command to create\/recreate the grub.cfg file:<\/p>\n<div>\n<pre>(chroot) # grub-mkconfig -o \/boot\/grub\/grub.cfg<\/pre>\n<\/div>\n<p>Now you can exit from the chroot environment and unmount the drives:<\/p>\n<div>\n<pre>(chroot) # exit<\/pre>\n<\/div>\n<div>\n<pre># umount \/mnt\/sabayon\/boot \/mnt\/sabayon\/dev \/mnt\/sabayon\/proc \/mnt\/sabayon<\/pre>\n<\/div>\n<p>Now you can reboot to Grub2.<br \/>\nYou can find more information in the article\u00a0<a href=\"http:\/\/en.gentoo-wiki.com\/wiki\/Grub2\" rel=\"nofollow\">Grub2<\/a>\u00a0in the Gentoo Wiki.<\/p>\n<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Terminal Commands Mount the partition your Ubuntu Installation is on. If you are not sure which it is, launch GParted (included in the Live CD) and find out. It is usually a EXT4 Partition. Replace the XY with the drive letter, and partition number, for example: sudo mount \/dev\/sda1 \/mnt. sudo mount \/dev\/sdXY \/mnt Now [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/73"}],"collection":[{"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=73"}],"version-history":[{"count":10,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/73\/revisions"}],"predecessor-version":[{"id":891,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/73\/revisions\/891"}],"wp:attachment":[{"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=73"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=73"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=73"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}