Outils pour utilisateurs

Outils du site


issue121:tutoriel2

Ceci est une ancienne révision du document !


Installing Ubuntu is not a complex process these days. Downloading an ISO image, and alternatively burning a DVD or creating a bootable USB to launch a LiveCD that can then be installed, is a well-documented process. Looking back at earlier times, this was not always the case. Many of us can still remember when the Knoppix CD was the first GNU/Linux distribution that could actually launch a live environment, and it was still some time after that until the first installable LiveCD images came out. So it can be said that much progress has been made on the ease-of-use of installation media.

However, we are never satisfied. Having to burn the image to a CD or DVD just to test out a new distribution soon lost its attractiveness. Using an USB pendrive was a move in the good direction, but nowadays one does not always have a spare pendrive lying around. I tend to lose mine, and think I may possibly not be the only one. Most administrators of large networks soon learn to make an ISO image available to boot over the network using PXE, but this may not always be possible, or even attractive, for more casual users, since it does mean messing around with your local DHCP server.

So, what if we went one step further and did away completely with an installation medium? The scenario is as follows: suppose we have a functioning Ubuntu installation on a computer, at a certain version of the distribution. We then download a new version as an ISO file to our hard drive, and wish to install the new version over the existing one, without using any other local drives, an optical reader, or anything else connected via USB. It’s just us, and our computer’s single internal hard drive.

A point to be noted is that we will be needing sufficient RAM to hold most of the ISO image as well as running the Live CD environment, so our computer will be best off with at least the 4 GigaBytes memory size that has been standard for laptops for some time now.

Read on, dear reader, and find out how. Though, be warned: things will likely get fairly geeky at times. Do not try this on a computer you would not be happy to format completely, and make a backup of any user data before proceeding. Qapla'!

I started out with a very slightly tweaked installation of Ubuntu 14.04. Partitioning of the hard drive was left to the Ubuntu installer’s default settings, and as a result we ended up with only two partitions:

/dev/sda1 (ext4 file format) containing both the operating system and user data;

/dev/sda2 as a swap space.

The only main changes done to the system configuration are user preferences such as the WiFi network, Firefox browser history, and the desktop background. It would be nice to retain these, as well as any user files on the hard drive.

I then downloaded a more recent version of Ubuntu, ISO file: “ubuntu-16.10-desktop-amd64.iso”, to directory /home/alan/Downloads. (That version is no longer current, but the procedure remains the same.)

Booting from an ISO image

The first major challenge in this project is to boot from the ISO file image on our hard drive. Luckily, GRUB is well able to do this - with some persuading from the command-line. However, when a single Ubuntu system is installed on a drive, then, when booting, the default GRUB configuration times out and immediately launches the only operating system it sees. We will need some time to enter GRUB command-line mode. To solve this problem, edit the default configuration file using:

sudo gedit /etc/default/grub

commenting out or erasing the line that starts with GRUB_HIDDEN_TIMEOUT . This configuration then needs to be put in place with command:

sudo update-grub

We can then reboot. Once the GRUB menu comes up, hit key ‘c’ to obtain a command-line that starts with the ‘grub>’ prompt.

We now need to tell GRUB to use the first partition of our hard drive as its boot drive. We then tell it to identify the ISO filename in variable $isofile. We create a loopback drive with the filename, which basically sets up the file as a virtual disk drive. We then load the Linux kernel and the initial RAM disk. So, successively:

set root=(hd0,msdos1)

set isofile=/home/alan/Downloads/ubuntu-16.10-desktop-amd64.iso

loopback loop (hd0,msdos1)$isofile

linux (loop)/casper/vmlinuz.efi ro boot=casper iso-scan/filename=$isofile toram

initrd (loop)/casper/initrd.lz

boot

Naturally, these commands may need to be tailored to suit your specific setup, both as regards the partition on which the ISO file is located, and concerning the filename and directory. Please take extra care to append parameter ‘toram’ to the line loading the kernel - this shall be explained further on.

We should boot successfully into the LiveCD environment. Depending on the speed of our hard drive, boot times should compare favourably with that of booting from a USB pendrive and, obviously, without the hassle of actually creating the USB drive in the first place.

If all we need is to test the new distribution, then this is it. We can use the Live CD environment exactly as we would if we had booted from a DVD or a pendrive, and without altering the configuration of our hard drive.

But, since we wish to install the new system onto our hard drive, some tweaks need to be applied. The main question that needs to be addressed is the fact that the Unity installer, Ubiquity, does not like to modify a partition on a disk drive that it has booted from - and our ISO image is contained within the same partition /dev/sda1 which we will now be modifying.

Now, the parameter ‘toram’ appended to the kernel in GRUB comes to the fore. This parameter told the kernel (through the Casper boot hook) to load the complete ISO file into RAM during boot. It is for this reason that we need a bit more RAM available to us than would normally be required to boot a Live CD. The time taken to load the file into RAM also explains why the boot process may seem slightly slower than expected if our computer has a fast SSD hard drive.

However, even though the ISO file’s contents have been loaded into RAM, the file itself is still left mounted on the directory /isodevice. This needs to be unmounted with the command:

sudo umount /isodevice

before proceeding. We can check that no other disks have been left mounted with the command:

mount | grep sd

We should see one single line reporting on gvtsd-fuse, and nothing more. Once this is the case, we can proceed with system installation in the usual way. The one caveat is concerning disk partitioning. To retain user files, it is best to select ‘Something else’ and partition the hard disk manually. In my (very simple) situation, I will choose /dev/sda1, use it as an extended 4 file system mounted on /, but NOT format it. In essence, I am retaining the very same partitioning scheme used before.

Since we are not formatting the partition destined for installing the operating system, the installer will complain about this and tell us that “Directories containing system files (/etc, /lib, /usr, /var, …) will be deleted during the install.” This is fine with us, since user data is contained within /home.

If I were using a separate /home partition, I could tell the installer to mount it on /home, but obviously not to format it either. In either case, using the same user accounts’ names will enable us to find our files back in the same places and accessible on the new system.

We can proceed with installation and, once finished, reboot as usual. As can be seen, all our user preferences and files - such as the desktop background - have been carried over. For whatever reason, the only element that was not preserved was the configuration for WiFi, which needed to be created anew.

The final result of this manipulation is that we have been able to reformat a computer running Ubuntu 14.04, with Ubuntu 16.10. This has been done by simply downloading the ISO file for the new version of the distribution, and using a combination of GRUB and Casper to boot it into RAM, without using any disks aside from our internal hard drive. Though some care must be exerted, the procedure should be accessible for many advanced users. For others, just being able to boot into a Live CD without needing to prepare an USB pendrive may be something of a time-saver when testing out several different options.

issue121/tutoriel2.1496069711.txt.gz · Dernière modification : 2017/05/29 16:55 de auntiee