Skip to main content

Cloning your Mac / Linux hard drive/SSD with dd

In the process of upgrading my Mac SSD drive (which is a whole story of its own), I've come across many different methods of doing so.
At one time, I was keeping "Time Machine" backups regularly which made the whole process quick and easy; I swapped the SSD cards and restored the most recent Time Machine backup from the hard drive I was keeping the backups on.

Eventually, I came across another method that I was already familiar with already but didn't think of in this particular scenario.

It evolves a command line utility called "dd" (Wikipedia) mainly used to copy and convert files.

This cloning method works on Macs, Linux, FreeBSD and any unix-based systems. You will have to be familiar with the command line interface (Terminal).

Normally the command looks like this:
$ sudo dd if=/dev/sda of=/dev/sdb
"sudo" is necessary as we are cloning a system drive.

"if" is the input file - it is the original drive we wish to clone.

"of" is of course, the output file - our target drive.

Normally, in a Linux system, "sda" represents the first disk and "sdb" would represents the secondary disk.

Normally the command used to display all disks looks like this: "sudo fdisk -l".
However, this command will not work on Mac systems. Instead a different command can be used.

The MacOS disk utility (diskutil) can help achieve this task. The full command will look like this:
"diskutil list".

 
While this simple command and and does work in most cases; It is considered unstable as the dd utility will skip every error it encounters which can cause an error.
$ sudo dd if=/dev/sda of=/dev/sdb bs=64K conv=noerror,sync
Note: Mac systems usually refer to disks as "disk0", "disk1" etc. Therefore, in order to clone "disk0" to "disk1" we would use a command that looks like this:
$ sudo dd if=/dev/disk0 of=/dev/disk1 bs=64K conv=noerror,sync
The purpose of the "bs" operand is to specify the block size. 64K is usually recommended.
The "conv=noerror,sync" tells dd to replace missing input data (from the disk of origin) with empty (Null) bytes. These will be processed as normal input buffers which will ensure a successful clone.

Comments

Popular posts from this blog

How to Keep HomeBrew Clean on a Mac

HomeBrew is a package manager (similar to the linux "apt-get"/"zypper"/"yum" front end package managers that are usually shipped with different distros) with one exception: it was built for Apple MacOS systems as a solution since Apple doesn't offer or ship one with MacOS.

Dependencies
While HomeBrew is a great solution and offers most features other modern package managers offer and has a rich reposatory, it lacks some useful features that make it difficult to use for the purpose of managing installed packages. One issue that I would like to describe here is the lack automatic removal of dependencies.

HomeBrew does not keep logs of installed dependencies the same way that the popular Linux package managers do. Some packages require dependencies to work and while HomeBrew can detect the required dependencies and install them automatically as part of the installation process, it will not remove them automatically while removing packages.

This can lead …

DFX Windows/Android/iOS Audio Enhancer

A free (freemium) audio-enhancer program for Windows (XP and above), Android and iOS device.