Flash disk cloning

From Rsewiki

SMR Flash Disk Cloning

2012 version with Xubuntu 12.04

NB! not finished yet, but:

Make new boot image

Update image on one of the 4GB sticks, then make new imagefile

  • put 4GB stick on another linux (with GRUP installed)
  • mount the disk on a local directory as root, e.g.:
sudo bash
mkdir -p disk
mount /dev/sdb1 disk
  • copy everything on disk to an image file (it takes several minutes):
cd disk
tar -czf ../image/smrXubuntu20120715.tar.gz *
cd ..
umount disk

Clone image to (new) disk

Make a new bootable disk from existing image:

  • put the destination disk on the system (if not already there), list disk devices:
ls /dev/sd*
/dev/sda  /dev/sda1  /dev/sdb  /dev/sdb1
  • use df to which disks are mounted (e.g. /dev/sda1 is mounted at /) :
df
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/sda1       55805420 50781108   2228604  96% /
  • Use fdisk -l /dev/sdb1 to see if it has the expected size.
  • reformat the disk (using all space (the first 2 ,,) for a linux partition (the L), and bootable (the*):
sudo bash
echo ",,L,*" | sfdisk -L /dev/sdb
  • make ext4 filesystem of the new partition
mkfs.ext4 /dev/sdb1
  • mount the new partition
mount /dev/sdb1 disk
  • now write the image to the partition (this takes several minutes)
cd disk
tar -xzf ../image/smrXubuntu20120715.tar.gz
  • now to the boot sector part - this may be optimized
  • as it should refer to the new system, then chroot is needed
  • and maybe some remount of system file-systems is needed too:
for i in /dev /dev/pts /proc /sys /run; do sudo mount -B $i /mnt$i
mount -B /dev dev
mount -B /dev/pts dev/pts
mount -B /proc proc
mount -B /sys sys
mount -B /run run
  • then engage the new system as the root filesystem and install grub from here
chroot .
grub-install /dev/sdb
  • then you may check the result
grub-install --recheck /dev/sdb
  • you may now halt the system and remove the new disk
halt

New in 2011 version

In order to support both VIA Nehemiah and Intel Atom based platforms two kernels must be included in the smr flash image.

  • 2.6.32.20-rtai supports multicore systems and hyperthreading
  • 2.6.32.20-rtai-up supports single core systems and is optimized to the Via processors

A new clone script called multiclone must be used when this image is flashed. The script is in the root folder of rt15.

Flash cloning procedure on rt15

Via processors using CF-card flash-disks:

  • Log in as root (If you don't know the password abort immediately)
  • Insert the CF-card in the reader in the front of rt15.
  • Check the device name the card is given: tail /var/log/messages. Usually it is /dev/sdb.
  • Go to the image folder: cd image
  • Locate the image you would like to burn (usually the newest one), for instance: flash-2011-01-01.tgz
  • Start the procedure:
root@rt15:~# ../multiclone flash-2011-01-01.tgz /dev/sdb via

NB: Note the two dots in front of multiclone

The procedure for cloning Intel Atom images is the same, except atom must be stated last in stead of via as in:

root@rt15:~# ../multiclone flash-2011-01-01.tgz /dev/sdb atom

Old description

Some of the SMR's now have solid-state flash memory disks, instead of the laptop, 2.5" disks used on older models.

This wiki page contains some notes describing how to write a bootable flash disk image (Slackware Linux) to a memory card. It assumes a Linux PC with USB flash card reader/writer, available as /dev/sda.

The commands below is implemented in this script Clone script. Usage:

clone <from_file.tar.gz> <to device>

<to device> can be both the USB bus (/dev/sdx) or a IDE device (/dev/hdx)

The script will place a file .cloned-at on the Flash Disk with time information for the cloning.

If you put the Flash Disk on the IDE bus and the computer will not boot (LILO - Timestamp mismatch) then the MBR on the Flash Disk must be erased as follows:

dd if=/dev/zero of=/dev/hdx bs=1 count=512

Writing an image

Format the disk, with one large Linux partition:

sfdisk -L /dev/sda <<EOF
,,L,*
EOF

Create a filesystem:

mke2fs /dev/sda1 -L /

Mount the new, empty partition:

mkdir -p /tmp/u
mount /dev/sda1 /tmp/u

Write a previously created image from flash.tar.gz

zcat flash.tar.gz |
tar --extract --file - --directory /tmp/u --preserve-permissions

Create a patched lilo.conf, so that we can run LILO with the flash card mounted via USB. (This won't be necessary if the image written above already contains such a file.)

patch -o /tmp/u/etc/lilo_usb.conf /tmp/u/etc/lilo.conf <<EOF
*** /tmp/u/etc/lilo.conf        Tue Nov  4 21:34:44 2003
--- lilo_usb.conf       Thu Dec 11 11:50:55 2003
***************
*** 4,6 ****
  # Start LILO global section
! boot = /dev/hda
  message = /boot/boot_message.txt
--- 4,7 ----
  # Start LILO global section
! boot = /dev/sda
! disk = /dev/sda bios=0x80
  message = /boot/boot_message.txt
EOF

Run LILO:

chroot /tmp/u lilo -v -C /etc/lilo_usb.conf

All done:

umount /dev/sda1
eject /dev/sda

Reading an image

Mount as above:

mkdir -p /tmp/u
mount /dev/sda1 /tmp/u

Read the partition:

tar --create --file - --directory /tmp/u --one-file-system --exclude lost+found . |
gzip > flash.tar.gz

or

tar -zcf - -C /tmp/u --one-file-system --exclude lost+found . > flash.tar.gz

All done:

umount /dev/sda1
eject /dev/sda