In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "how to dynamically expand the root partition size online". The content is simple and easy to understand, and the organization is clear. I hope it can help you solve your doubts. Let Xiaobian lead you to study and learn this article "how to dynamically expand the root partition size online".
preface
Dynamic online expansion of root partition size related content
qemu-img resize yourname.img +10G
First, increase the partition size with the command qemu-kvm
LVM
Scenario Description: Disk image for virtual machine has been expanded, or corresponding to physical machine, the capacity of disk has been increased. Then we want to use the expanded capacity without affecting the existing file system (unpartitioned disk).
In the actual use process, we sometimes need to expand the hard disk of the virtual machine image. For example, when we first created the virtual machine, we thought that 20G disk space was enough, but at one time we might copy a 10G + file into the virtual machine at one time. At this time, we were stupid.
We can easily expand the disk size of a virtual machine through VMware or VirtualBox graphical interfaces or commands, but when the disk size increases, the system does not use it. So at this time, we have to consider how to make this extra space can be used by the Linux system in the virtual machine.
Before that, add a "disk MBR" knowledge:
A hard disk is divided into two areas, one is the MBR (main boot partition) and the other is the data area.
MBR records two important information: boot program and disk partition table.
The partition table defines that "the nth disk block is from the xth cylinder to the yth cylinder," so every time the system takes the nth disk block, it will only read the data between the xth and yth sectors.
Due to the limited capacity of MBR, it was designed to have only 4 partition records. It can be used as 4 main partitions, or 3 main partitions and an extended partition.
If there are more than four partitions, the system allows additional hard disk space to be placed in another disk partition information, that is, an extended partition. When the hard disk is divided into an extended partition, the information in the MBR disk partition table is actually the location of the other partition table. Therefore, in the extended partition inside the logical partition can be used.
A maximum of 4 primary partitions are allowed per hard disk, and the remaining partitions can only be placed in extended partitions.
This shows that because the number of primary partitions is limited, and we want to increase the capacity is only used for storage, so we can add an extended partition. (And if you are a rich man, there are 4 main partitions in total, and you plan to use another main partition quota this time, then you can skip Part1 and look directly at Part2 below.)
PART1
We want to add the increased capacity to the extended partition. To expand the extended partition, this fdisk cannot be done, you need to use the parted command (if the system does not come with parted, then install one from the source):
parted /dev/xxx
Enter interactive mode and use help to view the help command.
A few commands worth noting in particular:
print View partition table. Note the partition 'Number' item to be operated on, which will be used later.
unit Change the default unit used by parted to describe the size (e.g.'compact' means 'MB').
It is worth noting that if MB/GB is used, there will be errors in the selection of disk sectors. Parted will pick the nearest sector for you, but not necessarily precisely. For example, if the unit is MB, then an error of +-500KB may occur; if it is GB, then an error of +-500MB may occur, which is intolerable. So if it is an operation like 'Create Partition', it is recommended to use units like'MiB'instead of' MB'. 'MiB' will be an exact value, and parted will not look for its nearest unit as it does for 'MB'.
resize For the partition with the specified minor number (or Number number), start/end can be xxxMB or negative, indicating how far forward from the end of the disk, such as-0 is to the end of the disk.
For more command details, please refer to http://www.gnu.org/software/parted/manual/html_chapter/parted_toc.html
Actual combat:
Before the operation, print the result as follows. The existing disk 62.3G, only allocated to extended 8G, there are more than 50 G not allocated at all.
Number Start End Size Type File system Flags1 1049kB 256MB 255MB primary ext2 boot2 257MB 8589MB 8332MB extended5 257MB 8589MB 8332MB logical lvm
I hope to use all of these 50 G's for extended use.
By order:
resize 2 257MB -0
In fact, just type resize 2, enter, the remaining two parameters, parted will let you fill in the interactive way. - 0 indicates the end of the disk to that partition.
Now take a look at the print again,
Number Start End Size Type File system Flags1 1049kB 256MB 255MB primary ext2 boot2 257MB 62.3GB 62.0GB extended5 257MB 8589MB 8332MB logical lvm
The extended zone has been successfully expanded.
The extended area is just equivalent to "a physical hard disk." If you want to use the additional space, you have to expand the lv with Number 5.
The size of a logic volume depends on the size of the volume group in which it is located. Because logic volume is separated from volume group, if volume group is not large, then logic volume cannot exceed volume group. So it's really about adding space to the volume group.
PART2
To increase the size of a volume group, use fdisk to create a new partition on extended using the disk space you just added but not yet allocated. Enter interactive mode with fdisk and view help with command m. First, enter n to create a new partition, then select l to set the new partition as a logical partition, and then set the starting and ending positions of the partition in turn (the default is to fully utilize all the remaining space on this disk, so the default is OK). The created partition is numbered 6. You can use the command p.
Device Boot Start End Blocks Id System/dev/vda1 * 2048 499711 248832 83 Linux/dev/vda2 501758 121634815 60566529 5 Extended/dev/vda5 501760 16775167 8136704 8e Linux LVM/dev/vda6 16777216 121634815 52428800 83 Linux
Next, since we are using LVM to manage this new partition, we need to change the administration system for the new partition from Linux to Linux LVM. In interactive mode, enter the command t, then select the 6 you just created, and enter 8e (code name for Linux LVM). Finally, we want to actually write these operations to the hard disk by typing the command w.
At this point, we can see that/dev/vda6 has been created via fdisk -l.
re-execution
vgextend /dev/vda6
Add the new partition to the volume group (VG Name can be found via vgdisplay).
Now use vgs to check the status of the volume group and see that the volume group has grown.
VG #PV #LV #SN Attr VSize VFree jiang51-vg 2 2 0 wz--n- 57.75g 50.03g
Then, increase the logic volume in the volume group.
Command (the last 'Logic Volumn name' can be found via lvdisplay):
lvresize -l +100%FREE
Warning: If the following warning occurs during operation, it means that the total size of logic volume is not correct now. Resize not only does not increase space, but reduces space. If you continue to operate, you will lose data. It 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]
Finally, update the file system on logic volume, otherwise you can see from df that the file system is unaware that logic volume is getting bigger.
Use the command (where file_system_name is found by df):
resize2fs -p
Thus, the expansion of the disk extended partition is finally completed.
Non-LVM
fdisk /dev/sdadnp1wresize2fs /dev/sda1df -h
The most important step: "delete the current partition, repartition" press d to delete the current partition 1, note: do not press w to save after deletion! Press n directly to create a new partition, and then start from the original cylinder until the last size (the default value can be entered twice. If the previous partition does not start from the first cylinder, you need to record the starting cylinder of the previous partition). After the new partition operation is completed, press w to save it.
The above is "how to dynamically expand the root partition size online" all the content of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.