vm and lxc in tmpfs

puertorico

Renowned Member
Mar 30, 2014
40
7
73
i tried just for the fun to se how well a kvm/vm would perform on a directory mounted on tmpfs, ohh my it is fast.
i am seeing - almost 7gb write and read speeds.

to overcome the non persistent nature of ram i i have configured proxmox to make a backup on a persistent disk every night. When a reboot occurs, it is just a matter of restoring the most current backup to tmpfs, in this setup i is possible to lose a day in the vm but for this setup i this is not a concern. the benefit of having a vm that fast and not be prone to disk overload is a massive win from my point of view.

This made me think about a lxc container that runs in tmpfs. is that even possible with the nature of lxc ?
i tried in the same directory but i get a error message when creating the container, but in containers there is no way to set writeback or similar that is key for making it work with kvm.?


Creating journal (16384 blocks): done
Multiple mount protection is enabled with update interval 5 seconds.
Writing superblocks and filesystem accounting information: 0/16
Warning, had trouble writing out superblocks.TASK ERROR: command 'mkfs.ext4 -O mmp -E 'root_owner=0:0' /mnt/ramdrive//images/100/vm-100-disk-1.raw' failed: exit code 144
 
Last edited:
  • Like
Reactions: travanx
Hey, since it was not possible for me to find anything on the internet on running containers in pure ram, i found a simple solution just to use of lvm on top of ram.

i hope this can be useful for anyone, use at your own risk. Since ram is not persistent you container will die on a reboot, but what i have done is taking a backup a day to spinning disks, that is enough, if i lose a day, it is not critical since it's just a front end with another backend with all the data, - the backup here is just configured within proxmox as a non compressed file, on thing to say is this is blazing fast, and even with over 50% iowait on the local disk you applications will not be affected but it requires a lot off memory, but with 64gb - 128 gb this is clearly not a issue to run a 10gb image, and since the backup is created as a sequential file, it is relatively fast to re-deploy

This simple script will create a ramdrive usable for containers in proxmox, just remember to add it from the gui within proxmox, as a directory on the mount point you chose. - /mnt/ramstorage


Create ramdrive script
-------------------------------------

#!/bin/bash

#probe the device
modprobe brd rd_size=22000000

#create the device
pvcreate /dev/ram0


#create volumegroup
vgcreate vgramdisk /dev/ram0

#create lvm partition
lvcreate -L 20G -n ramstorage vgramdisk

#make filsystem
mkfs.ext2 /dev/vgramdisk/ramstorage

#mount the filesystem
mount -o noatime /dev/vgramdisk/ramstorage /mnt/ramstorage
sleep 10
echo "ramstorage created"




Deployment script:
---------------------------------------

#!/bin/bash
#stop all
echo "shutting down ct, if any"
pct stop 999
sleep 5

#remove old
echo "removing old ct, if any"
pct destroy 999
sleep 5

#deploy ct 999
new999=$(ls /var/lib/vz/dump/vzdump-lxc-999*.lzo | awk '{ print $1 }')
new999file=$(basename $new999)
pct restore 999 local/"$new999file" --storage ramstorage --force
echo "-----RESTORE DONE 999-----"
pct start 999
echo "-----CT 999 STARTED -----"
 
Last edited:
  • Like
Reactions: travanx

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!