Holding the United Kingdom together will be an "enormous challenge", Britain's most senior civil servant has warned.

Cabinet Secretary Sir Gus O'Donnell said the question of whether the UK stayed together would be a major issue in the coming years.

His warning, on the eve of his retirement at the end of the year, comes as the SNP administration in Scotland is committed to holding a referendum on independence before 2016.

Writing in The Daily Telegraph, Sir Gus said: "Over the next few years, there will be enormous challenges, such as whether to keep our kingdom united."

Sir Gus said the Civil Service needed to overcome its "cultural inertia" and take a leading role in driving economic recovery.

"It is not enough now for the Civil Service simply to respond to a dampened economic climate: it needs to become a central part of its recovery and growth," he wrote.

In his article, Sir Gus also said he believed successive governments had been too quick to address problems with regulation and legislation.

He encouraged ministers and civil servants to be more creative in solving problems, urging them to take more risks and have a "grown-up approach to failure".

He said civil servants had risen to a challenge set out by the Prime Minister to do away with unnecessary regulations, having recommended scrapping more than half of the 1,200 rules they had looked at so far.

Sir Gus also wrote of his pride over the "thorough, evidence-based analysis" carried out under the last government, which resulted in Britain staying out of the euro.

"Without that, the challenge would be substantially greater," he added.

Earlier, in an interview for Channel 4 News, Sir Gus disclosed that Whitehall had carried out contingency planning in case the coalition breaks up - although he said he believed it would run its full course to 2015.

"My reading of the coalition, the relationship between the Prime Minister and the Deputy Prime Minister, is that is probably when the next election will be," he said.

"You have to do contingency planning, but I think our main scenario is that we go through to 2015."

Scotland's First Minister Alex Salmond said: "I have always regarded Sir Gus O'Donnell as a model civil servant, who has been extremely fair in recognising and respecting the democratic mandate of the Scottish Government.

"Sir Gus is right to recognise the importance of the constitutional issue, and the SNP Government are up for the challenge of building and winning the case for Scottish independence - unlike the Westminster parties, who seem to have their heads buried in the sand."

Former Liberal Democrat leader Sir Menzies Campbell, who is chairing a party commission on the question of home rule - rather than independence - for Scotland, said: "The Cabinet Secretary's prediction is by no means certain, but it is essential that those who acknowledge the importance of the Union start to make the argument for it more vigorously than before.

"It is nonetheless clear that as the three devolved legislatures in Scotland, Wales and Northern Ireland become bedded down, a new constitutional settlement for the whole of the UK will be required."

It will be necessary not only to solve the famous "West Lothian Question" over whether Scottish MPs should legislate on laws which do not affect Scotland, but also similar quandaries relating to Wales and Northern Ireland, said Sir Menzies.

First Minister of Wales Carwyn Jones said he wanted Wales to continue to be an "integral part" of both the UK and the EU.

However, he added: "While the Prime Minister says he is committed
to keeping the United Kingdom together, his decision to exclude the devolved administrations from policy development and decision-making on European matters that are of direct interest to their respective administrations, is not helpful.

"It's absolutely crucial the UK Government is both sympathetic and supportive of devolution, otherwise, it undermines the position of those of us who wish to keep the UK together."