aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Göthel <[email protected]>2024-11-27 08:41:05 +0100
committerSven Göthel <[email protected]>2024-11-27 08:41:05 +0100
commita48504822e9d646c5f2e21b6a11ec17c0be820da (patch)
tree22facebaae0707d659498a12562c1f247fd3f4ea
parentc46f18fa4ba9ad10e511e95710b4c96250520933 (diff)
Update `rescue` and `setup` folder
`setup` folder contains more examples/actions for setup and re-pool'ing as well as utilizing uefi.
-rw-r--r--rescue/chroot_zfs.sh1
-rw-r--r--setup/change_compression.sh17
-rw-r--r--setup/convert-mbr_to_uefi.txt29
-rw-r--r--setup/copy_to_new_pool.sh30
-rw-r--r--setup/export_import.sh7
-rw-r--r--setup/new_blank_zpool.sh64
-rw-r--r--setup/new_full_zpool.sh107
-rw-r--r--setup/new_gpt_efi_disk.sh37
-rw-r--r--setup/new_gpt_mpr_disk.sh (renamed from setup/new_disk.sh)11
-rw-r--r--setup/set_mountpoint.sh10
-rw-r--r--setup/zfs-zap-disk.txt27
11 files changed, 336 insertions, 4 deletions
diff --git a/rescue/chroot_zfs.sh b/rescue/chroot_zfs.sh
index cd700a7..6c2d662 100644
--- a/rescue/chroot_zfs.sh
+++ b/rescue/chroot_zfs.sh
@@ -21,6 +21,7 @@ mount --bind /proc/ /mnt/proc/
# Potentially you might need to
#
+# - fix/edit /etc/default/zfs
# - update-initramfs -u -k all
# - update-grub
# - grub-install /dev/disk/by-id/your_boot_root_device
diff --git a/setup/change_compression.sh b/setup/change_compression.sh
new file mode 100644
index 0000000..b26252a
--- /dev/null
+++ b/setup/change_compression.sh
@@ -0,0 +1,17 @@
+export POOL=tpool2
+export SNAPNAME=transfer
+
+export DSSRC=system/debian/var
+export DSDST=system/debian/var2
+
+export ZFS_COMPRESSION_METHOD=lz4
+#export ZFS_COMPRESSION_METHOD=zstd
+
+zfs create -o compression=${ZFS_COMPRESSION_METHOD} $POOL/$DSDST
+
+zfs snapshot $POOL/$DSSRC@$SNAPNAME
+#zfs send $POOL/$DSSRC@$SNAPNAME | zfs receive -Fduv -o compression=${ZFS_COMPRESSION_METHOD} $POOL/$DSDST
+zfs send $POOL/$DSSRC@$SNAPNAME | zfs receive -Fuv -o compression=${ZFS_COMPRESSION_METHOD} $POOL/$DSDST
+
+zfs destroy $POOL/$DSSRC@$SNAPNAME
+zfs destroy $POOL/$DSDST@$SNAPNAME
diff --git a/setup/convert-mbr_to_uefi.txt b/setup/convert-mbr_to_uefi.txt
new file mode 100644
index 0000000..d4e8c3f
--- /dev/null
+++ b/setup/convert-mbr_to_uefi.txt
@@ -0,0 +1,29 @@
+Setup /boot/efi vfat mount
+ 505 mkdir /boot/efi
+ 509 mount /dev/disk/by-id/ata-QEMU_HARDDISK_QM00007-part2 /boot/efi
+ 512 blkid /dev/disk/by-id/ata-QEMU_HARDDISK_QM00007-part2
+ 511 vi /etc/fstab
+ # was /dev/disk/by-id/ata-QEMU_HARDDISK_QM00007-part2
+ UUID=9F32-F032 /boot/efi vfat umask=0077 0 1
+ 518 systemctl daemon-reload
+ 514 umount /boot/efi
+ 515 mount /boot/efi
+
+Install grub efi
+ 522 sudo apt install grub-efi-amd64 -y
+ 525 dpkg -P grub-pc grub-pc-bin
+ 533 rm -rf /boot/grub/i386-pc
+ check
+ - existing /etc/default/grub
+ - only /boot/efi/EFI/debian/ should exist
+ - rm -rf /boot/efi/EFI/GRUB (???)
+ - may need: `sudo apt reinstall grub-efi-amd64 -y`
+
+ - Misc
+ - Not needed: `grub-install --target=x86_64-efi --bootloader-id=debian --efi-directory=/boot/efi`
+ - But could `sudo apt install --reinstall grub-efi-amd64`
+ 536 update-grub
+ 537 ls -la /boot/grub/
+
+BIOS
+ - Disable Secure-Boot
diff --git a/setup/copy_to_new_pool.sh b/setup/copy_to_new_pool.sh
new file mode 100644
index 0000000..6e2f45a
--- /dev/null
+++ b/setup/copy_to_new_pool.sh
@@ -0,0 +1,30 @@
+export ROOTFS_DIR="/mnt"
+export POOL1=tpool
+export POOL2=tpool2
+export SNAPNAME=transfer
+
+zfs snapshot -r $POOL1@$SNAPNAME
+zfs send -R $POOL1@$SNAPNAME | zfs receive -Fduv $POOL2
+
+zfs destroy -r $POOL1@$SNAPNAME
+zfs destroy -r $POOL2@$SNAPNAME
+
+# now re-import on $ROOTFS_DIR w/ mounting
+zpool export $POOL2
+zpool import -R $ROOTFS_DIR $POOL
+
+# Maintenance
+echo
+echo "$POOL2 mountpoints"
+zfs get -r mountpoint $POOL2
+
+echo
+echo "$POOL2 compression"
+zfs get -r compression $POOL2
+
+echo
+echo "$POOL2 snapshots"
+zfs list -r -t snapshot $POOL2
+
+# follow
+# - ../rescue/chroot_zfs.sh to update grub on new pool
diff --git a/setup/export_import.sh b/setup/export_import.sh
new file mode 100644
index 0000000..8185228
--- /dev/null
+++ b/setup/export_import.sh
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+export POOL=tpool2
+export ROOTFS_DIR="/mnt"
+
+zpool export $POOL
+zpool import -R $ROOTFS_DIR -N $POOL
diff --git a/setup/new_blank_zpool.sh b/setup/new_blank_zpool.sh
new file mode 100644
index 0000000..e766243
--- /dev/null
+++ b/setup/new_blank_zpool.sh
@@ -0,0 +1,64 @@
+#!/bin/bash
+
+DISK1=ata-QEMU_HARDDISK_QM00007
+DISK2=ata-QEMU_HARDDISK_QM00009
+DISK3=ata-QEMU_HARDDISK_QM00011
+
+export ROOTFS_DIR="/mnt"
+
+export POOL=tpool2
+export ZFS_COMPRESSION_METHOD=lz4
+# export ZFS_COMPRESSION_METHOD=zstd
+
+#
+# Manually enabled ZFS features for GRUB compatibility!
+# See https://wiki.archlinux.org/title/ZFS#GRUB-compatible_pool_creation
+# Tested w/ Grub 2.04-19
+#
+zpool create -f -o ashift=12 -o autoexpand=on \
+ -O atime=off -O compression=off \
+ -O mountpoint=/ -R ${ROOTFS_DIR} \
+ -d \
+ -o compatibility=grub2_readonly \
+ -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@allocation_classes=enabled \
+ -o feature@device_rebuild=enabled \
+ -o feature@livelist=enabled \
+ -o feature@log_spacemap=enabled \
+ -o feature@obsolete_counts=enabled \
+ -o feature@project_quota=enabled \
+ -o feature@resilver_defer=enabled \
+ -o feature@spacemap_v2=enabled \
+ -o feature@userobj_accounting=enabled \
+ -o feature@zpool_checkpoint=enabled \
+ \
+ $POOL raidz1 \
+ /dev/disk/by-id/$DISK1-part3 \
+ /dev/disk/by-id/$DISK2-part3 \
+ /dev/disk/by-id/$DISK3-part3
+
+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
+
+# zpool export $POOL
+# zpool import -R $ROOTFS_DIR -N $POOL
+
diff --git a/setup/new_full_zpool.sh b/setup/new_full_zpool.sh
new file mode 100644
index 0000000..8f2c87a
--- /dev/null
+++ b/setup/new_full_zpool.sh
@@ -0,0 +1,107 @@
+#!/bin/bash
+
+DISK1=ata-QEMU_HARDDISK_QM00007
+DISK2=ata-QEMU_HARDDISK_QM00009
+DISK3=ata-QEMU_HARDDISK_QM00011
+
+export ROOTFS_DIR="/mnt"
+# export MYSWAPSIZE=64G
+# export MYSWAPSIZE=1G
+
+export POOL=tpool2
+export ZFS_COMPRESSION_METHOD=lz4
+# export ZFS_COMPRESSION_METHOD=zstd
+
+#
+# Manually enabled ZFS features for GRUB compatibility!
+# See https://wiki.archlinux.org/title/ZFS#GRUB-compatible_pool_creation
+# Tested w/ Grub 2.04-19
+#
+zpool create -f -o ashift=12 -o autoexpand=on \
+ -O atime=off -O compression=off \
+ -O mountpoint=/ -R ${ROOTFS_DIR} \
+ -d \
+ -o compatibility=grub2_readonly \
+ -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@allocation_classes=enabled \
+ -o feature@device_rebuild=enabled \
+ -o feature@livelist=enabled \
+ -o feature@log_spacemap=enabled \
+ -o feature@obsolete_counts=enabled \
+ -o feature@project_quota=enabled \
+ -o feature@resilver_defer=enabled \
+ -o feature@spacemap_v2=enabled \
+ -o feature@userobj_accounting=enabled \
+ -o feature@zpool_checkpoint=enabled \
+ \
+ $POOL raidz1 \
+ /dev/disk/by-id/$DISK1-part3 \
+ /dev/disk/by-id/$DISK2-part3 \
+ /dev/disk/by-id/$DISK3-part3
+
+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=${ZFS_COMPRESSION_METHOD} $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=${ZFS_COMPRESSION_METHOD} $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=${ZFS_COMPRESSION_METHOD} $POOL/projects
+
+if [ ! -z "$MYSWAPSIZE" ]; then
+ # SWAP
+ 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
+ #
+ echo "Swap: /etc/fstab modified"
+ echo "Swap: Enable: swapon /dev/zvol/$POOL/swap"
+fi
+
diff --git a/setup/new_gpt_efi_disk.sh b/setup/new_gpt_efi_disk.sh
new file mode 100644
index 0000000..c9a5b75
--- /dev/null
+++ b/setup/new_gpt_efi_disk.sh
@@ -0,0 +1,37 @@
+
+NDISK1=ata-QEMU_HARDDISK_QM00007
+NDISK2=ata-QEMU_HARDDISK_QM00009
+NDISK3=ata-QEMU_HARDDISK_QM00011
+
+# Clear the partition table:
+sgdisk --zap-all /dev/disk/by-id/$NDISK1
+sgdisk --zap-all /dev/disk/by-id/$NDISK2
+sgdisk --zap-all /dev/disk/by-id/$NDISK3
+
+# 2.2 Partition your disk:
+#
+# Legacy (BIOS) booting (part-1): Used for GRUB boot-code in 'MBR-gap':
+sgdisk -a1 -n1:40:8191 -t1:EF02 /dev/disk/by-id/$NDISK1
+sgdisk -a1 -n1:40:8191 -t1:EF02 /dev/disk/by-id/$NDISK2
+sgdisk -a1 -n1:40:8191 -t1:EF02 /dev/disk/by-id/$NDISK3
+
+# Run this if you need legacy (EFI) booting:
+sgdisk -n2:0:+1G -t2:EF00 /dev/disk/by-id/$NDISK1
+sgdisk -n2:0:+1G -t2:EF00 /dev/disk/by-id/$NDISK2
+sgdisk -n2:0:+1G -t2:EF00 /dev/disk/by-id/$NDISK3
+
+#Run these in all cases:
+sgdisk -n3:0:0 -t3:BF01 /dev/disk/by-id/$NDISK1
+sgdisk -n3:0:0 -t3:BF01 /dev/disk/by-id/$NDISK2
+sgdisk -n3:0:0 -t3:BF01 /dev/disk/by-id/$NDISK3
+
+sleep 3
+sync
+
+# Create EFI filesystems
+mkfs.fat -F32 /dev/disk/by-id/$NDISK1-part2
+mkfs.fat -F32 /dev/disk/by-id/$NDISK2-part2
+mkfs.fat -F32 /dev/disk/by-id/$NDISK3-part2
+
+echo "Now replace the disk .."
+echo "zpool replace risa 12458555210078177352 /dev/disk/by-id/ata-WDC_WD40EFZX-68AWUN0_WD-WX92DA0798JN-part1"
diff --git a/setup/new_disk.sh b/setup/new_gpt_mpr_disk.sh
index 820fc6c..4335a25 100644
--- a/setup/new_disk.sh
+++ b/setup/new_gpt_mpr_disk.sh
@@ -10,15 +10,18 @@ sgdisk --zap-all /dev/disk/by-id/$NDISK1
# 2.2 Partition your disk:
#
-# Run this if you need legacy (BIOS) booting:
-sgdisk -a1 -n1:40:2047 -t1:EF02 /dev/disk/by-id/$NDISK1
-#sgdisk -a1 -n1:40:2047 -t1:EF02 /dev/disk/by-id/$NDISK2
-#sgdisk -a1 -n1:40:2047 -t1:EF02 /dev/disk/by-id/$NDISK3
+# Legacy (BIOS) booting (part-1): Used for GRUB boot-code in 'MBR-gap':
+sgdisk -a1 -n1:40:8191 -t1:EF02 /dev/disk/by-id/$NDISK1
+#sgdisk -a1 -n1:40:8191 -t1:EF02 /dev/disk/by-id/$NDISK2
+#sgdisk -a1 -n1:40:8191 -t1:EF02 /dev/disk/by-id/$NDISK3
#Run these in all cases:
sgdisk -n2:0:0 -t2:BF01 /dev/disk/by-id/$NDISK1
#sgdisk -n2:0:0 -t2:BF01 /dev/disk/by-id/$NDISK2
#sgdisk -n2:0:0 -t2:BF01 /dev/disk/by-id/$NDISK3
+sleep 3
+sync
+
echo "Now replace the disk .."
echo "zpool replace risa 12458555210078177352 /dev/disk/by-id/ata-WDC_WD40EFZX-68AWUN0_WD-WX92DA0798JN-part1"
diff --git a/setup/set_mountpoint.sh b/setup/set_mountpoint.sh
new file mode 100644
index 0000000..5413034
--- /dev/null
+++ b/setup/set_mountpoint.sh
@@ -0,0 +1,10 @@
+export POOL=tpool2
+
+zfs set -u mountpoint=/backup $POOL/backup
+zfs set -u mountpoint=/data $POOL/data
+zfs set -u mountpoint=/usr/local/projects $POOL/projects
+zfs set -u mountpoint=/srv $POOL/services
+zfs set -u mountpoint=/ $POOL/system/debian
+zfs set -u mountpoint=/home $POOL/users
+zfs set -u mountpoint=/root $POOL/users/root
+
diff --git a/setup/zfs-zap-disk.txt b/setup/zfs-zap-disk.txt
new file mode 100644
index 0000000..72185e8
--- /dev/null
+++ b/setup/zfs-zap-disk.txt
@@ -0,0 +1,27 @@
+#! /bin/sh
+
+strace -e pread64 zdb -l /dev/sdl >/dev/null
+pread64(5, "\0\1\0\0\0\0\0\0\1\0\0\0000\0\0\0\7\0\0\0\1\0\0\0\23\0\0\0doze"..., 13920, 0) = 13920
+pread64(5, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 262144, 0) = 262144
+pread64(5, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 262144, 262144) = 262144
+pread64(5, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 262144, 16000900136960) = 262144
+pread64(5, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 262144, 16000900399104) = 262144
++++ exited with 2 +++
+[root@fs01 etc]# for f in 0 262144 16000900136960 16000900399104; do dd if=/dev/zero of=/dev/sdl bs=1 seek=$f count=262144; done
+[root@fs01 etc]# for f in 0 262144 4000785367040 4000785629184; do dd if=/dev/zero of=/dev/disk/by-id/ata-WDC_WD40EFZX-68AWUN0_WD-WX92DA0798JN-part2 bs=1 seek=$f count=262144; done
+262144+0 records in
+262144+0 records out
+262144 bytes (262 kB, 256 KiB) copied, 0.507745 s, 516 kB/s
+262144+0 records in
+262144+0 records out
+262144 bytes (262 kB, 256 KiB) copied, 0.508549 s, 515 kB/s
+262144+0 records in
+262144+0 records out
+262144 bytes (262 kB, 256 KiB) copied, 0.499234 s, 525 kB/s
+262144+0 records in
+262144+0 records out
+262144 bytes (262 kB, 256 KiB) copied, 0.496669 s, 528 kB/s
+
+[root@fs01 etc]# partprobe /dev/sdl
+### LSBLK shows sdl has no partitions, so far so good
+