Liu Yongfu was born on 10 October 1837, in the town of
Qinzhou (Ch'in-chou, ) in southern China, close to the Vietnamese border. Qinzhou, now in Guangxi province, was at that time in the extreme southwest of
Guangdong province. The ancestral home of Liu's family was the village of Popai in Guangxi province, and when he was eight his parents moved to Shangsizhou (Shang-ssu-chou, , modern
Shangsi, Guangxi) in Guangxi. Liu's family was poor, living by manual work for others, and was only just able to scrape a living. In 1857, Liu joined a local militia force commanded by Wu Yuanqing (Wu Yuan-ch'ing, ), who claimed to hold a commission from the Taipings. The
fall of Nanking (capital of Taiping Heavenly kingdom) and the collapse of the
Taiping Heavenly Kingdom in 1864 altered Liu's prospects dramatically for the worse. Imperial forces gradually began to reassert their control over southwest China, and it was only a matter of time before they secured Guangxi province. To escape their vengeance, Liu needed to make himself sufficiently powerful to give the Imperial generals pause. His first step was to buy some time by retreating into the mountains of northern Tonkin. In 1868 he abandoned Wu Yuanqing's rebels and crossed into Vietnam with a force of 200 soldiers whose loyalty he could trust. He had dreamed as a youth that he would one day become a famous 'General of the Black Tiger', and christened his tiny band of adventurers the
Black Flag Army,
Hēiqí Jūn (''hei-ch'i chun'', ). The Black Flags marched slowly through northern Tonkin, recruiting men to their standard as they went, and eventually set up camp just outside
Sơn Tây, on the northern bank of the
Red River. The mountain regions of western Tonkin were inhabited by minority tribesmen who did not acknowledge the writ of the
Vietnamese government, and these
montagnards resented the arrival of the Black Flag Army on Vietnamese soil. Fearing that Liu might eventually pose a threat to their own ascendancy in the area, they declared their intention of attacking the intruders. Liu struck first, however, and defeated a far stronger army of montagnards in a surprise attack. The short conflict enabled Liu to come to an early arrangement with the Vietnamese authorities, who had observed the performance of the Black Flag Army with great interest. The Vietnamese government, reasoning that it would be difficult to dislodge Liu from its territory and that he might also be a useful ally against the refractory montagnards, co-opted Liu into its service in 1869 and gave him military rank in the Vietnamese army. Provided that he continued to act in accordance with his technical status as a Vietnamese military governor, the Vietnamese authorities promised not to trouble the Black Flag leader. == Black Flags versus Yellow Flags ==