If you want to start from first principals there's a pretty thorough paper here
There's a question here which is related Calculate covariance matrix from x,y,z data
And there's some pretty practical advice here: https://answers.ros.org/question/12642/calculating-covariances-of-robots-odometry/
Assuming you mean a LaserScan ROS message. It's possible to use the geometry of your robot and laser positions to create one ray per sensor in the laser scan. This is basically going to be a manual process to do this. You can see someone else working out the math here
There's a lot of questions on this already: https://answers.ros.org/question/348155/slam-...