Repository navigation
Upgrading Container Optimized OS
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.
Go to shell.cloud.google.com and wait for the prompt.
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.
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.
git clone https://github.com/dadatuputi/bitwarden_gcloud.git
cd bitwarden_gcloud
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.
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.
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.
Run this once. Every future upgrade is Part 4 alone.
./utilities/migrate-to-data-disk.sh --instance $INSTANCE --zone $ZONE
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.
=== 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.
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.
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.
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.
Only after that login succeeds:
gcloud compute ssh $INSTANCE --zone $ZONE --command 'rm -rf ~/bitwarden_gcloud'
./utilities/upgrade-cos.sh --instance $INSTANCE --zone $ZONE
=== 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.
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.
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.
The new instance has a new name. Point your variable at it:
export INSTANCE=${INSTANCE}-129
Use whatever milestone number the script reported.
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.
gcloud compute ssh $INSTANCE --zone $ZONE --command 'docker ps -a --format "{{.Names}}\t{{.Status}}"'
Every service Up, and bitwarden showing healthy.
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.
gcloud compute ssh $INSTANCE --zone $ZONE --command 'docker exec backup ash /backup.sh local,rclone'
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
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.
gcloud compute disks list --filter='-users:*'
Anything listed is unattached and still counts against your 30 GB. Delete what you do not need.
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
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-standardis free.pd-balancedandpd-ssdcharge 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-microinstances running at once draw the same pool down at twice the rate, so--overlapcosts instance-hours as well as disk. The default deletes first and avoids both.
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.
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
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.
- Assumes one instance, no external load balancer, and DNS handled by the
ddnscontainer. 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.
-
diskSizeGbstates 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.
- Installation
- Backup
utilities/README-cos-updates.md
- Installation
- Configuration
- Backup, required
- Email Providers, required
- DDNS, required on the Caddy path
- Countryblock (Caddy path)
- Fail2ban (Caddy path)
- Automatic Restarts
- Maintenance