If I move the data file of M1 to a safe place (outside directories of M1). How to config to make both M1 and M2 connect to those data to use those shared data?
The data file? If you're referring to the H2 database that's used by default, then stop now!
Migrate to a proper database before you lose all your work. Preferably Postgres, through MySQL is supported too.
You can't have two servers sharing an H2 database. It's only there to get you started.