<a id="images-copy"></a>

# How to copy and import images

To add images to an image store, you can either copy them from another server or import them from files (either local files or files on a web server).

#### NOTE
The UI does not currently support copying or importing images.

There is support for importing custom ISO files, but these ISO files are different from images.
When you create an instance from a custom ISO file, the ISO file is mounted as a storage volume in a new empty VM, and you can then install the VM from the ISO file.
See [Content type `iso`](https://canonical.com/lxd/docs/latest/explanation/storage/index.html.md#storage-content-types) and [Create a VM that boots from an ISO](https://canonical.com/lxd/docs/latest/howto/instances_create/index.html.md#instances-create-iso) for more information.

## Copy an image from another server

CLI

To copy an image from one server to another, enter the following command:

```none
lxc image copy [<registry>:|<source_remote>:]<image> <target_remote>:
```

The source can be an [image registry](https://canonical.com/lxd/docs/latest/reference/image_registries/index.html.md#ref-image-registries) or another LXD server that you have added as a remote.
If the target server supports image registries, the source image must be provided by an image registry (or already be available locally on the target server).

#### NOTE
To copy the image to your local image store, specify `local:` as the target remote.

See [`lxc image copy --help`](https://canonical.com/lxd/docs/latest/reference/manpages/lxc/image/copy/index.html.md#lxc-image-copy-md) for a list of all available flags.
The most relevant ones are:

`--alias`
: Assign an alias to the copy of the image.

`--copy-aliases`
: Copy the aliases that the source image has.

`--auto-update`
: Keep the copy up-to-date with the original image.

`--vm`
: When copying from an alias, copy the image that can be used to create virtual machines.

API

To copy an image from one server to another, [export it to your local machine](https://canonical.com/lxd/docs/latest/howto/images_manage/index.html.md#images-manage-export) and then [import it to the other server](#images-copy-import).

<a id="images-copy-import"></a>

## Import an image from files

If you have image files that use the required [Image format](https://canonical.com/lxd/docs/latest/reference/image_format/index.html.md#image-format), you can import them into your image store.

There are several ways of obtaining such image files:

- Exporting an existing image (see [Export an image to a set of files](https://canonical.com/lxd/docs/latest/howto/images_manage/index.html.md#images-manage-export))
- Building your own image using LXD image builder (see [Build an image](https://canonical.com/lxd/docs/latest/howto/images_create/index.html.md#images-create-build))
- Downloading image files from an [image source](https://canonical.com/lxd/docs/latest/reference/remote_image_servers/index.html.md#remote-image-servers) (note that it is usually easier to [use an image registry](https://canonical.com/lxd/docs/latest/howto/images_remote/index.html.md#images-remote) directly instead of downloading it to a file and importing it)

### Import from the local file system

CLI

To import an image from the local file system, use the [`lxc image import`](https://canonical.com/lxd/docs/latest/reference/manpages/lxc/image/import/index.html.md#lxc-image-import-md) command.
This command supports both [unified images](https://canonical.com/lxd/docs/latest/reference/image_format/index.html.md#image-format-unified) (compressed file or directory) and [split images](https://canonical.com/lxd/docs/latest/reference/image_format/index.html.md#image-format-split) (two files).

To import a unified image from one file or directory, enter the following command:

```none
lxc image import <image_file_or_directory_path> [<target_remote>:]
```

To import a split image, enter the following command:

```none
lxc image import <metadata_tarball_path> <rootfs_tarball_path> [<target_remote>:]
```

In both cases, you can assign an alias with the `--alias` flag.
See [`lxc image import --help`](https://canonical.com/lxd/docs/latest/reference/manpages/lxc/image/import/index.html.md#lxc-image-import-md) for all available flags.

API

To import an image from the local file system, send a POST request to the `/1.0/images` endpoint.

For example, to import a unified image from one file:

```none
curl -X POST -H 'Content-Type: application/octet-stream' --unix-socket /var/snap/lxd/common/lxd/unix.socket lxd/1.0/images \
--data-binary @<image_file_path>
```

To import a split image from a metadata file and a container `rootfs` file:

```none
curl -X POST -H 'Content-Type: multipart/form-data' --unix-socket /var/snap/lxd/common/lxd/unix.socket lxd/1.0/images \
--form metadata=@<metadata_tarball_path> --form rootfs=@<rootfs_tarball_path>
```

To import a split image from a metadata file and a VM `rootfs.img` file:

```none
curl -X POST -H 'Content-Type: multipart/form-data' --unix-socket /var/snap/lxd/common/lxd/unix.socket lxd/1.0/images \
--form metadata=@<metadata_tarball_path> --form rootfs.img=@<rootfs_tarball_path>
```

#### NOTE
For a split image, you must send the metadata tarball first and the rootfs image after.

See [`POST /1.0/images`](/lxd/latest/api/#/images/images_post) for more information.
