#!/bin/bash
# Drive must be partitioned before using this, just run fdisk and set up the correct size partitions
# calculate maximum drive size
NEWDRIVE="sda"
OLDHOST="192.168.0.1"
# Create mount points
mkdir /mnt/${NEWDRIVE}{1,2,5,6,7,8}
# Create file systems
mkfs -t ext3 -L /boot /dev/${NEWDRIVE}1
mkfs -t ext3 -L /usr /dev/${NEWDRIVE}2
mkfs -t ext3 -L /var /dev/${NEWDRIVE}5
mkfs -t ext3 -L /tmp /dev/${NEWDRIVE}6
mkfs -t ext3 -L / /dev/${NEWDRIVE}7
mkfs -t ext3 -L /home /dev/${NEWDRIVE}8
# Mount them
mount -t ext3 /dev/${NEWDRIVE}1 /mnt/${NEWDRIVE}1
mount -t ext3 /dev/${NEWDRIVE}2 /mnt/${NEWDRIVE}2
mount -t ext3 /dev/${NEWDRIVE}5 /mnt/${NEWDRIVE}5
mount -t ext3 /dev/${NEWDRIVE}6 /mnt/${NEWDRIVE}6
mount -t ext3 /dev/${NEWDRIVE}7 /mnt/${NEWDRIVE}7
mount -t ext3 /dev/${NEWDRIVE}8 /mnt/${NEWDRIVE}8
# Transfer each partition
cd /mnt/${NEWDRIVE}1
ssh $OLDHOST "dump -0uan -f - /boot" | restore -r -f -
cd /mnt/${NEWDRIVE}2
ssh $OLDHOST "dump -0uan -f - /usr" | restore -r -f -
cd /mnt/${NEWDRIVE}5
ssh $OLDHOST "dump -0uan -f - /var" | restore -r -f -
cd /mnt/${NEWDRIVE}6
ssh $OLDHOST "dump -0uan -f - /tmp" | restore -r -f -
cd /mnt/${NEWDRIVE}7
ssh $OLDHOST "dump -0uan -f - /" | restore -r -f -
cd /mnt/${NEWDRIVE}8
ssh $OLDHOST "dump -0uan -f - /home" | restore -r -f -
echo "Dumping file systems done, please make sure fstab is correct and reinstall grub."
echo "/mnt/sda7/sbin/grub --no-floppy"
echo "root (hd0,0)"
echo "setup (hd0)"