卡饭网 > linux > 正文

在linux系统下添加新硬盘

来源:本站整理 作者:梦在深巷 时间:2013-09-08 23:13:21

fdisk -l ## 这里是查看目前系统上有几块硬盘

Disk /dev/sda: 36.4 GB, 36401479680 bytes
255 heads, 63 sectors/track, 4425 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 255 2048256 83 Linux
/dev/sda2 256 1530 10241437+ 83 Linux
/dev/sda3 4296 4425 1044225 82 Linux swap
/dev/sda4 1531 4295 22209862+ f Win95 Ext'd (LBA)
/dev/sda5 1531 2805 10241406 83 Linux
/dev/sda6 2806 4295 11968393+ 83 Linux

Partition table entries are not in disk order

Disk /dev/sdb: 36.7 GB, 36703918080 bytes ## 这里发现/dev/sdb,容量36.7G,且未被分区
255 heads, 63 sectors/track, 4462 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

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

在服务器上把硬盘接好,启动linux,以root登陆。

比如我新加一块SCSI硬盘,需要将其分成三个区:

#fdisk /dev/sdb
进入fdisk模式:
Command (m for help):p //查看新硬盘的分区
Command (m for help):n //创建新分区

可以用m命令来看fdisk命令的内部命令;n命令创建一个新分区;d命令删除一个存在的分区;p命令显示分区列表;t命令修改分区的类型ID号;l命令显示分区ID号的列表;a命令指定启动分区;w命令是将对分区表的修改存盘让它发生作用。

Command action
e extended //输入e为创建扩展分区
p primary partition (1-4) //输入p为创建主分区,这里我们选择p

Partion number(1-4):1 //第一个扩展分区,按你需求可以最多分4个主分区
First Cylinder(1-1014,default 1): 1 //第一个主分区起始的磁盘块数
Last cylindet or +siza or +sizeM or +sizeK: +1024MB //可以是以MB为单位的数字或者以

磁盘块数,这里我们输入+1024MB表示分区大小为1G。

这样我们就创建完一个分区,如果要创建更多分区可以照上面的步骤继续创建。

创建完后用w保存分区。

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

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

这样就分区完,我们还要进行格式化

#mkfs -t ext3 -c /dev/sdb1 //如果有多个分区,则分区修改为sdb2这样

格式化完后我们需要进行挂载分区,

#mkdir www //创建/www目录,我们将把新的分区挂到www下
#mount /dev/sdb1 /www //将/dev/sdb1挂载到/www
# df //用df命令进行查看
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 3771316 1388956 2190788 39% /
/dev/sda1 101089 9463 86407 10% /boot
none 62988 0 62988 0% /dev/shm
/dev/sdb1 485906 8239 452580 2% /www //看到了,这就是我们刚

才新挂载的分区

到这里我们工作已接近尾声了,不过我们如果这样就结束的话,我们每次重新启动服务器后都要

进行手工挂载,这样很麻烦,我们需要修改/etc/fstab文件来进行自动挂载。

#vi /etc/fstab

在文件的末尾填加如下内容:

/dev/sdb1 /www ext3 defaults 1 2

如有多个分区可修改sdb1和/www,修改完后保存,重起服务器。

到此我们添加新硬盘的工作结束了。

相关推荐