天天看点

磁盘分区管理

1.设备的识别 

/dev/sda    ###系统中的第一块串口硬盘  (sata串口) 

/dev/hda    ###系统中第一快并口硬盘  (IDE) 

/dev/hdb    ###系统中第二快并口硬盘 

/dev/cdrom    ###系统光驱 

/dev/mapper/xxx    ###虚拟设备  

2.设备的使用 

mount    设备    挂载点    ###挂载 

mount /dev/sda1  /mnt  ###把系统中的第一快硬盘的第一个分区挂载到/mnt下 

umount    设备|挂载点    ###卸载设备  

blkid            ###显示所有可用设备的id信息 

df     -h(2的n次方) -H(10的n此方)            ####查看挂载信息 

du    -h(显示单位)    -s(只统计目录本身) 

file|dir    ####统计文件大小 

3.当设备卸载出现以下问题时 

[root@foundation0 ~]# umount /mnt/ umount: /mnt: target is busy.         (In some cases useful info about processes that use          the device is found by lsof(8) or fuser(1))  

  用 fuser    设备|挂载点

      lsof    设备|挂载点 

    来找到占用设备的进程

4.什么时mbr?

    MBR是Main Bootable Record,即主引导记录,它记录了整个硬盘的分区信息。在硬盘做分区动作时,保存在被激活的分区(一般是将C区激活)里。格式化不能清除MBR,只有重新分区里才以新的MBR信息替换掉原有的。 

5.分区

[root@diskctrl ~]# fdisk  /dev/vdb        ##划分/dev/vdb 

Welcome to fdisk (util-linux 2.23.2).

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

Be careful before using the write command.

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            ##删除设备

   g   create a new empty GPT partition table

   G   create an IRIX (SGI) partition table

   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

Partition type:p            ##指定划分设备的分区类型

   p   primary (0 primary, 0 extended, 4 free)

   e   extended

Partition number (1-4, default 1):1    ##指定使用的分区表号

First sector (2048-20971519, default 2048):enter    ##分区起始快,选择默认

Using default value 2048

Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +1G ##设备大小指定

Command (m for help): p            ##显示分区表

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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 label type: dos

Disk identifier: 0x7c2200a8

   Device Boot      Start         End      Blocks   Id  System

/dev/vdb1            2048     2099199     1048576   83  Linux        ##被划分出来的分区

Command (m for help):  wq                        ##保存更改方式并退出

[root@diskctrl ~]# partprobe             ##同步分区表

[root@diskctrl ~]# cat /proc/partitions     ##查看系统能识别的分区

major minor  #blocks  name

 253        0   10485760 vda

 253        1   10484142 vda1

 253       16   10485760 vdb

 253       17    1048576 vdb1

mkfs.ext4   /vdb1  创建文件系统

6.如何使用新建立的分区

vim /etc/fstab 实现永久挂载

/dev/vdb1  /mnt  ext4  defaults  0  0

7.设备删除

卸载

删除 /etc/fstab中设备的自动挂载条目

用fdisk删除分区

8.swap分区的管理

swapon -s        ##查看系统中的swap分区

建立swap分区

mkswap    /dev/vdb1    ###把/dev/vdb1格式化成swap格式

swapon -a /dev/vdb1    ##激活

vim /etc/fstab        ##开机自动激活

/dev/vdb1    swap    swap    defautls    0 0

本文转自willis_sun 51CTO博客,原文链接:http://blog.51cto.com/willis/1846984,如需转载请自行联系原作者