burmilla / os

Tiny Linux distro that runs the entire OS as Docker containers
https://burmillaos.org
Apache License 2.0
210 stars 13 forks source link

(v2.0.0-beta5) Failed to add swap (swapon failed: Invalid argument) #140

Closed benok closed 2 years ago

benok commented 2 years ago

BurmillaOS Version: (ros os version) v2.0.0-beta5

Where are you running BurmillaOS? (docker-machine, AWS, GCE, baremetal, etc.) a cloud service (kvm based hosting)

Which console you use (default, ubuntu, centos, etc..) default

Please share copy of your cloud-init (remember remove all sensitive data first)

write_files:
- content: |+
    #!/bin/sh
    # add swap (taken from https://web.archive.org/web/20170713205503/https://coreos.com/os/docs/latest/adding-swap.html)
    SWAP_PATH=/var/vm
    SWAP_FILE=swapfile1
    SWAP_SIZE=4g
    SWAPINESS=5
    /bin/rm -rf ${SWAP_PATH}
    /bin/mkdir -p ${SWAP_PATH}
    /bin/touch ${SWAP_PATH}/${SWAP_FILE}
    /bin/bash -c "fallocate -l ${SWAP_SIZE} ${SWAP_PATH}/${SWAP_FILE}"
    /bin/chmod 600 ${SWAP_PATH}/${SWAP_FILE}
    /sbin/mkswap ${SWAP_PATH}/${SWAP_FILE}
    /sbin/sysctl vm.swappiness=${SWAPINESS}
    /sbin/swapon ${SWAP_PATH}/${SWAP_FILE}
  owner: root
  path: /etc/rc.local
  permissions: "0755"

Thank you for developing version 2. I tried v2.0.0-beta5, and found a problem with adding a swap.

rancher@myhost*:~:-) sudo /etc/rc.local                                                                                                             (Aug 30) 13:54:26
Setting up swapspace version 1, size = 4 GiB (4294963200 bytes)
no label, UUID=dc934851-c7b2-4b4b-93ba-df4b6cd6e55a
vm.swappiness = 5
swapon: /var/vm/swapfile1: swapon failed: Invalid argument
rancher@myhost*:~:-( 

I googled about this problem, and found some sites that say its cause is sparse file handling.

So, I tried making a swap using dd, but no luck.

rancher@myhost*:~:-( sudo rm /var/vm/swapfile1

rancher@myhost*:~:-) sudo dd if=/dev/zero of=/var/vm/swapfile1 bs=4M count=1024 status=progress
4294967296 bytes (4.3 GB, 4.0 GiB) copied, 7.86539 s, 546 MB/s
1024+0 records in
1024+0 records out

rancher@myhost*:~:-) sudo chmod 600 /var/vm/swapfile1

rancher@myhost*:~:-) sudo mkswap /var/vm/swapfile1
mkswap: /var/vm/swapfile1: warning: wiping old swap signature.
Setting up swapspace version 1, size = 4 GiB (4294963200 bytes)
no label, UUID=93566d66-a07e-4db4-a437-0c4e7785b319

rancher@myhost*:~:-) sudo swapon -v /var/vm/swapfile1
swapon: /var/vm/swapfile1: found signature [pagesize=4096, signature=swap]
swapon: /var/vm/swapfile1: pagesize=4096, swapsize=4294967296, devsize=4294967296
swapon /var/vm/swapfile1
swapon: /var/vm/swapfile1: swapon failed: Invalid argument

Swap is mandatory for me. Could you confirm this?

p.s. I tried v2.0.0-beta5 almost the whole day, I don't have any problem other than this issue.

olljanat commented 2 years ago

I would try by having separate partition or disk for swap and by following https://burmillaos.org/docs/storage/custom-partition-layout/#burmilla_swap instead of partition file.

Also note that we looks to have search & replace failure on that guide, those partition labels should use prefix RANCHER_ instead of BURMILLA_ for backward compatibility.

benok commented 2 years ago

Umm, I prefer swapfile. It's pretty handy because it can be configurable within cloud-init.yml only. I don't want to change the disk layout on every install.

I've perhaps read v2 kernel shares k3os's kernel code, somewhere. Do you think this problem exists on k3os, too? (I don't have env/experience of k3os)

olljanat commented 2 years ago

Ok. One big issue which I see is at least you are using folder /var/vm because in BurmillaOS console is also running inside of container and view to it is different that which kernel see.

With quick look to code at least folder /var/lib/rancher/cache should be mounted to both so if you use SWAP_PATH=/var/lib/rancher/cache/swap it would fix at least that part.

On other why I'm not aware that there would be anything which would prevent you from using swap file.

benok commented 2 years ago

Ok. One big issue which I see is at least you are using folder /var/vm because in BurmillaOS console is also running inside of container and view to it is different that which kernel see.

Ah, Ok. That sounds very reasonable.

(I don't know why above script works on v1.9.3, but :-) I confirmed I can add a swap with SWAP_PATH=/var/lib/rancher/cache/swap.

I'll try to find is there any better location, but thank you for your advice!

olljanat commented 2 years ago

(I don't know why above script works on v1.9.3, but :-)

Ok. Then it might be caused something else too.

I confirmed I can add a swap with SWAP_PATH=/var/lib/rancher/cache/swap.

But did it fix the issue?

benok commented 2 years ago

I confirmed I can add a swap with SWAP_PATH=/var/lib/rancher/cache/swap.

But did it fix the issue?

Yes, it did.
At least, with the above path, it works as expected.