The diskimage_builder.block_device.blockdevice Module

class diskimage_builder.block_device.blockdevice.BlockDevice(params)

Bases: object

Handles block devices.

This class handles the complete setup and deletion of all aspects of the block device level.

A typical call sequence:

cmd_init: initialize the block device level config. After this
call it is possible to e.g. query information from the (partially automatic generated) internal state like root-label.
cmd_getval: retrieve information about the (internal) block device
state like the block image device (for bootloader) or the root-label (for writing fstab).
cmd_create: creates all the different aspects of the block
device. When this call is successful, the complete block level device is set up, filesystems are created and are mounted at the correct position. After this call it is possible to copy / install all the needed files into the appropriate directories.

cmd_writefstab: creates the (complete) fstab for the system.

cmd_umount: unmount and detaches all directories and used many
resources. After this call the used (e.g.) images are still available for further handling, e.g. converting from raw in some other format.
cmd_cleanup: removes everything that was created with the
‘cmd_create’ call, i.e. all images files themselves and internal temporary configuration.
cmd_delete: unmounts and removes everything that was created
during the ‘cmd_create’ all. This call should be used in error conditions when there is the need to remove all allocated resources immediately and as good as possible. From the functional point of view this is mostly the same as a call to ‘cmd_umount’ and ‘cmd_cleanup’ - but is typically more error tolerance.

In a script this should be called in the following way:

dib-block-device init … # From that point the database can be queried, like ROOT_LABEL=$(dib-block-device getval root-label)

Please note that currently the dib-block-device executable can only be used outside the chroot.

dib-block-device create … trap “dib-block-device delete …” EXIT # copy / install files dib-block-device umount … # convert image(s) dib-block-device cleanup … trap - EXIT

cmd_cleanup()

Cleanup all remaining relicts - in good case

cmd_create()

Creates the block device

cmd_delete()

Cleanup all remaining relicts - in case of an error

cmd_getval(symbol)

Retrieve value from block device level

The value of SYMBOL is printed to stdout. This is intended to be captured into bash-variables for backward compatibility (non python) access to internal configuration.

Arguments: :param symbol: the symbol to get

cmd_init()

Initialize block device setup

This initializes the block device setup layer. One major task is to parse and check the configuration, write it down for later examiniation and execution.

cmd_umount()

Unmounts the blockdevice and cleanup resources

cmd_writefstab()

Creates the fstab

create(result, rollback)
write_state(state)