Jump to content











Photo
- - - - -

Linux from VHD How To?

linux windows boot vhd image-file howto

  • Please log in to reply
64 replies to this topic

#1 Porfyr

Porfyr

    Newbie

  • Members
  • 10 posts
  •  
    European Union

Posted 25 July 2015 - 03:43 PM

Hi @ll.
 
Antecipated excuses if what I'm about to post is poorly worded, has already been answered or is in any other way inappropriate for the forum.
 
My question is simple: is there a known recipe to make any Linux flavor boot up from a VHD virtual disk image file?
 
Some context for this query has already been posted to UbuntuForums, but unfortunately the thread was closed before it got any relevant answers.

Notwithstanding, I just found a personal message containing encouraging info which I'll just transcribe here:
 

Ref:

LINUX-VHD for UBUNTU, ARCH, Fedora, OpenSuse, Mageia. (Chinese)
[教程] LINUX-VHD 系统的制作方法 UBUNTU, ARCH, Fedora, OpenSuse, Mageia 五种
http://bbs.wuyou.net....ead&tid=336079 [MANGLED URL, IRRETRIEVABLE!]

\[WUBI\] KLOOP: boot UBUNTU from img and vhd
http://newscentral.e...78691a65750d9f8

Hi, Everyone.

KLOOP is a new method to boot UBUNTU (Fedora, ARCH, OpenSuse, Mageia) from fixed img and fixed vhd.

It is based on the command 'kpartx' and using loop device as /, so I named it KLOOP (Kpartx+LOOP).
 
If you want to try it, click on the following :
http://pan.baidu.com/s/1bnnjBXX

download and decompress the file 'mydracut-English.zip', and read the file 'mydracut/ubuntu-kloop/readme-KLOOP-UBUNTU.txt' or 'mydracut/fedora-kloop/readme-KLOOP-FEDORA.txt'.[/font]

 
Sadly, the Baidu link doesn't have the English zip file available for download anymore, only a 'mydracut.zip' with Chinese instructions too complex for my extremely limited linguistic and computational capabilities; so I decided to post it here, where it is bound to at least stir some interest, in order to avoid a possible good solution going to waste....
 
Any help, info and/or links highly appreciated.

Edited by Porfyr, 25 July 2015 - 03:48 PM.


#2 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 13226 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 25 July 2015 - 04:21 PM

Well, maybe you could ask how to run *any* Linux from a RAW image file instead, and I could later tell you how a "static" .VHD file is nothing but a RAW image with a 512 byte footer appended to it ;).

 

At first sight the link you posted is about using kpartx together with a loopback device (which is available as an example through GRUB2), seemingly the nice Chinese guys have assembled a number of premade initrd images, most probably automating the mounting :unsure:, but there should be more traditional ways to boot from a RAW img a Linux distro, maybe the difference is between a "live" one (that can normally be booted from image) and an "installed" one? :dubbio:

 

The original post on bbs.wuyou.net is actually perfectly retrievable:

http://bbs.wuyou.net...read&tid=336079

maybe the code snippets in it are enough for your use.

 

:duff:

Wonko



#3 Porfyr

Porfyr

    Newbie

  • Members
  • 10 posts
  •  
    European Union

Posted 25 July 2015 - 04:40 PM

Thanks, Wonko. :thumbsup:

Looking into it right now...



#4 Porfyr

Porfyr

    Newbie

  • Members
  • 10 posts
  •  
    European Union

Posted 25 July 2015 - 06:07 PM

Nope, the Chinese forum is useless for me, can't make head or tails from it... :doh7:

 

But you seem to think this is doable -- so, how should one proceed to create an installed bootable Linux VHD? I already have it slotted in my Windows (7) boot menu, alongside the Windows system VHD, so that's all I'm missing...



#5 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 13226 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 26 July 2015 - 12:26 PM

Mind you I am not expert in Linux (and certainly not at that level) but there are a few "firm" points:

  • the booting mechanism of *any* Linux goes through loading in RAM a kernel and a initrd (Initial Ramdisk)
  • in *nix "everything is a file", there are none of the complexities usually found on NT systems when it comes to mount a volume or partition

 

From what I can understand at a glance what the good Chinese guys do is to simply automate the mounting (through one of the early executed scripts in the initrd) of the "rest of self" from a volume inside a file image instead of a volume on a physical device through kpartx, which seems like a nice approach :) but they don't really-really explain in detail how they do it (or maybe they do it only in the Chinese doc) and provide a number of pre-modified kernels and initrds for a number of distros.

 

BUT the given post on bbs.wuyou.net seems like listing the whole set of command needed (and it is not that bad in google translate) , it shouldn't be an issue for anyone familiar with Linux to replicate that.

 

Now, if you are looking for a step by step guide you might be out of luck :(, but if you are not (yet) at the level of experience/knowledge needed to replicate those steps, what is the issue with - say - WUBI?

https://en.wikipedia...Wubi_(software)

 

:duff:

Wonko


  • Porfyr likes this

#6 Porfyr

Porfyr

    Newbie

  • Members
  • 10 posts
  •  
    European Union

Posted 28 July 2015 - 05:26 PM

BUT the given post on bbs.wuyou.net seems like listing the whole set of command needed (and it is not that bad in google translate) , it shouldn't be an issue for anyone familiar with Linux to replicate that.

 

I'll try to work it out. I'll report back if I get any results.
 

Now, if you are looking for a step by step guide you might be out of luck :(, but if you are not (yet) at the level of experience/knowledge needed to replicate those steps, what is the issue with - say - WUBI?
https://en.wikipedia...Wubi_(software)

 

The(re are others, but the) main reason for not going with WUBI was detailed in the UbuntuForums post included in the OP.

FYI, I'm not a complete Linux noob (I've been using several flavors of it as backup OS for almost 10 years), but I ain't by any means a booting expert, too.

 

Thanks for your help, it is much appreciated. :thumbsup:


Edited by Porfyr, 28 July 2015 - 05:28 PM.


#7 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 13226 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 28 July 2015 - 06:04 PM

Ok :), then try with ArchLinux:

https://wiki.archlin...inux_disk_image

 

Again the "fallacy" :w00t: :ph34r: (if any) in the originally referenced topic on Ubuntu Forums is the mixed reference to vhdx (which has a different format) and vhd (which in it's basic form of "static" image is to all effects a RAW disk image with an appended footer and that most tools will access/use fine simply ignoring its last 512 bytes).

 

:duff:

Wonko



#8 Porfyr

Porfyr

    Newbie

  • Members
  • 10 posts
  •  
    European Union

Posted 28 July 2015 - 07:54 PM

I assumed there were ways to easily convert between VHDX and VHD...

#9 Porfyr

Porfyr

    Newbie

  • Members
  • 10 posts
  •  
    European Union

Posted 28 July 2015 - 08:00 PM

Oh, and the distro I was aiming to get in this setup was either Peppermint (L/Ubuntu based) or AntiX.

#10 Wonko the Insane

Wonko the Insane

    Frequent Member

  • Advanced user
  • 426 posts
  • Location:The Inside of the Asylum (gate is wide open)
  • Interests:That's for me to know and you to not find out.
  •  
    United States

Posted 29 July 2015 - 02:45 AM

Why do you need vhd/vhdx, specifically? I ask because .img is a much more common standard for Linux when it comes to disk images.



#11 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 13226 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 29 July 2015 - 03:57 PM

I assumed there were ways to easily convert between VHDX and VHD...

 

Sure a VHD can be converted to a VHDX (or to a VMDK or VDI for what matters) :).

 

BUT the result will be (obviously) a DIFFERENT file format :frusty:, still the message did not seemingly go through :(.

 

  1. There is "native" support for RAW images in Linux (though each specific distro may need this or that "tweak" to support the mounting at boot time).
  2. Coincidentally a "static" VHD is EXACTLY a RAW image (with an appended footer that will be read by tools specifically designed to deal with VHD and ignored as it provides no added usual information by tools designed to deal with RAW images).
  3. VHDX is DIFFERENT from VHD and thus it is not anymore a RAW image. 

1+2 means that booting and mounting a "static" VHD in Linux is possible natively and is (relatively) easy as you will actually be booting/mounting a RAW image.

1+3 means that doing the same with VHDX is NOT POSSIBLE unless specific mounting support for the peculiar VHDX format is added.

 

If you prefer:

  • *anything* designed to work with RAW images will also 99.99% work for "static" VHD images
  • the reverse is not true, *anything* designed to work with VHD images may (or may not) work for RAW images, 99.99% it WILL NOT work.
  • *anything* designed to work with RAW images WILL NOT work for VHDX images (that have a DIFFERENT file format)
  • *anything* designed to work with VHD images WILL NOT work for VHDX images (that have a DIFFERENT file format)
  • *anything* designed to work with VHDX images may (or may not) work for RAW images
  • *anything* designed to work with VHDX images usually also works with VHD images (but not necessarily it will work for RAW images)
  • Linux is designed to work with RAW images.

At the light of these info, choose the file format that you think more suitable, but choose wisely.

 

:duff:

Wonko



#12 Porfyr

Porfyr

    Newbie

  • Members
  • 10 posts
  •  
    European Union

Posted 30 July 2015 - 08:38 AM

I get you but that's really an easy one: VHD is the required format for booting from the Windows 7 boot manager -- any other format will be nothing more than an intermediary step, a mean to an end...

(And the same reason to you, AnonVendetta.)

#13 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 13226 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 30 July 2015 - 10:02 AM

I get you but that's really an easy one: VHD is the required format for booting from the Windows 7 boot manager -- any other format will be nothing more than an intermediary step, a mean to an end...

Just for the record, not really-really.

 

VHD is the format supported by some versions only of Windows 7 for  "VHD booting" natively. (but there are other ways to boot a Windows 7 from a disk image, casually a RAW one).

 

Conversely and as a side note, it makes very little sense to have a single (VHD or RAW) image multi-boot, the most useful feature of using an image for booting is its being self-contained and portable, to make a multi-boot image means (besides possible introducing some unneeded complications) that you need to create a larger image (which will be slower or more inconvenient anyway), while unless there are some really valid reasons for needing a monolithic image, making one VHD (or RAW) image for each OS is easier, faster and easier to manage.

 

:duff:

Wonko



#14 Porfyr

Porfyr

    Newbie

  • Members
  • 10 posts
  •  
    European Union

Posted 30 July 2015 - 02:12 PM

Beg your pardon, Wonko, but you're the one who mentioned a multi-boot image -- I'm keen on multi-booting images, as in one image, one OS. :hmm:

 

Any other way and the appeal of this solution (mainly easy backup and replacement) would dwindle fast...

 

Moreover, I'm aware of the possibility of chainloading bootstraps, but for the sake of KISS, I'll take the most easy and straightforward path I find. :)



#15 Porfyr

Porfyr

    Newbie

  • Members
  • 10 posts
  •  
    European Union

Posted 30 July 2015 - 02:46 PM

From what I could surmise about the procedure from our good Chinese benefactors, with the link you so kindly expunged for me, and through G∞gle Translate, this is the gist of it:
 

Ie only three steps

1 Use Virtualbox installed LINUX system,
2 Download the corresponding version of the kernel vmlinuz and initrd (dracut) There kernel driver module
3 Set the boot.

There UBUNTU series ARCH series dracut-opensue (3.16.6-2-desktop) dracut-fedora (3.17.8-2) dracut-mageia (3.14.27)

With small grub Universal starter -2014-12-06 help set the boot, inside there are instructions for use, the Edit menu to add the boot according to the instructions.


This still isn't 100% clear for me and there are several caveats: this looks like a chainloading scheme to my layman eyes; I'm unsure on whether I would be restricted to booting Linux only with the supplied kernels versions; translating from Chinese and VirtualBox are a complete PITA.

 

But not all is bad, because (at least according to this) VHD is fully supported by VirtualBox... :thumbsup:



#16 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 13226 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 30 July 2015 - 03:09 PM

Beg your pardon, Wonko, but you're the one who mentioned a multi-boot image -- I'm keen on multi-booting images, as in one image, one OS. :hmm:

 

 

Good, then you *need* NOT a VHD, and the reason you gave for choosing it is m00t.

A VHD is ONLY *needed* for booting natively some versions of Windows 7.

A RAW image is needed for booting Linux (or any version of Windows 7 non-natively), but you can use for any of these (in separate images) a "static" VHD.

A "static" VHD is a RAW image for all matters to the way the kpartx or the loop device mounts the device or to the way the non-native Windows 7 can boot from it.

 

 

:duff:

Wonko


  • ZEE likes this

#17 ZEE

ZEE

    Member

  • Members
  • 64 posts
  •  
    Portugal

Posted 31 July 2015 - 02:23 PM

Good, then you *need* NOT a VHD, and the reason you gave for choosing it is m00t (..)

 

:duff:

 

Always an enligthment to read your answers Wonko!!! thanx

 

If you came to advance more in this question please make a new topic...

 

Thanx


  • Porfyr likes this

#18 crashnburn

crashnburn

    Frequent Member

  • Advanced user
  • 111 posts

Posted 03 November 2015 - 06:23 PM

Why do you need vhd/vhdx, specifically? I ask because .img is a much more common standard for Linux when it comes to disk images.

 

So is there a how to guide to easily use

- a RAW .img with Linux (say Mint)

- just as a VHD is used with Windows for Native booting? 

 

And if thats doable and say we have few VHDs and RAW IMGs sitting on a HDD, how/ would we boot into them as / when needed. 



#19 reboot.pro-er

reboot.pro-er
  • Members
  • 3 posts
  •  
    Botswana

Posted 07 November 2015 - 03:05 PM

i guess this suggests that image-file has staying on ntfs (cause fat too less fo large file)???



#20 rawr

rawr

    Frequent Member

  • Advanced user
  • 163 posts

Posted 22 January 2016 - 09:18 PM

Always an enligthment to read your answers Wonko!!! thanx

+1 :thumbsup:
 


Mind you I am not expert in Linux (and certainly not at that level)...

 
Tinycore ( itsort of a bit like the 19mb minimal xp's )
has a good(CC Attribution-NonCommercial-ShareAlike license) pdf / book !

FYI

 

:ph34r:



#21 Porfyr

Porfyr

    Newbie

  • Members
  • 10 posts
  •  
    European Union

Posted 21 July 2016 - 02:58 PM

That thick-headed fool (me!) is still at it, and still failing to get this done... :alone:

 

From the wise input of Wonko, I surmised that having Windows 7 booting natively from VHD didn't automatically imply the same should be done to boot a Linux distro from an image file -- as he makes sure to clobber anyone who comes around mentioning VHDs to submit to the fact that static VHD are nothing more than RAW disk images with an extra sector at the end (e.g., see the previous discussion at http://reboot.pro/to...-in-grub4dos/).

 

Dismissing the fact that not all VHDs are static, and that static VHDs are not a requirement for native booting Windows 7 from a VHD -- after some more research, not a lot of testing and a grand-total of 0 results, it looks clear to me that the best route for multibooting OSes from image files is using native booting from VHD for Windows and then some kind of chainloading Grub4DOS to the native Windows bootloader for launching any desired Linux image file (any pointers for a quick and straightforward ways to do just that are more than welcome :book:).

 

Incidentally, I have a ready made (from VirtualBox) PeppermintOS disk image file lying around my root physical drive which obviously failed to natively boot (after attaching and activating) from the Windows bootloader. My current research is aimed at booting it via Grub4DOS.

 

So here's a link dump of stuff that looks promising in present context:


Edited by Porfyr, 21 July 2016 - 02:59 PM.


#22 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 13226 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 21 July 2016 - 05:40 PM

Good :), and just to introduce some degree of uncertainty in this thread,  grub4dos has been updated to provide some support to the "dynamic" type of VHD (besides the "static" ones, which are actually RAW images ;)) see:

http://grub4dos.chen....6a-2015-06-09/

http://reboot.pro/to...mic-vhd-to-ram/

 

but ONLY if --mem mapped.

 

To boot a Linux distro from a mapped disk image depends on the applicable (if any) kernel "cheatcodes", and thus depend on the specific Linux distro.

As an example:

https://forum.porteu...=62&t=324#p1651

Porteus uses the from_dev= and from_dir= cheatcodes, but it may depend on version:

https://forum.porteu...?t=4272&p=30784

Though I believe that most distro will need some modifications to the initrd to mount a loop or cloop device or integrate kpartx-boot.

 

Mapping a volume extents to an unused partition entry is the almost foolproof way, *similar* to this:

http://reboot.pro/to...brided/?p=88531

but of course this implies the need for an unused partition entry and writing to the MBR (which may or may not be possible on a specific setup), as a matter of fact in this case it's not anymore booting from an image but rather boot from a "normal" volume (that is inside a disk image inside another volume), more details here:
http://rmprepusb.blo...image-with.html

 

:duff:

Wonko



#23 Wonko the Insane

Wonko the Insane

    Frequent Member

  • Advanced user
  • 426 posts
  • Location:The Inside of the Asylum (gate is wide open)
  • Interests:That's for me to know and you to not find out.
  •  
    United States

Posted 24 July 2016 - 06:12 AM

I found VBoot/VMLite in another thread here, and I too am quite interested to know if it is possible to boot Linux from a VHD. The project, while old and seemingly out-of-date, presents a lot of possibilities. They have a prebuilt Ubuntu VHD, but I can't find much about installing other Linuxes to/booting from VHD. I suppose you could probably install Linux to VHD in a VM, but there would still be the issue of booting the VHD outside of a VM environment on real hardware. If a static, fixed size VHD is really nothing more than a plain, raw image with an appended footer, then this should be possible. Linux can already be booted from a raw IMG, I've been doing this on my phone for awhile. But since the VHD format was primarily created by and maintained by Microsoft, does this mean that VHD booting is entirely dependent on a Windows boot loader? I would like to find a way to do this either with or VBoot/VMLite, since a VHD has multiple benefits like portability, ease of snapshotting, etc. Even better would be to find a way to boot a generic raw disk image in an organized way that is much like how VBoot/VMLite already does.



#24 Wonko the Insane

Wonko the Insane

    Frequent Member

  • Advanced user
  • 426 posts
  • Location:The Inside of the Asylum (gate is wide open)
  • Interests:That's for me to know and you to not find out.
  •  
    United States

Posted 25 July 2016 - 07:25 PM

If what I'm reading is correct, then any Linux can be booted from a VHD as long as:

 

1. The VHD file is mounted as a loop device on boot

2. Some kind of boot loader is installed somewhere that can chainload the VHD

3. The correct hooks are set in the initramfs/kernel

 

Am I missing something? I would like to test this in a VM before trying it on real hardware (and possibly encountering big issues).

 

A few questions:

 

1. Linux in a VHD can be snapshotted, and ran (for instance) in RAM or some other way so that any changes are discarded on power off/reboot (and optionally saved to disk)? Is a VHD file considered an NTFS file with NTFS characteristics, or just a pure raw image with an appended footer that most utilities will ignore? This is what I've read in a blog.

2. Windows boot loader is needed?

3. The VHD will remain mounted after the transition from real mode to protected mode is made? If not, how to ensure that it remains mounted?

 

Is VBoot/VMLite a good way to accomplish this, or are there better ways?



#25 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 13226 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 25 July 2016 - 08:01 PM


A few questions:
 
1. Linux in a VHD can be snapshotted, and ran (for instance) in RAM or some other way so that any changes are discarded on power off/reboot (and optionally saved to disk)? Is a VHD file considered an NTFS file with NTFS characteristics, or just a pure raw image with an appended footer that most utilities will ignore? This is what I've read in a blog.
2. Windows boot loader is needed?
3. The VHD will remain mounted after the transition from real mode to protected mode is made? If not, how to ensure that it remains mounted?
 
Is VBoot/VMLite a good way to accomplish this, or are there better ways?

 

 

1. It depends on the type of VHD (wasn't it clear, a fixed type VHD is a RAW image with a single sector appended :frusty:) and on the specific driver you use to access/mount it. Of course RAW or fixed type vhd are images of a whole disk, while what is mounted is the (NTFS or FAT or whatever) volume/partition inside it,

2. No, unless you want to load windows.

3. No, it is not the way it works, not in windows, not in Linux, there is a (very brief) moment in which the image is not "mapped" or "mounted" by anything, the grub4dos or GRUB 2 "maps" the image just to read the kernel and the initrd, as soon as the kernel starts the mapping is lost and as soon as the initial ramdisk contents are executed the images is (should be) "mounted" again. This is the normal way both Windows NT and Linux boot, the boot volume is re-discovered in protected mode, the difficulties with an image are related to the fact that the built-in mechanism re-discovers by default "real" hardware and not an image (unless this mounting is forced in an early executed script).

 

But aren't you already booting Linux from a RAW image?

 


 Linux can already be booted from a raw IMG, I've been doing this on my phone for awhile. 

 

If it wasn't clear enough :whistling:, a fixed VHD is a RAW image with a sector appended (Conectix "descriptive" sector).

 

:duff:

Wonko







Also tagged with one or more of these keywords: linux, windows, boot, vhd, image-file, howto

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users