REDHAT7 LVM partition Scheme to achieve seamless expansion of Mount point

Source: Internet
Author: User

The LVM-formatted partitioning scheme can increase and subtract the partition's size freely after the initial partition. A server's disk consumption is gradually increasing close to the partition size, you can install another hard disk on the server and the capacity of the new hard drive into the original logical partition, the process is very fast, the server does not need terminals, the process does not need to stop. is a very convenient way to manage disk.

In general, when installing the Redhat server, set up the use of LVM partition scheme, reduce the trouble of later configuration.


First, when we use the CD to install REDHAT7, select "Install location"


Then be sure to select "I want to configure partitions" To manually configure mount points and set the partition format


Click "Finish" and then let you select the partition scheme, select LVM, and click the plus sign to set the mount point.



To set an initial capacity size for different mount points, you do not need to partition all the disks cleanly, because you can also use the LVM tool to add unallocated space to the mount point later


After adding mount points, also select the device type "LVM" and set the file system format format. Here is a default volume group Rhel.

Note: A volume group can be understood as a virtual hard disk, this virtual hard disk is scalable, can be free to add and subtract capacity, can be a lot of physical hard disk (or physical hard disk inside the physical partition) together to form a volume group, the volume group is generally expressed in VG. With VG, you can divide the logical partitioning--LV in VG, and logical partitions are generally the various mount points we choose, such as/home,/tmp,/var,swat and so on, if you choose mount point then they become logical partitions. Let's say that at first we gave/home 10GB, then the amount of data exceeded 9GB is not enough, you can immediately add a new hard disk or the source hard disk unallocated capacity allocated to/home.


After the mount point is configured, click "Finish" in the top left corner to complete the configuration of the server operating system.



When a certain mount point of the server is about to be full, we add a new hard drive or unallocated capacity from the original hard disk to the volume group Rhel, and then allocate it to a mount point to complete the expansion of the logical partition.

Assuming that the disk is almost full now, but the original hard disk has some unallocated space, the following to the source hard disk space to join the logical partition.

You can first use Df-h to view the current mount points:

[root@localhost ~]# df-h
file system               capacity  used  available% mount point
/dev/mapper/rhel-root   50G  4.5G   43G   10%/
devtmpfs               7.8G     0  7.8G    0%/dev
tmpfs                  7.8G  228K  7.8G    1% /dev/shm
tmpfs                  7.8G   18M  7.8G    1%/run
tmpfs                  7.8G     0  7.8G    0%/sys /fs/cgroup
/dev/sda1              190M  133M   44M   76%/boot
/dev/mapper/rhel-tmp   9.8G   37M  9.2G    1%/tmp
/dev/sr0               3.8G  3.8G     0  100%/run/media/alex/rhel-7.2 server.x86 _64
tmpfs                  1.6G   88K  1.6G    1%/run/user/0
tmpfs                  1.6G   16K  1.6G    1% /RUN/USER/42
/dev/mapper/rhel-home  4.8G   37M  4.6G    1%/home



Note The df-h command sees only the partitions and capacities that have been mounted, the hard disk that is not mounted, and the capacity that is not allocated on the existing hard disk, and you can use Fdisk-l to view the physical hard drive.


[root@localhost ~]# fdisk-l disk/dev/sda:214.7 GB, 214748364800 bytes, 419.4304 million sectors Units = Sector of 1 *-The bytes sector size (      Logical/Physical): 512 Bytes/512 bytes I/o size (min/best): 512 Bytes/512 bytes disk label type: DOS disk identifier: 0X0001B91A device Boot Start End    Blocks Id system/dev/sda1 * 2048 411647 204800 411648 180774911 90181632 8e Linux LVM disk/dev/mapper/rhel-root:53.7 GB, 53687091200 bytes, 104.8576 million sectors Units = Sector of 1 * the BYT  ES sector size (logical/Physical): 512 Bytes/512 bytes I/o size (min/best): 512 Bytes/512 bytes Disk/dev/mapper/rhel-swap:17.2 GB, 17179869184 bytes, 33554432 Sector Units = Sector of 1 * The bytes sector size (logical/Physical): 512 Bytes/512 bytes I/o size (min/best): 512 Bytes/512 bytes Disk/dev/mapper/rhel-t  mp:10.7 GB, 10737418240 bytes, 20,971,520 sectors Units = Sector of 1 * = bytes sector size (logical/Physical): 512 Bytes/512 bytes I/o size (min/best): 512 bytes /512-byte disk/dev/mapper/rhel-home:5368 MB, 5368709120 bytes, 10,485,760 sectors Units = Sector of 1 * = bytes sector size (logical/Physical): 5 12 Bytes/512 bytes I/O size (minimum/best): 512 Bytes/512 bytes 



From here, we see/DEV/SDA this is a hard drive, the total size of this hard drive is 214.7 Gb,/dev/sda1,sda2,sda3 is a physical partition (PV) that is drawn from this disk, where sda2 is mounted on/;/home;swat;/ TMP, and so on Mount point. A total of about 50G of capacity is allocated. SDA1 is the boot partition, 200m.

After removing the sda1,sda2, there is 122G space left, the following is to add more than 100 g to the existing logical partitions

First look at the current hard drive structure


Below, draw a new physical partition from the 122G remaining space, using Fdisk

Fdisk/dev/sda

Input m for help

Command Operation
   A   toggle a bootable flag
   B   Edit BSD Disklabel
   c   Toggle the DOS compatibility flag
   D   Delete a partition
   g   Create a new empty GPT partition table
   g   Create an IRIX (SGI) partition table< C12/>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)



Enter n Create a new partition, generally use the default starting position, then enter a size, the last input w save and write to the partition table

Command (input m get help): N
Partition type:
   P   Primary (2 primary, 0 extended, 2 free)
   e   extended
Select ( Default p): P
-area code (3,4, default 3): 3
starting sector (180774912-419430399, default = 180774912):
will use default value 180774912 last
sector, + sector O R +size{k,m,g} (180774912-419430399, default 419430399): +10GB
partition 3 has been set to the Linux type, the size is set to 9.3 GiB

command (input M get help): W
T He 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 is used at the
next reboot or after you run Partprobe (8) or KPARTX (8)
is synchronizing the disk.

And then run

Partprobe/dev/sda


Before you can update the partition table and then observe the allocation of the disk, the new 10GB partition is already separated. If you do not execute this sentence, then, like no partitions, can not mount, you can only restart the computer to fail. So be sure to execute.



Note that at this point the partition type is not LVM (running Fdisk discovery ID is not 8e) and needs to be changed to LVM. (Note that you can also use the T command to enter the 8e completion when you partition the new partition above)

After you change it, be aware that if the "content" item is not a "LVM2 physical volume (LVM2 001)" Then you may not find the volume if you want to add a physical volume (PV) to the VG below. This is generally the case with a previously formatted disk.

[root@localhost ~]# fdisk-l

disk/dev/sda:214.7 GB, 214748364800 bytes, 419.4304 million sectors
Units = Sector of 1 * The bytes
sector size (logical/Physical): 512 Bytes/512 bytes
I/o size (min/best): 512 Bytes/512 bytes
disk label type: dos
disk identifier: 0x0001b91a

   device Boot      Start end      Blocks   Id  System
/dev/sda1   *        2048      411647      204800  Linux
/dev/sda2          411648   180774911    90181632   8e  Linux LVM
/dev/sda3       180774912   200306687     9765888  Linux




And then the physical partitions are just done, below we just need to add this new physical partition to the Rhel VG, only to be divided into VG, to achieve the expansion of a mount point, after the expansion, a mount point can use two or more physical volumes (PV) or physical hard disk, Solve a problem with insufficient capacity of a mount point.

For convenience, use the graphical interface SYSTEM-CONFIG-LVM, which can be found in the Redhat6 disc, but REDHAT7 has been removed, but the RPM package on the 6 CD can be taken out and mounted on the REDHAT7. System-config-lvm-1.1.12-17.el6.noarch Download Address: http://download.csdn.net/download/lvshaorong/9975218

First look at the virtual volumes before the new physical volumes are added



You can see that a portion of the physical volume is mapped to a logical volume, and now we're going to put the new physical volume into the Rhel logical volume group



Note: If you click on "Extended Volume group", there is no physical volume or the physical volume you want, you need to manually add PV to the VG by using the command line, as follows (this typically occurs when the hard disk or the current partition is moved to it before, and you need to reformat and erase the data):

[Root@oa-app ~]# vgextend rhel/dev/sda3 WARNING:EXT4 Signature detected On/dev/sda3 at
offset 1080. Wipe it? [y/n]: y
  wiping Ext4 signature On/dev/sda3.
  Physical volume "/dev/sda3" successfully created volume
  Group "Rhel" successfully extended

After executing the above command, the "content" of disk Management will also become "LVM2 physical volume (LVM2 001)"

Then it's easy to add it, no need to reboot, no need to interrupt, it's done in less than a second.


Now that we have capacity in the Rhel logical volume group, we can add this piece of capacity to the/home mount point, which means that/home mount is not just a/dev/sda2, but also a/dev/sda3 mount. Methods are as follows


Click OK to enlarge the success, do not need to restart, do not need to kill the process.

Then you can use Df-h to see if the rest of the space has increased

Expansion is easier,/home this mount point can also be reduced, but the reduction is more troublesome, the first to umount mount point/home,umount before all the process of reading and writing/home killed, but also to all the hard drive monitoring software to stop. To be able to shrink. So performing a scaling operation typically interrupts the current service. After the reduction of the original logical partition of the physical location will be divided into two physical intervals, to reduce the number of logical partitions so the physical hard disk will become thin and brittle, so generally do not recommend reduction.


Postscript:

In general, if you use a virtualized host to add a hard disk, you need to reboot in order to recognize it, but if you restart it, you will not see this hard drive, but generally we do not want to reboot the host, so we need to realize the function of the virtual hard disk hot plug, the scheme is as follows I've tested it. It works: quoting http://zshou.is-programmer.com/posts/39489.html

To view current disk information

Cat/proc/scsi/scsi

I returned the following results: attached DEVICES:HOST:SCSI1 channel:00 id:00 lun:00 vendor:necvmwar model:vmware IDE CDR10 rev:1.00  Type:cd-rom ANSI SCSI revision:05 host:scsi2 channel:00 id:00 lun:00, Model:vmware Virtual S rev:1.0 type:direct-access ANSI SCSI revision:02

Above SCSI1 is the optical drive, SCSI2 that device is my system hard drive.

3. Add hard disk device
echo "SCSI add-single-device 2 0 1 0" >>/PROC/SCSI/SCSI
Digital parameter Description: The default to add a hard disk and the original system hard disk is the same group, the first number is SCSI2 here 2, the second is channel here is 0, the third is the ID, the original value above the 1,lun default is 0. Then use CAT/PROC/SCSI/SCSI can see the hard drive information, fdisk-l, can see/dev/sdb hard drive.

If you need to remove the hard drive you just added, use echo "SCSI remove-single-device 2 0 1 0" >>/proc/scsi/scsi, Replaced the Add-single-device with Remove-single-device, the other same.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.