LoginSignup
4
3

More than 3 years have passed since last update.

LXDをapt版からsnap版に移行する

Last updated at Posted at 2018-10-31

概要

余っているマシン2台にUbuntu Server + LXDをいれて実験用にコンテナを作って遊んでいるのだが、
1台はUbuntu Server 16.04で、もう1台が18.04なので、インストールされたLXDのバージョンが違う。

そのため2台のマシン間でLXDコンテナのマイグレーションができなかった。

ということで、どちらのマシンにもsnap版のLXDをインストールしてバージョンを揃え、
マイグレーションができるようにした(残念ながらsnap版ではライブマイグレーションは今の所できない追記: どこのバージョンからかはわからないが、snap set lxd criu.enable=trueでできる模様、ただ実験してみると失敗することが多い)。

手順

まずはsnap版のLXDをインストール

$ sudo snap install lxd

apt版からsnap版への以降には、lxd.migrateという便利コマンドがある。
コマンドを叩いたあと、yesとタイプすればapt版からsnap版に移行してくれる。助かる!

$ sudo lxd.migrate 
=> Connecting to source server
=> Connecting to destination server
=> Running sanity checks

=== Source server
LXD version: 2.0.11
LXD PID: 1429
Resources:
  Containers: 1
  Images: 2

=== Destination server
LXD version: 3.1
LXD PID: 8716
Resources:
  Containers: 0
  Images: 0
  Networks: 0
  Storage pools: 0

The migration process will shut down all your containers then move your data to the destination LXD.
Once the data is moved, the destination LXD will start and apply any needed updates.
And finally your containers will be brought back to their previous state, completing the migration.

Are you ready to proceed (yes/no) [default=no]? yes
=> Shutting down the source LXD
=> Stopping the source LXD units
=> Stopping the destination LXD unit
=> Unmounting source LXD paths
=> Unmounting destination LXD paths
=> Wiping destination LXD clean
=> Backing up the database
=> Moving the data
=> Updating the storage backends
=> Starting the destination LXD
=> Waiting for LXD to come online
=> Converting the network configuration
=> Reloading LXD after network update
=> Waiting for LXD to come online

=== Destination server
LXD version: 3.1
LXD PID: 10286
Resources:
  Containers: 1
  Images: 2
  Networks: 1
  Storage pools: 1

The migration is now complete and your containers should be back online.
Do you want to uninstall the old LXD (yes/no) [default=no]? yes

All done. You may need to close your current shell and open a new one to have the "lxc" command work.
To migrate your existing client configuration, move ~/.config/lxc to ~/snap/lxd/current/.config/lxc

最後はapt版のアンインストールまでやってくれた。

2台のマシンともsnap版に移行したあとは、普通にコンテナのマイグレーションができる。
(ライブマイグレーションはできないので、一旦stopしてからmove、start)

$ lxc stop CONTAINER
$ lxc move CONTAINER MACHINE2:
$ lxc start MACHINE2:CONTAINER
4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3