Developed the program for simple expansion of the section and file system (xfs, ext3,4) without data loss. github.com/rekby/fsextender/releases/latest
After expansion of a disk of the virtual computer from wasps of linux family to expand in it the section of data.
The file system occupies all disk, without partition table
In the simplest case (one file system on all disk, without sections) it is enough to cause xfs_growfs or resize2fs and it's done.
File system on LVM volume
If the file system works over LVM — expansion becomes complicated a little, but it is still safe: to add the new section, to create there a physical volume of LVM, to add it to LVM group, to expand a logical volume and after that to expand file system. The heap of sections and physical volumes if the place is added gradually several times will be ghost effect here. in the portions. And if the msdos-partition table is used, then it is necessary to remember even about use of extended partitions, otherwise their quantity is limited to 4 pieces and then it is necessary to practise shamanism also rewriting of the partition table.
File system in the normal section
The most dangerous option for manual execution: it is necessary to delete and recreate manually the section so that it began where also previous in the same place, and came to an end on the last free sector of a disk.
Here the increased attentiveness and accuracy is required — at an error in digits it is possible to lose all data easily. Besides as ghost effect GUID of GPT sections to which there can be some bindings in settings of system change.
In all cases when perhaps I decided to rewrite the partition table. In the automatic mode it is not so dangerous as manually (in the msdos-table all table finds room in one sector, and record of sector of an atomarn, and in GPT tables there are a checksum and the spare copy on a case of damage of the first table).
Language of implementation selected go since on an output very just to receive a static binarnik, without external dependences, it is important since the same binarnik has to be started different versions of OS from centos 5.4 x86 to the last ubuntu 14.04 x64 and further — in process of updating of templates.
Two libraries for work directly with partition tables are written: github.com/rekby/mbr — for work with the partition table msdos (the external interface not really, but works regularly) and github.com/rekby/gpt — for work with the tables GPT.
The extender of sections and file systems is written. He is able:
1. To expand the main (primary, not logical) sections of the table msdos and the sections GPT in the place, without data loss, flags, indentifikator, etc. (if the kernel supports, then and without reset — such as in ubuntu 14.04).
2. To expand physical volumes of LVM (LVM-PV) in the place without data loss if it is possible to expand the section under LVM-PV.
2. To create new sections for the LVM expansion (in avoidance of misunderstanding sections are created only on disks where there is already a ready partition table).
3. To filter disks for creation of new sections (by default new sections are created only on those disks where this LVM group is already placed, filters can be switched-off).
4. To expand the file systems ext3, ext4, xfs.
5. Determines by automatic machine whether reset after rewriting of the partition table is necessary.
Work with partition tables happens directly rewriting of data in office areas of a disk. So it turns out safer, than work via tools like parted since time of violation of integrity of the partition table is less, and in some cases is absent absolutely.
Work with LVM and expansion of file systems becomes through external challenges of sootvetstvushchy commands (pvcreate, xfs_growfs, etc.) so these commands have to be set and be present at PATH, i.e. to be available to a challenge just by name. In the podavlyashchy majority of cases this condition is satisfied naturally.
As a result now expansion of file system and underlying sections looks so:
fsextender /home --do
fsextender /dev/sda2 --do
fsextender /dev/lvm-group/lvm-volume --do
This article is a translation of the original post at habrahabr.ru/post/274451/
If you have any questions regarding the material covered in the article above, please, contact the original author of the post.
If you have any complaints about this article or you want this article to be deleted, please, drop an email here: email@example.com.
We believe that the knowledge, which is available at the most popular Russian IT blog habrahabr.ru, should be accessed by everyone, even though it is poorly translated.
Shared knowledge makes the world better.