Moving iocage jails to new pool

gb123

Dabbler
Joined
Oct 12, 2018
Messages
10
After looking in multiple location to find all the information I needed on how to move a my jails to a new pool, I succeeded, and decided to write this guide in case anyone else is struggling with how to do this. This was done on FreeNAS 11.3u5.

The two locations I will be referencing are:

/mnt/OLD/iocage (the current location of the jail)
/mnt/NEW/iocage (the desired location of the jail)

OLD and NEW are whatever pool names you create

Make sure to note what release your jail is running, you will need to import the appropriate release to the new pool

Stop the jail/create copy of the jail

iocage stop JAILNAME
iocage export JAILNAME (this creates a .zip of the jail in /mnt/OLD/iocage/images)

Activate the new jail pool/fetch appropriate release

in the GUI, go to the Jails tab, click the gear icon
"Choose Pool for Plugin and Jail Storage" select the new pool

in the CLI:
iocage fetch (select the appropriate release)

Move jail to new location/edit jail fstab

cp /mnt/OLD/iocage/images/* /mnt/NEW/iocage/images
iocage import JAILNAME

Edit the fstab for each jail, changing every instance of /mnt/OLD to /mnt/NEW, fstab for jails is located at:

/mnt/NEW/iocage/jails/JAILNAME/fstab

Start the jail with: iocage start JAILNAME
 

gb123

Dabbler
Joined
Oct 12, 2018
Messages
10
One issue I ran into was moving very large jails. Apparently the data is written to RAM before it is written to the new location. This caused the system to freeze with swap space errors. The workaround is as follows:

1. On the new pool, create a dataset under the jails dataset for the new jail. Under that newly created dataset, also create a dataset called root.

2. Unzip the .zip file that resulted from iocage export, resulting in two files, one with the jail name, the other the same, but ending in root

3. Run the following commands:

zfs recv -F POOLNAME/iocage/jails/JAILNAME < JAILNAME_2021-03-30
zfs recv -F POOLNAME/iocage/jails/JAILNAME/root < JAILNAME_2021-03-30_root

4. Edit the fstab for the jail as described in orginal post.

5. Start the jail
 

KL2001

Cadet
Joined
Feb 23, 2022
Messages
1
This worked well for me (small jail)

I used sed to make changing fstab faster.

sed -i '.bak' 's/OLD/NEW/g' /mnt/NEW/iocage/jails/JAILNAME/fstab

Hopefully this helps someone.
 

sensor

Dabbler
Joined
Jul 16, 2022
Messages
10
Very helpfull :) all three of you!
Just what I was looking for.
 
Top