10/20/2015 - 4:06 PM

"drive migration script"

"drive migration script"


#http://www.techrepublic.com/article/solutionbase-moving-linux-from-one-disk-to-another/ #http://www.tcm.phy.cam.ac.uk/~mr349/backup_restore_linux.html #http://www.linuxjournal.com/magazine/hack-and-migrate-new-hard-drive?page=0,1

test ! -d $1 && { echo "$1 not a valid dir. Exiting..."; exit 1; }

RSYNC approach

#--progress alias rsynccopy="rsync --partial --links --specials --devices --progress --append --rsh=ssh -r -h " alias rsyncmove="rsync --partial --links --specials --devices --progress --append --rsh=ssh -r -h --remove-sent-files"

cd / rsynccopy for i in /mnt /proc /sys /srv2 /opt/srv/bkp /hg2g/bkp.man; do echo -e " --exclude=$i "; done / $1 cd -

echo "Continue with:" echo "rm -rf $1/dev/pts/" echo "rm -rf $1/dev/shm/" echo "mkdir $1/sys" echo "mkdir $1/proc"

exit 0

Old time variant

DIRS=ls / |grep -v "mnt\|proc\|sys\|srv2"

tar cf - ${DIRS}A | (cd $1; tar xvf -) cp -v /* $1/ echo "Continue with:" echo "rm -rf $1/dev/pts/" echo "rm -rf $1/dev/shm/" echo "mkdir $1/sys" echo "mkdir $1/proc"

exit 0 #TBD #chroot grub-install /dev/sda if initrd and vmlinuz are in /boot, otherwise you will need: grub-install --root-directory=/mnt /dev/sda

#-- chroot /mnt/sdb1 /usr/sbin/grub-install --recheck /dev/sdb

Change /mnt/sdb1 and /dev/sdb to reflect your new mounted root partition and its disk 
device, respectively. If the chrooted grub-install doesn't work, you typically can use 
your rescue disk (or single user) grub-install with the --root-directory option:

/usr/sbin/grub-install --recheck --root-directory /mnt/sdb1 /dev/sdb

#grub reinstall #update /etc/fstab, /etc/crypttab etc.