Code Monkey home page Code Monkey logo

amazon-ec2-hibinit-agent's People

Contributors

anchalag avatar ayusan0890 avatar bwagner5 avatar deborshi1988 avatar einynot avatar fred-lefebvre avatar kjeffsh avatar matthewruffell avatar mitchdz avatar mohamedabdelsalam avatar o8vm avatar secarola avatar yoshifumi-kinoshita avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

amazon-ec2-hibinit-agent's Issues

hibinit-agent lacks fs checks and uses fallocate to create swapfiles

It looks like the hibinit-agent is currently not doing any checks to determine the underlying filesystem and it uses fallocate when creating swapfiles.

def fallocate(fl, size):

def do_allocate(self):

It's best to use dd or something other than fallocate for creating swapfiles. There should also be checks to determine the backing filesystem and possibly kernel version as not all file systems (also depends on kernel version/backports) support swapfiles.

https://man.archlinux.org/man/swapon.8#Files_with_holes

https://unix.stackexchange.com/questions/518559/what-are-the-holes-in-files-created-with-fallocate

https://btrfs.readthedocs.io/en/latest/Swapfile.html?highlight=swap%20files

https://bugzilla.redhat.com/show_bug.cgi?id=1129205

https://manpages.ubuntu.com/manpages/xenial/en/man8/mkswap.8.html

Note that a swap file must not contain any holes. Using cp to create the file  is  not acceptable.
Neither  is  use  of  fallocate on file systems that support preallocated files, such as XFS or
ext4, or on copy-on-write filesystems like btrfs.  It is recommended to use dd and /dev/zero in 
these cases.  Please read notes from swapon before adding a swap file to copy-on-write 
filesystems.

https://manpages.ubuntu.com/manpages/jammy/en/man8/swapon.8.html

Files with holes

The swap file implementation in the kernel expects to be able to write to the file directly, 
without the assistance of the filesystem. This is a problem on files with holes or on copy-on-
write files on filesystems like Btrfs.

Commands like cp or truncate create files with holes. These files will be rejected by swapon.

Preallocated files created by fallocate may be interpreted as files with holes too depending of 
the filesystem. Preallocated swap files are supported on XFS since Linux 4.18.

The most portable solution to create a swap file is to use dd and /dev/zero.

Btrfs

Swap files on Btrfs are supported since Linux 5.0 on files with nocow attribute. See the 
btrfs manual page for more details.

Compatibility with the latest setuptools

With setuptools 62.1 and newer, it's not possible to build this package. The error says:

error: Multiple top-level packages discovered in a flat-layout: ['etc', 'agent', 'packaging'].

To avoid accidental inclusion of unwanted files or directories,
setuptools will not proceed with this build.

If you are trying to create a single distribution with multiple packages
on purpose, you should not rely on automatic discovery.
Instead, consider the following options:

1. set up custom discovery (`find` directive with `include` or `exclude`)
2. use a `src-layout`
3. explicitly set `py_modules` or `packages` with a list of names

To find more information, look for "package discovery" on setuptools docs.

Amazon Linux 2 requires `pm-utils` package to hibernate

When you install ec2-hibinit-agent to amzn2-ami-minimal, EC2 Hibernation doesn't work as expected.

Repro steps:

  1. Create instance with the following configuration
  • Region: us-west-2
  • AMI: ami-09db9da37d31787f3 (amzn2-ami-minimal-hvm-2.0.20220606.1-x86_64-ebs)
  • Instance Type: t3.micro
  • EBS: 30GB gp2, Encrypted
  • Stop - Hibernate behavior: Enable
  1. Install ec2-hibinit-agent
  $ sudo yum update -y
  $ sudo yum install ec2-hibinit-agent -y
  1. Reboot
  $ sudo reboot
  1. Hibernate the instance from Management console

Expected result:

The instance successfully hibernate.
We expect the following messages in /var/log/messages.

Jan  8 21:56:54 ip-172-31-1-206 kernel: PM: hibernation entry
...
Jan  8 21:56:54 ip-172-31-1-206 kernel: PM: hibernation exit

Actual result:

The instance keeps running.
You might see the following log in /var/log/messages.

Jan  8 21:44:22 ip-172-31-1-206 root: Hibernation failed, Sleeping 2 mins before retry

Note

Looking at /etc/acpi/actions/sleep.sh, it apparently depends on /usr/sbin/pm-hibernate included in pm-utils package.
( https://github.com/aws/amazon-ec2-hibinit-agent/blob/master/acpid.sleep.sh#L13 )

        swapon --priority=$swap_priority /swap && /usr/sbin/pm-hibernate

If you install pm-utils, hibernation works as expected.

$ sudo yum install pm-utils

Ubuntu 22.04 incorrect installation

Have just created a new EC2 instance with AMI image: ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-20230516 with a 48gb EBS volume and I have noticed that the root directory contains the following folder structure:

"
> var
> lib
> hibinit-agent"

The top level folder (at same level as boot, dev, etc, home...) is a double quote with a var folder within and so on.

Firstly, am I safe to delete this?
Secondly, how do I reinstall hibinit-agent as it isn't in the directory where I presume from above it should, namely, /var/lib/

Please support encrypted swap

Hi,

some cis-hardened operating systems (such as bottlerocket) require an encrypted swap partition due to kernel_lockdown LSM module.
This is a not-uncommon setup/requirement which should be supported

Fails with "Not enough swap space for hibernation"

When trying to hibernate an Ubuntu EC2 instance (either through the console or with this procedure), I'm getting the error

Failed to hibernate system via logind: Not enough swap space for hibernation

Looking into the logs with sudo journalctl -u systemd-logind, I see

/swapfile: is a candidate device.
/swap-hibinit: ignoring device with lower priority
No swap partitions or files matching resume config were found in /proc/swaps.

Running sudo cat /proc/swaps I see

Filename				Type		Size		Used		Priority
/swapfile                               file		4194300		0		-2
/swap-hibinit                           file		4095996		0		-3

so that the /swapfile which I created has higher priority than the /swap-hibinit file (managed by the Ubuntu-patched hibinit-agent) which is referenced in the grub settings.

Perhaps the priority needs to be set in the swapon command?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.