Skip to content

Migrating to a Data Disk

Claude edited this page Nov 6, 2026 · 22 revisions

Moves the vault onto its own persistent disk. Do this once. After it, Upgrading Container-Optimized OS never touches your data.¹

Everything on this page runs in Cloud Shell.² Allow 30 minutes. Your vault is offline for 10 to 20 of them.


Before you start

1. Set up Cloud Shell

Work through Cloud Shell Setup. It leaves you in ~/bwgc with the scripts downloaded and INSTANCE and ZONE exported.

2. Confirm gcloud reaches your deployment

gcloud compute ssh $INSTANCE --zone $ZONE --command 'whoami; ls -d ~/bitwarden_gcloud 2>/dev/null || ls -d /home/*/bitwarden_gcloud 2>/dev/null'

The path printed must be under the home of the user whoami reports. If it names a different user, run this page from the machine that installed the vault.³

3. Check the deployment's age

gcloud compute ssh $INSTANCE --zone $ZONE --command 'cd ~/bitwarden_gcloud && git log -1 --format="%h %cs" && grep -c "^  backup:" docker-compose.yml || true'

4. Turn backups on

The script takes and verifies a backup before it moves anything, so the backup container must be running. Check:

gcloud compute ssh $INSTANCE --zone $ZONE --command 'docker ps --format "{{.Names}}" | grep -qx backup && echo running || echo NOT running'

Whatever it says, run these. They change nothing that is already set:

gcloud compute ssh $INSTANCE --zone $ZONE --command 'cd ~/bitwarden_gcloud && grep -q "^BACKUP=" .env || echo "BACKUP=local" >> .env'
gcloud compute ssh $INSTANCE --zone $ZONE --command 'cd ~/bitwarden_gcloud && sed -i "s/^BACKUP_ENV=.*/BACKUP_ENV=true/" .env; grep -q "^BACKUP_ENV=" .env || echo "BACKUP_ENV=true" >> .env'

Optional: encrypt the backup. Replace the value with a long random string of your own, then run:

export MY_BACKUP_KEY='pick-a-long-random-string'
gcloud compute ssh $INSTANCE --zone $ZONE --command "cd ~/bitwarden_gcloud && grep -q '^BACKUP_ENCRYPTION_KEY=.' .env || echo 'BACKUP_ENCRYPTION_KEY=$MY_BACKUP_KEY' >> .env"

Record that string somewhere you can reach without this vault. Without it the backup cannot be opened. Skipping encryption is supported; the backup is then a plain tar.gz to keep private.⁵

Now bring the stack up, so the backup container starts with these settings:⁶

gcloud compute ssh $INSTANCE --zone $ZONE --command '. ~/.bwgc-compose.sh; cd ~/bitwarden_gcloud && docker-compose up -d'

5. Return to the script directory

If Cloud Shell has timed out, re-export the two variables. Run the script from ~/bwgc, because it downloads the backup beside wherever it runs:

cd ~/bwgc
export INSTANCE=bitwarden
export ZONE=us-central1-a

Move the vault

Stay at the keyboard until Step 5. Every prompt reads [y/N]: type y to go on. Pressing Enter aborts.⁷

Step 1. Start the migration

./migrate-to-data-disk.sh --instance $INSTANCE --zone $ZONE

Step 2. Confirm the plan

=== Plan
  instance    bitwarden  (us-central1-a)
  deployment  /home/you/bitwarden_gcloud
  new disk    bwgc-data  15GB  pd-standard
  mounted at  /mnt/disks/bwgc
  This will reboot the instance to prove the mount survives.
Proceed? [y/N]

Type y. If you set a startup-script of your own in the instance metadata, save it first: the script removes it.

The script now backs up and downloads the vault into bwgc-backups/, printing the path. Keep that file until you have logged in at Step 6. Then it stops the vault and copies it to the new disk.⁸

Step 3. Answer the sizing question, if asked

On a 10 GB boot disk you see only a summary, and nothing to answer:

Vault is 850 MB; data disk will be 15GB (boot 10 GB, free tier 30 GB).

On a 30 GB boot disk, from the old installation instructions, the script asks first:

NOTE: this instance has a 30 GB boot disk, so a 15 GB data disk
puts you at 45 GB against a 30 GB free allowance.
...
Continue with a 15 GB data disk? [y/N] y
Vault is 850 MB; data disk will be 15GB (boot 30 GB, free tier 30 GB).

Type y. The overage is about $0.60 a month, and it ends when you run the OS upgrade.⁹

If your vault is too big for any free-tier disk, the script stops instead. See Sizing.

Step 4. If you abort partway

Abort at State it leaves What to do
Proceed? Nothing changed. Re-run when ready.
Continue with a NN GB data disk? or Use a NN GB data disk? Vault running, backup downloaded, no disk created. Re-run when you have decided.
Replace the user-data metadata? Vault stopped, copy on the disk. Re-run. The script offers to finish the interrupted migration; answer y.¹⁰
Reboot ... to prove the mount survives? Vault stopped, everything else done. Reboot by hand (below), wait about a minute, then go to Step 6. Re-running will not help.¹¹

To reboot by hand:

gcloud compute ssh $INSTANCE --zone $ZONE --command 'sudo systemctl reboot'

Step 5. Approve the reboot

Reboot bitwarden now to prove the mount survives? [y/N]

Type y.¹² The instance takes a couple of minutes to return. The script waits, then prints the mount and the running containers.

Step 6. Confirm the vault works

gcloud compute ssh $INSTANCE --zone $ZONE --command 'df -h /mnt/disks/bwgc && docker ps --format "{{.Names}}\t{{.Status}}"'

Open your vault in a browser and log in. Check that your entries and attachments are there.

Step 7. Remove the old copy

The script offered this at the end of its run. Check which answer you gave:

gcloud compute ssh $INSTANCE --zone $ZONE --command 'ls -ld ~/bitwarden_gcloud; mountpoint /mnt/disks/bwgc'
  • A line ending -> /mnt/disks/bwgc/bitwarden_gcloud, plus is a mountpoint: already done.
  • A line starting drwx, plus is a mountpoint: the old copy is still there. Remove it and leave a symlink:
gcloud compute ssh $INSTANCE --zone $ZONE --command 'sudo rm -rf ~/bitwarden_gcloud && ln -s /mnt/disks/bwgc/bitwarden_gcloud ~/bitwarden_gcloud'

Do not run that unless /mnt/disks/bwgc reported is a mountpoint. Otherwise it deletes your only copy.


Done

Your vault now runs from /mnt/disks/bwgc/bitwarden_gcloud.

Check which release it is on:

gcloud compute ssh $INSTANCE --zone $ZONE --command 'cd /mnt/disks/bwgc/bitwarden_gcloud && git describe --tags --always'

v2.0.3-41-gabc1234 means 41 commits past v2.0.3. Anything older than the newest release means the migration moved your files as they were, and you should update next with Updating Your Deployment.¹⁸

Then: Upgrading Container-Optimized OS. Cloud Shell is already set up, so start at Part 1 there.


A deployment older than mid-2023

For a deployment whose docker-compose.yml has no backup service. Bring it up to date with these five steps, then return to 4. Turn backups on.

1. Take a backup by hand. The vault is offline for a few seconds.

gcloud compute ssh $INSTANCE --zone $ZONE --command 'cd ~/bitwarden_gcloud && docker stop bitwarden && sudo tar czf ~/pre-update.tar.gz --exclude=bitwarden/backups bitwarden .env caddy/Caddyfile; docker start bitwarden; sudo chown "$(id -u)" ~/pre-update.tar.gz'
gcloud compute scp $INSTANCE:~/pre-update.tar.gz . --zone $ZONE

The archive is not encrypted and holds your vault database, admin token and SMTP password. Keep it private, and delete it once the migration is done.

2. Update the code. The first command lists local changes. Copy anything listed that you want to keep, then run the second.

gcloud compute ssh $INSTANCE --zone $ZONE --command 'cd ~/bitwarden_gcloud && git status --porcelain'
gcloud compute ssh $INSTANCE --zone $ZONE --command 'cd ~/bitwarden_gcloud && git checkout -- docker-compose.yml && git fetch -q --tags origin && git checkout -q "$(git tag -l "v*" --sort=-v:refname | head -1)" && git describe --tags'

A warning that git could not open directory 'ddns/' is harmless.¹³

3. Replace the old compose.

gcloud compute ssh $INSTANCE --zone $ZONE --command 'cd ~/bitwarden_gcloud && sh utilities/install-alias.sh'

Do not edit docker-compose.yml to suit the old compose.¹⁴

4. Bring .env up to date. This lists settings your .env lacks:

gcloud compute ssh $INSTANCE --zone $ZONE --command 'cd ~/bitwarden_gcloud && grep -oE "^#?[A-Z_]+=" .env.template | tr -d "#" | sort -u > /tmp/t && grep -oE "^[A-Z_]+=" .env | sort -u > /tmp/e && comm -23 /tmp/t /tmp/e'

None is needed for the migration, which only needs BACKUP, set in step 4 above. Add what applies to you from the comments in .env.template.

Then fix any of these values the old template left behind. Each one stops a current container:

In your .env What happens Fix
BACKUP_EMAIL_NOTIFY=true with no SMTP_HOST Backups run but no notice is sent.¹⁵ Fill in the SMTP settings, or comment the line out
YUBICO_SERVER= with no value Vaultwarden restarts in a loop Comment the line out
EMAIL= with no value Caddy restarts in a loop Set it to your address

The first fix in one command:

gcloud compute ssh $INSTANCE --zone $ZONE --command 'cd ~/bitwarden_gcloud && grep -q "^SMTP_HOST=." .env || sed -i "s/^BACKUP_EMAIL_NOTIFY=true/#BACKUP_EMAIL_NOTIFY=true/" .env'

5. Recreate the stack.

gcloud compute ssh $INSTANCE --zone $ZONE --command '. ~/.bwgc-compose.sh; cd ~/bitwarden_gcloud && docker-compose up -d --remove-orphans && docker ps --format "{{.Names}}\t{{.Status}}"'

This also brings watchtower back.¹⁶

Log in to your vault to check it still works, then return to 4. Turn backups on.


Reference

What the script does

To do the move by hand, these are the steps. Read the script for the exact commands and the checks between them.

Script step What happens
Checks Finds the deployment, installs the compose shim, and refuses to start without a running backup container.
1/7 Prunes unused Docker images and the build cache, and empties bitwarden/bitwarden.log.
2/7 Runs docker exec backup ash /backup.sh local, confirms the archive holds db.sqlite3, and downloads it with gcloud compute scp.
3/7 gcloud compute disks create a pd-standard disk, then instances attach-disk with --device-name set to the disk name, so it appears at /dev/disk/by-id/google-<disk>.
4/7 Formats it ext4 if it is blank, mounts it at /mnt/disks/bwgc, runs compose down, sudo rsync -a the deployment onto it (leaving out bitwarden/backups/), checks the copy, and sets BWGC_RESTART_POLICY=no in the copied .env.
5/7 Writes the output of --print-cloud-config to the instance's user-data metadata and removes startup-script. That cloud-config mounts the disk and starts the stack on every boot.
6/7 Reboots and waits for the mount and bwgc.service.
7/7 Offers to replace ~/bitwarden_gcloud with a symlink to the data disk.

Step 5/7 is the one that cannot be skipped.¹⁷

Sizing

within 3 GB of filling the default size?
  no  -> use the default (15 GB)
  yes -> room to expand?
           yes -> expand to the ceiling, with a warning
           no  -> stop, and offer --force

The ceiling is whatever the free tier leaves beside your boot disk, which the script reads from the instance. When it expands, it says so:

Vault is 13 GB, within 3 GB of filling a 15 GB disk.
Expanding the data disk to 20 GB.

WARNING: 20 GB of data plus a 10 GB boot disk is the whole 30 GB free tier
allowance, with nothing spare.

On a 10 GB boot disk the ceiling is 20 GB:

Vault Data disk Result
up to 11 GB 15 GB 25 GB total, 5 GB spare
12–17 GB 20 GB prompts first, no margin left
18 GB or more stops --force --disk-size <size> to accept the charge

A 30 GB boot disk already fills the allowance, so the script prices the overage and asks:

NOTE: this instance has a 30 GB boot disk, so a 15 GB data disk
puts you at 45 GB against a 30 GB free allowance.

Persistent disks cannot be shrunk, so the boot disk stays this size until the
instance is replaced. The COS upgrade does replace it, and builds the new one at
10 GB, which brings you back inside the allowance. Until then the overage is
about $0.60 a month at $0.04 per GB.
Continue with a 15 GB data disk? [y/N]

Free tier

The Always Free tier covers 30 GB of standard persistent disk and one e2-micro in us-west1, us-central1 or us-east1.

  • Only pd-standard is free. pd-balanced and pd-ssd charge from the first gigabyte.
  • Snapshots are never free.

Options

migrate-to-data-disk.sh
  --instance NAME       required
  --zone ZONE           required
  --disk-name NAME      default bwgc-data
  --disk-size SIZE      override the automatic size
  --mount PATH          default /mnt/disks/bwgc
  --reboot-time HH:MM   OS update reboot window, default 06:00
  --print-cloud-config  print the generated cloud-config and exit
  --yes                 skip prompts
  --force               size past the free tier and accept the charge

See also


Notes

1. A default install keeps everything on the boot disk, so replacing the OS means moving data. On its own disk, the vault detaches from the old instance and attaches to the new one instead.

2. Cloud Shell has gcloud installed and signed in. Container-Optimized OS does not ship gcloud, so none of this can run on the instance itself.

3. gcloud compute ssh takes the login name from your local machine, not from your Google account. A deployment that has not been migrated lives in a home directory, so connecting from a different machine lands in a different home, where ~/bitwarden_gcloud does not exist.

4. The backup service was added in July 2023. Before that, backups ran inside the vaultwarden container, which the script cannot use. The update has to come before the migration, because the migration takes its safety backup through the backup container.

5. BACKUP names a method, not a boolean; local is enough here, and Backup covers email and rclone. BACKUP_ENV=true puts .env inside the archive, so a restore brings your settings back; because .env holds your admin token and SMTP password, pair it with BACKUP_ENCRYPTION_KEY. The script reports which of these you have before it takes the backup, and stops only when there is no backup container at all.

6. The backup container reads its settings when it is created. A value added after the stack is up does not reach it, and you would get a plaintext archive while the scripts report it as encrypted.

7. The script stops and asks before anything irreversible, and waits at a prompt indefinitely. Which prompts you see depends on your deployment. The script's own Step N/7 headings do not match this page's steps: its Steps 1/7 to 5/7 all run between Proceed? and the reboot prompt.

8. The full list is under What the script does. Along the way it deletes unused Docker images, empties bitwarden/bitwarden.log, refuses to reformat a disk that already has a filesystem, and sets BWGC_RESTART_POLICY=no in the copied .env so that bwgc.service starts the stack after the disk mounts, not the Docker daemon before it.

9. The old installation instructions created a 30 GB boot disk, which is the whole free allowance on its own. Persistent disks cannot be shrunk, so the overage lasts until the OS upgrade replaces the instance with a 10 GB boot disk, leaving you at 25 GB of 30 GB.

10. Declining here while re-running after a lost data disk leaves the instance set to mount a disk that is gone. See Recovering a lost data disk.

11. By the reboot prompt the script has stopped the stack, copied the vault, set BWGC_RESTART_POLICY=no and replaced the metadata. A re-run sees all of that, reports The migration is complete, and exits.

12. A mount that does not come back after a reboot leaves a vault that starts against an empty directory. Finding that out now is far better than during an upgrade.

13. The ddns container owns that directory.

14. Old installs aliased docker-compose to a Compose 1.26.2 image, which cannot read the current file. The script above installs the current shim and removes that alias, and the shim reads the file as it is.

15. A backup image from before October 2026 stops every backup instead, including the one the migration takes.

16. The old deployment ran the abandoned containrrr/watchtower, which no longer works with current Docker. Recreating the stack replaces it with nickfedor/watchtower. To stop it updating, see Operations.

17. Container-Optimized OS resets /etc on every boot, so a mount added any other way is gone after the next reboot, and the stack then starts against an empty directory.

18. The migration copies the deployment and does not update it. A deployment on code from before January 2026 still runs the abandoned containrrr/watchtower, which no longer works with current Docker, so its images get no security updates until the update replaces it.

Clone this wiki locally