fixed errors in unmounting and deleting loop devices

taken from
https://github.com/markvdb/build-raspbian-image/commit/599e59cad68a59a87
b5d5bb407d0e34fd79bc12e#diff-643e8b19da66138091f2d85fe549c1edR258

thanks @markvdb