This article describes how to transfer your current Arch Linux installation in or out of a virtual environment (i.e. QEMU, VirtualBox, VMware), and is heavily based on the [[Full System Backup with rsync]] article. A virtual machine ("VM", for short) uses different hardware, which needs to be addressed by re-generating the initramfs image. While any Linux [[File_Systems|filesystem]] should work, it's recommended that you go with [[ext4]], at least at first, until you get the hang of it.

+

This article describes how to transfer your current Arch Linux installation in or out of a virtual environment (i.e. QEMU, VirtualBox, VMware), and is heavily based on the [[Full System Backup with rsync]] article. A virtual machine ("VM", for short) uses different hardware, which needs to be addressed by re-generating the initramfs image and possibly adjusting the fstab – especially if it's an [[SSD]].

+

+

While any Linux [[File_Systems|filesystem]] should work, it's recommended that you go with [[ext4]], at least at first, until you get the hang of it.

== Moving out of a VM ==

== Moving out of a VM ==

Line 41:

Line 43:

=== Adjust the fstab ===

=== Adjust the fstab ===

−

Since your entire root tree has been transferred to a single partition, edit the [[fstab]] file to reflect the right partition. Check with {{ic|blkid}} (since {{ic|lsblk}} is not very useful inside a chroot).

+

Since your entire root tree has been transferred to a single partition, edit the [[fstab]] file to reflect the right partition(s):

+

+

# nano /etc/fstab

+

+

Check with the {{ic|blkid}} command, since {{ic|lsblk}} is not very useful inside a chroot.

=== Re-generate the initramfs image ===

=== Re-generate the initramfs image ===

Line 59:

Line 65:

=== Create the container ===

=== Create the container ===

−

This will create a 10 GB raw image:

+

This will create a 10 GB raw image (fallocate is faster):

+

# fallocate -l 10GB -o 1024 /media/Backup/backup.img

+

or

# dd if=/dev/zero of=/media/Backup/backup.img bs=1024 count=10482381

# dd if=/dev/zero of=/media/Backup/backup.img bs=1024 count=10482381

Line 76:

Line 84:

{{Tip|If you want, you can add however many partitions you want: home, boot, var, tmp, whatever floats your boat. Of course, it will add a layer of complexity, but it's doable. The point is that you don't necessarily need another container.}}

{{Tip|If you want, you can add however many partitions you want: home, boot, var, tmp, whatever floats your boat. Of course, it will add a layer of complexity, but it's doable. The point is that you don't necessarily need another container.}}

+

{{Note|If you use the command-line parted instead of gparted, don't forget to leave 1 or 2 megabytes of unpartitioned space at the start of the disk for GRUB's embedded partition.}}

Reinstall either Syslinux or GRUB, using the [[Beginners'_Guide#Install_and_configure_a_bootloader|instructions]] from the Beginners' Guide. Just don't forget to update its configuration file:

+

Reinstall either Syslinux or GRUB, using the [[Beginners'_Guide#Install_and_configure_a_bootloader|instructions]] from the Beginners' Guide. Don't forget to update its configuration file:

* For Syslinux, it should be {{ic|1=APPEND root=/dev/sda1 ro}} in {{ic|syslinux.cfg}}.

* For Syslinux, it should be {{ic|1=APPEND root=/dev/sda1 ro}} in {{ic|syslinux.cfg}}.

Line 113:

Line 120:

=== Adjust the fstab ===

=== Adjust the fstab ===

−

Since your entire root tree has been transferred to a single partition, edit the [[fstab]] file to look like this:

+

Since your entire root tree has been transferred to a single partition, edit the [[fstab]] file. You may use the UUID or label if you want, but those are more useful in multi-drive, multi-partition configurations (to avoid confusions). For now, {{ic|/dev/sda1}} for your entire system is just fine.

{{hc|# nano /etc/fstab|

{{hc|# nano /etc/fstab|

−

tmpfs /tmp tmpfs nodev,nosuid 0 0

+

tmpfs /tmp tmpfs nodev,nosuid 0 0

−

/dev/sda1 / ext4 defaults,noatime 0 1}}

+

/dev/sda1 / ext4 defaults,noatime 0 1}}

=== Disable any Xorg-related files ===

=== Disable any Xorg-related files ===

−

Having an {{ic|nvidia}} entry (or {{ic|nouveau}}, {{ic|radeon}}, {{ic|intel}}, etc) in the {{ic|Device}} section from one of the Xorg configuration files will inhibit the {{ic|startx}} command, since you will be using ''emulated'' hardware (including the video card). So it's recommended that you move/rename or delete the following:

+

Having an {{ic|nvidia}}, {{ic|nouveau}}, {{ic|radeon}}, {{ic|intel}}, etc., entry in the {{ic|Device}} section from one of the Xorg configuration files will prevent it from starting, since you will be using ''emulated'' hardware (including the video card). So it's recommended that you move/rename or delete the following:

# mv /etc/X11/xorg.conf /etc/X11/xorg.conf.bak

# mv /etc/X11/xorg.conf /etc/X11/xorg.conf.bak

Line 143:

Line 150:

=== "mount: special device /dev/loop5p1 does not exist" ===

=== "mount: special device /dev/loop5p1 does not exist" ===

−

Check with {{ic|fdisk}} for the starting block and use it as an offset:

+

First, check the loopback device with {{ic|fdisk}} for the starting block:

{{hc|# fdisk -l /dev/loop5|2=

{{hc|# fdisk -l /dev/loop5|2=

Line 156:

Line 163:

Device Boot Start End Blocks Id System

Device Boot Start End Blocks Id System

/dev/loop5p1 * 2048 20963327 10480640 83 Linux}}

/dev/loop5p1 * 2048 20963327 10480640 83 Linux}}

+

+

Then use it as an offset when mounting it:

# mount -o offset=$(('''2048''' * 512)) /dev/loop5 /mnt/Virtual/

# mount -o offset=$(('''2048''' * 512)) /dev/loop5 /mnt/Virtual/

Line 168:

Line 177:

[rootfs /]# _

[rootfs /]# _

−

It most likely means that you didn't run {{ic|poweroff}} like ''you were instructed to'', and closed the VM with the "close" button, which is the equivalent of a power outage. Now you need to regenerate your initramfs image. To do that, you can start the VM using the Fallback entry. If you don't have a Fallback entry, press {{Keypress|Tab}} (for Syslinux) or {{Keypress|e}} (for GRUB) and rename it {{ic|initramfs-linux-fallback.img}}.

+

It most likely means that you didn't run {{ic|poweroff}} like ''you were instructed to'', and closed the VM with the "close" button, which is the equivalent of a power outage. Now you need to regenerate your initramfs image. To do that, you can start the VM using the Fallback entry. If you don't have a Fallback entry, press {{ic|Tab}} (for Syslinux) or {{ic|e}} (for GRUB) and rename it {{ic|initramfs-linux-fallback.img}}. After it boots, open up a terminal and run:

−

+

−

After it boots, open up a terminal and run:

+

# mkinitcpio -p linux

# mkinitcpio -p linux

Line 178:

Line 185:

You will need to install (reinstall) a bootloader. See the [[Beginners'_Guide#Install_and_configure_a_bootloader|instructions]] from the Beginners' Guide.

You will need to install (reinstall) a bootloader. See the [[Beginners'_Guide#Install_and_configure_a_bootloader|instructions]] from the Beginners' Guide.

+

+

Also, check the boot order from the BIOS or from the VM's settings and make sure that the drive containing the bootloader is the first to boot.

=== I'm asked for the root password, for maintenance ===

=== I'm asked for the root password, for maintenance ===

−

:: Checking Filesystems [BUSY]

+

:: Checking Filesystems [BUSY]

fsck.ext4: Unable to resolve '...'

fsck.ext4: Unable to resolve '...'

This means that you forgot to add the drive's UUID, label or device name in {{ic|/etc/fstab}}. The UUID is different every time you format it (or in this case, create one from scratch), and they likely do not match. Check with {{ic|blkid}}.

This means that you forgot to add the drive's UUID, label or device name in {{ic|/etc/fstab}}. The UUID is different every time you format it (or in this case, create one from scratch), and they likely do not match. Check with {{ic|blkid}}.

This article describes how to transfer your current Arch Linux installation in or out of a virtual environment (i.e. QEMU, VirtualBox, VMware), and is heavily based on the Full System Backup with rsync article. A virtual machine ("VM", for short) uses different hardware, which needs to be addressed by re-generating the initramfs image and possibly adjusting the fstab – especially if it's an SSD.

While any Linux filesystem should work, it's recommended that you go with ext4, at least at first, until you get the hang of it.

Chroot and reinstall the bootloader

Boot a "live" Linux distribution, mount the root partition and chroot into it:

# mount /dev/sdb2 /mnt
# arch-chroot /mnt

Reinstall either Syslinux or GRUB, using the instructions from the Beginners' Guide. Don't forget to update the configuration file (i.e. syslinux.cfg or grub.cfg).

Adjust the fstab

Since your entire root tree has been transferred to a single partition, edit the fstab file to reflect the right partition(s):

# nano /etc/fstab

Check with the blkid command, since lsblk is not very useful inside a chroot.

Re-generate the initramfs image

Because the hardware has changed, while you're still in the chroot, re-generate the initramfs image:

# mkinitcpio -p linux

And that's about it.

You'll most likely need to set up the network, since the virtual machine was probably piggybacking on the host OS's network settings. See Configure the network from the Beginners' Guide.

Moving into a VM

Moving into a virtual environment takes a little more effort.

Create the container

This will create a 10 GB raw image (fallocate is faster):

# fallocate -l 10GB -o 1024 /media/Backup/backup.img

or

# dd if=/dev/zero of=/media/Backup/backup.img bs=1024 count=10482381

If you want to create one the exact size of your root partition, run fdisk -l and use the value from the Blocks column. Note that you will transfer you entire root tree, so that includes the /boot and /home folders. If you have any separate partitions for those, you need to take them into account when creating the container.

Now load the necessary module and mount it as a loopback device, on /dev/loop5 (for example):

# modprobe loop
# losetup /dev/loop5 /media/Backup/backup.img

Install gparted and slap a partition table on it (e.g. "msdos") and a filesystem (e.g. "ext4"):

# pacman -S gparted
# gparted /dev/loop5

Tip: If you want, you can add however many partitions you want: home, boot, var, tmp, whatever floats your boat. Of course, it will add a layer of complexity, but it's doable. The point is that you don't necessarily need another container.

Note: If you use the command-line parted instead of gparted, don't forget to leave 1 or 2 megabytes of unpartitioned space at the start of the disk for GRUB's embedded partition.

Chroot and reinstall the bootloader

Hook up the converted file from above, and the latest Arch Linux ISO into the virtual CD-ROM. Then start the virtual machine and chroot into it:

# mount /dev/sda1 /mnt
# arch-chroot /mnt

Reinstall either Syslinux or GRUB, using the instructions from the Beginners' Guide. Don't forget to update its configuration file:

For Syslinux, it should be APPEND root=/dev/sda1 ro in syslinux.cfg.

For GRUB, it's recommended that you automatically re-generate a grub.cfg.

Adjust the fstab

Since your entire root tree has been transferred to a single partition, edit the fstab file. You may use the UUID or label if you want, but those are more useful in multi-drive, multi-partition configurations (to avoid confusions). For now, /dev/sda1 for your entire system is just fine.

Disable any Xorg-related files

Having an nvidia, nouveau, radeon, intel, etc., entry in the Device section from one of the Xorg configuration files will prevent it from starting, since you will be using emulated hardware (including the video card). So it's recommended that you move/rename or delete the following:

Re-generate the initramfs image

Because the hardware has changed, while you're still in the chroot, re-generate the initramfs image and do a proper shutdown:

# mkinitcpio -p linux
# poweroff

Finally, pull out the LiveCD (the ISO file) and start the virtual machine.

Note: At this point you may notice that you no longer have a wallpaper. Don't worry about it. It's most likely because it is located on a different partition mounted in /media or /mnt, folders which were excluded from the transfer.

It most likely means that you didn't run poweroff like you were instructed to, and closed the VM with the "close" button, which is the equivalent of a power outage. Now you need to regenerate your initramfs image. To do that, you can start the VM using the Fallback entry. If you don't have a Fallback entry, press Tab (for Syslinux) or e (for GRUB) and rename it initramfs-linux-fallback.img. After it boots, open up a terminal and run:

# mkinitcpio -p linux
# poweroff

"Missing operating system. FATAL: INT18: BOOT FAILURE"

You will need to install (reinstall) a bootloader. See the instructions from the Beginners' Guide.

Also, check the boot order from the BIOS or from the VM's settings and make sure that the drive containing the bootloader is the first to boot.

I'm asked for the root password, for maintenance

:: Checking Filesystems [BUSY]
fsck.ext4: Unable to resolve '...'

This means that you forgot to add the drive's UUID, label or device name in /etc/fstab. The UUID is different every time you format it (or in this case, create one from scratch), and they likely do not match. Check with blkid.