1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
|
(first-steps)=
# First steps with Incus
This tutorial guides you through the first steps with Incus.
It covers installing and initializing Incus, creating and configuring some instances, interacting with the instances, and creating snapshots.
After going through these steps, you will have a general idea of how to use Incus, and you can start exploring more advanced use cases!
## Install and initialize Incus
1. Install the Incus package
Incus is available on most common Linux distributions.
For detailed distribution-specific instructions, refer to {ref}`installing`.
1. Allow your user to control Incus
Access to Incus in the packages above is controlled through two groups:
- `incus` allows basic user access, no configuration and all actions restricted to a per-user project.
- `incus-admin` allows full control over Incus.
To control Incus without having to run all commands as root, you can add yourself to the `incus-admin` group:
sudo adduser $USER incus-admin
newgrp incus-admin
The `newgrp` step is needed in any terminal that interacts with Incus until you restart your user session.
1. Initialize Incus
```{note}
If you are migrating from an existing LXD installation, skip this step and refer to {ref}`server-migrate-lxd` instead.
```
Incus requires some initial setup for networking and storage. This can be done interactively through:
incus admin init
Or a basic automated configuration can be applied with just:
incus admin init --minimal
If you want to tune the initialization options, see {ref}`initialize` for more information.
## Launch and inspect instances
Incus is image based and can load images from different image servers.
In this tutorial, we will use the [official image server](https://images.linuxcontainers.org/).
You can list all images that are available on this server with:
incus image list images:
See {ref}`images` for more information about the images that Incus uses.
Now, let's start by launching a few instances.
With *instance*, we mean either a container or a virtual machine.
See {ref}`containers-and-vms` for information about the difference between the two instance types.
For managing instances, we use the Incus command line client `incus`.
1. Launch a container called `first` using the Debian 12 image:
incus launch images:debian/12 first
```{note}
Launching this container takes a few seconds, because the image must be downloaded and unpacked first.
```
1. Launch a container called `second` using the same image:
incus launch images:debian/12 second
```{note}
Launching this container is quicker than launching the first, because the image is already available.
```
1. Copy the first container into a container called `third`:
incus copy first third
1. Launch a VM called `debian-vm` using the Debian 12 image:
incus launch images:debian/12 debian-vm --vm
```{note}
Even though you are using the same image name to launch the instance, Incus downloads a slightly different image that is compatible with VMs.
```
1. Check the list of instances that you launched:
incus list
You will see that all but the third container are running.
This is because you created the third container by copying the first, but you didn't start it.
You can start the third container with:
incus start third
1. Query more information about each instance with:
incus info first
incus info second
incus info third
incus info debian-vm
1. We don't need all of these instances for the remainder of the tutorial, so let's clean some of them up:
1. Stop the second container:
incus stop second
1. Delete the second container:
incus delete second
1. Delete the third container:
incus delete third
Since this container is running, you get an error message that you must stop it first.
Alternatively, you can force-delete it:
incus delete third --force
See {ref}`instances-create` and {ref}`instances-manage` for more information.
## Configure instances
There are several limits and configuration options that you can set for your instances.
See {ref}`instance-options` for an overview.
Let's create another container with some resource limits:
1. Launch a container and limit it to one vCPU and 192 MiB of RAM:
incus launch images:debian/12 limited --config limits.cpu=1 --config limits.memory=192MiB
1. Check the current configuration and compare it to the configuration of the first (unlimited) container:
incus config show limited
incus config show first
1. Check the amount of free and used memory on the parent system and on the two containers:
free -m
incus exec first -- free -m
incus exec limited -- free -m
```{note}
The total amount of memory is identical for the parent system and the first container, because by default, the container inherits the resources from its parent environment.
The limited container, on the other hand, has only 192 MiB available.
```
1. Check the number of CPUs available on the parent system and on the two containers:
nproc
incus exec first -- nproc
incus exec limited -- nproc
```{note}
Again, the number is identical for the parent system and the first container, but reduced for the limited container.
```
1. You can also update the configuration while your container is running:
1. Configure a memory limit for your container:
incus config set limited limits.memory=128MiB
1. Check that the configuration has been applied:
incus config show limited
1. Check the amount of memory that is available to the container:
incus exec limited -- free -m
Note that the number has changed.
1. Depending on the instance type and the storage drivers that you use, there are more configuration options that you can specify.
For example, you can configure the size of the root disk device for a VM:
1. Check the current size of the root disk device of the Debian VM:
```{terminal}
:input: incus exec debian-vm -- df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 9.6G 1.4G 8.2G 15% /
tmpfs 483M 0 483M 0% /dev/shm
tmpfs 193M 604K 193M 1% /run
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 50M 14M 37M 27% /run/incus_agent
/dev/sda15 105M 6.1M 99M 6% /boot/efi
```
1. Override the size of the root disk device:
incus config device override debian-vm root size=30GiB
1. Restart the VM:
incus restart debian-vm
1. Check the size of the root disk device again:
```{terminal}
:input: incus exec debian-vm -- df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 29G 1.4G 28G 5% /
tmpfs 483M 0 483M 0% /dev/shm
tmpfs 193M 588K 193M 1% /run
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 50M 14M 37M 27% /run/incus_agent
/dev/sda15 105M 6.1M 99M 6% /boot/efi
```
See {ref}`instances-configure` and {ref}`instance-config` for more information.
## Interact with instances
You can interact with your instances by running commands in them (including an interactive shell) or accessing the files in the instance.
Start by launching an interactive shell in your instance:
1. Run the `bash` command in your container:
incus exec first -- bash
1. Enter some commands, for example, display information about the operating system:
cat /etc/*release
1. Exit the interactive shell:
exit
Instead of logging on to the instance and running commands there, you can run commands directly from the host.
For example, you can install a command line tool on the instance and run it:
incus exec first -- apt-get update
incus exec first -- apt-get install sl -y
incus exec first -- /usr/games/sl
See {ref}`run-commands` for more information.
You can also access the files from your instance and interact with them:
1. Pull a file from the container:
incus file pull first/etc/hosts .
1. Add an entry to the file:
echo "1.2.3.4 my-example" >> hosts
1. Push the file back to the container:
incus file push hosts first/etc/hosts
1. Use the same mechanism to access log files:
incus file pull first/var/log/syslog - | less
```{note}
Press `q` to exit the `less` command.
```
See {ref}`instances-access-files` for more information.
## Manage snapshots
You can create a snapshot of your instance, which makes it easy to restore the instance to a previous state.
1. Create a snapshot called "clean":
incus snapshot create first clean
1. Confirm that the snapshot has been created:
incus list first
incus info first
```{note}
`incus list` shows the number of snapshots.
`incus info` displays information about each snapshot.
```
1. Break the container:
incus exec first -- rm /usr/bin/bash
1. Confirm the breakage:
incus exec first -- bash
```{note}
You do not get a shell, because you deleted the `bash` command.
```
1. Restore the container to the state of the snapshot:
incus snapshot restore first clean
1. Confirm that everything is back to normal:
incus exec first -- bash
exit
1. Delete the snapshot:
incus snapshot delete first clean
See {ref}`instances-snapshots` for more information.
|