Dev/Embedded/Rootfs

From Embeded Linux (and more) Wiki by Nathael
< Dev‎ | Embedded
Revision as of 13:01, 16 October 2019 by Drizzt (talk | contribs)
Jump to navigation Jump to search

Busybox rootfs

Devuan rootfs

Rootfs Backup (or Copy)

First of all, avoid any site which tells you to use dd to backup or clone your system, as it's author either does not want to take some time to explain how things work, or simply doesn't know.
When using dd :

  • you won't be able to extract the content to explore it on your development system
  • you will not be able to change the partition sizes or layout when creating a copy
  • you will not be able to change the filesystem type
  • even if you compress the result, extracting it will require as much space as your SD card had, using 4GB (or 8, or 16 ?), and no way to extract to a smaller µSD card or you may loose data and get a broken filesystem.
  • and you will also copy any junk found on the SD card, as the empty space is not necessarily filled with zeroes, making a bigger image than required, even when compressed !!

The right way to do it is to use tar.

For each partition you need to backup, you must mount it on an empty directory, possibly with bind mount option, and then create an archive :

mntpoint=/mnt/tmp
mkdir ${mntpoint}
disk=mmcblk0  # Use the right disk name (sda, sdb, ... mmcblk1, ...)
partition=p1  # Use the right partition indicator (p1, p2, p3, ... for mmcblk* or simply 1, 2, 3, ... for sd*)
mount -o bind /dev/${disk}${partition} ${mntpoint}
cd ${mntpoint}
tar cjf /somewhere/else/backup_${disk}${partition}_$(date +%Y-%m-%d).tar.bz2 *
cd && umount ${mntpoint}

You can of course chose the backup image name according to your preferences, this is only an example, but the Archive file MUST be on another partition.
Alternatively you can combine tar and ssh to directly transfer the archive to your host system :