Armbian OS – Backing up eMMC/NAND (Via CLI)

Backing up if you are using eMMC/NAND for booting/running Armbian OS

These instructions are for those whom are running Armbian from an internal eMMC storage and wish to make a backup image. If you are wanting to make an image of a SD Card/USB stick, then please look at this document here.

Because of the length of some of the commands used in this process, I would suggest either opening this page on your TV box when performing this OR use Microsoft Remote Desktop (RDP)/VNC from another machine with this open, where you can copy/paste the text over. 

UNIX commands are CAPS specific, so must be typed exactly as shown, because “command“, “COMMAND” and “CoMManD” would try to run 3 different programs, not the same one like Windows would (which is why I suggest you copy/paste commands out of this document).

You will need the following to do this

Option A – (Perform ALL steps below) Either a blank SD card with enough space to make a copy of your eMMC/NAND Armbian installation AND your original Armbian image file you used that matches what you have installed on your eMMC/NAND.

Option B – (Perform Step 3 onwards from Below) Your original, still imaged Armbian SD card with enough space to make a copy of your eMMC/NAND Armbian installation.

So if you have 18GB of data on your eMMC/NAND, you would need a 32GB or larger SD card.

Performing the backup (Command Line BASED)

1) With your Backup SD card, complete steps 1 to 8 of the Armbian Installation, using your original Armbian Image file that matches your Armbian version installed on your eMMC/NAND.

2) When thats completed, edit your uEnv.ini and extlinux.conf files to use the correct DTB file for the TV box you will use this card in as detailed here.

3) Log into your Armbian TV box as the root account. 

This is CRITICAL for the instructions I am giving you to work and allowing me to keep the instructions simple.

4) Put your Backup SD card into your booted/running Armbian TV box.

5) You should see BOOT and ROOTFS appear on your desktop. In the BOOT volume, delete the “System Volume Information” folder thats been created by Windows, as per the instructions here.

6) Install the utility called parted (as this will make things 10000% simpler) and make your mount directory.

sudo apt-get install parted
mkdir -p /media/root/ROOTFS

7) We now need to identify the correct name of your SD card (or other device) where the ROOTFS partition is stored.

lsblk -o NAME,FSTYPE,LABEL,SIZE,MOUNTPOINT

In the example I am about to show you, my SD card is called mmcblk0 and my ROOTFS partition is called mmcblk0p2

8) Now we have those names, we need to run the parted utility and type a few commands into it. In the Terminal type

parted

This starts the parted utility and the next 3 commands will be typed in it.

select /dev/mmcblk0

Replace mmcblk0 with the name of your SD card as we identified back in step 2 of this manual process.

resizepart 2 100%
quit

ROOTFS should always be partition 2… as in you should see mmcblk0p1 being BOOT and mmcblk0p2 being the ROOTFS partition.

9) Now we need to re-probe the partitions so the kernel is updated. Format our partition and we can re-check that things have been resized.

partprobe
mkfs.ext4 /dev/mmcblk0p2 -L ROOTFS

Replace mmcblk0p2 with the name of your ROOTFS partition we identified back in step 2.

lsblk -o NAME,FSTYPE,LABEL,SIZE,MOUNTPOINT

You should be able to see that the ROOTFS partition is larger now.

10) Mount the partition.

mount /dev/mmcblk0p2 /media/root/ROOTFS

Replace mmcblk0p2 with the name of your ROOTFS partition we identified back in step 2.

11) Its possible that you might now end up with 2 mount points in the /media folder, under the name of root (/media/root/ROOTFS and /media/root/ROOTFS1), because its detecting the newly formatted partition as an entirely new partition separate to the one it had mounted prior. With your Backup SD card in your box, you can browse over to /media/root/ to look inside that folder and check if you have two ROOTFS mount points. If this has occurred, physically eject your Backup SD card from your Box and type:

cd /media

Make sure you have moved into this folder before you run the next command, or you may delete a system folder.

rm -rf root

This will delete all your root user account’s mount points if you have any, which is very unlikely, but if you have created some, I assume you know how to clear this area down.

After this, you can put the Backup SD card back in your TV Box.

12) Enter the following command and wait for it to complete:

rsync -arlthD --info=progress2 --delete --exclude={/boot/*,/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found,*thinclient_drives} / /media/root/ROOTFS/

13) Enter the same command AGAIN and wait for it to complete (it should be quick this time, like 1 minute or less):

rsync -arlthD --info=progress2 --delete --exclude={/boot/*,/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found,*thinclient_drives} / /media/root/ROOTFS/

14) In the terminal window, type the following to edit the FSTAB file.

nano /media/root/ROOTFS/etc/fstab
Make sure you DONT edit your emmc/NAND’s fstab, or your system wont boot until you edit it back (this is why we are using the # for those lines).
DONT FORGET, UNIX IS CASE SenSITive….. SO MAKE SURE YOU TYPE THE FSTAB LINES BACK INTO THE FILE AS I SHOWN HERE) OR COPY/PASTE THEM IN THE TERMINAL WINDOW OF YOUR CHOICE FROM ANOTHER MACHINE.

15) Change the following in the fstab file and save it. You will have 3 lines you want to comment out with a hash # 

/dev/root............................
tmpfs................................
LABEL=BOOT_EMMC......................

to

#/dev/root...........................
#tmpfs...............................
#LABEL=BOOT_EMMC.....................

And you will want to copy the below in.

LABEL=ROOTFS / ext4 defaults,noatime,nodiratime,commit=600,errors=remount-ro 0 1
LABEL=BOOT /boot vfat defaults 0 2
tmpfs /tmp tmpfs defaults,nosuid 0 0

These are important, without them, you may just end up with a black screen on boot. You can always boot to the emmc and re-edit this on the /media/root/ROOTFS/etc/fstab 

If you dont change these, the automated routine to copy the SD card to eMMC/NAND will not work properly, should you ever use it in the future.

19) Make the changes you need, exit NANO and unmount the partition

umount /dev/mmcblk0p2 -l

20) Log out as the root user OR shut down your system 

Your Backup SD card is now ready and you can boot from it on whatever system you have configured the DTB files for. Just remember to not leave it in your TV Box it it will boot from that and not your eMMC/NAND.

How can I confirm Ive booted from my Backup SD card?

The mounted/mountable drives on your desktop will be labeled BOOT_EMMC and ROOT_EMMC when you are booting from your SD card, and called BOOT and ROOTFS when you are booting from your eMMC/NAND.

What have we actually just done?

This process will copy your emmc/NAND Armbian OS over the destination Backup SD card’s partition. On the Backup SD card, it will delete, create, update files with permissions etc, as needed until you have a copy of what is on your eMMC/NAND. So in effect, you will have a 1-2-1 copy of the operating system on your eMMC/NAND, just without the BOOT partition, which we created by imaging the SD card in the first place.

What can I do with my imaged SD card?

This Backup SD card used on your current system or a new destination system (if you have changed the DTB files to the correct ones).

Can I use either of the above processes to copy my Armbian installation over to an SSD for booting on the USB 3 port of my system?

Yes, these processes can be used for that purpose.

Armbian Tech Guides

Read Previous

Armbian OS – Backing up eMMC/NAND (Via GUI)

Read Next

Armbian OS/Ubuntu – Remote Management/Access

avatar
500
error: Content is protected !!