Skip to main content

File system backup

After developing under the armsom product, it is necessary to package the current system environment. Here is a method for reference

1. Debian system backup

1.1 Operations on ArmSoM products

1.1.1 Installing SSH rsync

sudo apt-get install ssh
sudo apt-get install rsync

1.1.2 Set root user password

sudo passwd root

#If the current user is already the root user, they can run it directly
passwd

1.1.3 Set root login

PermitRootLogin is one of the configuration items for the sshd service, which determines whether root users are allowed to log in to the system through SSH. PermitRootLogin has the following values:

  1. yes:Allow root user to log in via SSH
  2. no:Prohibit root user from logging in through SSH
  3. without-password:Only root users who use public keys for authentication are allowed to log in via SSH
  4. forced-commands-only:Only root users who authenticate through forced commands (such as scp) are allowed to log in via SSH

Edit SSH configuration file to check the setting of the PermitRootLogin option. Ensure that root users are allowed to log in

vi /etc/ssh/sshd_config

The default is:
#PermitRootLogin prohibit-password
change to:
PermitRootLogin yes

After saving the file, restart the SSH service:

sudo systemctl restart sshd

1.1.4 Clear excess files from the system

When configuring the development board environment, there may be a lot of residual cache or temporary files. You can first clean up the space on the board

Firstly, use the command to view the usage of disk space

du -sh /*

Clean up temporary files and cache generated by the system

sudo rm -rf /tmp/*
sudo rm -rf /var/tmp/*
sudo rm -rf /var/cache/

If there is no requirement for firmware size in this step, it can also be ignored

1.2 Operation on Ubuntu host

1.2.1 Install SSH rsync

sudo apt-get install ssh
sudo apt-get install rsync

1.2.2 Synchronize development board files

Ping the development board to ensure communication between the Ubuntu host and the development board Next, create a directory on the Ubuntu host to store the exported development board file system

lhd@lhd:~/3576_rootfs_test$ mkdir rootfs

Use the following command to synchronize the file system on the RK3576 development board

sudo rsync -avx root@192.168.100.123:/ rootfs

Among them:

  • Root is the username for the development board
  • 192.168.100.123 is the IP address of the development board, which depends on the actual situation of the board
  • /:The root directory is the root directory of the development board
  • rootfs:This is the path to the rootfs folder created on the Ubuntu host

To perform this step, the root user is required, as mentioned earlier on how to configure the root user for SSH login

The synchronization process takes some time, and after executing the command, the file system of the development board can be synchronized to the Ubuntu host

1.2.3 Create an image file

First, use the dd command to create an empty image file

lhd@armsom:~/3576_rootfs_test$ dd if=/dev/zero of=rk3576_rootfs.img  bs=1M count=7168

其中:

  • /dev/zero:A special device file used to generate a file of a specified size with zero content
  • rk3576_rootfs.img:The image file to be created
  • bs=1M :Each block reads and writes 1M data
  • count=4096:Each block reads and writes 1M data

The actual size of the count here can be adjusted according to the system size of the development board

1.2.4 Format image file

Format the image file using the following command and add the Linux root volume label

sudo mkfs.ext4 -F -L linuxroot rk3576_rootfs.img

*This command will create an ext4 file system on the * rk3576urootfs. img file, which can be used to store data or as a disk image file。

1.2.5 Fill in image file

Mount the root file image and copy the modified file system into it. Use the following command to complete the operation:

mkdir rk3576_rootfs_mount
sudo mount rk3576_rootfs.img rk3576_rootfs_mount
sudo cp -rfp rootfs/* rk3576_rootfs_mount

After executing the previous command, it is necessary to uninstall the image

sudo umount rk3576_mount

1.2.6 Simplify image files

Check the integrity of the image file and reduce file size

lhd@armsom:~/3576_rootfs_test$ sudo e2fsck -p -f rk3576_rootfs.img
linuxroot: 97295/655360 文件(0.1% 不连续),1442978/2621440 块
lhd@armsom:~/3576_rootfs_test$ sudo resize2fs -M rk3576_rootfs.img
resize2fs 1.46.5 (30-Dec-2021)
将 rk3576_rootfs.img 上的文件系统调整为 1556652 个块(每块 4k)。
rk3576_rootfs.img 上的文件系统大小已经调整为 1556652 个块(每块 4k)。

Thus, a system image containing the complete original development board has been obtained

1.3 Deploy firmware

After obtaining the firmware, it is necessary to test it and deploy the firmware to re burn the root file system image to the development board for testing rkdevtool

1.Burn firmware for development boards without deployed applications

2.Power on the development board and put it into Loader mode. Use the Rockchip RKDevToolv3.28 burning tool, select the rootfs partition, click on the device partition table to confirm the partition location, and finally select the firmware as shown in the above figure

3.Enter the system to confirm if the previously deployed files exist

2. Armbian system backup

It is recommended to use the armbian-config tool to back up to an SD card. Armbian-config Backup

Follow the script below to generate a backup image:

#!/bin/bash

# The following operations are performed on the USB partition to avoid affecting local storage. The USB partition is mounted on/mnt

# Root partition type of GPT partition table
PARTITION_TYPE_UUID_ROOT="B921B045-1DF0-41C3-AF44-4C6F280D3FAE"

# Create an empty image
truncate --size=6500M sdcard.img

# Create a root partition starting from 16MiB
echo "1 : name=\"rootfs\", start=16MiB, type=${PARTITION_TYPE_UUID_ROOT}"|sfdisk --label gpt sdcard.img

# Create a loop device
losetup -fP ./sdcard.img

# Create root partition mount directory
mkdir -p rootfs_mount

# Create an ext4 partition
sudo mkfs.ext4 /dev/loop0p1

# Get root partition uuid
rootfs_uuid=$(blkid -s UUID -o value /dev/loop0p1)

# Mount root partition
sudo mount /dev/loop0p1 ./rootfs_mount/

# Transfer the local disk file rsync to the mounted root partition
sudo rsync -aHWh -X --exclude="/dev/*" --exclude="/proc/*" --exclude="/run/*" --exclude="/tmp/*" --exclude="/sys/*" --exclude="/mnt/*" --info=progress0,stats1 / ./rootfs_mount/

# Modify the root partition uuid in the kernel startup parameters
sudo sed -i "s|^rootdev=UUID.*$|rootdev=UUID=${rootfs_uuid}|g" ./rootfs_mount/boot/armbianEnv.txt

# Automatically resize partition size upon startup
sudo chroot ./rootfs_mount/ systemctl --no-reload enable armbian-resize-filesystem.service

# Synchronize disk write operations
sudo sync

# Uninstall root partition
sudo umount ./rootfs_mount

# Install uboot onto the loop image
source /usr/lib/u-boot/platform_install.sh
write_uboot_platform $DIR /dev/loop0

# Uninstall loop device
losetup -D

# The generated sdcard.img is the same as a normal Armbian image, and can be written to both EMMC and SD cards. After entering the system, you need to run the command sudo systemctl start Armbian-resite-filesystem.service to expand the partition to its normal size

Burn to SD card partition:

sudo dd if=./sdcard.img of=/dev/mmcblk1 bs=4M status=progress conv=sync