Howto Convert Xen Image to KVM

#count=10000 makes an image of 10000MB make sure your image is at least the same as your existing
dd if=/dev/zero of=yourimage.img bs=1M count=10000


# losetup -fv newimage.raw
# fdisk -cu /dev/loop0


# kpartx -a /dev/loop0

# dd if=<xenimage> of=/dev/mapper/loop0p1
# e2fsck -f /dev/mapper/loop0p1
# resize2fs /dev/mapper/loop0p1



# a lot of guides tell you to edit /etc/fstab and /boot/grub/menu.conf and make everything vda or vda1 but I have no idea why
# You need to make it /sda1 or whatever the root partition is

for i in dev sys proc; do mount -o bind /$i mnt/$i; done
mount -o bind <directory which contains raw image> mnt/mnt
chroot mnt

yum -y install grub

[root@testbox /]# echo "(hd0) /dev/vda" > /boot/grub/devices.map
[root@testbox /]# grub --no-floppy
Probing devices to guess BIOS drives. This may take a long time.


    GNU GRUB  version 0.97  (640K lower / 3072K upper memory)

 [ Minimal BASH-like line editing is supported.  For the first word, TAB
   lists possible command completions.  Anywhere else TAB lists the possible
   completions of a device/filename.]
grub> device (hd0) /mnt/kvmuser5900.img
device (hd0) /mnt/kvmuser5900.img
grub> root (hd0,0)
root (hd0,0)
 Filesystem type is ext2fs, partition type 0x83
grub> setup (hd0)
setup (hd0)
 Checking if "/boot/grub/stage1" exists... no
 Checking if "/grub/stage1" exists... no

Error 15t: File not found
grub>

grub
Probing devices to guess BIOS drives. This may take a long time.


    GNU GRUB  version 0.97  (640K lower / 3072K upper memory)

 [ Minimal BASH-like line editing is supported.  For the first word, TAB
   lists possible command completions.  Anywhere else TAB lists the possible
   completions of a device/filename.]
grub> device (hd0) /mnt/kvmuser5900.img
device (hd0) /mnt/kvmuser5900.img
grub> root (hd0,0)
root (hd0,0)
 Filesystem type is ext2fs, partition type 0x83
grub> setup (hd0)
setup (hd0)
 Checking if "/boot/grub/stage1" exists... yes
 Checking if "/boot/grub/stage2" exists... yes
 Checking if "/boot/grub/e2fs_stage1_5" exists... yes
 Running "embed /boot/grub/e2fs_stage1_5 (hd0)"...  27 sectors are embedded.
succeeded
 Running "install /boot/grub/stage1 (hd0) (hd0)1+27 p (hd0,0)/boot/grub/stage2 /boot/grub/grub.conf"... succeeded
Done.
grub> quit
quit



#edit grub.conf with the right options obviously dev=xvda is wrong you'll likely want /dev/sda1 as your root or whatever the partition is
[root@testbox /]# vi /boot/grub/grub.conf
#edit fstab to mount the right partition
[root@testbox /]# vi /etc/fstab
#setup inittab properly
#Comment the line containing xvc0.
[root@testbox /]# vi /etc/inittab
[root@testbox /]# exit


[root@testbox kvmuser5900]# umount mnt/*
umount: mnt/bin: not mounted
umount: mnt/boot: not mounted
umount: mnt/etc: not mounted
umount: mnt/home: not mounted
umount: mnt/lib: not mounted
umount: mnt/lost+found: not mounted
umount: mnt/media: not mounted
umount: mnt/mnt: not mounted
umount: mnt/opt: not mounted
umount: mnt/root: not mounted
umount: mnt/sbin: not mounted
umount: mnt/selinux: not mounted
umount: mnt/srv: not mounted
umount: mnt/tmp: not mounted
umount: mnt/usr: not mounted
umount: mnt/var: not mounted

[root@testbox kvmuser5900]# umount mnt/
[root@testbox kvmuser5900]# kpartx -d /dev/loop0
[root@testbox kvmuser5900]# losetup -d /dev/loop0


Tags:

howto, convert, xen, kvm, mb, existing, dd, dev, yourimage, img, bs, losetup, fv, newimage, fdisk, cu, kpartx, xenimage, mapper, fsck, resize, fs, guides, edit, etc, fstab, grub, conf, vda, sda, partition, sys, proc, mount, bind, mnt, directory, contains, chroot, yum, install, testbox, echo, quot, hd, devices, floppy, probing, bios, gnu, minimal, bash, editing, supported, tab, lists, completions, filename, kvmuser, filesystem, ext, fs_stage, _, embed, sectors, embedded, succeeded, xvda, ll, vi, inittab, containing, xvc, umount, bin, mounted, lib, opt, sbin, selinux, srv, tmp, usr, var,

Latest Articles

  • How high can a Xeon CPU get?
  • bash fix PATH environment variable "command not found" solution
  • Ubuntu Linux Mint Debian Redhat Youtube Cannot Play HD or 4K videos, dropped frames or high CPU usage with Nvidia or AMD Driver
  • hostapd example configuration for high speed AC on 5GHz using WPA2
  • hostapd how to enable and use WPS to connect wireless devices like printers
  • Dell Server Workstation iDRAC Dead after Firmware Update Solution R720, R320, R730
  • Cloned VM/Server/Computer in Linux won't boot and goes to initramfs busybox Solution
  • How To Add Windows 7 8 10 11 to GRUB Boot List Dual Booting
  • How to configure OpenDKIM on Linux with Postfix and setup bind zonefile
  • Debian Ubuntu 10/11/12 Linux how to get tftpd-hpa server setup tutorial
  • efibootmgr: option requires an argument -- 'd' efibootmgr version 15 grub-install.real: error: efibootmgr failed to register the boot entry: Operation not permitted.
  • Apache Error Won't start SSL Cert Issue Solution Unable to configure verify locations for client authentication SSL Library Error: 151441510 error:0906D066:PEM routines:PEM_read_bio:bad end line SSL Library Error: 185090057 error:0B084009:x509 certif
  • Linux Debian Mint Ubuntu Bridge br0 gets random IP
  • redis requirements
  • How to kill a docker swarm
  • docker swarm silly issues
  • isc-dhcp-server dhcpd how to get longer lease
  • nvidia cannot resume from sleep Comm: nvidia-sleep.sh Tainted: Linux Ubuntu Mint Debian
  • zfs and LUKS how to recover in Linux
  • [error] (28)No space left on device: Cannot create SSLMutex Apache Solution Linux CentOS Ubuntu Debian Mint