Needless to state the obvious, if you are doing this due to an impending disk failure, the first thing is to make a backup of your installation.
The Procedure
- Mount the partition containing the backup or the original installation. I will assume it is on /dev/sdb1. Again, for conformity, create a directory named sdb1 under /mnt.
Code: Select all
mkdir /mnt/sdb1
Code: Select all
mount /dev/sdb1 /mnt/sdb1
- Do the preceding step for the destination partition, let us say, /dev/sda2.
Code: Select all
mkdir /mnt/sda2
Code: Select all
mount /dev/sda2 /mnt/sda2
- Do the actual transfer. Some people use rsync, which is OK, however cp -a can do it implying there is no need of rsync for this procedure.
This will take some time as it will copy an entire installation.
Code: Select all
cp -a /mnt/sdb1/* /mnt/sda2/
- Unmount the original partition i.e. sdb1.
Code: Select all
umount /mnt/sdb1
- With the destination partition still mounted, browse its newly copied file hierarchy to open /etc/fstab. Please note that this file needs root rights to be overwritten. In my case, I use vim, but you can choose any tool that can run with root privileges.
Code: Select all
vim /mnt/sda2/etc/fstab
- Find the line for the '/' directory. On this partitcular installation, it is:
Code: Select all
# / was on /dev/sda2 during installation UUID=e56156fe-5848-1254-bf93-7132a1e54321 / ext4 errors=remount-ro 0 1
- Use the blkid command as root to determine the UUID of sda2, the destination. Copy it instead of the UUID shown in vim or your text editor. Save and exit.
- Update grub-pc to update its menu items.
- Unmount the partition.
Code: Select all
Umount /mnt/sda2
Note:
If an installation is spanned over several partitions, the copy procedure has to be done for every partition in the installation being transferred. A multi-partition installation can also be transferred to a lesser number of partitions, provided, care is taken to copy the contents of every dropped mapped partition to their respective root folder, say /var, /home, /usr, etc.