linux two disk expansion

When insufficient LVM partition space, can be expansion. Major expansion in two ways:

For expansion through spare disk, this method is relatively simple, it does not affect the original data.
The other part of the LVM partition space taken LVM partition in need of expansion.
The following were detailed description of these two methods.

Check the system disk
when using the df -h command to view disk usage of the system, as shown below.

[Home the root @ localhost] # DF -H
the Filesystem Size Used Avail the Use% Mounted ON
/ dev / Mapper / volgroup-lv_root
51G 25G 24G, 49% /
tmpfs 935M 0 935M 0% / dev / SHM
/ dev / 93M 360M 21 is 477m xvda1 % / Boot
/ dev / Mapper / volgroup-lv_home
199g 189g. 1% 60M / Home
use of free expansion of the disk
1. first, using the fdisk -l command to view the disk, this system has two hard disks, / dev / xvda 274.9G, / dev / xvdb 10.7G

[Home the root @ localhost] # the fdisk -l

Disk / dev / xvdb: 10.7 GB, 10737418240 bytes
255 Heads, 63 is sectors / Track, 1305 Cylinders
Units = Cylinders of 16065 * 512 = 8.22528 million bytes
Sector size (Logical / PHYSICAL): 512 bytes / 512 bytes
the I / O size (Minimum / Optimal): 512 bytes / 512 bytes

2. Create pv, the disk / dev / xvdb pvcreate command created by a PV system

[Home the root @ localhost] # the pvcreate / dev / xvdb
the Physical Volume "/ dev / xvdb" Created successfully

3. Add the PV / dev / xvdb VolGroup in the volume group. The disk has been added to the VolGroup, and increased space volume group 10G. Use the command vgextend VolGroup / dev / xvdb

[Home the root @ localhost] # the vgextend volgroup / dev / xvdb
Volume Group "volgroup" Extended successfully
[Home the root @ localhost] # Vgs
VG of the Attr #PV #LV #SN VSize vfree
volgroup WZ 2. 3 0 - 0 N- 265.50g

4. / 10G to add space. Use command lvextend -L + 10G / dev / mapper / VolGroup-lv_root

[Home the root localhost @] + # 1OG the lvextend -L / dev / Mapper / volgroup-lv_root
Size of Logical Volume volgroup / lv_root changed from 50.98 GiB (13050 extents) to 55.98 GiB (14330 extents).
the Logical Volume Resized lv_root successfully

. 5. after the logical Volume expansion will not immediately take effect, you need to use the "resize2fs" command to reload the logical volume size. Use the command resize2fs / dev / VolGroup / lv_root. Then use the command df -h to view the find / have more than 10G.

[root@localhost home]# resize2fs /dev/VolGroup/lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/VolGroup/lv_root is mounted on /; on-line resizing required
old desc_blocks = 4, new_desc_blocks = 4
Performing an on-line resize of /dev/VolGroup/lv_root to 14673920 (4k) blocks.
The filesystem on /dev/VolGroup/lv_root is now 14673920 blocks long.


[root@localhost home]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
60G 24G 34G 41% /
tmpfs 935M 0 935M 0% /dev/shm
/dev/xvda1 477M 93M 360M 21% /boot
/dev/mapper/VolGroup-lv_home
199G 60M 189G 1% /home

利用其他LVM分区空余空间进行扩容
1. Use df -h to view usage for each partition. As found / dev / mapper / VolGroup-lv_home capacity is sufficient, this expansion by reducing the / dev / mapper / VolGroup-lv_home space to / dev / mapper / VolGroup-lv_root.

[root@localhost home]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
60G 24G 34G 41% /
tmpfs 935M 0 935M 0% /dev/shm
/dev/xvda1 477M 93M 360M 21% /boot
/dev/mapper/VolGroup-lv_home
199G 60M 189G 1% /home

2. 卸载/home

[the root @ localhost Home] # umount / Home
umount: / Home:. Device IS BUSY
(the In some Cases Useful info About Processes that use
The Device IS found by the lsof (. 8) or the fuser (. 1))

umount / Home if the tips do not uninstall, because of the process of occupation / home, use the following command to terminate the occupation process:

[root @ localhost Home] # fuser -m / Home
/ Home: 1463c

If you still can not be uninstalled, use the following command:

[Home the root @ localhost] # umount -l / Home

3. adjust / dev / mapper / VolGroup-lv_home partition size

We need to detect the disk, enter the command e2fsck -f / dev / mapper / VolGroup  -lv_home.
Note: encountered Abort <y> input side is n, in order to proceed?.

[root@localhost ~]# e2fsck -f /dev/mapper/VolGroup-lv_home
e2fsck 1.41.12 (17-May-2010)
The filesystem size (according to the superblock) is 52848640 blocks
The physical size of the device is 52592640 blocks
Either the superblock or the partition table is likely to be corrupt!
Abort<y>? no

Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/VolGroup-lv_home: 26/13213696 files (0.0% non-contiguous), 877250/52848640 blocks

然后输入命令resize2fs -p /dev/mapper/VolGroup-lv_home 100G,进行磁盘重订大小。

[root@localhost ~]# resize2fs -p /dev/mapper/VolGroup-lv_home 100G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/VolGroup-lv_home to 26214400 (4k) blocks.
Begin pass 2 (max = 32768)
Relocating blocks XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 3 (max = 1613)
Scanning inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/mapper/VolGroup-lv_home is now 26214400 blocks long.
4. 重新挂载/home

After remounting the input df -h, found / dev / mapper / VolGroup-lv_home has [root @ localhost ~] # mount / home


[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
60G 24G 34G 41% /
tmpfs 935M 0 935M 0% /dev/shm
/dev/xvda1 477M 93M 360M 21% /boot
/dev/mapper/VolGroup-lv_home
99G 60M 94G 1% /home

5. 设置空闲空间

Use the command vgdisplay, you can see Free PE / Size 25760 / 100.62 GiB, with 100G of free space. Or use the vgs command

[root@localhost ~]# lvreduce -L 100G /dev/mapper/VolGroup-lv_home
WARNING: Reducing active and open logical volume to 100.00 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv_home? [y/n]: y
Size of logical volume VolGroup/lv_home changed from 200.62 GiB (51360 extents) to 100.00 GiB (25600 extents).
Logical volume lv_home successfully resized
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name VolGroup
Free PE / Size 25760 / 100.62 GiB
VG UUID hQoxGl-H4T9-Lu9W-sITN-hO2B-aos7-T5TmKC

6. 把闲置空间挂在到根目录下

[the root localhost ~ @] + # 100.62G the lvextend -L / dev / Mapper / volgroup-lv_root
a Rounding size to boundary extents BETWEEN PHYSICAL: 100.62 GiB
Size of Logical Volume volgroup / lv_root changed from 60.97 GiB (15609 extents) to 161.59 GiB ( extents 41368).
the Logical Volume Resized lv_root successfully

use the command resize2fs -p / dev / mapper / volGroup -lv_root, can not restart, it displays the latest of disk space.

[root@localhost ~]# resize2fs -p /dev/mapper/VolGroup-lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/VolGroup-lv_root is mounted on /; on-line resizing required
old desc_blocks = 4, new_desc_blocks = 11
Performing an on-line resize of /dev/mapper/VolGroup-lv_root to 42360832 (4k) blocks.
The filesystem on /dev/mapper/VolGroup-lv_root is now 42360832 blocks long.
7. 最后结果

[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
159G 24G 128G 16% /
tmpfs 935M 0 935M 0% /dev/shm
/dev/xvda1 477M 93M 360M 21% /boot
/dev/mapper/VolGroup-lv_home

Reference blog
https://blog.csdn.net/weixin_44130166/article/details/86621425
 

Now there is such a situation, there is a disk usage is too high, more than 90%, so as not to affect the use, has now decided to mount point for expansion

There are two solutions

   A: Other underutilized mount point can be a soft link -> high utilization mount point (after write data is transferred to the high utilization rate is not high on the utilization of mount points on the mount point, the mount point to expansion in disguise)

   Two: the new disk and partition, format, mount

For now explain these two methods:

A soft link

First we look at the utilization of disk

df -h

We can find the root of utilization reached 90%, while the utilization of / dev / sdb this disc is 1%, so we chose this dish soft connection 

Here we should pay attention to doing a soft link, if the target file has data to make a soft link when it will not show, so we try to back up files

Copy the code
1. Create / tmp2 folder 
2.mkdir / tmp2 
3. New Disk / tmp 
cd / the Data / htdocs / Topic / Resource 
mkdir -m 1777 tmp 
files under 4. backup / tmp 
cp sess * / tmp2 
5. Create a soft link 
ln -s / data / htdocs / topic / resource / tmp / tmp
Copy the code

Second, the new disk expansion

Copy the code
Vmvare go on increasing the size of the disk or disks in the new matrix in a tray 

(1) Linux operating system boot VMware environment, add a new partition, you need the root account status. 

[1.1] The maximum partition fdisk -l / dev / sda2, explained the newly created partition will be sda3 

1.2 input [fdisk / dev / sda] 

1.2.1 Input command line prompt [m] 

1.2.2 [n enter the command ] add a new partition. 

1.2.3 Enter the command [p] create a primary partition. 

1.2.4 Input [Enter], select the default size, so do not waste space 

1.2.5 Input [Enter], select the default start cylinder. 

1.2.6 Input [w] and keep modifying 

1.3 Input [reboot] to restart linux, you must reboot, or / dev / sda4 can not be formatted. 
    Partprobe or perform [] to force the kernel to re-find a partition table 

1.4 in this case / dev / directory to see the new partition such as / dev / sda3 

1.5 [mkfs.ext3 / dev / sda3] format 
mkfs -t ext3 / dev / sda3 

1.6 Creating tmp2 directory in the root directory 
cd / 
mkdir tmp2 

1.7 save the file originally under the tmp 
cd / tmp 
cp sess * / tmp2 

1.7 [mount / dev / sda3 / tmp /] partition mount to / tmp / on

1.8 modify the vim / etc / fstab file, add [/ dev / sda3 / tmp ext3 defaults 0 0 ] line, and save, and boot automatically mount. 

At this point, the newly added disk space, it can on the / tmp reflect, and re-boot automatically mount the partition, disk space, additional work was done. 

If no current disk capacity may be wide, a method can increase the disk in the main interface VMware, VMware] [select pull-down menu and select [Settings], [with] Add a way to increase the disk, similar to the latter operation, will not be repeated.
Copy the code

Guess you like

Origin www.cnblogs.com/klb561/p/11960313.html