How can I write a Windows (NTFS) .img file to a partition and add it to grub?

Darlan Alves

I'm trying some crazy stuff here. First, I had a VirtualBox machine with Windows XP installed, using .vdi format. Then I exported the image to a OVA, extracted the .vmdk and converted it to a raw .img file. Then I've created a new VM into KVM via virt-manager, loaded this image as a hard disk and got it running.

Now, I'm trying to copy this entire image to a disk partition, via dd, and boot the first NTFS partition inside this image on boot, via grub. So far, i've already dd'ed the first partition inside the image (the actual NTFS partition) and it was recognized both by gParted as NTFS and grub as a Windows install, but I can't boot it. So I've tried to copy the entire image, including the partition table, boot sector and stuff, to this /dev/sda4 physical partition. Now the image is booting via KVM, but I can't find a way to add it to Grub. I'm trying to find a way to do it via loop mounting, I just have no idea on how config grub to mount/map/boot this image and access the first (NTFS) partition inside it.

What I want to do:

- Turn my XP image into a valid physical installation to dual boot
- Keep the VM running from this disk partition

This way, if possible, I'll use the VM on Ubuntu, or boot it on grub.

For clarification, the commands I used:

$ sudo su

# mounts the entire image
$ losetup /dev/loop0 /path/to/WindowsXP.img
$ fdisk -l /dev/loop0

> Device        Boot    Start   End         Blocks      Id  System
> /dev/loop0p1  *       63      31439204    15719571    7   HPFS/NTFS/exFAT

# mounts the first NTFS partition inside image (offset 63*512)
$ losetup /dev/loop1 -o 32256 /dev/loop0

At this point, I have both NTFS partition on /dev/loop1 and the full disk (with MBR) on /dev/loop0. Then:

# copied the entire image to /dev/sda4. This is not recognized by GRUB, 
# therefore it must be loopmounted before booted via grub config somehow
$ dd if=/dev/loop0 of=/dev/sda4 bs=10m

# copied the NTFS virtual partition to physical one
# GRUB should recognize and boot it, since is a valid XP install, however it misses the partition table,
# so the virtual machine won't be able to boot it.
$ dd if /dev/loop1 of=/dev/sda4 bs=10m

As an alternative, I thought about a second disk image attached to VM, only with GRUB and minimal info to boot this partition. This way, I could keep the NTFS partition on /dev/sda4 to grub as a dual boot, and boot from a second tiny image on KVM.

Ideas?

Aaron Okano

Disclaimer: this is more of a suggestion, not a well-informed answer.

Since you seem to be able to copy the Windows partition to a legitimate physical partition (/dev/sda4) why don't you just boot /dev/sda in a virtual machine? You could then boot into the Windows partition by choosing the Windows option in GRUB. It appears this sort of setup has been done before: https://bbs.archlinux.org/viewtopic.php?id=68216

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I resize NTFS partition in GParted?

Can't write on ntfs partition shared with Windows 10

How can I fix an inconsistent NTFS file system without Windows?

How can I reinstall GRUB to the EFI partition?

How can I trace NTFS and Share Permissions to see why I can (or can't) write a file

How do I give multiple users access to a Windows NTFS partition?

How can I clone only a bootable windows partition(not the disk) to a file?

Ubuntu 18.04 can't write on NTFS partition

Can't mount NTFS partition with write permissions

How can I resize an external USB NTFS partition?

How can I automatically mount an NTFS partition in Lubuntu on startup?

How can I use fdisk to create a ntfs partition on /dev/sdx?

How can I enable Trash feature in a NTFS partition with permissions?

how i can get ntfs data on ext4 partition?

Grub - boot debian iso file from ntfs partition and install it

how do I detect Grub partition in windows disk management

Unable to open file from Windows NTFS partition

How can I write dataframe to csv file using one partition although the file size exceeds executors memory

How can I make Grub recognise my old Linux Partition

Why can't I resize NTFS partition?

How do I shrink the partition of an img file made from dd?

How can I write Windows batch file command with loop and % operator?

How can I append to a file in grub 2.06?

How can I import a video to my HTML file? I only know how to add a GIF and IMG

How to add Windows to grub?

How to add Windows to GRUB

How to delete a corrupted file on an NTFS partition?

How can I shrink a Windows 10 partition?

Can I shrink an NTFS partition running Windows 7 from the 'left' / 'start' side?