lxc - vanaware/openwrt GitHub Wiki

LXC at openwrt x86_64 machines

Prepare ext root

nano /etc/config/fstab
config mount 'lxc'
        option target '/srv/lxc'
        option uuid '68706ead-a626-4209-b3d0-1187b835f803'
        option fstype 'btrfs'
	option btrfs_raid '1'
	option options 'subvol=/containers,noatime,nodiratime,noacl,nossd'
#        option options 'subvol=/containers,noatime,nodiratime,noacl,degraded,nossd,device=/dev/sda,device=/dev/sdb,device=/dev/sdc,device=/dev/sdd' 
        option enabled '1'

Building alpine images

lxc-create --bdev btrfs --name google -t alpine -- --release edge
lxc-start -n google
lxc-attach -n google
lxc-console -n google
lxc-stop -n google

config file
nano /srv/lxc/google/config

lxc.include = /usr/share/lxc/config/alpine.common.conf
lxc.arch = x86_64

# Container specific configuration
lxc.rootfs.path = btrfs:/srv/lxc/google/rootfs
#lxc.rootfs.path = overlayfs:/lower:/upper # specifies that the rootfs should be an overlay with /upper being mounted read-write over a read-only mount of /lower

lxc.uts.name = google

lxc.mount.entry=/mnt/data/media/Server/vanaware usr/local/share/vanaware/ none bind 0 0

# Network configuration
lxc.net.0.type = veth
lxc.net.0.link = br-lan
lxc.net.0.flags = up
lxc.net.0.hwaddr = 42:e7:f9:0e:95:48


# Log Level
# 0 = trace, 1 = debug, 2 = info, 3 = notice, 4 = warn, 5 = error, 6 = critical, 7 = alert, and 8 = fatal
lxc.log.level = 1
#lxc.log.file = /srv/lxc/google/google.log

Install basic software

apk update
apk add openssh nano
rc-update add sshd
/etc/init.d/sshd start
nano /etc/ssh/sshd_config
/etc/init.d/sshd restart
nano /etc/motd
apk --no-cache add curl python py-crcmod bash libc6-compat openssh-client git gnupg
CLOUD_SDK_VERSION=241.0.0
mkdir /google/
cd /google/
curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-${CLOUD_SDK_VERSION}-linux-x86_64.tar.gz
tar xzf google-cloud-sdk-${CLOUD_SDK_VERSION}-linux-x86_64.tar.gz
rm google-cloud-sdk-${CLOUD_SDK_VERSION}-linux-x86_64.tar.gz
ln -s /lib /lib64
cat >> /etc/profile.d/google.sh << \EOF
  PATH=$PATH:/google/google-cloud-sdk/bin
EOF
gcloud init
gcloud config set core/disable_usage_reporting true
gcloud config set component_manager/disable_update_check true
apk add -U screen curl bash ca-certificates openssl ncurses coreutils python2 make gcc g++ libgcc linux-headers grep util-linux binutils findutils
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
cat >> /etc/profile.d/nvm.sh << \EOF
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
EOF
nvm install -s --lts=carbon
nvm alias default node
gcloud components list
cd /usr/local/share/vanaware/javascript/<project>
npm install -g firebase-tools
firebase login --no-localhost
firebase init
firebase serve

Building debian images

LXC_CACHE_PATH=/srv/lxc/cache lxc-create --bdev btrfs --name build -t debian -- -r buster -a amd64
chroot /srv/lxc/build/rootfs bash

apt-get remove --purge --auto-remove systemd
apt-get install sysvinit-core sysvinit-utils
apt-get purge systemd*
echo -e 'Package: *systemd*\nPin: release *\nPin-Priority: -1\n' > /etc/apt/preferences.d/systemd
echo -e 'Package: libsystemd0\nPin: version *\nPin-Priority: 500\n' >> /etc/apt/preferences.d/nosystemd
rm /etc/systemd/system/default.target
ln -s /dev/null /etc/systemd/system/udev.service
ln -s /dev/null /etc/systemd/system/systemd-udevd.service
ln -s /lib/systemd/system/multi-user.target /etc/systemd/system/default.target

config file

lxc.net.0.hwaddr = 00:16:3e:d2:21:44
lxc.net.0.type = veth
lxc.net.0.link = br-lan
lxc.net.0.flags = up

lxc.rootfs.path = btrfs:/srv/lxc/build/rootfs

# Common configuration
lxc.include = /usr/share/lxc/config/debian.common.conf

# Container specific configuration
lxc.tty.max = 4
lxc.uts.name = build
lxc.arch = amd64
lxc.pty.max = 1024

Start and connect into lxc container

lxc-start --name build
lxc-attach --name build
lxc-console --name build
lxc-stop -n build
⚠️ **GitHub.com Fallback** ⚠️