Sunday, June 29, 2014

Unmount All

The task is to unmount all the mountpoints of a specified block device, such that we can e.g., remove it from the system. However, unmounting filesystems in question and disassembling a chain consisting of several devices (crypt, lvm, raid, etc.) has to be done in correct order which makes the whole process complex and prone to errors if done manually.

I've took a look at ArchLinux 'initcpio' shutdown script (/usr/lib/initcpio/shutdown), which turned out to be a great source of inspiration. In fact, I've ended up reusing crucial bit of it.
$ umountall 
usage: umountall <block-device-name> (e.g., sda, dm-0)

It takes a single argument 'block-device-name', which actually has to be any of '/sys/class/block/*' names.

So before removing 'sdb' drive do:

$ sudo umountall sdb

If no errors are reported you are free to go and unplug it (if that is supported at all).

Grab the latest version here.