Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of extending LVM Root Directory under Ubuntu system

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Preface

Recently, a server running under Hyper-V (Ubuntu 16.04) ran out of disk space and didn't put the data in a separate partition before, so I had to find a way to make the root directory a little bigger. I have not dealt with such a problem before. I have searched a lot of information on the Internet, and now I record and share the expansion methods.

It is recommended to do a good backup before operation.

Overview of steps

Expand the physical disk to determine the physical extension partition where the LVM logical partition is located add a new LVM logical partition and merge the new partition into the corresponding Volumn Group update file system

Magnify the physical disk

Shut down the virtual machine, and then operate directly in the virtual machine management.

Now the disk has been adjusted from 100g to 300g.

Determine the disk to be operated on

First take a look at the disk usage and run the command

Root@vm003:~# df-hFilesystem Size Used Avail Use% Mounted onudev 3.9G 0 3.9G 0% / devtmpfs 798M 8.6M 789M 2% / run/dev/mapper/Ubuntu-root 94G 88G 1.9G 98% / tmpfs 3.9G 0 3.9G 0% / dev/shmtmpfs 5.0M 05.0M 0% / run/locktmpfs 3.9G 03.9G 0% / sys/fs/cgroup/dev/sda1 472M 382M 66M 86% / boottmpfs 100K 0 100K 0% / run/lxcfs/controllerstmpfs 798M 0 798M 0% / run/user/0

Although we have adjusted the physical disk to 300G, the root directory is still 100g, which is 98%.

Run command

Root@vm003:~# fdisk-lDisk / dev/sda: 300 GiB, 322122547200 bytes, 629145600 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 4096 bytesI/O size (minimum/optimal): 4096 bytes / 4096 bytesDisklabel type: dosDisk identifier: 0xa88f1366Device Boot Start End Sectors Size Id Type/dev/sda1 * 2048999423 997376 487M 83 Linux/dev/sda2 1001470 209713151 208711682 99.5G 5 Extended/dev/sda5 1001472 20913151 208711680 99.5G Linux LVMPartition 2 does not start on physical sector boundary.Disk / dev/mapper/Ubuntu-root: 95.5 GiB 102563315712 bytes, 200318976 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 4096 bytesI/O size (minimum/optimal): 4096 bytes / 4096 bytesDisk / dev/mapper/Ubuntu-swap_1: 4 GiB, 4294967296 bytes, 8388608 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 4096 bytesI/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.

We also know that we are going to operate / dev/sda

Expand the physical partition where the LVM logical partition is located

Run command

Root@vm003:~# parted / dev/sdaGNU Parted 3.2Using / dev/sdaWelcome to GNU Parted! Type 'help' to view a list of commands. (parted) print # View partition Model: Msft Virtual Disk (scsi) Disk / dev/sda: 322GBSector size (logical/physical): 512B/4096BPartition Table: msdosDisk Flags:Number Start End Size Type File system Flags 1 1049kB 512MB 511MB primary ext2 boot 2 513MB 107GB 107GB extended 5 513MB 107GB 107GB logical lvm (parted) resizepart 2 # Resize sda2 partition End? [107GB]?-0 # directly fill (parted) print # View Model: Msft again Virtual Disk (scsi) Disk / dev/sda: 322GBSector size (logical/physical): 512B/4096BPartition Table: msdosDisk Flags:Number Start End Size Type File system Flags 1 1049kB 512MB 511MB primary ext2 boot 2 513MB 322GB 322GB extended 5 513MB 107GB 107GB logical lvm (parted) Q # completed 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/sdaWelcome 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 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 4096 bytesI/O size (minimum/optimal): 4096 bytes / 4096 bytesDisklabel type: dosDisk identifier: 0xa88f1366Device Boot Start End Sectors Size Id Type/dev/sda1 * 2048 999423 997376 487M 83 Linux/dev/sda2 1001470 629145599 628144130 299.5G 5 Extended/dev/sda5 1001472 209713151 208711680 99.5G 8e Linux LVMPartition 2 does not start on physical sector boundary.Command (m for help): n # New Partition Select a logical partition and enter it depending on the starting point and ending point. The default value is to fill the entire disk All space for primary partitions is in use.Adding logical partition 6First sector (209715200-629145599, default 209715200): Last sector, + sectors or + size {K GiB M Linux' and of size Greco T ·P} (209715200-629145599, default 629145599): Created a new partition 6 of type 'disk 200GiB.Command (m for help): P # View the new partition Disk / dev/sda: 300 GiB, 322122547200 629145600 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 4096 bytesI/O size (minimum/optimal): 4096 bytes / 4096 bytesDisklabel type: dosDisk identifier: 0xa88f1366Device Boot Start End Sectors Size Id Type/dev/sda1 * 2048 999423 997376 487M 83 Linux/dev/sda2 1001470 629145599 628144130 299.5G 5 Extended/dev/sda5 1001472 209713151 208718099.5G 8e Linux LVM/dev/sda6 209715200629145599419430400 83 LinuxPartition 2 does not start on physical sector boundary.Command (m for help): t # change the partition type to Linux LVMPartition number Default 6): 6 # sda6Partition type (type L to list all types): 8e # Id code of type LVM 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 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 4096 bytesI/O size (minimum/optimal): 4096 bytes / 4096 bytesDisklabel type: dosDisk identifier: 0xa88f1366Device Boot Start End Sectors Size Id Type/dev/sda1 * 2048 999423 997376 487M 83 Linux/dev/sda2 1001470 629145599 628144130 299.5G 5 Extended/dev/sda5 1001472 209713151 208711680 99.5G 8e Linux LVM/dev/sda6 209715200 629145599 419430400 200G Linux LVMPartition 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 busyThe kernel still uses the old table. The new table 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

You can see that the VG Name we are going to operate is Ubuntu. 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'.

Er, hint that the / dev/sda6 device has not been found, it is better to restart it.

Root@vm003:~# reboot

Execute again after reboot

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 2 20 wz--n- 299.52g 200.00g

I did add it.

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, write it down.

Then run

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

It worked.

Warning: if the following warning appears during the operation, it means that the total size of the logic volumn is not right now. Instead of increasing the space, the resize is shrinking the space. If the operation continues, the data will be lost. It should be stopped 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? [YBO] *

Update the file system

The last step is to run the command

Root@vm003:~# resize2fs-p / dev/mapper/Ubuntu-root # / dev/mapper/Ubuntu-root is the file system information resize2fs 1.42.13 (17-May-2015) Filesystem at / dev/mapper/Ubuntu-root is mounted on / seen from the df command; on-line resizing requiredold_desc_blocks = 6, new_desc_blocks = 19The 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 disk usage

Root@vm003:~# df-hFilesystem Size Used Avail Use% Mounted onudev 3.9G 0 3.9G 0% / devtmpfs 798M 8.6m 789M 2% / run/dev/mapper/Ubuntu-root 291G 88G 191G 32% / tmpfs 3.9G 0 3.9G 0% / dev/shmtmpfs 5.0M 05.0M 0% / run/locktmpfs 3.9G 03.9G 0% / sys/fs/cgroup/dev/sda1 472M 382M 66M 86% / boottmpfs 100K 0100K 0 % / run/lxcfs/controllerstmpfs 798M 0 798M 0% / run/user/0

The great task has been completed!

Reference:

Https://www.jb51.net/article/139565.htm

Summary

The above is the whole content of this article, I hope that the content of this article has a certain reference and learning value for your study or work, if you have any questions, you can leave a message and exchange, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report