Compare commits
27 commits
Author | SHA1 | Date | |
---|---|---|---|
7271b90b1f | |||
ce889eae36 | |||
b40238ea8e | |||
9c95213ab8 | |||
6c32be12ec | |||
|
a74474ef36 | ||
ebbaf1aec3 | |||
8db33f0d33 | |||
f1e3080592 | |||
2a88d2389e | |||
494d4bfe77 | |||
71eaf726af | |||
5ca1b1837c | |||
bb6e1841f7 | |||
02bca84b4a | |||
b223032435 | |||
ea52dd7ded | |||
66132a2f41 | |||
2ac8f5fd55 | |||
55713536c5 | |||
d322258252 | |||
9fb25fd1a9 | |||
0aab5f6c4e | |||
06beb49390 | |||
4c18e2590a | |||
717d3006a9 | |||
e929bb9312 |
6 changed files with 49 additions and 406 deletions
34
README.md
34
README.md
|
@ -1,48 +1,34 @@
|
||||||
__Features:__
|
__Features:__
|
||||||
|
|
||||||
copy_containers ->
|
setup-msl-mm_install_requirements ->
|
||||||
script for easy bulk container migrate via SSH between instalations of usl-mm, is also possible use it in non-interactive mode with parameters in this order: container-name, destination-host, destination-port(optional)
|
install dialog utility
|
||||||
|
|
||||||
zfs-backup-mm-example-config ->
|
setup-msl-mm
|
||||||
example config for zfs-backup-mm script, that backup all running containers, except those with "testing" or "deluge "in container name.
|
|
||||||
|
|
||||||
setup-usl-mm_install_requirements ->
|
|
||||||
configure main and universe repo in sources.list, install dialog utility
|
|
||||||
|
|
||||||
usl-mm-bionic-upgrade ->
|
|
||||||
replace current release codename with codename in first argument, upgrade LXD to 4.16 SNAP version, upgrade system, replace some lines in /root/onstart, reboot
|
|
||||||
|
|
||||||
setup-usl-mm ->
|
|
||||||
1. Pre-reboot script ->
|
1. Pre-reboot script ->
|
||||||
install zfs-utils,
|
install linuxXY-zfs(for latest installed kernel),
|
||||||
change timezone to Prague,
|
change timezone to Prague,
|
||||||
crypt swap partition with ecryptfs-utils,
|
crypt swap partition with ecryptfs-utils,
|
||||||
crypt some partition with dmcrypt to use with /var/lib/lxd and LXD ZFS storage,
|
crypt some partition with dmcrypt to use with /var/snap/lxd/common/lxd/* and LXD ZFS storage,
|
||||||
add some config to sysctl.conf,
|
add some config to sysctl.conf,
|
||||||
disable lxd service,
|
disable snapd.lxd service,
|
||||||
delete everything in /var/lib/lxd/*,
|
delete everything in /var/snap/lxd/common/lxd/*,
|
||||||
delete netplan, install ifupdown,
|
|
||||||
configure bridged networking (you can put LXD container to your network simple by add br0 to container),
|
|
||||||
create zpool with ashift=12,
|
create zpool with ashift=12,
|
||||||
set compression=on on crypted zpool,
|
set compression=on on crypted zpool,
|
||||||
configure zfs cache min 256MB max 1536MB,
|
configure zfs cache min 256MB max 1536MB,
|
||||||
do dist-upgrade,
|
|
||||||
create /root/onstart script to decrypt crypted parition with password and start lxd (you need start this script on every reboot),
|
create /root/onstart script to decrypt crypted parition with password and start lxd (you need start this script on every reboot),
|
||||||
reboot
|
reboot
|
||||||
|
|
||||||
2. Post-reboot script ->
|
2. Post-reboot script ->
|
||||||
for sure, stop lxd service and delete everything in /var/lib/lxd/*,
|
for sure, stop snapd.lxd service and delete everything in /var/snap/lxd/common/lxd/*,
|
||||||
exec /root/onstart to decrypt partition and import zpool,
|
exec /root/onstart to decrypt partition and import zpool,
|
||||||
configure LXD to use encrypted partition as storage,
|
configure LXD to use encrypted partition as storage,
|
||||||
add some config to /root/.screenrc (for gnuscreen utility),
|
add some config to /root/.screenrc (for gnuscreen utility),
|
||||||
install htop mc zfsnap smartmontools screen and pv
|
install htop mc smartmontools screen and pv
|
||||||
|
|
||||||
3. Install uptrack-upgrade ->
|
|
||||||
install ksplice tool for kernel live patching
|
|
||||||
|
|
||||||
__Requirements:__
|
__Requirements:__
|
||||||
|
|
||||||
Fresh installation of Ubuntu 18.04.1, swap partition and some paritition to crypted data
|
Fresh installation of Manjaro with kernel package with kernelXY-zfs package, swap partition and some paritition to crypted data
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
218
copy_containers
218
copy_containers
|
@ -1,218 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
CONTS_LIST=$(lxc list | grep "RUNNING\|STOPPED" | awk {'print $2'})
|
|
||||||
|
|
||||||
if [ $# -eq 0 ]
|
|
||||||
then
|
|
||||||
echo "No arguments supplied, doing interactive mode"
|
|
||||||
sleep 1
|
|
||||||
let i=0
|
|
||||||
W=()
|
|
||||||
while read -r line;
|
|
||||||
do
|
|
||||||
let i=$i+1
|
|
||||||
W+=($i "$line" off)
|
|
||||||
done < <( echo "$CONTS_LIST" )
|
|
||||||
CONTS=$(dialog --checklist "Choose containers to copy" 24 80 17 "${W[@]}" 3>&2 2>&1 1>&3)
|
|
||||||
DEST_IP=$(dialog --inputbox "Enter destination IP:" 25 25 --output-fd 1)
|
|
||||||
DEST_PORT=$(dialog --inputbox "Enter destination SSH port(leave blank for default 22):" 25 25 --output-fd 1)
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ ! -z "$1" ]]; then
|
|
||||||
if [[ ! -z "$2" ]]; then
|
|
||||||
CONTS=$(echo "$CONTS_LIST" | nl | grep "$1" | awk {'print $1'})
|
|
||||||
DEST_IP="$2"
|
|
||||||
DEST_PORT="$3"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
[ -z "$DEST_PORT" ] && DEST_PORT=22
|
|
||||||
|
|
||||||
|
|
||||||
DEST_ZPOOL=$(echo crypt)
|
|
||||||
DEST_ZPOOL_2=$(echo storage)
|
|
||||||
|
|
||||||
DATASETS=$(zfs list)
|
|
||||||
SNAPS=$(zfs list -t snapshot)
|
|
||||||
DEST_SNAPS=$(ssh $DEST_IP -p $DEST_PORT zfs list -t snapshot); (($? != 0)) && { echo "SSH command to fill DEST_SNAPS exited with non-zero"; exit 1; }
|
|
||||||
|
|
||||||
|
|
||||||
bionic_checker=$(ssh $DEST_IP -p $DEST_PORT lsb_release -c | awk {'print $2'}); (($? != 0)) && { echo "SSH command to fill bionic_checker exited with non-zero"; exit 1; }
|
|
||||||
|
|
||||||
for CONT in $CONTS;
|
|
||||||
do
|
|
||||||
CONT_VAR=$(echo "$CONTS_LIST"| sed -n "`echo "$CONT p" | sed 's/ //'`")
|
|
||||||
SNAPS_CLEANED=$(echo "$SNAPS" | grep crypt | grep lxd | grep storage | grep containers | grep -E "....-..-.._........--.d" | awk {'print $1'} | grep "$CONT_VAR"@)
|
|
||||||
DEST_SNAPS_CLEANED=$(echo "$DEST_SNAPS" | grep crypt | grep lxd | grep storage | grep containers | grep -E "....-..-.._........--.d" | awk {'print $1'} | grep "$CONT_VAR"@)
|
|
||||||
SOURCE_DEST_IDENTICAL_SNAPS=$(grep -Fxf <(echo "$SNAPS_CLEANED") <(echo "$DEST_SNAPS_CLEANED"))
|
|
||||||
SNAP_TO_SEND_FIRST=$(echo "$SOURCE_DEST_IDENTICAL_SNAPS" | tail -n1)
|
|
||||||
DATASET_VAR=$(echo "$DATASETS" | grep crypt | grep lxd | grep storage | grep containers | awk {'print $1'} | grep -E "$CONT_VAR"$)
|
|
||||||
DATASET_RECORDSIZE_VAR=$(zfs get recordsize -H -o value "$DATASET_VAR")
|
|
||||||
DATASET_ATIME_VAR=$(zfs get atime -H -o value "$DATASET_VAR")
|
|
||||||
DATASET_RELATIME_VAR=$(zfs get relatime -H -o value "$DATASET_VAR")
|
|
||||||
DATASET_QUOTA_VAR=$(zfs get quota -H -o value "$DATASET_VAR")
|
|
||||||
|
|
||||||
SNAP_TO_SEND_FIRST_FOR_LATER_CHECK=$(echo "$SNAP_TO_SEND_FIRST")
|
|
||||||
IFS="
|
|
||||||
"
|
|
||||||
|
|
||||||
echo "Start move "$CONT_VAR""
|
|
||||||
|
|
||||||
if [ -z "$SNAP_TO_SEND_FIRST" ]
|
|
||||||
then
|
|
||||||
|
|
||||||
if [ -z "$SNAPS_CLEANED" ]
|
|
||||||
then
|
|
||||||
|
|
||||||
echo "Creating first snapshot"
|
|
||||||
for command in $(zfSnap -n -zpool28fix -a 7d "$DATASET_VAR" | grep snapshot | grep "$DATASET_VAR")
|
|
||||||
do
|
|
||||||
SNAP_TO_SEND_FIRST=$(echo "$command" | awk '{print $3}')
|
|
||||||
echo "Doing "$command""
|
|
||||||
eval "$command";
|
|
||||||
done
|
|
||||||
|
|
||||||
else
|
|
||||||
SNAP_TO_SEND_FIRST=$(echo "$SNAPS_CLEANED" | tail -n 48 | head -n 1)
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Sending first snapshot"
|
|
||||||
echo "Sending "$SNAP_TO_SEND_FIRST""
|
|
||||||
zfs send "$SNAP_TO_SEND_FIRST" | lzop | pv | ssh "$DEST_IP" -p $DEST_PORT "lzop -d | zfs recv -o recordsize="$DATASET_RECORDSIZE_VAR" -o atime="$DATASET_ATIME_VAR" -o relatime="$DATASET_RELATIME_VAR" -o quota="$DATASET_QUOTA_VAR" "$DEST_ZPOOL"/lxd/storage/containers/"$CONT_VAR""; (($? != 0)) && { echo "SSH command to send first snapshot exited with non-zero"; exit 1; }
|
|
||||||
|
|
||||||
|
|
||||||
echo "Sleep 2"
|
|
||||||
sleep 2
|
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Creating second snapshot"
|
|
||||||
for command in $(zfSnap -n -zpool28fix -a 7d "$DATASET_VAR" | grep snapshot | grep "$DATASET_VAR")
|
|
||||||
do
|
|
||||||
SNAP_TO_SEND_SECOND=$(echo "$command" | awk '{print $3}')
|
|
||||||
echo "Doing "$command""
|
|
||||||
eval "$command";
|
|
||||||
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "Sending second snapshot"
|
|
||||||
echo "Sending "$SNAP_TO_SEND_FIRST" to "$SNAP_TO_SEND_SECOND" with -I parameter"
|
|
||||||
zfs send -I "$SNAP_TO_SEND_FIRST" "$SNAP_TO_SEND_SECOND" | lzop | pv | ssh "$DEST_IP" -p $DEST_PORT "lzop -d | zfs recv -o recordsize="$DATASET_RECORDSIZE_VAR" -o atime="$DATASET_ATIME_VAR" -o relatime="$DATASET_RELATIME_VAR" -o quota="$DATASET_QUOTA_VAR" "$DEST_ZPOOL"/lxd/storage/containers/"$CONT_VAR" -F"; (($? != 0)) && { echo "SSH command to send second snapshot exited with non-zero"; exit 1; }
|
|
||||||
|
|
||||||
echo "Sleep 2"
|
|
||||||
sleep 2
|
|
||||||
|
|
||||||
echo "Creating third snapshot"
|
|
||||||
for command in $(zfSnap -n -zpool28fix -a 7d "$DATASET_VAR" | grep snapshot | grep "$DATASET_VAR")
|
|
||||||
do
|
|
||||||
SNAP_TO_SEND_THIRD=$(echo "$command" | awk '{print $3}')
|
|
||||||
echo "Doing "$command""
|
|
||||||
eval "$command";
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "Sending third snapshot"
|
|
||||||
echo "Sending "$SNAP_TO_SEND_SECOND" to "$SNAP_TO_SEND_THIRD""
|
|
||||||
zfs send -i "$SNAP_TO_SEND_SECOND" "$SNAP_TO_SEND_THIRD" | lzop | pv | ssh "$DEST_IP" -p $DEST_PORT "lzop -d | zfs recv -o recordsize="$DATASET_RECORDSIZE_VAR" -o atime="$DATASET_ATIME_VAR" -o relatime="$DATASET_RELATIME_VAR" -o quota="$DATASET_QUOTA_VAR" "$DEST_ZPOOL"/lxd/storage/containers/"$CONT_VAR" -F"; (($? != 0)) && { echo "SSH command to send third snapshot exited with non-zero"; exit 1; }
|
|
||||||
|
|
||||||
echo "Sleep 2"
|
|
||||||
sleep 2
|
|
||||||
|
|
||||||
echo "Creating fourth snapshot"
|
|
||||||
for command in $(zfSnap -n -zpool28fix -a 7d "$DATASET_VAR" | grep snapshot | grep "$DATASET_VAR")
|
|
||||||
do
|
|
||||||
SNAP_TO_SEND_FOURTH=$(echo "$command" | awk '{print $3}')
|
|
||||||
echo "Doing "$command""
|
|
||||||
eval "$command";
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "Sending fourth snapshot"
|
|
||||||
echo "Sending "$SNAP_TO_SEND_THIRD" to "$SNAP_TO_SEND_FOURTH""
|
|
||||||
zfs send -i "$SNAP_TO_SEND_THIRD" "$SNAP_TO_SEND_FOURTH" | lzop | pv | ssh "$DEST_IP" -p $DEST_PORT "lzop -d | zfs recv -o recordsize="$DATASET_RECORDSIZE_VAR" -o atime="$DATASET_ATIME_VAR" -o relatime="$DATASET_RELATIME_VAR" -o quota="$DATASET_QUOTA_VAR" "$DEST_ZPOOL"/lxd/storage/containers/"$CONT_VAR" -F"; (($? != 0)) && { echo "SSH command to send fourth snapshot exited with non-zero"; exit 1; }
|
|
||||||
|
|
||||||
echo "Sleep 2"
|
|
||||||
sleep 2
|
|
||||||
|
|
||||||
echo "Stopping "$CONT_VAR" on source"
|
|
||||||
lxc stop "$CONT_VAR" --timeout 30; (($? != 0)) && echo "lxc stop timed-out after 30 seconds, doing with force parameter" && lxc stop "$CONT_VAR" --force
|
|
||||||
|
|
||||||
echo "Sleep 2"
|
|
||||||
sleep 2
|
|
||||||
|
|
||||||
echo "Creating fifth snapshot"
|
|
||||||
for command in $(zfSnap -n -zpool28fix -a 7d "$DATASET_VAR" | grep snapshot | grep "$DATASET_VAR")
|
|
||||||
do
|
|
||||||
SNAP_TO_SEND_FIFTH=$(echo "$command" | awk '{print $3}')
|
|
||||||
echo "Doing "$command""
|
|
||||||
eval "$command";
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "Sending fifth snapshot"
|
|
||||||
echo "Sending "$SNAP_TO_SEND_FOURTH" to "$SNAP_TO_SEND_FIFTH""
|
|
||||||
zfs send -i "$SNAP_TO_SEND_FOURTH" "$SNAP_TO_SEND_FIFTH" | lzop | pv | ssh "$DEST_IP" -p $DEST_PORT "lzop -d | zfs recv -o recordsize="$DATASET_RECORDSIZE_VAR" -o atime="$DATASET_ATIME_VAR" -o relatime="$DATASET_RELATIME_VAR" -o quota="$DATASET_QUOTA_VAR" "$DEST_ZPOOL"/lxd/storage/containers/"$CONT_VAR" -F"; (($? != 0)) && { echo "SSH command to send fifth snapshot exited with non-zero"; exit 1; }
|
|
||||||
|
|
||||||
if [ $bionic_checker == bionic ]
|
|
||||||
then
|
|
||||||
|
|
||||||
if [ -z "$SNAP_TO_SEND_FIRST_FOR_LATER_CHECK" ]
|
|
||||||
then
|
|
||||||
|
|
||||||
echo "Setting up mountpoint on destination for "$CONT_VAR""
|
|
||||||
ssh "$DEST_IP" -p $DEST_PORT zfs set mountpoint=/var/lib/lxd/storage-pools/"$DEST_ZPOOL_2"/containers/"$CONT_VAR" "$DEST_ZPOOL"/lxd/storage/containers/"$CONT_VAR"; (($? != 0)) && { echo "SSH command to setup mountpoint on destination exited with non-zero"; exit 1; }
|
|
||||||
|
|
||||||
echo "Fixing config for bionic"
|
|
||||||
ssh "$DEST_IP" -p $DEST_PORT sed -i '/volatile.idmap.current/d' /var/lib/lxd/storage-pools/"$DEST_ZPOOL_2"/containers/"$CONT_VAR"/backup.yaml; (($? != 0)) && { echo "SSH command to setup volatile.idmap exited with non-zero"; exit 1; }
|
|
||||||
ssh "$DEST_IP" -p $DEST_PORT sed -i '/volatile.uuid/d' /var/lib/lxd/storage-pools/"$DEST_ZPOOL_2"/containers/"$CONT_VAR"/backup.yaml; (($? != 0)) && { echo "SSH command to setup volatile.uuid exited with non-zero"; exit 1; }
|
|
||||||
ssh "$DEST_IP" -p $DEST_PORT sed -i '/volatile.cloud-init.instance-id/d' /var/lib/lxd/storage-pools/"$DEST_ZPOOL_2"/containers/"$CONT_VAR"/backup.yaml; (($? != 0)) && { echo "SSH command to setup volatile.cloud-init.instance-id exited with non-zero"; exit 1; }
|
|
||||||
ssh "$DEST_IP" -p $DEST_PORT sed -i '/volatile.last_state.ready/d' /var/lib/lxd/storage-pools/"$DEST_ZPOOL_2"/containers/"$CONT_VAR"/backup.yaml; (($? != 0)) && { echo "SSH command to setup volatile.last_state.ready exited with non-zero"; exit 1; }
|
|
||||||
|
|
||||||
echo "Importing "$CONT_VAR" on destination"
|
|
||||||
ssh "$DEST_IP" -p $DEST_PORT lxd import "$CONT_VAR" --force; (($? != 0)) && { echo "SSH command to import container exited with non-zero"; exit 1; }
|
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Starting "$CONT_VAR" on destination"
|
|
||||||
ssh "$DEST_IP" -p $DEST_PORT lxc start "$CONT_VAR"; (($? != 0)) && { echo "SSH command to start container exited with non-zero"; exit 1; }
|
|
||||||
|
|
||||||
echo " "
|
|
||||||
|
|
||||||
else
|
|
||||||
|
|
||||||
if [ -z "$SNAP_TO_SEND_FIRST_FOR_LATER_CHECK" ]
|
|
||||||
then
|
|
||||||
echo "Setting up mountpoint on destination for "$CONT_VAR""
|
|
||||||
target_snap_version=$(ssh "$DEST_IP" -p $DEST_PORT snap info lxd| grep tracking: | awk {'print $2'} | cut -d"/" -f-1 | cut -d"." -f-1); (($? != 0)) && { echo "SSH command to fill target_snap_version exited with non-zero"; exit 1; }
|
|
||||||
if [[ "$target_snap_version" == 4 ]]
|
|
||||||
then
|
|
||||||
ssh "$DEST_IP" -p $DEST_PORT zfs set canmount=noauto "$DEST_ZPOOL"/lxd/storage/containers/"$CONT_VAR"; (($? != 0)) && { echo "SSH command to setup mountpoint on destination exited with non-zero"; exit 1; }
|
|
||||||
ssh "$DEST_IP" -p $DEST_PORT zfs set mountpoint=/var/snap/lxd/common/lxd/storage-pools/"$DEST_ZPOOL_2"/containers/"$CONT_VAR" "$DEST_ZPOOL"/lxd/storage/containers/"$CONT_VAR"; (($? != 0)) && { echo "SSH command to setup mountpoint on destination exited with non-zero"; exit 1; }
|
|
||||||
ssh "$DEST_IP" -p $DEST_PORT zfs mount "$DEST_ZPOOL"/lxd/storage/containers/"$CONT_VAR"; (($? != 0)) && { echo "SSH command to setup mountpoint on destination exited with non-zero"; exit 1; }
|
|
||||||
REMOTE_LXD_PID=$(ssh "$DEST_IP" -p $DEST_PORT cat /var/snap/lxd/common/lxd.pid); (($? != 0)) && { echo "SSH command to get REMOTE_LXD_PID on destination exited with non-zero"; exit 1; }
|
|
||||||
ssh "$DEST_IP" -p $DEST_PORT "nsenter -t $REMOTE_LXD_PID -m bash -c \"mount -t zfs "$DEST_ZPOOL"/lxd/storage/containers/"$CONT_VAR" /var/snap/lxd/common/lxd/storage-pools/"$DEST_ZPOOL_2"/containers/"$CONT_VAR"\""; (($? != 0)) && { echo "SSH command to set REMOTE_LXD_PID on destination exited with non-zero"; exit 1; }
|
|
||||||
|
|
||||||
echo "Fixing config for lxd version 4"
|
|
||||||
ssh "$DEST_IP" -p $DEST_PORT sed -i '/volatile.cloud-init.instance-id/d' /var/snap/lxd/common/lxd/storage-pools/"$DEST_ZPOOL_2"/containers/"$CONT_VAR"/backup.yaml; (($? != 0)) && { echo "SSH command to setup volatile.cloud-init.instance-id exited with non-zero"; exit 1; }
|
|
||||||
ssh "$DEST_IP" -p $DEST_PORT sed -i '/volatile.last_state.ready/d' /var/snap/lxd/common/lxd/storage-pools/"$DEST_ZPOOL_2"/containers/"$CONT_VAR"/backup.yaml; (($? != 0)) && { echo "SSH command to setup volatile.last_state.ready exited with non-zero"; exit 1; }
|
|
||||||
|
|
||||||
echo "Importing "$CONT_VAR" on destination"
|
|
||||||
ssh "$DEST_IP" -p $DEST_PORT /snap/bin/lxd import "$CONT_VAR" --force; (($? != 0)) && { echo "SSH command to import container exited with non-zero"; exit 1; }
|
|
||||||
ssh "$DEST_IP" -p $DEST_PORT zfs umount "$DEST_ZPOOL"/lxd/storage/containers/"$CONT_VAR"; (($? != 0)) && { echo "SSH command to import container exited with non-zero"; exit 1; }
|
|
||||||
else
|
|
||||||
|
|
||||||
echo "Doing lxd recover"
|
|
||||||
ssh "$DEST_IP" -p $DEST_PORT zfs set mountpoint=legacy "$DEST_ZPOOL"/lxd/storage/containers/"$CONT_VAR"; (($? != 0)) && { echo "SSH command to setup mountpoint=legacy on destination exited with non-zero"; exit 1; }
|
|
||||||
ssh "$DEST_IP" -p $DEST_PORT "cat <<EOF | lxd recover
|
|
||||||
no
|
|
||||||
yes
|
|
||||||
yes
|
|
||||||
EOF"; (($? != 0)) && { echo "SSH command lxd recover exited with non-zero"; exit 1; }
|
|
||||||
fi
|
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Starting "$CONT_VAR" on destination"
|
|
||||||
ssh "$DEST_IP" -p $DEST_PORT /snap/bin/lxc start "$CONT_VAR"; (($? != 0)) && { echo "SSH command to start container exited with non-zero"; exit 1; }
|
|
||||||
|
|
||||||
echo " "
|
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
done
|
|
102
setup-usl-mm
102
setup-usl-mm
|
@ -12,16 +12,18 @@ else
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Exec ifconfig"
|
echo "Doing pacman -Syy"
|
||||||
ifconfig
|
pacman -Syy
|
||||||
read -p "Enter interface for configure bridge:" NET_IF
|
|
||||||
|
|
||||||
echo "Starting lsblk"
|
echo "Starting lsblk"
|
||||||
lsblk
|
lsblk
|
||||||
read -p "Enter partition to encrypt:" PARTITION
|
read -p "Enter partition to encrypt:" PARTITION
|
||||||
|
|
||||||
echo "Installing requirements"
|
echo "Installing requirements"
|
||||||
apt install cryptsetup ecryptfs-utils zfsutils-linux lzop -y
|
pacman -S --noconfirm cryptsetup ecryptfs-utils $(pacman -Q linux | tail -n 1 | awk {'print $1'})-zfs $(pacman -Q linux | tail -n 1 | awk {'print $1'})-headers parted
|
||||||
|
|
||||||
|
echo "Loading ZFS kernel module"
|
||||||
|
modprobe zfs
|
||||||
|
|
||||||
echo "Setting timezone to Prague"
|
echo "Setting timezone to Prague"
|
||||||
timedatectl set-timezone Europe/Prague
|
timedatectl set-timezone Europe/Prague
|
||||||
|
@ -46,16 +48,26 @@ zfs create crypt/lxd
|
||||||
zfs create crypt/lxd/dir
|
zfs create crypt/lxd/dir
|
||||||
zfs create crypt/lxd/storage
|
zfs create crypt/lxd/storage
|
||||||
|
|
||||||
|
echo "Install snapd and lxd"
|
||||||
|
pacman -S snapd --noconfirm
|
||||||
|
systemctl enable snapd
|
||||||
|
systemctl start snapd
|
||||||
|
sleep 5
|
||||||
|
snap install lxd
|
||||||
|
|
||||||
|
echo "Switch to 5.19 LXD version"
|
||||||
|
snap switch --channel 5.19/stable lxd
|
||||||
|
snap refresh
|
||||||
|
|
||||||
echo "Stopping and disabling lxd"
|
echo "Stopping and disabling lxd"
|
||||||
systemctl disable lxd
|
snap stop --disable lxd
|
||||||
systemctl disable lxd.socket
|
snap disable lxd
|
||||||
systemctl stop lxd
|
|
||||||
|
|
||||||
echo "Deleting everything in /var/lib/lxd/*"
|
echo "Deleting everything in /var/snap/lxd/common/lxd/*"
|
||||||
rm /var/lib/lxd/* -r
|
rm /var/snap/lxd/common/lxd/* -r
|
||||||
|
|
||||||
echo "Creating mountpoint /var/lib/lxd to crypt/lxd/dir"
|
echo "Creating mountpoint /var/snap/lxd/common/lxd to crypt/lxd/dir"
|
||||||
zfs set mountpoint=/var/lib/lxd crypt/lxd/dir
|
zfs set mountpoint=/var/snap/lxd/common/lxd crypt/lxd/dir
|
||||||
|
|
||||||
echo "Configuring sysctl"
|
echo "Configuring sysctl"
|
||||||
echo "vm.swappiness = 1" > /etc/sysctl.d/50-usl-mm.conf
|
echo "vm.swappiness = 1" > /etc/sysctl.d/50-usl-mm.conf
|
||||||
|
@ -74,39 +86,11 @@ echo "options zfs zfs_arc_min=268435456" > /etc/modprobe.d/zfs.conf
|
||||||
echo "options zfs zfs_arc_max=1610612736" >> /etc/modprobe.d/zfs.conf
|
echo "options zfs zfs_arc_max=1610612736" >> /etc/modprobe.d/zfs.conf
|
||||||
echo "options zfs zfs_txg_timeout=3" >> /etc/modprobe.d/zfs.conf
|
echo "options zfs zfs_txg_timeout=3" >> /etc/modprobe.d/zfs.conf
|
||||||
|
|
||||||
echo "Doing update-initramfs -u"
|
echo "Doing mkinitcpio -P"
|
||||||
update-initramfs -u
|
mkinitcpio -P
|
||||||
|
|
||||||
echo "Configuring network to use bridge"
|
echo "Doing pacman -Suu"
|
||||||
echo "auto lo" > /etc/network/interfaces
|
pacman -Suu --noconfirm
|
||||||
echo "iface lo inet loopback" >> /etc/network/interfaces
|
|
||||||
echo " " >> /etc/network/interfaces
|
|
||||||
echo "iface $NET_IF inet manual" >> /etc/network/interfaces
|
|
||||||
echo "iface $NET_IF inet6 manual" >> /etc/network/interfaces
|
|
||||||
echo "auto br0" >> /etc/network/interfaces
|
|
||||||
echo "iface br0 inet dhcp" >> /etc/network/interfaces
|
|
||||||
echo " bridge_ports $NET_IF" >> /etc/network/interfaces
|
|
||||||
echo " bridge_stp off" >> /etc/network/interfaces
|
|
||||||
echo " bridge_fd 0" >> /etc/network/interfaces
|
|
||||||
echo " " >> /etc/network/interfaces
|
|
||||||
echo "iface br0 inet6 auto" >> /etc/network/interfaces
|
|
||||||
echo " bridge_ports $NET_IF" >> /etc/network/interfaces
|
|
||||||
echo " bridge_stp off" >> /etc/network/interfaces
|
|
||||||
echo " bridge_fd 0" >> /etc/network/interfaces
|
|
||||||
|
|
||||||
echo "Add DNS to systemd-resolved"
|
|
||||||
echo "[Resolve]" > /etc/systemd/resolved.conf
|
|
||||||
echo "DNS=8.8.8.8" >> /etc/systemd/resolved.conf
|
|
||||||
echo "FallbackDNS=1.1.1.1" >> /etc/systemd/resolved.conf
|
|
||||||
|
|
||||||
echo "Purging netplan,disabling dhcpcd and install ifupdown"
|
|
||||||
apt purge nplan -y
|
|
||||||
rm /etc/netplan/* -f
|
|
||||||
apt install bridge-utils ifupdown -y
|
|
||||||
|
|
||||||
echo "Doing apt update and apt dist-upgrade"
|
|
||||||
apt update
|
|
||||||
apt dist-upgrade -y
|
|
||||||
|
|
||||||
echo "Creating onstart script in /root"
|
echo "Creating onstart script in /root"
|
||||||
echo "#!/bin/bash" > /root/onstart
|
echo "#!/bin/bash" > /root/onstart
|
||||||
|
@ -119,11 +103,16 @@ echo "else" >> /root/onstart
|
||||||
echo "echo \"Passwords not match!\"" >> /root/onstart
|
echo "echo \"Passwords not match!\"" >> /root/onstart
|
||||||
echo "exit 1" >> /root/onstart
|
echo "exit 1" >> /root/onstart
|
||||||
echo "fi" >> /root/onstart
|
echo "fi" >> /root/onstart
|
||||||
|
echo "echo \"Stopping LXD snap daemon and deleting /var/snap/lxd/common/lxd/*\"" >> /root/onstart
|
||||||
|
echo "snap disable lxd" >> /root/onstart
|
||||||
|
echo "rm /var/snap/lxd/common/lxd/* -rf" >> /root/onstart
|
||||||
echo "echo \"Opening encrypted partition\"" >> /root/onstart
|
echo "echo \"Opening encrypted partition\"" >> /root/onstart
|
||||||
echo "echo \$pass_var | cryptsetup open $PARTITION crypt -c -" >> /root/onstart
|
echo "echo \$pass_var | cryptsetup open $PARTITION crypt -c -" >> /root/onstart
|
||||||
echo "partprobe" >> /root/onstart
|
echo "partprobe" >> /root/onstart
|
||||||
echo "zpool import -d /dev/mapper crypt -f -m" >> /root/onstart
|
echo "zpool import -d /dev/mapper crypt -f -m" >> /root/onstart
|
||||||
echo "systemctl start lxd" >> /root/onstart
|
echo "sleep 5" >> /root/onstart
|
||||||
|
echo "snap enable lxd" >> /root/onstart
|
||||||
|
echo "snap start lxd" >> /root/onstart
|
||||||
|
|
||||||
chmod +x /root/onstart
|
chmod +x /root/onstart
|
||||||
read -p "Press any key for reboot"
|
read -p "Press any key for reboot"
|
||||||
|
@ -131,9 +120,9 @@ reboot
|
||||||
}
|
}
|
||||||
|
|
||||||
post_reboot_script () {
|
post_reboot_script () {
|
||||||
echo "Stopping lxd and delete /var/lib/lxd/*"
|
echo "Stopping lxd and delete /var/snap/lxd/common/lxd/*"
|
||||||
systemctl stop lxd
|
systemctl stop snap.lxd.daemon
|
||||||
rm /var/lib/lxd/* -r
|
rm /var/snap/lxd/common/lxd/* -r
|
||||||
|
|
||||||
echo "Executing /root/onstart"
|
echo "Executing /root/onstart"
|
||||||
bash /root/onstart
|
bash /root/onstart
|
||||||
|
@ -177,11 +166,10 @@ echo "scrollback 5000" >> /root/.screenrc
|
||||||
echo "hardstatus string \"%{=b kw} %?%-Lw%?%{=br kw}[%n %t]%{=b kw}%?%+Lw%? %= %c\"" >> /root/.screenrc
|
echo "hardstatus string \"%{=b kw} %?%-Lw%?%{=br kw}[%n %t]%{=b kw}%?%+Lw%? %= %c\"" >> /root/.screenrc
|
||||||
|
|
||||||
echo "Install utilities"
|
echo "Install utilities"
|
||||||
apt install -y mc htop screen zfsnap smartmontools pv
|
pacman -S --noconfirm mc htop screen smartmontools pv
|
||||||
|
|
||||||
echo "Setting-up wireguard"
|
echo "Setting-up wireguard"
|
||||||
apt update
|
pacman -S --noconfirm wireguard-dkms wireguard-tools
|
||||||
apt install wireguard -y
|
|
||||||
lxc profile set default linux.kernel_modules wireguard
|
lxc profile set default linux.kernel_modules wireguard
|
||||||
|
|
||||||
echo "Set max processes to 3000 in default profile in LXD"
|
echo "Set max processes to 3000 in default profile in LXD"
|
||||||
|
@ -194,21 +182,11 @@ read -p "Done, press any key to return to main menu"
|
||||||
main_menu
|
main_menu
|
||||||
}
|
}
|
||||||
|
|
||||||
install_uptrack () {
|
|
||||||
cd /tmp
|
|
||||||
wget https://ksplice.oracle.com/uptrack/dist/bionic/ksplice-uptrack.deb
|
|
||||||
apt install libgtk2-perl dbus-x11 libglade2-0 libpython-stdlib libpython2.7-minimal libpython2.7-stdlib python python-cairo python-dbus python-gi python-glade2 python-gobject-2 python-gtk2 python-minimal python-pycurl python-yaml python2.7 python2.7-minimal -y
|
|
||||||
dpkg -i ksplice-uptrack.deb
|
|
||||||
read -p "Done, press any key to return to main menu"
|
|
||||||
main_menu
|
|
||||||
}
|
|
||||||
|
|
||||||
main_menu () {
|
main_menu () {
|
||||||
cmd=(dialog --nocancel --menu "Welcome in setup-lxd-mm!" 22 76 16)
|
cmd=(dialog --nocancel --menu "Welcome in setup-lxd-mm!" 22 76 16)
|
||||||
options=(
|
options=(
|
||||||
1 "Pre-reboot script"
|
1 "Pre-reboot script"
|
||||||
2 "Post-reboot script"
|
2 "Post-reboot script"
|
||||||
3 "Install uptrack-upgrade"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
|
choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
|
||||||
|
@ -225,10 +203,6 @@ main_menu () {
|
||||||
post_reboot_script
|
post_reboot_script
|
||||||
;;
|
;;
|
||||||
|
|
||||||
3)
|
|
||||||
install_uptrack
|
|
||||||
;;
|
|
||||||
|
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
clear
|
clear
|
||||||
|
|
|
@ -1,6 +1,2 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
echo "deb http://archive.ubuntu.com/ubuntu bionic main universe" > /etc/apt/sources.list
|
pacman -S dialog --noconfirm
|
||||||
echo "deb http://archive.ubuntu.com/ubuntu bionic-security main universe" >> /etc/apt/sources.list
|
|
||||||
echo "deb http://archive.ubuntu.com/ubuntu bionic-updates main universe" >> /etc/apt/sources.list
|
|
||||||
apt update
|
|
||||||
apt install dialog
|
|
|
@ -1,67 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
# Use with first argument with codename of new ubuntu distro(eoan,focal, etc)
|
|
||||||
IFS='
|
|
||||||
'
|
|
||||||
current_release=$(lsb_release -c | awk {'print $2'})
|
|
||||||
export DEBIAN_FRONTEND=noninteractive
|
|
||||||
apt update
|
|
||||||
apt dist-upgrade -y -o Dpkg::Options::="--force-confold"
|
|
||||||
apt install rpl -y
|
|
||||||
snap install --channel 4.16/stable lxd
|
|
||||||
if [ $current_release == bionic ]; then
|
|
||||||
lxd.migrate -yes
|
|
||||||
fi
|
|
||||||
zfs set mountpoint=/var/snap/lxd/common/lxd crypt/lxd/dir
|
|
||||||
rpl $current_release $1 /etc/apt/sources.list
|
|
||||||
rpl $current_release $1 /etc/apt/sources.list.d/*
|
|
||||||
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 82562EA9AD986DA3
|
|
||||||
apt update
|
|
||||||
apt dist-upgrade -y -o Dpkg::Options::="--force-confold"
|
|
||||||
|
|
||||||
echo "Creating onstart-new script in /root"
|
|
||||||
echo "#!/bin/bash" > /root/onstart-new
|
|
||||||
echo "read -p \"Press any button to start...\"" >> /root/onstart-new
|
|
||||||
echo "pass_var=\$(dialog --passwordbox \"Enter password:\" 25 25 --output-fd 1)" >> /root/onstart-new
|
|
||||||
echo "pass_var2=\$(dialog --passwordbox \"Enter password again:\" 25 25 --output-fd 1)" >> /root/onstart-new
|
|
||||||
echo "if [ \"\$pass_var\" == \"\$pass_var2\" ]; then" >> /root/onstart-new
|
|
||||||
echo "echo \"Passwords match!\"" >> /root/onstart-new
|
|
||||||
echo "else" >> /root/onstart-new
|
|
||||||
echo "echo \"Passwords not match!\"" >> /root/onstart-new
|
|
||||||
echo "exit 1" >> /root/onstart-new
|
|
||||||
echo "fi" >> /root/onstart-new
|
|
||||||
echo "echo \"Stopping LXD snap daemon and deleting /var/snap/lxd/common/lxd/*\"" >> /root/onstart-new
|
|
||||||
echo "snap disable lxd" >> /root/onstart-new
|
|
||||||
echo "rm /var/snap/lxd/common/lxd/* -rf" >> /root/onstart-new
|
|
||||||
echo "echo \"Opening encrypted partition\"" >> /root/onstart-new
|
|
||||||
for i in $(cat /root/onstart | grep "cryptsetup open")
|
|
||||||
do echo "$i" >> /root/onstart-new
|
|
||||||
done
|
|
||||||
echo "partprobe" >> /root/onstart-new
|
|
||||||
for i in $(cat /root/onstart | grep "zpool import")
|
|
||||||
do echo "$i" >> /root/onstart-new
|
|
||||||
done
|
|
||||||
echo "snap enable lxd" >> /root/onstart-new
|
|
||||||
for i in $(cat /root/onstart | grep "iptables")
|
|
||||||
do echo "$i" >> /root/onstart-new
|
|
||||||
done
|
|
||||||
for i in $(cat /root/onstart | grep "firewall")
|
|
||||||
do echo "$i" >> /root/onstart-new
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "cryptdisks_start cryptswap1" >> /root/onstart-new
|
|
||||||
echo "swapon -a" >> /root/onstart-new
|
|
||||||
|
|
||||||
chmod +x /root/onstart-new
|
|
||||||
|
|
||||||
mv /root/onstart /root/onstart-old
|
|
||||||
mv /root/onstart-new /root/onstart
|
|
||||||
|
|
||||||
zfs set mountpoint=/var/snap/lxd/common/lxd crypt/lxd/dir
|
|
||||||
|
|
||||||
snap switch --channel 5.19/stable lxd
|
|
||||||
snap refresh
|
|
||||||
|
|
||||||
apt install uptrack -y
|
|
||||||
|
|
||||||
read -p "Press any key for reboot"
|
|
||||||
reboot
|
|
|
@ -1,28 +0,0 @@
|
||||||
#Backup server settings
|
|
||||||
|
|
||||||
backup_server="192.168.0.10"
|
|
||||||
backup_server_port="22"
|
|
||||||
backup_server_ipv=4
|
|
||||||
backup_server_dataset="tank/backups"
|
|
||||||
backup_server_delete_old_snaps=y
|
|
||||||
backup_server_number_keep_snaps=31
|
|
||||||
|
|
||||||
shape_megabytes=20
|
|
||||||
#Source server settings
|
|
||||||
#DO NOT CHANGE zfsnap_days_keep_snaps AFTER FIRST FULL BACKUP!
|
|
||||||
|
|
||||||
zfsnap_enable=y
|
|
||||||
zfsnap_days_keep_snaps=7
|
|
||||||
|
|
||||||
running_containers=$(lxc list | grep RUNNING | awk {'print $2'})
|
|
||||||
stopped_containers=$(lxc list | grep STOPPED | awk {'print $2'})
|
|
||||||
|
|
||||||
excluded_strings="deluge\|testing"
|
|
||||||
|
|
||||||
if [ -z "$stopped_containers" ]
|
|
||||||
then
|
|
||||||
source_datasets="$(zfs list | awk {'print $1'} | grep "crypt/lxd/storage/containers" | grep -ve "crypt/lxd/storage/containers$" | grep -e "$running_containers" | grep -ve "$excluded_strings")"
|
|
||||||
else
|
|
||||||
source_datasets="$(zfs list | awk {'print $1'} | grep "crypt/lxd/storage/containers" | grep -ve "crypt/lxd/storage/containers$" | grep -e "$running_containers" | grep -ve "$stopped_containers" | grep -ve "$excluded_strings")"
|
|
||||||
fi
|
|
||||||
|
|
Loading…
Reference in a new issue