We report a method of efficiently generating ultracold hydrogen molecular ions HD+ in a segmented linear ion trap. HD+ ions are created by [2+1′] resonance-enhanced multiphoton ionization (REMPI) of an HD supersonic molecular beam, and sympathetically cooled by laser-cooled Be+ ions. The HD+ ions are generated species-selectively using 201 nm and 395 nm pulse lasers with energies of 0.08 mJ (5.1 × 106 W/cm2) and 1.5 mJ (9.5 × 107 W/cm2) respectively. The average loading rate of 4.3(2) HD+ ions per second in the ion trap is determined by comparing the experimental images with the simulated images of Be+-HD+ bi-component Coulomb crystals. This method paves a way to produce the state-selected HD+ ions, which can improve the signal strengths of the selected rovibrational transitions of HD+ ions.