在Windows分区上的文件中安装ubuntu(类似于Wubi安装程序)

我正在ntfs Windows分区上的文件中安装ubuntu。

这很容易做到:

disable safe boot in bios
you might also need to set AHCI SSD interface access
boot and run live cd

打开一个终端并以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/ubutnu.img

并在/ dev / sdx中将ubuntu安装在单独的磁盘上。

要从新环境启动,我使用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 ###

rmmod tpm导致安装循环挂起(grub 2.04)

在旧版本上,需要加载ntfs驱动程序(grub 2.02): modprobe ntfs

这实际上会将引导过程放到initramfs shell中

此时,您需要手动添加命令以加载图像

#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

可以轻松将其添加到initramfs脚本中。

我的问题是,我们可以将此功能添加到Ubuntu吗?

我觉得这很容易而且非常有用。我可以在本机环境中启动ubuntu,但也可以像虚拟磁盘映像一样移动映像。 要移动我的安装,我只需要在另一个实例上执行相同的步骤,只需从旧实例复制ubuntu.img文件,然后在新实例上覆盖它即可。

谢谢, 拉兹万