Migrating a linux root partiton

From Blue-IT.org Wiki

TAR

A method that only copies files and dirories from root "/":

$ mkfs -t ext2 /dev/hda4 
$ mkdir /mnt/temp 
$ mount -t ext2 /dev/hda4 /mnt/temp 
$ cd / 
$ tar lcf - .|(cd /mnt/temp; tar xpvf - )

from Linux and XFS HowTo


Rsync

A method for a backup that checks, if the selected partition is mounted. It further checks if there is a file with a special name (here: itsroot) assuring that it is the right partition.

mkdir -p /${ROOTDIR}
if test -e /${ROOTDIR}/itsroot
then echo ${ROOTDEV} already mounted as /${ROOTDIR}...
    echo ---------------------------------------------------------------
else
       if mount -rv ${ROOTDEV} /${ROOTDIR}
       then echo - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
            echo Mounted ${ROOTDEV} on /${ROOTDIR} ...
            echo ---------------------------------------------------------------
       else
               if mount -r -o bind / /${ROOTDIR}
               then echo - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                    echo Mounted ${ROOTDEV} on /${ROOTDIR} VIA BIND - OK.
                    echo ---------------------------------------------------------------
                       if test -e /${ROOTDIR}/itsroot
                       then echo Seams to be the right directory - OK.
                       else echo ERROR mounting  ${ROOTDEV} on /${ROOTDIR};clear; canceled;
                       fi

               else echo ERROR mounting  ${ROOTDEV} on /${ROOTDIR};clear; canceled;
               fi
       fi
fi
rsync -a --progress --delete /${ROOTDIR}/. /${BACKUPDIR}/${ROOTDIR}/.

from a personal backup script.