0

I did a file copy of a running debian8 installation to a image. Following is the proceedure.

  1. create a vdisk image - raw / vdi.
  2. mount it locally.
  3. do a file wise copy of a running linux distro:

    rsync -aAXv --delete --exclude={"/dev/","/proc/","/sys/","/tmp/","/run/","/mnt/","/media/","/lost+found","/home/"} /* "$TMPDIR"

  4. install extlinux bootloader and related /boot/extlinux.conf, update /etc/fstab, umount and boot.

I am able to boot using qemu. Able to login to console mode.

ISSUES:

  1. It fails at trying to mount swap partitions, but no reference is provided in /etc/fstab.
  2. It fails to load kernel modules.
  3. I see message starting lightdm, but next VT is displayed to login.
  4. I haven't recreated initram-fs for target, could this cause the problem?

Please help.

-- regards, JB

0

Have been able to resolve some of the issues, resulting in making a bootable vm image from a running system.

Issue:

  1. No effect.
  2. No effect.
  3. 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.
  4. 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.