Disk Image Restoration: Transferring 120GB Backup to 320GB HDD with dd Command


2 views

When dealing with disk image restoration across drives of different capacities, several technical considerations come into play. The fundamental question revolves around whether a byte-for-byte copy using dd will properly utilize the additional space on the target drive.

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

This command will create an exact replica of your 120GB source on the first 120GB of your 320GB target drive. However, the remaining 200GB will remain as unallocated space. The partition table from the original disk will be copied verbatim, maintaining the original partition sizes.

After the dd operation completes, you'll need to extend your partitions to utilize the additional space. For Linux systems, the process typically involves:

fdisk /dev/sdb
# Delete and recreate the partition with larger size (keeping same start sector)
# Then for ext2/3/4 filesystems:
resize2fs /dev/sdb1

For more sophisticated handling, consider tools that understand filesystems:

# Using partclone (for ext4):
partclone.ext4 -r -s backup.img -o /dev/sdb1
# Then expand:
e2fsck -f /dev/sdb1
resize2fs /dev/sdb1

For Windows systems, the process differs slightly:

ntfsclone --restore-image --overwrite /dev/sdb1 backup.img
ntfsresize --expand /dev/sdb1
  • Bootloader may need reinstallation if partition UUIDs change
  • LVM configurations require special handling
  • Swap partitions might need recreation

Here's a bash script that handles the entire process for a simple ext4 single-partition disk:

#!/bin/bash
SOURCE_IMG="backup.img"
TARGET_DEV="/dev/sdb"

# Restore image
dd if="$SOURCE_IMG" of="$TARGET_DEV" bs=4M status=progress

# Resize partition
echo ", +" | sfdisk -N 1 "$TARGET_DEV" --force

# Resize filesystem
resize2fs "${TARGET_DEV}1"

Always verify your operations:

fdisk -l /dev/sdb
df -h
lsblk

When restoring a disk image created with dd to a larger drive, several technical considerations come into play. The fundamental command:

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

will indeed copy the exact byte-for-byte contents of your 120GB image to the new 320GB drive. However, the remaining 200GB won't be automatically accessible due to partition table limitations.

After the dd operation completes, you'll need to handle the partition expansion manually. Here's a complete workflow:

# Verify the disk layout
fdisk -l /dev/sdb

# Enter fdisk interactive mode
fdisk /dev/sdb

# Delete and recreate the partition with same starting sector
# (Press 'd' to delete, then 'n' to create new partition)

# Important: When recreating, specify the same start sector!
# Use default values for first sector, but set last sector to maximum

# Set partition type if needed (usually 't' command)
# Write changes with 'w'

For ext4 filesystems (common in Linux):

# First check the filesystem
e2fsck -f /dev/sdb1

# Then resize it to fill available space
resize2fs /dev/sdb1

For NTFS (Windows systems):

ntfsresize --expand /dev/sdb1

For more complex scenarios, consider these alternatives:

# Using partclone for partition-aware copying
partclone.ext4 -b -s /dev/sda1 -o /dev/sdb1

# Using gparted for graphical management
# (Boot from LiveCD and use GUI tool)
  • Always verify the target disk device (/dev/sdb) to avoid overwriting the wrong drive
  • Consider testing with a smaller image first
  • Backup important data before attempting partition modifications
  • MBR vs GPT differences may affect the process

For frequent operations, you might create a script:

#!/bin/bash
# Verify parameters
if [ $# -ne 2 ]; then
    echo "Usage: $0 input_image output_device"
    exit 1
fi

# Perform the copy
dd if="$1" of="$2" bs=4M status=progress

# Expand partition (example for single-partition ext4)
parted "$2" resizepart 1 100%
e2fsck -f "${2}1"
resize2fs "${2}1"