下面介绍相应的步骤:1、安装硬盘(过程略)
2、fdisk -l 查看硬盘代号
3、fdisk 分区格式化
4、创建新的挂载点:/disk2
5、手动挂载分区
6、设置为开机自动挂载分区
- 将硬盘分区:
- 将硬盘连接起来,fdisk -l 可以得到计算机上连接的硬盘的信息
- 使用命令fdisk(/sbin/fdisk)
- fdisk的使用可以参看fdisk提供的帮助,根据此命令运行时的信息操作即可
- 我的电脑上有两块sata的硬盘,第二块就是/dev/sdb
fdisk /dev/sdb - 创建新的分区:
输入n - 创建逻辑分区:
输入p - 输入分区号以及指定分区大小
根据提示操作即可 - 检查分区情况,此时还未执行分区操作
Command(m for help):p 这里输入p检查刚才所做的操作是否正确: - 确认以后保存(w)退出(q)
输入wq - 硬盘分区操作完成,接着要进行格式化操作,否则硬盘不能使用
- 将硬盘格式化
- 分区完成后,接着要对硬盘进行格式化操作,使它成为Linux系统格式,相应用命令为mkfs.ext3 /dev/sdb(可以根据希望格式化的分区格式来执行不同的命令或者输入不同的参数,此命令将第二块串口硬盘格式化为ext3格式)
- 挂载硬盘
- 在当前硬盘上指定挂载点:
在/目录建立了一个新的目录用来挂载硬盘:mkdir /new_disk_dir - 挂载硬盘分区到挂载点
mount /dev/sdb1 /new_disk_dir - 使得新硬盘能够开机时就自动挂载。
修改文件/etc/fstab,在其中加入一行,在这个文件中记录了Linux系统外挂进来的文件格式,加入下面一行:
/dev/sdb1 /des_dir ext3 defaults 1 1
这样,/des_dir就是新硬盘的目录,这里ext3是Linux系统的文件格式,/etc/fstab的格式见下文; - 目录的访问的权限(谁能访问,以什么权限的访问)的操作:
自己有一个普通用户worker,将新的目录的拥有者更改为worker,
chown worker.worker /des_dir
这样,worker登陆以后,就可以正常的访问目录/des_di
- 在当前硬盘上指定挂载点:
- 开始使用
重新启动以后就可以正常使用
如何使用这个就不用多说了吧??哈哈!! - 对于/etc/fstab文件中的格式的补充说明:
/etc/fstab
/etc/fstab的格式如下:
fs_spec fs_file fs_type fs_options fs_dump fs_pass
fs_spec: 该字段定义希望加载的文件系统所在的设备或远程文件系统,对于nfs这个参数一般设置为这样:192.168.0.1:/NFS
fs_file: 本地的挂载点
fs_type: 文件系统格式,对于NFS来说这个字段只要设置成nfs就可以了
fs_options: 挂载的参数,可以使用的参数可以参考上面的mount参数。
fs_dump - 该选项被"dump"命令使用来检查一个文件系统应该以多快频率进行转储,若不需要转储就设置该字段为0
fs_pass - 该字段被fsck命令用来决定在启动时需要被扫描的文件系统的顺序,根文件系统"/"对应该字段的值应该为1,其他文件系统应该为2。若该文件系统无需在启动时扫描则设置该字段为0 。
-
对于新添加的硬盘如何使用fdisk的一个补充: 以root权限执行fdisk -l 以后,输出信息中会有如下一行信息显示: Disk /dev/sdc doesn't contain a valid partition table 在上一句中,/dev/sdc就是我新增加的硬盘在linux的标识。 得到新的硬盘的标识以后就可以进行分区、格式化等操作了
实例介绍: [root@AMD-LINUX ~]# fdisk -l Disk /dev/sda: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0x0007d856
Device Boot Start End Blocks Id System /dev/sda1 * 1 25 200781 83 Linux /dev/sda2 26 1305 10281600 8e Linux LVM
Disk /dev/sdb: 2147 MB, 2147483648 bytes <=新硬盘 255 heads, 63 sectors/track, 261 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0x00000000
Disk /dev/sdb doesn't contain a valid partition table
Disk /dev/dm-0: 9395 MB, 9395240960 bytes 255 heads, 63 sectors/track, 1142 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0x00000000
Disk /dev/dm-0 doesn't contain a valid partition table
Disk /dev/dm-1: 1073 MB, 1073741824 bytes 255 heads, 63 sectors/track, 130 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0x30307800
Disk /dev/dm-1 doesn't contain a valid partition table
[root@AMD-LINUX ~]# 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 0x623223a1. 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)
Command (m for help): p <=显示信息
Disk /dev/sdb: 2147 MB, 2147483648 bytes 255 heads, 63 sectors/track, 261 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0x623223a1
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,即/dev/sdb1 First cylinder (1-261, default 1): Using default value 1 Last cylinder or +size or +sizeM or +sizeK (1-261, default 261): Using default value 261
Command (m for help): p <=显示分区信息
Disk /dev/sdb: 2147 MB, 2147483648 bytes 255 heads, 63 sectors/track, 261 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0x623223a1
Device Boot Start End Blocks Id System /dev/sdb1 1 261 2096451 83 Linux
Command (m for help): w <=保存退出
The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@AMD-LINUX ~]# mkdir /disk2 [root@AMD-LINUX ~]# fdisk -l
Disk /dev/sda: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0x0007d856
Device Boot Start End Blocks Id System /dev/sda1 * 1 25 200781 83 Linux /dev/sda2 26 1305 10281600 8e Linux LVM
Disk /dev/sdb: 2147 MB, 2147483648 bytes 255 heads, 63 sectors/track, 261 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0x623223a1
Device Boot Start End Blocks Id System /dev/sdb1 1 261 2096451 83 Linux
Disk /dev/dm-0: 9395 MB, 9395240960 bytes 255 heads, 63 sectors/track, 1142 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0x00000000
Disk /dev/dm-0 doesn't contain a valid partition table Disk /dev/dm-1: 1073 MB, 1073741824 bytes 255 heads, 63 sectors/track, 130 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0x30307800
Disk /dev/dm-1 doesn't contain a valid partition table
[root@AMD-LINUX ~]# mke2fs -j /dev/sdb1 mke2fs 1.40.2 (12-Jul-2007) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) 262144 inodes, 524112 blocks 26205 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=536870912 16 block groups 32768 blocks per group, 32768 fragments per group 16384 inodes per group Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Writing inode tables: done Creating journal (8192 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 36 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@AMD-LINUX ~]# vi /etc/fstab <= 5、设置为开机自动挂载分区 [root@AMD-LINUX ~]# mount /dev/sdb1 /disk2/ <= 6、手动挂载分区
查看最后结果:df