How does Ubiquity determine the required disk space before installation?
To determine the required disk space, Ubiquity will multiply two by an amount of bytes found in the filesystem.size file. Depending on machine setup, Ubiquity may not show the actual required disk space. The full explanation as follows.
The built-in logic
Look into the exact ubiquity package. Browse the file at usr/lib/ubiquity/ubiquity/misc.py
and find the function install_size()
as follows.
def install_size():
if min_install_size:
return min_install_size
# Fallback size to 5 GB
size = 5 * 1024 * 1024 * 1024
# Maximal size to 8 GB
max_size = 8 * 1024 * 1024 * 1024
try:
with open('/cdrom/casper/filesystem.size') as fp:
size = int(fp.readline())
except IOError:
pass
# TODO substitute into the template for the state box.
min_disk_size = size * 2 # fudge factor
# Set minimum size to 8GB if current minimum size is larger
# than 8GB and we still have an extra 20% of free space
if min_disk_size > max_size and size * 1.2 < max_size:
min_disk_size = max_size
return min_disk_size
min_install_size = None
The min_install_size
seems irrelevant and useless at this time of finding.
The try statement will attempt to read the amount of bytes found in /cdrom/casper/filesystem.size
, then store the value as integer in the variable size
, which then will be multiplied by two, then store in another variable min_disk_size
. Finally, the function will return the value of min_disk_size
.
Based on the built-in logic, the required disk space is usually twice the amount of bytes found in the filesystem.size file.
Some clarification
The required disk space was previously about 5 GB (Ubuntu 12.04), 8 GB (Ubuntu 16.04), and has since increased to 25 GB (Ubuntu 18.04), as per minimum system requirements. In practice, the absolute minimum for required disk space may differ by installation media and machine.
The required disk space for Ubuntu 18.04 is overstated. If the required disk space is twice the amount of filesystem.size, Ubuntu 18.04 will actually need only about 10 GB or less.
I have clarified that Ubuntu 16.04 will require at least 8 GB disk space only on a physical machine, but the minimum changes to 8.3 GB when installing to a virtual machine (bottom half screenshot).
This either had been noted wrongly or had been mistaken for 16.04 release of other flavours. In fact, I could not reproduce the test result for seeing precisely 8 GB disk space required on a physical machine. From my recent test results, the required disk space for Ubuntu 16.04 is 8.3 GB, regardless of a physical machine or a virtual machine.
In the following screenshot combo, the amount of required disk space is shown for Ubuntu 16.04 32-bit (top half) and Ubuntu 18.04 64-bit when running in a virtual machine.
User experience may vary, due to the exact conditions to reproduce the different results are not really understood.
Some calculation
Known information of the Ubuntu releases:
- Ubuntu 16.04 filesystem.size: 4139667456
- Ubuntu 16.04 install size seen: 8.3 GB (when disk space is low)
- Ubuntu 18.04 filesystem.size: 4660985856
- Ubuntu 18.04 install size seen: 8.6 GB (when disk space is zero)
Given that the filesystem.size and the amount of disk space shown by the installer are known for each system, manual comparison can be made to determine whether each pair of figures would be tally or not.
# Use Python interactive shell to do manual calculation
# round(number,N) will return a floating point number in N digits
# The required disk space for Ubuntu 16.04 (xenial)
>>> size = 4139667456 # filesystem.size
>>> round((size*2)/1000/1000/1000.0,1)
8.3
# The required disk space for Ubuntu 18.04 (bionic)
>>> size = 4660985856 # filesystem.size
>>> round((size*2)/1000/1000/1000.0,1)
9.3
# The required disk space for fallback size
>>> size = 5*1024*1024*1024 # fallback size to 5 GB in ubiquity
>>> round((size*2)/1000/1000/1000.0,1)
10.7
# The required disk space for maximal size
# This is used "as it is" based on the built-in logic
>>> max_size = 8*1024*1024*1024 # maximal size to 8 GB in ubiquity
>>> round((max_size)/1000/1000/1000.0,1)
8.6
Ubuntu 18.04 supposedly needs 9.3 GB of required disk space, but Ubiquity instead had shown 8.6 GB in the screenshot; what went wrong? Try copy edit and test the relevant variables and the if statement from the function install_size()
:
# Redo calculation according to the built-in logic
# The required disk space for Ubuntu 18.04 (bionic)
# Before
>>> size = 4660985856 # filesystem.size
>>> min_disk_size = size*2 # fudge factor in ubiquity
>>> max_size = 8*1024*1024*1024 # maximal size in ubiquity
>>> round((min_disk_size)/1000/1000/1000.0,1)
9.3
>>> round((max_size)/1000/1000/1000.0,1)
8.6
# After
>>> if min_disk_size > max_size and size * 1.2 < max_size:
... min_disk_size = max_size
...
>>> round(min_disk_size/1000/1000/1000.0,1)
8.6
Here is what went wrong: The if statement had chosen the max_size
because the min_disk_size
for Ubuntu 18.04 is found to be larger than the maximal size.
Not sure why the condition assumed the required disk space (twice of the filesystem.size) would not be larger than 8 GiB (8.6 GB) as defined in the ubiquity package? This "wrong" result seems to be intended by design as per inline comment within the script.
Based on manual comparison, both pair of figures are found to be tally: Ubuntu 16.04 had the installer showing the real install size that is twice the amount of bytes found in the filesystem.size; Ubuntu 18.04 had the installer showing the apparent install size that has been defined as maximal size.
TL;DR The required disk space is twice the amount of filesystem.size, or twice the fallback size, or otherwise the maximal size as defined in the ubiquity package.