If you are in an Ubuntu machine, then you can just copy the running system in the external hard drive.
Let us assume you already partitioned the external hard drive. For this example I am going to use 2 partitions: / and /home.
$ sudo mkdir -p /target
$ sudo mount /media/external-hdd/main /target
$ sudo sync
$ sudo cp -ax / /target
$ sudo mount /media/external-hdd/home /target/home
$ sudo cp -ax /home /target/home
cp -ax
does not cross different file system and it is archived (preserve permissions, does not follow symlinks, etc.)
Then, you have to update the grub settings and the fstab in the target disk. You can use chroot
, but before, you will need:
$ sudo mount -o bind /sys /target/sys
$ sudo mount -o bind /proc /target/proc
$ sudo mount -o bind /dev /target/dev
Now you are ready to chroot:
$ sudo chroot /target
# (now you are in the external HD as root)
Now, you have to update the UUIDs in your fstab and grub. In order to get the UUID, you can run:
# blkid
Then, replace in /etc/fstab the UUID with the appropriate id gotten with blkid
.
The last step is to update the configuration for booting and install the bootloader in the external hard drive. In my case I use grub, so, I have edit /boot/grub/menu.lst
.
There you have to replace the line that starts with # kopt=root=UUID=... ro
and replace the content of UUID to the partition that has root file system.
# grub-install /device/name
# update-grub
Where /device/name is the external hdd.
Then, you can exit of chroot and unmount the devices.
# ^D
$ sudo umount /target/sys
$ sudo umount /target/proc
$ sudo umount /target/dev
$ sudo umount /target/home
$ sudo umount /target/
And the disk should be ready to be used. Once you boot it, it might ran fsck
, because it was not unmount properly (you copied the content live).