#!/bin/bash # Create new disk label # parted -s /dev/${NEWDRIVE} mklabel msdos # Before running this the new drive must have a dos partition table installed # Just run fdisk and hit "w" to write a new one. # calculate maximum drive size MAX=$(parted -s /dev/${NEWDRIVE} print | awk '/megabytes/ {print $5}' | cut -d "-" -f 2) echo $MAX # Create partitions # parted -s /dev/${NEWDRIVE} mkpart primary 0 1024 parted -s /dev/${NEWDRIVE} mkpart primary 1024 11264 parted -s /dev/${NEWDRIVE} mkpartfs primary linux-swap 11264 15360 parted -s /dev/${NEWDRIVE} mkpart extended 15360 $MAX parted -s /dev/${NEWDRIVE} mkpart logical 15360 25600 parted -s /dev/${NEWDRIVE} mkpart logical 25600 27648 parted -s /dev/${NEWDRIVE} mkpart logical 27648 29696 parted -s /dev/${NEWDRIVE} mkpart logical 29696 $MAX # Create mount points mkdir /mnt/${NEWDRIVE}{1,2,5,6,7,8} # Create file systems PARTS="1 2 5 6 7 8" for part in $PARTS; do mkfs -t ext3 /dev/${NEWDRIVE}${part}; done # Mount them for part in $PARTS; do mount -t ext3 /dev/${NEWDRIVE}${part} /mnt/${NEWDRIVE}${part}; done # Transfer each partition cd /mnt/${NEWDRIVE}1 dump -0uan -f - /boot | restore -r -f - cd /mnt/${NEWDRIVE}2 dump -0uan -f - /usr | restore -r -f - cd /mnt/${NEWDRIVE}5 dump -0uan -f - /var | restore -r -f - cd /mnt/${NEWDRIVE}6 dump -0uan -f - /tmp | restore -r -f - cd /mnt/${NEWDRIVE}7 dump -0uan -f - / | restore -r -f - cd /mnt/${NEWDRIVE}8 dump -0uan -f - /home | restore -r -f - # Apply labels e2label /dev/${NEWDRIVE}1 /boot e2label /dev/${NEWDRIVE}2 /usr e2label /dev/${NEWDRIVE}5 /var e2label /dev/${NEWDRIVE}6 /tmp e2label /dev/${NEWDRIVE}7 / e2label /dev/${NEWDRIVE}8 /home e2label /dev/${OLDDRIVE}1 /boot-old e2label /dev/${OLDDRIVE}2 /usr-old e2label /dev/${OLDDRIVE}5 /var-old e2label /dev/${OLDDRIVE}6 /tmp-old e2label /dev/${OLDDRIVE}7 /-old e2label /dev/${OLDDRIVE}8 /home-old echo "Dumping file systems done, please make sure fstab is correct and reinstall grub." echo "grub --no-floppy" echo "root (hd1,0)" echo "setup (hd1)"