0

Today, I bought a second server almost identical to my first one (I guess). Specs (processor model, RAM, HDD) are the same.

But I failed to copy the disk of the first one to the second one. It didn't boot. A technician dispatched to check for any hardware malfunction said "software misconfiguration. Server does not boot. Can't even tell which OS is installed).

Here is how I failed:

I did fdisk -l on my first disk.
Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x000b6660

Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        4096    16386047     8190976   83  Linux
/dev/sda2        16386048    17432575      523264   82  Linux swap / Solaris
/dev/sda3        17432576   222230527   102398976   83  Linux
/dev/sda4       222230528   976762879   377266176   83  Linux

Then I did boot the second server in rescue mode (kind like from a live CD: /dev/sda is not mounted and can safely be manipulated).

  1. I used fdisk to create 4 primary partitions using the start and end values provided by fdisk (eg: 4096 → 16386047 for /dev/sda1).

  2. I did set /dev/sda2 as "82".

  3. I did mark /dev/sda1 as bootable
  4. I did format /dev/sda3 (/var) and /dev/sda4 (/backup) as ext4
  5. I did mount both partitions.
  6. I did rsync /var from the /var of the first server
  7. I overwrote the first flock (0->4096) of the 2nd hdd with dd (data taken from the 1st hdd).
  8. I overwrote /dev/sda1 on the 2nd harddrive with dd image from the first hdd

I was expecting :

A harddrive with the same partition scheme, save first 4096 bytes, same /dev/sda1, a rsync copy of /dev/sda3 (/var) and a different /backup (useless for the server to operate).

Why does this scheme not work? How can I do better? I have no objection in transferring 500 GB on the network between the two servers to do the whole harddrive, but then I have no way of storing the image on the new server...

0

2 Answers 2

1

It does not work because you did not install a boot loader on the new disk. Grub typically occupies the first 64k of the disk, so you need to dd that much if you want to copy grub. Then grub looks for your root or boot partition by UUID, so if you formatted a new partition and copied your files, that will not match so grub will stop and wait for you to manually tell it what to boot. The changed UUIDs on the other partitions will also prevent them from being mounted.

If you just dd grub over then you will need to first tel it where to find itself with the set prefix=(hdXX,Y)/boot command ( fill in drive and partition number ), then the normal command should load the rest of grub and pull up the boot menu, but you will need to press e to edit it and change the kernel root= argument to point to the right partition instead of the old UUID. Finally you will need to update /etc/fstab so it can find the new partitions.

4
  • Thank you for your answer. I don't understand something : fdisk reports only the first 4096 bytes as not belonging to /dev/sda1. So, since I also copied /dev/sda1, I should be covered, right? Also, there are no uuid written in my fstab. Is there something special to do about it?
    – Adeline
    Jan 15, 2015 at 14:26
  • @Adeline, no, the units fdisk is using are sectors ( says so right there ). If the first 64k of the disk were part of sda1 then grub couldn't be installed there.
    – psusi
    Jan 15, 2015 at 15:16
  • I understand now. Up until now, I always thought the boot sector was only a boot sector and that actually, only the first few 44x or so bytes were used (I did a boot loader for a 1.44 MB disk many many many years ago in ASM. It only printed some text, that's all). Your answer gave me the missing piece of information to successful replicate my full harddrive.
    – Adeline
    Jan 15, 2015 at 21:02
  • @Adeline, yes, but that isn't nearly enough room to do, well... pretty much anything at all, so grub just has the MBR load the subsequent few dozen sectors where the core grub code is stored.
    – psusi
    Jan 15, 2015 at 21:14
1

What about using a downloaded tool to professionally clone the entire hard disc? You might look at this question where I tried to describe this to another user an provided some links: click me

The question is currently marked as "on hold" because it is a bit off-topic, but it will remain accessible as far as I know.

4
  • Because, once I have cloned the entire hard disk, what do I do with the image ? There is no way I can both have the 500 GB image on the new harddisk while I restore it.
    – Adeline
    Jan 15, 2015 at 15:01
  • I don't understand! I thought you have one hdd with Ubuntu or whatever installed and want to clone it so that you get two identical hdds with identical bootable systems that you can put into two different machines, or did I get you wrong?
    – Byte Commander
    Jan 15, 2015 at 15:19
  • I have one webserver with a 500GB HDD + 14.04 and one other webserver with a empty HDD of 500GB. Both are different machines. Both are located far far away. I can assess both server either with SSH (boot from harddrive) of with SSH (external boot, unmounted harddrive). If I send the full 500 GB dd image to the second server, I can't restore it (plus, a raw full dd image can't fit a harddrive of the same size with a filesystem on it).
    – Adeline
    Jan 15, 2015 at 20:58
  • Sorry, I do not know about cloning via network. I only did it by puting both drives in the same desktop pc. Then I can't help you out more.
    – Byte Commander
    Jan 15, 2015 at 21:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .