centos 6.4 fdisk分区、格式化、挂载新硬盘


 

 

 

1、# fdisk -l
查看当前磁盘信息,就会发现最下面显示新加入的硬盘不是有效分区,如下:

[root@mfsdata02 ~]# fdisk -l

 

Disk /dev/sda: 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 / 512bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x000601be

 

   DeviceBoot      Start         End      Blocks  Id  System

/dev/sda1  *           1          26      204800  83  Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2              26          91      524288  82  Linux swap / Solaris

Partition 2 does not end on cylinder boundary.

/dev/sda3              91        1306    9755648   83  Linux

 

Disk /dev/sdb: 2147 MB, 2147483648 bytes

255 heads, 63 sectors/track, 261 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000

 

 

2、# fdisk /dev/sdb

对新硬盘分区,并根据提示进一步操作:

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

Device contains neither a valid DOS partitiontable, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel with disk identifier0x0467cb4f.

Changes will remain in memory only, until youdecide to write them.

After that, of course, the previous content won'tbe recoverable.

 

Warning: invalid flag 0x0000 of partition table 4will be corrected by w(rite)

 

WARNING: DOS-compatible mode is deprecated. It'sstrongly recommended to

        switch off the mode (command 'c') and change display units to

        sectors (command 'u').

 

Command (m for help): m

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): p

 

Disk /dev/sdb: 2147 MB, 2147483648 bytes

255 heads, 63 sectors/track, 261 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x0467cb4f

 

   DeviceBoot      Start         End      Blocks  Id  System

 

Command (m for help): n  #输入n进行分区

 

Command action

   e   extended                                        #e为逻辑分区

   p   primary partition (1-4)              #p为主分区

p

Partition number (1-4): 1                            #(由于是新盘我们输入1来分第一个主分区,共可以分4个主分区)

#(选择该分区的起始磁盘数,如无特殊需求强烈建议选择默认,也就是1来分区(可直接按回车))

First cylinder (1-261, default 1):

Using default value 1

#定义该分区的大小,如果按默认(按回车)即是使用全部可用存储额,如分一个1G的空间,输入+1024m

Last cylinder, +cylinders or +size{K,M,G} (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

Sector size (logical/physical): 512 bytes / 512bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x0467cb4f

 

   DeviceBoot      Start         End      Blocks  Id  System

/dev/sdb1               1         261    2096451   83  Linux

 

Command (m for help): w                           #w写入分区

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

Syncing disks.

You have new mail in /var/spool/mail/root

 

 

3、# fdisk -l

可以找到我们刚才分的一个分区,内容如下:

[root@mfsdata02 ~]# fdisk -l

 

Disk /dev/sda: 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 / 512bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x000601be

 

   DeviceBoot      Start         End      Blocks  Id  System

/dev/sda1  *           1          26      204800  83  Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2              26          91      524288  82  Linux swap / Solaris

Partition 2 does not end on cylinder boundary.

/dev/sda3              91        1306    9755648   83  Linux

 

Disk /dev/sdb: 2147 MB, 2147483648 bytes

255 heads, 63 sectors/track, 261 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x0467cb4f

 

   DeviceBoot      Start         End      Blocks  Id  System

/dev/sdb1               1         261    2096451   83  Linux

[root@mfsdata02 ~]#

 

使用工具partprobe让kernel读取分区信息 
[root@mfsdata02 ~]# partprobe
使用fdisk工具只是将分区信息写到磁盘,如果需要mkfs磁盘分区则需要重启系统,而使用partprobe则可以使kernel重新读取分区 信息,从而避免重启系统。

 

4、# mkfs -t ext4 -c /dev/sdb1

对分区使用ext3格式化,-c参数要先检测磁盘坏道

[root@mfsdata02 ~]# mkfs -t ext4 -c /dev/sdb1

mke2fs 1.41.12 (17-May-2010)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

Stride=0 blocks, Stripe width=0 blocks

131072 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

8192 inodes per group

Superblock backups stored on blocks:

       32768, 98304, 163840, 229376, 294912

 

Checking for bad blocks (read-only test): done                               

Writing inode tables: done                           

Creating journal (8192 blocks): done

Writing superblocks and filesystem accountinginformation: done

 

This filesystem will be automatically checked every27 mounts or

180 days, whichever comes first.  Use tune2fs -c or -i to override.

 

5 新建挂载目录

[root@mfsdata02 ~]# mkdir /mfsdata

6 挂载新硬盘

[root@mfsdata02 ~]# mount /dev/sdb1 /mfsdata

 

7查看分区大小是否和我们预定的一样

[root@mfsdata02 ~]# df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/sda3             9.1G  2.2G 6.5G  25% /

tmpfs                 238M     0 238M   0% /dev/shm

/dev/sda1             190M   54M 127M  30% /boot

/dev/sdb1             2.0G  3.0M 1.9G   1% /mfsdata

[root@mfsdata02 ~]#

You have new mail in /var/spool/mail/root

[root@mfsdata02 ~]#

[root@mfsdata02 ~]#

8、最后也是很容易漏掉的一步

[root@mfsdata02 ~]# echo "/dev/sdb1                    /mfsdata                   ext4    defaults        0 0" >>/etc/fstab

[root@mfsdata02 ~]# cat /etc/fstab

 

#

# /etc/fstab

# Created by anaconda on Sat Jun 13 23:57:00 2015

#

# Accessible filesystems, by reference, aremaintained under '/dev/disk'

# See man pages fstab(5), findfs(8), mount(8)and/or blkid(8) for more info

#

UUID=a99b2855-789d-452d-9b44-aaf00b18fc76 /                       ext4    defaults        1 1

UUID=c229857f-d99f-40f0-bfa6-f68882e7a6a5/boot                   ext4    defaults        1 2

UUID=c2b1447f-6766-4a54-9764-c5b4fd723ca9 swap                    swap    defaults        0 0

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

/dev/sdb1                    /mfsdata                   ext4    defaults        0 0

[root@mfsdata02 ~]#

 

       如果忘了将这个写入配置文件的话,服务器如果重启,硬盘将不会自动挂载,将找不到挂载的文件夹。这时候要再一直mount 挂载一遍。。。

你可能感兴趣的:(Linux)