博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Linux:磁盘挂载
阅读量:5018 次
发布时间:2019-06-12

本文共 13140 字,大约阅读时间需要 43 分钟。

本来虚拟centos的服务器的磁盘分配的就不大,之前只分配了20G的样子,由于最近有装了不少软件,比如nifi压缩版就有1.2G的大小,一下子没有磁盘资源了。今晚就折腾在这事上了。

[root@master spark]# df -hFilesystem               Size  Used Avail Use% Mounted on/dev/mapper/centos-root   17G   17G   20K 100% /devtmpfs                 2.4G     0  2.4G   0% /devtmpfs                    2.4G  4.0K  2.4G   1% /dev/shmtmpfs                    2.4G   12M  2.4G   1% /runtmpfs                    2.4G     0  2.4G   0% /sys/fs/cgroup/dev/sda1               1014M  142M  873M  14% /boottmpfs                    479M     0  479M   0% /run/user/1000

1. 查看挂载点信息

df -h

显示结果:根目录可用磁盘只有20K。

2. 扩展VMWare硬盘空间

首先需要关闭操作系统,然后在设置中将磁盘调整到需要的容量。

如果选项是灰色的,说明虚拟机有快照,将其快照删除再操作。

备注:这里通过vmw,扩展master节点10G磁盘资源。

3. 对新增加的硬盘进行分区、格式化

(1)查看一下调整后的磁盘状态

[root@master spark]# fdisk -lDisk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x000aad3c   Device Boot      Start         End      Blocks   Id  System/dev/sda1   *        2048     2099199     1048576   83  Linux/dev/sda2         2099200    41943039    19921920   8e  Linux LVMDisk /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytes

备注:新增磁盘驱动目录为/dev/sda1,大小为10G。

(2)磁盘分区

[root@master]# fdisk /dev/sda

分别键入以下参数:

p       查看已分区数量(我看到有两个 /dev/sda1 和/dev/sda2)

n       新增加一个分区
p       分区类型,选择主分区
        分区号选3(1和2已占用,见上)
回车     默认选择(起始扇区)
回车     默认选择(结束扇区)
t       修改分区类型
       选分区3
8e     修改为LVM(8e就是LVM)
w       写分区表,完成后退出fdisk命令

实际操作:

[root@master spark]# fdisk /dev/sdaWelcome to fdisk (util-linux 2.23.2).Changes will remain in memory only, until you decide to write them.Be careful before using the write command.Command (m for help): pDisk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x000aad3c   Device Boot      Start         End      Blocks   Id  System/dev/sda1   *        2048     2099199     1048576   83  Linux/dev/sda2         2099200    41943039    19921920   8e  Linux LVMCommand (m for help): nPartition type:   p   primary (2 primary, 0 extended, 2 free)   e   extendedSelect (default p): pPartition number (3,4, default 3): 3First sector (41943040-62914559, default 41943040): #直接回车(不输入任何内容)Using default value 41943040Last sector, +sectors or +size{K,M,G} (41943040-62914559, default 62914559): #直接回车(不输入任何内容)Using default value 62914559Partition 3 of type Linux and of size 10 GiB is setCommand (m for help): tPartition number (1-3, default 3): 3Hex code (type L to list all codes): 8eChanged type of partition 'Linux' to 'Linux LVM'Command (m for help): wThe 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 will be used atthe next reboot or after you run partprobe(8) or kpartx(8)Syncing disks. #重新查看重新分区后的分区情况:[root@master spark]# fdisk /dev/sdaWelcome to fdisk (util-linux 2.23.2).Changes will remain in memory only, until you decide to write them.Be careful before using the write command.Command (m for help): pDisk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x000aad3c   Device Boot      Start         End      Blocks   Id  System/dev/sda1   *        2048     2099199     1048576   83  Linux/dev/sda2         2099200    41943039    19921920   8e  Linux LVM/dev/sda3        41943040    62914559    10485760   8e  Linux LVMCommand (m for help):

(3)格式化分区

注意:格式化之前要重启机器

[spark@master ~]$ mkfs.ext3 /dev/sda3mke2fs 1.42.9 (28-Dec-2013)mkfs.ext3: Permission denied while trying to determine filesystem size[spark@master ~]$ su rootPassword: [root@master spark]# mkfs.ext3 /dev/sda3mke2fs 1.42.9 (28-Dec-2013)Filesystem label=OS type: LinuxBlock size=4096 (log=2)Fragment size=4096 (log=2)Stride=0 blocks, Stripe width=0 blocks655360 inodes, 2621440 blocks131072 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=268435456080 block groups32768 blocks per group, 32768 fragments per group8192 inodes per groupSuperblock backups stored on blocks:         32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632Allocating group tables: done                            Writing inode tables: done                            Creating journal (32768 blocks): doneWriting superblocks and filesystem accounting information: done [root@master spark]#

4. 添加新LVM到已有的LVM组,实现扩容

进入lvm管理

[root@master]# lvm

实际上以下命令我在centos7下直接操作也行。

关于lvm的一些基础知识可以参考:《》

(1)初始化刚才的分区

pvcreate /dev/sda3

(2)查看卷和卷组

vgdisplay

要记下”VG Name”,这里为centos;再记下”Free PE/Size”的大小,例如这里为21513

(3)将初始化过的分区加入到虚拟卷组

vgextend centos /dev/sda3

刚才记下的”VG Name”就在这里使用。

但是执行到这一步时报错了:

Couldn't create temporary archive name.

Volume group "centos" metadata archive failed. Internal error:
Attempt to unlock unlocked VG #orphans.

查看了下,因为磁盘实在太小了,无法执行,删除一些数据就行。

(4)扩展已有卷的容量

lvextend -l +9.5G /dev/mapper/centos-root

lvextend指令用于在线扩展逻辑卷的空间大小,而不中断应用程序对逻辑卷的访问。其后有两个选项

选项 说明
-L 指定逻辑卷的大小,单位为“kKmMgGtT”字节,也就是Size
-l 指定逻辑卷的大小,单位为PE数

其余两个参数:+9.5G是磁盘扩增的大小(也可以是通过vgdisplay查看的free的大小【尽量不完全使用,小个几十到几百M】),后边的目录参数/dev/mapper/centos-root可以通过df命令查看

(5)查看卷容量

pvdisplay

(6)退出

quit

以下是具体实操操作记录:

[root@master spark]# pvcreate /dev/sda3  Physical volume "/dev/sda3" successfully created.[root@master spark]# [root@master spark]# vgextend centos /dev/sda3Couldn't create temporary archive name.Volume group "centos" metadata archive failed. Internal error:Attempt to unlock unlocked VG #orphans. [root@master spark]# df -hFilesystem               Size  Used Avail Use% Mounted on/dev/mapper/centos-root   17G   17G   20K 100% /devtmpfs                 2.4G     0  2.4G   0% /devtmpfs                    2.4G  4.0K  2.4G   1% /dev/shmtmpfs                    2.4G   12M  2.4G   1% /runtmpfs                    2.4G     0  2.4G   0% /sys/fs/cgroup/dev/sda1               1014M  142M  873M  14% /boottmpfs                    479M     0  479M   0% /run/user/1000#磁盘资源不足清理磁盘[root@master spark]# cd /opt/[root@master opt]# lsapache-maven-3.5.4                   elasticsearch-head-master      hdfs-over-ftp-master.zip    kibana-6.2.2-linux-x86_64.tar.gz  node-v8.9.1.tar.gz             zookeeper-3.4.12apache-maven-3.5.4-bin.tar.gz        elasticsearch-head-master.zip  jdk1.8.0_171                nifi-1.7.1                        scala-2.11.0                   zookeeper-3.4.12.tar.gzelasticsearch-6.2.2                  hadoop-2.9.0                   jdk-8u171-linux-x64.tar.gz  nifi-1.7.1-bin.zip                scala-2.11.0.tgzelasticsearch-6.2.2.zip              hadoop-2.9.0.tar.gz            kafka_2.11-1.1.0            node-8.9.1                        spark-2.2.1-bin-hadoop2.7elasticsearch-analysis-ik-6.2.2.zip  hdfs-over-ftp-master           kibana-6.2.2-linux-x86_64   node-v8.9.1                       spark-2.2.1-bin-hadoop2.7.tgz          [root@master opt]# rm *.gzrm: remove regular file ‘apache-maven-3.5.4-bin.tar.gz’? yrm: remove regular file ‘hadoop-2.9.0.tar.gz’? yrm: remove regular file ‘jdk-8u171-linux-x64.tar.gz’? yrm: remove regular file ‘kibana-6.2.2-linux-x86_64.tar.gz’? yrm: remove regular file ‘node-v8.9.1.tar.gz’? yrm: remove regular file ‘zookeeper-3.4.12.tar.gz’? y[root@master opt]# rm *.ziprm: remove regular file ‘elasticsearch-6.2.2.zip’? yrm: remove regular file ‘elasticsearch-analysis-ik-6.2.2.zip’? yrm: remove regular file ‘elasticsearch-head-master.zip’? yrm: remove regular file ‘hdfs-over-ftp-master.zip’? yrm: remove regular file ‘nifi-1.7.1-bin.zip’? y[root@master opt]# rm *.tgzrm: remove regular file ‘scala-2.11.0.tgz’? yrm: remove regular file ‘spark-2.2.1-bin-hadoop2.7.tgz’? y#磁盘清理后查看磁盘资源[root@master opt]# df -hFilesystem               Size  Used Avail Use% Mounted on/dev/mapper/centos-root   17G   15G  2.1G  88% /devtmpfs                 2.4G     0  2.4G   0% /devtmpfs                    2.4G  4.0K  2.4G   1% /dev/shmtmpfs                    2.4G   12M  2.4G   1% /runtmpfs                    2.4G     0  2.4G   0% /sys/fs/cgroup/dev/sda1               1014M  142M  873M  14% /boottmpfs                    479M     0  479M   0% /run/user/1000#重启服务器[root@master opt]# reboot#重新登录Last login: Tue Aug  7 23:16:33 2018 from 192.168.0.103[spark@master ~]$ su rootPassword: [root@master spark]# pvcreate /dev/sda3WARNING: ext3 signature detected on /dev/sda3 at offset 1080. Wipe it? [y/n]: y  Wiping ext3 signature on /dev/sda3.  Physical volume "/dev/sda3" successfully created.[root@master spark]# vgdisplay  --- Volume group ---  VG Name               centos  System ID               Format                lvm2  Metadata Areas        1  Metadata Sequence No  3  VG Access             read/write  VG Status             resizable  MAX LV                0  Cur LV                2  Open LV               2  Max PV                0  Cur PV                1  Act PV                1  VG Size               <19.00 GiB  PE Size               4.00 MiB  Total PE              4863  Alloc PE / Size       4863 / <19.00 GiB  Free  PE / Size       0 / 0     VG UUID               cKJ05H-yI4f-5qfY-5SO5-ybTW-2zDx-M5uyg0   [root@master spark]# vgextend centos /dev/sda3  Volume group "centos" successfully extended[root@master spark]# df -hFilesystem               Size  Used Avail Use% Mounted on/dev/mapper/centos-root   17G   15G  2.1G  88% /devtmpfs                 2.4G     0  2.4G   0% /devtmpfs                    2.4G     0  2.4G   0% /dev/shmtmpfs                    2.4G   12M  2.4G   1% /runtmpfs                    2.4G     0  2.4G   0% /sys/fs/cgroup/dev/sda1               1014M  142M  873M  14% /boottmpfs                    479M     0  479M   0% /run/user/1000[root@master spark]# fdisk -lDisk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x000aad3c   Device Boot      Start         End      Blocks   Id  System/dev/sda1   *        2048     2099199     1048576   83  Linux/dev/sda2         2099200    41943039    19921920   8e  Linux LVM/dev/sda3        41943040    62914559    10485760   8e  Linux LVMDisk /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytes

5. 文件系统扩容

以上只是卷扩容了,还要对文件系统实现真正扩容

CentOS 7 下面 由于使用的是 XFS,所以要用

xfs_growfs /dev/mapper/centos-root

CentOS 6 下面 要用

resize2fs /dev/mapper/centos-root

以下是具体实操操作记录:

[root@master spark]# df -hFilesystem               Size  Used Avail Use% Mounted on/dev/mapper/centos-root   17G   15G  2.1G  88% /devtmpfs                 2.4G     0  2.4G   0% /devtmpfs                    2.4G     0  2.4G   0% /dev/shmtmpfs                    2.4G   12M  2.4G   1% /runtmpfs                    2.4G     0  2.4G   0% /sys/fs/cgroup/dev/sda1               1014M  142M  873M  14% /boottmpfs                    479M     0  479M   0% /run/user/1000[root@master spark]# xfs_growfs /dev/mapper/centos-rootmeta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=1113856 blks         =                       sectsz=512   attr=2, projid32bit=1         =                       crc=1        finobt=0 spinodes=0data     =                       bsize=4096   blocks=4455424, imaxpct=25         =                       sunit=0      swidth=0 blksnaming   =version 2              bsize=4096   ascii-ci=0 ftype=1log      =internal               bsize=4096   blocks=2560, version=2         =                       sectsz=512   sunit=0 blks, lazy-count=1realtime =none                   extsz=4096   blocks=0, rtextents=0data blocks changed from 4455424 to 6945792[root@master spark]# df -hFilesystem               Size  Used Avail Use% Mounted on/dev/mapper/centos-root   27G   15G   12G  57% /devtmpfs                 2.4G     0  2.4G   0% /devtmpfs                    2.4G     0  2.4G   0% /dev/shmtmpfs                    2.4G   12M  2.4G   1% /runtmpfs                    2.4G     0  2.4G   0% /sys/fs/cgroup/dev/sda1               1014M  142M  873M  14% /boottmpfs                    479M     0  479M   0% /run/user/1000

6. 查看新的磁盘空间

df -h

 

 

参考《》

转载于:https://www.cnblogs.com/yy3b2007com/p/9440457.html

你可能感兴趣的文章
lintcode:整数排序||
查看>>
HDU 6214 Smallest Minimum Cut(最少边最小割)
查看>>
旧数据迁移心得
查看>>
Python学习第八天(os)
查看>>
math类
查看>>
用膳吧大学生创业扶持计划
查看>>
转:Ubuntu 11.04启动Ctrl-Alt-BackSpace组合键重启X server
查看>>
支付密码框
查看>>
.net探索文件夹位置
查看>>
运算符重载
查看>>
JS中String与Array的一些常用方法
查看>>
python内置类型:列表,包括 list 和 tuple
查看>>
对python的认识
查看>>
微信会员卡线上线下积分打通研究
查看>>
[笔记]ACM笔记 - 组合数
查看>>
bzoj 2783: [JLOI2012]树
查看>>
ES6获取页面所有页面标签名
查看>>
建立顺序表
查看>>
ebay分布式事务方案
查看>>
索引类型
查看>>