26 Commits
Author SHA1 Message Date
Kierán Meinhardt 669ca49ae4 disk-deactivate: wipe raid arrays before stopping them
Previously, the `disk-deactivate` script stopped mdadm arrays before
wiping the underlying physical disks. This caused filesystems with
backup superblocks (like BTRFS at 64 MiB and 256 GiB offsets) to
survive the wipe, as the backups were striped across the physical
disks and missed by `wipefs` on the raw block devices.

When the array was reassembled during reprovisioning, the filesystem
superblocks realigned. `disko` would detect the old filesystem via
`blkid` and silently skip the `mkfs` step, leaving stale data intact.

This commit adds a `wipefs --all` command against the assembled RAID
device *before* stopping it, ensuring all filesystem signatures and
backup superblocks are cleanly destroyed.
2026-04-08 09:40:37 +02:00
Jörg ThalheimandJörg Thalheim a8e75da08f disko-deactivate: fix jq syntax 2025-04-08 18:03:50 +00:00
Jörg ThalheimandJörg Thalheim 8f806681d7 tree-wise: quote path correctlys 2025-04-08 15:36:04 +00:00
Jörg ThalheimandJörg Thalheim b36e87600d zfs: properly disable zfs-based swap 2025-04-01 15:42:50 +00:00
Jörg Thalheim eea057603d fix syntax of disk-deactivate.jq 2025-03-12 13:19:46 +01:00
Jörg ThalheimandJörg Thalheim 6c1b834456 also deactivate swap partitions 2025-03-11 09:06:40 +00:00
Jörg Thalheim 736c8150b9 disk-deactivate: also clear zpool labels
this helps to avoid ghost pools.
2024-09-03 17:10:47 +02:00
Jörg Thalheim c789d113c6 disk-deactivate: only run zfs command if they are present 2024-09-03 17:10:47 +02:00
Immaeandmergify[bot] a816daa384 Allow more ways to detect disk to deactivate 2024-04-25 11:17:07 +00:00
Jared Baurandmergify[bot] 0a17298c0d Add missing dependency gnused
gnused is used in the disk-deactivate.jq script, but was not defined in
the list of dependencies.
2024-04-05 22:34:38 +00:00
lassulus f6b72bfed7 types *: make create idempotent 2024-03-13 09:58:33 +01:00
Jason Yundtandmergify[bot] 810eccbad2 Allow Disko to be run in a systemd service
Before this change, if you created a systemd service that ran
“disko --mode disko <path-to-config>”, then you would (probably) get
this error:

    disk-deactivate: line 6: /dev/stderr: No such device or address

Since disk-deactivate uses “set -e”, that error would prevent
disk-deactivate from actually deactivating any disks. The problem is
that disk-deactivate tries to print text to stderr by doing this:

    echo "Text" >/dev/stderr

systemd.exec(5) explains why that doesn’t work and goes on to say [1]:

> This means when executing shell scripts the construct
> **echo "hello" > /dev/stderr** for writing text to stderr will not
> work. To mitigate this use the construct **echo "hello" >&2** instead,
> which is mostly equivalent and avoids this pitfall.

[1]: <https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html#StandardOutput=>

---

You can test this commit by doing the following:

1. Download a copy of this gist:
   <https://gist.github.com/Jayman2000/60b483659e89283716582ac38856dca6>

2.  Build a custom NixOS installation ISO that contains a systemd service
    that runs disko:

        nix-build --arg diskoDir <path-to-disko-repo> <path-to-gist>

    Once that command finishes, the ISO will be in ./result/iso/.

3. Create a VM. Make sure that it has a VirtIO disk that’s more than
   500M large. Also make sure that it has an optical disc drive.

4. Put the ISO file from step 2 into the VM’s optical disc drive.

5. Turn on the VM and boot into the installation ISO.

6. Start the systemd service:

    sudo systemctl start disko-test

7. Check journalctl to see if there are any errors related to
   disk-deactivate.
2024-02-15 20:31:41 +00:00
danjujanandGitHub f7424625dc Rework Hybrid MBR https://github.com/nix-community/disko/pull/168 (#508)
Add hybrid MBR functionality to the gpt type
2024-01-26 21:59:23 +01:00
phaerandmergify[bot] be305848c6 umount md device before stopping the raid 2024-01-11 10:37:12 +00:00
12d0c39ed3 Don't print an error if there's no raid
Co-authored-by: Jörg Thalheim <Mic92@users.noreply.github.com>
2024-01-11 10:37:12 +00:00
phaerandmergify[bot] acd2cbdb31 deactivate: stop raid if disk is a member of it
this is useful in cases where the target machine has
a pre-configured RAID setup, as otherwise disko would
wipe the partition tables and create new ones but would
not be able to inform the kernel about it, as the old
raid was still in use.
2024-01-11 10:37:12 +00:00
Carl Dongandmergify[bot] 196a5deeea disk-deactivate: Use bash and pipefail 2023-10-22 17:26:03 +00:00
Carl Dongandmergify[bot] 94af39d27e disk-deactivate: Remove MBR bootstrap code for disk 2023-10-22 17:26:03 +00:00
lassulusandmergify[bot] 7304727801 disk-deactivate: support all raid types 2023-09-12 08:41:56 +00:00
lassulusandmergify[bot] 7036bb8b30 disk-deactivate: execute directly instead of echoing script 2023-09-12 08:41:56 +00:00
lassulusandmergify[bot] 7bee8de8e6 disk-deactivate: return correct bash script 2023-09-07 06:48:47 +00:00
lassulusandmergify[bot] b2ea7d6258 disk-deactivate: show disk layout before and after running 2023-09-05 09:23:03 +00:00
Jörg Thalheim a511f59961 jq: filter null values from mountpoints from lsblk output 2023-02-03 14:57:55 +01:00
lassulusandlassulus 08dc4d06da disk-deactivate: follow by-id/by-uuid links to real device 2023-01-28 18:08:31 +01:00
Victor Engmark 4553130780 fix: Quote variable reference
As recommended by ShellCheck.
2023-01-10 17:02:29 +13:00
lassulus 17da9b0708 init disk-deactivate for cleaning up the disk 2022-12-24 20:53:56 +01:00