4

I am trying to use dd command to accomplish complete restore of a linux image on a new computer. I have two partitions sda1(main) and sda2(extended), I took a backup of mbr image using:

dd if=/dev/sda of=/mnt/sdb1/mbr_image bs=512 count=1

and dbr image as follows:

dd if=/dev/sda2 of=/mnt/sdb1/ebr_image bs=512 count=1

I also took a backup of main partition(the one that I want to restore) using:

dd if=/dev/sda1 of=/mnt/sdb1/sda1_image

I open the new system with a slax cd and first restore mbr and ebr images that I backed up before(I didn't use 446 bytes, because I want to restore the partition table as well)

dd if=/mnt/sdb1/mbr_image of=/dev/sda
dd if=/mnt/sdb1/ebr_image of=/dev/sda2

after that I restore main partition:

dd if=/mnt/sdb1/sda1_image of=/dev/sda1

once it finishes I resize the main partition using following set of commands:

umount /dev/sda1
e2fsck -f /dev/sda1
resize2fs /dev/sda1 -p

after this point I restart the computer hoping that I restored everything correctly. Unfortunately when I do this on a new computer whose hard drive has never been used before, Computer gets stuck in grub bootloader saying GRUB...

I am suspecting that there's something machine specific in mbr image because if I run the same restore process on the machine that I took back up, everything works fine and machine boots normally.

Can you please shed some light on what I've been doing wrong for the last 2 days...

erin c
  • 157
  • 1
  • 7
  • You are aware that you also need to the restore the data? GRUB is not completely stored in the MBR, but rather on whatever partition it is installed on (most likely `/dev/sda1`). – Bobby Mar 29 '12 at 12:23
  • I am restoring sda1 completely using: dd if=/mnt/sdb1/sda1_image of=/dev/sda1, do I need to do anything else? – erin c Mar 29 '12 at 12:25
  • grub is under /boot/grub in sda1, since I restore sda1 with the above command, I was thinking that everything will boot properly. Is that a false assumption? – erin c Mar 29 '12 at 12:31
  • Ah, sorry, completely missed that...and no, I would assume the same. – Bobby Mar 29 '12 at 12:35

3 Answers3

2

I know that it is a solution that forces you to do all the work from beginning but I will recomend using Clonezilla to do backup and restore it to new machine. Specialy if you need restore image on many machines

B14D3
  • 5,110
  • 13
  • 58
  • 82
  • I will give it a try. – erin c Mar 29 '12 at 14:33
  • I backed up succesfully using clonezilla, when I connect the usb to the new computer and attempt to start restore operation, I don't see restoredisk option in the menu. any idea on why this might happen. – erin c Mar 30 '12 at 11:24
  • did you connect usb drive in proper time when clonezilla asked you to do so ? Connecting before may not be effective and clonezilla did not see USb drive with image. – B14D3 Mar 31 '12 at 06:34
  • I finally managed to make it work, Clonezilla is a useful tool, but has some problems. At the end of backup operation, I switched to console2 and checked what is written to /home/partimag, I realized clonezilla writes more files to partimag then my usb stick, which is to say some files were missing, at that point I mounted my usb drive and copied everything manually to usb, and I exited from command line. after that on another computer I deleted whatever clonezilla copied to my usb, on the restore I used what I managed to copy and viola, restoredisk was there for me to select. it succeeded. – erin c Mar 31 '12 at 08:17
  • @erinc best of all is clonezilla server I manage to restore 100 machines at ones and make all operations without leaving my room. I'm glad that a could help you – B14D3 Mar 31 '12 at 08:35
1

I would try partimage for what you're trying to do. dd is a little crude, copies byte for byte. A 500 gig hd would = a 500 gig image. You would not have this issue with partimage.

Also running a partimage server would allow you to restore that image on multiple computers quickly.

Hope this helps. I know its not a dd answer.

steve
  • 176
  • 3
  • not necessarily true, my main partition is 450 gb, but only 2 GB is being used, dd command creates something around 2-3 GB, but you are right, I should give another solution a try, been scratching my hair. – erin c Mar 29 '12 at 18:01
  • I have never had a result such as that while using dd, as dd should not be smart enough to know the difference between free space and used space. Nor should it be able to tell the difference between filesystems. May I ask what version of dd you are using? – steve Mar 29 '12 at 18:22
  • You are right, I guess I am totally exhausted now, I forgot that I created a second smaller partition and restored everything there, and took a smaller backup from that small partition. That's why my backup is small. – erin c Mar 29 '12 at 18:56
  • Yeah, dd is for raw device read/write. its pretty basic. not the right choice for that kind of backup in my humble opinion. partimage sounds more like you're looking for. (clonezilla can as well but im not familiar with it) – steve Mar 29 '12 at 20:41
0

Did you try to reinstall grub to new sda?

Are the disks, old and new, the same size? If they are, dd the entire disk and it should work.

If not, you can transfer files with rsync or tar, and the use livecd to reinstall grub.

johnshen64
  • 5,747
  • 23
  • 17
  • I didn't try reinstalling grub after restore, I prefer not to since I need a automated way of doing this to 75 new computers. I want to give manufacturer a usb stick so he can restore this image on the new computers. I can't afford manually fixing things because of the number of computers this has to be done. they all have same hardware configuration. In the past we've done this with the same procedure, and it worked fine, the only difference is mbr and ebr images. mbr_images and ebr_images had to be changed since new hdds are twice the size. – erin c Mar 29 '12 at 12:43
  • So I restored with the old image on a new computer, changed the partition sizes using fdisk, resize2fs and then I took backup of mbr and ebr images. I am guessing in the past they were backing up the mbr images differently because the one that worked before is 10 kb long, it worked fine with new computers. the one that I create is only 1 byte, since I only back up first 512 bytes of /dev/sda... – erin c Mar 29 '12 at 12:46
  • unfortunately nobody documented how old mbr_images were backed up. – erin c Mar 29 '12 at 12:49
  • Same size disks doesn't always work, due to block size and abstraction. I've had mixed results with using this kind of approach on drives that were the same size. – Bart Silverstrim Mar 29 '12 at 12:50
  • testdisk ends up telling me more about the post-mortem than anything else...sometimes even manages to repair it. – Bart Silverstrim Mar 29 '12 at 12:52
  • maybe this approach is flawed, but given that it works with another mbr image which seems to be more than 512 bytes, makes me think that this approach is possible with some modifications. – erin c Mar 29 '12 at 15:35
  • As a last step, I tried grub-install /dev/sda, it warns me saying that stage1 not read correctly – erin c Mar 30 '12 at 06:43