-
Notifications
You must be signed in to change notification settings - Fork 1
/
commands.sh
123 lines (89 loc) · 4.1 KB
/
commands.sh
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
######################## SAFETY START
if [[ $EUID -eq 0 ]]; then
error "Do not run this as the root user"
echo "This is not intended to be run as bulk bash commands. Read the file using editor nano or cat and apply commands one by one."
exit 1
fi
######################## SAFETY END
########################
######## Description of variables and vars use cases
########################
# take care and make all changes wisely!!!
# https://github.com/openzfs/zfs/wiki/ZFS-on-Linux-Module-Parameters
########################
######## status commands
########################
# general zfs pools check
zfs list
# all zpool status
zpool status
# certain pool status
zpool status zpool-name-here
# arc statistics
arc_summary
########################
######## add L2ARC cache disk (SSD or NVMe) to zpool
########################
#### note: L2ARC need to be clean from any partition
#### to clear (destroy) partition from cache disk use:
# step 1) list and locate ssd/nvme disk
# in our example we have device under path /dev/nvme0n1
lsblk
# step 2) use utility 'fdisk' on your disk
fdisk /dev/nvme0n1
# step 2a) destroy partition by command 'd', repeat until you see: 'No partition is defined yet!'
d
# step 2b) write changes to disk
w
# step 2c) exit 'fdisk' utility (however you like)
ctrl + c
# step 3) attach cache device to pool
zpool add zpool-name-here cache nvme0n1
# step 4) confirm that cache is attached by using 'zpool status'
zpool status zpool-name-here
# you should see your cache device under column NAME -> cache. You now have L2ARC device
# shutdown and start again active VMs machines
########################
######## ZFS file system variables optimisation for speed, performance, IOPS
########################
# check (list) current zpool settings
zfs get all zpool-name-here
# 'sync' - disabled means that data gets synced either every 5 seconds or every 64M IIRC. If you're willing to risk the last ~5 seconds you can run with this.
# UPS as backup power should avoid transaction loss in case of power outage
zfs set sync=disabled zpool-name-here
# 'axttr' - you can use the xattr property to disable or enable extended attributes for a specific ZFS file system. The default value is on
zfs set xattr=sa zpool-name-here
# 'secondarycache' - (L2ARC) - if set to 'all', both user data and metadata are cached. If set to 'none', neither user data nor metadata is cached. If set to 'metadata', only metadata is cached.
zfs set secondarycache=all zpool-name-here
# 'atime' - will disable writing timestamp of access to file on read - leave on when you want to know where you access file
zfs set atime=off zpool-name-here
########################
######## ZFS L2ARC optimisation
########################
# bellow optimization commands need to be inside zfs.conf file. It's probably empty by default so edit:
nano /etc/modprobe.d/zfs.conf
# l2arc_noprefetch' enables (0/zero is not a mistake) L2ARC prefetching - read stream from pool is cached inside L2ARC so this acts as aggressive cache method. Usefull when you have relatively large L2ARC device and enough RAM for standard ARC.
options zfs l2arc_noprefetch=0
# Maximum number of bytes to be written to each cache device for each L2ARC feed thread interval (see l2arc_feed_secs). The actual limit can be adjusted by l2arc_write_boost. By default l2arc_feed_secs is 1 second, delivering a maximum write workload to cache devices of 8 MiB/sec.
# default: 8388608 / 1024 / 1024 = 8 MiB/s
# max: 50331648 / 1024 / 1024 = 48 MiB/s
# boosted if cache cold: 100663296 = 96 MiB/s
options zfs l2arc_write_max=50331648
options zfs l2arc_write_boost=100663296
########################
######## misc/other helpful commands
########################
# lower the tendence to swappines - stay on ARC/L2ARC reads more than 'swap' (which is on slower disk)
# bellow optimization commands need to be inside sysctl.conf
# step 1)
nano /etc/sysctl.conf
# step 1b )
vm.swappiness=10
########################
######## reboot to changes take place
########################
reboot
########################
######## analyze (list) arc statistic (ARC and L2ARC + tunable commands)
########################
arc_summary