How to extend the root directory of LVM under Ubuntu system

Foreword

Recently, a server running under Hyper-V to capture data (Ubuntu 16.04) has insufficient disk space, and the data has not been placed in a separate partition before, so I can only find a way to enlarge the root directory. I haven't dealt with such a problem before. I searched a lot of information on the Internet. Now I record and share the expansion method.

It is recommended to do backup work before operation

Step overview

  1. Increase physical disk
  2. Determine the disk to operate
  3. The physical expansion partition where the logical partition of the expansion LVM is located
  4. Add LVM logical partition
  5. The new partition is merged into the corresponding Volumn Group
  6. Update file system

Increase physical disk size

Turn off the virtual machine, and then operate directly in the virtual machine management.

Now adjust the disk from 100G to 300G

Determine the disk to be operated

First look at the disk usage, run the command

root@vm003:~# df -h
Filesystem  Size Used Avail Use% Mounted on
udev   3.9G 03.9G 0%/dev
tmpfs   798M 8.6M 789M 2%/run
/dev/mapper/Ubuntu-root 94G 88G 1.9G 98% /
tmpfs   3.9G 03.9G 0%/dev/shm
tmpfs   5.0M 05.0M 0%/run/lock
tmpfs   3.9G 03.9G 0%/sys/fs/cgroup
/dev/sda1  472M 382M 66M 86%/boot
tmpfs   100K 0 100K 0%/run/lxcfs/controllers
tmpfs   798M 0 798M 0%/run/user/0

Although we have adjusted the physical disk to 300G, the root directory is still 100G, 98% has been used

Run command

root@vm003:~# fdisk -l
Disk /dev/sda:300 GiB,322122547200 bytes,629145600 sectors
Units: sectors of1*512=512 bytes
Sector size(logical/physical):512 bytes /4096 bytes
I/O size(minimum/optimal):4096 bytes /4096 bytes
Disklabel type: dos
Disk identifier:0xa88f1366

Device Boot Start End Sectors Size Id Type
/dev/sda1 *2048999423997376 487M 83 Linux
/dev/sda2 100147020971315120871168299.5G 5 Extended
/dev/sda5 100147220971315120871168099.5G 8e Linux LVM

Partition 2 does not start on physical sector boundary.

Disk /dev/mapper/Ubuntu-root:95.5 GiB,102563315712 bytes,200318976 sectors
Units: sectors of1*512=512 bytes
Sector size(logical/physical):512 bytes /4096 bytes
I/O size(minimum/optimal):4096 bytes /4096 bytes

Disk /dev/mapper/Ubuntu-swap_1:4 GiB,4294967296 bytes,8388608 sectors
Units: sectors of1*512=512 bytes
Sector size(logical/physical):512 bytes /4096 bytes
I/O size(minimum/optimal):4096 bytes /4096 bytes

You can see that /dev/sda has indeed been adjusted to 300GiB, but the system hasn't used it yet.

Also know that we want to operate /dev/sda

Enlarge the physical partition where the LVM logical partition is located

Run command

root@vm003:~# parted /dev/sda
GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.(parted) print #View partition
Model: Msft Virtual Disk(scsi)
Disk /dev/sda: 322GB
Sector size(logical/physical): 512B/4096B
Partition Table: msdos
Disk Flags:

Number Start End Size Type File system Flags
 1 1049 kB 512MB 511MB primary ext2  boot
 2 513 MB 107GB 107GB extended
 5 513 MB 107GB 107GB logical  lvm(parted) resizepart 2 #Resize sda2 partition
End?[107GB]?-0 #Directly filled(parted) print #Check again
Model: Msft Virtual Disk(scsi)
Disk /dev/sda: 322GB
Sector size(logical/physical): 512B/4096B
Partition Table: msdos
Disk Flags:

Number Start End Size Type File system Flags
 1 1049 kB 512MB 511MB primary ext2  boot
 2 513 MB 322GB 322GB extended
 5 513 MB 107GB 107GB logical  lvm(parted) q #Finish exit
Information: You may need to update /etc/fstab.

Now we have expanded /dev/sda2

Add LVM logical partition

Run command

root@vm003:~# fdisk /dev/sda
Welcome to fdisk(util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.Command(m for help): p #Check the current partition situation
Disk /dev/sda:300 GiB,322122547200 bytes,629145600 sectors
Units: sectors of1*512=512 bytes
Sector size(logical/physical):512 bytes /4096 bytes
I/O size(minimum/optimal):4096 bytes /4096 bytes
Disklabel type: dos
Disk identifier:0xa88f1366
Device Boot Start End Sectors Size Id Type
/dev/sda1 *2048999423997376 487M 83 Linux
/dev/sda2 1001470629145599628144130299.5G 5 Extended
/dev/sda5 100147220971315120871168099.5G 8e Linux LVM
Partition 2 does not start on physical sector boundary.Command(m for help): n #Add a new partition, select a logical partition, and enter the start and end points depending on the situation. The default value is to fill the entire disk
All space for primary partitions is in use.
Adding logical partition 6
First sector(209715200-629145599,default209715200):
Last sector,+sectors or +size{K,M,G,T,P}(209715200-629145599,default629145599):
Created a newpartition6of type 'Linux' and of size 200 GiB.Command(m for help): p #View the newly added partition
Disk /dev/sda:300 GiB,322122547200 bytes,629145600 sectors
Units: sectors of1*512=512 bytes
Sector size(logical/physical):512 bytes /4096 bytes
I/O size(minimum/optimal):4096 bytes /4096 bytes
Disklabel type: dos
Disk identifier:0xa88f1366
Device Boot Start End Sectors Size Id Type
/dev/sda1 *2048999423997376 487M 83 Linux
/dev/sda2  1001470629145599628144130299.5G 5 Extended
/dev/sda5  100147220971315120871168099.5G 8e Linux LVM
/dev/sda6 209715200629145599419430400 200G 83 Linux
Partition 2 does not start on physical sector boundary.Command(m for help): t #Change the partition type to Linux LVM
Partition number(1,2,5,6,default6):6 # sda6
Partition type(type L to list all types): 8e #Id code of LVM type
Changed type of partition 'Linux' to 'Linux LVM'.Command(m for help): p #Check the partition again
Disk /dev/sda:300 GiB,322122547200 bytes,629145600 sectors
Units: sectors of1*512=512 bytes
Sector size(logical/physical):512 bytes /4096 bytes
I/O size(minimum/optimal):4096 bytes /4096 bytes
Disklabel type: dos
Disk identifier:0xa88f1366
Device Boot Start End Sectors Size Id Type
/dev/sda1 *2048999423997376 487M 83 Linux
/dev/sda2  1001470629145599628144130299.5G 5 Extended
/dev/sda5  100147220971315120871168099.5G 8e Linux LVM
/dev/sda6 209715200629145599419430400 200G 8e Linux LVM
Partition 2 does not start on physical sector boundary.Command(m for help): wq #Confirm that there is no problem, save and exit
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: Device or resource busy
The kernel still uses the old table. The newtable will be used at the next reboot or after you run partprobe(8) or kpartx(8).

The new partition is merged into the corresponding Volumn Group

Run command

root@vm003:~# vgdisplay
- - - Volume group ---
VG Name  Ubuntu
System ID
Format  lvm2

It can be seen that the VG Name we want to operate is Ubuntu, and record it.

Then run the command

root@vm003:~# vgextend Ubuntu /dev/sda6 # /dev/sda6 is the newly added LVM partition
Device /dev/sda6 not found(or ignored by filtering).
Unable to add physical volume '/dev/sda6' to volume group 'Ubuntu'.

Uh,, it prompts that the device /dev/sda6 is not found, so it's better to restart it.

root@vm003:~# reboot

Execute again after restart

root@vm003:~# vgextend Ubuntu /dev/sda6 # /dev/sda6 is the newly added LVM partition
Physical volume "/dev/sda6" successfully created
Volume group "Ubuntu" successfully extended

Check the status of Volumn Group again and run the command

root@vm003:~# vgs
VG #PV #LV #SN Attr VSize VFree
Ubuntu 220 wz--n-299.52g 200.00g

It was indeed added.

Then run

root@vm003:~# lvdisplay
- - - Logical volume ---
LV Path  /dev/Ubuntu/root
LV Name  root
VG Name  Ubuntu

We know that the LV Path of Ubuntu VG is /dev/Ubuntu/root, record it.

Then run

root@vm003:~# lvresize -l +100%FREE /dev/Ubuntu/root # /dev/Ubuntu/root is LV Path
Size of logical volume Ubuntu/root changed from95.52GiB(24453 extents) to 295.52GiB(75652 extents).
Logical volume root successfully resized.

This is a success.

Warning: If the following warning appears during the operation, it means that the total size of the logic volumn is not correct. Resize does not increase the space, but reduces the space. If you continue to operate, you will lose data. Should stop immediately! Press n to cancel.

WARNING: Reducing active and open logical volume to 32.00 MiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce root? [y/n]*

Update file system

The last step, run the command

root@vm003:~# resize2fs -p /dev/mapper/Ubuntu-root # /dev/mapper/Ubuntu-root is the file system information seen from the df command
resize2fs 1.42.13(17-May-2015)
Filesystem at /dev/mapper/Ubuntu-root is mounted on /; on-line resizing required
old_desc_blocks =6, new_desc_blocks =19
The filesystem on /dev/mapper/Ubuntu-root is now 77467648(4k) blocks long.

This process may take a few minutes, just wait patiently.

Then run the df command to view the disk usage

root@vm003:~# df -h
Filesystem  Size Used Avail Use% Mounted on
udev   3.9G 03.9G 0%/dev
tmpfs   798M 8.6M 789M 2%/run
/dev/mapper/Ubuntu-root 291G 88G 191G 32% /
tmpfs   3.9G 03.9G 0%/dev/shm
tmpfs   5.0M 05.0M 0%/run/lock
tmpfs   3.9G 03.9G 0%/sys/fs/cgroup
/dev/sda1  472M 382M 66M 86%/boot
tmpfs   100K 0 100K 0%/run/lxcfs/controllers
tmpfs   798M 0 798M 0%/run/user/0

That's it!

reference:

https://www.zalou.cn/article/139565.htm

to sum up

The above is the entire content of this article. I hope that the content of this article has a certain reference value for your study or work. If you have any questions, you can leave a message and exchange. Thank you for your support to ZaLou.Cn.

Recommended Posts

How to extend the root directory of LVM under Ubuntu system
How to create LVM for XFS file system under Ubuntu
How to fix the problem of missing system settings on Ubuntu 14.04
How to open the ubuntu system in win10
How to turn the language of Ubuntu into Chinese? ?
Modify the default root password of the Ubuntu operating system
How to install two versions of OpenCV under ubuntu?
How to control the ubuntu system in win10 through ssh
The process of solving the problem of installing ImageMagick under Ubuntu system
Deploy the mail system under Ubuntu 19.10
How to compile ijkplayer-android under ubuntu
Overview of the Ubuntu file system
How to install Audacious under Ubuntu
How to install Tensorflow under ubuntu 16.04
How to open root account in Ubuntu20.04
How to change MySQL password under Ubuntu
How to modify the hostname on Ubuntu 20.04
How to install vim editor under Linux (Ubuntu 18.04)
Expand the disk size of Ubuntu under VMware
Summary of methods to use Evernote under Ubuntu 14.04
Centos7.5 expands the space size under the root directory
Install the old version of seurat under Ubuntu
The solution to the failure to install .deb under Ubuntu 16.04
How to use dpkg command in Ubuntu system
[Practice] How to install python3.6 on Ubuntu system
The road to reinstallation of ubuntu 18.04 from scratch
Wsl sets the default account to root (ubuntu18.04)
Publish the node.js project under Ubuntu to heroku
How to quickly modify root password under CentOS8
How to configure /var/log/messages in Ubuntu system log
Introduction to the use of Hanlp in ubuntu
Mount the disk in a directory under Ubuntu 18.04
How to run the parsing server on Ubuntu 14.04
How to change root user password on Ubuntu
Tencent Cloud ubuntu system changed to root login
How to check the installed JDK on Ubuntu
How to enable Mysql remote access under Ubuntu 14.04
How to install gcc compiler faster under Ubuntu
How to install the latest MySQL on Ubuntu 18.04
Centos7 adjusts the size of the root directory mount partition
[Video] Teach you how to install the latest Linux version of QQ under Centos 8
How to repackage Deb files under Debian and Ubuntu
How to use LVM to manage storage devices on Ubuntu 18.04
How to add the gzip module to Nginx on Ubuntu 14.04
How to upgrade to Ubuntu 20.04
Detailed explanation of static DNS configuration under Ubuntu system
Example of how to replace domestic sources on Ubuntu 18.04
How to understand the introduction of packages in Python
How to modify time zone and time in ubuntu system
Example of how to modify ip address in Ubuntu20.04
How to install theano and keras on ubuntu system
Solution to the slow speed of ubuntu18.04 wireless network
Online expansion of file system by LVM under Centos7
How to repair a damaged Ubuntu system without reinstalling
How to upgrade to Ubuntu 20.04
Teach you how to install Ubuntu system enhancement tools
How to open https on nginx server under Ubuntu
How to find the area of a circle in python
How to set or modify the time zone on Ubuntu 20.04
Ubuntu adds the Chrome icon to the correct posture of the launcher
How to set or modify the time zone on Ubuntu 20.04