Cloning Any Automation Controller Storage Memory: Compact Flash, SSD, and CFast Cards

Why Linux for Cloning

Tools like dd, wipefs, fdisk, and lsblk are readily available, and Linux’s robust command-line environment allows for precise control over cloning operations. Additionally, Linux can handle a wide variety of hardware, making it compatible with most CF cards used in automation PCs and, for example, PacDrive 600 controllers.

Command to check if dd is available:

which dd

If the command returns a path (e.g., /usr/bin/dd), dd is available and ready to use.

Clone Anything Using dd

Compact Flash Cards

When it comes to cloning storage devices used in automation systems, the process can be straightforward, whether you’re dealing with Compact Flash (CF) cards, SSDs, or CFast cards. In this guide, we’ll focus on cloning Compact Flash cards specifically for the PACDrive 600 Controller.

Compact Flash Fast Cards

Process described below should also work for CFast cards. CFast cards are essentially faster versions of Compact Flash cards, utilizing the SATA interface for faster data transfer speeds, but they are still block devices. Therefore, the dd command and other tools like lsblk, wipefs, and fdisk work in the same way as with regular CF cards.

Additional considerations for CFast cards:

  • SATA Interface: Since CFast cards use a SATA interface (instead of the parallel interface used by traditional CF cards), the card might be connected to the system via a USB-to-SATA adapter or directly to a SATA port on the system. This doesn’t change the cloning process; the card is still treated as a block device.
  • Speed: While cloning, CFast cards will generally transfer data faster than traditional CF cards, which may reduce the overall cloning time but doesn’t affect the method itself.

SSD

This method would work for SSDs inside automation PCs as well. The cloning process using dd works for any block device, including SSDs, as long as the SSD is recognized by the system. You would follow the same steps, but ensure you are working with the correct device (e.g., /dev/sda for an SSD instead of a CF card).

Some additional considerations for SSDs:

  • Wear leveling: Unlike CF cards, SSDs have wear leveling algorithms that distribute write operations to extend the lifespan of the drive. However, this doesn’t affect the cloning process using dd; it’s just something to keep in mind for long-term data reliability.
  • TRIM support: If the target SSD supports TRIM and you want to optimize the space and performance, you may need to run a TRIM operation after cloning, especially if the SSD is used for write-intensive tasks.

Let’s move onto the process. It is simple, I promise.

Verifying the Correct Device

The most important step.

To ensure you are working with the correct device, use lsblk to list block devices and their partitions. It’s crucial to identify your source (/dev/sdb) and target (/dev/sdc) correctly.

List block devices:

lsblk

This will show all connected drives and their partitions. Confirm that /dev/sdb is your source card and /dev/sdc is your target.

Additional check with fdisk:

sudo fdisk -l /dev/sdb

This provides detailed information about the partitions and filesystem on the source card.

Preparing the Target Card

Before cloning, ensure the target CF card is clean, especially if it has data or partitions you don’t want. The wipefs tool will help remove existing partition signatures, and you can optionally zero out the first few blocks to ensure a fresh start.

Wipe the target card (–force will help with ‘device busy’ issue, however, make sure it is the correct device):

sudo wipefs --all --force /dev/sdb

This command will remove all partition signatures from /dev/sdc. To zero out the first few blocks (optional but thorough), use:

sudo dd if=/dev/zero of=/dev/sdb bs=1M count=10
sync

This ensures that the target CF card is clean and ready for cloning. ‘sync’ will take few seconds and will output no messages. It is safe to remove the card afterwards.

Creating an Image Backup of the CF Card

The main cloning process is done using dd. You’ll create an image of the source CF card (/dev/sdb) and store it in an image file (clone.img). This image can then be used for backup or for restoring to another card.

Optional – navigate to /home and create a new directory for your backups:

cd /home
mkdir backups
cd backups

Clone the CF card to an image:

sudo dd if=/dev/sdb of=clone.img bs=4M status=progress

if=/dev/sdb – The input file (your source CF card).

of=~/clone.img – The output file where the image will be stored.

bs=4M – Block size for efficient copying.

status=progress – Displays progress during cloning.

Cloning Directly to Another Compact Flash Card

If you want to clone the CF card directly to another CF card, you can skip creating an image file and clone bit by bit using dd. Make sure the target CF card has enough space (e.g., 512MB for a 128MB source).

Clone directly to the target CF card:

sudo dd if=~/clone.img of=/dev/sdc bs=4M status=progress

Here, if=~/clone.img is the image file, and of=/dev/sdc is the target CF card.

Alternatively, you can clone directly from source to target without an image:

sudo dd if=/dev/sdb of=/dev/sdc bs=4M status=progress

This will copy the data from /dev/sdb (source) to /dev/sdc (target).

Verifying the Clone

After cloning, it’s important to verify the clone’s integrity. You can use several tools like cmp, fdisk, and lsblk to check the data and partitions.

Verify the image with cmp:

sudo cmp /dev/sdb clone.img

This compares the source CF card and the image file. If cmp finds no differences, it will return no output. If there are differences, it will show the location of the first mismatch.

Verify the partition structure:

You can use fdisk to compare the partition table on both the source and the clone:

sudo fdisk -l /dev/sdb
sudo fdisk -l /dev/sdc

alternative:
sudo fdisk -l clone.img

Check that the partition structure, sizes, and types are identical.

Compare lsblk output:

Use lsblk to check that the partitions on both the source and cloned CF card match.

lsblk /dev/sdb
lsblk /dev/sdc

These tools ensure that the clone is identical to the source, including partition tables and data integrity.