At the time of the October revolution, the Bolsheviks were not at all popular, particularly in comparison to the Mensheviks, so how did they manage to form a government with such little public support and divisions within the party, and go on to rule the country with great popularity for a number of decades?
Whoah there. The Bolsheviks were plenty popular before the revolution. That's pretty much why they ended up in power. It was afterwards that the dip occurred.
By October 1917 the Bolsheviks were by some distance the most popular party in urban Russia. From July onwards their popularity surged amongst the workers as the economic conditions worsened, the country radicalised and the Provisional Government floundered. In these months they took control (via elections) of a host of soviets and commanded a majority of delegates to the Second Congress of Soviets (which formally endorsed the seizure of power). They also tended, in Petrograd at least, to dominate the trade union and factory committee movements. So in urban centres they were the only real show in town in late summer 1917.
Amongst the peasants (and soldiers) the picture was more mixed. The closer a village or front was to a large urban centre then the more popular the Bolsheviks were. But generally they had little presence throughout most of the countryside, where the Socialist Revolutionaries held sway as the traditional peasant parties.
This picture is reflected in the voting to the Constituent Assembly in Nov 1917. The Bolsheviks swept almost every urban centre and did okay amongst the peasants - 24% of the vote is actually pretty good for an almost exclusively urban party with an almost exclusive focus on the workers.
(The Mensheviks in comparison picked up a mere 3% of the Constituent Assembly vote and had only 72 delegates, to the Bolsheviks' 390, to the October Congress of Soviets.)
So by the time of the Revolution the only two parties that mattered were the Bolsheviks and the Left SRs [1]; not coincidentally these were the only two that unreservedly supported immediate land reform in favour of the peasants and the transfer of power to the soviets.
Bolshevik popularity did drop in 1918 as the economic turmoil continued and the party shifted its attention from winning votes to official Soviet work. There were revolts and there were Menshevik attempts to agitate but judging popularity becomes difficult. Partly that's due to increased use of repression but also because the Civil War made such questions somewhat redundant. Popularity fades in importance when the choice is supporting the Soviet or the restoration of White rule. A lot of populations and former rivals rallied to the Red cause simply because the alternative was judged to be worse.
I'll stop there for now because into the NEP and Stalinist periods questions of support/popularity become both more difficult and less important. Less important because by this point the regime was not based on democratic elections and more difficult because there's no clear answer as to what degree the Stalinist dictatorship relied on mass support. There's a range of academic opinions on this: from 'people chaffing under a totalitarian state' (Pipes) to 'widespread acceptance of Soviet civilisation' (Kotkin). But if you want then I'm happy to go on.
[Edit: Just as a postscript, it's worth noting that all the above stands in opposition to the traditional view (as espoused by, say, Richard Pipes) of the October Revolution as the actions of a small band of isolated intellectuals. To my mind that's been unsustainable since Rabinowitch's research in the 1970s, at the latest. Bolshevism in 1917 was a mass movement that came to power precisely because it was popular.]
[1] The Soviet Revolutionaries split into Left and Right factions during the Second Congress in October 1917. The Left allied with the Bolsheviks in transferring power to the soviets, the Right walked out. Both were ultimately subsumed by the Red and White movements, respectively.
Annoyingly for us, the ballot papers for the Constituent Assembly elections had already been printed at this point, so the split wasn't reflected on the ballot and there's no way of knowing for sure which faction was the most popular at the time. However subsequent events (and the massive popularity of the Soviet Decree on Land) strongly suggests that the Left were significantly more aligned to the peasant masses than the Right leadership.