linux
安装LXD及相关工具
sudo snap install lxd --channel=4.0/stable
sudo snap install lxd --channel=latest/stable
sudo apt-get install zfsutils-linux bridge-utils
初始化配置
sudo lxd init
创建容器
lxc image list images: # list remote image
lxc launch ubuntu:20.04 stash
查看容器
lxc list
启动停止容器
lxc start/restart stop stash
执行容器内进程
lxc exec stash /bin/bash
删除容器
lxc delete stash
为容器创建用户
useradd -r -m -s /bin/bash maky
#passwd maky # change password
echo "user:pw" | chpasswd
chmod +w /etc/sudoers
echo "maky ALL=(ALL:ALL) ALL" >> /etc/sudoers
chmod -w /etc/sudoers
用户登陆
lxc exec stash -- sudo --user maky --login
mount本地目录
#lxc config device add {container-name} {name} disk source={/path/to/source/} path={/path/to/container/}
lxc config device add stash share disk source=/home/maky/stash path=/home/maky/stash
写权限
id # lxc container user id
lxc config set stash raw.idmap "both <host_id> <container_id>"
gpu
gui
lxc config device add stash X0 disk path=/tmp/.X11-unix/X0 source=/tmp/.X11-unix/X0
lxc config device add stash Xauthority disk path=/home/ubuntu/.Xauthority source=${XAUTHORITY}
echo "export DISPLAY=:0" >> /etc/profile
echo "export EDITOR=vim" >> /etc/profile
lxc profile create gui
lxc profile edit gui
lxc profile add stash gui
config:
environment.DISPLAY: :0
raw.idmap: both 1000 997
user.user-data: |
#cloud-config
runcmd:
- 'sed -i "s/; enable-shm = yes/enable-shm = no/g" /etc/pulse/client.conf'
- 'echo export PULSE_SERVER=unix:/tmp/.pulse-native | tee --append /home/ubuntu/.profile'
packages:
- x11-apps
- mesa-utils
- pulseaudio
description: GUI LXD profile
devices:
PASocket:
path: /tmp/.pulse-native
source: /run/user/1000/pulse/native
type: disk
X0:
path: /tmp/.X11-unix/X0
source: /tmp/.X11-unix/X0
type: disk
mygpu:
type: gpu
name: gui
used_by:
windows
sudo snap install distrobuilder --classic
sudo apt install -y libguestfs-tools libwin-hivex-perl wimtools
sudo apt-get install -y remmina-plugin-spice virt-viewer
sudo systemctl reload snap.lxd.daemon.service
sudo distrobuilder repack-windows windows10_x64.iso windows10-distrobuilder.iso
#lxc init win10 --empty --vm -c security.secureboot=false
lxc init win10 --empty --vm -c security.secureboot=false -c limits.cpu=16 -c limits.memory=16GiB
lxc config device override win10 root size=30GiB
lxc config set win10 limits.cpu=4 limits.memory=8GiB
#lxc config device add win10 vtpm tpm path=/dev/tpm0
lxc config device add win10 iso disk source=/path_to/windows10-distrobuilder.iso boot.priority=10
lxc start win10 --console=vga
lxc console win10 --type=vga
lxc config device remove win10 iso
[1] https://ubuntu.com/server/docs/containers-lxd
[2] https://blog.simos.info/ how-to-run-graphics-accelerated-gui-apps-in-lxd-containers-on-your-ubuntu-desktop/
[3] https://blog.csdn.net/u012558210/article/details/120243466
[4] https://github.com/shenuiuin/LXD_GPU_SERVER
[5] https://ubuntu.com/blog/ros-development-with-lxd
[6] https://ubuntu.com/tutorials/how-to-install-a-windows-11-vm-using-lxd#1-overview
[7] https://gihyo.jp/admin/serial/01/ubuntu-recipe/0679