of the Tang ruling house, Li Yuan's seventh-generation ancestor was Li Gao, the Han Chinese founder of the Sixteen Kingdoms state Western Liang. After Western Liang's destruction, Li Gao's grandson Li Zhong'Er () served as a Northern Wei official, but for several generations after that, Li Yuan's ancestors had only minor military titles. Li Yuan's paternal grandfather Li Hu () served as a major general under Western Wei's paramount general Yuwen Tai, and was created the Duke of Longxi and given the Xianbei surname Daye (). Li Hu died before Yuwen Tai's son Emperor Xiaomin of Northern Zhou founded Northern Zhou, but was posthumously created the Duke of Tang after Northern Zhou's founding. His son and Li Yuan's father Li Bing (), of Han ethnicity, inherited the title of the Duke of Tang and married one of the Dugu sisters and daughter of the prominent Xianbei general Dugu Xin. Li Bing died in 572, and Li Yuan inherited the title of Duke of Tang, a title he continued to hold after the throne was seized by Emperor Wen of Sui (Yang Jian) in 581, establishing Sui Dynasty, as Emperor Wen's wife, Empress Dugu, was an aunt of his. At some point, he married Lady Dou, a daughter of Dou Yi () the Duke of Shenwu and Northern Zhou's Princess Xiangyang (Yuwen Tai's daughter) as his wife and duchess. During Emperor Wen's reign (581–604), Li Yuan served three terms as a provincial governor. Early in the reign of Emperor Wen's son Emperor Yang, Li Yuan served as commandery governor (as Emperor Yang converted provinces into commanderies), but was later recalled to serve as a junior minister within Emperor Yang's administration. When Emperor Yang carried out his second campaign against Goguryeo in 613, Li Yuan was in charge of part of the logistics operation. When the general Yang Xuangan rebelled near the eastern capital Luoyang, Emperor Yang commissioned Li Yuan as a general and made him be in charge of the operations west of the Tong Pass, although Yang Xuangan's rebellion eventually did not involve that region. Li Yuan took the opportunity to recruit talented people to his staff. Later that year, when Emperor Yang summoned him to his presence, he declined, citing ill health—an excuse that Emperor Yang did not believe, as he questioned Li Yuan's niece, Consort Wang (Emperor Yang's concubine), "Will he die?". In fear, Li Yuan took up