In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
How to expand the virtual machine root partition disk in CentOS, in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
First, shut down your virtual machine system
View image size
Qemu-img info test.img
Expand the image capacity of a virtual machine by 40G
Dd if = / dev/zero bs=1024M count=40 > > test.img
Use qemu-img info to see the image size again.
2. Start the virtual machine and use the fdisk tool under linux to partition
Log in to your linux system with root users and view the partition of your system
# fdisk-l
Disk / dev/sda: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00008d26
Device Boot Start End Blocks Id System
/ dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/ dev/sda2 64 2611 20458496 8e Linux LVM
Disk / dev/mapper/VolGroup-lv_root: 18.9 GB, 18865979392 bytes
255 heads, 63 sectors/track, 2293 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk / dev/mapper/VolGroup-lv_swap: 2080 MB, 2080374784 bytes
255 heads, 63 sectors/track, 252 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
According to the prompt, we can judge that the disk interface of this system is SCSI, corresponding to "sda". If the red font above is "hda", then the disk interface of this system is IDE corresponding to "hda", so let me do something:
# fdisk / dev/sda
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
Switch off the mode (command 'c') and change display units to
Sectors (command'u').
Command (m for help): M / / lists fdisk's help
Command action
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 (m for help): n / / command n is used to add a new partition
Command action
E extended
P primary partition (1-4)
P / / choose to create a primary partition at this time
Partition number (1-4): 3 / / fdisk will let you choose the number of the primary partition. If you already have the primary partition sda1,sda2, select 3, that is, the partition to be created is sda3.
First cylinder (2611-7832, default 2611): / / at this point, fdisk will ask you to select the starting value of the partition. This is the Start value (start cylinder) of the partition. It is best to press enter directly here.
Using default value 2611
Last cylinder, + cylinders or + size {KJM MagneG} (2611-7832, default 7832): / / at this point, fdisk will ask you to select the starting value of the partition, which is the End value of the partition. Here, it is best to press enter directly.
Using default value 7832
Command (m for help): W / / Save all and exit, partition finished
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 at
The next reboot or after you run partprobe (8) or kpartx (8)
Syncing disks.
Third, our new partition / dev/sda3 is not LVM's. So, next, use fdisk to change it to LVM's
# fdisk / dev/sda
Command (m for help): M
Command (m for help): t / / change the partition system id
Partition number (1-4): 3 / / specify the partition number
Hex code (type L to list codes): 8e / / specifies the id number to be changed, and 8e represents LVM
Changed system type of partition 3 to 8e (Linux LVM)
Command (m for help): W
Fourth, after restarting the system, log in to the system. (be sure to restart the system, otherwise the new partition cannot be expanded)
Format the newly added partition
# fdisk-l
Disk / dev/sda: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00008d26
Device Boot Start End Blocks Id System
/ dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/ dev/sda2 64 2611 20458496 8e Linux LVM
/ dev/sda3 2611 7832 41939020 8e Linux LVM
Disk / dev/mapper/VolGroup-lv_root: 18.9 GB, 18865979392 bytes
255 heads, 63 sectors/track, 2293 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk / dev/mapper/VolGroup-lv_swap: 2080 MB, 2080374784 bytes
255 heads, 63 sectors/track, 252 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
You will find that there is an extra partition.
# mkfs-t ext3 / dev/sda3 / / create a "ext3" file system on the hard disk partition "/ dev/sda3"
Mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
2621440 inodes, 10484755 blocks
524237 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
320 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208
4096000, 7962624
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 23 mounts or
180 days, whichever comes first. Use tune2fs-c or-i to override.
At this point, we can use the new partition:
VI. Expansion of the new partition
# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
Lv_root VolGroup-wi-ao---- 17.57g
Lv_swap VolGroup-wi-ao---- 1.94g
# pvcreate / dev/sda3
Physical volume "/ dev/sda3" successfully created
The # pvcreate / dev/sda3 / / pvcreate directive is used to initialize a physical hard disk partition into a physical volume for use by LVM. To create a physical volume, you must partition the hard disk and set the type of hard disk partition to "8e" before initializing the partition to a physical volume using the pvcreat directive
Physical volume "/ dev/sda3" successfully created
# df-h
Filesystem Size Used Avail Use% Mounted on
/ dev/mapper/VolGroup-lv_root 18G 1.7G 15G 10% /
Tmpfs 1.9G 0 1.9G 0% / dev/shm
/ dev/sda1 485M 32m 428M 7% / boot
# vgextend / dev/mapper/VolGroup-lv_root / dev/sda3 / / where is the lvm group name that needs to be expanded, which can be viewed through df-h. For example, my: / dev/mapper/VolGroup-lv_root) / / vgextend directive is used to dynamically extend the volume group, which increases the capacity of the volume group by adding physical volumes to the volume group.
Volume group name VolGroup/lv_root has invalid characters
# vgextend / dev/mapper/VolGroup / dev/sda3 / / originally this group name is-- the previous string-- if there is no article looking at the comparative analysis, who knows?
Volume group "VolGroup" successfully extended
# vgdisplay / / used to display metadata information for LNM volume groups
-Volume group
VG Name VolGroup
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 59.50 GiB
PE Size 4.00 MiB
Total PE 15232
Alloc PE / Size 4994 / 19.51 GiB
Free PE / Size 10238 / 39.99 GiB
VG UUID Ecv3ml-86eg-LTsH-mALD-mLxW-v3Ao-GEqiFc
(mainly see Free PE / Size 10238 / 39.99GiB, which shows that we can expand 39.99GB at most. I usually choose less than or equal to 39.99GB)
# lvextend-L + 39.99G / dev/VolGroup/lv_root / dev/sda3
Rounding size to boundary between physical extents: 39.99 GiB
Extending logical volume lv_root to 57.56 GiB
Logical volume lv_root successfully resized
# e2fsck-f / dev/VolGroup/lv_root
E2fsck 1.41.12 (17-May-2010)
/ dev/VolGroup/lv_root is mounted.
E2fsck: Cannot continue, aborting.
# resize2fs / dev/VolGroup/lv_root (if this step is wrong, the reason for switching to xfs_growfs/dev/VolGroup/lv_root is said to be the xfs file system)
Resize2fs 1.41.12 (17-May-2010)
Filesystem at / dev/VolGroup/lv_root is mounted on /; on-line resizing required
Old desc_blocks = 2, new_desc_blocks = 4
Performing an on-line resize of / dev/VolGroup/lv_root to 15089664 (4k) blocks.
The filesystem on / dev/VolGroup/lv_root is now 15089664 blocks long.
# df-h
Filesystem Size Used Avail Use% Mounted on
/ dev/mapper/VolGroup-lv_root 57G 1.7G 53G 3% /
Tmpfs 1.9G 0 1.9G 0% / dev/shm
/ dev/sda1 485M 32m 428M 7% / boot
This is the answer to the question about how to expand the virtual machine root partition disk in CentOS. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.
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.