How to mount a new hard disk under Linux

Hard Disk Recognition in Linux:

Generally use the "fdisk -l" command to list the currently connected hard disks in the system

Device and partition information. The new hard disk has no partition information, only the hard disk size information is displayed.


1. Turn off the server and add a new hard disk


2. Start the server and log in as root user


3. View hard disk information

#fdisk -l

[cpp]  view plain copy  
  1. Disk /dev/sda: 42.9 GB, 42949672960 bytes  
  2. 255 heads, 63 sectors/track, 5221 cylinders  
  3. Units = cylinders of 16065 * 512 = 8225280 bytes  
  4. Sector size (logical/physical): 512 bytes / 512 bytes  
  5. I/O size (minimum/optimal): 512 bytes / 512 bytes  
  6. Disk identifier: 0x0004406e  
  7.    Device Boot      Start         End      Blocks   Id  System  
  8. /dev/sda1   *           1          39      307200   83  Linux  
  9. Partition 1 does not end on cylinder boundary.  
  10. /dev/sda2              39        2589    20480000   83  Linux  
  11. /dev/sda3            2589        2850     2097152   82  Linux swap / Solaris  
  12. /dev/sda4            2850        5222    19057664    5  Extended  
  13. /dev/sda5            2850        5222    19056640   83  Linux  
  14.    
  15. Disk /dev/sdb: 10.7 GB, 10737418240 bytes  
  16. 255 heads, 63 sectors/track, 1305 cylinders  
  17. Units = cylinders of 16065 * 512 = 8225280 bytes  
  18. Sector size (logical/physical): 512 bytes / 512 bytes  
  19. I/O size (minimum/optimal): 512 bytes / 512 bytes  
  20. Disk identifier: 0x14b52796  
  21.    Device Boot      Start         End      Blocks   Id  System  

4.创建新硬盘分区命令参数:

fdisk可以用m命令来看fdisk命令的内部命令;

a:命令指定启动分区;

d:命令删除一个存在的分区;

l:命令显示分区ID号的列表;

m:查看fdisk命令帮助;

n:命令创建一个新分区;

p:命令显示分区列表;

t:命令修改分区的类型ID号;

w:命令是将对分区表的修改存盘让它发生作用。

 


5.进入磁盘,对磁盘进行分区,注意红色部分。

#fdisk /dev/sdb

[cpp]  view plain  copy
  1. Command (m for help):n  
  2. Command action  
  3.      e    extended                  //输入e为创建扩展分区  
  4.      p    primary partition (1-4)      //输入p为创建逻辑分区  
  5. p  
  6. Partion number(1-4):1      //在这里输入l,就进入划分逻辑分区阶段了;  
  7. First cylinder (51-125, default 51):   //注:这个就是分区的Start 值;这里最好直接按回车,如果您输入了一个非默认的数字,会造成空间浪费;  
  8. Using default value 51  
  9. Last cylinder or +size or +sizeM or +sizeK (51-125, default 125): +200M 注:这个是定义分区大小的,+200M 就是大小为200M ;当然您也可以根据p提示的单位cylinder的大小来算,然后来指定 End的数值。回头看看是怎么算的;还是用+200M这个办法来添加,这样能直观一点。如果您想添加一个10G左右大小的分区,请输入 +10000M ;  
  10.   
  11. Command (m for help): w                     //最后输入w回车保存。  

查看一下: 

#fdisk -l

可以看到/dev/sdb1分区,我就省略截图咯。

 

6.格式化分区:

#mkfs.ext3 /dev/sdb1           //注:将/dev/sdb1格式化为ext3类型

[cpp]  view plain  copy
  1. mke2fs 1.41.12 (17-May-2010)  
  2. 文件系统标签=  
  3. 操作系统:Linux  
  4. 块大小=4096 (log=2)  
  5. 分块大小=4096 (log=2)  
  6. Stride=0 blocks, Stripe width=0 blocks  
  7. 640848 inodes, 2562359 blocks  
  8. 128117 blocks (5.00%) reserved for the super user  
  9. 第一个数据块=0  
  10. Maximum filesystem blocks=2625634304  
  11. 79 block groups  
  12. 32768 blocks per group, 32768 fragments per group  
  13. 8112 inodes per group  
  14. Superblock backups stored on blocks:  
  15.         32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632  
  16.    
  17. 正在写入inode表: 完成  
  18. Creating journal (32768 blocks): 完成  
  19. Writing superblocks and filesystem accounting information: 完成  
  20.    
  21. This filesystem will be automatically checked every 35 mounts or  
  22. 180 days, whichever comes first.  Use tune2fs -c or -i to override.  

这样就格式化好了,我们就可以用mount 加载这个分区,然后使用这个文件系统;


7.创建/data1目录:

#mkdir /data1


8. Start mounting the partition:

#mount /dev/sdb1 /data1


9. Check the hard disk size and mounted partition:

#df -h


10. Configure automatic mount at startup

Because the mount will fail after restarting the server, you need to write the partition information to the /etc/fstab file to make it permanently mounted:

#vim /etc/fstab

join in:

/dev/sdb1 (disk partition) /data1 (mount directory) ext3 (file format) defaults 0 0


11. Restart the system


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324668167&siteId=291194637