磁盘管理是linux管理的基础知识,同时也是学习linux的必备知识。系统需要从硬盘读写数据时,需要以下步骤:应用程序向(系统库)系统接口调用发起读写请求,系统接口调用将用户请求转译到虚拟文件系统,虚拟文件系统按特定格式对硬盘进行操作

linux磁盘管理_基础知识



  1. 分区为什么要对硬盘进行分区,一块硬盘正如一个大的书架,我们要在书架上存放各种书籍(数据),为了以后方便管理使用,一般会把书架分成几个区域,比如第一层存放科技类的书籍,第二层存放杂志类书籍……

    分区常用到的命令fdisk

查看分区状态,下图未分区的硬盘

linux磁盘管理_基础知识_02

  1. 2    选择要进行分区的硬盘,按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 ---------添加dos分区

   p   print the partition table ------显示当前硬盘已分区状况

   q   quit without saving changes ------退出不保存之前所做操作

   s   create a new empty Sun disklabel -----创建一个新的sun(Oracle Solairs )硬盘标签

   t   change a partition's system id ------改变分区ID(相当于改变分区类型)

   u   change display/entry units ------改变显示的单位

   v   verify the partition table ------检查验证分区表

   w   write table to disk and exit 保存退出

   x   extra functionality (experts only)

linux磁盘管理_应用程序_03

linux磁盘管理_应用程序_04

linux磁盘管理_科技类_05

  1. 格式化常用用到的命令:mkfs, mkfs.ext[2-4]

  2. 1 格式化的意义

   从各个逻辑盘指定柱面开始,对扇区进行逻辑编号。

在基本分区上建立mbr引导记录

在各个逻辑分区建立文件分配表

建立根目录相应的元数据属性及数据区(DATA

linux磁盘管理_action_06

linux磁盘管理_linux_07

mke2fs 1.41.12 (17-May-2010)

文件系统标签=

操作系统:Linux

块大小=4096 (log=2)

分块大小=4096 (log=2)

Stride=0 blocks, Stripe width=0 blocks

655776 inodes, 2622603 blocks  #表示inode数值,数据块大小

131130 blocks (5.00%) reserved for the super user

第一个数据块=0

Maximum filesystem blocks=2688548864

81 block groups

32768 blocks per group, 32768 fragments per group

8096 inodes per group

Superblock backups stored on blocks:

         32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

 

正在写入inode: 完成                           

Creating journal (32768 blocks): 完成

Writing superblocks and filesystem accounting information: 完成

 

This filesystem will be automatically checked every 39 mounts or

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

 

  1. 挂载

磁盘分区格式化之后,linux不会自动挂载,必须手动挂载。

挂载方式

  1. 以设备名挂载

  2. uuid挂载

  3. 以自定义设备标签挂载

查看UUID

# blkid /dev/sdb1

/dev/sdb1: UUID="f6ae3d68-4ee1-405d-968f-d67395532616" TYPE="ext4"

挂载到指定目录(目录事先存在)

# mount UUID="f6ae3d68-4ee1-405d-968f-d67395532616" /mydata

临时挂载会在系统重启后失效,将挂载信息写入/etc/fstab,开机时会自动进行挂载

#vim /etc/fstab

# /etc/fstab

# Created by anaconda on Sun Jan 11 06:10:41 2015

#

# Accessible filesystems, by reference, are maintained under '/dev/disk'

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

#

UUID=4637b7ad-88c8-4b77-84e4-d7a620ab7e0f /                       ext4    defaults        1 1

UUID=70a07a88-bb71-4602-9df2-570edfafcdc4 /boot                   ext4    defaults        1 2

UUID=5eeec46e-d66a-4974-8aec-6783d8f413d5 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

UUID=f6ae3d68-4ee1-405d-968f-d67395532616 /mydata               ext4    defaults        1 2

 

 

 

 

 

 

 

 

 

 

 

 

 

 

http://www.iteye.com/topic/816268