Linux下添加新硬盘,分区并设置启动自动挂载
Linux下的分区相对Windows而言要稍微复杂一点,下面就由我给大家带来在Linux下新添加硬盘,分区并实现系统启动时自动挂载的过程
操作方法
- 01
检查发现系统上目前并没有挂载新的硬盘,如下图所示:
- 02
添加硬盘后我们启动电脑并再次检查,我们可以看到最下面多了一行“Disk /dev/sdb doesn't contain a valid partition table”,告诉我们有一块新的硬盘,但是还没有分区;如下图所示:
- 03
根据以上提示开始对新的硬盘进行分区操作,由于截图比较麻烦所以呢我把命里copy出来了,需要操作的部分我会标记出来 [root@Linux ~]# fdisk /dev/sdb //根据提示,对新硬盘进行分区操作Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabelBuilding a new DOS disklabel. Changes will remain in memory only,until you decide to write them. After that, of course, the previouscontent won't be recoverable.The number of cylinders for this disk is set to 2610.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: unknown commandCommand 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,建立主分区Partition number (1-4): 1 //一共可以分4个主分区,输入 1,建立第一个主分区First cylinder (1-2610, default 1): //选择该分区的起始磁盘数,如无特殊需求强烈建议选择默认,也就是默认用1 来分区(直接按回车)Using default value 1Last cylinder or +size or +sizeM or +sizeK (1-2610, default 2610): //定义该分区的大小,如果按默认(直接回车),就是使用全部可用存储空间;如果要分成一个 1G 的空间,输入 +1024m 即可,1G=1024m算法以此类推Using default value 2610Command (m for help): w //写入分区信息,其实就是保存分区信息The partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.
- 04
完成以上操作后我们可以看到新添加的硬盘已经存在分区了
- 05
下面对分区进行格式化操作: [root@Linux ~]# mkfs -t ext3 -c /dev/sdb1 //对分区使用 ext3 格式化,如果建立了多个分区,显示 /dev/sdb2、/dev/sdb3 等,以此类推,重复输入这条命令,就可以进行其它分区的格式化操作了。因为新硬盘加了-c参数,要先检测磁盘坏道,因此,这个过程全有些长,需要耐心等待……注意这里的时间长短时根据你的硬盘大小来实现的,如果硬盘大时间就会久一些,否则就会小短一些mke2fs 1.39 (29-May-2006) Filesystem label= OS type: Linux Block size=4096 (log=2)Fragment size=4096 (log=2)1310720 inodes, 5241198 blocks131029 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=0160 block groups32768 blocks per group, 32768 fragments per group16384 inodes per groupSuperblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632Checking for bad blocks (read-only test): done Writing inode tables: done Creating journal (32768 blocks): doneWriting superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 32 mounts or180 days, whichever comes first. Use tune2fs -c or -i to override.
- 06
开始对分区进行挂载使用,首先创建一个用于挂载的目录
- 07
将分区挂载到www目录下
- 08
输入vim /etc/fstab进行编辑,并在该文件内输入以下内容,然后在:wq保存并退出,重启验证即可