forked from NLaundry/zfsbootmenu-autoinstaller
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup-zfsbootmenu.yml
More file actions
402 lines (333 loc) · 10.5 KB
/
Copy pathsetup-zfsbootmenu.yml
File metadata and controls
402 lines (333 loc) · 10.5 KB
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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
- hosts: localhost
become: true
become_method: sudo
gather_facts: false
vars_prompt:
- name: "ansible_become_password"
prompt: "Enter sudo password for chroot tasks"
private: yes
- name: "username"
prompt: "Enter the username for the new user"
private: no # Set to `yes` to hide input
- name: "user_password"
prompt: "Enter the password for the new user"
private: yes
- name: "root_password"
prompt: "Enter the root password"
private: yes
- name: "hostname"
prompt: "Enter the hostname for this system"
private: no
vars:
# ID: "{{ lookup('ini', 'ID section=None file=/etc/os-release') }}"
ID: "debian"
BOOT_DISK: '/dev/nvme0n1' # Adjust as needed
BOOT_PART: '1'
BOOT_DEVICE: "{{ BOOT_DISK }}p{{ BOOT_PART }}"
POOL_DISK: '/dev/nvme0n1' # Adjust as needed
POOL_PART: '2'
POOL_DEVICE: "{{ POOL_DISK }}p{{ POOL_PART }}"
KERNEL_VERSION: '6.1.0-25-amd64'
tasks:
- name: Configure apt sources
copy:
dest: /etc/apt/sources.list
content: |
deb http://deb.debian.org/debian bookworm main contrib non-free-firmware
deb-src http://deb.debian.org/debian bookworm main contrib non-free-firmware
deb http://deb.debian.org/debian-security bookworm-security main contrib non-free-firmware
deb-src http://deb.debian.org/debian-security/ bookworm-security main contrib non-free-firmware
deb http://deb.debian.org/debian bookworm-updates main contrib non-free-firmware
deb-src http://deb.debian.org/debian bookworm-updates main contrib non-free-firmware
deb http://deb.debian.org/debian bookworm-backports main contrib non-free-firmware
deb-src http://deb.debian.org/debian bookworm-backports main contrib non-free-firmware
- name: Update apt cache
apt:
update_cache: yes
# - name: Get kernel version
# command: uname -r
# register: kernel_version
#
# - name: Debug kernel version
# debug:
# var: kernel_version
- name: Install necessary packages
apt:
name:
- debootstrap
- gdisk
- dkms
- "linux-headers-{{ KERNEL_VERSION }}"
- zfsutils-linux
state: present
- name: Generate hostid
command: zgenhostid -f 0x00bab10c
- name: Wipe zpool labels from POOL_DISK
command: zpool labelclear -f "{{ POOL_DISK }}"
ignore_errors: yes
- name: Wipe filesystem signatures from disks
command: wipefs -a "{{ item }}"
loop:
- "{{ POOL_DISK }}"
- "{{ BOOT_DISK }}"
- name: Zap all partitions on disks
command: sgdisk --zap-all "{{ item }}"
loop:
- "{{ POOL_DISK }}"
- "{{ BOOT_DISK }}"
- name: Create EFI boot partition
command: sgdisk -n "{{ BOOT_PART }}:1M:+512M" -t "{{ BOOT_PART }}:ef00" "{{ BOOT_DISK }}"
- name: Create zpool partition
command: sgdisk -n "{{ POOL_PART }}:0:-10M" -t "{{ POOL_PART }}:bf00" "{{ POOL_DISK }}"
- name: Create zpool
command: >
zpool create -f -o ashift=12
-O compression=lz4
-O acltype=posixacl
-O xattr=sa
-O relatime=on
-o autotrim=on
-o compatibility=openzfs-2.1-linux
-m none zroot "{{ POOL_DEVICE }}"
- name: Create ZFS datasets
command: zfs create -o mountpoint=none zroot/ROOT
- name: Create root dataset
command: zfs create -o mountpoint=/ -o canmount=noauto zroot/ROOT/{{ ID }}
- name: Create home dataset
command: zfs create -o mountpoint=/home zroot/home
- name: Set bootfs property
command: zpool set bootfs=zroot/ROOT/{{ ID }} zroot
- name: Export zpool
command: zpool export zroot
- name: Import zpool
command: zpool import -N -R /mnt zroot
- name: Mount root dataset
command: zfs mount zroot/ROOT/{{ ID }}
- name: Mount home dataset
command: zfs mount zroot/home
- name: Trigger udevadm
command: udevadm trigger
- name: Install minimal Debian system
command: debootstrap bookworm /mnt
- name: Copy /etc/hostid
copy:
src: /etc/hostid
dest: /mnt/etc/hostid
owner: root
group: root
mode: '0644'
- name: Copy /etc/resolv.conf
copy:
src: /etc/resolv.conf
dest: /mnt/etc/resolv.conf
owner: root
group: root
mode: '0644'
- name: Mount /proc
mount:
path: /mnt/proc
src: proc
fstype: proc
state: mounted
- name: Mount /sys
mount:
path: /mnt/sys
src: sys
fstype: sysfs
state: mounted
- name: Mount /dev
mount:
path: /mnt/dev
src: /dev
fstype: bind
opts: bind
state: mounted
- name: Mount /dev/pts
mount:
path: /mnt/dev/pts
src: /dev/pts
fstype: bind
opts: bind
state: mounted
- name: Ensure /mnt directory exists
file:
path: /mnt
state: directory
mode: '0755'
- hosts: chroot
become: true
become_method: sudo
gather_facts: false
tasks:
- name: Set hostname
hostname:
name: "{{ hostname }}"
- name: Set /etc/hosts entry
lineinfile:
path: /etc/hosts
line: '127.0.1.1\t{{ hostname }}'
create: yes
- name: Set root password
user:
name: root
password: "{{ root_password | password_hash('sha512') }}"
- name: Configure apt sources
copy:
dest: /etc/apt/sources.list
content: |
deb http://deb.debian.org/debian bookworm main contrib non-free-firmware
deb-src http://deb.debian.org/debian bookworm main contrib non-free-firmware
deb http://deb.debian.org/debian-security bookworm-security main contrib non-free-firmware
deb-src http://deb.debian.org/debian-security/ bookworm-security main contrib non-free-firmware
deb http://deb.debian.org/debian bookworm-updates main contrib non-free-firmware
deb-src http://deb.debian.org/debian bookworm-updates main contrib non-free-firmware
deb http://deb.debian.org/debian bookworm-backports main contrib non-free-firmware
deb-src http://deb.debian.org/debian bookworm-backports main contrib non-free-firmware
- name: Update apt cache
apt:
update_cache: yes
- name: Install base packages
apt:
name:
- locales
- keyboard-configuration
- console-setup
state: present
- name: Reconfigure locales
command: dpkg-reconfigure locales
args:
stdin: 'en_US.UTF-8 UTF-8'
- name: Reconfigure tzdata
command: dpkg-reconfigure tzdata
- name: Reconfigure keyboard-configuration
command: dpkg-reconfigure keyboard-configuration
- name: Reconfigure console-setup
command: dpkg-reconfigure console-setup
- name: Install ZFS packages
apt:
name:
- linux-headers-amd64
- linux-image-amd64
- zfs-initramfs
- dosfstools
state: present
- name: Set DKMS config
lineinfile:
path: /etc/dkms/zfs.conf
line: 'REMAKE_INITRD=yes'
create: yes
- name: Enable ZFS services
systemd:
name: "{{ item }}"
enabled: yes
loop:
- zfs.target
- zfs-import-cache
- zfs-mount
- zfs-import.target
- name: Update initramfs
command: update-initramfs -c -k all
- name: Set ZFSBootMenu commandline
command: zfs set org.zfsbootmenu:commandline="quiet" zroot/ROOT
- name: Create EFI filesystem
filesystem:
fstype: vfat
dev: "{{ BOOT_DEVICE }}"
force: yes
- name: Ensure /boot/efi in fstab
blockinfile:
path: /etc/fstab
block: |
UUID={{ lookup('pipe', "blkid -s UUID -o value {{ BOOT_DEVICE }}") }} /boot/efi vfat defaults 0 0
- name: Create /boot/efi directory
file:
path: /boot/efi
state: directory
- name: Mount /boot/efi
mount:
path: /boot/efi
src: "{{ BOOT_DEVICE }}"
fstype: vfat
state: mounted
- name: Install curl
apt:
name: curl
state: present
- name: Install ZFSBootMenu
get_url:
url: https://get.zfsbootmenu.org/efi
dest: /boot/efi/EFI/ZBM/VMLINUZ.EFI
mode: '0755'
- name: Copy VMLINUZ.EFI to backup
copy:
src: /boot/efi/EFI/ZBM/VMLINUZ.EFI
dest: /boot/efi/EFI/ZBM/VMLINUZ-BACKUP.EFI
mode: '0755'
- name: Copy VMLINUZ.EFI to default boot path
copy:
src: /boot/efi/EFI/ZBM/VMLINUZ.EFI
dest: /boot/efi/EFI/BOOT/bootx64.efi
mode: '0755'
- name: Mount efivarfs
mount:
path: /sys/firmware/efi/efivars
src: efivarfs
fstype: efivarfs
state: mounted
- name: Install efibootmgr
apt:
name: efibootmgr
state: present
- name: Add EFI boot entry for ZFSBootMenu (Backup)
command: efibootmgr -c -d "{{ BOOT_DISK }}" -p "{{ BOOT_PART }}" -L "ZFSBootMenu (Backup)" -l '\\EFI\\ZBM\\VMLINUZ-BACKUP.EFI'
- name: Add EFI boot entry for ZFSBootMenu
command: efibootmgr -c -d "{{ BOOT_DISK }}" -p "{{ BOOT_PART }}" -L "ZFSBootMenu" -l '\\EFI\\ZBM\\VMLINUZ.EFI'
- name: Add EFI boot entry for default path
command: efibootmgr -c -d "{{ BOOT_DISK }}" -p "{{ BOOT_PART }}" -L "ZFSBootMenu" -l '\\EFI\\BOOT\\bootx64.efi'
- name: Install system utilities
apt:
name:
- systemd-timesyncd
- net-tools
- iproute2
- isc-dhcp-client
- iputils-ping
- traceroute
- curl
- wget
- dnsutils
- ethtool
- ifupdown
- tcpdump
- nmap
- nano
- vim
- htop
- openssh-server
- git
- tmux
state: present
- name: Run dist-upgrade
apt:
upgrade: dist
update_cache: yes
- name: Create user
user:
name: "{{ username }}"
groups: "audio,cdrom,dip,floppy,netdev,plugdev,sudo,video"
shell: /bin/bash
create_home: yes
password: "{{ user_password | password_hash('sha512') }}"
- hosts: localhost
become: true
gather_facts: false
tasks:
- name: Unmount filesystems
command: umount -lf {{ item }}
loop:
- /mnt/dev/pts
- /mnt/dev
- /mnt/sys
- /mnt/proc
- name: Export zpool
command: zpool export -a