磁盘管理之二磁盘分区
来源:互联网 发布:淘宝差评时间 编辑:程序博客网 时间:2024/05/20 00:50
在学习Linux磁盘分区之前,我们先来初步了解下硬盘分区的基本概念。在Linux中规定,每一个硬盘设备最多能有4个主分区
(包含扩展分区
),扩展分区也需要占用一个主分区号码,并且扩展分区在使用的时候必须先进行分区后才能使用,也就是第二次分区。第二次分它就是逻辑分区
。同时需要注意分区的编号,主分区按1234编号。如果第一个IDE硬盘的第一个主分区为hd1,则该硬盘的逻辑分区编号应重hd5开始。
好了,我们开始来学习命令了。磁盘分区常用的命令有:fdisk
、partprobe
、mkfs
、mke2fs
、fsck
、badblocks
、mount
、umount
。
分区流程:
- 使用fdisk命令对磁盘进行分割
- 分割完成的磁盘进行格式化,以便创建系统可以的文件系统
- 对创建完成后的文件系统进行检验
- 检验完成后对磁盘进行挂载就好了
磁盘分区 fdisk、 partprobe
[root@bogon ~]# fdisk -l #查看根目录下的磁盘,和磁盘的相关信息 Disk /dev/sda: 21.4 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System/dev/sda1 * 1 38 305203+ 83 Linux/dev/sda2 39 1255 9775552+ 83 Linux/dev/sda3 1256 1499 1959930 83 LinuxDisk /dev/sdb: 10.7 GB, 10737418240 bytes255 heads, 63 sectors/track, 1305 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System/dev/sdb1 1 244 1959898+ 83 Linux
格式为:[root@bogon ~]# fdisk 磁盘名称 [root@bogon ~]# fdisk /dev/sdb #磁盘名称不要加数字哦The number of cylinders for this disk is set to 1305.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)
fdisk命令在离开时使用q退出,所有的操作都不会生效,相反w就动作生效的意思。实际生产中要谨慎使用w。
Command (m for help): n #新建分区Command action e extended p primary partition (1-4)p #主分区Partition number (1-4): 2 #2号分区First cylinder (245-1305, default 245): #使用Enter件默认开始扇区地址Using default value 245Last cylinder or +size or +sizeM or +sizeK (245-1305, default 1305): +4G #可指定的扇面结束位置或给定磁盘大小
新建完分区怎么删除呢?其实很简单,使用d就可以
Command (m for help): d #删除Partition number (1-4): 2 #2号分区Command (m for help): p #查看分区情况Disk /dev/sdb: 10.7 GB, 10737418240 bytes255 heads, 63 sectors/track, 1305 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System/dev/sdb1 1 244 1959898+ 83 Linux
操作完成后使用w完成分区同步。线上请谨慎使用w进行操作。
[root@bogon ~]# partprobe 通知内核更新分区表
磁盘格式化 mkfs
格式为:[root@bogon ~]# mkfs [-t 文件系统] 磁盘分区名称 [root@bogon ~]# mkfs -t ext3 /dev/sdb1 mke2fs 1.39 (29-May-2006)Filesystem label=OS type: LinuxBlock size=4096 (log=2)Fragment size=4096 (log=2)245280 inodes, 489974 blocks24498 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=50331648015 block groups32768 blocks per group, 32768 fragments per group16352 inodes per groupSuperblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912Writing inode tables: done Creating journal (8192 blocks): doneWriting superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 33 mounts or180 days, whichever comes first. Use tune2fs -c or -i to override.
磁盘检验 fsck、 badblocks
[root@bogon ~]# fsck -t 文件系统 [-ACay]硬盘分区名称-t 指定文件系统,系统默认情况下可以自动匹配到文件系统-A 依据/etc/fstab 的内容,将需要的装置扫瞄一次。。-a 自动修复检查到的有问题的扇区-y 与-a类似,有效文件系统只支出-y-C 用来显示目前的进度![root@bogon ~]# fsck -C -f -t ext3 /dev/sdb1fsck 1.39 (29-May-2006)e2fsck 1.39 (29-May-2006)Pass 1: Checking inodes, blocks, and sizesPass 2: Checking directory structure Pass 3: Checking directory connectivityPass 4: Checking reference countsPass 5: Checking group summary information/dev/sdb1: 11/245280 files (9.1% non-contiguous), 16629/489974 blocks
fsck检查文件系统,badblocks为检查磁盘是否有坏轨。
格式为:[root@bogon ~]# badblocks -[svw]磁盘分区名称-s 列出进度-v 看到进度条-w 以写的方式检查,注意尽量不要使用此参数,特别是当有硬盘有内容时。[root@bogon ~]# badblocks -sv /dev/sdb1Checking blocks 0 to 1959898Checking for bad blocks (read-only test): done Pass completed, 0 bad blocks found.
磁盘的挂载和卸载 mount、 umount
磁盘的挂载
格式为:[root@bogon ~]# mount [-L label] [-o 额外选项] [-n]分区名 挂载点[root@bogon ~]# mount -a #显示未挂载的磁盘[root@bogon ~]# mount -l #显示目前挂载的信息 包含label
示例1 挂载ext3文件系统:[root@bogon ~]# mkdir /mnt/sdb1 [root@bogon ~]# mount /dev/sdb1 /mnt/sdb1 [root@bogon ~]# dfFilesystem 1K-blocks Used Available Use% Mounted on.....中间省略..... /dev/sdb1 1976312 42072 1833836 3% /mnt/hdc6
示例2 挂载u盘:[root@bogon ~]# mkdir /mnt/flash [root@bogon ~]# mount -t vfat -o iocharset=cp950 /dev/sda1 /mnt/flash [root@bogon ~]# dfFilesystem 1K-blocks Used Available Use% Mounted on.....中间省略...../dev/sda1 8102416 4986228 3116188 62% /mnt/flash
磁盘的卸载
格式为:[root@bogon ~]# umount [-fn]分区名或挂载点-f 强制卸载-n 不升级/etc/mtab 情况下卸除
卸载磁盘,可使用挂载点或磁盘分区或磁盘lable[root@bogon ~]# umount /dev/sdb1 #卸载[root@bogon ~]# mount -L "logical_1" /mnt/sdb1 #使用lable卸载
阅读全文
0 0
- 磁盘管理之二磁盘分区
- 磁盘管理1--磁盘分区
- 磁盘管理之二
- linux磁盘管理二之磁盘配额
- Linux--磁盘管理(磁盘分区、挂载卸载及磁盘限额)
- Windows磁盘管理工具Diskpart之二 管理动态磁盘
- Solaris10中级读书笔记之二:管理本地磁盘设备
- Linux磁盘管理之LVM及RAID管理二之RAID管理
- 磁盘分区管理
- 磁盘分区管理
- Linux--磁盘管理(磁盘分区、挂载卸载及磁盘限额)
- 磁盘管理之三
- 磁盘管理之四
- 磁盘管理之五
- vim 之 磁盘管理
- 磁盘管理之分区
- 操作系统之磁盘管理
- Linux之磁盘管理
- Kotlin真的会取代JAVA吗?
- python(pil)图像处理(等比例压缩、裁剪压缩) 缩略(水印)图
- [乐意黎转载]Centos 7 Apache 服务安装及配置
- 浅谈 Linux 下的文件描述符 fd fp
- 如何给div添加placeholder属性
- 磁盘管理之二磁盘分区
- 代价敏感损失函数
- Android 广播介绍以及使用示例
- 一个recycleview实现的画廊
- android之语言国际化
- Flex实例
- redis安装及使用
- 从进程和线程的角度看操作系统
- [乐意黎转载]Centos 7 nginx 服务安装及配置