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

本文发布时间: 2019-Mar-22
磁盘分区,格式化与检验磁盘分区:fdisk磁盘格式化:mkfs,mke2fs磁盘检测:fsck磁盘分区 语法:fdisk[-l] 设备名称-l:输出系统内所有分区 举例:[root@localhost ~]# fdisk -l Disk /dev/sda: 21.4 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = 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 Linux1. 查看磁盘文件名[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): mCommand 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 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = 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): dPartition number (1-6): 3 Command (m for help): p Disk /dev/sda: 21.4 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = 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 后可以看到磁盘信息不在包含sad3Command (m for help): dPartition number (1-6): 4 Command (m for help): p Disk /dev/sda: 21.4 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = 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 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = 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): nFirst 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): dPartition number (1-6): 4 Command (m for help): p Disk /dev/sda: 21.4 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = 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): nCommand 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 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = 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): dPartition number (1-6): 4 Command (m for help): nCommand action e extended p primary partition (1-4)eSelected partition 4First cylinder (1926-2610, default 1926):Using default value 1926Last 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 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = 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 Extendedsd4为新创建的扩展分区,大小为从柱面1926到2610Command (m for help): nFirstcylinder (1926-2610, default 1926):Usingdefault value 1926Lastcylinder or +size or +sizeM or +sizeK (1926-2610, default 2610): +500M对于此处可以指定柱面号码,以可以通过+XXM指定大小,让其自动分配柱面Command (m for help): p Disk /dev/sda: 21.4 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = 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 Linuxsd5为新创建的逻辑分区,大小为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/sda7mke2fs 1.39 (29-May-2006)Filesystemlabel=OS type: LinuxBlocksize=1024 (log=0)Fragment size=1024 (log=0)50200 inodes, 200780 blocks10039 blocks (5.00%) reserved for the superuserFirst data block=1Maximum filesystem blocks=6737100825 block groups8192 blocks per group, 8192 fragments pergroup2008 inodes per groupSuperblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729 Writing inode tables: done Creating journal (4096 blocks): doneWriting superblocks and filesystemaccounting information: done This filesystem will be automaticallychecked every 37 mounts or180 days, whichever comes first. Use tune2fs -c or -i to override.其中文件系统Label 以及iBLOCK大小均采用默认大小。如果对于EXT2/EXT3 我们对这些信息由特殊的需求,可以使用mke2fsmke2fs语法: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/sda7mke2fs 1.39 (29-May-2006)Filesystemlabel=TKFDISKOS type: LinuxBlocksize=2048 (log=1)Fragment size=2048 (log=1)50288 inodes, 100390 blocks5019 blocks (5.00%) reserved for the superuserFirst data block=0Maximum filesystem blocks=1038090247 block groups16384 blocks per group, 16384 fragments pergroup7184 inodes per groupSuperblock backups stored on blocks: 16384, 49152, 81920 Writing inode tables: done Creatingjournal (4096 blocks): doneWriting superblocks and filesystemaccounting information: done This filesystem will be automaticallychecked every 31 mounts or180 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/sda7fsck 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 informationTKFDISK: 11/50288 files (9.1%non-contiguous), 7673/100390 blocks 说明:需要磁盘检查的分区不能挂载在系统上,需要先被卸载才能磁盘检测


(以上内容不代表本站观点。)
---------------------------------
本网站以及域名有仲裁协议。
本網站以及域名有仲裁協議。

2024-Mar-04 02:10pm
栏目列表