2023拉

Linux下磁盘挂载及分区

上一篇 / 下一篇  2012-05-22 13:03:05 / 个人分类:Linux杂谈

Linux磁盘挂载是比较常见的对linux系统管理的操作之一,需要耐心才能正确实现自动挂载,便于日后提高工作效率,和方便查看。

首先,为了需要,新添加一块磁盘到linux主机中,目的是让这个新添加的磁盘分区格式化并可以随系统启动自动挂载。

1.首先查看系统中磁盘信息,并确定是否需要分区。

[root@localhost ~]# fdisk -l

Disk /dev/sda: 16.1 GB, 16106127360 bytes

255 heads, 63 sectors/track, 1958 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: 0x0000d60e

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          64      512000   83  Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2              64        1959    15215616   8e  Linux LVM

Disk /dev/sdb: 10.7 GB, 10737418240 bytes

255 heads, 63 sectors/track, 1305 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        此处显示磁盘dev/sdb尚未格式化。

如上所示,系统中有两块磁盘sdasdb,并提示sdb未含有分区表,需要将其进行分区操作。

2.对磁盘进行分区操作

[root@localhost ~]# fdisk /dev/sdb

Command (m for help): p                               pprint the partintion table

Disk /dev/sdb: 6442 MB, 6442450944 bytes                显示磁盘基本信息

255 heads, 63 sectors/track, 783 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

此处可以看出,尚未对磁盘进行分区

Command (m for help):n                              nadd a new partition

Command action

e extended                                           选择主分区还是扩展分区,在此选择主分区

p primary partition (1-4)

p

Partition number (1-4): 1                               选择分区数。

First cylinder (1-783, default 1):                            设置分区大小。此处定义1000M。就是最接近1000M的柱面号码

Using default value 1

Last cylinder or +size or +sizeM or +sizeK (1-783, default 783): +1000M

Command (m for help):w                                如无误输入w保存配置信息,如不保存输入q退出

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

Command (m for help): p                                如下查看分区之后的磁盘信息

3.将分区好的磁盘进行格式化操作

[root@localhost ~]# fdisk –l                              使用fdisk查看磁盘分区情况

4.将分区格式化完毕的磁盘挂载,检查确认分区格式化完毕。

[root@localhost dev]# mkdir /mnt/sdb3                 新建一个目录sdb,便于管理系统在mnt目录下创建目录。

[root@localhost mnt]# mount /dev/sdb3 /mnt/sdb3     将磁盘sdb挂载到系统中

[root@localhost sdb3]# ls                              进行写文件测试,检查是否可以对磁盘进行读写(是否格式化)

a.txt b.txt lost+found                                  使用vi a.txt进行写测试

5.测试无误后将其卸载

[root@localhost mnt]#umount /dev/sdb3

6.修改fstab文件,如下所示:

[root@localhost mnt]# vi /etc/fstab

LABEL=/ / ext3 defaults 1 1

tmpfs /dev/shm tmpfs defaults 0 0

devpts /dev/pts devpts gid=5,mode=620 0 0

sysfs /sys sysfs defaults 0 0

proc /proc proc defaults 0 0

LABEL=SWAP-sda2 swap swap defaults 0 0

/dev/sdb3 /mnt/sdb3 ext3 defaults 0 0

提示:you must specify the filesystem type

执行这个 mkfs.ext3 /dev/sda3


7.重启linux系统,检查挂载情况

[root@localhost sdb1]# df

文件系统   1K-块    已用     可用       已用  挂载点

/dev/sda1  8022104  2893532  4714500     39%      /

tmpfs       127720        127720      0%       /dev/shm

/dev/sdb3  972404   17640   905368      2%      /mnt/sdb3

如上所示,将新建的磁盘的1个分区顺利挂载到系统中。


TAG:

blue40131的个人空间 引用 删除 blue40131   /   2012-06-06 17:32:37
5
 

评分:0

我来说两句

Open Toolbar