---
title: Charmhub | Deploy Operator Libs Linux using Charmhub - The Open Operator Collection
description: Deploy the latest version of Operator Libs Linux on any cloud.
url: https://charmhub.io/operator-libs-linux/libraries/grub
---

# Operator Libs Linux

[Jon Seager](https://charmhub.io/publisher/jnsgruk "View all packages from Jon Seager")

* [Jon Seager](https://charmhub.io/publisher/jnsgruk "View all packages from Jon Seager")

Platform:

22.04

20.04

stable 2

```
juju deploy operator-libs-linux
```

[Learn to deploy on juju >](https://juju.is/docs/juju/manage-applications)

[Toggle side navigation](https://charmhub.io/operator-libs-linux/libraries/grub#drawer)

## charms.operator\_libs\_linux.v0.grub

* [*Docstrings*Docstrings](https://charmhub.io/operator-libs-linux/libraries/grub)
  [*Code*Source code](https://charmhub.io/operator-libs-linux/libraries/grub/source-code)
* + Download

    Fetch library

    ```
    charmcraft fetch-lib charms.operator_libs_linux.v0.grub
    ```

    [Download grub.py](https://charmhub.io/operator-libs-linux/libraries/grub/download)
  + *Last updated* 31 Aug 2023
  + *Revision* Library version 0.3

Simple library for managing Linux kernel configuration via GRUB.

This library is only used for setting additional parameters that will be stored in the
"/etc/default/grub.d/95-juju-charm.cfg" config file and not for editing other
configuration files. It's intended to be used in charms to help configure the machine.

Configurations for individual charms will be stored in "/etc/default/grub.d/90-juju-",
but these configurations will only have informational value as all configurations will be merged
to "/etc/default/grub.d/95-juju-charm.cfg".

Example of use:

```
class UbuntuCharm(CharmBase):
    def __init__(self, *args):
        ...
        self.framework.observe(self.on.install, self._on_install)
        self.framework.observe(self.on.update_status, self._on_update_status)
        self.framework.observe(self.on.remove, self._on_remove)
        self.grub = grub.GrubConfig(self.meta.name)
        log.debug("found keys %s in GRUB config file", self.grub.keys())

    def _on_install(self, _):
        try:
            self.grub.update(
                {"GRUB_CMDLINE_LINUX_DEFAULT": "$GRUB_CMDLINE_LINUX_DEFAULT hugepagesz=1G"}
            )
        except grub.ValidationError as error:
            self.unit.status = BlockedStatus(f"[{error.key}] {error.message}")

    def _on_update_status(self, _):
        if self.grub["GRUB_CMDLINE_LINUX_DEFAULT"] != "$GRUB_CMDLINE_LINUX_DEFAULT hugepagesz=1G":
            self.unit.status = BlockedStatus("wrong GRUB configuration")

    def _on_remove(self, _):
        self.grub.remove()
```

---

Index

* [class ValidationError](https://charmhub.io/operator-libs-linux/libraries/grub#validationerror)
* + [def \_\_init\_\_(
    self,
    key,
    message)](https://charmhub.io/operator-libs-linux/libraries/grub#validationerror-__init__)
* + [def \_\_str\_\_(
    self)](https://charmhub.io/operator-libs-linux/libraries/grub#validationerror-__str__)
* [class IsContainerError](https://charmhub.io/operator-libs-linux/libraries/grub#iscontainererror)
* [class ApplyError](https://charmhub.io/operator-libs-linux/libraries/grub#applyerror)
* [def check\_update\_grub(
  )](https://charmhub.io/operator-libs-linux/libraries/grub#check_update_grub)
* [def is\_container(
  )](https://charmhub.io/operator-libs-linux/libraries/grub#is_container)
* [class Config](https://charmhub.io/operator-libs-linux/libraries/grub#config)
* + [def \_\_init\_\_(
    self,
    charm\_name)](https://charmhub.io/operator-libs-linux/libraries/grub#config-__init__)
* + [def \_\_contains\_\_(
    self,
    key)](https://charmhub.io/operator-libs-linux/libraries/grub#config-__contains__)
* + [def \_\_len\_\_(
    self)](https://charmhub.io/operator-libs-linux/libraries/grub#config-__len__)
* + [def \_\_iter\_\_(
    self)](https://charmhub.io/operator-libs-linux/libraries/grub#config-__iter__)
* + [def \_\_getitem\_\_(
    self,
    key)](https://charmhub.io/operator-libs-linux/libraries/grub#config-__getitem__)
* + [def applied\_configs(
    self)](https://charmhub.io/operator-libs-linux/libraries/grub#config-applied_configs)
* + [def blocked\_keys(
    self)](https://charmhub.io/operator-libs-linux/libraries/grub#config-blocked_keys)
* + [def charm\_name(
    self)](https://charmhub.io/operator-libs-linux/libraries/grub#config-charm_name)
* + [def path(
    self)](https://charmhub.io/operator-libs-linux/libraries/grub#config-path)
* + [def apply(
    self)](https://charmhub.io/operator-libs-linux/libraries/grub#config-apply)
* + [def remove(
    self,
    apply)](https://charmhub.io/operator-libs-linux/libraries/grub#config-remove)
* + [def update(
    self,
    config,
    apply)](https://charmhub.io/operator-libs-linux/libraries/grub#config-update)

#### class ValidationError

Description

Exception representing value validation error. None

Methods

ValidationError.
\_\_init\_\_(

*self*

,
key: str

,
message: str
)

ValidationError.
\_\_str\_\_(

*self*
)

Description

Return string representation of error. None

#### class IsContainerError

Description

Exception if local machine is container. None

#### class ApplyError

Description

Exception if applying new config failed. None

#### def check\_update\_grub()

Description

Report whether an update to /boot/grub/grub.cfg is available. None

#### def is\_container()

Description

Report whether the local machine is a container. None

#### class Config

Manages GRUB configuration.

Description

This object will load current configuration option for GRUB and provide option
to update it with simple validation, remove charm option and apply those changes.

Methods

Config.
\_\_init\_\_(

*self*

,
charm\_name: str
)

Description

Initialize the GRUB config. None

Config.
\_\_contains\_\_(

*self*

,
key: str
)

Description

Check if key is in config. None

Config.
\_\_len\_\_(

*self*
)

Description

Get size of config. None

Config.
\_\_iter\_\_(

*self*
)

Description

Iterate over config. None

Config.
\_\_getitem\_\_(

*self*

,
key: str
)

Description

Get value for key form config. None

Config.
applied\_configs(

*self*
)

Description

Return list of charms configs which registered config in LIB\_CONFIG\_DIRECTORY. None

Config.
blocked\_keys(

*self*
)

Description

Get set of configured keys by other charms. None

Config.
charm\_name(

*self*
)

Description

Get charm name or use value obtained from JUJU\_UNIT\_NAME env. None

Config.
path(

*self*
)

Description

Return path for charm config. None

Config.
apply(

*self*
)

Description

Check if an update to /boot/grub/grub.cfg is available. None

Config.
remove(

*self*

,
apply: bool
)

Remove config for charm.

Description

This function will remove config file for charm and re-create the `95-juju-charm.cfg`
GRUB config file without changes made by this charm.

Config.
update(

*self*

,
config

,
apply: bool
)

Description

Update the Grub configuration. None
