1

I have my rootfs snapshot in /mnt/mydisk/my_test_snapshot. It is completely writable copy of my current system.

I want to boot a virtual machine (possibly an LXC container or maybe something else) that will use /mnt/mydisk/my_test_snapshot as its root (/) folder.

At the end, I need to boot a virtual machine that:

  1. uses a regular folder as its root filesystem.
  2. can mount some permitted folders in its virtual environment
  3. will use bridged networking (with zero configuration on the host's iptables)
  4. hopefully will have a X window to use GUI applications within

Is there any LXC recipe (or something else) for that purpose?

Purpose

It might be re-inventing Docker or something, I don't know, but I need the following good bits:

  1. As using BTRFS for the root partition, we can take a snapshot of current system with no cost and boot a virtual machine and play around (by installing new software, deleting something etc...)

  2. If we liked what we did in the virtual machine, we can boot our real operating system from that snapshot (modified by VM)

  3. We can clone any VM with no cost (time, cpu or disk space)

  4. We can use this virtual machine as a time machine, for example, that will serve a database server from a backup. Good part is we can bring all services online in 1 minute and at once. Good for disaster recovery.

  5. We can use it for specific applications (that we use for business) that will has to run any time we need, no matter what kind of upgrade or operating system change we did. This will completely create a sandbox for each application, without the cost of disk space and will bring BTRFS benefits (like snapshotting etc.)

  • 1
    Sounds like you want systemd-nspawn. – Mio Rin May 6 '17 at 2:50
  • That was what I was looking for. I'll check it out, thank you! – ceremcem May 6 '17 at 8:11
0

As a partial answer, I created the following tool to create an LXC container from a subvolume: https://github.com/aktos-io/lxc-to-the-future

if [[ "$(grep br0 /etc/network/interfaces)" == "" ]]; then 
    cat <<ONETIME
ERROR: No br0 bridge device found in  /etc/network/interfaces file. 
Edit your /etc/network/interfaces file and add/replace the following section 
in place of "eth0" section 

    auto br0
    iface br0 inet dhcp
        bridge-ifaces eth0
        bridge-ports eth0
        up ifconfig eth0 up

    iface eth0 inet manual


Then run the following: 
    sudo ifup br0
ONETIME
    exit
fi

echo "creating the container directory: $NAME"
mkdir $DIR/$NAME

echo "creating a writable snapshot of given subvolume"
btrfs sub snap $SUBVOL $DIR/$NAME/rootfs

echo "emptying the /etc/fstab file"
echo > $DIR/$NAME/rootfs/etc/fstab

echo "creating the config file"
cat <<CONFIG > $DIR/$NAME/config
# Distribution configuration
lxc.include = /usr/share/lxc/config/debian.common.conf
lxc.arch = x86_64
# Container specific configuration
lxc.rootfs = /var/lib/lxc/$NAME/rootfs
lxc.rootfs.backend = dir
lxc.utsname = $NAME
# Network configuration
lxc.network.type = veth
lxc.network.link = br0
lxc.network.hwaddr = 00:16:3e:7e:11:ac
lxc.network.flags = up 
CONFIG

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.