通过LVM 扩容挂载硬盘



需求: VM下 在原来挂载硬盘的基础上,通过LVM扩容此硬盘。  不需要额外挂载硬盘

1、显示硬盘及所属分区情况
[root@localhost ~]# fdisk -l
Disk /dev/sda: 60 GiB, 64424509440 bytes, 125829120 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x8d75991a

Device     Boot     Start       End   Sectors Size Id Type
/dev/sda1  *         2048 121634815 121632768  58G 83 Linux
/dev/sda2       121636862 125827071   4190210   2G  5 Extended
/dev/sda5       121636864 125827071   4190208   2G 82 Linux swap / Solaris

Disk /dev/sdb: 19 GiB, 41875931136 bytes, 81788928 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x0cbd968b

2、分区:

[root@localhost ~]# fdisk /dev/sdb

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): p

Disk /dev/sdb: 19 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x44817895

   Device Boot      Start         End      Blocks   Id  System

增加三个分区的操作/dev/sdb1
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p ##分区类型
Partition number (1-4): 1 
First cylinder (1-6527, default 1):
Using default value 1     ##起始块
Last cylinder, +cylinders or +size{K,M,G} (1-6527, default 6527):  回车

Command (m for help): t
Partition number (1-4): 1
Hex code (type L to list codes): 8e
Changed system type of partition 3 to 8e (Linux LVM)

Command (m for help): p



Disk /dev/sdb: 19 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x44817895

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1306    10490413+  8e  Linux LVM


Command (m for help): w                      ##最后记得保存,写入分区表
The partition table has been altered!

3、创建物理卷PV

[root@localhost ~]# pvcreate /dev/sdb1  
  Physical volume "/dev/sdb1" successfully created  #创建成物理卷

4、创建卷组VG

创建卷组vg_server1 将物理卷/dev/sdb1 加入卷组vg_server1 

[root@localhost ~]# vgcreate vg_server1 /dev/sdb1
  Volume group "vg_server1" successfully created
[root@localhost ~]#

5、创建逻辑卷lV

分在卷组vg_server1创建逻辑卷

[root@localhost ~]# lvcreate -L 19G -n vg_server1_lvm1 vg_server1    # -L指定卷大小,-n 指定逻辑卷名
  Logical volume "vg_server1_lvm1" created.                                        #指定跟卷组名
[root@localhost ~]#

[root@localhost ~]# lvdisplay  #查看生成的逻辑卷

  --- Logical volume ---
  LV Path                /dev/vg_server1/vg_server1_lvm1
  LV Name                vg_server1_lvm1
  VG Name                vg_server1
  LV UUID                j4UX2E-LuRf-WKgW-9KGH-dBb3-RvAK-PXcORB
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2016-04-14 00:20:54 +0800
  LV Status              available
  # open                 0
  LV Size                19.00 GiB
  Current LE             3840
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

6、格式化

[root@localhost ~]# mke2fs -t ext4 /dev/vg_server1/vg_server1_lvm1
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
inodes, 3932160 blocks
blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=4026531840
block groups
blocks per group, 32768 fragments per group
inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208

正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

This filesystem will be automatically checked every 20 mounts or
days, whichever comes first.  Use tune2fs -c or -i to override.

7 创建目录/mnt/lvm1挂载生成逻辑卷

[root@localhost vg_server1]# mount /dev/vg_server1/vg_server1_lvm1 /mnt/lvm1



8、LVM 扩容

VM下载硬盘里从19G改为29G
然后进行分区 

root@ubuntu:~# 
root@ubuntu:~# fdisk -l

Disk /dev/sda: 60 GiB, 64424509440 bytes, 125829120 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x8d75991a

Device     Boot     Start       End   Sectors Size Id Type
/dev/sda1  *         2048 121634815 121632768  58G 83 Linux
/dev/sda2       121636862 125827071   4190210   2G  5 Extended
/dev/sda5       121636864 125827071   4190208   2G 82 Linux swap / Solaris

Disk /dev/sdb: 39 GiB, 41875931136 bytes, 81788928 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x0cbd968b

Device     Boot Start      End  Sectors Size Id Type
/dev/sdb1        2048 39845887 39843840  19G 8e Linux LVM

Disk /dev/mapper/vg_server1-vg_server1_lvm1: 18 GiB, 19327352832 bytes, 37748736 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

#######################################################################################################

root@ubuntu:~# fdisk /dev/sdb 

Welcome to fdisk (util-linux 2.25.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk /dev/sdb: 39 GiB, 41875931136 bytes, 81788928 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x0cbd968b

Device     Boot Start      End  Sectors Size Id Type
/dev/sdb1        2048 39845887 39843840  19G 8e Linux LVM


Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2): 2
First sector (39845888-81788927, default 39845888): 
Last sector, +sectors or +size{K,M,G,T,P} (39845888-81788927, default 81788927): 

Created a new partition 2 of type 'Linux' and of size 20 GiB.

Command (m for help): t
Partition number (1,2, default 2): 2
Hex code (type L to list all codes): 8e

Changed type of partition 'Linux' to 'Linux LVM'.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: 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).

#############################################################################################################

root@ubuntu:~# fdisk -l

Disk /dev/sda: 60 GiB, 64424509440 bytes, 125829120 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x8d75991a

Device     Boot     Start       End   Sectors Size Id Type
/dev/sda1  *         2048 121634815 121632768  58G 83 Linux
/dev/sda2       121636862 125827071   4190210   2G  5 Extended
/dev/sda5       121636864 125827071   4190208   2G 82 Linux swap / Solaris

Disk /dev/sdb: 39 GiB, 41875931136 bytes, 81788928 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x0cbd968b

Device     Boot    Start      End  Sectors Size Id Type
/dev/sdb1           2048 39845887 39843840  19G 8e Linux LVM
/dev/sdb2       39845888 81788927 41943040  20G 8e Linux LVM


分完区后 执行下面命令, 不然识别不到新分的去
root@ubuntu:~# partprobe


#将分区/dev/sdb2创建为物理卷
root@ubuntu:~# pvcreate /dev/sdb2
  Physical volume "/dev/sdb2" successfully created

root@ubuntu:~# vgextend vg_server1 /dev/sdb2     #将物理卷/dev/sdb2 加入卷组vg_server1
  Volume group "vg_server1" successfully extended


扩容/dev/vg_server1/vg_server1_lvm1逻辑卷,其中-L指定大小,#+5G 容量增加5G ,如果没有”+“ 表示扩展到多少

root@ubuntu:~# lvextend -L +10G /dev/vg_server1/vg_server1_lvm1 /dev/sdb2 
  Extending logical volume vg_server1_lvm1 to 28.00 GiB
  Logical volume vg_server1_lvm1 successfully resized
  
[root@localhost lvm1]# /sbin/resize2fs /dev/vg_server1/vg_server1_lvm1                                   #最后记得用命令resize 扩展逻辑大小  

df查看

root@ubuntu:~# df -h
Filesystem                              Size  Used Avail Use% Mounted on
/dev/sda1                                57G  6.6G   48G  13% /
none                                    4.0K     0  4.0K   0% /sys/fs/cgroup
udev                                    988M  4.0K  988M   1% /dev
tmpfs                                   201M  500K  200M   1% /run
none                                    5.0M     0  5.0M   0% /run/lock
none                                   1001M     0 1001M   0% /run/shm
none                                    100M     0  100M   0% /run/user
/dev/mapper/vg_server1-vg_server1_lvm1   28G   44M   26G   1% /opt














































 

转载于:https://my.oschina.net/u/3170201/blog/814874

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值