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
-
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. -
Assuming the original IPFire disk is
sdaand the target issdb, issue addcommand as root:
dd if=/dev/sda of=/dev/sdb bs=4M status=progress
if=/dev/sdaspecifies the input file (source disk).of=/dev/sdbspecifies the output file (target disk).bs=4Msets the block size to 4 Megabytes to speed up the copying process.status=progressshows 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
- As root, open the partition manager
fdiskto extend the right hand-side boundary of partition 4:
fdisk /dev/sdb
-
In
fdisk, perform the following operations:- Press
pto print the partition table and note the start sector of the fourth partition. - Press
dto delete a partition, then enter4to delete the fourth partition. - Press
nto create a new partition, then choosepfor primary partition, and enter4for 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
wto write the changes to disk and exit.
During this process, if
fdiskasks if you want to remove the ext4 flag, keep it. - Press
Step 3: Expand the File System
-
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. -
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.