Transfer system disk from SD card to hard disk

Revision as of 13:52, 2 March 2014 by Geertivp (talk | contribs) (e2label)
Jump to: navigation, search

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:

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


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...

Move the partition

Imagine the system disk is on /dev/mmcblk0p2. You can verify the partition size as follows:

fdisk -l /dev/mmcblk0
  • Create an empty partition big enough on an USB hard disk; suppose /dev/sda4 with 20 or 30 GB -- You can use gparted
  • Transfer the system disk:
dd bs=4M if=/dev/mmcblk0p2 of=/dev/sda4

Important: Please note sda4 is just an example! Verify your own partition... The dd command is unforgiving for errors -- you might loose data if you do not use the right command!

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

Configure the partition


Right click on the new partition, and Check. This will:

  • Correct any disk errors from the original SD card partition
  • Resize the partition to fit its new size (resize2fs)

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

Now quit the gparted utility.

Get the new UUID

You can obtain the new UUID as follows:

e2label /dev/sda4 Raspbian

/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
#/dev/mmcblk0p2  /               ext4    defaults,noatime  0       1

UUID=11ed1dc5-0507-48f1-b1c6-d5926df1ee88       /               ext4    defaults        0 1

Change the boot configuration

You must set the new root device:

vi /boot/cmdline.txt
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2
rootfstype=ext4 elevator=deadline rootwait

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...


Now everything is OK and you can reboot:



shutdown -r now

Reuse the previous SD card partition

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