aboutsummaryrefslogtreecommitdiffstats
path: root/README.txt
blob: 67cf621920382d880303d1ebcb3df399dedbf4de (plain)
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
#
# Debian ZFS Live 
# ====================
# This package provides recipes and scripts to produce 
# a Debian ZFS Live ISO or USB image.
#
# ZFS on Linux https://zfsonlinux.org/
#
# Derived from: https://github.com/zfsonlinux/zfs/wiki/Debian-Buster-Root-on-ZFS
#               https://github.com/zfsonlinux/zfs/wiki/Debian-Stretch-Root-on-ZFS
#
# Binary debian packages within 
# - zfs-linux-0.7.13-debian10-amd64
# - zfs-linux-0.7.13-debian9-amd64
#
# have been produced using the contained zfs-linux-0.7.13-source.tar.gz
# on debian10-amd64 and debian9-amd64, which use git sources from
# - https://github.com/zfsonlinux/spl.git
# - https://github.com/zfsonlinux/zfs.git
# 
# Assuming this packages is contained in its folder 'debian-zfs-live',
# all scripts should be executed from within the 'debian-zfs-live/scripts' folder.
#
# Sven Gothel - http://jausoft.com (See LICENSE.txt)

# Assuming the following steps have been prepared - all artifacts are available
# 1) Using own Debian10 Prepared debootstrap: debootstrap01.sh - debootstrap03.sh
# 2) Using own Debian10 Live ISO: deblive01.sh - deblive03-iso.sh
#
# (All scripts should be executed from within the 'debian-zfs-live/scripts' folder)
#
# Boot with the created (1) Debian ZFS Live System
#
# <s00.sh start>
#
MYHOSTNAME=jordan
POOL=jordan
DISK1=ata-WDC_WD2003FYYS-02W0B1_WD-WCAY00187731
DISK2=ata-WDC_WD2003FYYS-02W0B1_WD-WCAY00187732
DISK3=ata-WDC_WD2003FYYS-02W0B1_WD-WCAY00187733
MYSWAPSIZE=33G
STRAPBALL=../debian10-zfs-debootstrap.tar.bz2
#
# <s00.sh end>
#

## Host

sudo -i

#
# <s01.sh start>
#
apt-get update
apt-get clean

#sed -i "s/PasswordAuthentication no/PasswordAuthentication yes/g" /etc/ssh/sshd_config
#service ssh restart

modprobe zfs

# If you are re-using a MDADM disk, clear it as necessary:
# 
# If the disk was previously used in an MD array, zero the superblock:
#apt-get install --yes mdadm
#mdadm --zero-superblock --force /dev/disk/by-id/$DISK1
#mdadm --zero-superblock --force /dev/disk/by-id/$DISK2
#mdadm --zero-superblock --force /dev/disk/by-id/$DISK3

# Clear the partition table:
sgdisk --zap-all /dev/disk/by-id/$DISK1
sgdisk --zap-all /dev/disk/by-id/$DISK2
sgdisk --zap-all /dev/disk/by-id/$DISK3

# 2.2 Partition your disk:
#
# Run this if you need legacy (BIOS) booting:
sgdisk -a1 -n2:34:2047  -t2:EF02 /dev/disk/by-id/$DISK1
sgdisk -a1 -n2:34:2047  -t2:EF02 /dev/disk/by-id/$DISK2
sgdisk -a1 -n2:34:2047  -t2:EF02 /dev/disk/by-id/$DISK3

#Run these in all cases:
sgdisk     -n1:0:0      -t1:BF01 /dev/disk/by-id/$DISK1
sgdisk     -n1:0:0      -t1:BF01 /dev/disk/by-id/$DISK2
sgdisk     -n1:0:0      -t1:BF01 /dev/disk/by-id/$DISK3

# 2.3 Create the root pool
#
zpool create -f -o ashift=12 -o autoexpand=on \
      -O atime=off -O compression=off \
      -O mountpoint=/ -R /mnt \
      $POOL raidz2 \
      /dev/disk/by-id/$DISK1-part1 \
      /dev/disk/by-id/$DISK2-part1 \
      /dev/disk/by-id/$DISK3-part1

zpool autoexpand=on $POOL
zpool autoreplace=off $POOL
zpool listsnapshots=off $POOL

zfs set dedup=off $POOL
zfs set compression=off $POOL
zfs set atime=off $POOL
zfs set mountpoint=none $POOL
zfs set aclinherit=passthrough $POOL
zfs set acltype=posixacl $POOL
zfs set xattr=sa $POOL

# Create Dataset System Root 
zfs create -o mountpoint=none $POOL/system
zfs create -o mountpoint=/ $POOL/system/debian
#zfs mount $POOL/system/debian
zpool set bootfs=$POOL/system/debian $POOL

zfs create -o compression=lz4 $POOL/system/debian/var

# Create Datasets ..
zfs create -o mountpoint=/home $POOL/users
zfs create -o mountpoint=/root $POOL/users/root

zfs create -o mountpoint=/backup -o compression=lz4 $POOL/backup
zfs create -o mountpoint=/data $POOL/data
zfs create -o mountpoint=/srv $POOL/services
zfs create -o mountpoint=/usr/local/projects -o compression=lz4 $POOL/projects

## Export / Import ( '-d ..' also changes the dev names )
##zpool export $POOL
##zpool import -d /dev/disk/by-id -R /mnt $POOL

#3.4 Prepare ROOT

## /mnt already must exist as the just created zfs fs
##mkdir -p /mnt

(cd /mnt && \
 tar --xattrs -xapf $STRAPBALL
)

zfs set devices=off $POOL

#Step 4: System Configuration
#
#4.1 Configure the hostname (change HOSTNAME to the desired hostname).
#
echo $MYHOSTNAME > /mnt/etc/hostname

echo "127.0.1.1       $MYHOSTNAME" >> /mnt/etc/hosts
#or if the system has a real name in DNS:
#echo "127.0.1.1       $MYFQDN $MYHOSTNAME" >> /mnt/etc/hosts

#Using NetworkManager should not require this
# mv /mnt/etc/resolv.conf /mnt/etc/resolv.conf-orig
# cat /etc/resolv.conf > /mnt/etc/resolv.conf
#

#4.3 Bind the virtual filesystems from the LiveCD environment to the new system and chroot into it:
#
cp -a ../../zfs /mnt/root/

mount --rbind /dev  /mnt/dev
mount --rbind /proc /mnt/proc
mount --rbind /sys  /mnt/sys
mount --make-rslave /mnt/dev
mount --make-rslave /mnt/proc
mount --make-rslave /mnt/sys
echo umount -R /mnt/dev
echo umount -R /mnt/proc
echo umount -R /mnt/sys
echo "cat /proc/mounts | awk '{print $2}' | grep "/mnt" | sort -r | xargs umount"

echo RUN chroot /mnt /bin/bash --login

#
# <s01.sh end>
#

CHROOT ENVIRONMENT

#4.0 Without NetworkManager, you may want to adjust /etc/network/interfaces
#
#Find the interface name:
ip addr show

vi /etc/network/interfaces.d/NAME
+++
auto NAME
iface NAME inet dhcp
+++

#4.1 Refine ZFS default (JAU - Required for ZFS 0.7)
# /etc/default/zfs
# ZFS_INITRD_ADDITIONAL_DATASETS before fstab, i.e. ready for bind!
ZFS_INITRD_ADDITIONAL_DATASETS="$POOL/users $POOL/users/root $POOL/backup $POOL/data $POOL/services $POOL/projects"
#VERBOSE_MOUNT='yes'

#4.2 Optional (but highly recommended): Make debugging GRUB easier:
#
vi /etc/default/grub
+++
Remove quiet from: GRUB_CMDLINE_LINUX_DEFAULT
Add 'elevator=noop' to: GRUB_CMDLINE_LINUX_DEFAULT
    GRUB_CMDLINE_LINUX_DEFAULT="elevator=noop"
Uncomment: GRUB_TERMINAL=console
Save and quit.
+++
# (JAU - Required for ZFS 0.7)
++
# /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="elevator=noop"
GRUB_CMDLINE_LINUX="root=ZFS=$POOL/system/debian boot=zfs rpool=$POOL bootfs=$POOL/system/debian"
++
+++

#5.0 Configure a basic system environment:
#

#
# <s02.sh start>
#
apt-get update
apt-get clean

passwd

#5.1 Verify that the ZFS root filesystem is recognized:
#
grub-probe /
++
zfs
++

#Step 5: GRUB Installation
#
#5.2 Refresh the initrd files:
#

update-initramfs -u -k all

#5.4 Update the boot configuration:
#
update-grub

#5.5 Install the boot loader
#
#5.5a For legacy (MBR) booting, install GRUB to the MBR:
#
grub-install /dev/disk/by-id/$DISK1
grub-install /dev/disk/by-id/$DISK2
grub-install /dev/disk/by-id/$DISK3

#5.6 Verify that the ZFS module is installed:
#
ls /boot/grub/*/zfs.mod
#

#Step 6: First Boot
#
#6.1 Snapshot the initial installation:
#
zfs snapshot $POOL/system/debian@install
#
# <s02.sh end>
#

#6.2 Exit from the chroot environment back to the LiveCD environment:
#
exit

HOST ENVIRONMENT

#6.3 Run these commands in the LiveCD environment to unmount all filesystems:
#
# <s03.sh start>
#

#7.2 Configure the swap device:
#7.2a Create an unencrypted (regular) swap device:
#
# Swap ZVOL / machine w/ 32GB Ram, x86_64 4k pagesize `getconf PAGESIZE`
#
zfs create -V $MYSWAPSIZE -b $(getconf PAGESIZE) -o compression=zle \
      -o logbias=throughput -o sync=always \
      -o primarycache=metadata -o secondarycache=none \
      -o com.sun:auto-snapshot=false $POOL/swap

zfs set compression=zle $POOL/swap
zfs set logbias=throughput $POOL/swap
zfs set sync=always $POOL/swap
zfs set primarycache=metadata $POOL/swap
zfs set secondarycache=none $POOL/swap
zfs set com.sun:auto-snapshot=false $POOL/swap
zfs set checksum=off $POOL/swap

mkswap -f /dev/zvol/$POOL/swap
echo /dev/zvol/$POOL/swap none swap defaults 0 0 >> /etc/fstab
# UUID=ee57ce05-7287-4b37-93c4-03aeaba756f1
# /etc/fstab
# /dev/zvol/$POOL/swap   none  		   swap    defaults  0  0
# 
swapon /dev/zvol/$POOL/swap

#umount -R /mnt/dev
#umount -R /mnt/proc
#umount -R /mnt/sys
cat /proc/mounts | awk '{print $2}' | grep "/mnt" | sort -r | xargs umount

zfs unmount -a
zpool export $POOL
#
# <s03.sh end>
#

#6.4 Reboot:
#
reboot

#Step 8: Full Software Installation
#
#8.1 Upgrade the minimal system:
#
apt-get update
apt-get dist-upgrade --yes

# squeeze in some default ACLs for new files and directories
setfacl -d --set u::rwx,g::rwx,o::r-x /data
setfacl -d --set u::rwx,g::r-x,o::r-x /usr/local/projects
setfacl -d --set u::rwx,g::rwx,o::r-x /srv
setfacl -d --set u::rwx,g::r-x,o::--- /backup
setfacl -d --set u::rwx,g::r-x,o::--- /home
setfacl -d --set u::rwx,g::r-x,o::--- /root

#8.2 Optional: Disable log compression:
#
# <s04.sh start>
#
for file in /etc/logrotate.d/* ; do
  if grep -Eq "(^|[^#y])compress" "$file" ; then
    sed -i -r "s/(^|[^#y])(compress)/\1#\2/" "$file"
  fi
done
#
# <s04.sh end>
#

#8.3 Reboot:
reboot