nested lxd wip1

This commit is contained in:
pvincent
2024-02-26 22:57:41 +04:00
parent c874f2c180
commit 2bf8289238
5 changed files with 66 additions and 22 deletions
+40 -15
View File
@@ -47,14 +47,39 @@ function prepare_lxd {
echo "bridge <lxdbr0> down, so initialization will use default preseed..."
empty_block_partition=''
if lsblk -o NAME,FSTYPE,GROUP --noheadings -p | grep -E ^.─ | grep disk; then
# FIXME: when nesting no DISK type partition found!
if [[ $(printenv container) == 'lxc' ]]; then
echo "nested configuration applying..."
cat <<EOF | lxd init --preseed
config: {}
networks:
- name: lxdbr0
type: bridge
config:
ipv4.address: auto
ipv6.address: none
profiles:
- config:
security.privileged: "true"
description: ""
devices:
eth0:
name: eth0
nictype: bridged
parent: lxdbr0
type: nic
root:
path: /
pool: default
type: disk
name: default
projects: []
cluster: null
EOF
else
empty_block_partition=$(lsblk -o NAME,FSTYPE,GROUP --noheadings -p | grep -E ^.─ | grep disk | awk '{if($3=="") print $1}' | cut -d'/' -f3)
fi
if [[ -n "$empty_block_partition" ]]; then
echo "use empty block partition /dev/$empty_block_partition"
cat <<EOF | sudo lxd init --preseed
if [[ -n "$empty_block_partition" ]]; then
echo "use empty block partition /dev/$empty_block_partition for speed and optimization"
cat <<EOF | sudo lxd init --preseed
config: {}
networks:
- config:
@@ -86,10 +111,10 @@ profiles:
projects: []
cluster: null
EOF
echo OK
else
echo "use dir partition"
cat <<EOF | lxd init --preseed
echo OK
else
echo "use dir partition for development purpose"
cat <<EOF | lxd init --preseed
config: {}
networks:
- name: lxdbr0
@@ -98,13 +123,14 @@ networks:
ipv4.address: auto
ipv6.address: none
EOF
fi
fi
else
echo "bridge <lxdbr0> found implies it has been already initialized!"
fi
set_alias 'sameuser' "exec @ARG1@ -- su --whitelist-environment container_hostname - $(whoami)"
set_alias 'login' 'exec @ARGS@ --mode interactive -- /bin/bash -c $@${user:-root} - exec su --whitelist-environment container_hostname - '
set_alias 'sameuser' "exec @ARG1@ -- su --whitelist-environment container,container_hostname - $(whoami)"
set_alias 'login' 'exec @ARGS@ --mode interactive -- /bin/bash -c $@${user:-root} - exec su --whitelist-environment container,container_hostname - '
set_alias 'll' 'list -c ns4mDN'
# test environment container hostname
@@ -194,8 +220,7 @@ function check_credential {
check_yaml_defined_value /etc/miaou/defaults.yaml 'credential.username' &&
check_yaml_defined_value /etc/miaou/defaults.yaml 'credential.shadow' &&
check_yaml_defined_value /etc/miaou/defaults.yaml 'credential.email' &&
check_yaml_defined_value /etc/miaou/defaults.yaml 'credential.password'
check_yaml_defined_value /etc/miaou/defaults.yaml 'credential.email'
}