Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

preinit-mounts: Add check for overlay file errors #59

Merged
merged 1 commit into from
Oct 23, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 33 additions & 3 deletions meta-phosphor/recipes-phosphor/preinit-mounts/preinit-mounts/init
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/bin/sh

mount_overlay() {
if ! mount overlay /etc -t overlay -o defaults,lowerdir=/etc,upperdir=/var/persist/etc,workdir=/var/persist/etc-work; then
mount overlay /etc -t overlay -o defaults,lowerdir=/etc:/var/persist/etc
fi
}

if ! mount ubi0:rwfs /var -t ubifs -o defaults; then
if ! mount ubi0:rwfs /var -t ubifs -o defaults,ro; then
mount tmpfs /var -t tmpfs -o defaults
Expand All @@ -12,8 +18,32 @@ rm -rf /var/persist/etc-work/*
# rm -rf specifically skips . and .. directories; pipe all output to null to avoid the error message
rm -rf /var/persist/etc-work/.* > /dev/null 2>&1

if ! mount overlay /etc -t overlay -o defaults,lowerdir=/etc,upperdir=/var/persist/etc,workdir=/var/persist/etc-work; then
mount overlay /etc -t overlay -o defaults,lowerdir=/etc:/var/persist/etc
fi
mount_overlay

# Check if there are any issues accessing the files in /etc after mounting the
# overlay by doing an 'ls' command
error="/var/overlay-error"
cd /var/persist/etc/
for i in *; do
# Only check regular files at the top of the directory
if [[ -f $i ]]; then
ls -i /etc/$i >/dev/null 2>${error};
if [[ -s ${error} ]]; then
# We don't have a way to print this error to the journal, delete it
rm -f ${error}
# Attempt to re-create the overlay by moving out the overlay contents and
# copying them back to /etc, which would create them back in the overlay
cd
umount /etc
rm -rf /var/persist/etc-save
mv /var/persist/etc /var/persist/etc-save
mkdir -p /var/persist/etc
mount_overlay
cp -rp /var/persist/etc-save/* /etc/
rm -rf /var/persist/etc-save
break
fi
fi
done

exec /lib/systemd/systemd