KVM guest OS from partition












2















I have a dual-boot configuration with Linux and Windows. Now, I would like to keep dual-boot setup and also be able to run Windows inside of KVM on Linux.



The following configuration works fine. I include the entire disk (/dev/sda) inside of KVM. For running Windows, I created an ISO image of grub (grub-mkresque), which has been configured to boot Windows from its partition (/dev/sda2). However, I am not happy with this solution, because the Windows guest then gets access to the whole disk with all partitions.



This, as commenters @telcoM & @kenneth-b-jensen had also pointed out, is/should_be part of my strategy to avoid corruption by avoiding concurrent access/mounting by both OSs.



The desired solution is only to include the Windows partition (/dev/sda2) and then start Windows from there. Because this partition is not bootable, I cannot boot Windows just from there. Because KVM apparently binds the single partition to a disk with its own partition table, grub from my image cannot find the corresponding partition from which to boot.



I need to finalize the configuration or some other idea to get a working configuration.




  • Use VirtualBox because it provides the possibility to create an image for raw disk access keeping the partitioning table, but specifying only the necessary partitions. IMHO, one should avoid this, as KVM brings more performance.


  • Find a solution to keep the partition table (as described above) with KVM.


  • Set up grub to use the proper partition inside of KVM. I would like to receive expert guidance on configuring grub according to the goals.











share|improve this question





























    2















    I have a dual-boot configuration with Linux and Windows. Now, I would like to keep dual-boot setup and also be able to run Windows inside of KVM on Linux.



    The following configuration works fine. I include the entire disk (/dev/sda) inside of KVM. For running Windows, I created an ISO image of grub (grub-mkresque), which has been configured to boot Windows from its partition (/dev/sda2). However, I am not happy with this solution, because the Windows guest then gets access to the whole disk with all partitions.



    This, as commenters @telcoM & @kenneth-b-jensen had also pointed out, is/should_be part of my strategy to avoid corruption by avoiding concurrent access/mounting by both OSs.



    The desired solution is only to include the Windows partition (/dev/sda2) and then start Windows from there. Because this partition is not bootable, I cannot boot Windows just from there. Because KVM apparently binds the single partition to a disk with its own partition table, grub from my image cannot find the corresponding partition from which to boot.



    I need to finalize the configuration or some other idea to get a working configuration.




    • Use VirtualBox because it provides the possibility to create an image for raw disk access keeping the partitioning table, but specifying only the necessary partitions. IMHO, one should avoid this, as KVM brings more performance.


    • Find a solution to keep the partition table (as described above) with KVM.


    • Set up grub to use the proper partition inside of KVM. I would like to receive expert guidance on configuring grub according to the goals.











    share|improve this question



























      2












      2








      2








      I have a dual-boot configuration with Linux and Windows. Now, I would like to keep dual-boot setup and also be able to run Windows inside of KVM on Linux.



      The following configuration works fine. I include the entire disk (/dev/sda) inside of KVM. For running Windows, I created an ISO image of grub (grub-mkresque), which has been configured to boot Windows from its partition (/dev/sda2). However, I am not happy with this solution, because the Windows guest then gets access to the whole disk with all partitions.



      This, as commenters @telcoM & @kenneth-b-jensen had also pointed out, is/should_be part of my strategy to avoid corruption by avoiding concurrent access/mounting by both OSs.



      The desired solution is only to include the Windows partition (/dev/sda2) and then start Windows from there. Because this partition is not bootable, I cannot boot Windows just from there. Because KVM apparently binds the single partition to a disk with its own partition table, grub from my image cannot find the corresponding partition from which to boot.



      I need to finalize the configuration or some other idea to get a working configuration.




      • Use VirtualBox because it provides the possibility to create an image for raw disk access keeping the partitioning table, but specifying only the necessary partitions. IMHO, one should avoid this, as KVM brings more performance.


      • Find a solution to keep the partition table (as described above) with KVM.


      • Set up grub to use the proper partition inside of KVM. I would like to receive expert guidance on configuring grub according to the goals.











      share|improve this question
















      I have a dual-boot configuration with Linux and Windows. Now, I would like to keep dual-boot setup and also be able to run Windows inside of KVM on Linux.



      The following configuration works fine. I include the entire disk (/dev/sda) inside of KVM. For running Windows, I created an ISO image of grub (grub-mkresque), which has been configured to boot Windows from its partition (/dev/sda2). However, I am not happy with this solution, because the Windows guest then gets access to the whole disk with all partitions.



      This, as commenters @telcoM & @kenneth-b-jensen had also pointed out, is/should_be part of my strategy to avoid corruption by avoiding concurrent access/mounting by both OSs.



      The desired solution is only to include the Windows partition (/dev/sda2) and then start Windows from there. Because this partition is not bootable, I cannot boot Windows just from there. Because KVM apparently binds the single partition to a disk with its own partition table, grub from my image cannot find the corresponding partition from which to boot.



      I need to finalize the configuration or some other idea to get a working configuration.




      • Use VirtualBox because it provides the possibility to create an image for raw disk access keeping the partitioning table, but specifying only the necessary partitions. IMHO, one should avoid this, as KVM brings more performance.


      • Find a solution to keep the partition table (as described above) with KVM.


      • Set up grub to use the proper partition inside of KVM. I would like to receive expert guidance on configuring grub according to the goals.








      partition grub2 kvm






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Feb 9 at 18:36









      Rui F Ribeiro

      40.3k1479137




      40.3k1479137










      asked Feb 6 at 16:53









      CuporaCupora

      332




      332






















          3 Answers
          3






          active

          oldest

          votes


















          0














          I've tried to run the same Windows disk alternately on hardware and inside a virtual machine, but always failed because the devices presented inside the virtual machine are different than the actual hardware.



          But drawing on your "some other idea" clause, let me explain how I run Linux and Windows on the same machine.



          Windows is running in a KVM virtual machine, but virt-viewer has control of one virtual console. It appears for all the world as if it's a dedicated Windows machine when I switch to that console. And I can log into and out of Linux and Windows independently. (And with Cygwin installed on Windows, I can ssh between them.)



          These are roughly the steps I took to set it up. I downloaded the .iso from Microsoft and bought a license separately. You may be able to reinstall your existing Windows license.



          sudo vgcreate vg0 /dev/sd...
          sudo lvcreate --size 128G --name win10 vg0
          sudo virt-install --name Windows --connect qemu:///system --virt-type kvm --disk path=/dev/vg0/win10,format=raw --cdrom '<path>/Win10_1607_English_x64.iso' --network bridge=br0 --video qxl --chanel spicevm,target_type=virtio --graphics spice,listen=0.0.0.0,port=5900 --os-variant win10 --memorybacking nosharepages=true --memory 2048 --vcpus 1


          I've created a network bridge device br0 on the Linux host so I can transparently connect virtual machines. But that's a separate topic.



          The virt-install command brings up virt-viewer automatically the first time, which brought up the Windows 10 installation program. The only disk it sees is the virtual disk I created and put on the virt-install command-line. Then I boot it subsequently:



          virsh --connect qemu:///system start Windows


          That starts the machine, but doesn't view the output. To view the output, I switch to an unused virtual console pressing e.g. CTRLALTF6 and enter this command. Note that we're starting an X app (virt-viewer) directly on an X server with no window manager.



          The -k switch puts virt-viewer in kiosk mode which effectively hides the fact that it's really running in a virtual machine.



          startx /usr/bin/virt-viewer -a -k -r -w -c qemu:///system Windows -- :6  -config CtrlAltBksp.conf -nolisten tcp -novtswitch


          The CtrlAltBksp.conf file is optional. It allows you to shutdown virt-viewer by pressing CTRLALTBackspace. It must be put in /etc/X11/ on the host, or another directory that xorg knows about. Here it is:



          Section "ServerFlags"
          Option "DontZap" "false"
          EndSection
          Section "InputClass"
          Identifier "CTRL_ALT_BACKSPACE"
          MatchIsKeyboard "on"
          Option "XkbOptions" "terminate:ctrl_alt_bksp"
          EndSection


          Note: You don't need to install with spice and qxl as I did, but if you do, it's best to install the spice tools.






          share|improve this answer































            0














            I've ran a few operating systems installed for dual-boot side-by-side with QEMU residing on disks, but I don't think ever one without a bootloader.



            If you're booting with UEFI, you will need to use OVMF for QEMU, which means things have gotten much hairier and out of the scope of my knowledge.



            Try installing & configuring GRUB on the Windows partition, or booting a Windows rescue/install media with QEMU (otherwise, Windows will eat GRUB) and reinstalling to get a Windows bootloader back.
            To install GRUB, use grub-install /dev/sdxY, mount the filesystem, and run grub-mkconfig -o /mnt/grub/grub.cfg. Then, copy over just what you need from your existing grub.cfg, and edit it as necessary -- feel free to ask for help in this thread.



            Another option is doing some research on just installing a bootloader natively on Windows.



            The nuclear option is something along the lines of creating an .img file the same size as your Windows partition with qemu-img, reinstalling Windows via QEMU to that file, and copying everything after a certain offset from the partition (probably just past the first 1024 cylinders or so) to the .img file with dd.



            A very dangerous option is to continue using your existing GRUB to chain-boot into windows by using all of your disks with the read-only option. See @telcoM's comment on the OP; DO NOT RUN A VIRTUAL MACHINE ON A DISK THAT IS IN-USE BY THE HOST! THE FILESYSTEM WILL BE CORRUPTED AND UNRECOVERABLE! (ONLY unless it's used read-only by the guest.) Try qemu-xxxxxxx -drive file=/dev/sdxX,format=raw,readonly.



            Nonetheless, QEMU can run a raw disk:



            qemu-xxxxxxxx -drive file=/dev/sdxY,format=raw (see man 1 qemu & search for -drive for more information).



            If you haven't much experience with QEMU/KVM, running & configuring it directly from the command-line can be intimidating and frustrating -- consider a front-end for your health.






            share|improve this answer


























            • I've added an answer about creating an abstraction of the physical disk with same size/"geometry"/partition-table etc as the real disk, but with the Linux partitions "blanked" out by using zero targets in the dmsetup table map. Sounds like that would fit some of your usecases too.

              – Alex Stragies
              Feb 8 at 16:25



















            0














            You can use dmsetup from the device-mapper tools with the --table option to "construct" a block-device resembling your /dev/sda by specifying a table file (Search "Table Format").



            You could use read-only maps (or copies) of some partitions like the EFIBOOT partition, and the gpt/mbrpartition-table, along with some zero targets for "replacing" your Linux-partitions in that map. Just make sure you include the real Windows partition(s) in the table map, and at the right location in the table.



            I have used this in the past for a similar endeavor, and this is most likely the mechanism virtualbox uses under the hood on Linux to construct of custom, composed block devices.



            Make sure, none of your partitions are mounted/accessed by more than one OS at a time.






            share|improve this answer

























              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "106"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f499105%2fkvm-guest-os-from-partition%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              I've tried to run the same Windows disk alternately on hardware and inside a virtual machine, but always failed because the devices presented inside the virtual machine are different than the actual hardware.



              But drawing on your "some other idea" clause, let me explain how I run Linux and Windows on the same machine.



              Windows is running in a KVM virtual machine, but virt-viewer has control of one virtual console. It appears for all the world as if it's a dedicated Windows machine when I switch to that console. And I can log into and out of Linux and Windows independently. (And with Cygwin installed on Windows, I can ssh between them.)



              These are roughly the steps I took to set it up. I downloaded the .iso from Microsoft and bought a license separately. You may be able to reinstall your existing Windows license.



              sudo vgcreate vg0 /dev/sd...
              sudo lvcreate --size 128G --name win10 vg0
              sudo virt-install --name Windows --connect qemu:///system --virt-type kvm --disk path=/dev/vg0/win10,format=raw --cdrom '<path>/Win10_1607_English_x64.iso' --network bridge=br0 --video qxl --chanel spicevm,target_type=virtio --graphics spice,listen=0.0.0.0,port=5900 --os-variant win10 --memorybacking nosharepages=true --memory 2048 --vcpus 1


              I've created a network bridge device br0 on the Linux host so I can transparently connect virtual machines. But that's a separate topic.



              The virt-install command brings up virt-viewer automatically the first time, which brought up the Windows 10 installation program. The only disk it sees is the virtual disk I created and put on the virt-install command-line. Then I boot it subsequently:



              virsh --connect qemu:///system start Windows


              That starts the machine, but doesn't view the output. To view the output, I switch to an unused virtual console pressing e.g. CTRLALTF6 and enter this command. Note that we're starting an X app (virt-viewer) directly on an X server with no window manager.



              The -k switch puts virt-viewer in kiosk mode which effectively hides the fact that it's really running in a virtual machine.



              startx /usr/bin/virt-viewer -a -k -r -w -c qemu:///system Windows -- :6  -config CtrlAltBksp.conf -nolisten tcp -novtswitch


              The CtrlAltBksp.conf file is optional. It allows you to shutdown virt-viewer by pressing CTRLALTBackspace. It must be put in /etc/X11/ on the host, or another directory that xorg knows about. Here it is:



              Section "ServerFlags"
              Option "DontZap" "false"
              EndSection
              Section "InputClass"
              Identifier "CTRL_ALT_BACKSPACE"
              MatchIsKeyboard "on"
              Option "XkbOptions" "terminate:ctrl_alt_bksp"
              EndSection


              Note: You don't need to install with spice and qxl as I did, but if you do, it's best to install the spice tools.






              share|improve this answer




























                0














                I've tried to run the same Windows disk alternately on hardware and inside a virtual machine, but always failed because the devices presented inside the virtual machine are different than the actual hardware.



                But drawing on your "some other idea" clause, let me explain how I run Linux and Windows on the same machine.



                Windows is running in a KVM virtual machine, but virt-viewer has control of one virtual console. It appears for all the world as if it's a dedicated Windows machine when I switch to that console. And I can log into and out of Linux and Windows independently. (And with Cygwin installed on Windows, I can ssh between them.)



                These are roughly the steps I took to set it up. I downloaded the .iso from Microsoft and bought a license separately. You may be able to reinstall your existing Windows license.



                sudo vgcreate vg0 /dev/sd...
                sudo lvcreate --size 128G --name win10 vg0
                sudo virt-install --name Windows --connect qemu:///system --virt-type kvm --disk path=/dev/vg0/win10,format=raw --cdrom '<path>/Win10_1607_English_x64.iso' --network bridge=br0 --video qxl --chanel spicevm,target_type=virtio --graphics spice,listen=0.0.0.0,port=5900 --os-variant win10 --memorybacking nosharepages=true --memory 2048 --vcpus 1


                I've created a network bridge device br0 on the Linux host so I can transparently connect virtual machines. But that's a separate topic.



                The virt-install command brings up virt-viewer automatically the first time, which brought up the Windows 10 installation program. The only disk it sees is the virtual disk I created and put on the virt-install command-line. Then I boot it subsequently:



                virsh --connect qemu:///system start Windows


                That starts the machine, but doesn't view the output. To view the output, I switch to an unused virtual console pressing e.g. CTRLALTF6 and enter this command. Note that we're starting an X app (virt-viewer) directly on an X server with no window manager.



                The -k switch puts virt-viewer in kiosk mode which effectively hides the fact that it's really running in a virtual machine.



                startx /usr/bin/virt-viewer -a -k -r -w -c qemu:///system Windows -- :6  -config CtrlAltBksp.conf -nolisten tcp -novtswitch


                The CtrlAltBksp.conf file is optional. It allows you to shutdown virt-viewer by pressing CTRLALTBackspace. It must be put in /etc/X11/ on the host, or another directory that xorg knows about. Here it is:



                Section "ServerFlags"
                Option "DontZap" "false"
                EndSection
                Section "InputClass"
                Identifier "CTRL_ALT_BACKSPACE"
                MatchIsKeyboard "on"
                Option "XkbOptions" "terminate:ctrl_alt_bksp"
                EndSection


                Note: You don't need to install with spice and qxl as I did, but if you do, it's best to install the spice tools.






                share|improve this answer


























                  0












                  0








                  0







                  I've tried to run the same Windows disk alternately on hardware and inside a virtual machine, but always failed because the devices presented inside the virtual machine are different than the actual hardware.



                  But drawing on your "some other idea" clause, let me explain how I run Linux and Windows on the same machine.



                  Windows is running in a KVM virtual machine, but virt-viewer has control of one virtual console. It appears for all the world as if it's a dedicated Windows machine when I switch to that console. And I can log into and out of Linux and Windows independently. (And with Cygwin installed on Windows, I can ssh between them.)



                  These are roughly the steps I took to set it up. I downloaded the .iso from Microsoft and bought a license separately. You may be able to reinstall your existing Windows license.



                  sudo vgcreate vg0 /dev/sd...
                  sudo lvcreate --size 128G --name win10 vg0
                  sudo virt-install --name Windows --connect qemu:///system --virt-type kvm --disk path=/dev/vg0/win10,format=raw --cdrom '<path>/Win10_1607_English_x64.iso' --network bridge=br0 --video qxl --chanel spicevm,target_type=virtio --graphics spice,listen=0.0.0.0,port=5900 --os-variant win10 --memorybacking nosharepages=true --memory 2048 --vcpus 1


                  I've created a network bridge device br0 on the Linux host so I can transparently connect virtual machines. But that's a separate topic.



                  The virt-install command brings up virt-viewer automatically the first time, which brought up the Windows 10 installation program. The only disk it sees is the virtual disk I created and put on the virt-install command-line. Then I boot it subsequently:



                  virsh --connect qemu:///system start Windows


                  That starts the machine, but doesn't view the output. To view the output, I switch to an unused virtual console pressing e.g. CTRLALTF6 and enter this command. Note that we're starting an X app (virt-viewer) directly on an X server with no window manager.



                  The -k switch puts virt-viewer in kiosk mode which effectively hides the fact that it's really running in a virtual machine.



                  startx /usr/bin/virt-viewer -a -k -r -w -c qemu:///system Windows -- :6  -config CtrlAltBksp.conf -nolisten tcp -novtswitch


                  The CtrlAltBksp.conf file is optional. It allows you to shutdown virt-viewer by pressing CTRLALTBackspace. It must be put in /etc/X11/ on the host, or another directory that xorg knows about. Here it is:



                  Section "ServerFlags"
                  Option "DontZap" "false"
                  EndSection
                  Section "InputClass"
                  Identifier "CTRL_ALT_BACKSPACE"
                  MatchIsKeyboard "on"
                  Option "XkbOptions" "terminate:ctrl_alt_bksp"
                  EndSection


                  Note: You don't need to install with spice and qxl as I did, but if you do, it's best to install the spice tools.






                  share|improve this answer













                  I've tried to run the same Windows disk alternately on hardware and inside a virtual machine, but always failed because the devices presented inside the virtual machine are different than the actual hardware.



                  But drawing on your "some other idea" clause, let me explain how I run Linux and Windows on the same machine.



                  Windows is running in a KVM virtual machine, but virt-viewer has control of one virtual console. It appears for all the world as if it's a dedicated Windows machine when I switch to that console. And I can log into and out of Linux and Windows independently. (And with Cygwin installed on Windows, I can ssh between them.)



                  These are roughly the steps I took to set it up. I downloaded the .iso from Microsoft and bought a license separately. You may be able to reinstall your existing Windows license.



                  sudo vgcreate vg0 /dev/sd...
                  sudo lvcreate --size 128G --name win10 vg0
                  sudo virt-install --name Windows --connect qemu:///system --virt-type kvm --disk path=/dev/vg0/win10,format=raw --cdrom '<path>/Win10_1607_English_x64.iso' --network bridge=br0 --video qxl --chanel spicevm,target_type=virtio --graphics spice,listen=0.0.0.0,port=5900 --os-variant win10 --memorybacking nosharepages=true --memory 2048 --vcpus 1


                  I've created a network bridge device br0 on the Linux host so I can transparently connect virtual machines. But that's a separate topic.



                  The virt-install command brings up virt-viewer automatically the first time, which brought up the Windows 10 installation program. The only disk it sees is the virtual disk I created and put on the virt-install command-line. Then I boot it subsequently:



                  virsh --connect qemu:///system start Windows


                  That starts the machine, but doesn't view the output. To view the output, I switch to an unused virtual console pressing e.g. CTRLALTF6 and enter this command. Note that we're starting an X app (virt-viewer) directly on an X server with no window manager.



                  The -k switch puts virt-viewer in kiosk mode which effectively hides the fact that it's really running in a virtual machine.



                  startx /usr/bin/virt-viewer -a -k -r -w -c qemu:///system Windows -- :6  -config CtrlAltBksp.conf -nolisten tcp -novtswitch


                  The CtrlAltBksp.conf file is optional. It allows you to shutdown virt-viewer by pressing CTRLALTBackspace. It must be put in /etc/X11/ on the host, or another directory that xorg knows about. Here it is:



                  Section "ServerFlags"
                  Option "DontZap" "false"
                  EndSection
                  Section "InputClass"
                  Identifier "CTRL_ALT_BACKSPACE"
                  MatchIsKeyboard "on"
                  Option "XkbOptions" "terminate:ctrl_alt_bksp"
                  EndSection


                  Note: You don't need to install with spice and qxl as I did, but if you do, it's best to install the spice tools.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Feb 6 at 20:51









                  Ken JacksonKen Jackson

                  1063




                  1063

























                      0














                      I've ran a few operating systems installed for dual-boot side-by-side with QEMU residing on disks, but I don't think ever one without a bootloader.



                      If you're booting with UEFI, you will need to use OVMF for QEMU, which means things have gotten much hairier and out of the scope of my knowledge.



                      Try installing & configuring GRUB on the Windows partition, or booting a Windows rescue/install media with QEMU (otherwise, Windows will eat GRUB) and reinstalling to get a Windows bootloader back.
                      To install GRUB, use grub-install /dev/sdxY, mount the filesystem, and run grub-mkconfig -o /mnt/grub/grub.cfg. Then, copy over just what you need from your existing grub.cfg, and edit it as necessary -- feel free to ask for help in this thread.



                      Another option is doing some research on just installing a bootloader natively on Windows.



                      The nuclear option is something along the lines of creating an .img file the same size as your Windows partition with qemu-img, reinstalling Windows via QEMU to that file, and copying everything after a certain offset from the partition (probably just past the first 1024 cylinders or so) to the .img file with dd.



                      A very dangerous option is to continue using your existing GRUB to chain-boot into windows by using all of your disks with the read-only option. See @telcoM's comment on the OP; DO NOT RUN A VIRTUAL MACHINE ON A DISK THAT IS IN-USE BY THE HOST! THE FILESYSTEM WILL BE CORRUPTED AND UNRECOVERABLE! (ONLY unless it's used read-only by the guest.) Try qemu-xxxxxxx -drive file=/dev/sdxX,format=raw,readonly.



                      Nonetheless, QEMU can run a raw disk:



                      qemu-xxxxxxxx -drive file=/dev/sdxY,format=raw (see man 1 qemu & search for -drive for more information).



                      If you haven't much experience with QEMU/KVM, running & configuring it directly from the command-line can be intimidating and frustrating -- consider a front-end for your health.






                      share|improve this answer


























                      • I've added an answer about creating an abstraction of the physical disk with same size/"geometry"/partition-table etc as the real disk, but with the Linux partitions "blanked" out by using zero targets in the dmsetup table map. Sounds like that would fit some of your usecases too.

                        – Alex Stragies
                        Feb 8 at 16:25
















                      0














                      I've ran a few operating systems installed for dual-boot side-by-side with QEMU residing on disks, but I don't think ever one without a bootloader.



                      If you're booting with UEFI, you will need to use OVMF for QEMU, which means things have gotten much hairier and out of the scope of my knowledge.



                      Try installing & configuring GRUB on the Windows partition, or booting a Windows rescue/install media with QEMU (otherwise, Windows will eat GRUB) and reinstalling to get a Windows bootloader back.
                      To install GRUB, use grub-install /dev/sdxY, mount the filesystem, and run grub-mkconfig -o /mnt/grub/grub.cfg. Then, copy over just what you need from your existing grub.cfg, and edit it as necessary -- feel free to ask for help in this thread.



                      Another option is doing some research on just installing a bootloader natively on Windows.



                      The nuclear option is something along the lines of creating an .img file the same size as your Windows partition with qemu-img, reinstalling Windows via QEMU to that file, and copying everything after a certain offset from the partition (probably just past the first 1024 cylinders or so) to the .img file with dd.



                      A very dangerous option is to continue using your existing GRUB to chain-boot into windows by using all of your disks with the read-only option. See @telcoM's comment on the OP; DO NOT RUN A VIRTUAL MACHINE ON A DISK THAT IS IN-USE BY THE HOST! THE FILESYSTEM WILL BE CORRUPTED AND UNRECOVERABLE! (ONLY unless it's used read-only by the guest.) Try qemu-xxxxxxx -drive file=/dev/sdxX,format=raw,readonly.



                      Nonetheless, QEMU can run a raw disk:



                      qemu-xxxxxxxx -drive file=/dev/sdxY,format=raw (see man 1 qemu & search for -drive for more information).



                      If you haven't much experience with QEMU/KVM, running & configuring it directly from the command-line can be intimidating and frustrating -- consider a front-end for your health.






                      share|improve this answer


























                      • I've added an answer about creating an abstraction of the physical disk with same size/"geometry"/partition-table etc as the real disk, but with the Linux partitions "blanked" out by using zero targets in the dmsetup table map. Sounds like that would fit some of your usecases too.

                        – Alex Stragies
                        Feb 8 at 16:25














                      0












                      0








                      0







                      I've ran a few operating systems installed for dual-boot side-by-side with QEMU residing on disks, but I don't think ever one without a bootloader.



                      If you're booting with UEFI, you will need to use OVMF for QEMU, which means things have gotten much hairier and out of the scope of my knowledge.



                      Try installing & configuring GRUB on the Windows partition, or booting a Windows rescue/install media with QEMU (otherwise, Windows will eat GRUB) and reinstalling to get a Windows bootloader back.
                      To install GRUB, use grub-install /dev/sdxY, mount the filesystem, and run grub-mkconfig -o /mnt/grub/grub.cfg. Then, copy over just what you need from your existing grub.cfg, and edit it as necessary -- feel free to ask for help in this thread.



                      Another option is doing some research on just installing a bootloader natively on Windows.



                      The nuclear option is something along the lines of creating an .img file the same size as your Windows partition with qemu-img, reinstalling Windows via QEMU to that file, and copying everything after a certain offset from the partition (probably just past the first 1024 cylinders or so) to the .img file with dd.



                      A very dangerous option is to continue using your existing GRUB to chain-boot into windows by using all of your disks with the read-only option. See @telcoM's comment on the OP; DO NOT RUN A VIRTUAL MACHINE ON A DISK THAT IS IN-USE BY THE HOST! THE FILESYSTEM WILL BE CORRUPTED AND UNRECOVERABLE! (ONLY unless it's used read-only by the guest.) Try qemu-xxxxxxx -drive file=/dev/sdxX,format=raw,readonly.



                      Nonetheless, QEMU can run a raw disk:



                      qemu-xxxxxxxx -drive file=/dev/sdxY,format=raw (see man 1 qemu & search for -drive for more information).



                      If you haven't much experience with QEMU/KVM, running & configuring it directly from the command-line can be intimidating and frustrating -- consider a front-end for your health.






                      share|improve this answer















                      I've ran a few operating systems installed for dual-boot side-by-side with QEMU residing on disks, but I don't think ever one without a bootloader.



                      If you're booting with UEFI, you will need to use OVMF for QEMU, which means things have gotten much hairier and out of the scope of my knowledge.



                      Try installing & configuring GRUB on the Windows partition, or booting a Windows rescue/install media with QEMU (otherwise, Windows will eat GRUB) and reinstalling to get a Windows bootloader back.
                      To install GRUB, use grub-install /dev/sdxY, mount the filesystem, and run grub-mkconfig -o /mnt/grub/grub.cfg. Then, copy over just what you need from your existing grub.cfg, and edit it as necessary -- feel free to ask for help in this thread.



                      Another option is doing some research on just installing a bootloader natively on Windows.



                      The nuclear option is something along the lines of creating an .img file the same size as your Windows partition with qemu-img, reinstalling Windows via QEMU to that file, and copying everything after a certain offset from the partition (probably just past the first 1024 cylinders or so) to the .img file with dd.



                      A very dangerous option is to continue using your existing GRUB to chain-boot into windows by using all of your disks with the read-only option. See @telcoM's comment on the OP; DO NOT RUN A VIRTUAL MACHINE ON A DISK THAT IS IN-USE BY THE HOST! THE FILESYSTEM WILL BE CORRUPTED AND UNRECOVERABLE! (ONLY unless it's used read-only by the guest.) Try qemu-xxxxxxx -drive file=/dev/sdxX,format=raw,readonly.



                      Nonetheless, QEMU can run a raw disk:



                      qemu-xxxxxxxx -drive file=/dev/sdxY,format=raw (see man 1 qemu & search for -drive for more information).



                      If you haven't much experience with QEMU/KVM, running & configuring it directly from the command-line can be intimidating and frustrating -- consider a front-end for your health.







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Feb 8 at 7:43

























                      answered Feb 8 at 6:50









                      Kenneth B. JensenKenneth B. Jensen

                      57839




                      57839













                      • I've added an answer about creating an abstraction of the physical disk with same size/"geometry"/partition-table etc as the real disk, but with the Linux partitions "blanked" out by using zero targets in the dmsetup table map. Sounds like that would fit some of your usecases too.

                        – Alex Stragies
                        Feb 8 at 16:25



















                      • I've added an answer about creating an abstraction of the physical disk with same size/"geometry"/partition-table etc as the real disk, but with the Linux partitions "blanked" out by using zero targets in the dmsetup table map. Sounds like that would fit some of your usecases too.

                        – Alex Stragies
                        Feb 8 at 16:25

















                      I've added an answer about creating an abstraction of the physical disk with same size/"geometry"/partition-table etc as the real disk, but with the Linux partitions "blanked" out by using zero targets in the dmsetup table map. Sounds like that would fit some of your usecases too.

                      – Alex Stragies
                      Feb 8 at 16:25





                      I've added an answer about creating an abstraction of the physical disk with same size/"geometry"/partition-table etc as the real disk, but with the Linux partitions "blanked" out by using zero targets in the dmsetup table map. Sounds like that would fit some of your usecases too.

                      – Alex Stragies
                      Feb 8 at 16:25











                      0














                      You can use dmsetup from the device-mapper tools with the --table option to "construct" a block-device resembling your /dev/sda by specifying a table file (Search "Table Format").



                      You could use read-only maps (or copies) of some partitions like the EFIBOOT partition, and the gpt/mbrpartition-table, along with some zero targets for "replacing" your Linux-partitions in that map. Just make sure you include the real Windows partition(s) in the table map, and at the right location in the table.



                      I have used this in the past for a similar endeavor, and this is most likely the mechanism virtualbox uses under the hood on Linux to construct of custom, composed block devices.



                      Make sure, none of your partitions are mounted/accessed by more than one OS at a time.






                      share|improve this answer






























                        0














                        You can use dmsetup from the device-mapper tools with the --table option to "construct" a block-device resembling your /dev/sda by specifying a table file (Search "Table Format").



                        You could use read-only maps (or copies) of some partitions like the EFIBOOT partition, and the gpt/mbrpartition-table, along with some zero targets for "replacing" your Linux-partitions in that map. Just make sure you include the real Windows partition(s) in the table map, and at the right location in the table.



                        I have used this in the past for a similar endeavor, and this is most likely the mechanism virtualbox uses under the hood on Linux to construct of custom, composed block devices.



                        Make sure, none of your partitions are mounted/accessed by more than one OS at a time.






                        share|improve this answer




























                          0












                          0








                          0







                          You can use dmsetup from the device-mapper tools with the --table option to "construct" a block-device resembling your /dev/sda by specifying a table file (Search "Table Format").



                          You could use read-only maps (or copies) of some partitions like the EFIBOOT partition, and the gpt/mbrpartition-table, along with some zero targets for "replacing" your Linux-partitions in that map. Just make sure you include the real Windows partition(s) in the table map, and at the right location in the table.



                          I have used this in the past for a similar endeavor, and this is most likely the mechanism virtualbox uses under the hood on Linux to construct of custom, composed block devices.



                          Make sure, none of your partitions are mounted/accessed by more than one OS at a time.






                          share|improve this answer















                          You can use dmsetup from the device-mapper tools with the --table option to "construct" a block-device resembling your /dev/sda by specifying a table file (Search "Table Format").



                          You could use read-only maps (or copies) of some partitions like the EFIBOOT partition, and the gpt/mbrpartition-table, along with some zero targets for "replacing" your Linux-partitions in that map. Just make sure you include the real Windows partition(s) in the table map, and at the right location in the table.



                          I have used this in the past for a similar endeavor, and this is most likely the mechanism virtualbox uses under the hood on Linux to construct of custom, composed block devices.



                          Make sure, none of your partitions are mounted/accessed by more than one OS at a time.







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Feb 8 at 16:03

























                          answered Feb 8 at 11:21









                          Alex StragiesAlex Stragies

                          3,3151639




                          3,3151639






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Unix & Linux Stack Exchange!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f499105%2fkvm-guest-os-from-partition%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              How to make a Squid Proxy server?

                              第一次世界大戦

                              Touch on Surface Book