handle readonly mounted filesystem
We need fs dump target being mounted firstly before creating mkdumprd This is because we want to get the mount options from kernel mountinfo instead of simply mount it without considering mount options. To avoid the filesystem being used by something other than kdump we suggest them to mount it as 'ro', mkdumprd will remount it as 'rw' when necessary and remount it back to 'ro' In 2nd kernel kdump will still use 'rw' to mount it though. Tested local read-only mounted fs dump. [v1->v2]: improve documentation add error handling for `mount -o remount,ro` Fixed the changelog per Vivek's comment The code was reviewed by Vivek. Signed-off-by: Dave Young <dyoung@redhat.com>
This commit is contained in:
parent
b30fee648c
commit
f21cbb5165
|
@ -328,6 +328,10 @@ For both local filesystem and nfs dump the dump target must be mounted before
|
||||||
building kdump initramfs. That means one needs to put an entry for the dump
|
building kdump initramfs. That means one needs to put an entry for the dump
|
||||||
file system in /etc/fstab so that after reboot when kdump service starts,
|
file system in /etc/fstab so that after reboot when kdump service starts,
|
||||||
it can find the dump target and build initramfs instead of failing.
|
it can find the dump target and build initramfs instead of failing.
|
||||||
|
Usually the dump target should be used only for kdump. If you worry about
|
||||||
|
someone uses the filesystem for something else other than dumping vmcore
|
||||||
|
you can mount it as read-only. Mkdumprd will still remount it as read-write
|
||||||
|
for creating dump directory and will move it back to read-only afterwards.
|
||||||
|
|
||||||
Raw partition
|
Raw partition
|
||||||
|
|
||||||
|
|
51
mkdumprd
51
mkdumprd
|
@ -78,10 +78,13 @@ get_rootdev() {
|
||||||
}
|
}
|
||||||
|
|
||||||
to_mount() {
|
to_mount() {
|
||||||
local _dev _mntopts _pdev
|
local _dev _t _o _mntopts _pdev
|
||||||
_dev=$(to_dev_name $1)
|
_dev=$(to_dev_name $1)
|
||||||
_mntopts=$(findmnt -k -f -n -r -o TARGET,FSTYPE,OPTIONS $_dev)
|
_t=$(findmnt -k -f -n -r -o TARGET,FSTYPE $_dev)
|
||||||
[ -z "$_mntopts" ] && return
|
_o=$(findmnt -k -f -n -r -o OPTIONS $_dev)
|
||||||
|
[ -z "$_t" -o -z "$_o" ] && return
|
||||||
|
_o=${_o/#ro/rw} #mount fs target as rw in 2nd kernel
|
||||||
|
_mntopts="$_t $_o"
|
||||||
#for non-nfs _dev converting to use udev persistent name
|
#for non-nfs _dev converting to use udev persistent name
|
||||||
if [ -b "$_dev" ]; then
|
if [ -b "$_dev" ]; then
|
||||||
_pdev="$(get_persistent_dev $_dev)"
|
_pdev="$(get_persistent_dev $_dev)"
|
||||||
|
@ -96,6 +99,15 @@ to_mount_point() {
|
||||||
echo $(findmnt -k -f -n -r -o TARGET $1)
|
echo $(findmnt -k -f -n -r -o TARGET $1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
is_readonly_mount() {
|
||||||
|
local _mnt
|
||||||
|
_mnt=$(findmnt -k -f -n -r -o OPTIONS $1)
|
||||||
|
|
||||||
|
#fs/proc_namespace.c: show_mountinfo():
|
||||||
|
#seq_puts(m, mnt->mnt_flags & MNT_READONLY ? " ro" : " rw");
|
||||||
|
[[ "$_mnt" =~ ^ro ]]
|
||||||
|
}
|
||||||
|
|
||||||
#Function: get_ssh_size
|
#Function: get_ssh_size
|
||||||
#$1=dump target
|
#$1=dump target
|
||||||
get_ssh_size() {
|
get_ssh_size() {
|
||||||
|
@ -111,17 +123,43 @@ get_ssh_size() {
|
||||||
echo -n $_size
|
echo -n $_size
|
||||||
}
|
}
|
||||||
|
|
||||||
#Function: get_fs_size
|
#mkdir if save path does not exist on dump target filesystem
|
||||||
#$1=dump target
|
#$1=dump target
|
||||||
get_fs_size() {
|
mkdir_save_path() {
|
||||||
local _mnt=$(to_mount_point $1)
|
local _mnt=$(to_mount_point $1)
|
||||||
|
local _remount="no"
|
||||||
|
local _ret
|
||||||
|
|
||||||
[ ! -d ${_mnt}/$SAVE_PATH ] && {
|
[ ! -d ${_mnt}/$SAVE_PATH ] && {
|
||||||
mkdir -p ${_mnt}/$SAVE_PATH
|
if is_readonly_mount $1; then
|
||||||
|
echo "Mounting $1 as read-write for creating dump directory.."
|
||||||
|
mount -o remount,rw $1
|
||||||
[ $? -ne 0 ] && {
|
[ $? -ne 0 ] && {
|
||||||
|
echo "Mounting $1 as read-write failed."
|
||||||
|
exit 1;
|
||||||
|
}
|
||||||
|
_remount="yes"
|
||||||
|
fi
|
||||||
|
mkdir -p ${_mnt}/$SAVE_PATH
|
||||||
|
_ret=$?
|
||||||
|
[ "$_remount" = "yes" ] && {
|
||||||
|
echo "Remounting $1 as read-only."
|
||||||
|
mount -o remount,ro $1 || {
|
||||||
|
echo "Remounting $1 as read-only failed."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[ $_ret -ne 0 ] && {
|
||||||
echo "Creating ${_mnt}/$SAVE_PATH failed."
|
echo "Creating ${_mnt}/$SAVE_PATH failed."
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#Function: get_fs_size
|
||||||
|
#$1=dump target
|
||||||
|
get_fs_size() {
|
||||||
|
local _mnt=$(to_mount_point $1)
|
||||||
echo -n $(df -P "${_mnt}/$SAVE_PATH"|tail -1|awk '{print $4}')
|
echo -n $(df -P "${_mnt}/$SAVE_PATH"|tail -1|awk '{print $4}')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,6 +260,7 @@ do
|
||||||
echo "Dump target $config_val is probably not mounted."
|
echo "Dump target $config_val is probably not mounted."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
mkdir_save_path $config_val
|
||||||
check_size fs $config_val
|
check_size fs $config_val
|
||||||
;;
|
;;
|
||||||
raw)
|
raw)
|
||||||
|
|
Loading…
Reference in New Issue