If your buck mode is most efficient you should go from higher voltage to lower. If boost is most efficient just the opposite.
Check the voltage inside the PI. I think internally it only needs 3V3. At least 90% runs of 3V3 if I remember correctly. Thus you are having 5V capacitors which discharge. You boost to 5V which then inside the PI gets converted back to 3V3: not ideal!
For Linux shutdown you can ignore everything which is 5V anyway as only the CPU and DRAM need to keep working and that is all 3V3.
Oh! and the SDCARD, also 3V3.
Post edit.
Assuming the CPU etc. need 3.3V, add internal Pi regulator voltage drop ~200mV. Use your 2 seconds run time: Then you external voltage can drop from 5V to 3.5V in two seconds. Using @ Spehro Pefhany formula gives you ~0.33F
without need for a buck/boost converter. I would take one a bit bigger as we used a number of estimated values.
Be aware that when you switch the 5V supply on, those capacitors will need to charge and look almost like a short circuit for a while. Your 5V supply might not like that. You can work around that by adding an R plus parallel diode in series with the cap, but that gives an additional voltage drop which you have to compensate for.