在CentOS 6.5里添加一块硬盘,分区并格式化后,挂载到/data下

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在CentOS 6.5里添加一块硬盘,分区并格式化后,挂载到/data下相关的知识,希望对你有一定的参考价值。

常用命令:

[[email protected] etc]# uname –a------à查看内核版本

Linux goodluck 2.6.32-431.el6.x86_64 #1 SMPFri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

 

[[email protected] etc]# cat /proc/version -----------à查看内核等版本信息

Linux version 2.6.32-431.el6.x86_64 ([email protected])(gcc version 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC) ) #1 SMP Fri Nov 2203:15:09 UTC 2013

 

[[email protected] etc]# cat/etc/redhat-release------------------à查看版本号

CentOS release 6.5 (Final)

[[email protected] etc]#cat /etc/centos-release------------------à查看版本号

CentOS release 6.5 (Final)

 

[[email protected] etc]# rpm -q centos-release------------------à查看版本号

centos-release-6-5.el6.centos.11.1.x86_64

 

[[email protected] ~]# runlevel--------à运行级别

N 3

 

[[email protected] ~]# logout-------à登出

Last login: Thu Mar  3 20:22:04 2016

 

[[email protected] ~]# df –h---------à查看硬盘使用情况,以人类可读方式,-h 就是human

Filesystem      Size Used Avail Use% Mounted on

/dev/sda3        20G 2.2G   16G  12% /

tmpfs           491M     0 491M   0% /dev/shm

/dev/sda1       194M  34M  151M  19% /boot

.host:/         432G 407G   26G  95% /mnt/hgfs

 

[[email protected] /]# cd /mnt

[[email protected] mnt]# ls

cdrom hgfs------------------------àcdrom是光盘挂载点,hgfsVMware的共享文件夹

[[email protected] /]# cd /mnt/hgfs/liuyong

[[email protected] liuyong]# ls

goodluck_160120_1619.nmon                               nmon analyserv46.xlsm [email protected]:-mnt-hgfs-liuyong.png

mysql-5.7.4-m14-1.linux_glibc2.5.x86_64.rpm-bundle.tar  nmon_linux_14i.tar.gz   Screenshot-System Monitor.png

 

 

CentOS 6.5里添加一块硬盘,分区并格式化后,挂载到/data

VMware里添加一块硬盘:

技术分享

技术分享

技术分享

技术分享

技术分享

[[email protected] ~]# fdisk -l--------------------------------->查看磁盘分区信息,以下信息显示有两块硬盘,都是21.5GB,这里的21.5GB是不准确的,是按1000MB=1GB计算,不是1024MB=1GB,所以有出入。/dev/sdb没有分区信息。

 

Disk /dev/sda: 21.5 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280bytes

Sector size (logical/physical): 512 bytes /512 bytes

I/O size (minimum/optimal): 512 bytes / 512bytes

Disk identifier: 0x0000721e

 

  Device Boot      Start         End      Blocks  Id  System

/dev/sda1  *           1          26      204800  83  Linux

Partition 1 does not end on cylinderboundary.

/dev/sda2              26          91      524288  82  Linux swap / Solaris

Partition 2 does not end on cylinderboundary.

/dev/sda3              91        2611   20241408   83  Linux

 

Disk /dev/sdb: 21.5 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280bytes

Sector size (logical/physical): 512 bytes /512 bytes

I/O size (minimum/optimal): 512 bytes / 512bytes

Disk identifier: 0x00000000

 

分区:

[[email protected] ~]# fdisk /dev/sdb ------------------------------------à对新加的/dev/sdb进行分区,步骤:fdisk /dev/sdbàmànàpà1àenteràwà完成

Device contains neither a valid DOSpartition table, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel with diskidentifier 0x9eace345.

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

After that, of course, the previous contentwon‘t be recoverable.

 

Warning: invalid flag 0x0000 of partitiontable 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): m--------à注:查看更多信息

Command action

  a   toggle a bootable flag

  b   edit bsd disklabel

  c   toggle the dos compatibilityflag

  d   delete a partition

  l   list known partition types

  m   print this menu

  n   add a new partition-----à注:增加新分区

  o   create a new empty DOSpartition table

  p   print the partition table

  q   quit without saving changes

  s   create a new empty Sundisklabel

  t   change a partition‘s system id

   u  change display/entry units

  v   verify the partition table

  w   write table to disk and exit--------à注:写入分区表后退出

  x   extra functionality (expertsonly)

 

Command (m for help): n-------------à增加新分区

Command action

  e   extended----------à扩展分区

   p  primary partition (1-4)-----------à主分区数量

p

Partition number (1-4): 1--------------à一个主分区

First cylinder (1-2610, default 1):

Using default value 1

Last cylinder, +cylinders or +size{K,M,G}(1-2610, default 2610): ------à输入主分区容易大小,直接回车是将所有容量一次分完成

Using default value 2610

 

Command (m for help): w----------------------à写入分区表并退出

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

Syncing disks.

[[email protected] ~]# fdisk -l---------------à可以看到/dev/sdb已有分区信息,多了一个/dev/sdb1注意sdb后面有个1

 

Disk /dev/sda: 21.5 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280bytes

Sector size (logical/physical): 512 bytes /512 bytes

I/O size (minimum/optimal): 512 bytes / 512bytes

Disk identifier: 0x0000721e

 

  Device Boot      Start         End      Blocks  Id  System

/dev/sda1  *           1          26      204800  83  Linux

Partition 1 does not end on cylinderboundary.

/dev/sda2              26          91      524288  82  Linux swap / Solaris

Partition 2 does not end on cylinderboundary.

/dev/sda3              91        2611   20241408   83  Linux

 

Disk /dev/sdb: 21.5 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280bytes

Sector size (logical/physical): 512 bytes /512 bytes

I/O size (minimum/optimal): 512 bytes / 512bytes

Disk identifier: 0x9eace345

 

  Device Boot      Start         End      Blocks  Id  System

/dev/sdb1               1        2610   20964793+  83  Linux

 

格式化:

[[email protected] ~]# mkfs.ext4 /dev/sdb1-----------------à/dev/sdb1格式化,格式化成ext4格式

mke2fs 1.41.12 (17-May-2010)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

Stride=0 blocks, Stripe width=0 blocks

1310720 inodes, 5241198 blocks

262059 blocks (5.00%) reserved for thesuper user

First data block=0

Maximum filesystem blocks=4294967296

160 block groups

32768 blocks per group, 32768 fragments pergroup

8192 inodes per group

Superblock backups stored on blocks:

        32768, 98304, 163840, 229376, 294912,819200, 884736, 1605632, 2654208,

       4096000

 

Writing inode tables: done                           

Creating journal (32768 blocks): done

Writing superblocks and filesystemaccounting information: done

 

This filesystem will be automaticallychecked every 20 mounts or

180 days, whichever comes first.  Use tune2fs -c or -i to override.

 

[[email protected] ~]# df –h---------------à格式化完成后,用df –h并不能看到/dev/sdb1,需要挂载,就是mount一下。

Filesystem      Size Used Avail Use% Mounted on

/dev/sda3        20G 2.2G   16G  12% /

tmpfs           491M     0 491M   0% /dev/shm

/dev/sda1       194M  34M  151M  19% /boot

.host:/         432G 407G   26G  95% /mnt/hgfs

 

挂载:

[[email protected] ~]# mount /dev/sdb1 /data/-----------------à/dev/sdb1挂载到/data/目录下

mount: mount point /data/ does not exist--------------à提示没有/data/目录

 

[[email protected] /]# mkdir /data-------------à创建/data目录

 

[[email protected] /]# mount /dev/sdb1 /data/-----------------à/dev/sdb1挂载到/data/目录下成功

 

[[email protected] /]# df –h-----------------à挂载成功后,有/dev/sdb1显示

Filesystem      Size Used Avail Use% Mounted on

/dev/sda3        20G 2.2G   16G  12% /

tmpfs           491M     0 491M   0% /dev/shm

/dev/sda1       194M  34M  151M  19% /boot

.host:/         432G 407G   26G  95% /mnt/hgfs

/dev/sdb1        20G 172M   19G   1% /data

 

[[email protected] /]# df –T--------------------à显示文件格式,/dev/sdb1ext4,跟分区时设定的一致

Filesystem     Type  1K-blocks      Used Available Use%Mounted on

/dev/sda3      ext4   19923216   2264172  16646976 12% /

tmpfs          tmpfs     502204         0   502204   0% /dev/shm

/dev/sda1      ext4     198337     34236    153861 19% /boot

.host:/        vmhgfs 452471804 425990248  26481556 95% /mnt/hgfs

/dev/sdb1      ext4   20635700    176064  19411400  1% /data

 

 

增加硬盘(20GB),分区(一个主分区)、格式化(ext4格式)、挂载到/data目录下完成。

技术分享

解挂:

[[email protected] /]# umount /data/-----------à/data/解挂

[[email protected] /]# df –hT---------------à再查看,/dev/sdb1没有了。

Filesystem     Type   Size  Used Avail Use% Mounted on

/dev/sda3      ext4    20G  2.2G   16G 12% /

tmpfs          tmpfs   491M    0  491M   0% /dev/shm

/dev/sda1      ext4   194M   34M  151M 19% /boot

.host:/        vmhgfs 432G  407G   26G 95% /mnt/hgfs

 

想用,再[[email protected] /]# mount /dev/sdb1 /data/

 

有一个问题:系统重启后,mount的挂载点就会消失,两种解决办法:

第一种、[[email protected] /]# vi /etc/rc.local,增加一行mount /dev/sdb1/data/,保存退出。

技术分享

 

第二种、写到fstab

#vi /etc/fstab
/dev/sdb1 /data ext4 defaults 0 0


以上是关于在CentOS 6.5里添加一块硬盘,分区并格式化后,挂载到/data下的主要内容,如果未能解决你的问题,请参考以下文章

Linux学习一:图解CentOS 6.5安装步骤

centos 7 增加一块硬盘的步骤

磁盘分区开机自动挂载

CentOS LVM逻辑卷管理

Linux学习-Centos磁盘分区挂载

centos查找未挂载磁盘格式化并挂载