Skip to content

Upgrading Container Optimized OS

Claude edited this page Aug 27, 2026 · 29 revisions

A running Container-Optimized OS instance never moves to a newer milestone. Patches arrive within the milestone it was built on, and when that milestone stops shipping builds the instance stops receiving them. Moving milestones means building a new instance.

This page walks through it. Two scripts do the work:

Script When
utilities/migrate-to-data-disk.sh Once, ever. Moves the vault onto its own disk.
utilities/upgrade-cos.sh Every upgrade after that.

Once the vault is on its own disk, upgrading never touches your data — the disk detaches from the old instance and attaches to the new one.

Everything runs in Cloud Shell, which has gcloud already installed and authenticated. COS does not ship gcloud, so these cannot run on the instance itself.

Work through the verification steps rather than assuming success, and delete nothing until the vault serves from the new instance.


Part 1 — Set up your session

Step 1. Open Cloud Shell

Go to shell.cloud.google.com and wait for the prompt.

Step 2. Set your instance name and zone

Find them:

gcloud compute instances list

You will see something like:

NAME       ZONE           MACHINE_TYPE  STATUS
bitwarden  us-central1-a  e2-micro      RUNNING

Set these once. Every later command uses them, so nothing below needs editing:

export INSTANCE=bitwarden
export ZONE=us-central1-a

Replace the two values with what the previous command showed.

Step 3. Record your backup encryption key

gcloud compute ssh $INSTANCE --zone $ZONE --command 'grep BACKUP_ENCRYPTION_KEY ~/bitwarden_gcloud/.env'

Copy the value somewhere outside this instance — a password manager entry, not a note on the box.

The scripts take a backup and download it into your Cloud Shell session. That archive is encrypted with this key, and the .env holding the key is inside the archive. Without it recorded separately, the backup cannot be opened.

Step 4. Get the scripts

git clone https://github.com/dadatuputi/bitwarden_gcloud.git
cd bitwarden_gcloud

Part 2 — Check whether you need to upgrade

Step 5. Find your milestone

gcloud compute ssh $INSTANCE --zone $ZONE --command 'grep -E "VERSION|BUILD_ID" /etc/os-release'

Output:

VERSION=109
VERSION_ID=109
BUILD_ID=17800.570.50

Note the VERSION number.

Step 6. Check whether that milestone is still supported

Substitute your number for 109:

gcloud compute images describe-from-family cos-109-lts --project cos-cloud --format='value(name)'

If it is out of support, the family has been withdrawn and you get:

ERROR: (gcloud.compute.images.describe-from-family) NOT_FOUND: The resource
'projects/cos-cloud/global/images/family/cos-109-lts' was not found

That error is the answer: this milestone receives no further security patches, and this page applies.

If it is still supported you get an image name instead, and upgrading is optional.

Step 7. See which milestones are available

for m in 117 121 125 129 133 137 141; do printf '%-14s ' "cos-$m-lts"; gcloud compute images describe-from-family "cos-$m-lts" --project cos-cloud --format='value(name)' 2>/dev/null || echo 'not published'; done

The highest one that returns a name is where you are going. The scripts pick it automatically; this is only so you know what to expect.

Do not answer this question by looking at image deprecation. Every individual build is marked deprecated when a newer one replaces it inside a perfectly healthy family, so an image listing reports live milestones as dead.


Part 3 — Move the vault onto its own disk

Run this once. Every future upgrade is Part 4 alone.

Step 8. Start the migration

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

Step 9. Read the sizing decision

The script measures your vault and picks a disk size:

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

If your vault is close to filling the default, it offers to expand and warns you why that matters:

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.

If nothing fits inside the free tier, it stops and tells you how to override.

Step 10. 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.

Step 11. Wait through the steps

The script reclaims disk space, backs up and verifies the archive, creates and formats the disk, copies the deployment across, and writes the layout into instance metadata.

That last part matters: COS mounts /etc on tmpfs, so a .mount unit written to /etc/systemd/system disappears at the next reboot. The layout goes into cloud-init instead, which reapplies on every boot.

Step 12. Approve the reboot

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

Type y. This is deliberate. A mount that does not come back after a reboot produces a vault that starts against an empty directory, and it is far better to discover that now than during an upgrade.

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

Step 13. Confirm the vault works

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

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

Step 14. Remove the old copy

Only after that login succeeds:

gcloud compute ssh $INSTANCE --zone $ZONE --command 'rm -rf ~/bitwarden_gcloud'

Part 4 — Upgrade the milestone

Step 15. Start the upgrade

./utilities/upgrade-cos.sh --instance $INSTANCE --zone $ZONE

Step 16. Confirm the plan

=== Resolving the target milestone
newest live LTS family: cos-129-lts

=== Plan
  from        bitwarden   (COS milestone 109)
  to          bitwarden-129  (cos-129-lts, 10GB pd-standard)
  data disk   bwgc-data  ->  /mnt/disks/bwgc
  zone        us-central1-a
Proceed? [y/N]

Type y.

Step 17. Note where your backup landed

backup pulled to /home/you/bitwarden_gcloud/bwgc-backups/bw_backup_....aes256
KEEP THIS until the new instance is confirmed working from a real client.

This is your rollback. It is encrypted with the key from Step 3.

Step 18. Let it run

The script stops the stack, detaches the data disk, deletes the old instance, then creates the replacement with the disk attached from first boot.

Deleting first is deliberate: it keeps only one boot disk and one instance in existence, so neither the disk allowance nor the instance-hours allowance is drawn down twice. Your data is on the detached disk and in the backup you just downloaded.

There is no DNS step. The ddns container repoints your record when the stack starts.

Step 19. Confirm the new instance

The new instance has a new name. Point your variable at it:

export INSTANCE=${INSTANCE}-129

Use whatever milestone number the script reported.


Part 5 — Verify

Step 20. Check the instance

gcloud compute ssh $INSTANCE --zone $ZONE --command 'grep -E "VERSION|BUILD_ID" /etc/os-release; docker --version; df -h /mnt/disks/bwgc; lsblk -o NAME,SIZE,TYPE | head -4'

You want the new milestone, a newer Docker, and the data disk mounted.

Step 21. Check the containers

gcloud compute ssh $INSTANCE --zone $ZONE --command 'docker ps -a --format "{{.Names}}\t{{.Status}}"'

Every service Up, and bitwarden showing healthy.

Step 22. Check fail2ban

gcloud compute ssh $INSTANCE --zone $ZONE --command 'docker exec fail2ban fail2ban-client status'

Jails should be listed. A count of 0 means fail2ban started but is protecting nothing.

Step 23. Check backups work on the new host

gcloud compute ssh $INSTANCE --zone $ZONE --command 'docker exec backup ash /backup.sh local,rclone'

Step 24. Check the vault from outside

Substitute your domain:

curl -sI https://YOUR_DOMAIN/api/version | head -1
HTTP/2 200

And that the security headers reach subpaths, not just the root:

curl -sI https://YOUR_DOMAIN/admin | grep -i x-frame-options
x-frame-options: DENY

Step 25. Log in from a real client

Do this before deleting anything. A vault returning 200 is not the same as a vault with your data in it. Check entries and attachments.

Step 26. Look for anything still billing

gcloud compute disks list --filter='-users:*'

Anything listed is unattached and still counts against your 30 GB. Delete what you do not need.


Rollback

The data disk is never rewritten by the upgrade, so it carries your vault either way.

If the new milestone misbehaves, run the same swap against the previous family:

./utilities/upgrade-cos.sh --instance $INSTANCE --zone $ZONE --image-family cos-125-lts

If the data disk itself is lost, restore from the archive downloaded in Step 17. On a fresh deployment, write a minimal .env containing only the key from Step 3 — the real .env comes back from inside the archive:

echo 'BACKUP_ENCRYPTION_KEY=paste-your-key-here' > .env
mkdir -p bitwarden/backups
cp ~/bwgc-backups/bw_backup_*.aes256 bitwarden/backups/
docker-compose up -d backup
docker-compose stop bitwarden
docker exec -it backup backup restore /data/backups/bw_backup_YYYY-MM-DD-HHMMSS.tar.gz.aes256
docker-compose up -d

Reference

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. Both scripts pass --type=pd-standard.
  • Snapshots are never free. Keeping "a snapshot of the last good image" is the one intuitive approach that generates a bill.
  • The instance allowance is by time, not by instance. Two e2-micro instances running at once draw the same pool down at twice the rate, so --overlap costs instance-hours as well as disk. The default deletes first and avoids both.

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 what the allowance leaves beside the boot disk, and the boot disk size comes from the image. With today's 10 GB minimum that is 20 GB, and it moves on its own if a milestone ever needs more.

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

Google has declared a 10 GB minimum for every COS milestone since 2019, across 22 milestones. The scripts read it rather than assume it.

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
upgrade-cos.sh
  --instance NAME       required
  --zone ZONE           required
  --new-instance NAME   default NAME-<milestone>
  --image-family FAM    default: newest live cos-*-lts
  --boot-size SIZE      default 10GB, raised to the image minimum if higher
  --overlap             keep the old instance until the new one verifies
  --keep-old            never delete the old instance
  --yes                 skip prompts

What the update timer does not do

If you installed the timer from utilities/, it reboots into staged updates and keeps you patched within your milestone. It cannot move you between milestones, and once a milestone stops shipping it correctly finds nothing, forever.

gcloud compute ssh $INSTANCE --zone $ZONE --command 'systemctl list-timers cos-update-reboot.timer --no-pager'

The two are complements. Keep the timer; use these scripts to change milestone.

Limits

  • Assumes one instance, no external load balancer, and DNS handled by the ddns container. If you point DNS by hand, update it after the stack starts.
  • SSH host keys change with the instance; your client will warn on first connection.
  • diskSizeGb states what an image requires, not what its partitions consume. On a 30 GB disk COS uses 4.15 GB for OS partitions. Step 20 prints the split on the new instance.

See also

Clone this wiki locally