WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Tinkering with rebuildfstab  (Read 3817 times)

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11179
Re: Tinkering with rebuildfstab
« Reply #30 on: March 10, 2023, 10:37:03 PM »
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: [Select]
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

My version of rebuildfstab:
Code: [Select]
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

The execution times have improved over my previous version:
... My version of rebuildfstab:
Code: [Select]
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
...

A copy of the new version of the script is attached if anyone
wants to do any testing.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 10957
Re: Tinkering with rebuildfstab
« Reply #31 on: March 10, 2023, 11:26:14 PM »
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.
The only barriers that can stop you are the ones you create yourself.

Offline CNK

  • Full Member
  • ***
  • Posts: 234
Re: Tinkering with rebuildfstab
« Reply #32 on: March 10, 2023, 11:45:41 PM »
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.
« Last Edit: March 10, 2023, 11:50:42 PM by CNK »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11179
Re: Tinkering with rebuildfstab
« Reply #33 on: March 11, 2023, 09:06:47 AM »
Hi curaga
...  This happened when the VM had no drives. ...
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 ...
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 ...
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.
Runs well. Looks good ...

Quote
... I also still dislike the queue logic. ...
It's atomic and it works, but OK.

However, I would like to point out I think this is kind of pointless:
Code: [Select]
# 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
As far as I can tell, the only program that knows to check for  /var/run/rebuildfstab.rescan
is  rebuildfstab  when it calls itself.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 10957
Re: Tinkering with rebuildfstab
« Reply #34 on: March 11, 2023, 09:25:32 AM »
Thanks CNK, added rm.
The only barriers that can stop you are the ones you create yourself.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11179
Re: Tinkering with rebuildfstab
« Reply #35 on: March 12, 2023, 10:10:30 AM »
Hi curaga
Found a bug.
Changed:
Code: [Select]
mkdir -p "/mnt/$DEVNAME" 2>/dev/null >/dev/nullTo:
Code: [Select]
mkdir -p "$MOUNTPOINT" 2>/dev/null >/dev/nullIn 2 places. Only the second instance caused an error, but both should
be using  "$MOUNTPOINT"  just like the  printf  statements do.

Pull request created.

Quick question. I logged into github and clicked on  Sync fork  so my
copy matches the Tinycore copy.

Locally, I have this:
Code: [Select]
c@E310:~$ cd TC-Git/
tc@E310:~/TC-Git$ ls -l
total 12
-rw-r--r-- 1 tc staff  170 Feb 28 13:13 CloneCommands.txt
drwxr-sr-x 9 tc staff 4096 Feb 28 13:39 Core-scripts/
-rwxrwxrwx 1 tc staff 1927 Mar  1 20:31 depends-on.sh
tc@E310:~/TC-Git$ git clone https://github.com/rarost/Core-scripts.git
fatal: destination path 'Core-scripts' already exists and is not an empty directory.
tc@E310:~/TC-Git$
I deleted  Core-scripts/  and ran  git clone https://github.com/rarost/Core-scripts.git
again and made my changes.

What command should I have run to make my local copy match my copy on github?

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 10957
Re: Tinkering with rebuildfstab
« Reply #36 on: March 12, 2023, 10:29:46 AM »
"git pull" should be enough. Merged.
The only barriers that can stop you are the ones you create yourself.