To transfer your Debian 12 installation to another drive, follow these steps. This method uses dd for cloning and ensures the new drive is bootable.
Step 1: Back Up Data
Before proceeding, back up critical data to avoid accidental loss.
Step 2: Identify Disks
- List disks to find the source (
sda) and target (sdb):
sudo fdisk -l
# or
sudo lsblk
- Source: e.g.,
/dev/sda (current Debian install).
- Target: e.g.,
/dev/sdb (new drive).
Step 3: Clone the Disk
- Boot from a Debian Live USB (to avoid mounting the source disk).
- Clone the disk using
dd:
sudo dd if=/dev/sda of=/dev/sdb bs=64M status=progress
- Replace
sda and sdb with your actual disk identifiers.
- Warning: Incorrect
if/of values will erase data!
Step 4: Resize Partitions (Optional)
If the target disk is larger, expand partitions:
- Check partitions:
sudo fdisk -l /dev/sdb
- Resize the partition (e.g., partition 2):
sudo parted /dev/sdb
resizepart 2 -1 # Resize to end of disk
quit
- Resize the filesystem:
sudo resize2fs /dev/sdb2
Step 5: Reinstall GRUB Bootloader
-
Mount the target disk:
sudo mount /dev/sdb2 /mnt # Mount root partition
sudo mount /dev/sdb1 /mnt/boot # If /boot is separate
- Adjust partitions (e.g.,
sdb1, sdb2) based on your setup.
-
Chroot into the system:
sudo mount --bind /dev /mnt/dev
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys /mnt/sys
sudo chroot /mnt
-
Reinstall GRUB (replace sdb with your target disk):
grub-install /dev/sdb
update-grub
-
Exit chroot:
exit
Step 6: Update fstab (If Needed)
If the new disk uses different UUIDs (unlikely if cloned), update /etc/fstab:
sudo blkid # Get UUIDs of new partitions
# Edit fstab:
sudo nano /mnt/etc/fstab
Step 7: Test the New Drive
- Unmount all partitions:
sudo umount /mnt/dev /mnt/proc /mnt/sys /mnt/boot /mnt
- Reboot and select the new drive in BIOS/UEFI.
Troubleshooting
- GRUB Errors: Re-run
grub-install and update-grub.
- Partition Issues: Use
parted or fdisk to verify alignment.
This method preserves your OS, applications, and data. Ensure the target disk is equal or larger than the source.