For chroot to work, you also need to bind the kernels file systems, such as procfs, sysfs and /dev.
To do this, you typically execute before chrooting:
mount -o bind /proc proc
mount -o bind /sys sys
mount -o bind /dev dev
And only then you chroot into
However, this is not equivalent to running the linux under a VM, because it does not have its own kernel. There are two more layers of isolation you can use, one is LXC Containers (also without its own kernel) and one is an actual VM.
Both can be managed by libvirt, and I suggest that you have a look at libvirt for that purpose, with the qemu driver and the lxc driver.
With libvirt, you can also mount host file systems as guest file systems (see the domain configuration¹). However, in general it might be wiser to just hand the whole partition to libvirt and let it do the rest. This has the restriction that you cannot access the files directly from the host system while the VM is running².
A simple example configuration would be:
<domain type='qemu'> <!-- if you have kvm, put kvm here instead of qemu -->
<type arch='x86_64' machine='pc-i440fx-1.6'>hvm</type>
<boot dev='cdrom' />
<boot dev='hd' />
<suspend-to-mem enabled='no' />
<suspend-to-disk enabled='no' />
<!-- for kvm, you have to put /usr/bin/qemu-kvm here -->
<!-- to directly use a filesystem here, please see the documentation -->
<disk type='block' device='disk'>
<driver name='qemu' type='raw' />
<target dev='vda' bus='virtio' />
<source dev='/dev/partition_used_by_the_other_linux' />
<target port='0' />
<target type='serial' port='0' />
<seclabel type='none' />
If you have multiple partitions to use, create multiple ones by duplicating the
disk section. For more details please see the documentation on the domain XML format. It also contains information on how to set up networking.
After setting up the domain, you can define it in libvirt with:
virsh define path/to/domain.xml
And start it with:
virsh start my_fancy_vm # that is the name chosen in the xml
To connect to the fake serial console defined in the xml, you can use:
virsh console my_fancy_vm
Note that nothing might show up – you may have to configure your archlinux to use it. For lxc guests there might be an easier way than binding a console to get a shell, but I have not tried it. There are tutorials for using libvirt with lxc though.
- One domain is one virtual machine, in case you don’t know.
- Well, you can, but you really, really should not. You can of course mount it via sshfs to the guest.