**************操作之前请看章节6,看系统是否支持LVM分区管理方式***************

1:新增磁盘

插入新的磁盘,比如物理机可以直接在卡槽插入,虚拟机可以在控制台添加磁盘或者扩充磁盘,如下图所示

2:查找新插入的磁盘名称

插入磁盘操作执行完以后,可以执行fdisk -l查看新磁盘的名称,如下面的文字所示,有一个1G的磁盘未分区,磁盘sda已分区,如下图所示/dev/sda1,/dev/sda2,/dev/sda3,/dev/sda4,/dev/sda5

---------------------------------------------------------------------------------------------------------------------------------

Disk /dev/sda: 40 GiB, 42949672960 bytes, 83886080 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: 0x08eecc1c

Device     Boot    Start      End  Sectors  Size Id Type

/dev/sda1  *        2048   999423   997376  487M 83 Linux

/dev/sda2        1001470 41940991 40939522 19.5G  5 Extended

/dev/sda3         999424  1001469     2046 1023K 83 Linux

/dev/sda4       41940992 83886079 41945088   20G 83 Linux

/dev/sda5        1001472 41940991 40939520 19.5G 8e Linux LVM

Partition table entries are not in disk order.

Disk /dev/sdb: 1 GiB, 1073741824 bytes, 2097152 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

由上面的操作可以看出,新的磁盘名称是/dev/sdb

3:对新增磁盘进行分区

登录系统,执行fdisk 新添加的磁盘名称,我这里新增加的磁盘是/dev/sdb

root@kingserver10:~# fdisk /dev/sdb

下面来到fdisk的分区工具的操作界面,会有一个过程

Welcome to fdisk (util-linux 2.27.1).

Changes will remain in memory only, until you decide to write them.

Be careful before using the write command.

Device does not contain a recognized partition table.

Created a new DOS disklabel with disk identifier 0x565ca282.

Command (m for help): p

Disk /dev/sdb: 1 GiB, 1073741824 bytes, 2097152 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: 0x565ca282

Command (m for help): n

Partition type

p   primary (0 primary, 0 extended, 4 free)

e   extended (container for logical partitions)

Select (default p): p

Partition number (1-4, default 1):

First sector (2048-2097151, default 2048):

Last sector, +sectors or +size{K,M,G,T,P} (2048-2097151, default 2097151):

Created a new partition 1 of type 'Linux' and of size 1023 MiB.

Command (m for help): w

The partition table has been altered.

Calling ioctl() to re-read partition table.

Syncing disks.

上面对新增磁盘分区的操作,下面查看一下分区是否成功,可以看到在sdb盘多了一个/dev/sdb1的分区,说明分区成功

root@kingserver10:~# fdisk -l

Disk /dev/sda: 40 GiB, 42949672960 bytes, 83886080 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: 0x08eecc1c

Device     Boot    Start      End  Sectors  Size Id Type

/dev/sda1  *        2048   999423   997376  487M 83 Linux

/dev/sda2        1001470 41940991 40939522 19.5G  5 Extended

/dev/sda3         999424  1001469     2046 1023K 83 Linux

/dev/sda4       41940992 83886079 41945088   20G 83 Linux

/dev/sda5        1001472 41940991 40939520 19.5G 8e Linux LVM

Partition table entries are not in disk order.

Disk /dev/sdb: 1 GiB, 1073741824 bytes, 2097152 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: 0x565ca282

Device     Boot Start     End Sectors  Size Id Type

/dev/sdb1        2048 2097151 2095104 1023M 83 Linux

Disk /dev/mapper/kingserver8--vg-root: 30.5 GiB, 32770097152 bytes, 64004096 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

Disk /dev/mapper/kingserver8--vg-swap_1: 8 GiB, 8589934592 bytes, 16777216 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

4:扩展文件分区

4.1:将新增物理硬盘分区初始化为物理卷

pvcreate命令用于将物理硬盘分区初始化为物理卷,以便LVM使用。

root@kingserver10:~# pvcreate /dev/sdb1

Physical volume "/dev/sdb1"
successfully created

4.2:查看VG NAME

root@kingserver10:~# vgdisplay

---
Volume group ---

VG
Name               kingserver8-vg

System ID

Format                lvm2

Metadata Areas        2

Metadata Sequence No  5

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               39.52 GiB

PE
Size               4.00 MiB

Total PE              10117

Alloc PE / Size       9861 / 38.52
GiB

Free  PE / Size       256 / 1.00 GiB

VG
UUID              
kBq0j1-qE2e-O1Ap-CURx-krhU-ydKi-lOZA4d

4.3:扩展VG

语法:vgextend vg-name 新增的要扩展的物理卷名称

root@kingserver10:~# vgextend
kingserver8-vg /dev/sdb1

Volume group "kingserver8-vg" successfully extended

4.4:查看 LV Path

要扩展的LV Path对应的是 root对应的LV Path,而不是swap对应的LV Path

root@kingserver10:~# lvdisplay

---
Logical volume ---

LV
Path               
/dev/kingserver8-vg/root

LV
Name                root

VG
Name                kingserver8-vg

LV
UUID               
19Bpd4-Yhe8-ZgEI-kQaD-oKav-n5O4-HXakw2

LV
Write Access        read/write

LV
Creation host, time kingserver8, 2017-12-07 18:21:36 +0800

LV
Status              available

#
open                 1

LV
Size                30.52 GiB

Current LE             7813

Segments               2

Allocation             inherit

Read ahead sectors     auto

-
currently set to     256

Block device           252:0

---
Logical volume ---

LV
Path               
/dev/kingserver8-vg/swap_1

LV
Name                swap_1

VG
Name                kingserver8-vg

LV
UUID               
xnTj8x-BcQd-24mH-gqZJ-v9Oa-bRm0-33x26V

LV
Write Access        read/write

LV
Creation host, time kingserver8, 2017-12-07 18:21:37 +0800

LV
Status              available

#
open                 2

LV
Size                8.00 GiB

Current LE             2048

Segments               1

Allocation             inherit

Read ahead sectors     auto

-
currently set to     256

Block device           252:1

4.5:扩展LV Path

语法:lvextend –L +新增的要扩展的物理卷大小
 root目录的LV-Path

root@kingserver10:~#  lvextend 
-L +1G /dev/kingserver8-vg/root

Size of logical volume kingserver8-vg/root changed from 30.52 GiB (7813
extents) to 31.52 GiB (8069 extents).

Logical volume root successfully resized.

4.6:重置主分区的大小

root@kingserver10:~# resize2fs
/dev/kingserver8-vg/root

resize2fs 1.42.13 (17-May-2015)

Filesystem at /dev/kingserver8-vg/root is
mounted on /; on-line resizing required

old_desc_blocks = 2, new_desc_blocks = 2

The filesystem on /dev/kingserver8-vg/root
is now 8262656 (4k) blocks long.

5:查看扩展后的文件系统

发现原来的/dev/mapper/kingserver8--vg-root从30G变为了31G说明扩展成功

root@kingserver10:~# df  -h

Filesystem                        Size  Used Avail Use% Mounted on

udev                              3.9G     0 
3.9G   0% /dev

tmpfs                             797M  9.0M 
788M   2% /run

/dev/mapper/kingserver8--vg-root   31G  
18G   12G  61% /

tmpfs                             3.9G     0 
3.9G   0% /dev/shm

tmpfs                             5.0M     0 
5.0M   0% /run/lock

tmpfs                             3.9G     0 
3.9G   0% /sys/fs/cgroup

/dev/sda1                         472M   57M 
391M  13% /boot

cgmfs                             100K     0 
100K   0% /run/cgmanager/fs

tmpfs                             797M     0 
797M   0% /run/user/0

root@kingserver10:~#

6:操作的可行性(LVM)

需要注意的是,并不是所有的磁盘都可以扩展,安装的时候需要支持LVM,LVM是什么?

如下:总之一句话,支持了LVM之后,新增加一个磁盘,就可以用来扩充文件分区的目录了;

LVM是逻辑盘卷管理(LogicalVolumeManager)的简称,它是Linux环境下对磁盘分区进行管理的一种机制,LVM是建立在硬盘和
分区之上的一个逻辑层,来提高磁盘分区管理的灵活性。通过LVM系统管理员可以轻松管理磁盘分区,如:将若干个磁盘分区连接为一个整块的卷组 (volumegroup),形成一个存储池。管理员可以在卷组上随意创建逻辑卷组(logicalvolumes),并进一步在逻辑卷组上创建文件系
统。管理员通过LVM可以方便的调整存储卷组的大小,并且可以对磁盘存储按照组的方式进行命名、管理和分配,例如按照使用用途进行定义:“development”和“sales”,而不是使用物理磁盘名“sda”和“sdb”。而且当系统添加了新的磁盘,通过LVM管理员就不必将磁盘的
文件移动到新的磁盘上以充分利用新的存储空间,而是直接扩展文件系统跨越磁盘即可。

7: 查看是否支持LVM

7.1、df  -h 可以看到root目录有vg的标示

7.2、vgdisplay ,可以看到vg name

7.3、lvdisplay 可以看到
LV path

Linux扩展文件分区的更多相关文章

  1. 为linux扩展swap分区

    1.查看当前swap分区使用情况 [root@localhost ~]# swapon -s Filename Type Size Used Priority /dev/sda2            ...

  2. linux img文件 分区挂载

    首先是将制作的img文件比如hd5.img和loop设备建立联系. losetup /dev/loop0 hd5.img 然后用fdisk分区:fdisk /dev/loop0 mkfs.ext4 / ...

  3. Linux扩展swap分区

    一.将sda磁盘进行分区: 先查看sda磁盘已经使用了多少主分区,如下图所示,主分区已使用3个,所以应选择扩展分区: 二.再将扩展分区进行分区: 三.分区完成后执行partprobe使系统重新识别分区 ...

  4. linux 扩展根分区

    参考链接:  http://blog.51cto.com/lubcdc/1763133

  5. linux mkfs命令参数及用法详解---linux格式化文件系统命令(包括swap分区)

    mkfs 命令  linux格式化磁盘命令           linux mkfs         指令:mkfs 使用权限 : 超级使用者 使用方式 : mkfs [-V] [-t fstype] ...

  6. NO21 Llinux的文件种类与扩展名--文件权限--软硬链接--Linux删除文件原理

    Linux的文件种类与扩展名 一.文件种类:1.普通文件(regular file)第一个字符为[ - ]包括:①纯文本档(ASCII):这是Linux系统中最多的一种文件类型,称为纯文本档.是因为内 ...

  7. linux的文件种类与扩展名

    一.文件种类: 1.普通文件(regular file)第一个字符为[ - ] 包括:①纯文本档(ASCII):这是Linux系统中最多的一种文件类型,称为纯文本档.是因为内容为我们人类可以直接读到的 ...

  8. 【Linux】文件种类与扩展名

    任何装置在Linux底下都是文件.不仅如此,连数据沟通的接口也有专属的文件在负责-所以,你会了解到,Linux的文件种类真的很多- Linux文件种类 我们在刚刚提到使用『ls -l』观察到第一栏那十 ...

  9. 【linux】lvm扩展根分区

    lvm扩展根目录 1.lvm的基本概念 physical volume (PV) 通常是一快硬盘.相当于一个物理设备,磁盘空间物理卷PV. volume group (VG) 相当于LVM的卷组,属于 ...

随机推荐

  1. centos docker compose安装

    docker compose离线安装 通过联网机器下载docker-compose离线安装包(参见Downloads部分) https://github.com/docker/compose/rele ...

  2. mongodb用mongoose查库的对象,不能增加属性

    node + koa2 + mongodb 写了一个给前端的接口 如果不是写这个接口,这辈子都发现不了mongodb里这个大坑 mongoose 是个ODM(Object Document Mappe ...

  3. Windows 7重启后USB 3.0无法使用的问题解决

    1.首先对主板USB3.0驱动程序进行重新安装 2.如果驱动程序重装后还是无法解决无法使用USB3.0设备的话,在win7桌面上找到“计算机”图标并鼠标右键,选择“管理”选项,找到设备管理器,然后找到 ...

  4. 使用SIGALRM信号为阻塞操作设置超时

    我们经常会遇到为阻塞操作设置超时的问题,比如说阻塞套接字read读取设置10秒超时,其中一个办法就是调用alarm函数,它在指定超时时期产生SIGALRM信号,使得阻塞操作中断. 但其弊端在于: 1. ...

  5. 移植Python3到TQ2440(二)

    接着前一篇博文. 在上一篇博文中我们用NFS挂载根文件系统的方式启动了系统,接下来我们把移植了Python3的根文件系统固化到NandFlash中,但是由于linux-4.9目前不支持Yaffs2文件 ...

  6. C#编程(四十)----------运算符重载

    运算符重载 所谓的运算符重载是指允许用户使用用户定义的类型编写表达式的能力. 例如,通常需要编写类似与以下内容的代码,入江两个数字相加,很明显,sum是两个数字之和. int i=5,j=4; int ...

  7. Javascript 身份证号获得出生日期、获得性别、检查身份证号码

    //---------------------------------------------------------- // 功能:根据身份证号获得出生日期 // 参数:身份证号 psidno // ...

  8. 【转】比较init-method,afterPropertiesSet和BeanPostProcessor

    一.简单介绍 1.init-method方法,初始化bean的时候执行,可以针对某个具体的bean进行配置.init-method需要在applicationContext.xml配置文档中bean的 ...

  9. yii开发第一部分之执行流程

    一 目录文件 |-framework 框架核心库 |--base 底层类库文件夹,包含CApplication(应用类,负责全局的用户请求处理,它管理的应用组件集,将提供特定功能给整个应用程序),CC ...

  10. localhost与127.0.0.1及本机ip的区别

    很多人会接触到这个ip地址127.0.0.1.也许你会问127.0.0.1是什么地址?其实127.0.0.1是一个回送地址,指本地机,一般用来测试使用.大家常用来ping 127.0.0.1来看本地i ...