Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
24 changes: 21 additions & 3 deletions files/initramfs-tools/union-mount.j2
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,22 @@ case $1 in
;;
esac

# Extract kernel parameters
set -- $(cat /proc/cmdline)
for x in "$@"; do
case "$x" in
loop=*)
image_dir=`echo $x | sed -e 's/.*loop=\(\S*\)\/.*/\1/'`
;;
varlog_size=*)
varlog_size="${x#varlog_size=}"
;;
*mmc_host*)
eMMC=1
esac
done

## Mount the overlay file system: rw layer over squashfs
image_dir=$(cat /proc/cmdline | sed -e 's/.*loop=\(\S*\)\/.*/\1/')
mkdir -p ${rootmnt}/host/$image_dir/rw
mkdir -p ${rootmnt}/host/$image_dir/work
mount -n -o lowerdir=${rootmnt},upperdir=${rootmnt}/host/$image_dir/rw,workdir=${rootmnt}/host/$image_dir/work -t overlay root-overlay ${rootmnt}
Expand All @@ -26,5 +40,9 @@ mount --bind ${rootmnt}/host/$image_dir/{{ DOCKERFS_DIR }} ${rootmnt}/var/lib/do
## Mount the boot directory in the raw partition, bypass the overlay
mkdir -p ${rootmnt}/boot
mount --bind ${rootmnt}/host/$image_dir/boot ${rootmnt}/boot
## Mount loop device for /var/log
[ -f ${rootmnt}/host/disk-img/var-log.ext4 ] && mount -t ext4 -o loop,rw ${rootmnt}/host/disk-img/var-log.ext4 ${rootmnt}/var/log
## Mount loop device for /var/log or a tmpfs device if the flash is eMMC
if [ -z ${eMMC+1} ]; then
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What is the purpose of the "+1" here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I originaly left it out but got pointed to https://stackoverflow.com/questions/3601515/how-to-check-if-a-variable-is-set-in-bash where it is stated that its a safer check

[ -f ${rootmnt}/host/disk-img/var-log.ext4 ] && mount -t ext4 -o loop,rw ${rootmnt}/host/disk-img/var-log.ext4 ${rootmnt}/var/log
else
mount -t tmpfs -o size=${varlog_size}M,mode=0755 tmpfs ${rootmnt}/var/log
fi
9 changes: 7 additions & 2 deletions files/initramfs-tools/varlog
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ for x in "$@"; do
case "$x" in
varlog_size=*)
varlog_size="${x#varlog_size=}"
;;
*mmc_host*)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So this change depends on a "mmc_host" kernel command line parameter. I agree with your description that this is a crude check. Is there a way for a vendor to override this for their platform (or for an end-user building an image, for that matter) in the case it is not desired? What is populating the "mmc_host" kernel command line parameter?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

On my device the actual kernel command line parameter is:
block_flash=pci0000:00/0000:00:14.7/mmc_host/.*$
instead of looking for block_flash I'm looking for an actual MMC discriminator hence the *mmc_host*
again this may need more research to find a robust way of detecting that the image depends on flash and its not just a usb key with a eMMC component that is inserted and not used
Of all the platforms I have in my lab ( 6+ ) this is the only one I have found this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

as for your question on overriding: maybe introduce a rules/config variable and check on that?
our vendor's recommendation for this change makes it clear that there is a real danger for the longevity of the switch if the default behavior is left as-is

eMMC=1
esac
done

Expand All @@ -32,5 +35,7 @@ if [ -e "${rootmnt}/host/disk-img/var-log.ext4" ]; then
fi
fi

# create varlog disk
mkdir -p ${rootmnt}/host/disk-img && ${rootmnt}/usr/bin/fallocate -l "$varlog_size"M ${rootmnt}/host/disk-img/var-log.ext4 && mkfs.ext4 -q -F ${rootmnt}/host/disk-img/var-log.ext4
# create varlog disk only if we are not running eMMC flash
if [ -z ${eMMC+1} ]; then
mkdir -p ${rootmnt}/host/disk-img && ${rootmnt}/usr/bin/fallocate -l "$varlog_size"M ${rootmnt}/host/disk-img/var-log.ext4 && mkfs.ext4 -q -F ${rootmnt}/host/disk-img/var-log.ext4
fi