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

How to expand the disk space of root directory in Linux system

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article mainly introduces how to expand the root disk space in the Linux system, which has a certain reference value, and interested friends can refer to it. I hope you will gain a lot after reading this article.

First, use the background

There is not enough disk space in the Linux root directory. When you modify the virtual machine template to increase the disk size or insert a new hard disk, it is found that the size in the system has not changed.

The reason is that the disk is not formatted and the partition is not added.

2. Method of operation

1. Check the amount of disk space and use the df-h command to find that the / dev/mapper/ubuntu14--vg-root that mounts the root node has only 28G capacity.

Root@ubuntu14:/opt# df-h file system capacity used available mount point / dev/mapper/ubuntu14--vg-root 28G 23G 3.3G 88% / none 4.0K 04.0K 0% / sys/fs/cgroupudev 3.9G 4.0K 3.9G 1% / devtmpfs 799M 384K 799M 1% / runnone 5.0M 0 5.0M 0% / run/locknone 3.9G 0 3.9G 0% / run/shmnone 100M 0100M 0% / run/user/dev/vda1 236M 37M 188M 17% / boot

two。 Increase disk space, such as the way the VM virtual machine is used in the following figure.

3. Use the fdisk-l command to view disk information. When you see that the first line Disk / dev/vda: 161.1 GB does not match the actual df-h display, the addition of the disk is successful.

Root@ubuntu14:/opt# fdisk-lDisk / dev/vda: 161.1 GB, 161061273600 bytes16 heads, 63 sectors/track, 312076 cylinders Total 314572800 sectorsUnits = sector of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x0001a023 device startup start and end blocks Id system / dev/vda1 * 2048 499711 248832 83 Linux/dev/vda2 501758 62912511 31205377 5 extension / dev/vda5 501760 62912511 312053768e Linux LVMDisk / dev/mapper/ubuntu14--vg-root: 29.8GB, 29804724224 bytes255 heads, 63 sectors/track 3623 cylinders, total 58212352 sectorsUnits = sector of 1 * 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk / dev/mapper/ubuntu14--vg-root doesn't contain a valid partition tableDisk / dev/mapper/ubuntu14--vg-swap_1: 2147 MB, 2147483648 bytes255 heads, 63 sectors/track, 261cylinders Total 4194304 sectorsUnits = sector of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk / dev/mapper/ubuntu14--vg-swap_1 doesn't contain a valid partition table

4. Using fdisk / dev/vda, create a new partition.

Note: different operating systems have different disk names, some of which are / dev/sda. For more information on how to use it, please refer to the first line of fdisk-l in step 3 to display Disk. If the first line of the system is displayed as Disk / dev/vda: 161.1 GB, 161061273600 bytes, so use the command fdisk / dev/vda)

Follow the Linux operation below to partition.

Root@ubuntu14:/opt# fdisk / dev/vda command (enter m for help): M command operation a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition l list known partition types m print this menu n add a new partition o create a new empty DOS partition table p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partition's system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only ) command (enter m for help): n # new new partition Partition type: P primary (1 primary) 1 extended, 2 free) l logical (numbered from 5) Select (default p): P # Select the primary partition number (1-4) Default is 3): 3 # partition sequence number starting sector (499712-314572799, default is 499712): # default value 499712Last sector will be used by default when partition starts to enter, + sector or + size {K Magi M Magi G} (499712-501757) Default is 501757): the default value 501757 command will be used (enter m for help): n # new new partition Partition type: P # primary (2 primary, 1 extended, 1 free) l logical (numbered from 5) Select (default p): P # Select the primary partition Selected partition 4 # partition sequence number starting sector (62912512-314572799, default is 62912512): # the default value 62912512Last sector will be used for partition start carriage return, + sector or + size {KGregor G} (62912512-314572799) Default is 314572799): will use the default 314572799 command (enter m for help): t # modify partition format partition number (1-5): 4 # modify partition number Hex code (type L to list codes): 8e # format Select 8e linux LVMChanged system type of partition 4 to 8e (Linux LVM) command (enter m for help): P # display partition information Disk / dev/vda: 161.1 GB, 161061273600 bytes16 heads, 63 sectors/track, 312076 cylinders Total 314572800 sectorsUnits = sector of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x0001a023 device startup start and end blocks Id system / dev/vda1 * 2048 499711 248832 83 Linux/dev/vda2 501758 62912511 31205377 5 extension / dev/vda3 499712501757 1023 Linux/dev/vda4 62912512 314572799125830144 8e Linux LVM/dev/vda5 501760 62912511 31205376 8e Linux LVMPartition table entries are not in disk order command (enter m for help): W # save information The partition table has been altered calling ioctl () to re-read partition table.WARNING: Re-reading the partition table failed with error 16: device or resource busy. The kernel still uses the old table. The new table will be used atthe next reboot or after you run partprobe (8) or kpartx (8) Syncing disks.

5. Restart the Linux operating system, using the reboot command.

6. Create a physical volume, using the pvcreate / dev/vda4 command.

Root@ubuntu14:~# pvcreate / dev/vda4 Physical volume "/ dev/vda4" successfully created

7. To view the newly created physical volume and size, use the pvdisplay command.

Root@ubuntu14:~# pvdisplay-Physical volume-PV Name ubuntu14-vg PV Size 29.76 GiB / not usable 2.00 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 7618 Free PE 0 Allocated PE 7618 PV UUID XR32TY-aRQC-IQC6-oCx7-aa9X-KdJe-bHmaBd "/ dev/vda4" / dev/vda5 VG Name is a new physical volume of "120.00 GiB" -NEW Physical volume-PV Name / dev/vda4 VG Name PV Size 120.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID MVK0IT-LDgP-eWwZ-fzQM-tdyY-kRQ-nbk122

8. A new physical volume will be added and loaded into the ubuntu14-vg volume group, using the vgextend ubuntu14-vg / dev/vda4 command.

Root@ubuntu14:~# vgextend ubuntu14-vg / dev/vda4Volume group "ubuntu14-vg" successfully extended

9. To view volume group information, use the vgdisplay command.

Root@ubuntu14:~# vgdisplay-Volume group-VG Name ubuntu14-vg System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 4 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 2 Act PV 2 VG Size 149.76 GiB PE Size 4.00 MiB Total PE 38338 Alloc PE / Size 7618 / 29.76 GiB Free PE / Size 30720 / 120.00 GiB VG UUID cq2Z6G-P6j1-S2gM-mibz-d63V-NjkS-dHYe7D

10. Increase the ubuntu14-vg size by 120g. Use the lvresize-L + 120g / dev/mapper/ubuntu14--vg-root command.

Root@ubuntu14:~# lvresize-L + 120g / dev/mapper/ubuntu14--vg-root Extending logical volume root to 147.76 GiB Logical volume root successfully resized

11. Re-recognize the ubuntu14-vg size, using the resize2fs / dev/mapper/ubuntu14--vg-root command.

Root@ubuntu14:~# resize2fs / dev/mapper/ubuntu14--vg-rootresize2fs 1.42.9 (4-Feb-2014) Filesystem at / dev/mapper/ubuntu14--vg-root is mounted on /; on-line resizing requiredold_desc_blocks = 2, new_desc_blocks = 10The filesystem on / dev/mapper/ubuntu14--vg-root is now 38733824 blocks long.

twelve。 To check the size after the expansion, use the df-h command.

Root@ubuntu14:~# df-h file system capacity used available mount point / dev/mapper/ubuntu14--vg-root 146G 23G 117G 17% / none 4.0K 04.0K 0% / sys/fs/cgroupudev 3.9G 4.0K 3.9g 1% / devtmpfs 799m 388K 799m 1% / runnone 5.0m 0 5.0 M 0% / run/locknone 3.9G 0 3.9G 0% / run/shmnone 100M 0 100 M 0% / run/user/dev/vda1 236M 37M 188M 17% / boot

When you see that / dev/mapper/ubuntu14--vg-root has been updated to the new size, the increase is successful.

Thank you for reading this article carefully. I hope the article "how to expand the disk space of the root directory in the Linux system" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

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