It always happens: your HD fills up and you have to move everything to a new, bigger one.
Well, yes there are clone tools, but sometime you just want the damn thing and of course you don’t need to install software or find that special CDROM or DVD-R with what-was-that-program-name? …. ;-)

Moreover if you have a virtual machine you want to clone, you probably wouldn’t need a 12GB disk for everything, so you start minimal with a 1GB disk for little apps and you want to use the basic setup for all your VMs, keeping vmware-tools and stuff like that.

I know everybody who has done that once in his/her life, knows the procedure, but sometimes you forget a command and thigs just blow up!

So here is a list of commands – for my own convenience – everybody may use.

1. If you are cloning to a new machine, you may want to have your sshd get a new key pair, so just run

rm /etc/ssh/ssh_host_*
dpkg-reconfigure -plow openssh-server

2. Then change hostname, check DNS, hosts, etc

pico -w /etc/hostname
...
pico -w /etc/resolv.conf
...
pico -w /etc/hosts
...
/etc/init.d/hostname.sh

Also check for your fstab for wrong mounts (or add new if you plan to add a separate partition) and change the static ip if using one

pico -w /etc/fstab
...
pico -w /etc/network/interfaces

…but if you do those, be sure you check software configs like Apache and stuff like that, before asking “why that doesn’t work anymore?”

3. Now setup the new disk (you have properly installed as secondary)

fdisk /dev/sdb

And create your partitions (don’t forget to add the bootable flag)

Here we’re assuming there are only a primary and a swap partition.

4. Setup filesystems
mkfs -t ext3 /dev/sdb1
mkswap /dev/sdb5

5. Copy everything
mkdir /mnt/second
mount /dev/sdb1 /mnt/second/
cp -ax / /mnt/second/.

6. Now set up GRUB and fstab

blkid /dev/sdb1
cd /mnt/second/boot/
cd grub/
pico -w menu.lst

blkid /dev/sdb5
pico -w /etc/fstab

7. Next init the grub setup
grub-install --recheck /dev/sdb
umount /mnt/second

…just to be sure the device.map is updated

8. If you need to configure anything, just run
mount /dev/sdb1 /mnt/second/
mount -t proc none /mnt/second/proc
mount -o bind dev /mnt/second/dev
chroot /mnt/second

9. Ensure the new device map is ok (this is the command after chroot, but you don’t need to chroot to edit device.map)
pico -w /boot/grub/device.map
"(hd0) /dev/sda"
shutdown -h now

10. Now let’s do the trick with the Grub console:

  • Boot
  • Press ESC at the Grub prompt
  • Press c to enter console

Then write

root (hd0,0)
grub> find /boot/grub/stage1
setup (hd1)

11. Now shutdown and swtich the hard drives: yes, I know this sounds strange, but I always get “Grub Hard Disk Error”, so just do it :-D

12. Boot again and enter Grub console again, then:
root (hd0,0)
find /boot/grub/stage1
setup (hd0)

13. Now you may shutdown and remove the old hard drive and you’re done

14. If you use this HD in a different VM, be sure either to set the correct MAC address as the original (not recommended) or make Ubuntu use the new MAC address as eth0. Just
pico -w /etc/udev/rules.d/70-persistent-net.rules

And search and change eth1 to eth0
Usually it’s the last line

16. Don’t forget to check for changed things like
/etc/resolv.conf
/etc/mailname (postfix)
/etc/postfix/main.cf

17. Ubuntu 8.04 seems to hang on the resume device: to speed up the thing you’ll have to
blkid /dev/sdb5
pico -w /etc/initramfs-tools/conf.d/resume

insert the correct UUID of your swap and then rebuild initramfs
update-initramfs -u

18. End

  • Share/Bookmark

Related posts

Related External Links

Rating

Not useful/interestingUseful/Interesting (No Ratings Yet)
Loading ... Loading ...

Leave a Reply

Powered by WP Hashcash