Copy Linux filesystem on bootable SD card

This tutorial is part of our Tutorials section. It shows how to flash an image onto an SD/SDHC card.

This guide assumes that the card is correctly partitioned, as described in the Create a bootable SD/SDHC card in Ubuntu tutorial.

Steps in this tutorial

  1. Mount the SD/SDHC card (if not already mounted)
  2. Write bootloader if necessary
  3. Write Linux kernel image
  4. Write Linux root file system
  5. Unmount

Quick Solution: Copy an already existing card

If you have already one working SD image and an (absolutely similar) formatted second card, you can just copy them. :!: WARNING Please be aware that the filesystem names (/dev/sdb1, etc.) can differ from system to system, make sure to select the right one.

Copy one SD card to another:

sudo dd if=/dev/sdb of=/dev/sdc

The safer alternative: Copy the SD card to harddisk and then onto another

sudo dd if=/dev/sdb of=~/sd-card-copy.bin

Now back on the second SD card:

sudo dd if=~/sd-card-copy.bin of=/dev/sdb

Mount SD/SDHC card

Check where linux mounted the card. One way is to check this via mount .
Call mount to see where the card has been mounted. Two partitions should have been mounted, one named '/media/BOOT' and the other one '/media/LINUX'. Note the device name, e.g. '/dev/sdb'.

mount

If the card has not been mounted, you have two choices:

Automatic

Just unplug and re-plug the cardreader. It will be detected and mounted automatically.

Manually

If the check with mount didn't work out, use dmesg:

dmesg | tail

Watch out for a line like this:

[sdc] Attached SCSI removable disk

Where sdc could also be sdc or sdd. If it was sdb, the device name of the memory card is /dev/sdc.

sudo mkdir -p /media/BOOT
sudo mount /dev/sdc1 /media/BOOT
sudo mkdir -p /media/LINUX
sudo mount /dev/sdc2 /media/LINUX

Copy files on the BOOT partition (MLO, u-boot.bin and uImage)

Please note that the bootloader files don't have to be rewritten every time. This applies especially when a new custom Linux system is created with BitBake and OpenEmbedded. However if you work close to the hardware, e.g. on drivers, this is different.

Overo

IMPORTANT: Copy MLO FIRST!.

The commands below download the two files and copy them in the right order on the boot partition. You may have to adjust the filenames for future revisions.

cd $HOME
wget http://pixhawk.ethz.ch/wiki/_media/symlink/images/overo/mlo-overo
wget http://pixhawk.ethz.ch/wiki/_media/symlink/images/overo/u-boot.bin-overo

And now copy the two files onto the boot partition (MLO first because of a bug in the X-loader which causes problems if MLO is not the first file written onto the boot partition).

cp MLO-overo* /media/BOOT/MLO
cp u-boot.bin-overo* /media/BOOT/u-boot.bin

The Linux kernel (uImage) resides also on the BOOT partition of the SD-card. If you compile a new version of the kernel you have to copy the new uImage on the BOOT partition. See the instructions below.

BeagleBoard

Download MLO and uBoot from this link (commands for shell below):

IMPORTANT: Copy MLO FIRST!.

The commands below download the two files and copy them in the right order on the boot partition. You may have to adjust the filenames for future revisions.

cd $HOME
wget http://www.angstrom-distribution.org/demo/beagleboard/MLO
wget http://www.angstrom-distribution.org/demo/beagleboard/u-boot.bin

And now copy the two files onto the boot partition (MLO first because of a bug in the X-loader which causes problems if MLO is not the first file written onto the boot partition).

cp MLO /media/BOOT/MLO
cp u-boot.bin /media/BOOT/u-boot.bin

The Linux kernel (uImage) resides also on the BOOT partition of the SD-card. If you compile a new version of the kernel you have to copy the new uImage on the BOOT partition. See the instructions below.

Copy Linux

The next step is to copy the Linux kernel and the Linux root filesystem on the BOOT and LINUX partitions. You can use precompiled binaries for both or compile an OpenEmbedded image yourself. Instructions for both options are provided below.

Copy the precompiled Ångström Image

The precompiled Ångström image consists (besided MLO and u-boot.bin from the bootloader section) of two files: The Linux kernel image (uImage) and the root file system.

Copy uImage

Download and copy the kernel image into the root directory of the boot partition.

Gumstix Overo

cd $HOME
wget http://pixhawk.ethz.ch/wiki/_media/symlink/images/overo/uimage.bin-overo
cp uimage.bin-overo* /media/BOOT/uImage

BeagleBoard

cd $HOME
wget http://www.angstrom-distribution.org/demo/beagleboard/uImage
cp uImage /media/BOOT/uImage

Copy the Linux root file system

The file is named *rootfs.tar.bz2 for the Beagle link and omap3-desktop-image-overo-*.tar.bz2 for the Overo link below. Check the main folder for the current name.

Download the files to a temporary directory, e.g. the Desktop or your user folder. The next step is to extract these files into the LINUX partition (NOT the boot partition). This can only be done by using Linux. If you're using Windows or MacOS, read this.

Gumstix Overo

If you have downloaded the console image:

wget http://pixhawk.ethz.ch/wiki/_media/symlink/images/overo/pixhawk-console-image-overo.tar.bz2
sudo tar xjf pixhawk-console-image-overo-*.tar.bz2 -C /media/LINUX

Or the desktop image:

wget http://pixhawk.ethz.ch/wiki/_media/symlink/images/overo/pixhawk-desktop-image-overo.tar.bz2
sudo tar xjf pixhawk-desktop-image-overo-*.tar.bz2 -C /media/LINUX

possibly, ”pixhawk-desktop-image-overo-*.tar.bz2” has to be changed into ”pixhawk-console-image-overo.tar.bz2” (just adept file name)

BeagleBoard

sudo tar xjf *rootfs.tar.bz2 -C /media/LINUX


Copy custom OpenEmbedded Linux Image

Linux Kernel Image and u-boot bootloader

Copy the kernel image and u-boot.

Gumstix Overo

sudo cp $OE_HOME/tmp/deploy/glibc/images/overo/uImage-overo.bin /media/BOOT/uImage
cp $OE_HOME/tmp/deploy/glibc/images/overo/u-boot-overo.bin /media/BOOT/u-boot.bin

BeagleBoard

sudo cp $OE_HOME/tmp/deploy/glibc/images/beagleboard/uImage-beagleboard.bin /media/BOOT/uImage
cp $OE_HOME/tmp/deploy/glibc/images/beagleboard/u-boot-beagleboard.bin /media/BOOT/u-boot.bin

Linux root filesystem

After the kernel, the root filesystem has to be copied as well. If you are overwriting an existing installation and you don't need a 100% clean system, you can just delete all files. The command below will delete all files in /media/LINUX except the lost+found directory of the EXT3 file system.

sudo rm -rf /media/LINUX/* && sudo mkdir /media/LINUX/lost+found

However if you want a really clean disk, you should format it, but this will take considerably longer.

sudo mkfs.ext3 -L LINUX /dev/sdc2

And now copy the new files.

Gumstix Overo

The console image:

sudo tar xjf $OE_HOME/tmp/deploy/glibc/images/overo/omap3-console-image-overo.tar.bz2 -C /media/LINUX

The pixhawk console image:

sudo tar xjf $OE_HOME/tmp/deploy/glibc/images/overo/pixhawk-console-image-overo.tar.bz2 -C /media/LINUX

Or the desktop image:

sudo tar xjf $OE_HOME/tmp/deploy/glibc/images/overo/omap3-desktop-image-overo.tar.bz2 -C /media/LINUX

BeagleBoard

The console image:

sudo tar xjf $OE_HOME/tmp/deploy/glibc/images/beagleboard/omap3-console-image-beagleboard.tar.bz2 -C /media/LINUX

Or the desktop image:

sudo tar xjf $OE_HOME/tmp/deploy/glibc/images/beagleboard/omap3-desktop-image-overo.beagleboard.bz2 -C /media/LINUX

Unmount the SD/SDHC card

Now unmount the drive either manually (by clicking the unmount icon on the desktop) or by shell command:

sync
sudo umount /media/BOOT
sudo umount /media/LINUX
sudo rm -r /media/BOOT
sudo rm -r /media/LINUX

Copy bytewise from one SDHC card to another

If you have modified your installation and want to clone the content of the SD card, you can do this with dd.

Make sure to plug in the source card first, then the destination card. Check the file names with:

dmesg | tail

And unmount the card (with the GUI or with umount /dev/sdb). Then use dd to copy the first gigabyte from one card to the other (including partition table, etc.):

sudo dd if=/dev/sdb of=/dev/sdc bs=1073741824

@USER@

Project

Related Sites

Micro Air Vehicles

2009-2011 System

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 3.0 Unported