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?

1
  • Have your tried rebooting into single-user mode? That should allow you to umount /home. Commented Jul 14, 2018 at 12:40

1 Answer 1

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.

4
  • 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? Commented Jul 14, 2018 at 0: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. Commented Jul 14, 2018 at 0: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.... Commented Jul 14, 2018 at 0:39
  • @steeldriver - that's why I like doing it the way I showed with a simple grep 8-) Commented Jul 14, 2018 at 0:40

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.