Monday 9 June 2008

Cloning an EEEPC Drive

There are various tutorials on cloning disks, configuring grub, recompiling disk images etc but I've yet to see one that goes through step by step how to clone an EEEPC disk.
A recent project I was given for Radio Lollipop required me to configure an EEPC and then clone the disk to an SD card and make it bootable. This allowed us to be able to insert the card into any EEEPC and have it boot with our software and configuration.

Now the EEEPC is shipped with two partitions
sda1 is the root partition which is only ever mounted as ro and contains the base install
sda2 is the user partition and contains all the user files, additional apps and modifications.
When the machine is turned on unionfs is used to combine these partitions into one bootable drive
When you do a factory reset on an EEEPC it basically just blanks the user partition returning you to a base install

So I had two options available to me:

Clone only the user partition and make the EEEPC use the memory card as the user partition whist booting from the existing root partition
Advantages:
Can be done on a smaller memory card
Drawbacks:
Would have to create a new bootloader.
Susceptible to incompatibility with newer releases of the EEEPC.


Clone everything from both partitions and combine them correctly onto one memory card.
Advantages:
Grub and the boot image would already exist and would just need to be configured.
Copying all the data means that it would be immune to incompatibility issues on newer releases of the EEEPC.
Drawbacks:
Would have to merge the partitions somehow
Requires a much bigger memory card


I'll begin with my progress on cloning only the user partition.

First I downloaded a copy of DamnSmallLinux and burnt it to a CD. Then by booting from the CD I could access both drive partitions quite happily. DamnSmallLinux views the root partitions as 'hdc1' and the user partition as 'hdc2' (you can check this by simply running the command 'mount').

I ran this command to copy the user partition to my SD card (I got a 2Gb SD card which did the job fine - a 1GB may even do)

dd if=/dev/hdc2 of=/dev/sdb2


This took a while but once it was done I had my clone.
Then I copied the boot folder from the root partition (hdc1) to the SD card aswell.

I then setup the Grub bootloader on the SD card:

sudo grub
> find /boot/grub/stage1
##Pick the last hd it finds e.g. (hd3,0)
> root (hd3,0)
> setup (hd3)
> quit


Now toggle the SD card's 'bootable' flag using the following commands:

sudo fdisk /dev/sdb1
option 2
option a
partition 1


And finally edit your drive's /boot/grub/device.map to add
(hd1)   /dev/sdb
(hd2) /dev/sdc


Now you have yourself a bootable SD card

I then followed what is said here about setting up menu.1st and the initramfs image (go from the heading 'Changing the SD card so that the EeePC boots and uses the SD card for it's disk'. However I had to make a couple of changes to the instructions:

Where it says to copy the device files for sda1 and sda2 into your initramfs dev folder instead run these commands.

sudo mknod sdb1 b 8 17
sudo mknod sdb2 b 8 18
sudo mknod sdc1 b 8 33
sudo mknod sdc2 b 8 34


As firstly the copy command just plain doesn't work and secondly this will also give you access to sdc which is the USB

Also where it tells you to enter the sleep command into the init file you need to enter 25 or 30 in order to give it time to load the device drivers, otherwise when you boot it will be unable to mount the SD card or USB.

After you've zipped your initramfs image back up and copied it to the SD card you should be good to go. All you then need to do is press F2 at boot and change your boot order to default to your SD card and away you go!

No comments: