How to enable swap/swapfile on Google container optimized OS on GCE? - swapfile

Using the cos-stable container optimized OS on GCE. Micro instance so ram is pretty sparse. Tried to enable swap to prevent locking due to OOM during docker pulls, but can't get it to work.
I realize most folders are stateless, so I put the swapfile under home:
sudo fallocate -l 1G /home/user/swapfile
sudo chmod 600 /home/user/swapfile
sudo mkswap /home/user/swapfile
results in:
Setting up swapspace version 1, size = 1024 MiB (1073737728 bytes)
no label, UUID=6e965805-2ab9-450f-aed6-577e74089dbf
But sudo swapon /home/user/swapfile gives the error:
swapon: /home/user/swapfile: swapon failed: Invalid argument
Any ideas how to enable swap on COS?

Disk based swap is disabled in the COS image.
You can enable disk based swap with
sysctl vm.disk_based_swap=1
I have the following in my cloud-init:
bootcmd:
- sysctl vm.disk_based_swap=1
- fallocate -l 1G /var/swapfile
- chmod 600 /var/swapfile
- mkswap /var/swapfile
- swapon /var/swapfile

Swap is not supported in container optimized OS
Swap would effectively destroy much of the behavioral isolation Google offers between containers.
Guaranteed pods should never require swap. Burstable pods should have their requests met without requiring swap. BestEffort pods have no guarantee.
I highly suggest you use a bigger instance as a f1-micro only has 600MB of RAM and you still need to run the OS on the instance it addition with your containers

Related

MacOS Catalina read-write mount could not be mounted in single user or recovery mode with permission denied

I need to have writable access to the file system in recovery mode, but I always get the error
mount_apfs: volume could not be mounted: Permission denied.
I am aware of others who solved it like this: Read-only file system" with SIP disabled in macOS Catalina
i.e.:
start in recovery mode (Cmd-R at startup)
open terminal and disable SIP with csrutil disable
reboot into single user mode (Cmd-S at startup)
check SIP is disabled with csrutil status
try to mount the volumes with read/write:
sudo mount -uw /
sudo mount -uw /System/Volumes/Data
Neither of the two volumes can be mounted, I always get permission denied even with SIP disabled.
Interestingly, even if I boot the Mac from an external SSD (in this case an old Sierra installation) I cannot mount the disk as read/write.
Any further suggestions?
The problem in this case was a defect SSD, which switched into readonly mode after only 36 TB written, despite having a design of 1200 TBW.
Unfortunately, MacOS did not report this. When looking at System information > Storage > my SSD > SMART status the system still showed "Verified", which is supposed to mean that everything is ok.
It was not.
I determined this by installing smartmontools and running a check:
brew install smartmontools
smartctl -a disk1
it showed e.g.:
SMART overall-health self-assessment test result: FAILED
- Available spare has fallen below threshold
- media has been placed in read-only mode
- Data Units Written: ... 35,4 TB
- Available Spare: 1%
- Available Spare Threshhold: 10%
So issues
bad luck with SSD
bad error reporting by MacOS

LXD Issue, vm.max_map_count with Elasticsearch

Ok so to start, all the things I've tried so far:
Set vm.max_map_count in:
The host in etc/sysctl.conf
The host in /etc/sysctl.d/99-sysctl.conf
The LXD Container in /etc/sysctl.conf
The LXD container in /etc/sysctl.d/99-sysctl.conf
According to the official LXD production settings, this setting is possible with LXD:
source: https://linuxcontainers.org/lxd/docs/master/production-setup
According to multiple resources online, this is the approved fix to remediate the error, because the default setting is 65530.
I've checked the host, it says this:
cmd: sysctl vm.max_map_count
output: vm.max_map_count = 262144
I've checked the lxd container, it says this:
cmd: sysctl vm.max_map_count
output: vm.max_map_count = 65530
I also verified the configuration file again in LXD container in /etc/sysctl.conf, and it shows the setting as: vm.max_map_count=262144
I've rebooted the container, I've stop and restarted the container, I've even built a new test container. All of them keep saying 65530. What can I do here to close this out?
So I figured out two ways to solve this problem:
Apply the solution above, and then go through an incredibly lengthy and painful process of disabling Apparmor just to change the one setting, then reenable AppArmor again.
Build Elasticsearch on another box, and bypass the entire process.
Took a quick 3 minute assessment, figured it wasn't worth the time + frustration to deal with all the apparmor pains, build it elsewhere.
But to answer the question in case anyone is willing to eat the time & pain to do it in lxd, disable apparmor, apply the vm.max_map_count setting, and then turn apparmor back on.
As of 5-19-2022 I had good luck simply adding vm.max_map_count = 262144 in /etc/sysctl.conf on the host and rebooting the host.
Host is Ubuntu 22.04 as is the LXD container. The Elasticsearch process came up without an issue.
No having to mess with apparmor thankfully!

Resizng data disk on Alicloud

I have a production server running CentOS 6.9 on Alicloud in China. Instance is of ecs.sn1.3xlarge type. Recently one of my data disk became filled-up. So I decided to resize the volume and followed the step by step instructions available on this page: https://www.alibabacloud.com/help/doc-detail/25452.html.
Here are steps that I followed:
Resized disk form console
Rebooted system (Rebooting system didn't resized/populated disk on system)
umount disk
Run fdisk on desired disk
e2fsck -f /dev/vdb1 # check the file system
resize2fs /dev/vdb1 # resize the file system
Thank you in Advance

Resize Virtualbox Ubuntu VM storage not taking effect

I followed these instructions to resize my VirtualBox Ubuntu VM on Mac:
http://osxdaily.com/2015/04/07/how-to-resize-a-virtualbox-vdi-or-vhd-file-on-mac-os-x/
This is after the change:
*****-M-D2KA:$ VBoxManage showhdinfo ~/VirtualBox\ VMs/P4_Runtime/P4_Runtime.vdi
UUID: ce0ccd77-f265-46cd-9679-e25e64f1c992
Parent UUID: base
State: locked read
Type: normal (base)
Location: /Users/*****/VirtualBox VMs/P4_Runtime/P4_Runtime.vdi
Storage format: VDI
Format variant: dynamic default
Capacity: 25000 MBytes
Size on disk: 9967 MBytes
Encryption: disabled
In use by VMs: P4_Runtime (UUID: 5ea52b11-997f-45d8-b7d6-effa37a3b649) [Snapshot 1 (UUID: 409c1035-2134-4532-a931-a29018d33dc6)]
Child UUIDs: 540ae750-5307-44ef-a313-95134ae353b7
165fe99e-490d-4dd9-9602-00e3aaa8f82c
But for some reason, it does not seem to take effect:
This is the "df -k" output in the VM, and I get "No space left on device" error:
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda 10253588 9713020 0 100% /
What am I missing?
I found out what I missed. I used gparted to resize the partition.
Resizing the VHD doesn't change the size of the partition /dev/sda. You can run lsblk inside the guest to see the additional space. To get the extra space that is available in the guest OS, you may
Use something like gparted as mentioned here. Instructions to do that on VHD can be found here. Note that this might not be easiest, but you may be forced to if you plan to not move some of your mount points (Example if you're not ready to move /home/ to a new partition).
Or, create a new partition, again instructions on how to do is present here. I would prefer this option over the first.

More swap space for Docker on Mac OSX Yosemite

I am trying to add more swap space in docker in order to avoid this error installing oracle database:
This system does not meet the minimum requirements for swap space.
Based on the amount of physical memory available on the system, Oracle
Database 11g Express Edition requires 2048 MB of swap space. This
system has 1023 MB of swap space. Configure more swap space on the
system and retry the installation.
I am following the instructions commented here:
https://forums.docker.com/t/docker-for-mac-configure-swap-space/20656/2
but when I execute mkswap I get "command not found":
mkswap /var/swap.file
Any idea?
Docker for Mac runs an Alpine Linux VM to host containers.
This is a prebuilt boot image that is designed for ease of use, and also updates over time so it can be hard to customise some times as most config is reset when you reboot it.
In this case you can persist a swap file change, but config like this has the possibility of changing between versions without notice. You might be better off running a custom VM for this so your swap configuration hangs around.
Docker for Mac 17.06.0
Swap is controlled by the do_swapfile function in the /etc/init.d/automount init script in the VM. If the swap file exists, it will be used as is. As the swap file is stored in /var it is persisted across reboots and can be manually customised.
Attach to the VM's tty from your mac with screen (brew install screen if you don't have it)
screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty
Then in the VM, replace the existing swap file with a new one of the required size and reboot the box. The size of the file is the block size bs * count.
swapoff -a
dd if=/dev/zero of=/var/spool/swap bs=1k count=2097152
chmod 600 /var/spool/swap
mkswap /var/spool/swap
reboot
When the VM has rebooted, you should be able to connect again and see the new size of the VM's Swap space with free.
$ screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty
/ # free
total used free shared buffers cached
Mem: 3526164 389952 3136212 165956 20968 208160
-/+ buffers/cache: 160824 3365340
Swap: 2097148 0 2097148

Resources