Skip to contentSkip to conversation

losetup -d does not move partition devices

DISCUSSION [email protected] 4 participants 6 messages Sep 24, 2013 – Oct 9, 2013 Util-Linux package

lore
Share & tools
lore
#0 lore raw

Hi all

On Ubuntu Desktop 13.04 64bit the loop device partitions do not automatically get deleted when you call "losetup -d DEVICE". This causes other programs (like lvmdiskscan -l) to report Input/output errors.

Here is how to reproduce the problem:

LOOPDEV=/dev/loop3
IMAGEFILE=pwd/mydisk.img
MOUNTPOINT=pwd/mnt

# 1. Create and mount an ext4 partition from a file-based disk image dd if=/dev/zero of=$IMAGEFILE bs=1M count=80
sudo losetup $LOOPDEV $IMAGEFILE
sudo parted $LOOPDEV mklabel msdos
sudo parted $LOOPDEV mkpart primary 2048s 43007s
sudo mkfs -t ext4 ${LOOPDEV}p1
mkdir $MOUNTPOINT
sudo mount ${LOOPDEV}p1 $MOUNTPOINT

# 2. Unmount again => ERROR: the partition device files are not deleted sudo umount $MOUNTPOINT
sudo losetup -d $LOOPDEV
rmdir $MOUNTPOINT
rm $IMAGEFILE
ls -l ${LOOPDEV}*

The last command shows:

	/tmp/test[10:18]% ls -l ${LOOPDEV}*
	brw-rw---- 1 root disk   7, 3 Sep 24 18:18 /dev/loop3
	brw-rw---- 1 root disk 259, 0 Sep 24 18:17 /dev/loop3p1

As no device is connected there is no partition 1! Isn't this a bug?

Regards
BB.

maintainer
#1 lore raw
Quoted 5 lines · On Tue, Sep 24, 2013 at 06:22:11PM +0200, [email protected] wrote:

get deleted when you call "losetup -d DEVICE". This causes other programs (like lvmdiskscan -l) to report Input/output errors.

Here is how to reproduce the problem:

Quoted 7 lines

LOOPDEV=/dev/loop3
IMAGEFILE=pwd/mydisk.img
MOUNTPOINT=pwd/mnt

# 1. Create and mount an ext4 partition from a file-based disk image dd if=/dev/zero of=$IMAGEFILE bs=1M count=80
sudo losetup $LOOPDEV $IMAGEFILE

kernel uses partitions on loop devices conditionally, and here you said "I don't care about partitions...". You have to use

sudo losetup -P $LOOPDEV $IMAGEFILE

if you want to force kernel loopdev driver to use partitions.

Quoted 8 lines

sudo parted $LOOPDEV mklabel msdos
sudo parted $LOOPDEV mkpart primary 2048s 43007s
sudo mkfs -t ext4 ${LOOPDEV}p1
mkdir $MOUNTPOINT
sudo mount ${LOOPDEV}p1 $MOUNTPOINT

# 2. Unmount again => ERROR: the partition device files are not deleted sudo umount $MOUNTPOINT

mount/umount is completely irrelevant for this issue. The simple way to reproduce the problem is:

dd if=/dev/zero of=img bs=1M count=80
losetup -f img --show
parted /dev/loop0 mklabel msdos
parted /dev/loop0 mklabel msdos
losetup -d /dev/loop0

cat /sys/block/loop0/size
cat /sys/block/loop0/loop0p1/size

Anyway, the problem is that parted uses BLKPG_ADD_PARTITION ioctl to create /dev/loop0p1, but the loop0 device has been created without PARTSCAN flag (see /sys/block/loop0/loop/partscan). It means that loopdev kernel driver does not call BLKRRPART during loop0 cleanup (loop_clr_fd() in kernel code).

You can remove the partition manually by BLKPG_DEL_PARTITION ioctl:

    # partx -d /dev/loop0p1

... but this all is known issue, Phillip Susi tried to fix this disadvantage, but his solution has been reverted (see kernel commit c2fccc1c9f7c81700cbac2120a4ad5441dd37004).

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#2 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 3 lines · Karel Zak

... but this all is known issue, Phillip Susi tried to fix this disadvantage, but his solution has been reverted (see kernel commit c2fccc1c9f7c81700cbac2120a4ad5441dd37004).

Jens, I had assumed from your commit message that you intended to reintroduce a fixed version of that patch in the following cycle. Did I misunderstand or did this get lost in the shuffle?

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.17 (MingW32)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBAgAGBQJSUsQlAAoJEJrBOlT6nu75HpMH/RuVqo79Wlwr793RR2b9QSgU 58QHTcjcGb7pwOSnqHC68Ys5v3r1nqbp7VoRh8nc2V3XvMitGmwLbdDXafDTVOdt 2N3gl518w+XaIUMwUHYGnbGsaqba0OHr5u95/REUI1tW3hfgX+rQJBx7eJ5gC28x oeHK7gu1jAHlaKeA6OUIiVxGYCp2kwZGj0goJy7uP9mWvscVjy/skZBjIv5iCFnN gizrKxkD4++GjNul5TtfeI9SAW0coetrjXz11lJQ3o1JWu6X0shmp4KpR223ry3+ hdFdegaNXM3IDumHvdjkdxwUGg6M1VzojXJLguHs5NwYQTI6qzinvsxZJXkYPoQ= =2EWu
-----END PGP SIGNATURE-----

#3 lore raw
In reply to Karel Zak

Hi Karel

Thanks for your detailed explanation. Good to hear I did hit a real (although already known) issue. Too bad there is no easy fix.

Anyway, one last minor comment:

Ubuntu 13.04 64bit does not yet support option -P for losetup. So this must be an older version of util-linux. But then: how do I determine the version of util-linux installed? The binaries have no --version option and 'strings /sbin/losetup | egrep '[0-9]' does not reveal anything useful either. Maybe there is a general version for util-linux available in another binary? The man page does not tell. I failed to identify the version number!

Regards
BB.

Quoted 59 lines · Karel Zak
Quoted 5 lines · On Tue, Sep 24, 2013 at 06:22:11PM +0200, [email protected] wrote:

get deleted when you call "losetup -d DEVICE". This causes other programs (like lvmdiskscan -l) to report Input/output errors.

Here is how to reproduce the problem:

Quoted 7 lines

LOOPDEV=/dev/loop3
IMAGEFILE=pwd/mydisk.img
MOUNTPOINT=pwd/mnt

# 1. Create and mount an ext4 partition from a file-based disk image dd if=/dev/zero of=$IMAGEFILE bs=1M count=80
sudo losetup $LOOPDEV $IMAGEFILE

kernel uses partitions on loop devices conditionally, and here you said "I don't care about partitions...". You have to use

sudo losetup -P $LOOPDEV $IMAGEFILE

if you want to force kernel loopdev driver to use partitions.

Quoted 8 lines

sudo parted $LOOPDEV mklabel msdos
sudo parted $LOOPDEV mkpart primary 2048s 43007s
sudo mkfs -t ext4 ${LOOPDEV}p1
mkdir $MOUNTPOINT
sudo mount ${LOOPDEV}p1 $MOUNTPOINT

# 2. Unmount again => ERROR: the partition device files are not deleted sudo umount $MOUNTPOINT

mount/umount is completely irrelevant for this issue. The simple way to reproduce the problem is:

dd if=/dev/zero of=img bs=1M count=80
losetup -f img --show
parted /dev/loop0 mklabel msdos
parted /dev/loop0 mklabel msdos
losetup -d /dev/loop0

cat /sys/block/loop0/size
cat /sys/block/loop0/loop0p1/size

Anyway, the problem is that parted uses BLKPG_ADD_PARTITION ioctl to create /dev/loop0p1, but the loop0 device has been created without PARTSCAN flag (see /sys/block/loop0/loop/partscan). It means that loopdev kernel driver does not call BLKRRPART during loop0 cleanup (loop_clr_fd() in kernel code).

You can remove the partition manually by BLKPG_DEL_PARTITION ioctl:

    # partx -d /dev/loop0p1

... but this all is known issue, Phillip Susi tried to fix this disadvantage, but his solution has been reverted (see kernel commit c2fccc1c9f7c81700cbac2120a4ad5441dd37004).

Karel

maintainer
#4 lore raw
Quoted 9 lines · On Wed, Oct 09, 2013 at 01:22:50AM +0200, [email protected] wrote:

Anyway, one last minor comment:

Ubuntu 13.04 64bit does not yet support option -P for losetup. So this must be an older version of util-linux. But then: how do I determine the version of util-linux installed? The binaries have no --version option and 'strings /sbin/losetup | egrep '[0-9]' does not reveal anything useful either. Maybe there is a general version for util-linux available in another binary? The man page does not tell. I failed to identify the version number!

The option --version for losetup is supported since v2.21.

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#5 lore raw
Quoted 11 lines · Karel Zak
Quoted 9 lines · On Wed, Oct 09, 2013 at 01:22:50AM +0200, [email protected] wrote:

Anyway, one last minor comment:

Ubuntu 13.04 64bit does not yet support option -P for losetup. So this must be an older version of util-linux. But then: how do I determine the version of util-linux installed? The binaries have no --version option and 'strings /sbin/losetup | egrep '[0-9]' does not reveal anything useful either. Maybe there is a general version for util-linux available in another binary? The man page does not tell. I failed to identify the version number!

Quoted 1 line

The option --version for losetup is supported since v2.21.

As Debian (even SID/unstable) only has an ancient version of util-linux i'm not surprised.

$ dpkg -l | grep util-linux
ii  util-linux                              2.20.1-5.5                          i386         Miscellaneous system utilities
$ losetup --version
losetup: unrecognized option '--version'
...

If Ubuntu doesn't roll it's own util-linux, there is the explantion.

Signature · 1 line
Matthias