Created
June 30, 2021 12:47
-
-
Save mkg20001/fa0eecbbca86cbde15b767407115335b to your computer and use it in GitHub Desktop.
Ubuntu LXD container for local development with home folder mounted
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env/bash | |
# launch as "setup-ubuntu-container.sh <container-name>" | |
# replace "maciej" with your username and you're good to go | |
# NOTE: this assumes you're UID 1000 on your local system, otherwise this script needs tweaks | |
set -exuo pipefail | |
NAME="$1" | |
# start privileged so UIDs match | |
lxc launch ubuntu:20.04 "$NAME" -c security.privileged=true | |
echo 'set -x | |
# replace ubuntu group with my group | |
sed "s|ubuntu|maciej|g" -i /etc/group | |
# replace | |
sed -r "s|ubuntu:.*||g" -i /etc/passwd | |
yes " | |
" | adduser maciej | |
addgroup maciej sudo | |
# sudo nopasswd | |
echo "H4sIALu/blsAA+3RsQrCMBCA4az6FFkEXWxiooLgUHAsKnRwLqarkSTF1zd1lKJLQYT/g7vjuBsOrk3XInbOtyEuXXHz9ybGhxOjUpm16lWz95qHWmiTrc12szJCaau0EVKNe8awLqYmSCmC9+nT3rf5n5r1z5+UVbWf57TLsZDH07ms68uh76a/PhAAAAAAAAAAAAAAAAAAMOgJqvttVwAoAAA=" | base64 -d | tar xvfzp - -C / | |
apt purge snapd | |
' | lxc exec "$NAME" /bin/bash - | |
lxc stop "$NAME" | |
lxc config device add "$NAME" home disk source=/home/maciej path=/home/maciej | |
# this is optional - if you have a bridge on your main nic you can have the container talk directly to your router for DHCP | |
# lxc config device add "$NAME" eth0 nic name=eth0 nictype=bridged parent=br0 | |
lxc start "$NAME" | |
# you can now lxc exec CONTAINER |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment