{"id":24,"date":"2007-01-30T17:35:00","date_gmt":"2007-01-31T00:35:00","guid":{"rendered":"http:\/\/blog.brandonking.net\/?p=24"},"modified":"2009-07-09T15:01:56","modified_gmt":"2009-07-09T22:01:56","slug":"rescuing-a-linux-installation","status":"publish","type":"post","link":"https:\/\/brandonking.net\/blog\/2007\/01\/30\/rescuing-a-linux-installation\/","title":{"rendered":"Rescuing a Linux installation"},"content":{"rendered":"<p>In an attempt to save a system without doing a fresh reinstall by copying the contents from dying hard drive to new hard drive using external hard drive enclosure. This method seems to have worked well for me. I&#8217;m posting it as reference so others have a guide to work from and improve upon. I have only used this method once so make sure you know what you are doing if you follow the guide.<\/p>\n<p>WARNING: Use the following formation at your own risk. Make sure you make proper backups. The following information may have errors or may not work properly<span style=\"font-weight: bold;\"> and could possibly <span style=\"font-style: italic;\">damage your system<\/span> or <span style=\"font-style: italic;\">cause the loss of data<\/span>. Once again, <span style=\"font-style: italic;\">use the following at your own risk<\/span>. Research how to use each individual command so you know what you are doing.<\/span><\/p>\n<p><span style=\"font-weight: bold;\">Guide to moving a Debian or Ubuntu Linux installation from an old hard drive to a new hard drive without re-installing.<\/span><\/p>\n<ol>\n<li>Attach external hard drive<\/li>\n<li>Reboot computer into single user mode (i.e. rescue mode)<\/li>\n<li>Find the new device of the external hard drive (probably sda or sdb) dmesg | grep hd; dmesg | grep sd<\/li>\n<li>create new partions on new drive: fdisk \/dev\/sd(a,b, etc.)\n<ol>\n<li>create swap partition<\/li>\n<li>create linux partition(s)<\/li>\n<\/ol>\n<\/li>\n<li>initialize swap: mkswap<\/li>\n<li>create filesystem (I&#8217;m using ext3): mkfs.ext3<\/li>\n<li>Mount the new hard drive (referred to as \/dev\/sda2 from now on): mount -t ext3 \/dev\/sda2 \/mnt<\/li>\n<li>Use debootstrap to get base install (ubuntu edgy example): debootstrap edgy \/mnt http:\/\/us.archive.ubuntu.com\/ubuntu<\/li>\n<li>Now the copy command: rsync -av &#8211;exclude=\/dev &#8211;exclude=\/sys &#8211;exclude=\/mnt &#8211;exclude=\/proc &#8211;exclude=\/media \/ \/mnt<\/li>\n<li>Make partition bootable: fdisk \/dev\/sda2  # use the &#8216;a&#8217; option<\/li>\n<li>Shutdown system and put in the new drive.<\/li>\n<li>Get Grub working again:\n<ol>\n<li>Insert Ubuntu or other Debian based live CD (Knoppix is a good choice too).<\/li>\n<li>Mount the new drive: mount -t ext3 \/dev\/hda2 \/mnt<\/li>\n<li>Install grub: install-grub &#8211;root-directory=\/mnt \/dev\/hda2<\/li>\n<li>chroot into new drive: chroot \/mnt<\/li>\n<li>edit \/boot\/grub\/menu.lst\n<ol>\n<li>Update groot(hd0,)  #if bootable partition changed (i.e. Was \/dev\/hda5 is now \/dev\/hda2&#8230; Old: <span style=\"font-weight: bold;\">groot(hd0,4)<\/span> New: <span style=\"font-weight: bold;\">groot(hd0,1)<\/span><\/li>\n<li>Update kopt=root #if bootable partition changed (i.e. Was \/dev\/hda5 is now \/dev\/hda2&#8230;  Old: <span style=\"font-weight: bold;\">kopt=root=UUID=<\/span> or <span style=\"font-weight: bold;\">kopt=root=\/dev\/hda5<\/span> New:  <span style=\"font-weight: bold;\">kopt=root=\/dev\/hda2<\/span> (NOTE: There is probably a way of getting the new UUID of the new partition, in which case you can just update the UUID option, but I don&#8217;t know enough about this yet to offer advice&#8230; Feel free to post a comment if you know more.)<\/li>\n<\/ol>\n<\/li>\n<li>type: update-grub<\/li>\n<\/ol>\n<\/li>\n<li>Reboot and hope everything works properly.<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>In an attempt to save a system without doing a fresh reinstall by copying the contents from dying hard drive to new hard drive using external hard drive enclosure. This method seems to have worked well for me. I&#8217;m posting it as reference so others have a guide to work from and improve upon. I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,15,4,10],"tags":[19,26,29,33,91,46,53,60],"class_list":["post-24","post","type-post","status-publish","format-standard","hentry","category-computers_it","category-error-fixes","category-linux-it","category-sysadmin","tag-backup","tag-debian","tag-debootstrap","tag-fdisk","tag-linux-it","tag-mount","tag-rsync","tag-system-adminstration"],"_links":{"self":[{"href":"https:\/\/brandonking.net\/blog\/wp-json\/wp\/v2\/posts\/24","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/brandonking.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/brandonking.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/brandonking.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/brandonking.net\/blog\/wp-json\/wp\/v2\/comments?post=24"}],"version-history":[{"count":1,"href":"https:\/\/brandonking.net\/blog\/wp-json\/wp\/v2\/posts\/24\/revisions"}],"predecessor-version":[{"id":85,"href":"https:\/\/brandonking.net\/blog\/wp-json\/wp\/v2\/posts\/24\/revisions\/85"}],"wp:attachment":[{"href":"https:\/\/brandonking.net\/blog\/wp-json\/wp\/v2\/media?parent=24"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/brandonking.net\/blog\/wp-json\/wp\/v2\/categories?post=24"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/brandonking.net\/blog\/wp-json\/wp\/v2\/tags?post=24"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}