Difference between revisions of "How to use overlayfs on Linux"

From FriendlyELEC WiKi
Jump to: navigation, search
(updated by API)
(updated by API)
Line 72: Line 72:
 
The next time you boot to the ramdisk stage, the data partition will be formatted, and the /var/.init_wipedata file will also be deleted.
 
The next time you boot to the ramdisk stage, the data partition will be formatted, and the /var/.init_wipedata file will also be deleted.
 
====H3/H5 platform====
 
====H3/H5 platform====
=====chnage boot.cmd=====
+
=====change boot.cmd=====
 
Enter the boot directory and modify file boot.cmd, change the following:
 
Enter the boot directory and modify file boot.cmd, change the following:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">

Revision as of 05:13, 19 May 2022

查看中文

1 What Is OverlayFS

OverlayFS is a union mount filesystem implementation for Linux. It allows a virtual merge of two partitions, while keeping their actual contents separate. One partition is the rootfs partition and the other is the data partition. It has the following advantages:
1) you can easily restore a system's factory settings by formatting the data partition;
2) you can still boot your system since the rootfs is read-only even when the data partition cannot be correctly mounted due to unexpected shutdown.

2 FriendlyELEC's Systems That Support OverlayFS

2.1 Hardware Systems

H3, H5, S5P4418, S5P6818, RK3399 based boards

2.2 OS Systems

FriendlyCore, FriendlyDesktop, Lubuntu

3 How to Check Whether OverlayFS Is Working

Run the df command. If the "/" partition is mounted as "overlay" it means OverlayFS is working;

pi@NanoPi-M1-Plus:~$ df
Filesystem     1K-blocks    Used Available Use% Mounted on
udev              474848       0    474848   0% /dev
tmpfs             102304    3564     98740   4% /run
overlay         28925547 1315493  26112465   5% /
tmpfs             511512       0    511512   0% /dev/shm
tmpfs               5120       4      5116   1% /run/lock
tmpfs             511512       0    511512   0% /sys/fs/cgroup
/dev/mmcblk0p1     40862   11852     29010  30% /boot
tmpfs             102304       0    102304   0% /run/user/1000

4 Partition Settings With OverlayFS

If OverlayFS is enabled in your system there will be three partitions:rootfs, data and boot, and these partitions correspond to a rootfs.img, a userdata.img and a boot.img separately:

root@NanoPi-M1-Plus:~# lsblk /dev/mmcblk0
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
mmcblk0     179:0    0 29.7G  0 disk
|-mmcblk0p2 179:2    0  1.2G  0 part
|-mmcblk0p3 179:3    0 28.5G  0 part
`-mmcblk0p1 179:1    0   40M  0 part /boot

The system data will be in the rootfs partition and the data written to the root directory will be in the data partition.

5 Restore Factory Settings With OverlayFS

5.1 Method 1: Operate in Userdata Partition

factory reset:

mount /dev/mmcblk0p3 /media/ && cd /media/
mv root/ deleteme.root
mv work/ deleteme.work
reboot

cleanup after reboot:

mount /dev/mmcblk0p3 /media/ && rm -rf /media/deleteme.*

5.2 Method 2: Restore by Setting Commandline Parameters

5.3 S5P4418 & S5P6818 platform

Add "wipedata=yes" to the kernel's commandline parameters. For S5P4418 and S5P6818 based boards you can do it after system boots;

5.3.1 恢复出厂设置

sudo fw_setenv bootargs "`sed 's/ wipedata=yes//g;s/ wipedata=no//g' /proc/cmdline` wipedata=yes"
sudo reboot

5.3.2 Keep Data in Data Partition on System Reboot

sudo fw_setenv bootargs "`sed 's/ wipedata=yes//g;s/ wipedata=no//g' /proc/cmdline` wipedata=no"
sudo reboot

For other SoC based boards you need to make changes in the kernel commandline by following the methods supported by their BSPs or by entering uboot to proceed.

5.3.3 RK3399 platform

echo wipedata=yes > /var/.init_wipedata; sync; reboot

The next time you boot to the ramdisk stage, the data partition will be formatted, and the /var/.init_wipedata file will also be deleted.

5.3.4 H3/H5 platform

5.3.4.1 change boot.cmd

Enter the boot directory and modify file boot.cmd, change the following:

setenv bootargs "console=${debug_port} earlyprintk
root=/dev/mmcblk0p2 rootfstype=ext4 rw rootwait fsck.repair=${fsck.repair}
panic=10 fbcon=${fbcon} ${hdmi_res} ${overlayfs} ${pmdown}"

to:

setenv bootargs "console=${debug_port} earlyprintk
root=/dev/mmcblk0p2 rootfstype=ext4 rw rootwait fsck.repair=${fsck.repair}
panic=10 fbcon=${fbcon} ${hdmi_res} ${overlayfs} ${pmdown} wipedata=yes"

Added wipedata=yes.

5.3.4.2 regenerate boot.scr

Enter the boot directory,execute the following command:

$ mkimage -C none -A arm -T script -d boot.cmd boot.scr

6 Disable OverlayFS

If you have an installation TF card, use the fdisk command to delete the data partition.