ubuntu:disk:ramdisk:persisting_ramdisk_data
This is an old revision of the document!
Table of Contents
Ubuntu - Disk - Ramdisk - Persisting Ramdisk Data
A Ramdisk will usually lose all data within it when turned off, or upon a reboot.
The approach is:
- Save Ramdisk data to hard drive on system shutdown.
- Load data from hard drive to Ramdisk on system boot.
NOTE: The directory where the Ramdisk is mounted and where the backup data will be saved must have the same file permissions.
Create backup directory
Create a directory where the Ramdisk data will be saved on system shutdown:
sudo mkdir /mnt/ramdisk_backup
Create a system service file
vi /lib/systemd/system/ramdisk-sync.service
and populate with:
- /lib/systemd/system/ramdisk-sync.service
[Unit] Before=umount.target [Service] Type=oneshot User=root ExecStartPre=/bin/chown -Rf peter /mnt/ramdisk/ ExecStart=/usr/bin/rsync -ar /mnt/ramdisk_backup/ /mnt/ramdisk/ ExecStop=/usr/bin/rsync -ar /mnt/ramdisk/ /mnt/ramdisk_backup/ ExecStopPost=/bin/chown -Rf peter /mnt/ramdisk_backup RemainAfterExit=yes [Install] WantedBy=multi-user.target
Enable the ramdisk-sync service
sudo systemctl enable ramdisk-sync.service
NOTE: The ramdisk-sync service will start automatically on system boot.
Reboot
sudo reboot
Check whether the ramdisk-sync service is running
sudo systemctl status ramdisk-sync
Check the contents of the /mnt/ramdisk and /mnt/ramdisk_backup directories
ls /mnt/ramdisk{,_backup}
NOTE: Both should be empty.
Test
Copy some files to the Ramdisk /mnt/ramdisk.
Reboot again
Check again the contents of both the /mnt/ramdisk and /mnt/ramdisk_backup directories.
- They should be the same!
ubuntu/disk/ramdisk/persisting_ramdisk_data.1624359985.txt.gz · Last modified: 2021/06/22 11:06 by peter