日期:2014-05-16  浏览次数:20663 次

Linux下添加磁盘
        1、用命令fdisk -l查看新增的磁盘,如:我的是/dev/sdb。然后用命令fdisk /dev/sdb来对你刚才新增的空间划分磁盘分区。你可以分成一个分区,保存退出。在/dev/目录下面多出了一个设备/dev/sdb1,这就是刚才分出来的一个区,用命令mkfs.ext3 /dev/sdb1对其进行格式化。这样之后用MOUNT命令就可以把这个分区MOUNT到系统了,但这并没有完,用ROOT权限MOUNT的分区,mount -t ext3 /dev/sdc1 /usr_tmp其它的用户不能操作,而且这个分区上也不能够运行程序。所以下面继续。
        2、用普通权限在你的用户目录下面创建一个文件夹,如/home/linux/mtdmnt。以后就把你新增的分区MOUNT到这个目录下了哟。
        3、用ROOT权限打下/etc/fstab文件。新增加一个选项。具体fstab的操作在这里不解释了。新增如下: /dev/sdb1 /home/linux/ mtdmnt ext3 noauto,user,exec 0 0 记住中间一定要用TAB键格开。然后保存。这样就设置好了新分区的MOUNT格式。
        4、现在呢,我们来设置如何自动在系统启动的时候MOUNT,UMOUNT这个分区。进入你的用户目录,vi .bashrc,在其中增加一行mount /home/linux/mtdmnt。每项之间用tab隔开最后两个数字选0 0
        5、好了 都设置好了 重新启动系统吧。用df -h查看磁盘情况,就能看到自动mount上了。而且普通用户拥有所有权限,还可以在里面执行文件,跟系统本来的分区一样好使了。
linux下分区、格式化、挂载新硬盘的详细过程
1、# fdisk -l      查看当前磁盘信息,就会发现最下面显示新加入的硬盘不是有效分区,如下:
Disk /dev/sdc: 1500.3 GB, 1500301910016 bytes
255 heads, 63 sectors/track, 182401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdc doesn't contain a valid partition table
2、# fdisk /dev/sdc      对新硬盘分区,并根据提示进一步操作
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.

The number of cylinders for this disk is set to 182401.
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)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): h      输入h可查看帮助命令
h: unknown command
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): n      输入n进行分区
Command action
   e   extended
   p   primary partition (1-4)
p      输入p为主分区,e为逻辑分区
Partition number (1-4): 1      由于是新盘我们输入1来分第一个主分区,共可以分4个主分区
First cylinder (1-182401, default 1):      选择该分区的起始磁盘数,如无特殊需求强烈建议选择默认,也就是1来分区(直接按回车)
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-182401, default 182401):      定义该分区的大小,如果按默认(按回车)即是使用全部可用存储额,如分一个1G的空间,输入+1024m
Using default value 182401
Command (m for help): w      写入分区
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
3、# fdisk -l