Howto manually backup and (re)create SD cards

Put support questions regarding OPI here. Examples are hardware related issues and other questions that are specific to OPI.
Post Reply
User avatar
tor
Posts: 119
Joined: Thu Aug 14, 2014 3:42 am
Contact:

Howto manually backup and (re)create SD cards

Post by tor » Tue Jan 20, 2015 7:35 am

This is a short and somewhat technical howto on how to manually backup and recreate an SD card using a Linux workstation. The procedure could be used to manually doing backups of OPI and to restore this onto other cards possibly with a different size.

Note that this is not officially supported, and not thoroughly tested. Use with caution! Not doing this correctly could result in loss of data.
Prerequisites
To be able to use this howto you need a linux box wiht cryptsetup and parted installed. Further more you need space to store the SD card backup file.
Backup SD card
To be able to recreate the SD card we first have to create a backup of the card used in OPI.

Power down OPI using the web based admin UI. When powered down move the SD-card to your PC.
Mount the SD card
There is a good chance that the you will be prompted for the encryption password by Linux when inserting the SD card. If so just enter your OPI master password and follow the instructions.

If this does not work you will have to manually mount the card by doing something like:
sudo cryptsetup luksOpen "path to SD device" opi
Give the OPI master password when prompted.
sudo mount -text4 /dev/mapper/opi "wanted mountpoint"
Where the mountpoint can be any suitable path.
Backup SD card
You should now have all the files of the SD card accessible at the mountpoint. We now proceed by doing a backup of the contents.
sudo tar jcvf opi-content.tar.bz2 -C "path to mount point" .
This should successfully create the opi-content.tar.bz2 backup of the SD card.

End by unmounting the SD card and remove it.
sudo umount "mountpath"
sudo cryptsetup luksClose opi
Then remove the SD card from your computer.
Create new SD card
Note that this procedure will erase all content on the card.
Partitioning
Insert the new SD card into your computer.

Create new partitioning.
sudo parted -a optimal -s "Device path" -- mklabel msdos
sudo parted -a optimal -s "Device path" -- mkpart primary 1M -1
Where the device path is the path to your SD card device e.g. something like /dev/sdg
Create encrypted container
To create ths encrypted container issue the following commands. (Note that these settings most likely are not optimal from a security perspective)
sudo cryptsetup luksFormat "path to device partition"
sudo cryptsetup luksOpen "path to device partition" opi
Where device partition is the newly created partition on the device. E.g. /dev/sdg1 or similar. Answer YES and provide your OPI master password when prompted.
Format container
We now continue by formatting the newly created container.
sudo mkfs -text4 -L OPI /dev/mapper/opi
Mount and restore image to new card
Mount the newly created container
sudo mount -text4 /dev/mapper/opi "mount path"
Restore the created backup onto the new card
sudo tar jxvf opi-content.tar.bz2 -C "mount path"
Unmount and remove card
sudo umount "mount path"
sudo cryptsetup luksClose opi
sync
You should now be able to remove the SD-card, insert it in OPI and turn it on.

Post Reply