Tutorial: Creating a Mirror Copy of IPFire System Disk

Introduction

This tutorial guides you on how to create a mirror copy of an IPFire system disk on a larger secondary hard disk directly from the IPFire console.

CAUTION: Ensure you fully understand the source and destination of the mirroring copy. If you invert the destination and the source, you will risk losing your IPFire disk.

Problem

After the mirroring process, if the destination disk is larger than the source it will have unused space that we need to recover and make available to the Operating System.

Original Disk Partitions:

+-------+------+-------+---------------------+
| Boot  | EFI  | Swap  |       Main          |
+-------+------+-------+---------------------+

Target Disk Partitions After Mirror Copy:

+-------+------+-------+---------------------+-------------+
| Boot  | EFI  | Swap  |       Main          |  Unused     |
+-------+------+-------+---------------------+-------------+

Solution

We can expand the Main partition to include the unused space and grow the Ext4 file system to address the entire memory after the copy.

Step-by-Step Guide

All commands must be entered as root superuser.

Step 1: Create the Mirror Image

  1. Check which device is the original disk and which is the destination disk using the command lsblk. The disk and partition where the root file system is mounted will be the source.

  2. Assuming the original IPFire disk is sda and the target is sdb, issue a dd command as root:

dd if=/dev/sda of=/dev/sdb bs=4M status=progress
  • if=/dev/sda specifies the input file (source disk).
  • of=/dev/sdb specifies the output file (target disk).
  • bs=4M sets the block size to 4 Megabytes to speed up the copying process.
  • status=progress shows the progress of the copy operation.

Once the copy is successful, proceed to the next step.

Step 2: Expand the Partition in the Target Disk

  1. As root, open the partition manager fdisk to extend the right hand-side boundary of partition 4:
fdisk /dev/sdb
  1. In fdisk, perform the following operations:

    • Press p to print the partition table and note the start sector of the fourth partition.
    • Press d to delete a partition, then enter 4 to delete the fourth partition.
    • Press n to create a new partition, then choose p for primary partition, and enter 4 for the partition number.
    • Enter the start sector you noted earlier for the new partition start, and press Enter to use the default end sector (which should automatically occupy the remaining space on the disk).
    • Press w to write the changes to disk and exit.

    During this process, if fdisk asks if you want to remove the ext4 flag, keep it.

Step 3: Expand the File System

  1. As root, check the integrity of the filesystem using the command e2fsck -f /dev/sdb4. If it detects a size discrepancy, allow the fix to happen.

  2. Next, resize the file system with the command resize2fs /dev/sdb4.

Troubleshooting

Q: Why does e2fsck -f /dev/sdb4 not find any ext4 file system?

A: This might be due to incorrect input of the starting sector during the re-partitioning step in fdisk. If you didn’t enter the correct number for the beginning of partition 4, this issue could occur. Make sure you enter the correct number - the one proposed by fdisk is likely incorrect and you need to change it. However, the default value for the end sector of the fourth partition should be correct. If this issue arises, you need to repeat the process from the beginning.

4 Likes

Nice, ill have to try this out!

I’ve used tar in the past to transfer between machines which doesn’t require expanding the file system.

From source machine:

tar -cvpzf /root/backup.tar.gz --directory=/ --exclude=./proc --exclude=./sys --exclude=./boot --exclude=./bin --exclude=./dev --exclude=./lib --exclude=./etc/default --exclude=./tmp --exclude=./etc/fstab --exclude=./run --exclude=./root/backup.tar.gz --one-file-system .

On destination machine:

tar xvpzf /root/backup.tar.gz –C ./ --numeric-owner

extracting on the destination after you load up the new install of OS

1 Like

I tested it twice to be sure, but exert prudence as this is potentially dangerous and you could lose your IPFire disk. I am not saying this to your benefit because you are well aware of that, this is for anyone reading the tutorial with the intent to try the procedure.

1 Like