码迷,mamicode.com
首页 > 其他好文 > 详细

CentOS挂载新硬盘

时间:2014-06-14 20:23:10      阅读:400      评论:0      收藏:0      [点我收藏+]

标签:des   style   class   blog   code   tar   

1.查看当前硬盘使用状况:

df -h

 

root@VM_160_34_centos:~> df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/xvda1            7.9G  1.5G  6.1G  20% /

 

2.查看新硬盘 

 fdisk -l 

 

 1 root@VM_160_34_centos:~> fdisk -l            
 2 
 3 Disk /dev/xvda: 8589 MB, 8589934592 bytes
 4 255 heads, 63 sectors/track, 1044 cylinders
 5 Units = cylinders of 16065 * 512 = 8225280 bytes
 6 Sector size (logical/physical): 512 bytes / 512 bytes
 7 I/O size (minimum/optimal): 512 bytes / 512 bytes
 8 Disk identifier: 0xcd6e8236
 9 
10     Device Boot      Start         End      Blocks   Id  System
11 /dev/xvda1   *           1        1044     8385898+  83  Linux
12 
13 Disk /dev/xvdb: 53.7 GB, 53687091200 bytes
14 255 heads, 63 sectors/track, 6527 cylinders
15 Units = cylinders of 16065 * 512 = 8225280 bytes
16 Sector size (logical/physical): 512 bytes / 512 bytes
17 I/O size (minimum/optimal): 512 bytes / 512 bytes
18 Disk identifier: 0x00000000
19 
20 Disk /dev/xvdb doesnt contain a valid partition table
21 
22 Disk /dev/xvdc: 2147 MB, 2147483648 bytes
23 255 heads, 63 sectors/track, 261 cylinders
24 Units = cylinders of 16065 * 512 = 8225280 bytes
25 Sector size (logical/physical): 512 bytes / 512 bytes
26 I/O size (minimum/optimal): 512 bytes / 512 bytes
27 Disk identifier: 0x00000000
28 
29 Disk /dev/xvdc doesnt contain a valid partition table

这结果很明显让人烦躁,一坨屎一样,下面我们过滤一下

命令:

fdisk -l  |grep Disk

结果:

root@VM_160_34_centos:~> fdisk -l  |grep Disk
Disk /dev/xvdb doesnt contain a valid partition table
Disk /dev/xvdc doesnt contain a valid partition table
Disk /dev/xvda: 8589 MB, 8589934592 bytes
Disk identifier: 0xcd6e8236
Disk /dev/xvdb: 53.7 GB, 53687091200 bytes
Disk identifier: 0x00000000
Disk /dev/xvdc: 2147 MB, 2147483648 bytes
Disk identifier: 0x00000000

这个看起来让人舒心多了,

结果中:

提示这个

Disk /dev/xvdb doesnt contain a valid partition table
Disk /dev/xvdc doesnt contain a valid partition table

这两行应该就是说还没有挂载上去的硬盘了.

新添加的硬盘的编号为

/dev/xvdb
/dev/xvdc

3.硬盘分区 

  • 进入fdisk模式
 fdisk /dev/xvdb  

 

 1 root@VM_160_34_centos:~> fdisk /dev/xvdb  
 2 Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
 3 Building a new DOS disklabel with disk identifier 0x7ca79642.
 4 Changes will remain in memory only, until you decide to write them.
 5 After that, of course, the previous content wont be recoverable.
 6 
 7 Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
 8 
 9 WARNING: DOS-compatible mode is deprecated. Its strongly recommended to
10          switch off the mode (command c) and change display units to
11          sectors (command u).
12 
13 Command (m for help): 
  •  输入n进行分区 
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p

  这里有两个选项: 
?   p: 主分区 linux上主分区最多能有4个 
?   e: 扩展分区 linux上扩展分区只能有1个,扩展分区创建后不能直接使用,还要在扩展分区上创建逻辑分区。 


这里我选择的p。 

 

  • 选择分区个数 
Partition number (1-4): 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): 
Using default value 6527
  • 输入w,写入分区表,进行分区 
Command (m for help):w
Command (m for help): w
The partition table has been altered!

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

整个过程如下:

root@VM_160_34_centos:~> fdisk /dev/xvdb  
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x7ca79642.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content wont be recoverable.

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

WARNING: DOS-compatible mode is deprecated. Its strongly recommended to
         switch off the mode (command c) and change display units to
         sectors (command u).

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)

Last login: Fri Jun 13 18:19:47 2014 from 112.90.239.105
root@VM_160_34_centos:~>  
Display all 1286 possibilities? (y or n)
root@VM_160_34_centos:~> 
root@VM_160_34_centos:~> fdisk /dev/xvd
xvda   xvda1  xvdb   xvdc   
root@VM_160_34_centos:~> fdisk /dev/xvdb  
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xc925c1ae.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content wont be recoverable.

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

WARNING: DOS-compatible mode is deprecated. Its strongly recommended to
         switch off the mode (command c) and change display units to
         sectors (command u).

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): 
Using default value 6527

Command (m for help): w
The partition table has been altered!

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

4.格式化分区 

将新分区格式化为ext3文件系统 

  • 如果创建的是主分区 
#mkfs -t ext3  /dev/xvdb

 

root@VM_160_34_centos:~> mkfs -t ext3  /dev/xvdb
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
3276800 inodes, 13107200 blocks
655360 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
400 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

Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

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

5.  挂载硬盘

  • 创建挂载点

  在根目录下创建storage目录 

#mkdir /storage 
  • 将/dev/xvdb挂载到/storage下 
#mount /dev/xvdb /storage
  • 设置开机启动自动挂载 

    新创建的分区不能开机自动挂载,每次重启机器都要手动挂载。 
    设置开机自动挂载需要修改/etc/fstab文件 

 #vi /etc/fstab 

    在文件的最后增加一行 

 /dev/xvdb /storage ext3 defaults 1 2 

 

过程如下:

 1 root@VM_160_34_centos:~> mkdir /storage
 2 root@VM_160_34_centos:~> mount /dev/xvdb /storage
 3 root@VM_160_34_centos:~> vi /etc/fstab 
 4 
 5 
 6 
 7 /dev/xvda1            /                    ext3       noatime,acl,user_xattr 1 1
 8 /dev/xvdc            swap                 swap       defaults 0 0
 9 proc                 /proc                proc       defaults              0 0
10 sysfs                /sys                 sysfs      noauto                0 0
11 debugfs              /sys/kernel/debug    debugfs    noauto                0 0
12 devpts               /dev/pts             devpts     mode=0620,gid=5       0 0
13 /dev/xvdb            /storage             ext3       defaults              1 2
14 ~
15 ~
16 ~
17 ~
18 ~
19 "/etc/fstab" 7L, 536C written
20 root@VM_160_34_centos:~> clear

 

 结果:

 

root@VM_160_34_centos:/storage> ll /
total 104
dr-xr-xr-x   2 root root  4096 May 15 15:33 bin
dr-xr-xr-x   4 root root  4096 May 31  2013 boot
drwxr-xr-x   2 root root  4096 Dec 16 11:42 data
drwxr-xr-x  15 root root  3360 Jun 13 19:21 dev
drwxr-xr-x  73 root root  4096 Jun 13 19:37 etc
drwxr-xr-x   3 root root  4096 Jun  2 20:32 home
dr-xr-xr-x  12 root root  4096 Jun 20  2013 lib
dr-xr-xr-x   9 root root 12288 Jun 20  2013 lib64
drwx------   2 root root 16384 May 31  2013 lost+found
drwxr-xr-x   2 root root  4096 Sep 23  2011 media
drwxr-xr-x   2 root root  4096 Sep 23  2011 mnt
drwxr-xr-x   2 root root  4096 Sep 23  2011 opt
dr-xr-xr-x 106 root root     0 Jun 14  2014 proc
dr-xr-x---   2 root root  4096 Jun 13 19:35 root
dr-xr-xr-x   2 root root 12288 Jun 19  2013 sbin
drwxr-xr-x   2 root root  4096 May 31  2013 selinux
drwxr-xr-x   2 root root  4096 Sep 23  2011 srv
drwxr-xr-x   3 root root  4096 Jun 13 19:37 storage
drwxr-xr-x  13 root root     0 Jun 14  2014 sys
drwxrwxrwt   3 root root  4096 Jun 13 18:26 tmp
drwxr-xr-x  13 root root  4096 May 31  2013 usr
drwxr-xr-x  19 root root  4096 Jul 16  2013 var
root@VM_160_34_centos:/storage> fdisk -l  |grep Disk
Disk /dev/xvdb doesnt contain a valid partition table
Disk /dev/xvdc doesnt contain a valid partition table
Disk /dev/xvda: 8589 MB, 8589934592 bytes
Disk identifier: 0xcd6e8236
Disk /dev/xvdb: 53.7 GB, 53687091200 bytes
Disk identifier: 0x00000000
Disk /dev/xvdc: 2147 MB, 2147483648 bytes
Disk identifier: 0x00000000
root@VM_160_34_centos:/storage> df -lh              
Filesystem            Size  Used Avail Use% Mounted on
/dev/xvda1            7.9G  1.5G  6.1G  20% /
/dev/xvdb              50G  180M   47G   1% /storage

教程到此结束!

 

CentOS挂载新硬盘,布布扣,bubuko.com

CentOS挂载新硬盘

标签:des   style   class   blog   code   tar   

原文地址:http://www.cnblogs.com/mjorcen/p/3786443.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!