Loop devices not freed
August 10, 2009 —
BarryK
Oh dear, oh dear. Recently I have been puzzled. When I have chosen to unmount a partition, it would not unmount due to a loop device in use in that partition. What I had done is use a loop device to mount a ext2 or squashfs file.
Today I examined this more closely, and to my very great surprise I found that when such a file is unmounted, the loop device is not freed from the file. It has been the standard behaviour of Linux ever since loop devices were introduced, that when you execute a 'umount' to unmount such a file, the corresponding loop device is also freed. However the two kernels 2.6.29.6 and 2.6.30.1 that I tested do not free the loop device.
Just to be sure, I also tested the latest Puppy built with 2.6.25.16 kernel, and the loop device did get freed.
This is a major change, and could break many scripts. Fortunately in Puppy /bin/umount is a script, so I can put in a fix, 'losetup -d /dev/<loop device>', unless any script calls the binary executables 'busybox umount' or 'umount-FULL' directly.
Before implementing such a fix, I thought it best to come online and do a search to see if there is any discussion about this. Strangely enough, I can't find anything much.
I wondered if there might be a kernel configure option, so I looked at the .config file that I used to compile 2.6.29.6, but no, there's nothing I can see that would be relevant.
I am very surprised. Quite a fundamental change, and I don't recall reading anything about it, though I watch the kernel announcements. Well, I guess I will just have to put a fix into the 'umount' script.
Thinking about it a bit more, the Busybox umount applet docs state that the default behaviour is to free the loop device, whereas the '-D' option will prevent it from being freed. But, it no longer works that way.
Comments
loopUsername: linuxcbon
I read loop is a module now. you need to modprobe loop first, to be able to mount it.
Loop device freed
Username: BarryK
"Ha ha, the light came on! I have discovered the problem is with Busybox. I am using Busybox from svn, 2009-07-25, and its umount applet has been made more compatible with the full umount. The older Busybox, that I was using until recently, had default to free a loop device, unless the '-D' option was used. However, the full umount works the other way, default not to free the loop device, and option '-d' is required to free it. In the above post, I stated that I checked with the 2.6.25.16 kernel, but in fact that build still has the older Busybox. I want the old behaviour, to free loop devices by default, so I have added '-d' into the 'umount' script. Problem solved.
Tags: woof