Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save arvati/879d034e75758927e7b7705baea66557 to your computer and use it in GitHub Desktop.

Select an option

Save arvati/879d034e75758927e7b7705baea66557 to your computer and use it in GitHub Desktop.

Install LXC Container with Debian on LXC container in OpenWrt

Config LXC Containers

Config fstab btrfs subvolume /containers to hold all LXC Containers
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'

Config LXC to use /srv/lxc

Create or Modify config file to use /srv/lxc path in extroot of openwrt
nano /etc/lxc/lxc.conf

lxc.lxcpath = /srv/lxc

nano /etc/lxc/default.conf

lxc.net.0.type = veth
lxc.net.0.link = br-lan
lxc.net.0.flags = up

Debootstrap Debian into Container

First Clear any previous container

lxc-ls --fancy
LXC_CACHE_PATH=/srv/lxc/cache lxc-destroy --snapshots --force --name assistant

Create debian buster container with name assistant within btrfs subvolume

LXC_CACHE_PATH=/srv/lxc/cache lxc-create --bdev btrfs --name assistant -t debian -- -r buster -a amd64

Patch Debian Container

Patch debian container to work on openwrt. At this moment need to uninstall systemd

chroot /srv/lxc/assistant/rootfs bash
apt-get update --allow-releaseinfo-change
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 -sf /dev/null /etc/systemd/system/udev.service
ln -sf /dev/null /etc/systemd/system/systemd-udevd.service
ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
exit

Create assistant folder inside LXC Container

chroot /srv/lxc/assistant/rootfs bash
mkdir -m 777 -p /opt/assistant
exit

Config assistant Container

Config lxc config file container
nano /srv/lxc/assistant/config

lxc.net.0.hwaddr = fa:e6:af:5f:32:63
lxc.net.0.type = veth
lxc.net.0.link = br-lan
lxc.net.0.flags = up
lxc.rootfs.path = btrfs:/srv/lxc/assistant/rootfs
lxc.mount.entry=/mnt/data/home home/ none bind 0 0
lxc.mount.entry=/dev/snd dev/snd none bind,optional,create=dir 0 0
lxc.mount.entry=/dev/dsp dev/dsp none bind,optional,create=dir 0 0

# Use autodev to be compatible with systemd
#lxc.autodev = 1
#lxc.hook.autodev = /etc/lxc/hook/autodev

# Common configuration
lxc.include = /usr/share/lxc/config/debian.common.conf
# Container specific configuration
lxc.tty.max = 4
lxc.uts.name = assistant
lxc.arch = amd64
lxc.pty.max = 1024

#Sound device nodes - must be at the end of file after lxc.include
lxc.cgroup.devices.allow = c 116:* rwm
lxc.cgroup.devices.allow = c 14:* rwm

Test Container

Test Assistant LXC Container and create root password

lxc-start --name assistant
lxc-attach --name assistant
passwd
exit
lxc-console -n assistant
exit
#CTRL+a +q
lxc-stop -n assistant

Initial Container OS Config

Install some basic packages

apt-get dist-upgrade
apt-get install -yq --no-install-recommends \
    apt-transport-https \
    nano sudo locales wget curl gpg \
    apt-utils \
    bzip2 \
    git \
    ca-certificates \
    alsa-utils

Config SSH server

nano /etc/ssh/sshd_config

#PermitRootLogin yes
PasswordAuthentication yes
PermitEmptyPasswords no
ChallengeResponseAuthentication no
UsePAM yes
X11Forwarding no
PrintMotd yes
#Banner none
AcceptEnv LANG LC_*
Subsystem	sftp	/usr/lib/openssh/sftp-server

Config Timezone and Languages

Configuring Timezone

ln --force --symbolic '/usr/share/zoneinfo/America/Sao_Paulo' '/etc/localtime'
echo "America/Sao_Paulo" | tee /etc/timezone
dpkg-reconfigure --frontend=noninteractive tzdata

Configuring Languages

locale-gen pt_BR.UTF-8
locale-gen --purge en_US.UTF-8
sed -i -e 's/# pt_BR.UTF-8 UTF-8/pt_BR.UTF-8 UTF-8/' /etc/locale.gen
sed -i -e 's/en_US.UTF-8 UTF-8/# en_US.UTF-8 UTF-8/' /etc/locale.gen
echo 'LANG=pt_BR.UTF-8' > /etc/default/locale
dpkg-reconfigure --frontend=noninteractive locales
update-locale LANG='pt_BR.UTF-8'
update-locale LC_ALL='pt_BR.UTF-8'
update-locale LANGUAGE='pt_BR.UTF-8'

Sudo without passwords

sudo EDITOR=nano visudo /etc/sudoers.d/nopasswd

%sudo ALL = (ALL) NOPASSWD: ALL
Defaults exempt_group = sudo

Creating Users

Creating user manager and allow it to sudoers

adduser manager
usermod -aG sudo manager
usermod -aG audio manager

Check sudoers users
getent group sudo
Now log into container using user and password

exit
lxc-stop -n assistant
lxc-start -n assistant
lxc-console --name assistant

Create ssh login credentials

exit
#cat ~/.ssh/id_rsa.pub | ssh root@assistant "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
cat ~/.ssh/id_rsa.pub | ssh manager@assistant "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"

You may Log in using ssh now

#ssh root@assistant
ssh manager@assistant

Sound Config

sudo nano /etc/asound.conf

pcm.!default {
  type asym
  capture.pcm "mic"
  playback.pcm "speaker"
}
pcm.mic {
  type plug
  slave {
    pcm "hw:2,0"
  }
}
pcm.speaker {
  type plug
  slave {
    pcm "hw:2,0"
  }
}

Install apt packages into server

Add testing packages sudo nano /etc/apt/sources.list

deb http://deb.debian.org/debian          buster         main non-free contrib
deb http://security.debian.org/ buster/updates main non-free contrib
deb http://deb.debian.org/debian buster-backports main non-free contrib

deb http://deb.debian.org/debian testing main non-free contrib
deb http://deb.debian.org/debian unstable main non-free contrib

sudo nano /etc/apt/preferences

Package: *
 Pin: release a=buster
 Pin-Priority: 700

 Package: *
 Pin: release a=testing
 Pin-Priority: 650

 Package: *
 Pin: release a=unstable
 Pin-Priority: 600

Run apt instalation

sudo apt update
sudo apt-get install -yq --no-install-recommends \
    fonts-liberation \
    python3 python3-dev \
    python3-pip \
    python3-venv \
    python3-setuptools \
    libzmq3-dev \
    libssl-dev \
    libcurl4-openssl-dev \
    build-essential \
    libczmq4 \
    libtool libffi-dev \
    python3-grpcio/buster-backports \
    python3-google-auth \
    python3-wheel \
    portaudio19-dev \
    libssl-dev \
    libmpg123-dev \
    cargo

Install google assitant into server

Run sample instalation

cd /opt/assistant/
python3 -m venv env
source env/bin/activate
env/bin/python -m pip install --upgrade pip setuptools wheel
python -m pip install --upgrade google-assistant-library
python -m pip install --upgrade google-assistant-sdk[samples]
googlesamples-assistant-audiotest 
googlesamples-assistant-pushtotalk --project-id gerente-7f562 --device-model-id gerente-openwrt-x64-router
googlesamples-assistant-hotword --project-id gerente-7f562 --device-model-id gerente-openwrt-x64-router
@arvati
Copy link
Author

arvati commented Jun 22, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment