SD card contents disappear when unionfs-fuse is introduced in raspberry pi

Asked 2 years ago, Updated 2 years ago, 121 views

Raspberry pi3 wants to power down easily.
We introduced unionfs-fuse.
The installation and configuration have been completed with reference to several sites. Once shut down, it won't start. When I checked the contents of the SD card, all the files were empty.

Implemented as follows:

You have previously configured swap, log, etc. to move to RAM disk.

Package Deployment

$sudo apt-get install unionfs-fuse

Copy Configuration Files

$sudocp/usr/share/doc/unionfs-fuse/examples/S01a-unionfs-fuse-live-cd.sh/etc/init.d/a-unionfs-fuse-live-cd
$ sudo cp/usr/share/doc/unionfs-fuse/examples/rc.local.omit-pid.sh/usr/local/sbin/a-unionfs-fuse-omit-pid.sh 

Edit /etc/init.d/a-unionfs-fuse-live-cd

#!/bin/sh
### BEGIN INIT INFO
# Provides —a-unionfs-fuse-live-cd
# Required-Start: mountall-bootclean
# Required-Stop:
# Default-Start: S
# Default-Stop:
# X-Start-Before:procpsudev-mtab urandom
# Short-Description:UnionFS mode
# Description—Shutdown process will not be required
### END INIT INFO
# Copyright: Bernd Schubert <[email protected] >
# BSD license, see LICENSE file for details
FUSE_OPT="-o allow_other, use_ino, suid, dev, noneempty"
CHROOT_PATH="/tmp/unionfs"
UNION_OPT="-ocow, chroot=$CHROOT_PATH, max_files=32768"
UBIN=/usr/bin/unionfs-fuse
cd/boot
file=noprotect
if [-e${file}]; then
        echo "${file} exists"
    exit0
fi
mount-oremount, ro/dev/mmcblk0p1/boot
mount-t proc proc / proc
mount-tmpfs tmpfs /tmp
mkdir-p$CHROOT_PATH/root
mkdir-p$CHROOT_PATH/rw
mkdir-p/tmp/union
mount -- bind/$CHROOT_PATH/root
$UBIN$FUSE_OPT$UNION_OPT/rw=RW:/root=RO/tmp/union
mount-t proc proc proc / tmp / union / proc
cd/tmp/union
mkdir oldroot
pivot_root.oldroot
mount-o remote, ro/dev/root/oldroot
for in dev run run / lock sys run / shm dev / pts boot
do
mount -- bind/oldroot/$d/$d
done
init q
/usr/local/sbin/a-unionfs-fuse-omit-pid.sh
exit0

Register Script

$sudo update-rc.da-unionfs-fuse-live-cd defaults 

Scripting for Switching

  • $sudo vim/usr/local/bin/noprotect

    #!/bin/sh
    mount-or-ow, remove/boot
    cd/boot
    if [-e "protect"; then
        rm/boot/protect
    fi
    if [-e "noprotect"; then
        echo "noprotect mode"
    else
        touch/boot/noprotect
        echo "noprotect mode"
    fi
    mount-oro,remount/boot
    
  • $sudovim/usr/local/bin/protect

    #!/bin/sh
    mount-or-ow, remove/boot
    cd/boot
    if [-e "noprotect"; then
       rm/boot/noprotect
    fi
    if [-e "protect"; then
       echo "protect mode"
    else
       touch/boot/protect
       echo "protect mode"
    fi
    mount-oro,remount/boot
    

$sudovim/usr/local/bin/noprotect

#!/bin/sh
mount-or-ow, remove/boot
cd/boot
if [-e "protect"; then
    rm/boot/protect
fi
if [-e "noprotect"; then
    echo "noprotect mode"
else
    touch/boot/noprotect
    echo "noprotect mode"
fi
mount-oro,remount/boot

$sudovim/usr/local/bin/protect

#!/bin/sh
mount-or-ow, remove/boot
cd/boot
if [-e "noprotect"; then
   rm/boot/noprotect
fi
if [-e "protect"; then
   echo "protect mode"
else
   touch/boot/protect
   echo "protect mode"
fi
mount-oro,remount/boot

Grant execution permission

$sudo chmod a+x/usr/local/bin/noprotect   
$ sudo chmod a+x/usr/local/bin/protect

US>Reboot
Unionfs-fuse takes longer to boot than before, but
Boot successfully.

If you shut down or power down, and then look inside the SD card, all the files are gone.

If you know the solution, please take care of it.

raspberry-pi

2022-09-30 21:18

2 Answers

I encountered the same symptom.
In conclusion, there is a difference between the latest rasbian image as of March 4, 2017 and the information on the unionfs deployment site, so I think unionfs cannot be deployed as it is.
I also looked for a solution, but when the time ran out, I took care of ROMing by rebuilding the kernel with aufs.
Here are the details:

  • Target Raspi Image
    2017-01-11-raspbian-jessie.img
  • Workday
    March 2, 2017 - March 3, 2017
  • Symptoms
    Deployed unionfs for reference to other sites just like the questioner.You can reboot for the first time, but not for the second time.

The part I looked up.

  • In RAMDISK, /tmp is set to tmpfs, and I thought it might be bad, so I stopped.Also, I found parts such as /dev/shm that do not follow the current Rasbian image, so I made minor corrections.You can reboot repeatedly, but unionfs does not seem to work at all.
  • When I run the commands in the script one by one with root privileges, I get the error that the parameters are different in the pivot_root instruction.We have determined that the reason for the failure to reboot is probably because the root system change is not working.
  • In the meantime, the Raspi actual machine succeeded in building a kernel containing aufs, so the investigation was terminated.

That's all.


2022-09-30 21:18

I became interested in the questioner's question, so
I tried installing it on archlinuxarm instead of raspbian

Install unionfs-fuse first, and

pacman-Sunionfs-fuse

Create two configuration files,

/usr/lib/initcpio/install/unionfs:

#!/bin/bash

build(){
    add_binary"/usr/bin/unionfs"
    add_binary"/usr/bin/unionfsctl"
    add_module "fuse"

    add_runscript
}

help(){
    cat<<HELPEOF
This hook uses unionfs.
HELPEOF
}

# vim: set ft=shts=4sw=4et:

/usr/lib/initcpio/hooks/unionfs:

#!/usr/bin/ash

unionfs_mount_handler(){
    cd/tmp
    mkdir-punionfs/root
    mount-oro $root unionfs/root

    mkdir-p/boot
    mount -- fstab unionfs/root/etc/fstab-oro/boot
    noprotect = 0
    [-e/boot/noprotect] & noprotect = 1
    umount/boot

    umount unionfs/root
    rmdir-punionfs/root
    cd/

    if [$noprotect=1]; then
        default_mount_handler $1
        return
    fi

    cd/tmp
    mkdir-punionfs/root
    mkdir-punionfs/rw
    mount-oro $root unionfs/root
    mount-tmpfs none unionfs/rw
    unionfs-o allow_other, use_ino, suid, dev, noneempty-ocow, chroot=/tmp/unionfs/rw=RW:/root=RO$1
}

run_hook(){
    mount_handler = unionfs_mount_handler
}

Configure /etc/mkinitcpio.conf to load the above and

HOOKS="baseudev autodetect modconf block filesystems keyboard fsck unionfs"

Initramfs image has been created.

 mkinitcpio-p linux-raspberrypi

It seems to be moving in general.No matter how many times I reboot, there is no problem.
However, in Denbndb's answer, there was an error in pivot_root, but
US>archlinuxarm uses the command switch_root instead and
Maybe this difference is why I'm doing well in my environment.

When it didn't work well, we did the following research.It's a prerequisite that shell works.

    Try
  • exit.Init may die and panic, but that's an experience.
  • If you can't find ls while trying to run ls, try echo* instead.
  • Try
  • mount-t proc proc proc /proc.
    You will be able to see the mount situation and use the ps command.
  • If you know the PID of unionfs-fuse and can use /proc,
    cd/proc/PID/cwd allows you to navigate to the unionfs-fuse current directory.
    In other words, even after pivot_root, you can still see the filesystem that unionfs-fuse is looking at.

In the first place, raspbian and archlinuxarm seem to be very different, so
I wrote it as an answer in order to be helpful to some extent.


2022-09-30 21:18

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.