doc/migrating-storage-device: show how to resize the fs

This commit is contained in:
2025-08-22 02:57:08 +00:00
parent 028d903e9c
commit 8b333a8887

View File

@@ -1,18 +1,18 @@
## migrating a host to a new drive
1. copy persistent data off of the host:
### 1. copy persistent data off of the host:
```sh
$ mkdir -p mnt old/persist
$ mount /dev/$old mnt
$ rsync -arv mnt/persist/ old/persist/
```
2. flash the new drive
### 2. 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
```
3. expand the partition and filesystem
### 3.1. expand the partition
```sh
$ cfdisk /dev/$new
# scroll to the last partition
@@ -21,24 +21,29 @@ $ cfdisk /dev/$new
> Write
type "yes"
> Quit
$ btrfs filesystem resize max /dev/$new
```
### 3.2. expand the filesystem
```
$ mkdir -p /mnt/$new
$ mount /dev/$new /mnt/$new
$ btrfs filesystem resize max /mnt/$new
```
4. copy data onto the new host
### 4. copy data onto the new host
```
$ mkdir new
$ mount /dev/$new new
$ mkdir /mnt/$new
$ mount /dev/$new /mnt/$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
$ btrfs subvolume create /mnt/$new/persist
# restore the data
$ rsync -arv old/persist/ new/persist/
$ rsync -arv old/persist/ /mnt/$new/persist/
```
5. ensure/fix ownership
### 5. ensure/fix ownership
```
$ chmod -R a+rX new/nix
$ chmod -R a+rX /mnt/$new/nix
# or, let the nix daemon do it:
$ nix copy --no-check-sigs --to new $(nix-build -A hosts.moby)
$ nix copy --no-check-sigs --to /mnt/$new $(nix-build -A hosts.moby)
```
```
6. insert the disk into the system, and boot!
### 6. insert the disk into the system, and boot!