Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for incremental changes #568

Merged
merged 1 commit into from
Mar 13, 2024
Merged

Add support for incremental changes #568

merged 1 commit into from
Mar 13, 2024

Conversation

Lassulus
Copy link
Collaborator

@Lassulus Lassulus commented Mar 12, 2024

rework of #435 with a smaller (and more logical) scope

@Lassulus Lassulus force-pushed the idempotent-create branch 3 times, most recently from ec6453e to 275a412 Compare March 12, 2024 06:13
@Lassulus Lassulus marked this pull request as ready for review March 12, 2024 06:32
@Lassulus Lassulus requested a review from Mic92 March 12, 2024 06:32
@Lassulus Lassulus force-pushed the idempotent-create branch 3 times, most recently from 5df2a96 to 00602b0 Compare March 13, 2024 07:08
@Lassulus Lassulus force-pushed the idempotent-create branch from 00602b0 to f6b72bf Compare March 13, 2024 08:58
@Lassulus Lassulus merged commit 59e50d4 into master Mar 13, 2024
39 checks passed
@Lassulus Lassulus deleted the idempotent-create branch March 13, 2024 12:22
@Mic92 Mic92 changed the title types *: make create idempotent types *: add support for incremental changes Mar 25, 2024
@Mic92 Mic92 changed the title types *: add support for incremental changes add support for incremental changes Mar 25, 2024
@Mic92 Mic92 changed the title add support for incremental changes Add support for incremental changes Mar 25, 2024
if ! (blkid '${config.device}' -o export | grep -q '^TYPE='); then
mkfs.btrfs "${config.device}" ${toString config.extraArgs}
fi
if (blkid "${config.device}" -o export | grep -q '^TYPE=btrfs$'); then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that this is causing syntax error near unexpected token `fi' when formatting a btrfs filesystem without any swap or subvolume configuration.

I guess this all should be gaurded by config.swap & config.subvolumes being set? It's a bit annoying bash doesn't support empty if statements.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplest fix would be echo -n "" in the first line.

@gabevenberg
Copy link

Is there documentation on how to use this?

iFreilicht added a commit to iFreilicht/.dotfiles that referenced this pull request Aug 22, 2024
Thanks to nix-community/disko#568 it is possible
to change the drive configuration of an existing setup.
Also, I checked the source and options are set via `zfs set` except for
some special ones (like `mountpoint`) that are set with `-o` during
creation, so I can add the `com.sun:auto-snapshot` option here.
iFreilicht added a commit to iFreilicht/.dotfiles that referenced this pull request Aug 22, 2024
Thanks to nix-community/disko#568 it is possible
to change the drive configuration of an existing setup.
Also, since nix-community/disko#689 disko
also incrementally sets options via `zfs set` except for some special
ones (like `mountpoint`) that are set with `-o` during creation, so I
can add the `com.sun:auto-snapshot` option here.
@iFreilicht
Copy link
Contributor

@gabevenberg Basically, run this:

disko --mode format --dry-run disko.nix

This outputs a path to the script that will be run once you remove --dry-run Review the that script first! As this is a new and relatively untested feature, there might be bugs that cause it to change things you don't want it to change. Though when I did it, everything looked good 👍

Then, run the same command without --dry-run.

Be aware that this is only additive. When you add drives and partitions, they will be formatted as desired, but when you remove them from the config, they just become unmanaged. Same for zfs datasets and their options. Adding options will set them, but removing options will not remove them from the dataset.

@adam248
Copy link

adam248 commented Sep 14, 2024

@iFreilicht
Just to confirm, when you say "only additive" that means changing an existing disk from ext4 to btrfs will not work either.
I just did a test on a VM and it appears that it did not change the format.

So to be 100% clear... of the possible CRUD operations it will only do a Create but not the Update (modify) or Delete existing partitions when using --mode format. Thanks

@adam248
Copy link

adam248 commented Sep 14, 2024

@iFreilicht i just rebooted the VM and now it doesn't boot at all. it appears that it may have reformated the root drive even though i didn't change that part of the disk-config.nix.

update:
i have manually mounted the root drive which booting from the nixos min-iso and the data is still there. so it didn't wipe the drive.
This is strange as the only thing I did after booting was try the disko --mode format disko-config.nix after changing one of the data drives from 'ext4' to 'btrfs' then tried a reboot.

@Mic92
Copy link
Member

Mic92 commented Sep 14, 2024

No we don't support ext4 to btrfs conversion for now.

@iFreilicht
Copy link
Contributor

So to be 100% clear... of the possible CRUD operations it will only do a Create but not the Update (modify) or Delete existing partitions when using --mode format. Thanks

Not quite. Update is partially supported for some things like updating the mountpoint of a zfs dataset. The cases where this works are limited, though and there is no comprehensive list of this. That's why I specifically wrote in my instructions that you should use --dry-run and read the resulting script before running anything. This way you will know exactly what changes are made to your system.

This is strange as the only thing I did after booting was try the disko --mode format disko-config.nix after changing one of the data drives from 'ext4' to 'btrfs' then tried a reboot.

Are you sure that's all you did? Maybe you also did a nixos-rebuild after updating the disko-config.nix? That updates the fstab, which specifies which filesystem driver a partition should be mounted with, which will fail if there's a mismatch.

@TheRealGramdalf
Copy link

Be aware that this is only additive.

For future improvements, it might be possible to use custom ZFS properties, zfs history, and/or some other form of examining zfsprops to check what the delta changes are for additional error handling (i.e. dataset has been modified since last run, refusing to overwrite), viewing changes (i.e. datasets exist on device that don't exist in disko config) etc. Just a random thought I had.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants