linuxmint / ubiquity

Installer
https://www.linuxmint.com
47 stars 49 forks source link

[Cinnamon] INSTALLATION: /isodevice (as a mounted directory) locks a partition even if it is not listed by 'mount' #51

Open Martin-Laclaustra opened 2 years ago

Martin-Laclaustra commented 2 years ago

Describe the bug This occurs when installing from an iso file located in the same partition that will be formatted (e.g. as root or as boot) and installed.

The following procedure worked with linuxmint-20.3-cinnamon-64bit.iso.

I have been updating my systems this way so far. In brief, copying the iso file to /boot/grml or to /boot/boot-isos. An entry could be added manually to grub, but I have been using the 'grml-rescueboot' package (installed from the repository with apt install) or booting from USB with Super Grub Disk. In the boot sequence, in the ISO grub menu, edit the entry (pressing 'e') and add 'toram' to the 'linux' line and then boot ('F10'). After complete boot, in a terminal, losetup showed a loop for the iso file in the isodevice (the partition that contained the iso file) and mount showed /isodevice mount pointing to the partition (MOUNT DOES NOT SHOW THIS LINE ANY MORE IN MINT 21). Then I deleted the loop (with losetup -d) and afterwards unmounted /isodevice (IN MINT 21 THIS PRODUCES AND ERROR BECAUSE THERE IS NOT SUCH MOUNT). After that, I could install normally, formatting the partition that contained the iso file (NOT ANY MORE, NOW IT STOPS WITH AN ERROR BECAUSE THE PARTITION IS USED BY THE SYSTEM).

To Reproduce Steps to reproduce the behavior:

  1. COPY THE ISO FILE TO THE DESTINATION PARTITION AND INCLUDE IT IN GRUB
    sudo apt install grml-rescueboot 
    sudo cp /media/user/EXTERNAL/boot-isos/linuxmint-21-cinnamon-64bit-beta.iso /boot/grml/
    sudo update-grub

    Alternatively a manual entry in the grub menu could be added:

    
    menuentry "Grml Rescue System (linuxmint-21-cinnamon-64bit-beta.iso)" {
        insmod part_gpt
        insmod ext2
        set root='hd0,gpt5'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt5 --hint-efi=hd0,gpt5 --hint-baremetal=ahci0,gpt5  xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx
        else
          search --no-floppy --fs-uuid --set=root xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx
        fi
        iso_path="/boot/grml/linuxmint-21-cinnamon-64bit-beta.iso"
        export iso_path
        kernelopts="   "
        export kernelopts
        loopback loop "/boot/grml/linuxmint-21-cinnamon-64bit-beta.iso"
        set root=(loop)
        configfile /boot/grub/loopback.cfg
    }
2. REBOOT AND SELECT GRUB ENTRY "Grml Rescue System (linuxmint-21-cinnamon-64bit-beta.iso)"
3. IN THE NEXT GRUB MENU (THE ONE OF THE ISO FILE) EDIT THE FIRST ENTRY
Press 'e'.
Add 'toram' to the 'linux' line. And press 'F10'

linux /casper/vmlinuz file=/cdrom/pressed/linuxmint.seed boot=casper iso-scan/filename=${iso_path} toram quiet splash --

4. AFTER BOOTING, IN A TERMINAL WINDOW, TYPE:

mint@mint:~$ losetup NAME SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE DIO LOG-SEC /dev/loop1 0 0 0 0 /cdrom/casper/filesystem.squashfs 0 512 /dev/loop0 0 0 0 0 /isodevice/boot/grml/linuxmint-21-cinnamon-64bit-beta.iso 0 512 mint@mint:~$ sudo losetup -d /dev/loop0 mint@mint:~$ mount [[/isodevice IS NOT LISTED]] mint@mint:~$ sudo umount /isodevice umount: /isodevice: no mount point specified. mint@mint:~$

5. INSTALL ON SDA5, AN ERROR IS RAISED
![ROOT_PARTITION_FORMAT](https://user-images.githubusercontent.com/12773403/179389579-6586d81d-f85c-40c2-bdbb-43c73d39f48a.png)
![ERROR](https://user-images.githubusercontent.com/12773403/179389589-924dc702-ce18-4bf5-8803-8b9e2c798421.png)
6. THE PARTITION IS BUSY. CONFIRMED IN GPARTED
![GPARTED_ERROR](https://user-images.githubusercontent.com/12773403/179389604-9641f601-52ed-4c2c-9f78-2c1e89e64bc1.png)

**Expected behavior**
To work as it did with **_linuxmint-20.3-cinnamon-64bit.iso_**.
Everything works the same for 1, 2, and 3.
4. AFTER BOOTING, IN A TERMINAL WINDOW, TYPE:

mint@mint:~$ losetup NAME SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE DIO LOG-SEC /dev/loop1 0 0 0 0 /cdrom/casper/filesystem.squashfs 0 512 /dev/loop0 0 0 0 0 /isodevice/boot/grml/linuxmint-20.3-cinnamon-64bit.iso 0 512 mint@mint:~$ sudo losetup -d /dev/loop0 mint@mint:~$ mount sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime) proc on /proc type proc (rw,nosuid,nodev,noexec,relatime) udev on /dev type devtmpfs (rw,nosuid,noexec,relatime,size=1904916k,nr_inodes=476229,mode=755) devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000) tmpfs on /run type tmpfs (rw,nosuid,nodev,noexec,relatime,size=390432k,mode=755) /dev/sda5 on /isodevice type ext4 (rw,relatime) /dev/shm on /cdrom type tmpfs (rw,relatime,size=2307212k) /dev/loop1 on /rofs type squashfs (ro,noatime) [[... EDITED FOR BREVITY]] mint@mint:~$ sudo umount /isodevice mint@mint:~$


5. INSTALL ON SDA5 WORKS FLAWLESSLY
![ROOT_PARTITION_FORMAT](https://user-images.githubusercontent.com/12773403/179389579-6586d81d-f85c-40c2-bdbb-43c73d39f48a.png)
Martin-Laclaustra commented 2 years ago

As an additional information, /isodevice mount is absent in linuxmint-21-cinnamon-64bit-beta.iso while present in linuxmint-20.3-cinnamon-64bit.iso also when booted without the toram kernel option (skipping step 3 in the above to-reproduce section).

This does not make much sense, suggesting that it is a BUG that probably force-unmounts the partition hosting the ISO file, instead of detaching the loop device first and doing a normal unmount. Also it seems to delete /isodevice mount point. In the case that files are not copied to ram, the ISO must remain accessible, thus the hosting partition should not be unmounted.

clefebvre commented 2 years ago

I'm moving this towards ubiquity. It's not within the scope for us since it doesn't affect users in general and it's quite technical.

Martin-Laclaustra commented 1 year ago

This bug is still present in 21.1 beta. Could you point me to the commits used for releases 20.3 and 21? May be comparing them we could get an idea of where the problem is. With some support I might be able to help in debugging this question.

Martin-Laclaustra commented 1 year ago

I have a suspect for the problem:

In casper/scripts/casper-bottom/05mountpoints the following code could help...

if grep -q '^[^ ]* /isodevice ' /proc/mounts; then
    mkdir -p /root/isodevice
    mount -n -o move /isodevice /root/isodevice
fi

(This was present in the now extinct package lupin-casper in lupin-0.57build1/casper/scripts/casper-bottom/05mountpoints_lupin)

It would be great if this could be tested and fixed during current beta for the 20.1 release. Also, if this is the root of the problem, it could be reported upstream.

Martin-Laclaustra commented 1 year ago

Upstream, there are also people who seem to be missing this fix. (https://bugs.launchpad.net/ubuntu/+source/lupin/+bug/1960457/comments/33)

Martin-Laclaustra commented 1 year ago

The proposed patch in https://github.com/linuxmint/ubiquity/issues/51#issuecomment-1344978596 correctly fixes the issue in the following test. This is the procedure to create the patched ISO:

# mount the original linux mint iso image
mkdir /tmp/isomount
sudo mount -o loop /boot/grml/linuxmint-21.1-cinnamon-64bit.iso /tmp/isomount/
# extract initramfs from the iso image
mkdir /tmp/initrd_out
unmkinitramfs -v /tmp/isomount/casper/initrd.lz /tmp/initrd_out
# PATCH FILE "scripts/casper-bottom/05mountpoints"
sed -i -E "s/mount -n -o move \/cdrom \/root\/cdrom/mount -n -o move \/cdrom \/root\/cdrom\n\nif grep -q \'\^\[\^ \]\* \/isodevice \' \/proc\/mounts; then\n       mkdir -p \/root\/isodevice\n       mount -n -o move \/isodevice \/root\/isodevice\nfi/" /tmp/initrd_out/main/scripts/casper-bottom/05mountpoints
# create a partial initramd with the patched file
cd /tmp/initrd_out/main/
find . -name 05mountpoints | cpio -H newc -o > /tmp/initrd.partial.lz
# append the partial initramd to the original initramd, last file overwrites the original one at runtime
cat /tmp/isomount/casper/initrd.lz /tmp/initrd.partial.lz > /tmp/initrd.lz 
# copy iso contents to a new rw dir
mkdir /tmp/iso_out
rsync -a /tmp/isomount/ /tmp/iso_out
# replace initrd.lz in the new iso
sudo cp /tmp/initrd.lz /tmp/iso_out/casper/
# create the new iso
sudo mkisofs -D -r -V "LIVE" -cache-inodes -J -l -b isolinux/isolinux.bin -c boot.catalog -no-emul-boot -boot-load-size 4 -boot-info-table -o /tmp/custom.iso /tmp/iso_out/
# TEST

And the test that confirms that it is working is the one I mentioned in https://github.com/linuxmint/mint21.1-beta/issues/50#issuecomment-1353943584: the directory /isodevice reappears in the running live ISO (showing the contents of the device that holds the ISO file from where the system was booted), and the mount is listed with the command mount. Furthermore, the steps mentioned in the OP (detach the loop device, and then unmount) were also successful.

toivma commented 6 months ago

Do anyone know what is the status with this bug? Looks like it is still not be fixed in Ubuntu based installations. I have manually tested modifying 05mountpoints according to the instructions and after that you can unmount the ISO correctly when I boot an Ubuntu based live ISO from the hard drive. This would be important to get fixed as the fix is simple.