I'm writing an automated script that will remove a logical volume, but I'm not 100% sure how to do this. It looks like one should use the -f flag to lvremove, but the documentation seem too sloppy to make me comfortable with that:

-f|--force ...

Override various checks, confirmations and protections. Use with extreme caution.

What are those "various checks, confirmations and protections"? To me it seems that there's a risk I'm sidestepping something else than just the confirmation about deleting the volume.


I think your biggest risk is to remove a volume that is still in use somehow. I.e. if dmsetup info shows a non-zero Open count.

# dmsetup info SSD-root | grep Open
Open count:        1

However in this case lvremove will straight up refuse to operate.

# lvremove SSD/root
  Logical volume SSD/root contains a filesystem in use.

Even with --force it still refuses to delete it (don't try this at home).

# lvremove --force --yes --verbose SSD/root
    Device dm-33 (253:33) appears to be mounted on /.
  Logical volume SSD/root contains a filesystem in use.

This even works if not mounted, just in use otherwise.

# lvcreate -n test -L100M SSD
# losetup --find --show /dev/SSD/test
# time lvremove SSD/test
  Logical volume SSD/test is in use.
real    0m4.816s
user    0m0.008s
sys 0m0.005s

Actually this is very slow (5 seconds for this lvremove call!) since it looks for mountpoint everywhere, doesn't find one, and keeps re-checking the open count. So it's like "huh this isn't mounted so why still open".

So for regular volumes, I think it's reasonably safe to use --force here; it doesn't force cases that are actually dangerous. The manpage even suggests the use of force in the Examples section. However, I haven't tested what happens in case of snapshot, cache and otherwise special volumes.

| improve this answer | |

The man page for lvremove also offers --yes, which states

Do not prompt for confirmation interactively but always assume the answer yes.

This should allow you to avoid having to use --force (with all its unspecified checks and balances) while still being able to have the volume removed programmatically.

(I know I've not addressed the protections that --force removes. I have offered an alternative that I believe will address your underlying requirement. Don't feel you have to accept this answer if you actually want to know about --force.)

| improve this answer | |
  • Unfortunately that has the same disadvantage, perhaps to a lesser degree but still. It assumes the answer yes to any unspecified confirmation. Can I be sure that the only question asked is whether I should remove the specified volume? Or could it happen that some other (unexpected) question is asked? – skyking Oct 27 '18 at 11:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.