Just bought a brand new esax dano 500 for my notebook and need to clone my old system on 120Gb seagate into this 500Gb samsung hdd. I’d be lyin if I said that I need more space from my old tiny 120Gb hdd for my srpms. no. I have a plenty 40Gb of free space to work on because linux is not space hog like mac or winblows. simple and honest answer is I want to give the 120Gb old hdd to someone.because her hdd were damage just recently and she cannot sync anymore for her musics on her ipod.
There are many tools for this task to make your day much more easier, such as partimage, partclone and even clonezilla livecd. I also already including the partimage tool into the liveusb testqc so it can not be more easier than that. I have made some post in past about how powerful and flexible the dd command is and this could be the real example for the beginner to learn the full console command for cloning their system. I don’t think I have to explain that the dd command could be dangerous to erase all your harddisk if you inputting the wrong device parameter into it. I assume you will not reach this paragraph if you were not interested in console command. OMG there even no picture in this article and you still reading 🙂
Ok, enough, roll up the sleeve and here is what I do, just using console command for the whole task.
Preparing the partition for the new hdd :
The newhdd is still on the esax dano external usb case, and I need to create a scheme of partiition size that I decided to be 50Gb for the root system, 6Gb for swap because I have 3Gb of memory, 100Gb for my home partition and leave the rest for one big partition that maybe I can find to be useful for 1080p hd video storage. Clear enough the new 500Gb is on usb external storage then it must be on /dev/sdb device naming and the old 120Gb that is in my notebook has /dev/sda device name. I’m using fdisk command to create the new partition :
I press n to make new partition, press p for primary partition, press 1 to create the first partition on that disk, follow the default so it cover the entire disk rather than a part of it. Then I press t to define the partition type, and press L to see a list of known partition types and finally enter 83 as the type. To finalize the writing then I press w to make it permanent. For not being boring, of course the same logic is follow for the rest of the partitions.
After done, time to check the results :
[[email protected] ~]# sfdisk -d /dev/sdb # partition table of /dev/sdb unit: sectors /dev/sdb1 : start= 63, size=102398247, Id=83, bootable /dev/sdb2 : start=102398310, size= 12273660, Id=82 /dev/sdb3 : start=114671970, size=204796620, Id=83 /dev/sdb4 : start=319468590, size=657299475, Id= 5 /dev/sdb5 : start=319468653, size=657299412, Id=83 [[email protected] ~]#
Done, the partition is ready,
Formatting the partitions :
I make it in a row :
mkfs.ext4 /dev/sdb1 mkswap -c /dev/sdb2 mkfs.ext4 /dev/sdb3
done formatting. Reboot to make sure and check again with fdisk -l and maybe mount it and check with df
Cloning the paritions :
At this point I already disasemble the esax dano usb case and swap the hdd with the internal hdd on my notebook. This is where the dd command I mention before come in handy :
dd if=/dev/sdb1 of=/dev/sda1 & pid=$!
To make it clear, I repeat once more, the new 500Gb now is on sda and the old 120Gb is on usb external case which is sdb. With that command, I clone the entire partition of sdb1 into sda1. I preserve pid=$! command at the end for monitoring the progress purpose. I can check the progress at any time with :
kill -USR1 $pid
The main reason why I put the dd command work in background is for this progress monitor.
Same logic also for my 100Gb home partition which take a really long time, Watching veronica mars on universal till finish the progress is still 68% 🙂
dd if=/dev/sdb3 of=/dev/sda3 & pid=$!
After finish, I unplug the external usb hdd, I no longer needed because I already had a clone on the internal hdd of my notebook.
Verifying and Resizing the partition :
This step is needed because I move the less partition to bigger size partition, otherwise the new size will not accepted by the system :
fsck -f /dev/sda1 resize2fs /dev/sda1 fsck -f /dev/sda3 resize2fs /dev/sda3
Check again the results with fdisk -l and df to make sure of it.
Taking care of GRUB :
I need to create a grub bootloader for my new system, so I type grub, and after loaded I type find /boot/grub/menu.lst, grub answer with (hd0,0), then I select the partition with root (hd0,0) before fetching to recreate the grub with setup (hd0,0), and quit for done.
For very detail explanation here is the article to recreate grub.
Recreating initrd :
After reboot, the boot sequence will stay on “Waiting for sda1 to appear (1minute timeout)” (so does with sda3) for some time. This is normal since the the initrd image now cannot find the old hdd, we must recreating the initrd image file with this :
rm /boot/initrd-184.108.40.206-jf2.bfs.img mkinitrd -v /boot/initrd-220.127.116.11-jf2.bfs.img 18.104.22.168-jf2.bfs
and … done. I reboot and the delay was perish.
Making new swap work :
I clone the sda1 and sda3 thus the uuid from the old system was carried away by the process but not with swap sda2 since I don’t clone the swap. I need to supply the /etc/fstab for swap partition sda2 with the correct new uuid to make it work. Yeah I know it’s much much easier to use diskdrake to do this below job, but for the sake of command minded I do this by typing to get the uuid for the new swap partition :
blkid /dev/sda2 /dev/sda2: UUID="7cc6bfca-0cd3-4fe4-a160-7473fe88de7b" TYPE="swap"
Edit the /etc/fstab for the new swap uuid :
[[email protected] ~]# cat /etc/fstab # Entry for /dev/sda1 : UUID=67b4c017-7bcf-48ff-a206-fea943f7f133 / ext4 defaults,noatime 1 1 none /dev/pts devpts defaults 0 0 tmpfs /dev/shm tmpfs defaults 0 0 # Entry for /dev/sda3 : UUID=979d627e-5374-4ad5-b397-d8962901846f /home ext4 defaults,user_xattr 1 2 # Entry for /dev/sda5 : UUID=fa64ee4e-5c5f-4535-a159-57568c5b89f0 /media/hd ext4 defaults 1 2 none /proc proc defaults 0 0 none /tmp tmpfs defaults 0 0 # Entry for /dev/sda2 : UUID=7cc6bfca-0cd3-4fe4-a160-7473fe88de7b swap swap defaults 0 0 [[email protected] ~]#
and reboot …. wooohooo I can work again !!