This is based entirely off @Firelord's comment, with some modifications, so all credits go to him.
First things first, the stock ROM is not as such stored anywhere on device in a form which the device can use to recover itself in case of some catastrophic software failure, such as a botched OTA.
Now, as to how stock ROMs are stored for distribution, that is an entirely different issue. The method of ROM distribution or loading onto devices vary from OEM to OEM, even carrier to carrier. We find 3 common types of ROM distributions:
ROM image files (700-1400MB): These are like Windows System Images, as such being a logical bit-for-bit copy of an on-device partition, which can be written to the device's NAND storage by a flashtool such as fastboot
, nvflash
or SPFT, while the device is tethered to a PC/Mac. These are usually distributed as archives, but cannot be flashed as such, they need to be decompressed separately before flashing.
ROM zip files (250-600MB): These are also system images in essence, but they are compressed and lack some model-specific or device-specific partition images to lower distribution size as these are installed, in compressed form, on-device via the device's recovery. Some manufacturers do this, but this is commonly the distribution format for custom ROMs.
ROM OTA zip files (4-200MB): These are like ROM zip files, but instead of having all the system images in the zip, these contain image patch files. They are also installed via recovery. This method helps in reducing update file size to meagre amounts when major system changes are not involved in the update.
When we talk about custom ROMs, only methods 2 and 3 are important. Only some for some Cyanogen OS devices does CyanogenMod provide ROM images for fastboot
flashing.
Well, now you could wipe your device's /system
partition, but note that while installing the custom ROM you already did that, and so there isn't a stock ROM on device to speak of. Wiping /system
now would remove your custom ROM which you had installed, and then you would have to flash either a stock or custom ROM to make the device usable again.
Note something here: Stock recoveries cannot flash custom ROMs as the custom ROMs do not have the digital signatures that the recovery verifies before flashing them.
Similarly, custom recoveries such as CWM or TWRP cannot flash stock ROM zips as the zip checks for the integrity or stock nature of the device, which has been compromised by the presence of the custom recovery itself.