-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateSHR.bash
102 lines (79 loc) · 3.4 KB
/
createSHR.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/bash
apt update
mkdir install-tmp
mv createSHR.bash install-tmp
cd install-tmp
set-PASS () {
local passvar=1; local passvar2=2
while [ "$passvar" != "$passvar2" ]; do echo "SMB password previously unset or input inconsistent."; \
read -sp 'Password: ' passvar
echo
read -sp 'Confirm: ' passvar2
echo
done
smb_password="$(iconv -f ASCII -t UTF-16LE <(printf $passvar) | openssl dgst -md4 -provider legacy | awk -F '= ' {'print $2'})"
}
set-PASS
create-TEMPLATE () {
tpID=10001
vmNAME=microos
vmDESC="openSUSE MicroOS base template"
qm create $tpID \
--name $vmNAME --description "$vmDESC" --cores 1 --cpu cputype=host --memory 1024 --balloon 1024 --net0 model=virtio,bridge=vmbr0 --bios ovmf --ostype l26 \
--machine q35 --scsihw virtio-scsi-single --onboot 0 --cdrom none --agent enabled=1 --boot order=virtio0 --efidisk0 local-btrfs:4,efitype=4m,pre-enrolled-keys=1
curl -O -L https://download.opensuse.org/tumbleweed/appliances/openSUSE-MicroOS.x86_64-kvm-and-xen.qcow2
qm disk import $tpID openSUSE-MicroOS.x86_64-kvm-and-xen.qcow2 local-btrfs
qm set $tpID --virtio0 local-btrfs:$tpID/vm-$tpID-disk-1.raw,cache=writeback,discard=on,iothread=1
qm disk resize $tpID virtio0 25G
qm set $tpID --template 1
}
create-TEMPLATE
cd .. && rm -rf install-tmp
apt update && apt full-upgrade -y && apt autopurge -y
apt install -y bcache-tools duperemove samba snapper
systemctl enable smb
drive=$(ls /dev/sd*)
cache=( /dev/nvme0n1 /dev/nvme1n1 )
pvcreate -ff ${cache[@]}
vgcreate cache ${cache[@]}
lvcreate -n nvme -l 100%PV --type raid1 --wipesignatures y cache
make-bcache -C /dev/cache/nvme
make-bcache -B ${drive[@]}
sleep 1
bcache-super-show /dev/cache/nvme | grep cset.uuid | awk -F ' ' {'print $2'} | tee /sys/block/bcache*/bcache/attach
echo writethrough | tee /sys/block/bcache*/bcache/cache_mode
echo 0 | tee /sys/block/bcache*/bcache/writeback_percent
mkfs.btrfs -f -L data -m raid1 -d raid1 $(find /dev/bcache* -maxdepth 0 -type b)
mkdir -p /var/share/mnt
mount /dev/bcache0 /var/share/mnt
{ echo; echo '/dev/bcache0 /var/share/mnt btrfs nofail 0 2'; } >> /etc/fstab
fstrim -av
btrfs subvolume create /var/share/mnt/vms
btrfs subvolume create /var/share/mnt/vms/backup
pvesm add btrfs mass-storage --path /var/share/mnt/vms --content iso,vztmpl,images,rootdir
btrfs subvolume create /var/share/mnt/net
mkdir /var/share/mnt/.duperemove
{ echo "$smb_password"; echo "$smb_password"; } | smbpasswd -a root
pdbedit -u root --set-nt-hash "$smb_password"
cat <<'EOL' > /etc/samba/smb.conf
[smb-net]
comment = user data network share
path = /var/share/mnt/net
read only = no
inherit owner = yes
inherit permissions = yes
EOL
snapper -c data create-config /var/share/mnt/net
snapper -c data set-config "TIMELINE_CREATE=yes" "TIMELINE_CLEANUP=yes" \
"TIMELINE_LIMIT_HOURLY=24" "TIMELINE_LIMIT_DAILY=7" "TIMELINE_LIMIT_WEEKLY=6" \
"TIMELINE_LIMIT_MONTHLY=0" "TIMELINE_LIMIT_YEARLY=0"
snapper -c data setup-quota
{ crontab -l 2>/dev/null
cat <<'EOL'
#@reboot echo 0 | tee /sys/block/bcache*/bcache/sequential_cutoff
@reboot echo 0 | tee /sys/block/bcache*/bcache/writeback_percent
0 6 * * 1 duperemove -dhr --dedupe-options=same --hash=xxhash --hashfile=/var/share/mnt/.duperemove/hashfile.db /var/share/mnt
0 5 1 * * rm -rf /var/share/mnt/.duperemove/hashfile.db && btrfs balance start -musage=50 -dusage=50 /var/share/mnt
0 5 15 * * btrfs scrub start /var/share/mnt
EOL
} | crontab -