On the test, I use the Ubuntu Server 14.04.5 LTS system.
And so, on a running system, switch to root user:
1 | sudo -i |
Check which drives are connected:
1 | fdisk -l |
In my case, the first disk used is /dev/sda (automatically marked up by the system upon installation) and /dev/sdb is a new one not marked up:
/dev/sdb1 * Linux
/dev/sdb2 Advanced
/dev/sdb5 Linux swap / Solaris
/dev/sdb
Partition the new disk /dev/sdb in the same way as /dev/sda:
1 | sfdisk -d /dev/sda | sfdisk --force /dev/sdb |
Format the main partition and swap on the new disk:
1 2 | mkfs.ext4 /dev/sdb1 mkswap /dev/sdb5 |
Create an empty directory, mount the first main partition of the new disk into it:
1 2 | mkdir /newhdd mount /dev/sdb1 /newhdd |
Let’s see what the directories are and copy all the information into the new section:
1 2 3 4 5 | ls / cp -ax /bin/ /boot/ /etc/ /home/ /lib/ /lib64/ /opt/ /root/ /sbin/ /tmp/ /usr/ /var/ /initrd.img vmlinuz /newhdd cd /newhdd mkdir /dev /proc /srv /sys /mnt chmod 777 /tmp |
After copying, see the UUID of the new disk partitions:
1 2 | lsblk -o NAME,UUID blkid |
Change the UUID of the old partitions to the new ones in the /newhdd/etc/fstab file.
And finally, we will execute commands in the terminal to update the grub:
1 2 3 4 5 | mount /dev/sdb1 /newhdd mount --bind /dev /newhdd/dev chroot /newhdd update-grub exit |
After that, you can turn off the system and disconnect the old disk, when you turn on a copy of the system will start from the new disk.
By the way, once I copied all the information except the lib64 directory and the error was displayed while chroot:
chroot: failed to run command ‘/bin/bash’: No such file or directory
See also my article:
Backup Linux to archive and restore from it