Transfer system disk from SD card to hard disk
- an SD card is slow
- it wears out and frequently results in I/O errors and file system corruptions.
- it can get corrupt after power-failure or underpower conditions
- 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 partition from the SD card to a (USB) 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... 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
- 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:
dd bs=4M conv=noerror 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; it can accidentally overwrite any good partition -- you might lose 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
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 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] /dev/mmcblk0p2 / ext4 defaults,noatime 0 1 [after] 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 [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...
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 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...
SD Card reading error
SD cards are sensitive to I/O errors, especially due to underpower conditions:
dd: reading '/dev/sdb4': Input/Output error
- A file system error occurred
- Make sure to use the dd conv=noerror option
- Verify that the output size equals the input size
- Always check your target partition with GParted after duplicating