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 run 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, must be disabled 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)
instead of rmmod tpm, add:
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.