-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bash and script to flush writeback cache in OS suspend and shutdown #86
Comments
Today have happened the problem partial flush to disk using BTRFS and the file system was damaged, but is how new kernel modules have any BTRFS updates was possible easily recover the damaged partition. |
@Augusto7743 Any way you can do a pull request and place these files in a subdirectory called |
I believe that a very final flush via systemd services is a problem.
And from here:
Under Ubuntu, all the executables in #!/bin/sh
/sbin/dmsetup message /dev/mapper/rc-wb_sda1 0 flush I achieved the "final" flush. When the
I tried to remove the script and the result changed as this:
As you can see the volume needed recovering. So this solution may work. I only tried this on a virtual machine like this:
|
@matteotenca |
@Augusto7743 Again, if you can do a pull request and place these files in a subdirectory called scripts/rapiddisk-init with a README.md that gives a description of what each does, we can start officially reviewing it and if/when it looks good, merge it into master. |
Not being possible add script.zip in "rapiddisk pull request". Using waterfox. Perhaps not compatible browser ? |
@Augusto7743 I tried with the systemd approach (i.e. using services), with your files and with many variants found around the web, but the root filesystem with a rapiddisk device attached in writeback mode always ends up unclean on next reboot. The only working solution I found is to put the flushing script in Other writeback caches on other volumes may be flushed just before unmounting, but I believe the root mount cannot be properly flushed before the very last moment, by systemd targets/services. And the last thing the system does before reboot/shutdown is executing the contents of The sleep event is different story, maybe an appropriate systemd target to trigger the service which flush the cache may be found, I did not tried. |
Thanks very much for your reply. The files work here with Lubuntu (Ubuntu using LXQT) 20.04.4 LTS. "Other writeback caches on other volumes may be flushed just before unmounting" "I believe the root mount cannot be properly flushed before the very last moment, by systemd targets/services. And the last thing the system does before reboot/shutdown is executing the contents of /lib/systemd/system-shutdown." "sleep event is different story, maybe an appropriate systemd target to trigger the service which flush the cache may be found, I did not tried." In moment need figure what the correct name for "File System Pre" (systemd service for unmount others devices) or an service before "File System Pre" and use it in systemd service. |
Any progress on this topic? Does rapiddisk support auto flush on shutdown/reboot right now? |
Not support for auto flush. |
Hello.
I have used Rapiddisk for writeback cache since version 7.2 in Ubuntu 20.04.
install_initrd.sh does an good task creating commands in OS start thus loading Rapiddisk modules creating the disk cache.
If user choose writeback in root need manually run dmsetup to flush data before OS shutdown.
I had created bash files and systemd service to flush writeback cache when OS enter suspend mode and shutdown thus avoiding data loss and file system damage.
The bash file is
====
#!/bin/bash
sleep 6s
/usr/sbin/dmsetup message /dev/mapper/rc-wb_sdaX 0 flush
exit 0
BTRFS default commit is 6 seconds.
Thus being "sleep" good value is 6.
Path to save the bash is
/usr/local/bin/rapiddisk.sh
After
chmod u+x /usr/local/bin/rapiddisk.sh
The systemd service
====
[Unit]
Description=RapidDisk Writeback Cache Flush
DefaultDependencies=no
Before=sleep.target umount.target
[Service]
Type=oneshot
User=root
Group=root
ExecStart=/usr/local/bin/rapiddisk.sh
TimeoutStartSec=0
[Install]
WantedBy=sleep.target umount.target
Path to save the systemd service
/etc/systemd/system/rapiddisk.service
After enable the systemd service
sudo systemctl enable rapiddisk-flush
Tested since 7.2 to current version correctly working.
Is possible create more caches editing the install_initrd.sh adding commands in end of file.
===
fi
rapiddisk -a 128
rapiddisk -m rd1 -b /dev/sdaX -p wb
log_success_msg "rapiddisk: RAMDISKSIZE MB ramdisk attached to BOOTDEVICE successfully."
log_end_msg
exit 0
Example above 2 caches will be created. One being the default from the install_initrd.sh and the second the manually added in install_initrd.sh need edit the bash rapiddisk.sh.
The problem is if creating caches for others mount point example "home" "opt" or others disks when the OS is starting.
The cache will be created, but the systemd service writeback only work for suspend and shutdown.
Others mounts points than root are unmounted before root umount.
Thus need add in systemd service an configuration to run the bash file before "File System Pre" is being started because others mounts points will be unmounted not being possible flush the writeback data with high risk file system damage.
In moment I not known the name to "File System Pre" target to be added in systemd service.
When using more than one writeback cache I run manually an bash to flush all caches before of full flush in OS shutdown. Not doing that damage the file system. I saw that happen very much using BTRFS using kernel 5.10 in OS crash.
In moment testing writeback using kernel 5.17 without problems.
Would be good the install_initrd.sh allow create more than one default cache and detect if was created writeback cache automatically create one bash file with exact number of created caches and the systemd service.
The text was updated successfully, but these errors were encountered: