1. Disconnect the negative battery cable.
2. Remove the headliner.
3. Disconnect the connector.
4. Remove the screws, and then remove the sunroof motor.

Sunroof unit disassembly/assembly
Sunroof motor installationMazda 6 Service Manual: General procedures
PRECAUTION (FRONT AND REAR AXLE)
Wheel and Tire Removal/Installation
1. The removal and installation procedures for the wheels and tires are not
mentioned in this section. When a wheel is removed, tighten it to 88-118 N·m
{9.0-12.0 kgf·m, 65.0-87.0 ft·lbf}
Brake Line Disconnection/Connecti ...
Mazda 6 Service Manual: Keys
WARNING
Do not leave the key in your vehicle with children and keep them in a place
where your children will not find or play with them: Leaving children in a
vehicle with the key is dangerous. This could result in someone being badly injured
or even killed. Children may find these keys to be ...