[linux-lvm] rudimentary kill script

Xen list at xenhideout.nl
Sat Aug 27 12:41:50 UTC 2016


Here is a quick way to kill all processes that might have an open file 
on some volume you want to umount and close.

kill_all_dm() {
     hexdev=$(dmsetup info -c -o major,minor $1 --noheadings | tr ':' ' ' 
| { read a b; printf "D0x%02x%02x\n" $a $b; })
     process_list=$(lsof -F cDn0 | tr '\0' '\t' | awk -F '\t' '{ if 
(substr($1,1,1) == "p") P=$1; else print P "\t" $0 }' | grep $hexdev | 
awk '{print $1}' | sed "s/^p//")
     [ -n "$process_list" ] && echo "$process_list" | xargs kill -9
}

It works on logical volumes and device mapper (paths) equally, but you 
must specify the path:

kill_all_dm /dev/linux/root ;-).



Alternatively this will just list all open processes:

find_processes() {
     hexdev=$(dmsetup info -c -o major,minor $1 --noheadings | tr ':' ' ' 
| { read a b; printf "D0x%02x%02x\n" $a $b; })
     process_list=$(lsof -F cDn0 | tr '\0' '\t' | awk -F '\t' '{ if 
(substr($1,1,1) == "p") P=$1; else print P "\t" $0 }' | grep $hexdev | 
awk '{print $1}' | sed "s/^p//")
     [ -n "$process_list" ] && echo "$process_list" | xargs ps
}

find_processes /dev/linux/root




More information about the linux-lvm mailing list