Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions build_debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ sudo chmod +x $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-premount/arista-
sudo cp files/initramfs-tools/resize-rootfs $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-premount/resize-rootfs
sudo chmod +x $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-premount/resize-rootfs

# Hook into initramfs: run fsck to repair a non-clean filesystem prior to be mounted
sudo cp files/initramfs-tools/fsck-rootfs $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-premount/fsck-rootfs
Copy link
Collaborator

@qiluo-msft qiluo-msft Apr 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fsck [](start = 101, length = 4)

How slow is the fsck? any impact on fast-reboot or warm-reboot?

If it is slow, can we only check and log, but expect user to repair it later? #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is no error on the filesystem (i.e not marked as dirty), the command execution is immediate, So, on a clean filesystem, there is no impact on either fast-reboot or warm-reboot.
But if the filesystem is marked as dirty, there is no guarantee that the filesystem can be mounted as R/W. Or worse, if it still mounted, some files can be truncated or corrupted. Therefore, we strongly advise to repair a filesystem marked as dirty to avoid potential issues later on.

sudo chmod +x $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-premount/fsck-rootfs

## Hook into initramfs: after partition mount and loop file mount
## 1. Prepare layered file system
## 2. Bind-mount docker working directory (docker overlay storage cannot work over overlay rootfs)
Expand Down
6 changes: 6 additions & 0 deletions files/image_config/platform/rc.local
Original file line number Diff line number Diff line change
Expand Up @@ -340,4 +340,10 @@ if [ -f $FIRST_BOOT_FILE ]; then
firsttime_exit
fi

# Copy the fsck log into syslog
Copy link
Collaborator

@qiluo-msft qiluo-msft Apr 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy [](start = 2, length = 4)

Why copy to syslog? #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syslog being the unified way of seeing system messages, we thought that its was more appropriate to hold the fsck log messages instead of a compressed file under the /var/log directory

if [ -f /var/log/fsck.log.gz ]; then
gunzip -d -c /var/log/fsck.log.gz | logger -t "FSCK"
rm -f /var/log/fsck.log.gz
fi

exit 0
34 changes: 34 additions & 0 deletions files/initramfs-tools/fsck-rootfs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/sh

case $1 in
prereqs)
exit 0
;;
esac

# Extract kernel parameters
root_val=""
set -- $(cat /proc/cmdline)
for x in "$@"; do
case "$x" in
root=*)
root_val="${x#root=}"
;;
esac
done

# Check the filesystem we are using
if [ ! -z $root_val ]; then
fstype=$(blkid -o value -s TYPE $root_val)
case "$fstype" in
ext4)
cmd="fsck.ext4 -v -p"
;;
ext3)
cmd="fsck.ext3 -v -p"
;;
esac
if [ ! -z "$cmd" ]; then
$cmd $root_val 2>&1 | gzip -c > /tmp/fsck.log.gz
fi
fi
7 changes: 7 additions & 0 deletions files/initramfs-tools/union-mount.j2
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,12 @@ then
mount -t tmpfs -o rw,nosuid,nodev,size=${varlogsize}M tmpfs ${rootmnt}/var/log
[ -f ${rootmnt}/host/disk-img/var-log.ext4 ] && rm -rf ${rootmnt}/host/disk-img/var-log.ext4
else
[ -f ${rootmnt}/host/disk-img/var-log.ext4 ] && fsck.ext4 -v -p ${rootmnt}/host/disk-img/var-log.ext4 2>&1 \
Copy link
Collaborator

@qiluo-msft qiluo-msft Apr 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fsck.ext4 [](start = 50, length = 9)

Is there an option -y to prevent interactive prompt? #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The -p option that we use here will prevent interactive prompt.
The "-p" option as documented in fsck.ext3 and fsck.ext4 :
-p Automatic repair (no questions)

| gzip -c >> /tmp/fsck.log.gz
Copy link
Collaborator

@qiluo-msft qiluo-msft Apr 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/tmp/fsck.log.gz [](start = 60, length = 19)

Why append instead of overwrite? #Closed

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you only gzip 2 files, use 2 names and mv twice.


In reply to: 409184727 [](ancestors = 409184727)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are actually two ext3/ext4 filesystems that need to be checked:

  1. the root filesystem mounted on the hard-drive or ssd, defined as root=X in /proc/cmdline
    (this is done early from initrd by script fsck-rootfs)
  2. the log filesystem, which is stored in an ext4 file [host/disk-img/var-log.ext4]
    This is why we use one file, and we append to this file when the log fileystem is checked.

[ -f ${rootmnt}/host/disk-img/var-log.ext4 ] && mount -t ext4 -o loop,rw ${rootmnt}/host/disk-img/var-log.ext4 ${rootmnt}/var/log
fi

## fscklog file: /tmp will be lost when overlayfs is mounted
if [ -f /tmp/fsck.log.gz ]; then
Copy link
Collaborator

@qiluo-msft qiluo-msft Apr 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only need to mv inside above else block. #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we leave here?
if running fsck is later added to arista platforms, the test will need to be done.

mv /tmp/fsck.log.gz ${rootmnt}/var/log
fi