If using systemd in initramfs, we could run into a race condition when
dracut and systemd both are trying to mount and run fsck for the same
filesystem, and mount or fsck could be a failure.
To fix such failure, we should use systemd to mount/fsck from /etc/fstab
only.
v2: check $DRACUT_SYSTEMD suggested by Alexander Tsoy
Signed-off-by: WANG Chao <chaowang@redhat.com>
also fixup the logic what and when to mount.
first initramfs/etc/fstab is mounted
$NEWROOT/etc/fstab.sys takes precendence over initramfs/etc/fstab.sys
fstab-sys now also handles device passed by dracut argument "--mount"
The "--mount" mount point is possible not exist in $NEWROOT. Thus mount it
in initramfs if mount point is not exist in real rootfs
--add-fstab [FILE] Add file to the initramfs fstab
--mount "[DEV] [MP] [FSTYPE] [FSOPTS]"
Mount device [DEV] on mountpoint [MP] with filesystem
[FSTYPE] and options [FSOPTS] in the initramfs
To not pollute dracut-lib.sh, all the fsck related functions were moved
to fs-lib.sh. The functions available are as follows:
- fsck_single
this will detect/verify filesystem, check if it has necessary tools and
check the filesystem respecting additional flags (if any), using
specific "driver" (or falling back to generic one). Currently
available: fsck_drv_{com,xfs,std}. 'com' is used for tools following
typical subset of options/return codes (e.g. ext, jfs), 'std' is used
for "unknown" fs and doesn't assume it can be run non-interactively.
Please see comments around the code for more info.
- fsck_batch
this will check provided list of the devices;
Both of the above functions will fake empty fstab, to make generic fsck
not complain too much (excact devices are always provided on the command
line).
"Known" filesystems currently: ext234, reiser, jfs, xfs
- det_fs
Small bug fixed - as this function is meant to be called in $(), it may
not be verbose.
Current behaviour is:
- if detection is successful, use its result
- if detection is not successful, and filesystem is provided, return
the provided one; otherwise use auto
This patch mainly adds fsck functionality to fstab-sys, with additional
sanity checks (checking for device existence, verifying fstype via
det_fs).
Signed-off-by: Michal Soltys <soltys@ziu.info>
A new dracut module to implement fstab.sys handling
This module implements fstab.sys handling. This has to happen after the root
mount and before the nfsroot-cleanup pre-pivot at least. I've made to happen at
the beginning of the pre-pivot scripts, although it should maybe be at the end
of the mount scripts. This latter would be harder to do because the actual
mount is currently done by 99mount-root.sh and there is no 2 digit integer
higher than 99 :-(
There are perhaps other ways of achieving this end, such as having the
nfsroot-cleanup trawl through the newroot's /etc/fstab and auto-magically
figure out if there are any mounts which are pre-requisites for the
/var/lib/nfs/rpc_pipefs mount and do them first. Likewise post pivot,
/etc/rc.sysinit could figure out of there are any pre-requisite mounts for
/var/lib/stateless/{writeable,state} before doing those mounts. In short, make
it the responsibility of anything doing a mount to check if there are any
pre-requisites in /etc/fstab and mount them first. However, this spreads the
changes needed over more places, so I favour the fstab.sys approach. Also, who
knows what other uses administartors may have put fstab.sys to? and this undoes
a regression caused by the move from mkinitrd to dracut.