pychroot.base module

class pychroot.base.Chroot(path, /, *, log=None, mountpoints=(), hostname=None, skip_chdir=False)[source]

Bases: snakeoil.contexts.SplitExec

Context manager that provides chroot support.

This is done by forking, doing some magic on the stack so the contents are not executed in the parent, and executing the context in the forked child. Exceptions are pickled and passed through to the parent.

Parameters
  • path (str) – The path to the image to chroot into.

  • log (logging.Logger) – A log object to use for logging.

  • mountpoints (dict) – A dictionary defining the mountpoints to use. These can override any of the defaults or add extra mountpoints. Set to None to disable all default mountpoints.

  • hostname – The hostname for the chroot, defaults to the system

hostname. In order to set the chroot domain name as well specify an

FQDN instead of a singular hostname.

default_mounts = {'/dev': {'recursive': True}, 'proc:/proc': {}, 'sysfs:/sys': {}, 'tmpfs:/dev/shm': {}, '/etc/resolv.conf': {}}
property mounts