install ubuntu in a file on windows partition (similar to Wubi installer)

razvan becheriu razvan.becheriu at gmail.com
Sat May 9 12:26:10 UTC 2020


Hi,

I don't want to create a lot of spam, but I have also added this discussion
to:
https://answers.launchpad.net/ubuntu/+question/690575
and
https://askubuntu.com/questions/1237424/install-ubuntu-in-a-file-on-windows-partition-similar-to-wubi-installer

I am not sure where is the proper place to ask this question:
--------------------------------------------------------------------------------------------------------
I am installing ubuntu in a file on my ntfs windows partition.

This is quite easy to do:
```
disable safe boot in bios
you might also need to set AHCI SSD interface access
boot and run live cd
```
open a terminal and as root
```
#mount ntfs partition
mount -t ntfs /dev/nvme0n1p3 /mnt
#create installation folder
mkdir /mnt/ubuntu
#create virtual drive
mknod /dev/sdx b 7 100
#create virtual disk image
dd if=/dev/zero of=/mnt/ubuntu/ubuntu.img bs=1G count=256
#link the virtual drive to the virtual disk image
losetup /dev/sdx /mnt/ubuntu/ubuntu.img
```

and install ubuntu in /dev/sdx like on a separate disk.

common problems:
```
/dev/nvme0n1p3 not showing up - these are related to bios settings
mount -t ntfs /dev/nvme0n1p3 /host fail to mount - windows partition can be
encrypted, so disable from windows (no need to format or reinstall windows)
```

to boot from the new environment I use grub config:
```
### BEGIN /etc/grub.d/10_linux ###
menuentry 'ubuntu' {
        rmmod tpm
        loopback loop (hd0,gpt3)/ubuntu/ubuntu.img
        root=(loop)
        linux /boot/vmlinuz-generic root=/dev/sdx rw verbose nosplash
        initrd /boot/initrd.img-generic
}
set timeout_style=menu
if [ "${timeout}" = 0 ]; then
  set timeout=10
fi
### END /etc/grub.d/10_linux ###
```

the rmmod tpm is causing mounting loop to hang (grub 2.04)

on older versions loading ntfs driver was needed (grub 2.02):
modprobe ntfs

this will actually drop the boot process to initramfs shell

at this point you need to manually add commands to load the image
```
#create mount point needed by initramfs image
mkdir /host
#mount ntfs partition
mount -t ntfs /dev/nvme0n1p3 /host
#create virtual drive
mknod /dev/sdx b 7 100
#link the virtual drive to the virtual disk image
losetup /dev/sdx /host/ubuntu/ubuntu.img
#continue boot up
exit
```

this can be easily added to an initramfs scripts.

*my question is, can we add this functionality to Ubuntu?*

I find it easy to do and very useful. I can boot ubuntu in a native
environment, but also can move my image around just like a virtual disk
image.
To move my installation, I just need to follow the same steps on another
instance, and just copy my ubuntu.img file from the old instance and
overwrite it on the new instance.
--------------------------------------------------------------------------------------------------------

Thank you,
Razvan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-devel-discuss/attachments/20200509/b5624bc2/attachment.html>


More information about the Ubuntu-devel-discuss mailing list