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: System Operation
Make sure that the Lane-keep Assist System (LAS) & Lane Departure Warning System
(LDWS) OFF indicator light in the instrument cluster is turned off. When the Lane-keep
Assist System (LAS) & Lane Departure Warning System (LDWS) OFF indicator light is
turned on, press the switch and make ...
Mazda 6 Service Manual: Driving Tips
WARNING
Do not let the vehicle move in a direction opposite to the direction selected
by the selector lever: Do not let the vehicle move backward with the selector
lever in a forward position, or do not let the vehicle move forward with the selector
lever in the reverse position. Otherwise, t ...