美文网首页
添加一块新磁盘

添加一块新磁盘

作者: 千年面包 | 来源:发表于2017-07-10 15:58 被阅读0次

tag:由于业务需求的增长,磁盘空间日渐捉襟见肘,现新增一块硬盘到linux服务器,一起来看看怎么操作吧:

1.先看看已有的磁盘及挂载点

[root@GHCLC6X-6786 ~]# df
文件系统             1K-块      已用      可用 已用% 挂载点
/dev/sda3             13932624   2534836  10690052  20% /
tmpfs                  2996552         0   2996552   0% /dev/shm
/dev/sda1               516040     43608    446220   9% /boot

2.列出所有的硬盘

[root@GHCLC6X-6786 ~]# fdisk -l | grep -P "Disk /dev/[a-z]{0,3}:"
Disk /dev/sda: 16.1 GB, 16106127360 bytes
Disk /dev/sdb: 102.0 GB, 102005473280 bytes

根据之前的对比 可以看到一块102GB的新硬盘 位于/dev/sdb

3.下面就来分区吧

这里用到的是fdisk命令,下面是该命令的一些参数说明:
p、打印分区表。
n、新建一个新分区。
d、删除一个分区。
q、退出不保存。
w、把分区写进分区表,保存并退出。

[root@GHCLC6X-6786 ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xb23f0ad9.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

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):n  
#这里输入n 新建一个新分区

Command action
   e   extended
   p   primary partition (1-4)
p    
#这里的p为建立主分区,e为拓展分区,我这里是新建主分区,所以选p。

Partition number (1-4):1
#分区数量,我填的1,即单个分区

First cylinder (1-12401, default 1): 
Using default value 1
#这里默认就好,默认从第一柱面开始分配

Last cylinder, +cylinders or +size{K,M,G} (1-12401, default 12401): 
Using default value 12401
#默认为最后一个柱面结束,即分配全部空间

Command (m for help): w
#w  写入分区表并保存退出
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

4.格式化分区

这里使用快速格式化为ext4归档格式

[root@GHCLC6X-6786 ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
6225920 inodes, 24902750 blocks
1245137 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=4294967296
760 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
    4096000, 7962624, 11239424, 20480000, 23887872

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

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

5.挂载磁盘

[root@GHCLC6X-6786 ~]# mkdir /data  #建立挂载点
[root@GHCLC6X-6786 ~]# mount /dev/sdb1 /data

6.设置自动挂载

在这里,分区已经成功挂载上去了,我们用df命令可以看到挂载信息:

[root@GHCLC6X-6786 ~]# df
文件系统             1K-块      已用      可用 已用% 挂载点
/dev/sda3             13932624   2542920  10681968  20% /
tmpfs                  2996552         0   2996552   0% /dev/shm
/dev/sda1               516040     43608    446220   9% /boot
/dev/sdb1             98048020    192176  92875296   1% /data

但是,每次开机挂载未免太过麻烦,下面来设置开机自动挂载吧:

[root@GHCLC6X-6786 ~]# vim /etc/fstab

在文件尾写入挂载信息即可,如下图所示:

fstab.png

--大功告成!

相关文章

网友评论

      本文标题:添加一块新磁盘

      本文链接:https://www.haomeiwen.com/subject/fgayhxtx.html