Building Custom Bootloaders
Here are a couple sources of ATmega328PB bootloaders based on optiboot:


https://github.com/watterott/ATmega328PB-Testing
https://github.com/ElektorLabs/Arduino


I haven't used either.
If you are set on making your own at least they can provide you with a reference.