Остання активність 1 day ago

Версія 78bd4e115662471eae4cfa6f305c4f04a401f9c0

arm64-bionic-zfs Неформатований
1#!/bin/bash
2
3#
4# Read this script and modify it before running. It's not tested as is and is not
5# meant to be run unsupervised.
6#
7
8hostname='YOUR_DESIRED_HOSTNAME'
9user='YOUR_USERNAME'
10hdd_spindown_timeout=1800
11
12###### with bionic already installed, ssh as rock64, pass rock64
13# gain superuser privilege
14sudo su
15
16# set timezone
17timedatectl set-timezone America/New_York
18
19# adduser
20adduser "$user"
21
22# add to sudo group
23usermod -aG sudo "$user"
24
25###### login as user
26# generate ssh folder and keys
27ssh-keygen -t rsa -b 4096 -C "rock64"
28
29# add your remote host key to authorized_keys
30touch ~/.ssh/authorized_keys
31chmod 600 ~/.ssh/authorized_keys
32vi ~/.ssh/authorized_keys
33
34# gain superuser access
35sudo su
36
37# lock default rock64 account
38passwd -l rock64
39
40# update hostname
41hostnamectl set-hostname "$hostname"
42
43# install packages
44apt-get install -y \
45 zfsutils-linux zfs-dkms spl \
46 samba \
47 debhelper hdparm
48
49#### fix for kernel module builds
50#### https://forum.armbian.com/topic/6789-build-zfs-on-rk3328/?tab=comments#comment-53681
51# copy kernel source
52# NOTE: you may need to change these paths for your kernel version
53wget -qO- https://github.com/ayufan-rock64/linux-kernel/archive/4.4.167-1169-rockchip-ayufan.tar.gz | tar xvz -C /usr/src
54
55# copy kernel source tools + scripts folder for builds to work
56# NOTE: you may need to change these paths for your kernel version
57rsync -a /usr/src/linux-kernel-4.4.167-1169-rockchip-ayufan/tools/ /usr/src/linux-headers-4.4.167-1169-rockchip-ayufan-g3cde5c624c9c/tools/
58rsync -a /usr/src/linux-kernel-4.4.167-1169-rockchip-ayufan/scripts/ /usr/src/linux-headers-4.4.167-1169-rockchip-ayufan-g3cde5c624c9c/scripts/
59
60# comment out selinux
61# NOTE: read instructions at link, this sed command doesn't work
62# sed -i 's/subdir\-\$\(CONFIG_SECURITY_SELINUX\)/#subdir-$(CONFIG_SECURITY_SELINUX)/' /usr/src/linux-headers-4.4.167-1169-rockchip-ayufan-g3cde5c624c9c/scripts/Makefile
63
64# make kernel scripts
65# NOTE: you may need to change these paths for your kernel version
66cd /usr/src/linux-headers-4.4.167-1169-rockchip-ayufan-g3cde5c624c9c/
67make scripts
68
69#### fix for spl kernel module
70#### https://forum.armbian.com/topic/6789-build-zfs-on-rk3328/?tab=comments#comment-53681
71# remove some KUID lines
72# NOTE: read instructions at link, didn't get a chance to script it
73# vi /var/lib/dkms/spl/0.7.5/source/configure
74
75# NOTE: path may vary based on spl version
76dkms build spl/0.7.5
77dkms install --force spl/
78modprobe spl
79
80# attempt to install again
81apt-get install -y \
82 zfsutils-linux zfs-dkms spl \
83 samba \
84 debhelper hdparm
85
86#### configure samba
87#### https://www.computerbeginnersguides.com/blog/2018/04/27/install-and-configure-samba-in-ubuntu-18-04-bionic-beaver/
88# add curiouser user
89smbpasswd -a "$user"
90
91# add share
92cat <<EOF >> /etc/samba/smb.conf
93[curiouser-backup]
94path = SOME_PATH
95available = yes
96valid users = SOME_USER
97read only = no
98browseable = yes
99public = no
100writable = yes
101access based share enum = yes
102EOF
103
104#### HDD Power management
105## Allow disks to standby after 5 minutes of inactivty
106# NOTE: this may be all you need depending on your disks + enclosure, but for my use case
107# this doesn't spin the disks down, just uses less power
108cat <<EOF >> /etc/rc.local
109#!/bin/bash
110hdparm -B127 -S60 /dev/sda
111hdparm -B127 -S60 /dev/sdb
112exit 0
113EOF
114chmod u+x /etc/rc.local
115
116## Spin down disks after 30 minutes of inactivity using hd-idle
117# download, extract and install
118wget https://github.com/h31/hd-idle/archive/master.zip \
119 && unzip master.zip \
120 && cd hd-idle-master \
121 && dpkg-buildpackage \
122 && dpkg -i ../hd-idle_*.deb
123
124# configure hd-idle to start on boot
125sed -i 's/START_HD_IDLE=.*/START_HD_IDLE=true/' /etc/default/hd-idle
126# configure hd-idle to not spin down disks by default, but spin down our curiouser-backup after 30 minutes
127# NOTE: you'll want to edit the next command to target your disks and for your desired timeout
128echo 'HD_IDLE_OPTS="-i 0 -a sda -i $hdd_spindown_timeout -a sdb -i $hdd_spindown_timeout -l /var/log/hd-idle.log"' >> /etc/default/hd-idle
129
130#### Reboot
131systemctl reboot