Code review comment for lp:~noorez-kassam/ubuntu/utopic/initramfs-tools/fix-for-1317437

bcbc (bcbc) wrote :

This is the way I understand this is and my testing is shown below:

Mounting and creating the loop device in the same step with the readonly option, makes it impossible to remount the loop device later as read-write.

By creating the loop device separately (which defaults to read-write capable unless the -r option is supplied), the loop device can then be mounted readonly, and later remounted as read-write.

This change is needed since release 14.04, which - for unknown reasons - now won't let the loop device be remounted read-write (perhaps it's passing the -r option to losetup internally and it's losetup which has started enforcing this?).

The end result is that Wubi installs cannot boot, because the remount read-write fails.

My tests confirm this:
Setup:
1. Create a file, format as ext4.
bcbc@neptune:~$ dd if=/dev/zero of=new.disk bs=1MB count=100
bcbc@neptune:~$ mkfs.ext4 -F new.disk

2. Old method, mount and create loop device as read only, then try to remount
bcbc@neptune:~$ sudo mount -r -t ext4 -o loop new.disk /mnt
bcbc@neptune:~$ sudo touch /mnt/test
touch: impossible de faire un touch «/mnt/test»: Système de fichiers accessible en lecture seulement
bcbc@neptune:~$ sudo mount -o remount,rw /mnt
mount : impossible de remonter périphérique bloc /dev/loop0 en lecture/écriture, est protégé en écriture
bcbc@neptune:~$ sudo umount /mnt

3. New method, first create loop device (defaults to read-write capable), then mount as read only, then try to remount read-write
bcbc@neptune:~$ sudo losetup /dev/loop0 new.disk
bcbc@neptune:~$ sudo mount -r -t ext4 /dev/loop0 /mnt
bcbc@neptune:~$ sudo touch /mnt/test
touch: impossible de faire un touch «/mnt/test»: Système de fichiers accessible en lecture seulement
bcbc@neptune:~$ sudo mount -o remount,rw /mnt
bcbc@neptune:~$ sudo touch /mnt/test
bcbc@neptune:~$ sudo umount /mnt
bcbc@neptune:~$ sudo losetup -d /dev/loop0

4. To confirm it's probably passing -r to losetup
bcbc@neptune:~$ sudo losetup -r /dev/loop0 new.disk
bcbc@neptune:~$ sudo mount -r -t ext4 /dev/loop0 /mnt
bcbc@neptune:~$ sudo touch /mnt/test
touch: impossible de faire un touch «/mnt/test»: Système de fichiers accessible en lecture seulement
bcbc@neptune:~$ sudo mount -o remount,rw /mnt
mount : impossible de remonter périphérique bloc /dev/loop0 en lecture/écriture, est protégé en écriture
bcbc@neptune:~$ sudo umount /mnt
bcbc@neptune:~$ sudo losetup -d /dev/loop0

Conclusion:
This fix is appropriate and required for loop mounted installs

« Back to merge proposal