The genpkey command can create other types of private keys - DSA, DH, EC and maybe GOST - whereas the genrsa, as it's name implies, only generates RSA keys. There are equivalent gendh and gendsa commands.
However, the OpenSSL documentation states that these gen* commands have been superseded by the generic genpkey command.
In the case of your examples, both generate RSA private keys.
openssl genrsa -out genrsa.key 2048
and
openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out genpkey.key
will generate a 2048 bit RSA key with the exponent set to 65537.
Simply cat the resulting files to see that they are both PEM format private keys; although openssl rsa encloses them in BEGIN RSA PRIVATE KEY and END RSA PRIVATE KEY while openssl genpkey omits the RSA. The former is PKCS#1 format, while the latter is PKCS#8.
Running openssl rsa text -in <filename> against both shows that they are RSA private keys with the same publicExponent. The newer genpkey command has the option to change this using -pkeyopt rsa_keygen_pubexp:value while the genrsa command doesn't have this option.
genrsa(and alsorsa) and 'new' (since about 2000) PKCS8 format written bygenpkey(and alsopkeyandpkcs8 -topk8); although they contain semantically the same information they are not the same and the PEM labelRSA PRIVATE KEYvsPRIVATE KEYis very important. Also if they are password-encrypted (your example is not) the PBE used is very different (PKCS8 is better). There is no commandlinegendh-- and EC-specific gen is inconsistentlyecparam -genkey! – dave_thompson_085 Jan 10 '18 at 08:14gendhis listed as an option toopenssl help. That's as far as I've tried it though! – garethTheRed Jan 11 '18 at 06:23gendhandgendsagenerate parameters (aka groups) not keys, equivalent to new-stylegenpkey -genparam;dsaparam -genkeyandecparam -genkeygenerate keys for given parameters but there is no old-style way to generate a DH key (for any parameters), only new-stylegenpkey(without-genparam) can do a DH key. – dave_thompson_085 Jan 11 '18 at 09:43