Difference between revisions of "Transfer system disk from SD card to hard disk"

From eLinux.org
Jump to: navigation, search
(e2label)
m (Corrections)
Line 1: Line 1:
 
+
[[Category:Raspberry Pi]]
 +
[[Category:USB disk]]
 +
[[Category:SD card]]
 
Systems like [[Raspberry Pi]] can only boot from an [[SD card]].
 
Systems like [[Raspberry Pi]] can only boot from an [[SD card]].
 
The initial [[operating system]] is entirely installed on an SD card.
 
The initial [[operating system]] is entirely installed on an SD card.
Line 5: Line 7:
 
*an SD card is slow
 
*an SD card is slow
 
*it wears out and frequently results in [[I/O error]]s and [[file system]] corruptions.
 
*it wears out and frequently results in [[I/O error]]s and [[file system]] corruptions.
 +
*the SD card has limited capacity
  
Therefore we want to only use the SD card for the [[W95 FAT32]] partition containing the initial boot configuration.
+
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 hard disk.
+
We will transfer the complete system disk from the SD card to a (USB) hard disk.
  
 
==Considerations==
 
==Considerations==
 
At the end, it is not too complicated, if you follow carefully the below script...
 
At the end, it is not too complicated, if you follow carefully the below script...
 
You might do the conversion on a running system...
 
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...
+
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]].
  
==Move the partition==
+
==Copy the partition==
 
Imagine the system disk is on /dev/mmcblk0p2.
 
Imagine the system disk is on /dev/mmcblk0p2.
You can verify the partition size as follows:
+
You can verify the partition sizes as follows:
 
  [[fdisk ]]-l /dev/mmcblk0
 
  [[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]]
+
*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:
 
*Transfer the system disk:
  [[dd]] bs=4M if=/dev/mmcblk0p2 of=/dev/sda4
+
  [[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 -- you might loose data if you do not use the right command!
+
'''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...
 
'''Note''': You could use the same technique to move any other partition from one device to another...
  
==Configure the partition==
+
==Configure the new partition==
 
  [[gparted]]
 
  [[gparted]]
 
Right click on the new partition, and ''Check''.
 
Right click on the new partition, and ''Check''.
Line 36: Line 41:
 
Therefore you must set a new UUID: right click ''New UUID''
 
Therefore you must set a new UUID: right click ''New UUID''
  
Now quit the gparted utility.
+
Now quit the ''gparted'' utility.
  
 
==Get the new UUID==
 
==Get the new UUID==
 +
You can possibly assign a new partition name:
 +
[[e2label]] /dev/sda4 Raspbian
 
You can obtain the new UUID as follows:
 
You can obtain the new UUID as follows:
[[e2label]] /dev/sda4 Raspbian
 
 
  [[blkid]]
 
  [[blkid]]
 
   
 
   
Line 73: Line 79:
  
 
==Reuse the previous SD card partition==
 
==Reuse the previous SD card partition==
Once the system is running fine, you could use the old partition to store data,
+
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.
 
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.
+
Then you can reuse the previous 4, 8, 16, or 32 GB card for other purposes...

Revision as of 14:34, 18 November 2014

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
  • 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 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:

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

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