Comment 26 for bug 1489855

Akeo (b-pete-r) wrote :

This is a pretty serious and rather obvious bug, once you understand what's going on.

As pointed out by @DC-THINK, whom I will mostly be paraphrasing here, the gist of it is: /usr/share/initramfs-tools/scripts/casper-helpers may unmount a previously mounted device, that it should *NOT* leave unmounted on exit.

The following is an alternate description of what happens, so that it may helps dev assess the seriousness of the issue:

For this example, I will assume that you have extracted the installation media on a vfat image (say /dev/sdb1). It actually doesn't matter if you actually have a persistent partition or not, as it will fail even with a single vfat partition (which I tested with GPT/FAT32 single partition drive and ubuntu-19.04-desktop-amd64.iso after adding 'persistent' to the "Try Ubuntu without installing" in grub.cfg:

1. /dev/sdb1 is *ALREADY mounted (as /cdrom) when we enter find_cow_device(), as it was mounted during the init process.
2. As we are processing all (non floppy) block devices, we start processing /dev/sdb*, and therefore start to look at /dev/sdb1.
3. Because we are processing the vfat partition, we don't find label 'casper-rw', so we proceed to look for a 'casper-rw' file.
4. To look for that file, the first thing that the script issues is 'try_mount' which succeeds at remounting /dev/sdb1 "rw".
5. We now look for a 'casper-rw' on the newly mounted /dev/sdb1, and don't find it, since it doesn't exist.
6. [HERE IS THE BUG] /dev/sdb1 is now **UNCONDITIONALLY** unmounted... instead of being remounted to the mountpoint it was using (/cdrom) when we entered the function call.
7. Because /cdrom has become unavailable, all kind of bad things happen, starting with the casper script complaining...

In other words, the bug is: find_cow_device() can and DOES unmount legitimate devices it has no business of unmounting.

Ergo, find_cow_device() must be fixed, possibly by keeping history of already mounted devices in try_mount() and using a new restore_mount() call instead of the unconditional umount currently used.

Alternatively, try_mount device should not degrade write access (i.e. it may do ro -> rw but not rw -> ro) and optionally return the existing mountpoint of an already mounted devices, so that find_cow_device() can determine if it should umount the device or not.

Hope this helps. Note that this bug is indeed very problematic for Windows users, and will become even more so as the current Windows recommended tool for Ubuntu installtion media (Rufus) is about to introduce persistent partition [Disclaimer: I am the author of Rufus].