1.1 分区

1.1.1 准备环境 添加两块100MG(0.1G)的硬盘

                           

reboot 重启服务器

查看硬盘是否添加成功

fdisk -l 命令

[root@oldboy-39 ~]# fdisk -l|grep "/dev/sd[abc]:"

Disk /dev/sda: 10.7 GB, 10737418240 bytes

Disk /dev/sdb: 106 MB, 106954752 bytes

Disk /dev/sdc: 106 MB, 106954752 bytes

 

1.1.2 创建分区的过程

  fdisk给小于2TB磁盘进行分区(MBR

 parted 给大于2TB磁盘进行分区(GPT 小于2TB也可以用)

1.1.3  fdisk进行分区小于2TB的磁盘

【第一步】  fdisk -cu /dev/sdb

创建一个50M的主分区

[root@oldboy-39 ~]# fdisk -cu /dev/sdb   -c 关掉DOS-compatible模式  -u在列出分区表时,在扇区中给出大小,而不是柱面

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

Building a new DOS disklabel with disk identifier0xb58dc072.

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)

 

Command (m for help):

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

Command (m for help): n

Command action  

   e   extended                      ## 扩展分区

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

p

Partition number (1-4): 1

First sector (2048-208895, default 2048):            ##直接按回车

Using default value 2048

Last sector, +sectors or +size{K,M,G} (2048-208895,default 208895): +50M  ###分多大的空间(分50M)   

Command (m for help): p

 

Disk /dev/sdb: 106 MB, 106954752 bytes

64 heads, 32 sectors/track, 102 cylinders, total208896 sectors

Units = sectors of 1 * 512 = 512 bytes

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

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

Disk identifier: 0xb58dc072

 

   DeviceBoot      Start         End      Blocks  Id  System

/dev/sdb1           2048      104447       51200  83  Linux

 

Command (m for help):

【第二步】 先创建扩展在创建逻辑分区

Command (m for help): n

Command action

   e   extended

   p   primary partition (1-4)

e                                ##扩展分区

Partition number (1-4): 2                

First sector (104448-208895, default 104448):   

Using default value 104448

Last sector, +sectors or +size{K,M,G}(104448-208895, default 208895):   ##剩多少给多少 按回车

Using default value 208895

Command (m for help): n                             ##新建分区

Command action

   l   logical (5 or over)                      ##逻辑分区

   p   primary partition (1-4)

l

First sector (106496-208895, default 106496):                ##按回车

Using default value 106496

Last sector, +sectors or +size{K,M,G}(106496-208895, default 208895): +20  ##分20M的空间

 

Command (m for help): p

 

Disk /dev/sdb: 106 MB, 106954752 bytes

64 heads, 32 sectors/track, 102 cylinders, total208896 sectors

Units = sectors of 1 * 512 = 512 bytes

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

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

Disk identifier: 0xb58dc072

 

   DeviceBoot      Start         End      Blocks  Id  System

/dev/sdb1            2048      104447       51200  83  Linux

/dev/sdb2          104448      208895       52224   5  Extended

/dev/sdb5          106496      147455       20480  83  Linux

 

Command (m for help):

实例1-1删除分区

Command (m for help): d

Partition number (1-5): 1

实例1-2把磁盘sdb的容量用了创建一个分区 /dev/sdb1 ,把这个分区挂载到/mnt 
第一个里程碑-创建分区

Command (m for help): p

Disk /dev/sdb: 106 MB, 106954752 bytes
64 heads, 32 sectors/track, 102 cylinders, total 208896 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0c7ada8f

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First sector (2048-208895, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-208895, default 208895): 
Using default value 208895

Command (m for help): p         

Disk /dev/sdb: 106 MB, 106954752 bytes
64 heads, 32 sectors/track, 102 cylinders, total 208896 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0c7ada8f

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048      208895      103424   83  Linux
Command (m for help): w                ##保存退出
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

第二个里程碑-通知系统 /dev/sdb磁盘的分区表修改了  变化了

partprobe/dev/sdb                       ##执行命令即可

第三个里程碑-格式化创建文件系统

[root@oldboy-39 ~]# mkfs.ext4  /dev/sdb1         ##格式化

mke2fs 1.41.12 (17-May-2010)

Filesystem label=

OS type: Linux

Block size=1024 (log=0)

Fragment size=1024 (log=0)

Stride=0 blocks, Stripe width=0 blocks

25896 inodes, 103424 blocks

5171 blocks (5.00%) reserved for the super user

First data block=1

Maximum filesystem blocks=67371008

13 block groups

8192 blocks per group, 8192 fragments per group

1992 inodes per group

Superblock backups stored on blocks:

    8193,24577, 40961, 57345, 73729

 

Writing inode tables: done                           

Creating journal (4096 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.

第四个里程碑-让系统不对我们新创建的分区 进行磁盘检查

[root@oldboy-39 ~]# tune2fs -c 0 -i 0 /dev/sdb1   ##-c挂载次数 -i 每个多少天

tune2fs 1.41.12 (17-May-2010)

Setting maximal mount count to -1

Setting interval between checks to 0 seconds

第五个里程碑-挂载与检查

[root@oldboy-39 ~]# mount /dev/sdb1 /mnt/          ##挂载

[root@oldboy-39 ~]# df -h                          ##检查

Filesystem     Size  Used Avail Use% Mounted on

/dev/sda3      8.8G  1.5G  6.9G 18% /

tmpfs          491M     0  491M  0% /dev/shm

/dev/sda1      190M   35M  146M 19% /boot

/dev/sdb1       94M  1.6M   88M  2% /mnt

第六个历程碑-需要永久挂载

  1. 挂载命令放入到 /etc/rc.local 文件中

  2. /etc/fstab