# "Clone" your Gentoo root partition

## lakicsv

Dear Gentooers,

Often times there are upgrades or changes which can potentially render you nicely configured system unsusable. If this disaster happened, it is a very good feeling to have the EXACT copy of your original root partition backed up and ready to use! I wrote a bash script which will clone your gentoo partition on another partition, so you are safe to do anything advetureous...

Why is the script? Isn't "cp -a / /mnt/clone" would be enough? Unfortunately,  this would require to unmount separate partitions, like /home, and could cause problems with /dev partition which gentoo uses. Certain special files would also be left out. So, after a reading a long discussion on gentoo user list, I chosen the possibly safest solution (at least what I tried) and wrote a scrip around it to make it easy to use.

I have two (same sized) partitions for gentoo root.  I also have /home on a separate partiton and I have one separate partition containing /usr/local (symlinked), /opt (symlinked), /var/tmp/portage (PORTAGE_TMPDIR set in make.conf), /usr/portage/distfiles (DISTDIR set in make.conf). Before I do something dangerous, I run the script to duplicate my root partition, and with this setup I leave out some bulky stuff (copying your distfiles) which normally is not changed that much.

The script has a "pretend mode", so you can see what will happen without any danger...

Here is the help taken from the script (you can also display it with "gent-clone -h")

"############## gent-clone help #####################"

This script will clone your gentoo root partition to "

another partition. Usage:"

gent-clone mode [destination mount point]"

where mode = "-c"  Clones current root partition to a destination partition'

"-p"  Prentend cloning; useful to see what would happen without any changes'

"-h"  Prints this message...'

'Destination mount point should be given as /dir1/dir2 or /dir format, if it is not supplied, then the program uses internal defaults (can be changed at the beginning of the script). A partition should be attached to the destination directory or the mount point  listed in /etc/fstab before using the script! Normally, the /etc/fstab file on your root partition will be edited by the script: A new adjusted /etc/fstab is created and copied over - this contains your destination partition mounted as root. If you do not want this behavior, set the FSTAB_FLAG variable from 1 to 0 by editing the first part of this script.

Examples:

gent-clone -c /mnt/clone 

-->clone you root partititon to the partition  	mounted on /mnt/clone '

     gent-clone -c

-->clone your current root partition to your predefinied'

     partition (set this up by editing the first part of the script)

gent-clone -p

--> Pretend mode: Prints out what will happen when you issue a -c    argument'

I call this file as gent-clone. Copy it to an empty file and save it. 

I hope someone finds this helpful, I certainly used it regularly...

Cheers:  Viktor

```

#!/bin/bash

# This script will clone the root partition of your gentoo system to a selected

# partition and create the appropriate fstab file for the cloned partition

#################################################################################

# Change these variables according to your prefs, for CLONE_DIR always use a path

# like /dir1/dir2, never something like /dir or /dir1/dir2/dir3...

# CLONE_DIR either have to be defined in /etc/fstab, or mounted...

# BIND_DIR is a directory to mount - bind your root partition (it is needed for your 

# gentoo system which uses devfs - otherwise /dev will not be correctly copied...

# If you do not want to change the fstab file for your cloned partition, set

# FSTAB_FLAG to 0...

BIND_DIR=/mnt/oldroot

CLONE_DIR=/mnt/clone

FSTAB_FLAG=1

#################################################################################

# Do not change these:

SOURCE_DIR=/   

CREATE_BIND_DIR=0

MOUNT_CLONE_DIR=0

###################### Subroutines ##############################################

#

----------

## pilla

Works for me. Just don't forget to verify the fstab in the new partition before booting.

----------

## lakicsv

What do you mean by verifying? The script creates and copies the new fstab file where the destination partition is mounted as root...

Didn't it wok for you?

Viktor

----------

## pilla

The partition wasn't in the fstab (which is allowed by your script). Anyway, you never know....  :Wink: 

----------

## kram

I do this:

cp -ax / /mnt/clone

chroot /mnt/clone /bin/bash

emerge baselayout

and then that partition is bootable, works perfect for me  :Smile:  ... is their a reason why this script is better than my method?

----------

## lakicsv

I could think of a couple of things:

1. /dev does not get copied (since it is mounted as a dev file system). Doing an emerge baselayout (I think this is supposed to create your dev as well) does not give you an EXACT replica of your root dir...

2. If you have your DISTDIR  in a separate partition, you will run  into problems: emerge baselayout will fail since in the chroot only one partition is mounted... 

3. You have to manually edit /etc/fstab to reflect the changes when you boot your new partition

4. Convenience features: the script will mount your dirs for you, checks against mistakes

My script is intended to deal with all this, making this cloning as automatic as possible. If you dedicate a partition, you can even do it from a cronjob if you want (But I rather do it when it is needed, i.e. before major upgrades: I usually do non-security related upgrades weekly on my workstation - desktop machine)

Cheers:  Viktor

----------

## c_kuzmanic

Great script - saved me some work, thanks a million:)

My root partition is on a raid0 array, I should have no problem using your script though, correct ?

----------

## BlackBart

could you add support to instead of coppying it to compress everything into a file?

----------

## Dimitri

Here you are shown how to compress you gentoo into an tar.gz file. It's in German, but also understandable for non-Gernman speaking people

https://forums.gentoo.org/viewtopic.php?t=17462

Dim

----------

## water

I have made a backup using Mandrake (also somewhere on my harddisk). Not very beautifull, but it works.   :Very Happy: 

----------

## Freak_NL

An alternative way to do backup your partition into a compressed file is this:

```
tar -X tar.exclude -cvjpf backup.tar.bz2 /*
```

With this being an example tar.exclude file:

```
/mnt

/tmp

/usr/src

/usr/portage/distfiles

/var/tmp

/proc
```

Be sure to put the path for the backup tar.bz2 archive somewhere on a different partition then your / partition.

Also, I've found Linux Live-CD's (like Knoppix for instance) ideal for restoring backups.

----------

## kappax

much much simpler way would be.

mount drive to wich would hold the backup  

```

mount /dev/hdc3 /backup 

```

then copy files over 

```

rsync -va --deleate --exclude=/proc/* --exclude=/dev/* --exclude=/backuo/* / /baclup 

```

then have some code to change the fstab, and add the entry in to your grub config. all done.

then later you can add the  -u option to rsync and just update what has changed.

----------

## lakicsv

If you look at my original code (I started this thread), you will realize that the whole script could be done in two actual lines in it. 99% of it is checking the parameters, printing out docs making it as automatic as possible.

So by the time your one-liner would do similar things that would be just as complicated and not "much much simpler"...

Just my 2 cents...

Viktor  :Wink: 

----------

## garo

i just reboot with a live cd (i like knoppix), and do :

```
mount /dev/hda3 /mnt/hda3 && dd if=/dev/hda2 | bzip2 > /mnt/hda3/backuphda2.bz2
```

hda2 is my "/" and hda3 is a partition i use for my backups

----------

## modal

Or, you could just use EVMS to make a RAID 1 configuration on separate partitions, and constantly have it backed up...although, this script is great if you are going to do something daring like...shhh, emerge crazy-.9-alpha!!

 :Wink: 

----------

## dalu

your script doesn't work for me, it prints some errors.

```

./copydrive: line 21:  : command not found

./copydrive: line 177: syntax error near unexpected token `)'

./copydrive: line 177: `   -p) '

```

i named it copydrive

----------

## iplayfast

Ok, all you hotshots. I've got a question. If I've got two computers networked together. One fully loaded with disks (that I'm not going to take apart) the other with a 5gb virgin disk waiting to be filled... 

can I use knoppix on both computers and somehow ssh from one to the other and copy the root file system? (I've tried but failed miserably  :Rolling Eyes:  )

Or is there a better way?

----------

## Delphiki

Here's how I do this (and I've had to do it a couple times).

find / -xdev | cpio -pvdm /destdir

Works just fine for me.

----------

## iplayfast

 *Delphiki wrote:*   

> 
> 
> find / -xdev | cpio -pvdm /destdir
> 
> 

 

I think I'm being slow. Let's suppose I've got two computers booted under knoppix. I ssh from one to the other and they are talking. 

On the virgin computer ssh'd to the gentoo computer, I mount something like 

```
mount /dev/hda2 /mnt/srcdir
```

On the virgin computer I 

```
mount /dev/hda2 /mnt/destdir
```

Now where does this find come into play?

----------

## Delphiki

 *Quote:*   

> Now where does this find come into play?

 

find /mnt/srcdir -xdev | cpio -pvdm /mnt/destdir 

I wasn't specifically answering your question, but rather an alternative to the script posted, but this should work as long as you've got both drives mounted.

----------

## iplayfast

 *Delphiki wrote:*   

> 
> 
> I wasn't specifically answering your question, but rather an alternative to the script posted, but this should work as long as you've got both drives mounted.

 

Ooops. Oh well, as long as I have you on the line, how can you mount a drive across ssh then? So that on one computer I've got 

/mnt/srcdir

/mnt/destdir

Is that possible?

----------

## Delphiki

Accross ssh? I don't believe so. You would need Samba, NFS, or something along those lines for that. Knoppix might be able to do these but I wouldn't know as I've never used it.

----------

## iplayfast

Found it. Much simpler then I expected.

The situation: 

Machine one is a working gentoo system.

Machine two is an empty box.

A knoppix cd is available. 

step 1. 

Clean off any unneeded files. 

My list is:

/var/tmp/portage/work/*

/usr/portage/distfiles/*

There's probably more, but that gave me 1 gig that I didn't have to transfer.

step 2.

boot machine 2 with the knoppix cd.

open a terminal.

```
sudo su

passwd abc

cd /mnt

mount /dev/hda2 hda2

ifconfig

```

If all is well you will see the ip address of your tcp port. In my case it was 192.168.1.101

Step 3.

on machine 1 (the gentoo box) open a terminal

```

su -

password

cd /

tar lcz . | ssh -l root 192.168.1.101 'tar xz -C/mnt/hda2/'

```

you will be asked for root's password on machine 1 (abc) 

once this is finished, you have transferred the / directory. (I'll leave the /boot directory as an exercise  :Wink: 

To explain what this does (for the unfamiliar)

tar lcz . | ssh -l root 192.168.1.101 'tar xz -C/mnt/hda2/'

the first part 

```
tar lcz .
```

 creates a tar file which will be spewn out to wherever. Stdout (the console) is the default, but with the beauty of pipes we can put it elsewhere.  

The parameters lcz are:

	 l=local file system only. (no need to worry about /proc, /dev /mnt) 

	c is create a new archive,

	z is compress. 

this all gets piped to ssh

```
 | ssh -l root 192.168.1.101 
```

ssh is the transport mechanisum. It asks for the password and then executes

```
'tar xz -C/mnt/hda2/'
```

which extracts the archive spewing (I like that word) out of ssh, uncompresses it, and puts it into /mnt/hda2 (which we mounted in step 2).

It's also possible to open up another terminal and ssh to machine 1 to take a gander at how things are going.

----------

## delta407

 *Delphiki wrote:*   

> Accross ssh? I don't believe so.

 SSH can do marvelous things. I've transparently linked three disparate networks over SSH -- `ssh` gives you a bidirectional means of communication (stdin, stdout) so you can run pretty much anything (including pppd).

Again, SSH can do marvelous things.  :Wink: 

----------

## john Doe

hi guys, i have some problems with this script. (well i have the same error even with rsync metod listed above)

i have my gentoo root partition on /dev/hdd7, i installed gentoo here cause i wanted just to give it a try, but right now i've seen thet gentoo rocks :p, so i want to move to hda1 (hda is faster than hdd)

ok, i've run this script. All files seems to be copied to hda1, i've modified fstab to match new root on hda1 and grub.conf to add newroot entry:

```

root (hd0,0)

kernel=/boot/bzImage <parameters here>

initrd=/boot/initrd

```

Btw, When i try to boot hda1 partition, it instead boot hdd7... i mean that when i arrive on login if i type #mount i see:

/dev/hdd7 on / type reiserfs (rw,noatime,notail)

...

instead of /dev/hda1 as expected. I've found no way to boot hda1.

I've tried even to phisically unplug hdd drive, and when i boot (from a grub boot floppy-disk) hda1 it gives me an error on VFS. I don't remeber exactly which.

Some hints?

Thanks, and sorry for my poor english  :Smile: 

john

----------

## john Doe

thanks to boglin, I fixed

I just needed to add "root=/dev/hda1" to the kernel string of the cloned partition

John

----------

## dreamer3

Anyone looking for aa very interesting and novel way to do backups drive to drive please see:

Easy Automated Snapshot-Style Backups with Linux and Rsync

Imagine having /mnt/backup/daily-02.28.2003, daily-03.01.2003, daily-03.02.2003, daily-03.03.2003... etc... for as far back as you have space for... (with all of your important files)

It uses hard links and rsync so that only CHANGED files are actualy STORED on the desk of each snapshot... so with only 50% more room (than the real files) you can maybe store over a months worth of snapshots (depends on how frequently you change files, etc).

I wrote a working script of this the way that I like it and I've been happy with it... had to restore one or two files and it's as simply as copying them from their location in the snapshot I choose...

----------

## ninth_life

Has anyone tried partimage?  It is on the gentoo live cd.  You can boot the disk, mount a partition to store the backup on, and run "partimage" from the command line.  I have used this method to backup and restore my system and it works great.  Just a suggestion.  I haven't tried the script though so maybe it is better?

ninth_life

----------

## decker in flux

how about we assume that both drives are setup according to the install guide, then:

```

mkdir /mnt/oldboot

mkdir /mnt/newboot

mount /dev/hda1 /mnt/oldboot

mount /dev/hdb1 /mnt/newboot

mkdir /mnt/oldroot

mkdir /mnt/newroot

mount /dev/hda3 /mnt/oldroot

mount /dev/hdb3 /mnt/newroot

cp -Rpd /mnt/oldboot/* /mnt/newboot/

cp -Rpd /mnt/oldroot/* /mnt/newroot/

```

works for me.

-d

----------

## Superfly

 *iplayfast wrote:*   

> Ok, all you hotshots. I've got a question. If I've got two computers networked together. One fully loaded with disks (that I'm not going to take apart) the other with a 5gb virgin disk waiting to be filled... 
> 
> can I use knoppix on both computers and somehow ssh from one to the other and copy the root file system? (I've tried but failed miserably :roll: )
> 
> Or is there a better way?

 

Netcat!

If you don't have netcat (nc) on your knoppix cd, then I suggest downloading Timo's Rescue Cd.  It has instructions with it on how to make your own rescue cd using the tools it provides.  PCMCIA+netcat+vim == a great laptop recover disk.

So, on the destination machine, boot off the rescue cd:

```

# nc -l p 4000 > /dev/hda

```

Where /dev/hda is the destination drive

And then on the source machine, boot off the rescue cd and:

```

# cat /dev/hda | nc destination_ip 4000 -w 5

```

Where /dev/hda is the source drive and destination_ip is the ip of the destination machine.

The 4000 is just a random port.  You can choose what you want.  the "-w 5" means "Keep sending data until 5 seconds of no data"...  so that it automatically stops when it's done with the cat.

It is important that the filesystem is not mounted as you do this.  I've never done this with gentoo laptops, because everyone at work wants me to setup redhat boxes for them... but I don't see why it wouldn't work.

Now that I think about it...  this would only work if the drives were the same size.  If they are not the same size, you could partition the drives the same way and then do them one at a time /dev/hda1 /dev/hda2  etc...  Then install grub or lilo on the destination machine.  Or, you could mount the filesystems on the master somewhere ("mount /dev/hda1 /mnt", "mount /dev/hda2 /mnt/home", etc, fdisk and make the filesystems on the destination, mount them on the target under /mnt like you did on the master, and then use something similar to copy the files:

On the source machine:

```

( cd /mnt ; tar cvf - . ) | nc -l -p 4000

```

Then on the destination machine:

```

nc masterhostname 4000 | ( cd /mnt ; tar xvf - )

```

Then install grub or lilo on the destination machine.

-Ryan

----------

## traca_qc

simply use the command dd 

dd if=/dev/hda1 of=/dev/hda2

if = Input File

of = Output File

----------

## ljkopen

I used nc in the manor superfly suggested (with tar), but my symlinks didn't copy properly?  The link has no permissions for anyone, and doesn't point anywhere, filesize zero.

I'm reading up on tar, but the only thing I can find about linking and tar is that you can send the thing it points to if you want.

Any ideas?

----------

## Superfly

 *ljkopen wrote:*   

> I used nc in the manor superfly suggested (with tar), but my symlinks didn't copy properly?  The link has no permissions for anyone, and doesn't point anywhere, filesize zero.
> 
> I'm reading up on tar, but the only thing I can find about linking and tar is that you can send the thing it points to if you want.
> 
> Any ideas?

 

I just tried it out on my gentto box like so:

```

mkdir source

mkdir dest

cat "hi" > source/test

ln -s source/test source/blah

cd dest

nc -l -p 4000 | tar xvf -

```

And then in a seperate window:

```

cd source

tar cvf - . | nc localhost 4000 -w 5

```

And the sym link came out just fine. :/  I don't know what to suggest... maybe try "tar cvpf"?

----------

## iwasbiggs

 *traca_qc wrote:*   

> simply use the command dd 
> 
> dd if=/dev/hda1 of=/dev/hda2
> 
> if = Input File
> ...

 

If you want to save space/output to a file:

#time dd if=/dev/hdb1 | bzip2 > /mnt/backup/backup.img

Restore

#time cat /mnt/backup/backup.img | bunzip2 > /dev/hdb1

Though this doesn't seem to be working so well, I guess non-used part of disk is filled with too much random data (91 megs went to 87 on a near empty disk and took over 2 minutes on an athlon 1800xp!)

----------

## TenPin

I cloned a gentoo instalation to another hard disk by simply doing cp -R -p / /mnt/new and similarly for /boot. All that remained was to chroot in and run grub on the new disk. Worked perfectly.

----------

## JoeW71

Hello there, I've had a problem with running out of diskspace in my fresh Gentoo install (poor planning, I admit) so after reading this thread carefully i tried the following:

booted my Gee (naturally   :Smile:  );

mounted the newdisk as /mnt/newdisk

binded my old root as /mnt/olddisk

cd to /mnt/olddisk/

and typed this command:

```
find / -xdev | cpio -pvdm /mnt/newdisk
```

as I sat there watching the verbose output fly by I noticed something that could be errors of some kind. I couldn't tell as the messages where scrolling too fast.

Could this procedure generate problems with symlinks ??

----------

## JoeW71

Oh, naturally I forgot to mention  :Rolling Eyes:  that I have had strange problems and some segfaults in KDE and The Gimp since this little operation.....

----------

## cnf

i used your script to emigrate my gentoo to my new hd

but i had to edit and run the script for every mount point ...

as i use seperate partitions for

/

/boot

/usr

/var

/home

it took me a while :-)

maybe edit the script so it can handle that ?

----------

## green_buddy

 *traca_qc wrote:*   

> simply use the command dd 
> 
> dd if=/dev/hda1 of=/dev/hda2
> 
> if = Input File
> ...

 

How long does this take?  I mean, how do we know when the above has finished, or if our system is just hanging?  How long should we expect this to take I guess is really the question?

Thanks,

-green

----------

## green_buddy

Here's what I did...

```
root@mymachine / # dd if=/dev/hde3 of=/dev/hda3
```

and after a while it just hung, so I let it go for about an hour before hitting <ctrl-c>.  Then I got this...

```
8805265+0 records in

8805264+0 records out
```

The straight up dd didn't seem to work as traca_qc suggested.  Does anyone know why the dd command hung and seemed to not write one record to the outfile?  Very strange.  :Shocked: 

Now, when I try and mount /dev/hda3 I get...

```
root@mymachine /home/green # mount /dev/hda3 /mnt/root

mount: wrong fs type, bad option, bad superblock on /dev/hda3,

       or too many mounted file systems

```

Something definitely didn't work here.

Anyone?

-green

----------

## rgrue

green_buddy:

It looks like you copied the first 45 gigs (8805264 * 512 bytes) of /dev/hde3 onto /dev/hda3.  When you hit Ctrl-C, dd told you how many 512 byte blocks it had copied over and quit.  Since it didn't copy over the whole filesystem, mounting it failed.  I hope you didn't have anything important on /dev/hda3.

The reason it was taking so long, was because it was reading and writing only 512 bytes at a time.  Also, it wasn't just copying all of the files and directories over; it was copying EVERY byte on the partition, including every unused byte on the filesystem.  You can change how many bytes to read at a time with the bs option for dd.    Make sure DMA is turned on with hdparm too if you're gonna dd partitions that large.

Another point about using dd is that I think the two partitions have to be the same size to do this.  If you dd'd a smaller partition to a bigger partition, and then mounted the bigger partition, you would find it to be the same size as the smaller partition.  If you dd'd a bigger partition to a smaller partition, dd would quit when the smaller partition ran out of room, and you would probably be unable to mount it.  I'm kinda guessing about this last bit here, so someone please correct me if I'm wrong.

Hope that helps,

Rob

----------

## JoeW71

 *rgrue wrote:*   

> 
> 
> Another point about using dd is that I think the two partitions have to be the same size to do this. If you dd'd a smaller partition to a bigger partition, and then mounted the bigger partition, you would find it to be the same size as the smaller partition. If you dd'd a bigger partition to a smaller partition, dd would quit when the smaller partition ran out of room, and you would probably be unable to mount it. I'm kinda guessing about this last bit here, so someone please correct me if I'm wrong.

 

This is an accurate description indeed.   :Wink: 

Another alternative to this would be G4U at:

http://www.feyrer.de/g4u/

or Partimage at:

http://www.partimage.org/

wich seem to be available as an ebuild.

Also check out this thread:

https://forums.gentoo.org/viewtopic.php?p=332373#332373

----------

## JoeW71

 *me, myself wrote:*   

> or Partimage at: 
> 
> http://www.partimage.org/
> 
> wich seem to be available as an ebuild.

 

Oops, stated the already stated ... pardon !  :Embarassed: 

----------

## craftyc

 *Freak_NL wrote:*   

> An alternative way to do backup your partition into a compressed file is this:
> 
> ```
> tar -X tar.exclude -cvjpf backup.tar.bz2 /*
> ```
> ...

 

I just used this method to backup about 3.5 gigs of my / partition. Bzip2 compressed it to just over 1.3 gigs. Amazing.   :Shocked: 

----------

## sirwally

> Accross ssh? I don't believe so. You would need Samba, NFS, or something along those lines for that. Knoppix might be able to do these but I wouldn't know as I've never used it.

emerge shfs

shfs will allow mounting over ssh.  Very cool.

LUFS will also allow similar functionality.

I know, the post was old, but if it saves one person some time, I'm happy.

----------

## iplayfast

good one. I've also discovered sftp which is also useful.

----------

## deurk

Does this script work for any partition? (non-root ones also?)

I'd like to make a full backup every night of my 4 partitions drive on another drive (exact same disk)...

Can I use this?

Thanks in advance...

----------

## d3c3it

Ive got a quick question about this script, is there away i can create a backup and compress it onto a network drive but omitting some folders *mostly my ~/music and ~/video folders* as they are to huge and have them backed up already ?

----------

## feardapenguin

Very cool script.  This is just what I was looking for.  I needed an exact copy of my system for testing dev kernels, packages, etc.

FWIW, the process took only 55 minutes to clone a 4GB system (same disk, hdb1 to hdb7).

----------

## alligator421

 *decker in flux wrote:*   

> how about we assume that both drives are setup according to the install guide, then:
> 
> ```
> 
> mkdir /mnt/oldboot
> ...

 

Yes, it works pretty well with cp.

I migrated my gentoo as primary distro on my first disk with mere cp and it worked flawlessly.

For those interested, here is a detailed set of steps considered grub on first disk.

At start I had :

/dev/hda1 evilFS with bootable flag

/dev/hda2 swap

/dev/hda3 linux (redhat with grub.conf in its /boot, and grub installed on MBR (hd0) )

/dev/hdb1 /boot (gentoo with no grub)

/dev/hdb2 swap

/dev/hdb3 linux (gentoo)

===

make backup of everything as first step  :Smile: 

take a live-cd distribution or gentoo linux single user to boot, your partitions won't be mounted

I used knoppix.

-su

~hdparm -d 1 /dev/hda

~hdparm -d 1 /dev/hdb

~cat /proc/swaps

check if the live-cd is using swap partitions on hda, it was the case, so make :

~swapoff /dev/hda2

~fdisk /dev/hda

delete all partitions on hda

recreate partitions for a standard gentoo install, so now :

/dev/hda1 /boot (gentoo) with bootable flag

/dev/hda2 swap

/dev/hda3 linux (gentoo)

~mke2fs -j /dev/hda1 (or mkfs.ext3 /dev /hda1) if u want ext3 for boot

~mke2fs -j /dev/hda3

~mkswap /dev/hda2

~swapon /dev/hda2

~cd /mnt

~mkdir oldRoot

~mkdir oldBoot

~mkdir newRoot

~mkdir newBoot

~mount -t ext3 -o ro /dev/hdb1 /mnt/oldBoot

~mount -t ext3 -o ro /dev/hdb3 /mnt/oldRoot

~mount -t ext3 -o rw /dev/hda1 /mnt/newBoot

~mount -t ext3 -o rw /dev/hda3 /mnt/newRoot

~cp -ax /mnt/oldRoot/*   /mnt/newRoot

~cp -ax /mnt/oldBoot/*   /mnt/newBoot

take a coffee while it is copying

~umount /mnt/oldBoot

~umount /mnt/oldRoot

~umount /mnt/newBoot

~cd /mnt/newRoot

~chroot /mnt/newRoot ./bin/bash

#nano -w /etc/fstab (change it according to your new filesystem on hda)

#exit

~umount /mnt/newRoot

~reboot (without live-cd)

now grub is jammed because it was on former redhat filesystem, remember ?

no cool bootsplash with options but a nice grub prompt  :Smile: 

you have to boot on our fresh gentoo by hand typing in grub :

grub# root (hd0,0)

grub# kernel /bzImage ro root=/dev/hda3 hdc=ide-cd hdd=ide-scsi (depends on your config)

grub# boot

.. and gentoo boots on fresh disk  :Smile: 

once on gentoo, do as in the fine manual

-su

~mount /boot

~emerge grub

~grub

grub# root (hd0,0)

grub# setup (hd0)

grub# quit

~nano -w /boot/grub/grub.conf (configure grub as above)

~ln -s /boot/grub/grub.conf /boot/grub/menu.lst

~umount /boot

gator

----------

## RoVeRken

thanks alot!!, this script is very usefull for n00bs like me :p

----------

## unattachme

OK, I know many of the l33t wouldn't consider this, but the 'lil utility 'Konserve' (for KDesktop) is really a wonderful program, ESPECIALLY for the 'grandma types'.

Just my 2 cents, though the above solutions seem great too.

I've always just booted the gen2 live and done a 

mkdir /gen2

mkdir /bak

mount /dev/ROOT /gen2

mount /dev/BAK /bak

tar cvzf /bak/backupname.tgz /gen2

Perhaps it's more work than is necessary, and there's probably more 'efficient' ways to do it, but it's always 'just worked' so I keep using it.

----------

## tiny

Thnx for the script ... I did a 'cp -axR' and 'find -xdev|cpio' things but that always failed when I rebooted into new partition since there wasnt any /dev/files .

BTW: How does your script manage this /dev/devices problem? With -bind option on mounting BIND_DIR?

----------

## feardapenguin

Hmmm... this script no longer seems to work with the new cpio-2.5.90.  I get "too many arguments".

Anyone know what needs to be tweaked?

----------

## lakicsv

This seems to be a bug in cpio... see:

http://lists.gnu.org/archive/html/bug-cpio/2004-11/msg00003.html

Viktor

 *feardapenguin wrote:*   

> Hmmm... this script no longer seems to work with the new cpio-2.5.90.  I get "too many arguments".
> 
> Anyone know what needs to be tweaked?

 

----------

## feardapenguin

Thanks, I'll keep an eye on that and in the meantime stay with 2.5.

This script has been a very handy-dandy kitchen tool.  I've used it for both backup and to create test systems (easy since my entire system resides on a single partition).  In fact it saved my can during a recent glibc fiasco.  After a total crash-and-burn I was able to restore the original system from a cloned version (in about an hour) saving me from having to rebuild from scratch (which would have taken about three days).

Kudos!

----------

## BlinkEye

another way to backup your system is pointed out here: klick

(same thread as my signature points to at the moment)

----------

## stealthy

Ever since I've been on gentoo. I have used one this to backup my system...and  it has never failed me

```
cp -avix / /backup 
```

where /backup is the another partition/drive mounted

only drawback doing it this way is that each filesystem has to be done individually.

 Therefore for eg. 

if I had:

sda1 /boot

sda3 /

sda5 /usr

sda6 /var

sda7 /tmp

sda8 /home

sdb1 /backup/boot

sdb3 /backup/

sdb5 /usr

sdb6 /var

sdb7 /tmp

sda8 /home

I would do 

cp -avix / /backup

cp -avix /boot /backup

cp -avix /usr /backup

cp -avix /tmp /backup

cp -avix /var /backup

cp -avix /home /backup

Now having all the in a file and then running a cron job has never failed me

I have clone numerous systems like that without a hitch

Alhough for the first time i clone the drive, I also just run

grub

and the install mbr on on backup drive by

root (hd1,0)

setup (hd1)

Never failed for me.

Reasons why others should try other methods:

1. Although this tried method, its also slow and inefficent, cause it literally copies every file, even if the destination one already is latest

2. It doesn't work across the filesytems 

3. its not a one-liner

Why I still use it.

1. For Past 4 years it still hasn't failed me, and I've  had to use backups made by it countless times.

2. It works for me so why bother with anything else.

3. I am too lazy

----------

## BlinkEye

i only use tar and bzip2 to make the backup. my script does some useful things too, like giving the backup a timestamp, like compressing it and most usefully excluding unnecessary directories which make an archive really big. my system at the moment seems to be 16GB big, but after backing it up its merely 1GB small. there are a lot of unnecessary folders to backup ... this method does not only save space but a lot of time too

----------

## feardapenguin

OK, cpio-2.6 is out and it appears to have fixed the -p bug but it is not behaving the same as 2.5 (evidently).

I upgraded to cpio-2.6 a week or two ago and just finished cloning my system this morning using this script.  The newly cloned system booted but did not load kernel parameters or execute any of the /etc/init.d run-level scripts.  Immediately after loading modules it just entered run-level 3 and gave me a login prompt.  An 'rc-update show' was totally empty.

Just as a test I reverted cpio back to 2.5 and reran the same clone process.  It worked flawlessly.

I should have kept the 'flawed' system around so I could browse through it for differences (i.e. broken symlinks, dev files, etc) but I wasn't sure it was related to cpio until I tried the script again with the old version.

----------

## MagnusBerg

"My" method to backup is maybe to simle for you.  :Wink:  Just

# emerge partimage

and then run it in your terminal.

Partimage-0.6.4 Partimage is a Ghost/DriveImage clone for Linux. It allows you to save/restore any partition of your hard disk into an image file. If you have a problem with your partition (virus, hard disk crash, error), you can restore it without having to reinstall your OS.

----------

## BlinkEye

i certainly will have a look at it. thanks for the hint

----------

## dwblas

Script works fine with cpio-2.6.5-r5.  Thanks for the effort.

----------

