A search is presented for pair production of the standard model Higgs boson using data from proton-proton collisions at a centre-of-mass energy of 13~\mathrm{TeV}, collected by the CMS experiment at the CERN LHC in 20162018, corresponding to an integrated luminosity of 138~\mathrm{fb}^{-1}. The final state consists of two b quark-antiquark pairs. The search is conducted in the region of phase space where at least one of the pairs is highly Lorentz-boosted and is reconstructed as a single large-area jet. The other pair may be either similarly boosted or resolved, the latter reconstructed using two b-tagged jets. The data was found to be consistent with the measured standard model processes. Limits in the range 9.740.29~fb and 4.940.19~fb were set on the product of the cross sections and the branching fractions of the spin-0 radion and the spin-2 bulk graviton with a mass of 13~\mathrm{TeV}, respectively, in the context of warped extradimensional models.