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= 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 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

  • Centos 7 how to save iptables rules like Centos 6
  • nfs tuning maximum amount of connections
  • qemu-kvm error "Could not initialize SDL(No available video device) - exiting"
  • Centos 7 tftpd will not work with selinux enabled
  • Debian Ubuntu Mint Howto Create Bridge (br0)
  • How To Control Interface that dhcpd server listens to on Debian based Linux like Mint and Ubuntu
  • LUKS unable to type password to unlock during boot on Debian, Ubuntu and Mint
  • Debian Ubuntu and Linux Mint Broken Kernel After Date - New Extra Module Naming Convention
  • Wordpress overwrites and wipes out custom htaccess rules and changes soluton
  • Apache htaccess and mod_rewrite how to redirect and force all URLs and visitors to the SSL / HTTPS version
  • python 3 pip cannot install mysql module
  • QEMU-KVM won't boot Windows 2016 or 2019 server on an Intel Core i3
  • Virtualbox vbox not starting
  • Bind / named not responding to queries solution
  • Linux Mint How To Set Desktop Background Image From Bash Prompt CLI
  • ImageMagick Convert PDF Not Authorized
  • ImageMagick Converted PDF to JPEG some files have a black background solution
  • Linux Mint Mate Customize the Lock screen messages and hide username and real name
  • Ubuntu/Gnome/Mint/Centos How To Take a partial screenshot
  • ssh how to verify your host key / avoid MIM attacks