**EDIT** Originally I claimed a more general statement and along the incremental generalizations I reached a statement that was not true. Thanks to Carlos for pointing out this error! So, I thought it would be fair to point out where the error lied.
The main issue is that the original proof works for a finite morphism, but not if there are exceptional divisors, because then on the target the localization would not happen at a height $1$ prime. In order to preserve the original proof, here is a fix that divides the statement into two parts.

## 0

By Stein factorization it is enough to prove the statement for finite or birational morphisms.

## 1

**Thm** Let $\pi:Y\to X$ be a separable projective finite morphism between normal varieties of the same dimension. Assume that $K_X$ is a $\mathbb Q$-Cartier divisor (i.e., there exists an $m\in \mathbb N_+$ such that $mK_X$ is a Cartier divisor). Then there exists an effective divisor $R\subset Y$ whose support is contained in the ramification locus of $\pi$ (that is, the complement of the largest open subset of $Y$ on which $\pi$ is smooth) such that
$$K_Y\sim \pi^*K_X + R.$$

**Proof:**

We need to prove that the divisor $\pi^*K_X-K_Y$ is linearly equivalent to an effective divisor supported on the exceptional locus . This can be done by localizing at height $1$ primes, so the question reduces to a question about regular schemes of dimension $1$. One may apply the usual proof of the Hurwitz formula:

Consider the short exact sequence $$0\to \pi^*\Omega_X\to \Omega_Y\to \Omega_{Y/X}\to 0$$
and observe that $\Omega_{Y/X}$ is a torsion sheaf whose support is the ramification locus (this is where you need that the map is separable), which in this case is the same as the exceptional divisor (the smaller parts of the exceptional locus disappear at the localization). This is a finite set, so $\Omega_{X/Y}$ maybe considered as the structure sheaf of a finite subscheme of $Y$. Let $R\subseteq Y$ be this subscheme. Tensoring the above short exact sequence by $\Omega_Y^{-1}$ gives:
$$ 0\to \pi^*\Omega_X\otimes \Omega_Y^{-1}\to \mathscr O_Y \to \mathscr O_R \to 0,$$
which shows that $\pi^*\Omega_X\otimes \Omega_Y^{-1}\simeq \mathscr O_Y(-R)$. This implies the needed linear equivalence.

To find the original $R$ all you need to do is to take the divisor that localizes to the $R$ we found in the $1$-dimensional case. Since we're talking about divisors the codimension $2$ ambiguity makes no difference.

## 2

**Thm** Let $\pi:Y\to X$ be a projective birational morphism between smooth varieties. Then there exists an effective divisor $R\subset Y$ whose support is the exceptional locus $E\subseteq Y$ of $\pi$ such that
$$K_Y\sim \pi^*K_X + R.$$

**Proof:**
Consider (again) the short exact sequence $$0\to \pi^*\Omega_X\to \Omega_Y\to \Omega_{Y/X}\to 0$$
and notice that $\pi$ is an isomorphism on $Y\setminus E$, so similarly $\pi^*\Omega_X\to \Omega_Y$ is an isomorphism there. Now take the determinant of these locally free sheaves and conclude that $\pi^*\omega_X\subseteq\omega_Y$ and $\omega_Y/f^*\omega_X$ is supported on $E$. This implies that the divisor $K_Y-f^*K_X$ is an effective divisor supported on $E$.

We need to prove that the support of $R$ is the entire $E$. For this, first notice that in order to prove the desired statement, using what we have proved already, we may pass to another birational model that dominates $Y$. (The point is that a $\pi$-exceptional divisor will be exceptional for the combined map to $X$ but not for the map to $Y$.) Second, a theorem of Zariski says that every exceptional divisor can be reached by a sequence of blow-ups (see Kollár-Mori98, 2.45). We know how to compute the canonical divisor of a blow-up and we know that the entire exceptional locus is contained in the discrepancy divisor, so the desired statement follows.

## 3

**Comment** The reason the second part requires smoothness is that one needs $\Omega_X$ to be locally free so when pulled back it would give the right thing. Otherwise it might pick up torsion or co-torsion. The statement is true in a little bit more general situation, if $X$ has at worst canonical singularities, but that is essentially the definition of those singularities and this statement says that smooth points are canonical, so it is a reasonable condition to use to define singularities.

divisoras you said it. 2) Damian, that's not true. The exceptional divisor is a well defined notion for any birational morphism, not just blow ups. (Then again, every projective birational morphism is a blow-up, at least locally). $\endgroup$ – Sándor Kovács Nov 7 '11 at 15:22DefLet $f:X\to Y$ be a birational morphism and let $Z\subset Y$ be the smallest (closed) subset such that $f$ is an isomorphism over $Y\setminus Z$. Then $f^{-1}(Z)\subset X$ is called theexceptional locusand its codimension $1$ part the exceptional divisor.RemThe exceptional locus maybe larger than the union of fibres of positive dimension, think of the normalization of a singular curve. Also, the exceptional locus maybe larger than the exceptional divisor. For this, you need to go to dimension $3$ or higher. $\endgroup$ – Sándor Kovács Nov 7 '11 at 15:24exceptional divisorsare defined in general. Then again, if you look at my answer below you'll see that the statement is true in more generality in which case this distinction is important. I had that in mind when I wrote this comment. Cheers! $\endgroup$ – Sándor Kovács Nov 7 '11 at 16:194more comments