Transfer system disk from SD card to hard disk

Systems like Raspberry Pi can only boot from an SD card. The initial operating system is entirely installed on an SD card. This adds to simplicity, but has some limiting disadvantages:
 * an SD card is slow
 * it wears out and frequently results in I/O errors and file system corruptions.
 * the SD card has limited capacity

Therefore we want to use the SD card only for the W95 FAT32 partition containing the initial boot configuration. We will transfer the complete system disk from the SD card to a (USB) hard disk.

Considerations
At the end, it is not too complicated, if you follow carefully the below script... You might do the conversion on a running system... If you would be completely sure that the system disk is transferred without error, you might temporarily mount the source and target disk on another system... possibly booting from a live DVD.

Copy the partition
Imagine the system disk is on /dev/mmcblk0p2. You can verify the partition sizes as follows: fdisk -l /dev/mmcblk0 dd bs=4M conv=noerror if=/dev/mmcblk0p2 of=/dev/sda4
 * Make sure all partitions are unmounted
 * Create an empty (unformatted) partition big enough on an USB hard disk; suppose /dev/sda4 with 20 or 30 GB -- You can use GParted
 * Transfer the system disk:

Important: Please note sda4 is just an example! Verify your own partition... The dd command is unforgiving for errors; it can accidentally overwrite any good partition -- you might loose data if you do not use the right command! Known what you are doing...

Note: You could use the same technique to move any other partition from one device to another...

Configure the new partition
gparted Right click on the new partition, and Check. This will: The above dd command duplicated the UUID from the original partition. Every disk UUID must be unique. Therefore you must set a new UUID: right click New UUID
 * Correct any disk errors from the original SD card partition
 * Resize the partition to fit its new size (resize2fs)

Now quit the gparted utility.

Get the new UUID
You can possibly assign a new partition name: e2label /dev/sda4 Raspbian You can obtain the new UUID as follows: blkid /dev/sda4: UUID="11ed1dc5-0507-48f1-b1c6-d5926df1ee88" TYPE="ext4" LABEL="Raspbian"

Change the fstab file
Now prepare the new mount command: vi /etc/fstab [before] [after] UUID=11ed1dc5-0507-48f1-b1c6-d5926df1ee88      /               ext4    defaults        0 1
 * 1) /dev/mmcblk0p2 /               ext4    defaults,noatime  0       1

Change the boot configuration
You must set the new root device: vi /boot/cmdline.txt [before] dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait [after] dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/sda4 rootfstype=ext4 elevator=deadline rootwait Note that the UUID technique does not work for the Raspbian boot loader...

Reboot
Now everything is OK and you can reboot: reboot or shutdown -r now

Reuse the previous SD card partition
Once the system is running fine, you could reuse the old partition to store data, or create a new (small 64 or 128 MB SD card) just bearing the VFAT boot partition. Then you can reuse the previous 4, 8, 16, or 32 GB card for other purposes...