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

  • Cisco Unified Communication Manager (CUCM) - How To Add Phones
  • pptp / pptpd not working in DD-WRT iptables / router
  • systemd-journald high memory usage solution
  • How to Install FreePBX in Linux Debian Ubuntu Mint Guide
  • How To Install Cisco's CUCM (Cisco Unified Communication Manager) 12 Guide
  • Linux Ubuntu Redhat How To Extract Images from PDF
  • Linux and Windows Dual Boot Issue NIC Won't work After Booting Windows
  • Cisco CME How To Enable ACD hunt groups
  • How to install gns3 on Linux Ubuntu Mint
  • How to convert audio for Asterisk .wav format
  • Using Cisco CME Router with Asterisk as a dial-peer
  • Cisco CME How To Configure SIP Trunk VOIP
  • Virtualbox host Only Network Error Failed to save host network interface parameter - Cannot change gateway IP of host only network
  • Cisco CME and C7200 Router Testing and Learning Environment on Ubuntu 20+ Setup Tutorial Guide
  • Abusive IP ranges blacklist
  • How to Install Any OS on a Physical Drive from Windows Using VMware Workstation (Linux, Windows, BSD)
  • CDN Cloudflare how to set and preserve the real IP of the client without modifying application code on Apache
  • CentOS 7 fix Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=container error was 14: curl#6 -
  • Ubuntu Debian How To Install Recommended Packages Automatically
  • How to set Linux Ubuntu Redhat Debian Command Line http https socks proxy for yum apt