Ubuntu 18.04 came out April 26, 2018 and I want to try it to upgrade my programs and convert my data but don't want to commit if there are bugs.
I've shrunk Windows from 410 GB to 385 GB, rebooted Ubuntu 16.04 and ran gparted
to create a new 25 GB partition labeled "Ubuntu18.04". I ran rm-kernels
and removed about 20 kernels to eliminate about 10 GB on Ubuntu 16.04.
Now I want a script that will populate the new partition with 16.04 LTS and create a new Grub menu option to it. Only relevant directories should be copied. For example /sys
, /run
, /proc
and /dev
are virtual directories created during boot and shouldn't be copied.
I also want /etc/fstab
patched with the correct UUID and cron
reboot jobs disabled such that daily backups on cloned data isn't run after booting the clone.
I anticipate running the script many times over the next few weeks/months. As such the cloning process should effortlessly repeatable.
The same script could be used for testing security updates and new Ubuntu Kernel Team updates without effecting production systems.
Bash script to clone active Ubuntu Partition to clone partition
The
clone-ubuntu.sh
bash script will seamlessly and safely replicate 16.04 LTS into a partition for upgrading to 18.04 LTS:Important points to consider:
ext4
partition large enough to hold a Ubuntu 16.04 cloneclone-ubuntu.sh
the partition cannot be mounted. The script automatically mounts and unmounts the partition.rsync
is used to copy files from/
to the clone partition. The first time you runclone-ubuntu.sh
it will take a few minutes. The second time you run the script only file changes are updated and it should take less than a minute./
files & directories./etc/cron.d
(reboot) jobs are moved to a new sub-directory called/etc/cron.d/hold
. After booting clone remember to runsudo crontab -e
to prevent selected cron jobs from running./etc/fstab
is modified with the appropriate UUID for the partition it is on./boot/grub/grub.cfg
is modified with the appropriate UUID for successful clone booting. The cloned file'squiet splash
is changed tonosplash
so you get scrolling terminal messaging. This gives visual awareness booting a clone rather than "Real" version.update-grub
is run to update Grub with new menu options pointing to the cloned partition./etc/update-manager/release-upgrades
is modified to changePrompt=never
toPrompt=lts
. When you boot the clone and performdo-release-upgrade -d
this allows Ubuntu 16.04 to be upgraded to 18.04.Confirmation Screen
After selecting a target clone partition it is first verified to be
ext4
partition type and is not already mounted. If this test is passed, a confirmation message then appears:In this example a previous clone has been selected for recloning. The available space on the clone is a mute point because we already know there is enough space available.
If you have multiple Ubuntu installations, please verify you have selected the right partition to clone the currently booted Ubuntu, mounted as
/
(root), to.This is your last chance to abort by pressing any key except
y
orY
.Output listing
When you run the script you will get this output (excluding the output already listed above):
rsync
status display for new cloneWhen cloning for the first time,
rsync
will give an update from 0 to 100% of all files created. No files will be deleted or changed as the clone is empty:rsync
status display when recloningWhen
rsync
reclones it never hits100%
because files that never changed are not copied. There will be delays in the update progress asrsync
scans for the next file to be copied and when it deletes new files created in the clone that never existed in the original:Bash script -
clone-ubuntu.sh
Copy and paste the bash code above to a new file called
/usr/local/bin/clone-ubuntu.sh
. Then make the new file executable using:To call the script use:
How to upgrade 16.04 LTS clone to Ubuntu 18.04 LTS
This is a "bonus" section that may interest many people.
Reboot your machine. The
grub
menu will contain a new menu option pointing to the cloned partition. You can also select a specific kernel version from the clone's Advanced Options menu.One way to convert the cloned 16.04 LTS to 18.04 LTS is to run:
Note the
-d
flag was required prior to July 26, 2018 but is no longer necessary.Read the 18.04 upgrade confirmation carefully.
Before proceeding ensure inactive screen locking is turned off. The upgrade process could crash if your computer goes to the lock screen due to keyboard inactivity.
Summary of 18.04 upgrade process
This section will be machine specific because different apps are installed by different users. Here is a brief summary I made based on notes and memory:
Note step 10 most people will never see. I have an old nVidia driver installation on my Ubuntu 16.04 I never got around to fully removing. It's included because you might have similar old packages never fully removed.
Grub changes boot menu to clone under UEFI
Unlike 18.04 upgrades I found the 18.04.1 upgrade changed the Grub UEFI configuration to use the clone's grub menu instead of the original grub menu as per this answer: Dual boot and the files /boot/grub/grub.cfg -- which one is used?
Running
sudo update-grub
after booting the original partition isn't enough to change whichgrub.cfg
is loaded by grub. You need to usesudo grub-install
to force grub to use the original partition's configuration.Both the original partition and clone partition can use
update-grub
to maintain their own/boot/grub/grub.cfg
file but only one can be used during boot.Of course if you want grub to use the Clone's grub menu do not do the above steps on the original's partition.
Edit history
Edit May 6, 2018 - Information display for an empty clone (target) partition corrected.
Edit August 26, 2018 - Use
--inplace
option withrsync
so large files such as a 2 GB trash file are not duplicated on clone during copy process. This can lead to "out of disk space" error. Comment out/etc/cron.d
overrides because users may want to keep or want a different directory altogether. Update instructions to usedo-release-upgrade
without-d
flag because Ubuntu 18.04.1 LTS is now released.Problems with upgrading from previous releases to 18.04 LTS
It is not at all straightforward to upgrade from previous releases to 18.04 LTS. I don't know if there are more problems than such upgrading in the past, but people who do release upgrading now take a risk for themselves. On the other hand they find bugs and if the bugs are reported, it will help develop the upgrading tool as well as debug the Ubuntu 18.04 LTS system itself.
This means that people who are patient enough to wait until the upgrading is officially released with the first point release (18.04.1 LTS) will get a smoother ride.
Testing before doing the full upgrade ...
The method that @WinEunuuchs2Unix describes here makes it possible to test with a copy of the real system, if upgrading to 18.04 LTS will work with your current [more or less modified] operating system with your computer hardware.
This can prevent several disasters with corrupted operating system.
I have not used @WinEunuuchs2Unix's script yet, but I understand, that it is very useful, and I intend to use it. I was able to upgrade from 8.04 to 10.04 to 12.04, which I used for a long time. But when I set out to upgrade via 14.04 to 16.04 I failed and could not find the errors.
... and if problems, make a fresh installation
I had good backups, so I made a fresh install of 16.04 and later on copied, what I wanted to keep and checked for tweaks, scripts, aliases and installed programs. If I had used @WinEunuuchs2Unix's method I had seen the problem early, I would have made a fresh install directly.
Upgrading a persistent live system
Persistent live systems are used to get very portable Ubuntu systems, that are sometimes used for testing but sometimes used for a long time.
It is a known problem, that you should not update & upgrade such a system like you do with an installed system because it will get corrupted sooner or later. Furthermore, you are stuck with the kernel and kernel drivers, that come with the iso file, because they are started before the overlay system is started.
But it is usually possible to keep the
/home
directory, like you can, when you make a fresh installation with a separate 'home' partition. If you create ahome-rw
partition, a persistent live system will find and use it automatically during boot.I am developing and testing a shellscript, mk-persistent-live_with_home-rw, that can create a persistent live system with a
home-rw
partition, and that can later upgrade it,replace the iso file with a newer one. At least you should upgrade when a new iso file is released, but you can also upgrade an LTS system once a month and use the current daily iso files from the testing tracker,
modify grub for the new iso file.
wipe (reformat) the
casper-rw
file which stores the modifications of the operating system (so you must re-install the program packages that you added to the system),preserve the
home-rw
partition with your personal files, settings and tweaks.See this link for more details.
Extra link
General tips for people who want to test the latest and greatest version of Ubuntu can be found in the following link,
How to participate in testing and development of Ubuntu