I have used a wine cork in seatpost to hold spare spokes, but the wine cork dried out and shrunk, thus I had to wrap some electrical tape around it to make it fit tighter.
I have put spare bolts in unused places, my Nomad Mk II has bolt holes on the fork for a bottle generator mount. I think my Sherpa does to, but it is in storage, I can't check it right now. But a 30mm spare is something I carry in my tool bag, not threaded into the bike somewhere due to the length. For example, one of my spares threaded into the bike somewhere is a shoe cleat bolt, much shorter.
But if you really wanted to make the bolt stronger, use a stronger steel bolt, which unfortunately might be more prone to rust.
Or, re-thread it to M6 if it is of that big a concern.
If a bolt breaks off, how are you going to get it out of the frame or fork. Where I can with an M5 bolt, I thread a pan head type bolt into the frame from the inside, then use a nylock nut on the outside to hold my rack on. If the bolt broke, then I still have the pan head side of the bolt on the inside of the frame. Unfortunately this will not work on the drive side for the lower rack mount on a Sherpa, as the bolt head could interfere with shifting the chain to or from the outermost sprocket.