Created
December 18, 2018 14:43
-
-
Save PSF1/08734baac43aff6af71a40f7ef7f15c9 to your computer and use it in GitHub Desktop.
Run LXC in RAM completely
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
machinename="ubuntu" | |
# Help menu | |
print_help() { | |
cat <<-HELP | |
First, copy both .sh files to the LXC machine folder, next edit and configure the machine name in each. | |
To run the machine in ram you need edit the config file. Replace lxc.rootfs.path by /var/lib/lxc/{machine name}/ramdisk | |
Next run this script again how root. | |
To stop the machine and free the memory use: lxc_ram.stop.sh. To reset the machine run lxc_ram.start.sh again. | |
Be careful that you have enough free memory. | |
HELP | |
exit 0 | |
} | |
if [ $(id -u) != 0 ]; then | |
printf "**************************************\n" | |
printf "* Error: You must run this with sudo or root*\n" | |
printf "**************************************\n" | |
print_help | |
exit 1 | |
fi | |
# printf colors. | |
red=$'\e[1;31m' | |
grn=$'\e[1;32m' | |
yel=$'\e[1;33m' | |
blu=$'\e[1;34m' | |
mag=$'\e[1;35m' | |
cyn=$'\e[1;36m' | |
end=$'\e[0m' | |
mkdir ./ramdisk | |
./lxc_ram.stop.sh | |
printf "Mount the RAMdisk" | |
mount -t tmpfs -o size=5G,nr_inodes=2032748 discoram /var/lib/lxc/${machinename}/ramdisk | |
printf "%-10s [${grn}Ok${end}]\n" "$txt" | |
printf "Coping rootfs/" | |
cp -ar /var/lib/lxc/${machinename}/rootfs/. /var/lib/lxc/${machinename}/ramdisk | |
printf "%-10s [${grn}Ok${end}]\n" "$txt" | |
# Copy source code, or other external files, here. | |
printf "%s\n" "Starting ${machinename} LXC. ${blu}Stop it with lxc_ram.stop.sh${end}" | |
lxc-start -d -n ${machinename} | |
printf "%s\n" "${yel}*******************************************${end}" | |
printf "%s\n" "${yel}** REMEMBER: All changes will be lost !! **${end}" | |
printf "%s\n" "${yel}*******************************************${end}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
machinename="ubuntu" | |
# Help menu | |
print_help() { | |
cat <<-HELP | |
TODO: Help | |
HELP | |
exit 0 | |
} | |
if [ $(id -u) != 0 ]; then | |
printf "**************************************\n" | |
printf "* Error: You must run this with sudo or root*\n" | |
printf "**************************************\n" | |
print_help | |
exit 1 | |
fi | |
# printf colors. | |
red=$'\e[1;31m' | |
grn=$'\e[1;32m' | |
yel=$'\e[1;33m' | |
blu=$'\e[1;34m' | |
mag=$'\e[1;35m' | |
cyn=$'\e[1;36m' | |
end=$'\e[0m' | |
printf "Stoping ${machinename}" | |
lxc-stop -n ${machinename} | |
printf "%-10s [${grn}Ok${end}]\n" "$txt" | |
printf "Clean RAMdisk" | |
umount /var/lib/lxc/${machinename}/ramdisk | |
printf "%-10s [${grn}Ok${end}]\n" "$txt" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment