Ubuntu服务器挂载新硬盘的步骤

发表时间:2013-08-13 9:08 | 分类:Linux | 浏览:2,774 次

最近公司新购了一台戴尔R720的服务器,昨天u盘安装ubuntu系统后,首先要做的就是把另外两个raid设备挂载到服务器。现在在虚拟机中用root用户操作,挂载的具体步骤如下。

1、测试硬盘是否已连接

首先先查看硬盘信息。sda是虚拟的第一块硬盘,sdb是第二块硬盘,以此类推。


root@zhang:~# ls -l /dev/sd*
brw-rw---- 1 root disk 8, 0 2013-08-13 08:33 /dev/sda
brw-rw---- 1 root disk 8, 1 2013-08-13 08:33 /dev/sda1
brw-rw---- 1 root disk 8, 2 2013-08-13 08:33 /dev/sda2
brw-rw---- 1 root disk 8, 5 2013-08-13 08:33 /dev/sda5
brw-rw---- 1 root disk 8, 16 2013-08-13 08:33 /dev/sdb

#此命令测试linux系统是否能找到挂载的未分区硬盘

root@zhang:~# hdparm -I /dev/sdb

#这个是未挂载之前的硬盘信息

root@zhang:~# fdisk -l

Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 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: 0x000cf88c

Device Boot Start End Blocks Id System
/dev/sda1 * 1 994 7977984 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 994 1045 407553 5 Extended
/dev/sda5 994 1045 407552 82 Linux swap / Solaris

Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 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

Disk /dev/sdb doesn't contain a valid partition table

2、创建硬盘分区


root@zhang:~# 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 0xcbd0c60e.
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').

# 输入m,查看帮助信息 Command (m for help): m
Command action

a toggle a bootable flag 将分区设置为启动区
b edit bsd disklabel 编辑bsd的disklabel
c toggle the dos compatibility flag 设置该分区为dos分区
d delete a partition 删除分区
l list known partition types 列出已知的分区类型
m print this menu 打印帮助列表
n add a new partition 创建新分区
o create a new empty DOS partition table
p print the partition table查看分区信息
q quit without saving changes 退出不保存
s create a new empty Sun disklabel
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 (experts only)

#查看sdb这块硬盘的分区
Command (m for help): p

Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 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: 0xcbd0c60e

Device Boot Start End Blocks Id System

#创建sdb这块硬盘的分区

Command (m for help): n
Command action
 e extended
 p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1044, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1044, default 1044):
Using default value 1044

#查看创建sdb硬盘的分区

Command (m for help): p

Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 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: 0xcbd0c60e

Device Boot Start End Blocks Id System
/dev/sdb1 1 1044 8385898+ 83 Linux

#保存退出,分区创建结束。

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

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

#再用fdisk -l查看硬盘信息就可以看到sdb1新分区了

root@zhang:~# fdisk -l

Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 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: 0x000cf88c

Device Boot Start End Blocks Id System
/dev/sda1 * 1 994 7977984 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 994 1045 407553 5 Extended
/dev/sda5 994 1045 407552 82 Linux swap / Solaris

Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 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: 0xcbd0c60e

Device Boot Start End Blocks Id System
/dev/sdb1 1 1044 8385898+ 83 Linux

3、格式化硬盘


root@zhang:~# mkfs -t ext4 /dev/sdb1
mke2fs 1.41.11 (14-Mar-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
524288 inodes, 2096474 blocks
104823 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=2147483648
64 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

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

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

4、给新建的sdb1设置卷标命名,创建挂载点。


root@zhang:~# e2label /dev/sdb1 /data

root@zhang:~# mkdir /data

5、设置开机自动挂载

在上面一个步骤中,我已经把sdb1这个分区重新命名,当然也可以在设置自动挂载的时候用UUID。


root@zhang:~# ls -l /dev/disk/
total 0
drwxr-xr-x 2 root root 280 2013-08-13 08:47 by-id
drwxr-xr-x 2 root root 60 2013-08-13 08:52 by-label
drwxr-xr-x 2 root root 180 2013-08-13 08:47 by-path
drwxr-xr-x 2 root root 100 2013-08-13 08:51 by-uuid

#查看设置的卷标名称,这里有上一步中命名的分区/data
root@zhang:~# ls -l /dev/disk/by-label/
total 0
lrwxrwxrwx 1 root root 10 2013-08-13 08:52 \x2fdata -> ../../sdb1

#查看各个分区的uuid号
root@zhang:~# ls -l /dev/disk/by-uuid/
total 0
lrwxrwxrwx 1 root root 10 2013-08-13 08:33 b6dbd10c-7995-4b3d-abf0-2da1622298da -> ../../sda1
lrwxrwxrwx 1 root root 10 2013-08-13 08:33 d0d8b0bf-dc99-4d38-937d-f34d88072ce9 -> ../../sda5
lrwxrwxrwx 1 root root 10 2013-08-13 08:52 f90991b0-1082-45d8-b00d-87dceb81115e -> ../../sdb1

#设置开机自动挂载分区sdb1

root@zhang:~# vi /etc/fstab

# /etc/fstab: static file system information.
#
# Use 'blkid -o value -s UUID' to print the universally unique identifier
# for a device; this may be used with UUID= as a more robust way to name
# devices that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
proc /proc proc nodev,noexec,nosuid 0 0
# / was on /dev/sda1 during installation
UUID=b6dbd10c-7995-4b3d-abf0-2da1622298da / ext4 errors=remount-ro 0 1
# swap was on /dev/sda5 during installation
UUID=d0d8b0bf-dc99-4d38-937d-f34d88072ce9 none swap sw 0 0
LABEL=/data /data ext4 defaults 0 2
#或者用UUID,效果都是一样的。
#UUID=f90991b0-1082-45d8-b00d-87dceb81115e /data ext4 defaults 0 2

6、重新启动查看挂载结果


root@zhang:~# df -lh
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 7.5G 1.5G 5.7G 20% /
none 243M 216K 243M 1% /dev
none 247M 0 247M 0% /dev/shm
none 247M 56K 247M 1% /var/run
none 247M 0 247M 0% /var/lock
none 247M 0 247M 0% /lib/init/rw
/dev/sdb1 7.9G 146M 7.4G 2% /data

#挂载成功

本文标签:

本文链接:http://www.sijitao.net/1386.html

本文版权虫虫开源所有,欢迎您在本博客中留下评论,如需转载原创文章请注明出处,谢谢!

icon_wink.gif icon_neutral.gif icon_mad.gif icon_twisted.gif icon_smile.gif icon_eek.gif icon_sad.gif icon_rolleyes.gif icon_razz.gif icon_redface.gif icon_surprised.gif icon_mrgreen.gif icon_lol.gif icon_idea.gif icon_biggrin.gif icon_evil.gif icon_cry.gif icon_cool.gif icon_arrow.gif icon_confused.gif icon_question.gif icon_exclaim.gif 

一键脚本 SSH攻击 IP查询 博客历程 留言本 文章归档 网站地图 谷歌地图
托管于阿里云&七牛云. 已加入博客联盟. 浙ICP备13025236号.
Copyright © 2010-2017 虫虫开源 All Rights Reserved.