Difference between revisions of "How to use overlayfs on Linux"
(updated by API) |
(updated by API) |
||
Line 8: | Line 8: | ||
==FriendlyELEC's Systems That Support OverlayFS== | ==FriendlyELEC's Systems That Support OverlayFS== | ||
===Hardware Systems=== | ===Hardware Systems=== | ||
− | H3, H5, S5P4418, S5P6818, RK3399 based boards | + | H3, H5, S5P4418, S5P6818, RK3399, RK3328, RK3568, RK3588 based boards |
===OS Systems=== | ===OS Systems=== | ||
− | + | All Linux-based systems | |
− | + | ===Scope of Application=== | |
+ | This document is only applicable to products using Rockchip platform. If you are using other platforms, please click on this link: [[How to use overlayfs on S5Pxxxx,H3,H5 platform]] | ||
==How to Check Whether OverlayFS Is Working== | ==How to Check Whether OverlayFS Is Working== | ||
Run the df command. If the "/" partition is mounted as "overlay" it means OverlayFS is working; | Run the df command. If the "/" partition is mounted as "overlay" it means OverlayFS is working; | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | pi@NanoPi- | + | pi@NanoPi-R6C:/etc$ df -h |
− | Filesystem | + | Filesystem Size Used Avail Use% Mounted on |
− | + | tmpfs 792M 2.2M 790M 1% /run | |
− | tmpfs | + | overlay 25G 13G 11G 53% / |
− | overlay | + | tmpfs 3.9G 0 3.9G 0% /dev/shm |
− | tmpfs | + | tmpfs 5.0M 4.0K 5.0M 1% /run/lock |
− | tmpfs | + | tmpfs 793M 116K 793M 1% /run/user/1000 |
− | tmpfs | + | |
− | + | ||
− | + | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 30: | Line 28: | ||
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: | 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: | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | + | pi@NanoPi-R6C:/etc$ sudo apt install parted | |
− | + | pi@NanoPi-R6C:/etc$ sudo parted /dev/mmcblk0 print | |
− | mmcblk0 | + | Model: SD SR32G (sd/mmc) |
− | + | Disk /dev/mmcblk0: 31.9GB | |
− | + | Sector size (logical/physical): 512B/512B | |
− | + | Partition Table: gpt | |
+ | Disk Flags: | ||
+ | |||
+ | Number Start End Size File system Name Flags | ||
+ | 1 8389kB 12.6MB 4194kB uboot | ||
+ | 2 12.6MB 16.8MB 4194kB misc | ||
+ | 3 16.8MB 21.0MB 4194kB dtbo | ||
+ | 4 21.0MB 37.7MB 16.8MB resource | ||
+ | 5 37.7MB 79.7MB 41.9MB kernel | ||
+ | 6 79.7MB 113MB 33.6MB boot | ||
+ | 7 113MB 147MB 33.6MB recovery | ||
+ | 8 147MB 4173MB 4027MB ext4 rootfs | ||
+ | 9 4173MB 31.9GB 27.7GB ext4 userdata | ||
</syntaxhighlight> | </syntaxhighlight> | ||
The system data will be in the rootfs partition and the data written to the root directory will be in the data partition. | The system data will be in the rootfs partition and the data written to the root directory will be in the data partition. |
Revision as of 11:46, 17 March 2023
Contents
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, RK3328, RK3568, RK3588 based boards
2.2 OS Systems
All Linux-based systems
2.3 Scope of Application
This document is only applicable to products using Rockchip platform. If you are using other platforms, please click on this link: How to use overlayfs on S5Pxxxx,H3,H5 platform
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-R6C:/etc$ df -h Filesystem Size Used Avail Use% Mounted on tmpfs 792M 2.2M 790M 1% /run overlay 25G 13G 11G 53% / tmpfs 3.9G 0 3.9G 0% /dev/shm tmpfs 5.0M 4.0K 5.0M 1% /run/lock tmpfs 793M 116K 793M 1% /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:
pi@NanoPi-R6C:/etc$ sudo apt install parted pi@NanoPi-R6C:/etc$ sudo parted /dev/mmcblk0 print Model: SD SR32G (sd/mmc) Disk /dev/mmcblk0: 31.9GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 8389kB 12.6MB 4194kB uboot 2 12.6MB 16.8MB 4194kB misc 3 16.8MB 21.0MB 4194kB dtbo 4 21.0MB 37.7MB 16.8MB resource 5 37.7MB 79.7MB 41.9MB kernel 6 79.7MB 113MB 33.6MB boot 7 113MB 147MB 33.6MB recovery 8 147MB 4173MB 4027MB ext4 rootfs 9 4173MB 31.9GB 27.7GB ext4 userdata
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.