Linux下添加新硬盘并挂载使用

1、 查看新磁盘信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[root@Crayfish ~]# fdisk -l
 
Disk /dev/xvda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00060953
 
    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *           1        2611    20970496   83  Linux
 
Disk /dev/xvdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

2、硬盘分区

2.1、进入fdisk模式

1
2
3
4
5
6
7
8
9
10
11
[root@Crayfish ~]# 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 0xc233737d.
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').

2.2、输入n进行分区

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

2.3、选择分区类型,p为主分区,linux上主分区最多能有4个;e为扩展分区,扩展分区 linux上扩展分区只能有1个,扩展分区创建后不能直接使用,还要在扩展分区上创建逻辑分区。这里选择p

1
p

2.4、选择分区个数,最多可以分4个区,这里就只分一个了。

1
Partition number (1-4): 1

2.5、设置柱面,这里选择默认值就可以

1
2
First cylinder (1-2610, default 1): 
Using default value 1

2.6、设置柱面,这里选择默认值就可以

1
2
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): 
Using default value 2610

2.7、输入w,写入分区表,进行分区

1
2
3
4
5
6
Command (m for help): w
The partition table has been altered!
 
Calling ioctl() to re-read partition table.
Syncing disks.
[root@Crayfish ~]#

3、格式化分区

如果创建的是主分区

1
[root@Crayfish ~]# mkfs -t ext3  /dev/xvdb

4、挂载硬盘

4.1、创建挂载点
在根目录下创建storage目录

1
[root@Crayfish ~]#mkdir /storage

4.2、将/dev/sdb1挂载到/storage下

1
[root@Crayfish ~]#mount /dev/xvdb  /storage

5、设置开机启动自动挂载

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

1
[root@Crayfish ~]#vi /etc/fstab

在文件的最后增加一行

1
/dev/sdb5 /storage ext3 defaults 1 2

Leave a Reply