主要内容:

==========================================

一、fdisk命令中参数介绍

二、将/dev/sdd整个磁盘划成一个文件分区

三、删除整个分区

四、创建两个分区,分区一200M,分区二800M

五、创建主分区、扩展分区、逻辑分区

六、使用单个分区的方式进行格式化分区

七、挂载分区

八、配置开启自动挂载分区

九、挂载光驱

 

==========================================

 

一、fdisk命令中参数介绍:

Command (m forhelp): 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)

  

二、将/dev/sdd 整个磁盘划成一个文件分区

 

[root@db01 ~]# fdisk/dev/sdd

Command(m for help): p          ###查看分区信息

Disk /dev/sdd: 1073MB, 1073741824 bytes

255 heads, 63sectors/track, 130 cylinders

Units = cylinders of16065 * 512 = 8225280 bytes

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

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

Disk identifier:0x0814ae42

 

   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  ###分区号为1

First cylinder (1-130, default 1):  ###柱面默认为1

Using default value1

Last cylinder, +cylinders or +size{K,M,G} (1-130, default 130):   ###柱面默认为最大130 (即使用全部剩余空间)

Using default value130

 

Command(m for help): w      ###按照以上分区信息写入磁盘

The partition tablehas been altered!

 

Calling ioctl() tore-read partition table.

Syncing disks.

 

 

三、删除整个分区

 

Command(m for help):p                        ###查看分区信息

 

Disk /dev/sdd: 1073MB, 1073741824 bytes

255 heads, 63sectors/track, 130 cylinders

Units = cylinders of16065 * 512 = 8225280 bytes

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

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

Disk identifier:0x0814ae42

 

   Device Boot      Start         End      Blocks  Id  System

/dev/sdd1               1         130    1044193+  83  Linux

 

Command(m for help): d   ###删除分区

Selectedpartition1                        ###只有一个分区时,默认删除

 

Command(m for help): w  ###按照以上分区信息写入磁盘

The partition tablehas been altered!

 

Calling ioctl() tore-read partition table.

Syncing disks.

 

 

四、创建两个分区,分区一200M,分区二800M

[root@db01 ~]# fdisk/dev/sdd

 

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

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

         sectors (command 'u').

 

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

Command action

   e  extended

   p  primary partition (1-4)

p                                                                                ###创建主分区

Partition number (1-4): 1  ###分区号为1

First cylinder (1-130, default 1):   ###柱面默认为1

Using default value1

Last cylinder, +cylinders or +size{K,M,G} (1-130, default 130):+200M    ###该分区分配200M空间

 

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

Command action

   e  extended

   p  primary partition (1-4)

p                                                                                ###创建主分区

Partition number (1-4): 2  ###分区号为2

First cylinder (27-130, default 27): ###柱面默认为27

Using default value27

Last cylinder, +cylinders or +size{K,M,G} (27-130, default130):   ###柱面默认为最大130(即使用全部剩余空间)

Using default value130

 

Command (m forhelp): p

 

Disk /dev/sdd: 1073MB, 1073741824 bytes

255 heads, 63sectors/track, 130 cylinders

Units = cylinders of16065 * 512 = 8225280 bytes

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

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

Disk identifier:0x0814ae42

 

   Device Boot      Start         End      Blocks  Id  System

/dev/sdd1               1          26      208813+ 83  Linux

/dev/sdd2              27         130      835380  83  Linux

 

Command(m for help): w     ###按照以上分区信息写入磁盘

The partition tablehas been altered!

 

Calling ioctl() tore-read partition table.

Syncing disks.

 

 

五、创建主分区、扩展分区、逻辑分区

[root@db01 ~]# fdisk/dev/sdd

 

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

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

         sectors (command 'u').

 

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

Command action

   e  extended

   p  primary partition (1-4)

p                                                                            ###创建主分区

Partition number (1-4): 1  ###分区号为1

First cylinder (1-130, default 1): ###柱面默认为1

Using default value1

Last cylinder, +cylinders or +size{K,M,G} (1-130, default 130):+200M  ###该分区分配200M空间

 

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

Command action

   e  extended

   p  primary partition (1-4)

e                                                                                ###创建扩展分区

Partition number (1-4): 2  ###分区号为2

First cylinder (27-130, default 27):   ###柱面默认为27

Using default value27

Last cylinder, +cylinders or +size{K,M,G} (27-130, default130):    ###柱面默认为最大130 (即使用全部剩余空间)扩展分区必须是剩余全部空间

Using default value130

 

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

Command action

   l  logical (5 or over)

   p  primary partition (1-4)

l                                                                                ###创建逻辑分区

First cylinder (27-130, default 27): ###柱面默认为27

Using default value27

Last cylinder, +cylinders or +size{K,M,G} (27-130, default 130):+200M  ###该分区分配200M空间

 

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

Command action

   l  logical (5 or over)

   p  primary partition (1-4)

l                                                                                ###创建逻辑分区

First cylinder (53-130, default 53): ###柱面默认为53

Using default value53

Last cylinder, +cylinders or +size{K,M,G} (53-130, default 130):+200M ###该分区分配200M空间

 

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

Command action

   l  logical (5 or over)

   p  primary partition (1-4)

l                                                                                ###创建逻辑分区

First cylinder (79-130, default 79): ###柱面默认为79

Using default value79

Last cylinder, +cylinders or +size{K,M,G} (79-130, default130):  ###柱面默认为最大130(即使用全部剩余空间)

Using default value130

 

Command (m forhelp): p

 

Disk /dev/sdd: 1073MB, 1073741824 bytes

255 heads, 63sectors/track, 130 cylinders

Units = cylinders of16065 * 512 = 8225280 bytes

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

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

Disk identifier:0x0814ae42

 

   Device Boot      Start         End      Blocks  Id  System

/dev/sdd1               1          26      208813+ 83  Linux

/dev/sdd2              27         130      835380   5  Extended

/dev/sdd5              27          52      208813+ 83  Linux

/dev/sdd6              53          78      208813+ 83  Linux

/dev/sdd7              79         130      417658+ 83  Linux

 

Command(m for help):w   ###按照以上分区信息写入磁盘

 

 

 

六、使用单个分区的方式进行格式化分区

[root@db01 ~]# fdisk-l /dev/sdd

 

Disk /dev/sdd: 1073MB, 1073741824 bytes

255 heads, 63sectors/track, 130 cylinders

Units = cylinders of16065 * 512 = 8225280 bytes

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

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

Disk identifier:0x0814ae42

 

   Device Boot      Start         End      Blocks  Id  System

/dev/sdd1               1         130    1044193+  83  Linux

 

[root@db01~]# partprobe /dev/sdd    #将分区信息写入磁盘

 

[root@db01 ~]# ls-lsa /dev/sdd*

0 brw-rw----. 1 rootdisk 8, 48 Nov 21 11:02 /dev/sdd

0 brw-rw----. 1 rootdisk 8, 49 Nov 21 11:02 /dev/sdd1

 

格式化分区:

1mkfs -t ext4 /dev/sdd1    (这种方法不方便,不推荐使用)

2mkfs.ext4 /dev/sdd1

 

[root@db01 ~]#mkfs.ext4 /dev/sdd1

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

65280 inodes, 261048blocks

13052 blocks (5.00%)reserved for the super user

First data block=0

Maximum filesystemblocks=268435456

8 block groups

32768 blocks pergroup, 32768 fragments per group

8160 inodes pergroup

Superblock backupsstored on blocks:

        32768, 98304, 163840, 229376

 

Writing inodetables: done                           

Creating journal(4096 blocks): done

Writing superblocksand filesystem accounting information: done

 

This filesystem willbe automatically checked every 34 mounts or

180 days, whichevercomes first.  Use tune2fs -c or -i tooverride.

 

 

七、挂载分区

[root@db01 ~]# mkdir/alexpeng

[root@db01 ~]# mount/dev/sdd1 /alexpeng

[root@db01 ~]# df -h

Filesystem      Size Used Avail Use% Mounted on

/dev/sda3        45G 4.4G   39G  11% /

tmpfs          1004M     0 1004M  0% /dev/shm

/dev/sda1       485M  39M  421M   9% /boot

/dev/sdb2        79G 184M   75G   1% /oracle

/dev/sdb1        20G 172M   19G   1% /soft

/dev/sdd1      1004M  18M  936M   2% /alexpeng

[root@db01 ~]# cd/alexpeng/

[root@db01alexpeng]# mkdir test

[root@db01alexpeng]# ls

lost+found  test

[root@db01alexpeng]# cd test

[root@db01 test]#touch 1

[root@db01 test]# ls

1

[root@db01 test]# cd/   

[root@db01 /]#umount /alexpeng/

 

八、配置开启自动挂载分区

[root@db01 /]# vi/etc/fstab

 

UUID=3e8b0960-23d2-48f3-8661-3f24ce85e9e6/                       ext4    defaults        1 1

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/sdd1               /alexpeng               ext4    defaults        0 0

 

测试配置是否正确

[root@db01 /]#umount /alexpeng/

[root@db01 /]# mount/alexpeng/

 

如果不正确出现以下信息:

[root@db01 /]# mount/alexpeng/

mount: can't find/alexpeng/ in /etc/fstab or /etc/mtab

 

注:(1tmpfs类型:临时文件,默认为内存的一半,调优时根据实际进行调整。

2UUID  mkfs执行时生成的ID

 

[root@db01 /]# lsblk -f  ##fstab中的UUID来自以下文件

NAME   FSTYPE LABEL UUID                                 MOUNTPOINT

sr0                                                     

sda                                                     

|-sda1 ext4         303c8d3c-ec73-418b-8ad4-6fbf541b65b0/boot

|-sda2 swap         e64234e4-fe04-4d35-ada4-d8be48ceef4f[SWAP]

`-sda3 ext4         3e8b0960-23d2-48f3-8661-3f24ce85e9e6 /

sdb                                                     

|-sdb1 ext4         b630b5c1-fa7f-435e-93ef-374730511674/soft

`-sdb2 ext4         94296492-f293-4409-9dbe-8de35f62d16e/oracle                                                    

`-sdd1 ext4         b346b7a3-9a8c-4d83-88d1-1853af298fe2

                                                

九、挂载光驱

 

[root@db01 /]# touch 1.iso   ###创建iso格式的文件

[root@db01 /]# mount -t iso9660 -o loop /1.iso  /mnt   #挂载ISO格式,光驱为回环设备 。此处为文件系统类型错误。

mount: wrong fstype, bad option, bad superblock on /dev/loop0,

       missing codepage or helper program, orother error

       In some cases useful info is found insyslog - try

       dmesg | tail  or so

 

[root@db01 /]#

[root@db01 /]# mount-t iso9660  /1.iso  /mnt

mount: /1.iso is nota block device (maybe try `-o loop'?)

 

[root@db01/]# mount /dev/cdrom /mnt    ###挂载光驱

mount: block device/dev/sr0 is write-protected, mounting read-only

[root@db01/]# cd /mnt  ###检查是否挂载成功

[root@db01 mnt]# ls

EFI      EULA_pt                  RELEASE-NOTES-de-DE.html RELEASE-NOTES-ko-KR.html RELEASE-NOTES-te-IN.html    images

......

[root@db01 /]# umount /dev/cdrom  ###卸载光驱。 umount /mnt 也可以卸载光驱

[root@db01 /]#

[root@db01/]# mount /dev/cdrom /mnt   ###挂载光驱

mount: block device/dev/sr0 is write-protected, mounting read-only

[root@db01 /]#

[root@db01/]# eject /dev/cdrom   ###弹出光驱