Skip to content

Instantly share code, notes, and snippets.

@dlage
Last active October 27, 2023 17:11
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 14 You must be signed in to fork a gist
  • Save dlage/8dd97c285e2dd41f58c2 to your computer and use it in GitHub Desktop.
Save dlage/8dd97c285e2dd41f58c2 to your computer and use it in GitHub Desktop.
Bash script to convert an OpenVZ ploop container back to simfs
#!/bin/sh
# ./convert_ploop_to_simfs.sh VEID
# chmod +x convert_ploop_to_simfs.sh
rsync_options='-aHAX --progress --stats --numeric-ids --delete'
partition='vz'
if [ ! -e /etc/vz/conf/$1.conf ]; then
echo "Virtual server configuration file: /etc/vz/conf/$1.conf does not exist."
exit 1
fi
if [ ! -d /$partition/private/$1/root.hdd ]; then
echo "Server does not have a ploop device"
exit 1
fi
if [ ! -d /$partition/private/$1 ]; then
echo "Server does not exist"
exit 1
fi
# Get disk space in G of current VPS
#disk=`vzctl exec $1 df -BG | grep ploop | awk {'print $2'} | head -n1`
#if [ ! $disk ]; then
# echo "Could not retrieve disk space figure. Is VPS running?"
# exit 1
#fi
# Create and mount file system
mkdir -p /$partition/private/1000$1/
#ploop init -s $disk /$partition/private/1000$1/root.hdd/root.hdd
cp /etc/vz/conf/$1.conf /etc/vz/conf/1000$1.conf
vzctl mount 1000$1
# Rsync over files (sync 1)
rsync $rsync_options /$partition/root/$1/. /$partition/private/1000$1/
# Stop primary, mount, sync final
vzctl stop $1
vzctl mount $1
rsync $rsync_options /$partition/root/$1/. /$partition/private/1000$1/
vzctl umount $1
vzctl umount 1000$1
mv /$partition/private/$1 /$partition/private/$1.backup
mv /$partition/private/1000$1 /$partition/private/$1
vzctl start $1
# Cleanup
rm -f /etc/vz/conf/1000$1.conf
rmdir /vz/root/1000$1
# Verification
verify=`vzlist -H -o status $1`
if [ $verify = "running" ]; then
echo "Virtual server conversion successful. Verify manually then run: rm -Rf /$partition/private/$1.backup to remove backup."
else
echo "Server conversion was not successful..Reverting.."
mv -f /$partition/private/$1 /$partition/private/$1.fail
mv /$partition/private/$1.backup /$partition/private/$1
vzctl start $1
fi
@Fusl
Copy link

Fusl commented Aug 14, 2014

Change rsync_options to "-aHAX --progress --stats --numeric-ids --delete" which will keep ACLs, xattrs, numeric-ids and will delete files which changed between the two rsync stages.

@miraclebg
Copy link

Thank you! :)

@Technoboggle
Copy link

thank you, very helpful. I changed the rsync_options as above and worked perfectly 😃

@Norbert42
Copy link

There is an error. You must edit /etc/vz/$1.conf and set VE_LAYOUT=ploop to VE_LAYOUT=simfs otherwise vzctl searches the ploop disk.
Excellent script! Thank you.

@mbdwey
Copy link

mbdwey commented Mar 24, 2018

@coriaweb
Copy link

Forgive the translation, I use an online translator.

I'm having errors using this script. Does anyone know the reason for the error?

sent 304943 bytes received 2155 bytes 614196.00 bytes/sec total size is 340738857 speedup is 1109.54 Unmounting file system at /vz/root/161 Unmounting device /dev/ploop58999 Container is unmounted CT is not mounted Starting container... Error in ploop_open_dd (di.c:288): Can't resolve /vz/private/161/root.hdd/DiskDescriptor.xml: No such file or directory Failed to read /vz/private/161/root.hdd/DiskDescriptor.xml Error in ploop_open_dd (di.c:288): Can't resolve /vz/private/161/root.hdd/DiskDescriptor.xml: No such file or directory Failed to read /vz/private/161/root.hdd/DiskDescriptor.xml Error in ploop_open_dd (di.c:288): Can't resolve /vz/private/161/root.hdd/DiskDescriptor.xml: No such file or directory Failed to read /vz/private/161/root.hdd/DiskDescriptor.xml Server conversion was not successful..Reverting.. Starting container...

@dokbua
Copy link

dokbua commented Jan 30, 2020

There is an error. You must edit /etc/vz/$1.conf and set VE_LAYOUT=ploop to VE_LAYOUT=simfs otherwise vzctl searches the ploop disk.
Excellent script! Thank you.

I think you mean /etc/vz/conf/$1.conf

@dokbua
Copy link

dokbua commented Jan 30, 2020

Actually, I don't see how this script does any conversion. It creates a new folder, copies content over (by rsync) stops and restarts the server, but where is any actual conversion taking place?

There's a "ploop init" line but it's commented out.

What's the point?

@dlage
Copy link
Author

dlage commented Jan 30, 2020

Actually, I don't see how this script does any conversion. It creates a new folder, copies content over (by rsync) stops and restarts the server, but where is any actual conversion taking place?

There's a "ploop init" line but it's commented out.

What's the point?

The script copies to a new VEID, which defaults to simfs. If I recall correctly it's (or was) a step needed to convert openvz to proxmox.

@dlage
Copy link
Author

dlage commented Jan 30, 2020

Change rsync_options to "-aHAX --progress --stats --numeric-ids --delete" which will keep ACLs, xattrs, numeric-ids and will delete files which changed between the two rsync stages.

Thanks for the tip. Updated (better late than never)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment