LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   clonning linux with tar (https://www.linuxquestions.org/questions/linux-software-2/clonning-linux-with-tar-427964/)

gobexe 03-24-2006 05:59 AM

clonning linux with tar
 
Hello,

For those who dont have the time to go through all my ordeal, my question is simple. How can I clone a linux machine with tar (and not dd)?

Here is my story.

I needed to install 20-something machines with Linux (Redhat 9) and since they needed to have the same configuration, I decided to try to clone them instead of installing each separately. I googled for some pointers towards, didnt find any, so decided to take matters into my own hands.

I did the original installation with no problem, created four partitions [/, /usr, /home and swap, formatted with ext3]. After installing the machine just as I wanted it, i did a 'tar zcvpf' on / and /usr (i started the machine with a boot cd, mounted the partitions and then did the tar'ing). All was fine, until i started to clone the first machine.

In my mind, the procedure was simple. All I needed to do was create 4 partitions, and then untar the files on the corresponding partitions, do a grub-install and that was it. BUT NO!! The first problem I had was that unless the created partitions were the exact match (cylinder to cylinder) to the original, the machine will not boot (boot process stops with kernel panic). Though I feel st00pid, I created the exact partitions and did the installation and everything worked fine ... until yesterday (about 2 weeks from the day i did the installation).

The problem I have now is that on all machines, df -k shows that / is used only 1% (when in fact 20-something% is in use) and when i try to create a file (either touch or mkdir) i get a 'no space left on device'. If I reboot it i get a grub 117 error, and when i try to mount the / partition from a boot cd, i see that everything is corrupted. Now, I have to do the installation again ... unless someone points out the do's and dont's of machine cloning using tar.

I am now totally lost! I dont know what to do!

/G/

Randux 03-24-2006 07:22 AM

I'm no expert but I just did something similar (but with one machine) with tar. Since nobody has replied yet I will tell you what I can but I am sure the guys know how to do it. I did use an unused partition to test it before I did the real thing.

I created a .tar.bz2 of each filesystem (I had less mount points than you, but the deal is the same) by tar -cpjf rootfilesys.tar.bz2 / for example. I burned this stuff to a CD which is what I think you said you did also.

I loaded a live CD and I fdisked and made new filesystems (not the same sizes) and then I changed directory (not chroot) into the root of the new filesystem. I did tar -xvjf /dev/cd/rootfilesys.tar.bz2. It restored all the files and then I was able to edit the fstab on the new system and chroot into it. Then I ran lilo, which could be a difference...lilo resolves the kernel stuff at lilo time, not boot time. I really don't know what grub does. I rebooted into my new system and then I built the other mount points.

I think it would help if you could show some doc because it's a little hard to see where you might have gone wrong. I know for sure that you don't need to have the same size filesystems (but of course it does need to be big enough to contain the extracted archive).

If these 20 machines of yours can really be set up exactly the same, then I would suggest looking at partimage. It does a nice job of making copies of partitions and even splits up the images to fit whatever media you have, if you want. The only thing is, the file systems have to be exactly the same size or bigger, *even* if the data doesn't require it. For example, let's say you have a 1GB root but it's only 25% full. If you use partimage you will only be able to restore this image to a 1GB or bigger partition, even though you have 750M of free space. That does suck, but it is very very nice if you have identical machines like maybe in your scenario. Because then you really can clone without too much pain. You will need a live CD to do the boot management unless you figure out how to use the MBR feature of partimage.


All times are GMT -5. The time now is 08:02 AM.