Cloning PCLinuxOS to a new drive…

Hi Folks.

I have decided to share with You a method of cloning PCLinuxOS instance from one drive to another. There idea came from Cyryl and the whole HOWTO is just a translation with screenshots and little changes. I used it twice so far – both times successfully however I must WARN You – Your brain needs to be in the ON position when following this. No it’s not very difficult BUT if You won’t do it correctly You will loose all Your data.

So… Fair warning – this HOWTO is written for a bit advanced users or noobs who are not afraid to learn by borking like myself.

Let me tell You a bit about the situation that I have here before I will go any further. As You probably know I own a few laptops. Recently I have purchased a 160 gigs 2.5 inches HDD and I have decided to replace my main machine HDD with it. I could do the remaster of the 80 gigs drive and then install it on the 160 gigs drive. I could BUT… Remaster is limiting the size of the transferred data to 4.3 GB plus remaster skips some of the /var/ files. My installation was rather large so… I decided to use this method.

What I did first was I took out the 80 gigs HDD from the Packard Bell and placed it in the USB external case. Then I have assembled the laptop with a 160 gigs HDD inside and booted it from LiveCD. First thing done. Next thing is to create a partitions on the new HDD. We are going to need at least two partitons – root / and swap. I always add one extra partition for the /home and if there is any place left I add another one or two for my data. Partitions that You create on the new HDD must be at least the same size of the partitions that You want to clone to them. They can be bigger. They can’t be smaller. After creating new set of partitions I rebooted and booted to LiveCD again. When KDE4 was fully loaded I plugged in the 80 gig drive in the USB case to it. No drives were mounted. No drives should be mounted. You don’t need the USB case. It’s easily done with desktop HDDs as well. If You are an advanced user You will know what I mean. NO I do not mean to plug the HDD when the computer is running. I did it once several years ago – all I saw was a smoke coming out from the HDD. That was it. HDD went to the bin. Be careful and make sure You know what are You doing! Ok LiveCD is booted up. KDE4 is loaded. 160 gigs HDD is inside the lappy and 80 gigs HDD inside the USB case is plugged in and detected. No drives are mounted. Now using a set of few command I have cloned the 80 gigs / and /home partitions to the 160 gigs / and /home partitions. When this was done I unplugged the 80 gigs drive from the USB port. Next thing I did was checking the partitions and resizing them. Why? Cloning copies everything and makes the partition look like the one I had on the 80 gigs. Since I made partitions on the 160 gigs bigger I need to re-size them to their normal size. When this was done I had to setup grub and reboot. This time I booted from 160 gigs. First thing I have noticed was a “Timeout 1 min” problem for the cloned HDDs. It really took 2 minutes of just standing and looking at it. Then when the /dev was filling laptop rebooted. Ok… No problem. It booted to the KDE4 no problem this time – altho I still had to wait for 2 mins with the HDD timeout. No problem – there is cure for this. When the KDE4 was fully booted I had to mess around a bit with few things like HDD mounting and labeling, regenerating initrd file, adding swap to the /etc/fstab. Nothing to difficult. After all the final touches system was up and running and it had everything I needed and wanted. Super sweet Dude!!

So now I have 80 gigs HDD laying around collecting dust. 60 gigs HDD in a USB case. And 10 gig HDD in the Dell Latitude C610 machine. Yeah… 10 gigs… Ok that needed to be changed… No rush. In the future. Today I spoke to a good Friend of mine and I told Him about my little adventure. He told me that He could use this method to copy His massive install into a new drive. From one word to another I have decided to write a HOWTO for my blog. Reasons? Anybody will be able to use it and it will keep my head busy which is a good thing lately.

So… Here is the second time I did it.

Just like before. I took out the old drive from the machine and placed a new one in it. Then I booted from LiveCD and created set of partitions. Rebooted from LiveCD with the old drive plugged in as well. Cloned / checked / re-sized partitions and setup a grub. Then after booting from the cloned drive I mounted and labeled all the hdds, redid initrd to remove timeout problem and added swap entry and voila… second computer is done.

So now 80 gigs is in the USB case, 10 gigs waits for a 2nd USB case which I have purchased on eBay from a guy at Hong Kong for less then €6 including shipping. All is good.

Now that You know the background and all the fair warning it’s time to cut to the chase.

Preparing the partitions on the new HDD:

Boot from a LiveCD and start a konsole.

When the konsole window appears type in pcc and press [ENTER]

You will be asked for a root’s password. As You can read from the top right corner of the wallpaper its root.

PCLinuxOS Control Center will start up. Click on Local disks in the left pane. Now click on Manage disk partitions.

Now You can see the sda drive – in my case its completely empty. If You want to get rid of old partitions click Clear all below the drive info. Now click Toggle to expert mode in the bottom right corner.

You can see that the info section has been extended about some extra information. Now click on the long whitish rectangle representing an empty drive.

Info has changed and the Create button in the right pane appeared. Click on it. We will create the / root partition now.

Create a new partition window appeared. It has some data in it. What You need to change is the Size in MB value. Remember to make it either the exact size of the old root / partition or bigger.

It cannot be smaller otherwise the cloning process will fail due to the lack of space. Also remember that 1 gig = 1024 megs. In my case I will use 20 gigs root / partition so the number of megs I type in is 20480. Now press Ok.

Notice that the white rectangle is now divided into 2 rectangles. Smaller on the left. It’s the partition You have just created. You can check if You did everything correctly by reading the info below the partition.

Make sure that the focus is on the created sda1 partition by clicking on it and then click Format in the right pane. You will be asked about partition table to be written to the disk. Click Ok.

Check for bad blocks question will pop up. I tested my drive with HDD Regenerator sometime ago. I know it has no bad sectors so I clicked No. If You want to test the drive click Yes but be aware that it will take long time.

Drive is now being formatted. Wait till the process is finished.

Drive has now finished formatting. It’s time to create another partition. Click on the white rectangle on the right. This is the unpartitioned part of the drive. Click on Create button.

Create a new partition window appeared. It has some data in it. What You need to change is this time is the Size in MB value and Filesystem type. This will be our swap partition. Typical size of a swap partition will be equal to the 4 times amount of Your Ram memory but not bigger then 2 gigs. I recommend 2 gigs for most of the setups and that’s how much I will use here as well.

Remember that 1 gig = 1024 megs. In my case I will use 2 gigs swap partition so the number of megs I type in is 2048.

Now click on the expandable list next to the Filesystem type entry to make it drop down. Top left – Linux swap. Click on it.

Now press Ok.

Notice that the white rectangle is now divided into 3 rectangles. Small on the left. Smallest in the middle – its the swap partition You have just created. You can check if You did everything correctly by reading the info below the partition.

Make sure that the focus is on the created sda5 partition by clicking on it and then click Format in the right pane. You will be asked about partition table to be written to the disk. Click Ok.

Check for bad blocks question will pop up. I tested my drive with HDD Regenerator sometime ago. I know it has no bad sectors so I clicked No. If You want to test the drive click Yes but be aware that it will take long time.

Drive is now being formatted. Wait till the process is finished.

Drive has now finished formatting.

You can see that it says Formatted in the partitions info.

It’s time to create another partition. Click on the white rectangle on the right. This is the unpartitioned part of the drive. Click on Create button.

Create a new partition window appeared. It has some data in it. What You need to change is the Size in MB value. Remember to make it either the exact size of the old home /home partition or bigger.

It cannot be smaller otherwise the cloning process will fail due to the lack of space. Also remember that 1 gig = 1024 megs. In my case I will use 10 gigs home /home partition so the number of megs I type in is 10240. Now press Ok.

Notice that the white rectangle is now divided into 4 rectangles. Another partitions in now created. You can check if You did everything correctly by reading the info below the partition.

Make sure that the focus is on the created sda6 partition by clicking on it and then click Format in the right pane. You will be asked about partition table to be written to the disk. Click Ok.

Check for bad blocks question will pop up. I tested my drive with HDD Regenerator sometime ago. I know it has no bad sectors so I clicked No. If You want to test the drive click Yes but be aware that it will take long time.

Drive is now being formatted. Wait till the process is finished.

Drive has now finished formatting. You can see that it says Formatted in the partitions info.

It’s time to create another partition. Click on the white rectangle on the right. This is the unpartitioned part of the drive. Click on Create button.

Create a new partition window appeared. It has some data in it. What You need to change is the Size in MB value. I will not be cloning this partition so the size is not that important.

This partition will be used as a extra data (photos, documents) partition. I will use the remaining drive space by clicking on the little arrow in the box next to Size in MB. Now that the arrow is grayed out I know that I used the entire disk space. If You want You can create few smaller partitions instead of one big. Just repeat the steps as before. Press Ok.

Notice that the white rectangle is now divided into 4 rectangles. Another partitions in now created. No more space is left. You can check if You did everything correctly by reading the info below the partition.

Make sure that the focus is on the created sda7 partition by clicking on it and then click Format in the right pane. You will be asked about partition table to be written to the disk. Click Ok.

Check for bad blocks question will pop up. I tested my drive with HDD Regenerator sometime ago. I know it has no bad sectors so I clicked No. If You want to test the drive click Yes but be aware that it will take long time.

Drive is now being formatted. Wait till the process is finished.

Drive has now finished formatting. You can see that it says Formatted in the partitions info.

The disk is now prepared for cloning data onto it.

You can toggle between the partitions by clicking on the segments of the white horizontal rectangle.

Summary.

We have created 20 gigs root / partition sda1 and formatted it with Ext4 file system.
We have created 2 gigs swap partition sda5 and formatted it with Swap file system.
We have created 10 gigs home /home partition sda6 and formatted it with Ext4 file system.
We have created 23 gigs data partition sda7 and formatted it with Ext4 file system.

Click Done button in the right bottom. You will be asked for fstab modifications. Click Yes.

Close the PCLinuxOS Control Center window.

Close the Konsole window.

Restart the machine.

Now if You are using desktop it’s better to shutdown machine so You will have a chance to connect the old drive. Test that the drive is detected by bios. Now boot the machine from LiveCD.

If You are using laptop with one drive in the box and one drive in a USB case You can reboot the machine and boot to LiveCD again. After choosing the keyboard wait for the KDE4 to load completely and then plug in the drive to the USB port. Device Notifier will report that the drive was connected. Ignore it. Do not mount any drives.

Click on the KMenu and open a konsole window.

Done? Good.

Open another one.

Done? Good. In first konsole type in su and press [ENTER]

Now type in the root’s password. It’s root.

Now do the same thing in the second konsole window.

Now that both konsole windows have root privilages in the second window type in fdisk -l (small L letter) and press [ENTER]. A lot of info will be shown – don’t panic. On my screenshot its divided into two sections. Highlighted and not highlighted. If You will read into it You will notice that the highlighted section is nothing else but info about my old 10 gigs HDD. It has 2 partitions that are of interest to me. /dev/sdb1 which is my old root / partition and /dev/sdb6 which is my home /home partition. It also has /dev/sdb5 partition which was my old swap – there is no reason for cloning it. There is also /dev/sdb2 partition – marked as Extended. I will not be explaining why it’s there. If You know – good. If You don’t… You will find out in the future adventures with Your PC.

The most important info from the highlighted section is.

A) This is the drive we will be clonning from
B) /dev/sdb1 = old root /
C) /dev/sdb6 = old home /home

Now lets look at the not highlighted part. Analogically:

A) This is the drive we will be clonning to
B) /dev/sda1 = my new root /
C) /dev/sda6 = my new home /home

Examine Your output of the fdisk -l command. Make sure You understood everything. If not – go back and read my HOWTO again and again until You do.

Ok if You are still reading it means You understood everything. let’s continue.

In the first konsole I will type in

dd if=/from of=/to

from fdisk -l we know that from = /dev/sdb1 to = /dev/sda1 analogically the command will look like this:

dd if=/dev/sdb1 of=/dev/sda1 & pid=$!

dd is a command that clones the media. It does not looks what it does. It does not asks. It’s Your responsibility (not mine) to give a correct info to the command or You WILL loose all Your data. Just a fair warning. Got it all figured out? Command written? Ok then press [ENTER].

I used dd command in a way that will make it work in a background. Why? So we can check its progress by using command:

kill -USR1 $pid

You can do it as many times as You want. Sometimes it looks like the above command is stuck. Just press [ENTER] to go back to the root prompt.

It may take a long time to copy the partition. Do not unplug the USB cable. Basically leave the machine alone until it has finished copying.

Here is the message that dd has finished copying.

Confirm it… by using kill -USR1 $pid one more time. If it says No such process – it’s done.

Type in clear and press [ENTER]. Ready for round number two? Now we are copying /home partition. I won’t be explaining the whole syntax again.

Command I used this time was:

dd if=/dev/sdb6 of=/dev/sda6 & pid=$!

I used dd command in a way that will make it work in a background. Why? So we can check its progress by using command:

kill -USR1 $pid

You can do it as many times as You want. Sometimes it looks like the above command is stuck. Just press [ENTER] to go back to the root prompt.

It may take a long time to copy the partition. Do not unplug the USB cable. Basically leave the machine alone until it has finished copying.

Here is the message that dd has finished copying.

Confirm it… by using kill -USR1 $pid one more time. If it says No such process – it’s done. Now if You are using desktop just continue with the howto. If You are using laptop with one HDD inside and another in a USB case – You can unplug the USB cable. We won’t need the old HDD anymore.

In the first konsole type in clear and press [ENTER]. Ready for round number three? Now we are checking partitions and resizing them.

First my root / partition:

fsck -f /dev/sda1

Second my home /home partition:

fsck -f /dev/sda6

Remember that You need to adjust the commands to Your needs. When I was cloning the drives for the first time fsck asked me about some data in the journal and do I want to continue. I pressed y to confirm. The second time during writing this howto it did not asked. It may ask You but there is no general rule about this. If it does just press y.

Now in the second konsole window type in clear and press [ENTER].

Type in fdisk -l (small case L) and press [ENTER]

After unplugging the USB case – there is only one drive left in my laptop. It’s the 60 gigs HDD with my new root / and home /home partitions.

Good.

Now go back to the first konsole window and type in:

resize2fs /dev/sda1

and press [ENTER]

When its done type in

resize2fs /dev/sda6

and press [ENTER]

Drives are now re-sized and ready to be used.

Now we need to take care of the grub.

Type in grub in the first konsole window and press [ENTER].

When grub is loaded type in:

find /boot/grub/menu.lst

and press [ENTER]

Grub says hd(0,0)

This means that the first hdd on the first partition has a file we want. That’s a good sign.

We will set the root partition now. My root partition is a first partition of the first drive (grub is taking a 1 from the numeration that is why it says 0,0 as a location).

Type in

root (hd0,0)

and press [ENTER]

Now we will setup grub on our disk.

Type in:

setup (hd0)

and press [ENTER]

after a sec or two grub will finish and You will see it prompt ready and a whole bunch of info above it. If it looks anything like on my screenshot – You are good to go.

Type in:

quit

and press [ENTER].

This will close grub editor. Close both konsole windows and reboot. You can remove LiveCD from the drive and boot from the new – cloned HDD.

Now that the hdd has been cloned and You are booting to the system press [ESC] when the Plymout is shown. You should see a 1 minute delay for drives sda1 and sda6. The machine can even restart itself while booting. Happened to me so I am just warning. After the 2 minutes of waiting the machine should boot right into the system.

Now that we are inside our cloned system there are some final touches that You need to do before system is fully usable.

Open terminal window and use su command to gain root.

Type in pcc and press [ENTER].

PCLinuxOS Control Center will open. Click on Local disks in the left pane.

Now click on Manage disk partitions.

This will load partition manager we worked with before.

Click on Toggle to expert mode.

Click on the sda5 partition – it’s our swap. Check the details below the rectangle representing partitioned drive. In my screenshot swap drive is green but it may be gray in Your machine. Depends on the gtk theme used. Anyway click on swap partition and click Format in the right pane.

Click Ok on the warning popup.

Again… if You feel drive may contain bad sectors press Yes. I will press No.

Now click on the data partition (the one on the right) and click Unmount in the right pane.

The partition is now unmounted and we gained access to a few more options.

Click on the Mount point button. It offers /var by default.

Change it to /media/Data_Disk_1 or something similar.

On the red rectangle I now have the path to where the drive will be mounted by default.

Click on the Label button in the right pane. Type in Data Disk 1 and Ok the window.

Click Mount button in the right pane.

Drive is now mounted.

Click Done. Click Yes when asked about fstab entries.

Close the PCLinuxOS Control Center window.

Now about the delays… PCLinuxOS and wise Old-Polack has a solution for this

First I will remove the current initrd file using rm command as root in the terminal…

rm /boot/initrd-2.6.38.7-pclos1.bfs.img

Confirm when asked by pressing y.

Now we need to regenerate the deleted file. In my case the command will look like this.

mkinitrd -v /boot/initrd-2.6.38.7-pclos1.bfs.img 2.6.38.7-pclos1.bfs

It may look slightly different in Your case. Read Old-Polack’s post for more details.

The command may take a bit of time to finish.

Now we need to give ourselves permissions to read and write to the data disk. Chown will do it for us.

As root in the terminal use this command:

chown -Rf andrzejl:andrzejl /media/Data_Disk_1

and press [ENTER]. Of course You need to change andrzejl to Your username and the path to the data drive to match Your mount point.

Type in:

free -m

and press [ENTER].

You will notice that Swap is not mounted. We need to fix this.

I will use mcedit to fix this issue – You can use Your favorite file editor as root to amend the file.

mcedit /etc/fstab

and then I am adding the line below the sda1 entry lines.

# Entry for /dev/sda5 :

and below it

UUID=uuidoftheswappartition swap swap defaults 0 0

How to find out what’s the uuid of the swap partition?

Run blkid as root in another terminal…

After properly amending the file save it by pressing [F2].

and close the editor by pressing [F10].

Now reboot.

There should be no delay in the boot time. Swap should be mounted. You should be able to access the drive labeled Data Disk 1.

That’s it. All done.

Hope this helps somebody someday.

Andy

P.s. All the screenshots are available here thanks to Cyryl

Advertisements