Bali had a hundred sons, the eldest among whom was Vana. Vana was devoted to Shiva. He was also extremely powerful. He defeated Indra and conquered the three worlds.
Indra and the other gods went to Shiva. “Your devotee, Vana is oppressing us,” they told Shiva. “Please take care of him.”
Shiva took up a single arrow and with this, he completely burnt up Vana’s city.
(This is deviation from the usual account of the Puranas, such as the Vishnu Purana or the Bhagavata Purana. In those accounts, Krishna fought with Vana and defeated him, although Shiva fought on Vana’s side. It was because of Krishna’s blessings that Vana became Shiva’s companion. Vana’s capital was named Shonitapura.)
When Vana’s city was being burnt up, Vana emerged and started to pray to Shiva’s linga (image of Shiva). Pleased at Vana’s prayers, Shiva made Vana a ganapati. Thus, Vana came to be Shiva’s constant companion.