centos挂载新硬盘

查看所有硬盘

1
fdisk -l
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000d9a78

Device Boot Start End Blocks Id System
/dev/vda1 * 2048 83886046 41941999+ 83 Linux

Disk /dev/vdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

磁盘分区

1
2
3
4
5
6
7
8
fdisk  /dev/vdb

> n
> p
> 1
> 回车
> 回车
> w
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Welcome 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.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xc8b440ba.

Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039):
Using default value 41943039
Partition 1 of type Linux and of size 20 GiB is set

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

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

格式化磁盘并写入文件系统

这里可以用ext3,也可以用ext4

1
mkfs.ext4 /dev/vdb1   

创建挂载根目录下的data

1
2
3
4
mkdir /data
chmod -R 777 /data
# 应该挂载到根目录 data 下
mount /dev/vdb1 /data

查看磁盘信息

1
df

设置开机启动自动挂载

新创建的分区不能开机自动挂载,每次重启机器都要手动挂载。

设置开机自动挂载需要修改/etc/fstab文件 ;命令如下:

1
2
3
4
5
# 分配修改权限
chmod -R 777 /etc/fstab

# 打开后,在最后一行加入以下代码:
/dev/vdb1 /huichengff ext4 defaults 0 1 //如果上面用的是ext3,这里也要用ext3;