Step 1: Read the sentence.
When the principal entered the class, a student ____ on the blackboard.
Step 2: Find the time anchor.
The word entered is simple past, so the whole scene sits in the past.
Step 3: Remove present-tense options.
writes and is writing are present forms, which clash with the past setting, so options C and D go out.
Step 4: Compare the two past forms.
wrote is simple past for a finished action, while was writing is past continuous for an ongoing action.
Step 5: Decide which action is ongoing.
Writing on the board was already in progress when the principal entered at one sharp moment, so the longer action needs past continuous.
Step 6: Conclude.
The student was writing when the principal entered, option B.
\[ \boxed{\text{B. was writing}} \]