0

I am using Container Optimized OS and cloud-init script to run a service as a container. I have a script which format Persistent Drive device with ext4 file system. This script is under per-instance folder:

write_files:
  - path: /var/lib/cloud/scripts/per-instance/fs-prepare.sh
    permissions: 0544
    content: |
      #!/bin/bash
      
      mkfs.ext4 -L data -m 0 -E lazy_itable_init=0,lazy_journal_init=0,discard /dev/disk/by-id/google-data

But it executes every time I reboot the instance and wipe out data. Log file indicates that during the boot, cloud-init does not see cache and decides it is the first boot of the instance:

handlers.py[DEBUG]: start: init-local/check-cache: attempting to read from cache [check]
util.py[DEBUG]: Reading from /var/lib/cloud/instance/obj.pkl (quiet=False)
stages.py[DEBUG]: no cache found
handlers.py[DEBUG]: finish: init-local/check-cache: SUCCESS: no cache found

This corresponds to GCP's COS documentation, which lists /var/lib/cloud as stateless mount. Which brings up the question, how per-instance even suppose to work in COS if COS discards whole state of cloud-init on every reboot?

Vadym Chekan
  • 4,977
  • 2
  • 31
  • 24

0 Answers0