2.磁盘分区、格式化、挂载,ext文件系统管理命令

本文详细介绍了Linux系统中磁盘分区的过程,包括MBR、使用fdisk命令创建分区,以及分区类型的更改。接着讲解了如何格式化分区,特别是ext文件系统的创建、管理和维护。此外,还讨论了文件系统的挂载、卸载操作,以及swap文件系统和/etc/fstab配置文件在系统管理中的作用。内容涵盖了从创建分区到格式化,再到文件系统管理和挂载的完整流程。
摘要由CSDN通过智能技术生成

0.目录

1.创建分区

1.1 MBR

磁盘的最前端,即0号磁道,0号扇区(sector)称为MBR(Master Boot Record)。组成如下:

  • Bootloader
    MBR的前446字节是Bootloader,用来引导操作系统启动。
  • 分区表
    之后的64字节为分区表,每16个字节标识一个分区,所以一个磁盘最多划分为4个主分区
    若需划分4个以上的分区,可使用扩展分区。扩展分区指向磁盘中的某段空间,在这段空间中可标识各逻辑分区。逻辑分区可以像主分区一样格式化、挂载。
    不论主分区有多少,只要使用逻辑分区,它的编号都是从5开始,1-4是主分区使用的。
  • magic number
    魔数,占2字节。用来标识当前MBR是否有效。

1.2 命令fdisk

命令fdisk,用于管理磁盘分区。
选项“-l”,列出指定磁盘上的分区情况,如不指定参数则列出所有分区。

[root@localhost ~]# fdisk -l /dev/sda

Disk /dev/sda: 85.9 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00093481

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64       10444    83373056   8e  Linux LVM

其中Boot项下带“*”的表示,操作系统安装在该分区;Start表示分区的起始柱面号,End为其结束柱面号1;Blocks为分区的块数量;Id用来标识该分区的类型。

管理分区只需直接跟指定设备即可,fdisk是交互式的,使用m键可查看各功能。

[root@localhost ~]# fdisk /dev/sda

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

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)
按键 意义
n 创建新分区
d 删除分区
t 更改分区类型(即system Id)
l 列出所有支持的分区类型
w 保存退出
q 不保存退出,即放弃本次修改
p 效果同fdisk -l

1.3 实际创建、更改分区过程

1.3.1 创建分区、更改分区类型

1、在/dev/sdb创建一个3G大小的主分区:

[root@local ~]# fdisk /dev/sdb

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change 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                   # 分区编号
First cylinder (1-13054, default 1):        # 该分区的第一个柱面的编号,直接回车表示使用默认
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-13054, default 13054): +3G                                 # 指定该分区使用多少柱面,或直接指定其大小

2、其余空间分配给一个扩展分区:

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
e                                               # 指定为扩展分区
Partition number (1-4): 2                       # 分区编号
First cylinder (394-13054, default 394): 
Using default value 394
Last cylinder, +cylinders or +size{K,M,G} (394-13054, default 13054): 
Using default value 13054                       # 扩展分区大小默认使用所有剩余空间

3、在此扩展分区上创建一个5G大小的逻辑分区:

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l                                               # 指定创建逻辑分区。不论主分区有多少,逻辑分区的编号默认从5开始
First cylinder (39
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值