-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformat.sh
146 lines (116 loc) · 4.9 KB
/
format.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env bash
set -euo pipefail
declare -r DEST_DISK_ID="ata-ST1000LM024_HN-M101MBB_S314JB0FA42608"
declare -r DEST_DISK_PATH="/dev/disk/by-id/${DEST_DISK_ID}"
declare -r PACKAGELIST="sudo,popularity-contest"
declare -r DEST_CHROOT_DIR="/mnt/tmp"
mkdir -p "${DEST_CHROOT_DIR}"
zpool export bpool || true
zpool export rpool || true
zpool labelclear -f ${DEST_DISK_PATH}-part3 || true
zpool labelclear -f ${DEST_DISK_PATH}-part4 || true
# clear partition table
sgdisk --zap-all "${DEST_DISK_PATH}"
# BIOS
sgdisk -n1:2048:+1000K -t1:EF02 "${DEST_DISK_PATH}"
# or UEFI
#sgdisk -n2:1M:+512M -t2:EF00 "${DEST_DISK_PATH}"
# boot-pool
sgdisk -n3:0:+1G -t3:BF01 "${DEST_DISK_PATH}"
# root-pool
sgdisk -n4:0:0 -t4:BF01 "${DEST_DISK_PATH}"
partprobe
sleep 5
# create boot-pool
zpool create -o ashift=12 -d \
-o feature@async_destroy=enabled \
-o feature@bookmarks=enabled \
-o feature@embedded_data=enabled \
-o feature@empty_bpobj=enabled \
-o feature@enabled_txg=enabled \
-o feature@extensible_dataset=enabled \
-o feature@filesystem_limits=enabled \
-o feature@hole_birth=enabled \
-o feature@large_blocks=enabled \
-o feature@lz4_compress=enabled \
-o feature@spacemap_histogram=enabled \
-o feature@userobj_accounting=enabled \
-O acltype=posixacl -O canmount=off -O compression=lz4 -O devices=off \
-O normalization=formD -O relatime=on -O xattr=sa \
-O mountpoint=/ -R "${DEST_CHROOT_DIR}" \
bpool "${DEST_DISK_PATH}-part3"
# create root-pool
zpool create -o ashift=12 \
-o feature@log_spacemap=disabled \
-O acltype=posixacl -O canmount=off -O compression=lz4 \
-O dnodesize=auto -O normalization=formD -O relatime=on -O xattr=sa \
-O mountpoint=/ -R "${DEST_CHROOT_DIR}" \
rpool "${DEST_DISK_PATH}-part4"
# create containers
zfs create -o canmount=off -o mountpoint=none rpool/ROOT
zfs create -o canmount=off -o mountpoint=none bpool/BOOT
# create datasets
zfs create -o canmount=noauto -o mountpoint=/ rpool/ROOT/debian
zfs mount rpool/ROOT/debian
zfs create -o canmount=noauto -o mountpoint=/boot bpool/BOOT/debian
zfs mount bpool/BOOT/debian
zfs create rpool/home
# zfs create -o mountpoint=/root rpool/home/root
zfs create -o canmount=off rpool/var
# zfs create -o canmount=off rpool/var/lib
zfs create rpool/var/log
zfs create rpool/var/spool
#The datasets below are optional, depending on your preferences and/or software choices:
# If you wish to exclude these from snapshots:
zfs create -o com.sun:auto-snapshot=false rpool/var/cache
zfs create -o com.sun:auto-snapshot=false rpool/var/tmp
chmod 1777 "${DEST_CHROOT_DIR}"/var/tmp
# If you use /opt on this system:
#zfs create rpool/opt
# If you use /srv on this system:
#zfs create rpool/srv
# If you use /usr/local on this system:
#zfs create -o canmount=off rpool/usr
#zfs create rpool/usr/local
# If this system will store local email in /var/mail:
#zfs create rpool/var/mail
# If you use /var/www on this system:
#zfs create rpool/var/www
zfs create -o canmount=off rpool/var/lib
# If this system will use Docker (which manages its own datasets & snapshots):
zfs create -o com.sun:auto-snapshot=false rpool/var/lib/docker
# A tmpfs is recommended later, but if you want a separate dataset for /tmp:
#zfs create -o com.sun:auto-snapshot=false rpool/tmp
#chmod 1777 "${DEST_CHROOT_DIR}"/tmp
# finally debootstrap
debootstrap --cache-dir=/var/cache/debootstrap --components=main,contrib,non-free --variant=buildd --include=${PACKAGELIST} sid "${DEST_CHROOT_DIR}" https://deb.debian.org/debian/
# ?
zfs set devices=off rpool
# mount stuff into chroot
# not needed for systemd-nspawn
rsync -rlv seed-root/ "${DEST_CHROOT_DIR}/"
sed -i "s,__DEST_DISK_ID__,${DEST_DISK_ID},g" "${DEST_CHROOT_DIR}/var/tmp/systemd-nspawnscript.sh"
sed -i "s,__DEST_DISK_ID__,${DEST_DISK_ID},g" "${DEST_CHROOT_DIR}/var/tmp/chroot-script.sh"
systemd-nspawn -D "${DEST_CHROOT_DIR}" /bin/bash -x /var/tmp/systemd-nspawnscript.sh
if command -v arch-chroot; then
arch-chroot ${DEST_CHROOT_DIR} bash -x /var/tmp/chroot-script.sh
else
for _dir in dev proc sys; do
mount --rbind /${_dir} "${DEST_CHROOT_DIR}"/${_dir}
mount --make-rslave "${DEST_CHROOT_DIR}"/${_dir}
done
chroot ${DEST_CHROOT_DIR} bash -x /var/tmp/chroot-script.sh
for _dir in dev proc sys; do
umount "${DEST_CHROOT_DIR}"/${_dir}
done
fi
read -r -p "Switch to installed system (systemd-nspawn)?" _nspawn_switch
if [[ "$_nspawn_switch" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
systemd-nspawn -D "${DEST_CHROOT_DIR}" PATH=/usr/sbin:$PATH /bin/bash --login
fi
read -r -p "cleanup (umount __ALL ZFS MOUNTS__, zfs export etc.)?" _cleanup
if [[ "$_cleanup" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
zfs umount -a
zpool export bpool
zpool export rpool
fi