Files
nix-files/doc/migrating-storage-device.md

1001 B

migrating a host to a new drive

  1. copy persistent data off of the host:
$ mkdir -p mnt old/persist
$ mount /dev/$old mnt
$ rsync -arv mnt/persist/ old/persist/
  1. flash the new drive
$ nix-build -A hosts.moby.img
$ dd if=$(readlink ./result) of=/dev/$new bs=4M oflag=direct conv=sync status=progress
  1. expand the partition and filesystem
$ cfdisk /dev/$new
# scroll to the last partition
> Resize
  leave at default (max)
> Write
  type "yes"
> Quit
$ btrfs filesystem resize max /dev/$new
  1. copy data onto the new host
$ mkdir new
$ mount /dev/$new new
# if you want to use btrfs snapshots (e.g. snapper), then create the data directory as a subvolume:
$ sudo btrfs subvolume create new/persist
# restore the data
$ rsync -arv old/persist/ new/persist/
  1. ensure/fix ownership
$ chmod -R a+rX new/nix
# or, let the nix daemon do it:
$ nix copy --no-check-sigs --to new $(nix-build -A hosts.moby)
6. insert the disk into the system, and boot!