linux fdisk 分区、格式化、挂载! | 您所在的位置:网站首页 › 如何格式化一个磁盘 › linux fdisk 分区、格式化、挂载! |
文件系统的一个使用流程: 存储介质选择---》硬盘分区操作;创建分区来容纳文件系统;创建分区,这个分区可以是整个硬盘也可以是部分硬盘----》创建文件系统(我们在存储数据之前,你必须使用文件系统对其分区进行格式化)----》把它挂载到虚拟目录----》写入配置文件/etc/fstab 硬盘分区的划分标准: 硬盘分区由主分区、扩展分区和逻辑分区组成 在一块硬盘上,如果是MBR分区方式,那么它的主分区最多只能有4个,或者3个主分区和1个扩展分区;在扩展分区上我们可以创建多个逻辑分区 分区编号:主分区1-4 ,逻辑分区5.。。。。。 LINUX规定:逻辑分区必须建立在扩展分区之上,而不是建立在主分区上 分区作用: 主分区:主要是用来启动操作系统的,它主要放的是操作系统的启动或引导程序,/boot分区最好放在主分区上扩展分区不能使用的,它只是做为逻辑分区的容器存在的;我们真正存放数据的是主分区和逻辑分区,大量数据都放在逻辑分区中如果你用的是GPT的分区方式,那么它没有限制主分区个数注意:从MBR转到GPT分区或者说从GPT转到MBR会导致数据全部丢失因此我们在对硬盘分区时最好划分主分区连续,比如说:主分区一、主分区二、扩展分区。 此文以fdisk工具为例,对一个硬盘划分。 Command Reference *partprobe #分区之后,让内核更新分区信息,否则系统需要restart后,内核才能识别新的分区 */proc/partitions 文件夹(目录)也可以用来查看分区信息 fdisk用法: fdisk [选项] 更改分区表 fdisk [选项] -l 列出分区表 fdisk -s 给出分区大小(块数) 选项: -b 扇区大小(512、1024、2048或4096) -c[=] 兼容模式:“dos”或“nondos”(默认) -h 打印此帮助文本 -u[=] 显示单位:“cylinders”(柱面)或“sectors”(扇区,默认) -v 打印程序版本 -C 指定柱面数 -H 指定磁头数 -S 指定每个磁道的扇区数 1、fdisk -l 查看系统上的硬盘,找到需要分区的硬盘后比如说:/dev/sda. 可以看出sda磁盘仍然有很多空间未启动;接下来进行磁盘分区,fdisk /dev/sda 进入该设备。此时出现: 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 注:l是列出分区类型,以供我们设置相应分区的类型; m print this menu 注:m 是列出帮助信息; n add a new partition 注:添加一个分区; o create a new empty DOS partition table p print the partition table 注:p列出分区表; q quit without saving changes 注:不保存退出; s create a new empty Sun disklabel t change a partition's system id 注:t 改变分区类型; u change display/entry units v verify the partition table w write table to disk and exit 注:把分区表写入硬盘并退出; x extra functionality (experts only) 注:扩展应用,专家功能; 具体每个参数的含义,请仔细阅读。常用的就是:d l m p q t w 2、列出当前操作硬盘的分区情况,用p Command (m for help): p Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x000ea964 Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux Command (m for help): n 注:添加分区 Partition type: p primary (1 primary, 0 extended, 3 free) 注:1个主分区,3个空闲分区总共四个主分区 e extended Select (default p): p 注:添加主分区,默认主分区; Partition number (2-4, default 2): 2 注:添加主分区2,因为有系统已有主分区1; irst sector (2099200-209715199, default 2099200): 注:直接回车,主分区2的结束位置;默认为2099200,默认就好; Using default value 2099200 Last sector, +sectors or +size{K,M,G} (2099200-209715199, default 209715199): +10G 注:指定分区大小,用+10G来指定大小为10G Command (m for help): n Partition type: p primary (2 primary, 0 extended, 2 free) 注:2个主分区,2个空闲分区总共四个主分区 e extended Select (default p): e 注:添加扩展分区; Partition number (3,4, default 3): 注:直接回车,因为主分区已经分了两个了,这个也算主分区,从3开始; First sector (23070720-209715199, default 23070720): 注:直接回车; Using default value 23070720 Last sector, +sectors or +size{K,M,G} (23070720-209715199, default 209715199): 注:直接回车,把其余的所有空间都给扩展分区; Using default value 209715199 Partition 3 of type Extended and of size 89 GiB is set Command (m for help): p 注:再次打印分区查看分区结果 Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x000ea964 Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 23070719 10485760 83 Linux /dev/sda3 23070720 209715199 93322240 5 Extended Command (m for help): n 注:在扩展分区添加逻辑分区 Partition type: p primary (2 primary, 1 extended, 1 free) 注:显示已有2个主分区1个扩展分区1个空闲分区; l logical (numbered from 5) 注:增加一个逻辑分区;编号从5开始 ;因为主分区有4个; Select (default p): l 注:添加逻辑分区; Adding logical partition 5 逻辑分区编号为自增,不能选择 First sector (23072768-209715199, default 23072768): Using default value 23072768 Last sector, +sectors or +size{K,M,G} (23072768-209715199, default 209715199): Using default value 209715199 Partition 5 of type Linux and of size 89 GiB is set Command (m for help): p 列出分区表; Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x000ea964 Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 23070719 10485760 83 Linux /dev/sda3 23070720 209715199 93322240 5 Extended /dev/sda5 23072768 209715199 93321216 83 Linux 然后我们根据前面所说通过t指令来改变分区类型; Command (m for help): t 注:通过t来指定分区类型; Partition number (1-3,5, default 5): 注:要改变哪个分区类型呢?默认为5,其实也就是sda5,直接回车 Hex code (type L to list all codes): L 注:在这里输入L,就可以查看分区类型的id了; 0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris 1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT- 2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT- 3 XENIX usr 3c PartitionMagic 84 OS/2 hidden C: c6 DRDOS/sec (FAT- 4 FAT16 |
CopyRight 2018-2019 实验室设备网 版权所有 |