分区原理

  • 主分区表(64byte):记录分区的起始与结束柱面、主分区个数。主分区大小有限,不能超过四个主分区
  • 扩展分区:将一个主分区更改成扩展分区,扩展分区支持无限个分区(逻辑分区),逻辑分区的信息写在扩展分区表中。

格式化原理

也就是创建不同的文件系统,供数据的存储与读取。
常用的linux分区工具:fdisk,sfdisk,diskdruid

一般使用过程

  • 运行命令:#fdisk /dev/hdX
  • 添加/删除/修改分区
  • 重新启动计算机(生效,由内核读取分区表信息的)

    [root@server root]# fdisk /dev/hda

    The number of cylinders for this disk is set to 9729.
    There is nothing wrong with that, but this is larger than 1024,
    and could in certain setups cause problems with:
    1) software that runs at boot time (e.g., old versions of LILO)
    2) booting and partitioning software from other OSs
    (e.g., DOS FDISK, OS/2 FDISK)

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

Linux的格式化工具

mkfs - 支持ext2、ext3(日志)、vfat、msdos、jfs、reiserfs等    
用法1:mkfs -t <fstype> <partition>    
例:#mkfs -t ext3 /dev/hda1    
用法2:mkfs.<fstype> <partition>    
例:#mkfs.vfat /dev/hda2    
mke2fs - 支持ext2/ext3文件系统    
用法:mke2fs [-j] <partition>    
例:#mke2fs -j /dev/hdb2

## 硬盘分区的挂载

1、挂载命令:#mount  (临时挂载,重启系统无效)
例:#mount /dev/hda11 /mnt/d2
2、卸载命令:#umount
例:umount /dev/hda11
3、写入/etc/fstab(自动挂载,系统启动时)
/dev/hda11  /mnt/d2 /ext3 defaults 0 0

## 使用卷标挂载

  • 添加卷标 —— e2label

例:#e2label /dev/hda10 test

  • 根据卷标挂载

例:#mount LABEL=test /mnt/d1

  • 写入/etc/fstab

LABEL=test /mnt/d1 /ext3 defaults 0 0

ext2/ext3挂载选项

  • ro/rw ——只读/读写
  • exec/noexec——允许/不允许可执行
  • dev/nodev——允许/不允许设备文件
  • suid,sgid/nosuid/nosgid——允许/不允许suid,sgid文件
  • atime/noatime——更新/不更新节点的访问时间
  • async/sync——异步/同步磁盘I/O
  • user/nouser——允许/不允许普通用户挂载磁盘,用于/etc/fstable文件中的选项