General TC > Programming & Scripting - Unofficial
Tinkering with rebuildfstab
Rich:
Hi curaga
I've made the following changes:
1. The arbitration logic still queues up multiple scripts, but after the first script
exits, any scripts waiting in the queue will exit instead of processing fstab again.
2. I removed the test for 98) # User-mode virtual block devices. If someone creates
one of these devices and it contains a file system, the section labeled
### Loop through block devices will pick it up.
3. Added ext4 to ext2|ext3) OPTIONS="${OPTIONS},relatime" ;; test.
4. blkid now only gets called once with a filtered device list to process.
For consistency, I cleared the cache and ran the script 3 times with a fixed delay
for each benchmark.
Timing on Dell E310 desktop TC10 x86
rebuildfstab from git, shebang changed to bash so it would run under TC10:
--- Code: ---tc@E310:~/rebuildfstab$ time sudo ./rebuildfstab.git; sleep 1; echo; time sudo ./rebuildfstab.git; sleep 1; echo; time sudo ./rebuildfstab.git
real 0m 1.02s
user 0m 0.18s
sys 0m 0.53s
real 0m 0.77s
user 0m 0.16s
sys 0m 0.37s
real 0m 0.83s
user 0m 0.15s
sys 0m 0.39s
--- End code ---
My version of rebuildfstab:
--- Code: ---tc@E310:~/rebuildfstab$ time sudo ./rebuildfstab.devlist; sleep 1; echo; time sudo ./rebuildfstab.devlist; sleep 1; echo; time sudo ./rebuildfstab.devlist
real 0m 0.48s
user 0m 0.04s
sys 0m 0.05s
real 0m 0.08s
user 0m 0.03s
sys 0m 0.04s
real 0m 0.13s
user 0m 0.03s
sys 0m 0.05s
--- End code ---
The execution times have improved over my previous version:
--- Quote from: Rich on March 05, 2023, 12:41:22 PM --- ... My version of rebuildfstab:
--- Code: ---tc@E310:~/rebuildfstab$ time sudo ./rebuildfstab.rewrite
real 0m 0.72s
user 0m 0.06s
sys 0m 0.12s
tc@E310:~/rebuildfstab$ time sudo ./rebuildfstab.rewrite
real 0m 0.16s
user 0m 0.09s
sys 0m 0.06s
tc@E310:~/rebuildfstab$ time sudo ./rebuildfstab.rewrite
real 0m 0.23s
user 0m 0.07s
sys 0m 0.11s
--- End code ---
...
--- End quote ---
A copy of the new version of the script is attached if anyone
wants to do any testing.
curaga:
Mostly looks good, but it was a bit buggy when I tested. zram0 and sr0 got added twice for me when testing on tc 13.x, and it added loops. This happened when the VM had no drives. I also still dislike the queue logic.
I edited it a bit, and made some other changes:
- comments should not be aligned like devices
- auto filesystems should still get a dir created
- the relatime line is unneeded nowadays
Please try the git version and see if it looks ok.
CNK:
One thing that I'd add is that if the rebuildfstab process crashes, or gets killed due to running out of RAM, the $TMP file will probably be left over. Then sometime later rebuildfstab could run again with the same process ID, and any fstab entries added before it died the previous time would be duplicated or incorrect in the final /etc/fstab.
So I suggest adding a line to delete $TMP at the start if it already exists. EDIT: Or use mktemp.
Otherwise it seems to run fine for me in some brief tests.
Rich:
Hi curaga
--- Quote from: curaga on March 11, 2023, 02:26:14 AM --- ... This happened when the VM had no drives. ...
--- End quote ---
Yes, I forgot if you pass blkid an empty $DevList it spits out every device it can find.
Thanks for piping blkid output into read. Don't know how I missed that. :-[
--- Quote --- ... comments should not be aligned like devices ...
--- End quote ---
I saw that the comment was present, but my brain didn't register that it was indented.
Now I understand why you added the "#"*) # Comments clause.
--- Quote --- ... auto filesystems should still get a dir created ...
--- End quote ---
Yup. casualty of refactoring the script so blkid would only need to be called once.
--- Quote --- ... Please try the git version and see if it looks ok.
--- End quote ---
Runs well. Looks good ...
--- Quote --- ... I also still dislike the queue logic. ...
--- End quote ---
It's atomic and it works, but OK.
However, I would like to point out I think this is kind of pointless:
--- Code: ---# If another copy tried to run while we were running, rescan.
if [ -e /var/run/rebuildfstab.rescan ]; then
rm -f /var/run/rebuildfstab.rescan
exec $0 "$@"
fi
--- End code ---
As far as I can tell, the only program that knows to check for /var/run/rebuildfstab.rescan
is rebuildfstab when it calls itself.
curaga:
Thanks CNK, added rm.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version