cloning GPT disk to a smaller drive

while rescuing data from server having problems with either disk or raid controller i had to clone data from 2x 1TB RAID1 to 4x 500GB RAID10. as it turned out the space available on the destination server was 1GB less than on the source machine. shrinking the source drive with gparted-live and dd’ing over the network was not enough. full list of necessary steps – below.

  • first resize the partitions on the source machines so the total size of them fits on the destination machine. i use gparted-live.
    gparted-resize

  • run linux on both machines and do sector-by-sector clone over the network. i was lazy so instead of booting the source machine from a live-cd i have just re-mounted all partitions as read only to avoid any writes to the disk during cloning [this might be risky, dont do it with important data].:
    # all of this on the source machine
    # stop all processes that might keep files opened for writing
    /etc/init.d/cron stop; /etc/init.d/mysql stop ; /etc/init.d/apache2 stop; /etc/init.d/rsyslog stop 
    # re-mount all partitions as read only
    mount -no remount,ro / 
    # and clone
    dd if=/dev/sda bs=10M | ssh -c arcfour -o Compression=no root@destination "dd of=/dev/sda bs=10M"
    
  • after dd’ing the disk image boot the destination machine from gparted-live cd, go to the terminal and run gdisk and press v,x,e,w,y:
    root@debian:/home/user# gdisk /dev/sda
    GPT fdisk (gdisk) version 0.8.5
    
    Warning! Disk size is smaller than the main header indicates! Loading
    secondary header from the last sector of the disk! You should use 'v' to
    verify disk integrity, and perhaps options on the experts' menu to repair
    the disk.
    Caution: invalid backup GPT header, but valid main header; regenerating
    backup header from main header.
    
    Warning! One or more CRCs don't match. You should repair the disk!
    
    Partition table scan:
      MBR: protective
      BSD: not present
      APM: not present
      GPT: damaged
    
    ****************************************************************************
    Caution: Found protective or hybrid MBR and corrupt GPT. Using GPT, but disk
    verification and recovery are STRONGLY recommended.
    ****************************************************************************
    
    Command (? for help): v
    
    Caution: The CRC for the backup partition table is invalid. This table may
    be corrupt. This program will automatically create a new backup partition
    table when you save your partitions.
    
    Problem: The secondary header's self-pointer indicates that it doesn't reside
    at the end of the disk. If you've added a disk to a RAID array, use the 'e'
    option on the experts' menu to adjust the secondary header's and partition
    table's locations.
    
    Problem: Disk is too small to hold all the data!
    (Disk size is 7340032 sectors, needs to be 8388608 sectors.)
    The 'e' option on the experts' menu may fix this problem.
    
    Identified 3 problems!
    
    Command (? for help): x
    
    Expert command (? for help): e
    Relocating backup data structures to the end of the disk
    
    Expert command (? for help): w
    
    Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
    PARTITIONS!!
    
    Do you want to proceed? (Y/N): Y
    OK; writing new GUID partition table (GPT) to /dev/sda.
    The operation has completed successfully.
    
  • reboot – this time the system should boot from the smaller destination disk

Leave a Reply

Your email address will not be published. Required fields are marked *

 

(Spamcheck Enabled)