code: def set_mounted(unitname: str, mounted: bool, swallow_exc: bool = False):
      
      try:
          if mounted:
              LOG.info(f"Starting {unitname}")
              interface().StartUnit(unitname, 'replace')
              LOG.info(f"Started {unitname}")
          else:
              LOG.info(f"Stopping {unitname}")
              interface().StopUnit(unitname, 'replace')
              LOG.info(f"Stopped {unitname}")
      except Exception:
          LOG.info(
              f"Exception {'starting' if mounted else 'stopping'} {unitname}")
          if not swallow_exc:
              raise
docs: Mount or unmount a unit.
  
      Worker for the contextlibs
  
      :param unitname: The systemd unit for the mount to affect. This probably
                       should be one of :py:attr:`_SYSROOT_INACTIVE_UNIT` or
                       :py:attr:`_BOOT_UNIT` but it could be anything
      :param mounted: ``True`` to start the mount unit, ``False`` to stop it
      :param swallow_exc: ``True`` to capture all exceptions, ``False`` to pass
                          them upwards. This is useful for when you don't super
                          care about the success of the mount, like when trying
                          to restore the system after you write the boot part