overlay文件系统切换为根文件系统

内核配置

CONFIG_OVERLAY_FS

配置后编译烧写,可见支持了overlay文件系统

/tmp # cat /proc/filesystems 
nodev	sysfs
nodev	rootfs
nodev	ramfs
nodev	bdev
nodev	proc
nodev	cgroup
nodev	tmpfs
nodev	devtmpfs
nodev	sockfs
nodev	pipefs
nodev	rpc_pipefs
nodev	devpts
	ext3
	ext2
	ext4
	cramfs
	squashfs
	vfat
	msdos
	iso9660
nodev	nfs
nodev	jffs2
	fuseblk
nodev	fuse
nodev	fusectl
nodev	overlay
	udf
	yaffs
	yaffs2
nodev	mtd_inodefs
nodev	ubifs

正常挂载 

/tmp # mount
rootfs on / type rootfs (rw)
/dev/root on / type squashfs (ro,relatime)
proc on /proc type proc (rw,nosuid,nodev,relatime)
sysfs on /sys type sysfs (rw,nosuid,nodev,relatime)
tmpfs on /dev type tmpfs (rw,relatime)
ramfs on /tmp type ramfs (rw,nosuid,nodev,relatime,mode=1777)
/dev/root on /mnt/conf type squashfs (ro,relatime)
devpts on /dev/pts type devpts (rw,relatime,mode=600)
/dev/mtdblock3 on /mnt/conf type jffs2 (rw,relatime)

挂载脚本

#!/bin/sh
  
mkdir -p /mnt/conf
mount -t jffs2 /dev/mtdblock3 /mnt/conf

mkdir -p /mnt/conf/base
mkdir -p /mnt/conf/work

mount -t overlay overlay -o lowerdir=/,upperdir=/mnt/conf/base,workdir=/mnt/conf/work /mnt

mount /proc -o move /mnt/proc
mkdir -p /mnt/rom
pivot_root /mnt /mnt/rom
mount /rom/dev -o move /dev
mount /rom/tmp -o move /tmp
mount /rom/sys -o move /sys
mount /rom/dev/pts -o move /dev/pts

挂载效果

/tmp # mount
rootfs on / type rootfs (rw)
/dev/root on /rom type squashfs (ro,relatime)
proc on /proc type proc (rw,nosuid,nodev,relatime)
sysfs on /sys type sysfs (rw,nosuid,nodev,relatime)
tmpfs on /dev type tmpfs (rw,relatime)
ramfs on /tmp type ramfs (rw,nosuid,nodev,relatime,mode=1777)
devpts on /dev/pts type devpts (rw,relatime,mode=600)
/dev/mtdblock3 on /rom/mnt/conf type jffs2 (rw,relatime)
overlay on / type overlay (rw,relatime,lowerdir=/,upperdir=/mnt/conf/base,workdir=/mnt/conf/work)
/tmp # df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root                 8.4M      8.4M         0 100% /rom
tmpfs                   123.8M      4.0K    123.8M   0% /dev
/dev/mtdblock3          512.0K    200.0K    312.0K  39% /rom/mnt/conf
overlay                 512.0K    200.0K    312.0K  39% /

 

你可能感兴趣的:(Linux)