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