diff --git a/kexec-kdump-howto.txt b/kexec-kdump-howto.txt index cb8a725..b45f35a 100644 --- a/kexec-kdump-howto.txt +++ b/kexec-kdump-howto.txt @@ -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 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. +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 diff --git a/mkdumprd b/mkdumprd index e89334d..4c20798 100644 --- a/mkdumprd +++ b/mkdumprd @@ -78,10 +78,13 @@ get_rootdev() { } to_mount() { - local _dev _mntopts _pdev + local _dev _t _o _mntopts _pdev _dev=$(to_dev_name $1) - _mntopts=$(findmnt -k -f -n -r -o TARGET,FSTYPE,OPTIONS $_dev) - [ -z "$_mntopts" ] && return + _t=$(findmnt -k -f -n -r -o TARGET,FSTYPE $_dev) + _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 if [ -b "$_dev" ]; then _pdev="$(get_persistent_dev $_dev)" @@ -96,6 +99,15 @@ to_mount_point() { 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 #$1=dump target get_ssh_size() { @@ -111,17 +123,43 @@ get_ssh_size() { echo -n $_size } -#Function: get_fs_size +#mkdir if save path does not exist on dump target filesystem #$1=dump target -get_fs_size() { +mkdir_save_path() { local _mnt=$(to_mount_point $1) + local _remount="no" + local _ret + [ ! -d ${_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 ] && { + echo "Mounting $1 as read-write failed." + exit 1; + } + _remount="yes" + fi mkdir -p ${_mnt}/$SAVE_PATH - [ $? -ne 0 ] && { + _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." 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}') } @@ -222,6 +260,7 @@ do echo "Dump target $config_val is probably not mounted." exit 1 fi + mkdir_save_path $config_val check_size fs $config_val ;; raw)