Context. The Rosetta and Giotto missions investigated the composition of the cometary comae of 67P/Churyumov-Gerasimenko and 1P/Halley, respectively. In both cases, a surprisingly large amount of molecular oxygen (O 2 ) was detected and was well correlated with the observed abundances of H 2 O. Laboratory experiments simulating chemical processing for various astronomical environments already showed that formation of solid state O 2 is linked to water. However, a quantitative study of O 2 formation upon UV photolysis of pure H 2 O and H 2 O dominated interstellar ice analogues is still missing. Aims. The goal of this work is to investigate whether the UV irradiation of H 2 O-rich ice produced at the earliest stages of star formation is efficient enough to explain the observed abundance of cometary O 2 . Methods. The photochemistry of pure H 16 2 O (H 18 2 O) as well as mixed H 2 O:CO 2 (ratio of 100:11, 100:22, 100:44) and H 2 O:CO 2 :O 2 (100:22:2) ices was quantified during UV photolysis. Laser desorption post-ionisation time of flight mass spectrometry (LDPI TOF MS) was used to probe molecular abundances in the ice as a function of UV fluence. Results. Upon UV photolysis of pure amorphous H 2 O ice, deposited at 20 K, formation of O 2 and H 2 O 2 is observed at abundances of, respectively, (0.9 ± 0.2)% (O 2 /H 2 O) and (1.3 ± 0.3)% (H 2 O 2 /H 2 O). To the best of our knowledge, this is the first quantitative characterisation of the kinetics of this process. During the UV photolysis of mixed H 2 O:CO 2 ices, the formation of the relative amount of O 2 compared to H 2 O increases to a level of (1.6 ± 0.4)% (for H 2 O:CO 2 ratio of 100:22), while the (H 2 O 2 /H 2 O) yield remains similar to experiments with pure water. In an ice enriched with O 2 (2%), the O 2 level increases up to 7% with regard to H 2 O, at low UV fluence, which is higher than expected on the basis of the enrichment alone. The resulting O 2 /H 2 O values derived for the H 2 O and H 2 O:CO 2 ices may account for a (substantial) part of the high oxygen amounts found in the comae of 67P and 1P.