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 To Upgrade Debian 8,9,10 to Debian 12 Bookworm
  • Linux dhcp dhclient Mint Redhat Ubuntu Debian How To Use Local Domain DNS Server Instead of ISPs
  • Docker dockerd swarm high CPU usage cause solution
  • Docker Minimum Requirements/How Efficient is Docker? How Much Memory Does Dockerd Use?
  • qemu-nbd: Failed to set NBD socket solution qemu-nbd: Disconnect client, due to: Failed to read request: Unexpected end-of-file before all bytes were read
  • apache2 httpd apache server will not start [pid 22449:tid 139972160445760] AH00052: child pid 23248 exit signal Aborted (6) solution Mint Debian Ubuntu Redhat
  • How to use the FTDI USB serial cable to RJ45 adapter to connect to the console on Cisco/Juniper Switch Router Firewall in Linux Ubuntu Debian Redhat
  • How To Setup Python3 in Ubuntu Docker Image for AI Deep Learning
  • How to Configure NVIDIA GPUs with Docker on Ubuntu: A Comprehensive Guide for AI Deep Learning CUDA Solution
  • Linux Ubuntu Mint how to check nameservers when /etc/resolv.conf disabled solution
  • Docker cannot work on other overlayfs filesystems such as ecryptfs won't start overlayfs: filesystem on '/home/docker/overlay2/check-overlayfs-support130645871/upper' not supported as upperdir
  • Linux How To Access Original Contents of Directory Mounted Debian Mint CentOS Redhat Solution
  • ecryptfs how to manually encrypt your existing home directory or other directory
  • How to Reset CIPC Cisco IP Communicator for CME CUCM CallManager
  • Internet Explorer Cannot Download File "Your security settings do not allow for this file to be downloaded." Security Settings Solution
  • Linux How To Upgrade To The Latest Kernel Debian Mint Ubuntu
  • Firefox how to restore and backup saved passwords and history which files/location
  • Linux How To echo as root solution to use tee permission denied solution Ubuntu Debian Mint Redhat CentOS
  • Linux how to keep command line bash process running if you are disconnected or need to logout of SSH remotely
  • Linux swapping too much? How to check the swappiness and stop swapping