Install Ubuntu Desktop on LVM

    The classic partitions, on which the hard disk is most often divided for system installation and data storage, have a number of significant drawbacks. Their size is very difficult to change, they are in strict sequence and just taking a piece from the first section and adding to the last will fail if there are more sections between them. Therefore, very often during the initial partition of the hard drive, users rack their brains - how much space to allocate for a particular section. And almost always in the process of using the system they come to the conclusion that they made the wrong choice.

    Fortunately, LVM technology can solve most of these problems on Linux.. It creates an additional abstraction - logical volumes that are visible in the system as normal partitions, but they are not really them. This technology is very useful for servers, but on home computers it has to be very out of place. I no longer think what size disk to allocate for the system, so that some texlive would not clog the entire place, but also that the extra 5-10 gigabytes would not disappear just like that. LVM has a number of significant advantages that greatly simplify life:
    • LVM logical volumes are no longer bound to a physical location. Within the framework of LVM, there is no such thing as the order of logical volumes.
    • The size of logical volumes can be increased directly on the fly, and for unmounted volumes, you can also easily reduce the size without leaving the system.
    • If necessary, you can spread the logical volumes across several physical hard drives, thereby increasing the available space. At the same time, the system will still see only one logical volume, although its size will exceed the available sizes of the hard drives. You can also perform the reverse operation by removing the hard drive from the LVM, thus freeing it for another use.
    • LVM supports the snapshot mechanism - instant copies of the volume file system. This can be very useful for creating backups.
    • There are many more advantages that you can read about in specialized articles about LVM.
    Ubuntu fully supports LVM, however , the necessary utilities for working with LVM have been removed from the Desktop version of the installation disk. In addition, the Desktop installer does not know how to modify LVM volumes. Therefore, if you want to use LVM, you will either have to install the system from an Alternate disk, or cheat a little with a regular LiveCD . Installing with Alternate is inconvenient and causes discomfort for many, and besides, most often Alternate is not at hand, so let's consider the option with LiveCD.

    Note that LVM is controlled through the terminal, therefore, in order not to break anything, you must first learn how to work more or less comfortably with it. Also, familiarize yourself with the principles of operation and the basic concepts of LVM in order to understand what it is. The article is not intended for beginners, but for those who have already figured out the basics of Ubuntu.

    Preliminary preparation


    You need to start the system from LiveCD and connect the computer to the Internet. Next, open the terminal and install the necessary utilities directly into the LiveCD session with the command:

    sudo apt-get install lvm2

    That's it, now you can start working with LVM. But first you need to highlight the place where we will create LVM. To do this, you need the Gparted section editor , which is located in the menu System → Administration ( System → Administration ). Use it to create a partition on top of which you will deploy LVM. If you are ready to allocate the entire hard drive for LVM, then create a partition on the entire hard drive. Do not select any file system for the partition - just an empty (unformatted) partition. Do not forget, to apply all the changes you have made through Gparted, you need to click on the green checkmark on the top panel or select the Apply item in the Edit menu.

    After the markup changes have been successfully made, you will need to change the type of partition you need to Linux LVM . To do this, right-click the partition and select the flag control ( the Manage The flags ). In the window that opens, check the box with the name lvm , wait until all changes are applied and close Gparted. At this preparatory stage is completed.

    Creating LVM Logical Volumes


    Now it's time to start creating LVM directly. For example, we assume that we create LVM on top of the / dev / sda1 partition . In this case, you must first initialize the physical partition with the command:

    sudo pvcreate /dev/sda1

    Next, create a volume group (see what it is about in the articles about LVM) using the command

    sudo vgcreate local /dev/sda1

    And finally, create the logical volumes you need. Here it is worth noting that since it is possible to easily increase the size of LVM volumes directly in a running system, it is best to allocate the minimum required size for logical volumes. Do not be afraid that a large volume will remain unallocated within the volume group; it will not be lost. As soon as you need additional space, you can easily add it to any logical volume. But reducing the size of a logical volume is much more difficult.

    Typically, to install the system, you need a partition under the root, a partition under / home , a partition under swap, and sometimes a partition for data. You can create logical volumes for all these four tasks using the following commands:

    sudo lvcreate -L 7G -n root local
    sudo lvcreate -L 5G -n home local
    sudo lvcreate -L 3G -n swap local
    sudo lvcreate -L 10G -n data local

    The -n parameter , if you still do not understand, sets the name of the logical volume, -L - its size.

    Now you need to create file systems on the created logical volumes. You can do this with the following commands:

    sudo mkfs.ext4 /dev/local/root
    sudo mkfs.ext4 /dev/local/home
    sudo mkswap -f /dev/local/swap
    sudo mkfs.ext4 /dev/local/data

    Note that the LVM logical volume names on the system look like / dev / {volumegroup_name} / {volume_name} .

    In addition, the ext4 file system, by default, reserves part of the space for system data. Since there will never be any system data on / home , and even more so on the section with user files, it is better to cancel this reservation in order to free up wasted space. Commands are useful for this.

    sudo tune2fs -r 0 /dev/local/home
    sudo tune2fs -r 0 /dev/local/data

    In no case do not cancel the reservation for the root partition, otherwise the system may stop working at all!

    And finally, you might want to assign a normal label to the data section so that it displays beautifully in the installed system. You can do this with a command like this:

    sudo tune2fs -L Data /dev/local/data

    Now you can proceed directly to the installation on the logical volumes we created.

    System installation


    Actually, the installation itself is standard , however, when you are prompted to choose a method for partitioning the disk, select manual mode. In the window that opens, you will see all the LVM volumes you created. Indicate the appropriate mount point for each, but do not check the format box. For the section for data, you can specify the mount point / media / data .

    Wait for the installation to complete, but do not restart the computer!

    If you restart your computer, your new system will not start. In this case, you will need to log into LiveCD again, install the LVM utilities, and then run the command

    sudo vgchange -a y

    Then follow the instructions below.


    Activating LVM on an installed system


    You installed the system, but there was one small problem - the installed Ubuntu does not have utilities for working with LVM, which means it just won’t start. This is easy enough to fix.

    To get started, without leaving LiveCD, mount the logical volume that you allocated as root in the / mnt folder. You can do this with the team

    sudo mount /dev/local/root /mnt

    Now you will need to enter the installed system using chroot , but first you need to temporarily connect some important system resources to it. To do this, run the commands

    sudo mount --bind /dev /mnt/dev
    sudo mount --bind /proc /mnt/proc
    sudo mount --bind /sys  /mnt/sys

    Now go to the installed system with the command

    sudo chroot /mnt /bin/bash

    And install the necessary utilities with the command

    apt-get install lvm2

    That's it, the installation is complete. Close the terminal, press Ctrl-Alt-Del and reboot the computer. Remember to remove the LiveCD from the drive. The computer should boot into the newly installed system.

    Further work


    Suppose, at some point, the 5 gigabytes that you allocated to the / home partition ceased to be enough for you . No problem. See how much unused space remains in the volume group with the command

    sudo vgdisplay local

    Now increase the size of the logical volume / dev / local / home to the desired one with the command

    sudo lvresize -L 15G /dev/local/home

    Note that the -L parameter specifies the total desired size, not its increment. After increasing the size of the logical volume, it remains only to stretch the file system to the entire new volume. You can do this with the team

    sudo resize2fs /dev/local/home

    Everything, the size of the logical volume is increased.

    In addition to increasing the size of logical volumes on the fly, LVM can do much more. For example, create instant snapshots. However, about all the intricacies of working with this technology, read in specialized articles.

    References

    Actual version of the article


    The latest and most current version of this article is on the official Russian-language Wiki-resource documentation on Ubuntu. There you can freely improve and supplement the laid out reference and training materials, as well as add your own. If you have something to tell other Ubuntu users, then a huge request - write or edit the corresponding article on help.ubuntu.ru . Even with small improvements and additions you will help thousands of people, and one of them, in turn, will describe something useful and interesting for you.

    Also popular now: