4

Maybe there is a better way to do what I am trying to achieve, so let me describe the whole problem. My / and /home directories are on a separate LV. It happened so the / LV get out of space. I then backup my /home and try to remove it to be able to resize /. However, when I did login to root tty and try to umount the /home with lvchange -a n /dev/trixxxy-vg/home I get prompt that this logical volume is in use.

Logical volume trixxxy-vg/home contains a filesystem in use.

My .emacs.d and .bashrc directories in /root were links to /home/user/ relevant, so I thought that can cause the problem, but after removing them nothing have changed.

I guess there is a way, that I am not aware of, to check what file is currently using the particular logical volume. Or may one force remove such partition?

siery
  • 199
  • 2
  • 3
  • 9

1 Answers1

4

You can typically use tools like fuser or lsof to see what files are currently in use. Here's an example where I'm going to use lsof.

Background

Here I have the following setup:

$ mount | grep lvm
/dev/mapper/lvm--raid-lvm0 on /export/raid0 type ext3 (rw)

So if we run lsof and grep for that mount /export/raid0:

$ lsof | grep '/export/raid0'
$

We get nothing. However if we cd /export/raid0:

$ lsof | grep '/export'
bash      32083      root  cwd       DIR              253,2          4096          2 /export/raid0

We see our Bash shell now accessing the LVM. Now lets vi afile while still in the directory /export/raid0:

$ lsof | grep '/export'
bash      32083      root  cwd       DIR              253,2          4096          2 /export/raid0
vi        32140      root  cwd       DIR              253,2          4096          2 /export/raid0
vi        32140      root    3u      REG              253,2          4096     278612 /export/raid0/.afile.swp

And lsof sees these accesses as well.

slm
  • 363,520
  • 117
  • 767
  • 871
  • I find the multitude of lsof options confusing - is there a way to target this at the specific mount point, like `lsof +D /home` perhaps? – steeldriver Jul 14 '18 at 00:35
  • @steeldriver - yeah that switch can be used to do this as well, the thing I don't like about that is the `stat` of all the files as it walks down the tree. – slm Jul 14 '18 at 00:38
  • @steeldriver - the warning in the man page: ....Further note: lsof may process this option slowly and require a large amount of dynamic memory to do it. This is because it must descend the entire directory tree, rooted at D, calling stat(2) for each file and directory, building a list of all the files it finds, and searching that list for a match with every open file. When directory D is large, these steps can take a long time, so use this option prudently.... – slm Jul 14 '18 at 00:39
  • @steeldriver - that's why I like doing it the way I showed with a simple `grep` 8-) – slm Jul 14 '18 at 00:40