Unmounting QNAP system volume to perform e2fsck


The problem

This is just a quick note related to a problem I'm having from time to time, during maintenance of my QNAP volumes (QNAP TS-231K).

Sometimes I cannot resize my volumes as Filesystem is not clean. Please perform a check disk operation. However running the Check filesystem operation fails: Examination failed (Cannot unmount disk)

The solution

If it's safe, you may try rebooting the device and try again running the Check filesystem operation. This sometimes is enough.

However, often it just doesn't help. Usually this is the case with the volume marked by QNAP as the system volume. Basically, when creating a first volume on the storage pool, QNAP marks it as the system volume, and puts there some data.

In that case, my goto procedure is:

  1. Login via ssh to the user account and enter / directory: cd / (leave your homedir)
  2. Sudo to the admin account and enter / directory: cd / (leave your homedir)
  3. Stop all services #1: /etc/init.d/services.sh stop
  4. Stop all services #2: /etc/init.d/opentftp.sh stop
  5. Stop all services #3: /etc/init.d/Qthttpd.sh stop
  6. Find the device and it's mount point, you're having problems with. This command will help you make the choice: mount | grep -i cachedev. The device handle should look like /dev/mapper/cachedev1 and the mount point like /share/CACHEDEV1_DATA (ofc choose a proper one fitting your case, it might be called differently)
  7. Verify whethere there are still some opened files on this device: lsof | grep <mount-point>, e.g.: lsof | grep /share/CACHEDEV1_DATA
  8. If there are still opened files, kill processes that hold those file-handles. The second column of the lsof command shows the pid (process ID), so the command would look like: kill 1234 where 1234 is the PID. Repeat this step until lsof command shows nothing (no more opened files).
  9. Remember, that I wrote to leave your homedir after logging via SSH (both for normal user and admin?). This is very important step - if you enter a homedir, which is mounted inside of this volume, you may not see this thing as an opened file in the lsof output, but still, you won't be able to unmount the device properly!
  10. Now you may try unmounting the device: umount <device-handle>, e.g.: umount /dev/mapper/cachedev1
  11. If this fails, you may try enforcing it: umount -l <device-handle>
  12. If umount was successfull, you may try running check command: e2fsck -f -v -C 0 <device-handle>, e.g.: e2fsck -f -v -C 0 /dev/mapper/cachedev1

That usually works for me.