linux新增一块硬盘加入原有分区

原有硬盘空间已经不足,添加一块新硬盘,并且加入到原根目录下

 

查看新硬盘

1
2
fdisk -l
Disk /dev/sdb: 240.1 GB, 240057409536 bytes

在新硬盘上创建Lvm分区

 

1
2
     
fdisk /dev/sdb

 


输入输出如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-29185, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-29185, default 29185):
Using default value 29185
  
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)
  
Command (m for help): p
  
Disk /dev/sdb: 240.1 GB, 240057409536 bytes
255 heads, 63 sectors/track, 29185 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x40044fad
  
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1       29185   234428481   8e  Linux LVM
Partition 1 does not start on physical sector boundary.
  
Command (m for help): w

 

查看分区

1
2
3
4
fdisk -l
  
 Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1       29185   234428481   8e  Linux LVM

 

可以看到已经成功创建了LVM分区: /dev/sdb1

 

建立物理卷 

1
pvcreate /dev/sdb1

 

查看原有VG

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[root@localhost ~]# vgdisplay
  --- Volume group ---
  VG Name               VolGroup
  System ID            
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  9
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               111.30 GiB
  PE Size               4.00 MiB
  Total PE              28492
  Alloc PE / Size       28378 / 110.85 GiB
  Free  PE / Size       114 / 456.00 MiB

可以看到VG Name为VolGroup

 

下一步是将PV加入到原有VG中

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[root@localhost ~]# vgextend VolGroup /dev/sdb1
  Volume group "VolGroup" successfully extended
[root@localhost ~]# vgdisplay
  --- Volume group ---
  VG Name               VolGroup
  System ID            
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  10
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               334.86 GiB
  PE Size               4.00 MiB
  Total PE              85725
  Alloc PE / Size       28378 / 110.85 GiB
  Free  PE / Size       57347 / 224.01 GiB

 

VG Size已经改变

 

调整LV的空间  

1
2
3
4
5
6
7
8
9
[root@localhost ~]# lvextend -L +220G /dev/VolGroup/lv_root
Extending logical volume lv_root to 313.00 GiB
Logical volume lv_root successfully resized
[root@localhost ~]# df -h
文件系统          容量  已用  可用 已用%% 挂载点
/dev/mapper/VolGroup-lv_root
                       92G   61G   27G  70% /
tmpfs                 7.8G   88K  7.8G   1% /dev/shm
/dev/sda1             485M   32M  428M   7% /boot

 

可以看到调整后并没有马上增加,需要resize2fs

1
2
3
4
5
6
[root@localhost ~]# resize2fs -p /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 = 6, new_desc_blocks = 20
Performing an on-line resize of /dev/VolGroup/lv_root to 82051072 (4k) blocks.
The filesystem on /dev/VolGroup/lv_root is now 82051072 blocks long.

 

再次查看,已经成功显示。

1
2
3
4
5
6
[root@localhost ~]# df -h
文件系统          容量  已用  可用 已用%% 挂载点
/dev/mapper/VolGroup-lv_root
                      309G   61G  233G  21% /
tmpfs                 7.8G   88K  7.8G   1% /dev/shm
/dev/sda1             485M   32M  428M   7% /boot

 

done!

 

如果上文中的PV VG LV  等概念、命令不清楚,建议先看看LVM的基础知识再操作。

 

posted on 2014-04-21 17:55  solohac  阅读(545)  评论(0编辑  收藏  举报

导航