The Personal Blog of Stephen Sekula

Further Adventures in Disk Cloning!

Many months ago, I wrote about my experiences in cloning a system from a failing disk to a fresh disk. This process repeated itself this weekend. This time was a little different. Previously, the cloned disk used the old style “master boot record” (MBR) or “gnu partition table” (GPT) method of booting the disk. This weekend’s adventure involved UEFI (Unified Extensible Firmware Interface) booting, which is slightly different. I wanted to share my experiences again, as this was a bit easier than my experience with cloning and older MBR/GPT-booted partition.

In this case, one of my servers had an old magnetic drive that began throwing SMART errrors (Self-Monitoring, Analysis and Reporting Technology). That’s bad. It’s still an early warning, but things are getting to the point of dire when SMART begins detecting problems. In this case, physical sectors of the disk were damaged.

I quickly whipped out a spare solid-state drive (SSD), my preferred boot disk platform these days. It was time to clone!

The server disk had three partitions: the first was the EFI boot partition. Ubuntu was making these separate from the main partition for reasons of backward compatibility with older computer BIOSes. The second partition was the root filesystem. The third was the swap partition. It’s not longer necessary to make a dedicated swap partition, so that one I considered a 100% loss. It could be ignored.

I began by trying to use Clonezilla, my preferred starting tool, to do the full-disk clone. However, the presence of physical damage (bad sectors) made Clonezilla stop the clone. It was time to do it manually.

Trying to use Clonezilla to copy the drive. This approach works on a good-quality disk, but by default it quits when faced with damaged sectors.

The first steps are identical to my previous article. Use ddrescue to first gently copy as much of the disk as possible to a disk image file on another hard drive. Then use the aggressive mode to try to clone the data locked up in bad sectors of this disk. This resulted in my saving at least 99.99% of a 500 GB partition (there was just one irrecoverable sector by the end of the copy … not too bad).

I cloned this partition the to 1TB SSD. I expanded the 500GB partition to take the full disk. But when I went to fix the boot record for the disk, I got an error about EFI-related files missing. Uh-oh! I was in new territory.

So I did some homework and then tried the next-simplest thing: clone the EFI boot partition, put it on the 1 TB disk (shrink the existing partition by 512 MB and copy the 512 MB boot partition to the new SSD drive). I then set the boot flag on the FAT32 EFI boot partition. The new disk booted up on the first try!

So the lesson is: with EFI boot, clone the boot partition (if you have one) and the root partition and you should be good to go. Of course, your mileage may vary (you might have 10 partitions for a single filesystem because you like to curate your disks more heavily, or you might have your boot files in your root partition, which is more standard these days, if I understood correctly).

The server is back up and happy, and WAY faster to boot then it was with that grungy old magnetic disk.