## KernelDB.rewrite_metakernel()


Rewrite a metakernel for local use with minimal edits.


Usage

``` python
KernelDB.rewrite_metakernel(
    mk_path,
    output,
    *,
    mission=None,
    link_root=None,
)
```


The method creates a symlink tree at *link_root* that mirrors the original `$KERNELS/<type>/<filename>` layout. Each symlink points to the actual file on disk, which may live in a different mission's tree. Only `PATH_VALUES` in the output `.tm` file is changed, to point to *link_root*. `KERNELS_TO_LOAD`, `PATH_SYMBOLS` and all comments are preserved. See the design notes on minimal metakernel edits for the rationale.

A kernel that cannot be found gets no symlink and a warning. A kernel path that would escape *link_root* is skipped with a warning.


## Parameters


`mk_path: str | Path`  
The original metakernel: a path, or any reference [resolve_metakernel](resolve_metakernel.md#spice_kernel_db.resolve_metakernel) accepts.

`output: str | Path`  
Where to write the new `.tm` file.

`mission: str | None = None`  
Mission name for preferred-mission resolution.

`link_root: str | Path | None = None`  
Where to create the symlink tree. `None` means a `kernels/` directory next to *output*, matching the common `..` convention.


## Returns


`tuple[Path, list[str]]`  
`(output_path, warnings)`.


## Raises


`MetakernelNotTracked`  
*mk_path* matches nothing.

`AmbiguousMetakernel`  
*mk_path* matches several registry rows.
