`
tiankefeng0520
  • 浏览: 143065 次
  • 性别: Icon_minigender_1
  • 来自: 长春
社区版块
存档分类
最新评论

Linux学习记录--磁盘分区,格式化与检验

阅读更多

磁盘分区,格式化与检验

 

磁盘分区:fdisk

磁盘格式化:mkfs,mke2fs

磁盘检测:fsck

大容量磁盘分区:parted

 

磁盘分区

 

语法:fdisk[-l] 设备名称

-l:输出系统内所有分区

 

举例:

[root@localhost ~]# fdisk -l
 
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
 
  Device Boot      Start         End      Blocks  Id  System
/dev/sda1  *           1          13     104391   83  Linux
/dev/sda2              14        1288   10241437+  83  Linux
/dev/sda3            1289        1925    5116702+  83  Linux
/dev/sda4            1926        2610    5502262+   5  Extended
/dev/sda5            1926        2052    1020096   82 Linux swap / Solaris
/dev/sda6            2053        2302    2008093+  83  Linux


1.       查看磁盘文件名

[root@localhost ~]# df /

文件系统               1K-块        已用     可用 已用% 挂载点

/dev/sda2              9920624   4329108  5079448  47% /

 

2.       查看磁盘分区功能

[root@localhost ~]# fdisk /dev/sda  //这里不带数字
 
The number of cylinders for this disk isset to 2610.
There is nothing wrong with that, but thisis larger than 1024,
and could in certain setups cause problemswith:
1) software that runs at boot time (e.g.,old versions of LILO)
2) booting and partitioning software fromother 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 compatibilityflag
  d   delete a partition //删除磁盘分区
  l   list known partition types
  m   print this menu  //查看磁盘分区功能
  n   add a new partition //增加一个磁盘分区
  o   create a new empty DOSpartition table
  p   print the partition table //查看磁盘分区
  q   quit without saving changes
  s   create a new empty Sundisklabel
  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 (expertsonly)

 

删除磁盘分区

[root@localhost ~]# fdisk /dev/sda
 
The number of cylinders for this disk isset to 2610.
There is nothing wrong with that, but thisis larger than 1024,
and could in certain setups cause problemswith:
1) software that runs at boot time (e.g.,old versions of LILO)
2) booting and partitioning software fromother OSs
  (e.g., DOS FDISK, OS/2 FDISK)
 
Command (m for help): p
 
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
 
  Device Boot      Start         End     Blocks   Id  System
/dev/sda1  *           1          13      104391  83  Linux
/dev/sda2              14        1288   10241437+  83  Linux
/dev/sda3            1289        1925    5116702+  83  Linux
/dev/sda4            1926        2610    5502262+   5  Extended
/dev/sda5            1926        2052    1020096   82  Linux swap / Solaris
/dev/sda6            2053        2302    2008093+  83  Linux

由上可知我的磁盘主要分为6个分区,1,2,3为主分区,4为扩展分区,5为swap分区,6是逻辑分区

 

Command (m for help): d
Partition number (1-6): 3
 
Command (m for help): p
 
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
 
  Device Boot      Start         End      Blocks  Id  System
/dev/sda1  *           1          13      104391  83  Linux
/dev/sda2              14        1288   10241437+  83  Linux
/dev/sda4            1926        2610    5502262+   5  Extended
/dev/sda5            1926        2052    1020096   82  Linux swap / Solaris
/dev/sda6            2053        2302    2008093+  83  Linux
 
删除主分区sad3 后可以看到磁盘信息不在包含sad3
Command (m for help): d
Partition number (1-6): 4
 
Command (m for help): p
 
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
 
  Device Boot      Start         End      Blocks  Id  System
/dev/sda1  *           1          13      104391  83  Linux
/dev/sda2              14        1288   10241437+  83  Linux

删除扩展分区sad4 后可以看到扩展分区,逻辑分区都被删除(因为逻辑分区是由扩展分区衍生而来的)。

 

增加磁盘分区

磁盘分区最多只能有4个主分区+扩展分区组成,其中扩展分区最多只能有一个,剩下在创建的分区都是由扩展分区衍生出来的逻辑分区

 举例1. 由于磁盘现分区分为3个主分区,1个扩展分区。因此在创建时将直接创建逻辑分区,而不在询问是否创建主分区或者扩展分区

[root@localhost ~]# fdisk /dev/sda
 
The number of cylinders for this disk isset to 2610.
There is nothing wrong with that, but thisis larger than 1024,
and could in certain setups cause problemswith:
1) software that runs at boot time (e.g.,old versions of LILO)
2) booting and partitioning software fromother OSs
  (e.g., DOS FDISK, OS/2 FDISK)
 
Command (m for help): p
 
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
 
  Device Boot      Start         End      Blocks  Id  System
/dev/sda1  *           1          13      104391  83  Linux
/dev/sda2              14        1288   10241437+  83  Linux
/dev/sda3            1289        1925    5116702+  83  Linux
/dev/sda4            1926        2610    5502262+   5  Extended
/dev/sda5            1926        2052    1020096   82 Linux swap / Solaris
/dev/sda6            2053        2302    2008093+  83  Linux
 
Command (m for help): n
First cylinder (2303-2610, default 2303):


举例2:创建主/扩展分区

[root@localhost ~]# fdisk /dev/sda
 
The number of cylinders for this disk isset to 2610.
There is nothing wrong with that, but thisis larger than 1024,
and could in certain setups cause problemswith:
1) software that runs at boot time (e.g.,old versions of LILO)
2) booting and partitioning software fromother OSs
  (e.g., DOS FDISK, OS/2 FDISK)
 
Command (m for help): d //先将主分区和逻辑分区删除(如果为4个则默认创建逻辑分区)
Partition number (1-6): 2
 
Command (m for help): d
Partition number (1-6): 4
 
Command (m for help): p
 
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
 
  Device Boot      Start         End      Blocks  Id  System
/dev/sda1  *           1          13      104391  83  Linux
/dev/sda3            1289        1925    5116702+  83  Linux
 
Command (m for help): n
Command action
   e  extended
   p  primary partition (1-4)

 

提示用户选择是是创建主分区还是扩展分区

 

举例3.创建逻辑分区与扩展分区

root@localhost ~]# fdisk /dev/sda
 
The number of cylinders for this disk isset to 2610.
There is nothing wrong with that, but thisis larger than 1024,
and could in certain setups cause problemswith:
1) software that runs at boot time (e.g.,old versions of LILO)
2) booting and partitioning software fromother OSs
  (e.g., DOS FDISK, OS/2 FDISK)
 
Command (m for help): p
 
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
 
  Device Boot      Start         End      Blocks  Id  System
/dev/sda1  *           1          13      104391  83  Linux
/dev/sda2             14        1288   10241437+  83  Linux
/dev/sda3            1289        1925    5116702+  83  Linux
/dev/sda4            1926        2610    5502262+   5  Extended
/dev/sda5            1926        2052    1020096   82  Linux swap / Solaris
/dev/sda6            2053        2302    2008093+  83  Linux
 
Command (m for help): d
Partition number (1-6): 4
 
Command (m for help): n
Command action
  e   extended
  p   primary partition (1-4)
e
Selected partition 4
First cylinder (1926-2610, default 1926):
Using default value 1926
Last cylinder or +size or +sizeM or +sizeK(1926-2610, default 2610):
Using default value 2610
 
Command (m for help): p
 
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
 
  Device Boot      Start         End      Blocks  Id  System
/dev/sda1  *           1          13      104391  83  Linux
/dev/sda2              14        1288   10241437+  83  Linux
/dev/sda3            1289        1925    5116702+  83  Linux
/dev/sda4            1926        2610    5502262+   5  Extended

 

sd4为新创建的扩展分区,大小为从柱面1926到2610

 

Command (m for help): nFirstcylinder (1926-2610, default 1926):
Usingdefault value 1926
Lastcylinder or +size or +sizeM or +sizeK (1926-2610, default 2610): +500M

 

对于此处可以指定柱面号码,以可以通过+XXM指定大小,让其自动分配柱面

 

Command (m for help): p
 
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
 
  Device Boot      Start         End      Blocks  Id  System
/dev/sda1  *           1          13      104391  83  Linux
/dev/sda2              14        1288   10241437+  83  Linux
/dev/sda3            1289        1925    5116702+  83  Linux
/dev/sda4            1926        2610    5502262+   5  Extended
/dev/sda5            1926        1987      497983+ 83  Linux

 

sd5为新创建的逻辑分区,大小为500M

 

内核查找分区

当我们增加分区后,系统让我们reboot 以加载分区。也可以不用重启,只需要通知内容重新查找分区即可

The partition table has been altered!
 
Calling ioctl() to re-read partition table.
 
WARNING: Re-reading the partition tablefailed with error 16: 设备或资源忙.
The kernel still uses the old table.
The new table will be used at the nextreboot.
Syncing disks.[root@localhost~]# partprobe

 

 

磁盘格式化

分区完毕后要进行文件系统的格式化

 

mkfs

语法:mkfs[-t 文件系统格式] 设备文件名

选项与参数:

-t:文件系统格式,例如ext3,ext2,vfat等

 

举例

[root@localhost ~]# mkfs -t ext3 /dev/sda7
mke2fs 1.39 (29-May-2006)
Filesystemlabel=
OS type: Linux
Blocksize=1024 (log=0)
Fragment size=1024 (log=0)
50200 inodes, 200780 blocks
10039 blocks (5.00%) reserved for the superuser
First data block=1
Maximum filesystem blocks=67371008
25 block groups
8192 blocks per group, 8192 fragments pergroup
2008 inodes per group
Superblock backups stored on blocks:
       8193, 24577, 40961, 57345, 73729
 
Writing inode tables: done                           
Creating journal (4096 blocks): done
Writing superblocks and filesystemaccounting information: done
 
This filesystem will be automaticallychecked every 37 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

 

其中文件系统Label 以及iBLOCK大小均采用默认大小。如果对于EXT2/EXT3 我们对这些信息由特殊的需求,可以使用mke2fs

 

mke2fs

语法:mke2fs[-b block大小] [-i inode 大小] [-L 卷标] [-cj] 设备

选项与参数:

-b:设置block大小,目前支持1024,2048,4096

-i:多少容量给予一个inode

-c:检查磁盘错误

-L:卷标名称(Label)

-j:自动加入日志系统成为EXT3文件系统,不加在默认为EXT2

举例

[root@localhost ~]# mke2fs -b 2048 -i 4096-L "TKFDISK" -j /dev/sda7
mke2fs 1.39 (29-May-2006)
Filesystemlabel=TKFDISK
OS type: Linux
Blocksize=2048 (log=1)
Fragment size=2048 (log=1)
50288 inodes, 100390 blocks
5019 blocks (5.00%) reserved for the superuser
First data block=0
Maximum filesystem blocks=103809024
7 block groups
16384 blocks per group, 16384 fragments pergroup
7184 inodes per group
Superblock backups stored on blocks:
       16384, 49152, 81920
 
Writing inode tables: done                           
Creatingjournal (4096 blocks): done
Writing superblocks and filesystemaccounting information: done
 
This filesystem will be automaticallychecked every 31 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

 

磁盘检测(fsck)

语法: fsck [-t 文件系统格式] [-ACay]

选项与参数

-t  :文件系统格式。

-A  :依据/etc/fstab 的内容,将需要的装置扫瞄一次。

-a  :自动修复检查到的有问题的扇区.

-y  :与 -a 类似,但是某些filesystem 仅支持 -y 这个参数

-C  :可以在检验的过程当中,使用一个直方图来显示目前的进度!

 

EXT2/EXT3 的额外选项功能:(e2fsck 这支命令所提供)

-f  :强制检查!一般来说,如果 fsck 没有发现任何 unclean 的旗标,不会主动进入细部检查的,如果您想要强制 fsck 进入细部检查,就得加上 -f

-D  :针对文件系统下的目录进行优化配置。

 

举例

[root@localhost ~]# fsck -Cf /dev/sda7
fsck 1.39 (29-May-2006)
e2fsck 1.39 (29-May-2006)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure                                          
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
TKFDISK: 11/50288 files (9.1%non-contiguous), 7673/100390 blocks       

说明:需要磁盘检查的分区不能挂载在系统上,需要先被卸载才能磁盘检测

 

大容量磁盘分区(parted)

由于fdisk无法支持到高于2TB以上的分区,此时就需要parted来处理了

 

语法:parted [设备] [命令 [参数]]

选项与参数:

新增分区:mkpart [primary|logical|extended] [ext3|vfat]开始结束

分区表:print

删除分区:rm [partition]

 

举例1:查看分区表

[root@bogon ~]# parted /dev/sda print

Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type      File system  标志
 1      32.3kB  107MB   107MB   主分区    ext3         启动
 2      107MB   10.6GB  10.5GB  主分区    ext3             
 3      10.6GB  15.8GB  5240MB  主分区    ext3             
 4      15.8GB  21.5GB  5634MB  扩展分区                   
 5      15.8GB  16.9GB  1045MB  逻辑分区  linux-swap       

信息: 如果必要,不要忘记更新 /etc/fstab。  


 

通过以上信息可以看出,扩展分区到21.5G,逻辑分区使用到16.9G,那么16.9G~21.5G只部分空间还为被使用(未被分区)

 

举例2:新增分区

[root@bogon ~]# parted /dev/sda mkpart logical ext3 16.9G 18.9G
信息: 如果必要,不要忘记更新 /etc/fstab。                                 

[root@bogon ~]# parted /dev/sda print

Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type      File system  标志
 1      32.3kB  107MB   107MB   主分区    ext3         启动
 2      107MB   10.6GB  10.5GB  主分区    ext3             
 3      10.6GB  15.8GB  5240MB  主分区    ext3             
 4      15.8GB  21.5GB  5634MB  扩展分区                   
 5      15.8GB  16.9GB  1045MB  逻辑分区  linux-swap       
 6      16.9GB  18.9GB  2023MB  逻辑分区                   


 

举例3:删除分区

[root@bogon ~]# parted /dev/sda rm 6
信息: 如果必要,不要忘记更新 /etc/fstab。                                 

[root@bogon ~]# parted /dev/sda print

Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type      File system  标志
 1      32.3kB  107MB   107MB   主分区    ext3         启动
 2      107MB   10.6GB  10.5GB  主分区    ext3             
 3      10.6GB  15.8GB  5240MB  主分区    ext3             
 4      15.8GB  21.5GB  5634MB  扩展分区                   
 5      15.8GB  16.9GB  1045MB  逻辑分区  linux-swap       

信息: 如果必要,不要忘记更新 /etc/fstab。 
说明:parted分区提交即执行,因此使用起来需小心    
0
0
分享到:
评论

相关推荐

    RHCE课程笔记

    RHCE课程-RH131Linux管理笔记七-Linux分区,格式化,SWAP,LVM,软件RAID的创建 12月27日课程 8、自动挂载和NIS服务器及客户端配置 9、软件RIDE及XEN虚拟机 RHCE课程-RH131Linux管理笔记八-安装和管理XEN虚拟机 1月...

    鸟哥的私房菜.pdf

    第12章 正则表达式与文件格式化处理 第13章 学习shell script 第四部分 Linux使用者管理 第14章 Linux账号管理与ACL权限设置 第15章 磁盘配额(Quota)与高级文件系统管理 第16章 例行性工作(crontab) 第17章 ...

    入门学习Linux常用必会60个命令实例详解doc/txt

    Linux提供了大量的命令,利用它可以有效地完成大量的工作,如磁盘操作、文件存取、目录操作、进程管理、文件权限设定等。所以,在Linux系统上工作离不开使用系统提供的命令。要想真正理解Linux系统,就必须从Linux...

    LINUX操作系统(电子教案,参考答案)

    主要包括Linux的基本概念和操作,Linux的树型结构,Linux的文本编辑,Linux的安装和启动,用户管理,Shell编程技术,进程管理,C编译器,系统扩充,维护与监视,Linux的图形界面,网络的基本概念与设置,Linux在网络...

    linux教程——很使用的那种

    另外linux在每个分区都有保留块,这是专门留给root用户及其所属组使用,别的用户是无法使用的,一般为总数据块的5%,但是如果你的磁盘大的话,就显的浪费了。 mkfs.ext3 -b 2046 -m 2 /dev/hda5。格式化并设置数据块为2...

    Linux常用的命令。。。。。

    fdisk –l 查看磁盘分区信息 mkfs 查看格式化的版本 eg. mkfs.ext4 +设备 格式化 mount 查看挂载信息 virtual-manage 打开虚拟机 eg. mv /usr/bin/passwd /usr/bin/pw 将改密码的命令passwd 改为pw pwd 用户目前...

    grub4dos-V0.4.6a-2017-02-04更新

    FAT16、FAT32 分区使用 8.3 格式; ext2、exFAT、NTFS 分区使用 12 字符。 7.3 在 grldr.mbr 中:使用 12 字符。 7.4 为了兼容各类分区,建议文件名不要大于 8 字符,后缀不要大于 3 字符。若有分隔符“.”,...

    DISKGEN硬盘分区及数据恢复软件

     9、支持FAT12、FAT16、FAT32、NTFS分区的已删除文件恢复、分区误格式化后的文件恢复。成功率较高;  10、增强的已丢失分区恢复(重建分区表)功能,恢复过程中,可即时显示搜索到的分区参数及分区内的文件。搜索...

    rufus:可靠的USB格式化实用程序

    Rufus:可靠的USB格式化实用程序 Rufus是一个实用程序,可帮助格式化和创建可启动的USB闪存驱动器。 产品特点 将USB,闪存卡和虚拟驱动器格式化为FAT / FAT32 / NTFS / UDF / exFAT / ReFS / ext2 / ext3 使用或MS...

    RED HAT LINUX 6大全

    本书内容翔实、涉及领域广泛,并且提供了详细的例子和大量的参考资料(包括书籍、电子文档和Internet站点),是一本学习、使用和管理Linux不可多得的好书。 目 录 译者序 前言 第一部分 Red Hat Linux的介绍与安装 ...

    Linux指令一周通 (技术图书大系).azw3

    3.13 fdisk指令:Linux磁盘分区 3.14 fsck 指令:检查文件系统并修复分区错误 3.15 fsck.ext2指令:检查ext2文件系统 3.16 fsconf指令:设置文件系统相关功能 3.17 hdparm指令:显示和设定硬盘参数 3.18 lndir指令:...

    LINUX 20招

    一般的解决方法就是格式化硬盘来重新安装系统,但这有点儿小题大作了。准备好bootdisk和rootdisk两张软盘,从软驱启动,启动到root盘并出现shell提示符。将Linux根目录分区mount至/mnt目录,比如你的Linux在硬盘第一...

    ARM_Linux启动分析.pdf

    也就是说,我们的bzImage文件或者zImage文件是按照bootsect,setup, vmlinux这样的顺序组织,并存放于始于引导分区的首扇区的连续磁盘扇区之中。 bootsect.S完成加载动作后,就直接跳转到0x90200,这里正是setup....

    Linux搭建iscsi服务,客户端(Linux&Win XP)挂载使用

    文章目录实验环境实验步骤一、检验网络的连通性,三台计算机主机互联互通二、RHEL Server添加10G新磁盘,并安装target三、RHEL Server上target管理,将两个分区加入网络硬盘四、Linux Client安装iscsi客户端并发现、...

    Taobao oceanbase代码

    //供学习用,禁止用于商业用途。 2012.04.20  OceanBase解决什么问题  许多公司的核心资产是各种各样的商业数据,例如淘宝的商品、交易、订单、购物爱好等等,这些数据通常是结构化的,并且数据之间存在各种...

    万能启动u盘制作工具 FbinstTool v1.6

    格式化参数只有-p,-e,-l,--zip, --chs, --max-sectors的值,没有数据分区格式化的参数(它们无法自动检测)。而且,如果某一数值和缺省值相同时,将不会显示。-l里显示的数值将上调到510的倍数(实际保存的数值是以...

    ext2fsd-0.46.8.3

    1、偶尔的能用一次,后来都莫名其妙的不能挂载分区,或是挂载之后打不开分区(显示“未被格式化”); 2、基本上都不能正常挂载移动硬盘上的ext分区,甚至检测不到移动盘; 3、写操作之后会破坏ext文件系统或破坏...

    网管教程 从入门到精通软件篇.txt

    不扫描驱动器看是否有坏区域,因此只应对以前格式化过的驱动器使用该参数。  /fs:file-system  指定要使用的文件系统:FAT、FAT32 或 NTFS 。如果未指定文件系统,将使用现有的文件系统格式。  Map  显示...

    DISKGEN命令详解

    此外,它还具有分区格式化、分区无损调整、硬盘表面扫描、扇区拷贝、彻底清除扇区数据等实用功能。虽然Disk Genius功能更强大了,但它的身材依然“苗条”,只有区区143KB。 一、Disk Genius的主要功能及特点 1、...

Global site tag (gtag.js) - Google Analytics