LinuxCNC M2

M2 is a G-code program end command in LinuxCNC. It terminates the program and returns the machine to a defined modal state: Auto mode changes to MDI, offsets and plane reset to defaults, distance mode becomes absolute, feed mode becomes units per minute, overrides are enabled, cutter compensation is cancelled, the spindle stops, motion mode becomes feed, and coolant turns off. Pressing Cycle Start restarts the program from the beginning of the file.

Source checked3/3 values · 2026-10-26

Specification

1 source
Languagegcode
CodeM2
GroupProgram End
SyntaxM2
DialectLinuxCNC

Study notes

  • Pressing Cycle Start ("R" in the Axis GUI) restarts the program at the beginning of the file.
  • M2 changes the machine from Auto mode to MDI mode.
  • Origin offsets are set to the default (like G54).
  • Selected plane is set to the XY plane (like G17).
  • Distance mode is set to absolute mode (like G90).
  • Feed rate mode is set to units per minute (like G94).
  • Feed and speed overrides are set to ON (like M48).
  • Cutter compensation is turned off (like G40).
  • The current motion mode is set to feed (like G1).
  • Coolant is turned off (like M9).

Safety

  • Lines of code after M2/M30 will not be executed; pressing Cycle Start will start the program at the beginning of the file.
  • Using % to wrap the G-code does not do the same thing as a Program End; see the File Requirements section.
  • The spindle is stopped by M2 (like M5).
↑↓ navigate↵ openesc close