Have been able to resolve some of the issues, resulting in making a bootable vm image from a running system.
Issue:
- No effect.
- No effect.
- This is actually 1-issue and 1-mistake, I had a custom xorg.conf with a specific driver, removing the xorg.conf makes booting qemu into graphical mode. The other is due to plain slowness of qemu, you just need to wait for a long time for lightdm to startup.
- No effect.
I've summarized the entire process in a script for convinience:
#!/bin/bash
# create bootable image from running linux distro
IMG_format="raw"
IMG_name="debian8"
IMG_size="13G"
LNX_image="vmlinuz-4.4.3"
LNX_initrd="initrd.img-4.4.3"
LNX_rootdev="/dev/sda"
TMPDIR="/mnt/vmd/"
WRKDIR="/media/domnic/tmp1"
create_img(){
IMG="$WRKDIR/$IMG_name.$IMG_format"
echo "image => $IMG"
if [ -a "$IMG"]; then
echo "vm [$IMG] already exists... skipped!"
else
if [ "vdi" == "$IMG_format" ]; then
#- create .vdi
VBoxManage createhd --filename $IMG --size $(( IMG_size * 1024 ))
else
#- or create image on .raw disk
fallocate -l $IMG_size $IMG
mkfs.ext4 -F $IMG
fi
fi
}
mount_img(){
echo "mount => $TMPDIR"
IMG="$WRKDIR/$IMG_name.$IMG_format"
if [ ! -d "$TMPDIR" ]; then
mkdir -p $TMPDIR
fi
if [ "vdi" == "$IMG_format" ]; then
#- mount .vdi
vdfuse -a -f $IMG /mnt/vdi
mount -o loop /mnt/vdi/1 $TMPDIR
else
#- mount image to tmpdir
mount $IMG $TMPDIR
fi
}
clone_img(){
echo "clone => $TMPDIR"
#- copy files
rsync -aAX --delete --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found","/home/*"} /* "$TMPDIR"
#- install bootloader
extlinux --install $TMPDIR/boot
#- update bootloader
#-- qemu default: root=/dev/sda
cat > $TMPDIR/boot/syslinux/extlinux.conf <<- EOM
DEFAULT $IMG_name_$LNX_image
LABEL $IMG_name_$LNX_image
SAY Booting $IMG_name - $LNX_image
LINUX /boot/$LNX_image
INITRD /boot/$LNX_initrd
APPEND root=$LNX_rootdev rw
EOM
#-- remove invalid entries from $TMPDIR/etc/fstab
echo "/dev/sda / ext4 defaults 0 1" > $TMPDIR/etc/fstab
#- unmount image and boot
umount $TMPDIR
if [ "vdi" == "$IMG_format" ]; then
umount /mnt/vdi
fi
}
start_vm(){
IMG="$WRKDIR/$IMG_name.$IMG_format"
echo "vm => $IMG"
qemu-system-i386 \
-display sdl \
-soundhw ac97 \
-vga cirrus \
$IMG
}
case $1 in
create_img)
create_img
;;
mount_img)
mount_img
;;
clone_img)
clone_img
;;
start_vm)
start_vm
;;
esac
virt-p2v
. – Michael Hampton May 21 '16 at 16:33