Linux上挂载新硬盘详解

http://blog.csdn.net/sanshiqiduer/article/details/5954725

http://blog.chinaunix.net/uid-25829053-id-3067619.html

根据这两个网址,即可完成。拷贝数据如下:

针对阿里云服务器,进行系统初建。

(一)查看硬盘分布和对新硬盘进行分区

[root@cncmail data1]# 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 
[root@linux root]# fdisk /dev/vdb ## 接下去就对/dev/sdb分区进行分区

The number of cylinders for this disk is set to 4462. 
There is nothing wrong with that, but this is larger than 1024, 
and could in certain setups cause problems with: 
1) software that runs at boot time (e.g., old versions of LILO) 
2) booting and partitioning software from other OSs 
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): m 
Command action 
a toggle a bootable flag 
b edit bsd disklabel 
c toggle the dos compatibility flag 
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)

Command (m for help): p ## 打印出目前该硬盘下的分区列表

Disk /dev/sdb: 36.7 GB, 36703918080 bytes 
255 heads, 63 sectors/track, 4462 cylinders 
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

Command (m for help): n ## 增加一个分区 
Command action 
e extended 
p primary partition (1-4) 
## 因为通常选择主分区,所以这里打一个p 

Partition number (1-4): 1 ## 这里因为是第一个分区,所以只选择1,如果是第二个分区,则选择2,依次类推 
First cylinder (1-4462, default 1): ## 新分区起始的磁盘块数 
Using default value 1 
Last cylinder or +size or +sizeM or +sizeK (1-4462, default 4462): 
如果要分区10G,这里可以直接输入:+10240M,因为这里要全部使用硬盘空间,则用默认 
Using default value 4462

Command (m for help): p

Disk /dev/sdb: 36.7 GB, 36703918080 bytes 
255 heads, 63 sectors/track, 4462 cylinders 
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System 
/dev/sdb1 1 4462 35840983+ 83 Linux 
## 这里第一个分区已经分好了,接下去得把这个分区写入硬盘,用w 
Command (m for help): 
The partition table has been altered!

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


(二) 下面的工作就是对该硬盘进行格式 ,我这里是格式化成ext3 
[root@linux root]# mke2fs -j /dev/vdb1 
mke2fs 1.32 (09-Nov-2002) 
Filesystem label= 
OS type: Linux 
Block size=4096 (log=2) 
Fragment size=4096 (log=2) 
4480448 inodes, 8960245 blocks 
448012 blocks (5.00%) reserved for the super user 
First data block=0 
274 block groups 
32768 blocks per group, 32768 fragments per group 
16352 inodes per group 
Superblock backups stored on blocks: 
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
4096000, 7962624

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

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

检查一下,是否已经格式话好 
[root@linux root]# 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 
255 heads, 63 sectors/track, 4462 cylinders 
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System 
/dev/sdb1 1 4462 35840983+ 83 Linux

再输入fdisk -l 可以看到我们刚才分的一个分区,之后用 mkfs -t ext3 -c /dev/vdb1 进行格式化,如有多个分区可把sdb1改成sdb2 sdb3...以此类推,具体可用fdisk -l看到每个分区的名字
上图蓝色部分是写硬盘卷标的,如不想要卷标可直接按回车,现在分区好了我们用mount 挂载一下该分区即可使用了,这里我把它挂载到mnt目录下,也可以自建一个目录挂载
mount /dev/vdb1 /alidata
来看一下分区大小是否和预定的一样,使用df -TH命令看一下当前挂载的分区和大小,看到我们刚分的分区了吧
如果想每次系统重启都能自动挂载该分区可修改/etc/fstab文件。
vi /etc/fstab
在最后的位置上,添加:
/dev/vdb1  /alidata ext3 defaults 0 0
Esc :wq 保存后,重启机器的话,会自动挂载硬盘。否则,每次重启机器,需要手动mount挂载硬盘。





  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值