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

  • Cisco Switches How To Get Of Port Line Status Console Messages
  • Cisco DHCP Snooping Relay Setup Information
  • Cisco Switch Setup Guide Command List
  • Cisco 2960 Switch Reset To Factory Defaults
  • How To Boot Cisco CUCM UCSInstall 8.6, 10, 11 and 12 on KVM/Proxmox
  • VBOX VirtualBox How To Import Raw .img Disk File
  • Windows Server 2012, 2016, 2019 How To Install and Missing Disabled Telnet Client
  • proxmox vm networking breaks when you restart your network on the hostnode
  • Linux ln symlink how to update existing symbolic link
  • Ubuntu 18.04 / Linux Mint 19.1 Cannot Type or Login - solution
  • LUKS Hard Drive Encryption on Linux Mint Ubuntu Debian etc how to mount encrypted hard drive
  • How to use nmap locate other machines/computers/servers on your network using nmap
  • Linux Mint 18.2 Create Config File To Start Application Upon Login
  • Dell Wyse Thin Client BIOS Access Key
  • sudoers file in /etc warning about comments/includes!
  • Centos 7 Reallocate logical volume space to another
  • lvm how to reduce volume size
  • letsencrypt certbot error "Unable to find a virtual host listening on port 80 which is currently needed for Certbot to prove to the CA that you control your domain. Please add a virtual host for port 80."
  • SSH error cannot Forward or Listen "bind: Cannot assign requested address"
  • X11 SSH Linux Forwarding Error