千家信息网

Linux下新建分区并格式化的方法

发表于:2025-02-21 作者:千家信息网编辑
千家信息网最后更新 2025年02月21日,这篇文章主要讲解了"Linux下新建分区并格式化的方法",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"Linux下新建分区并格式化的方法"吧!在学习磁盘
千家信息网最后更新 2025年02月21日Linux下新建分区并格式化的方法

这篇文章主要讲解了"Linux下新建分区并格式化的方法",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"Linux下新建分区并格式化的方法"吧!

在学习磁盘管理时,使用fdisk将剩余的容量继续分区。却发现新建完分区后,无法通过partprobe重载分区。

具体操作如下所示:

1、使用fdisk新建分区

(。。。。)分区操作记录没有保存下来,执行w后,出现下列信息

Disk /dev/sda: 21.5 GB, 21474836480 bytes  255 heads, 63 sectors/track, 2610 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: 0x000b604c Device Boot Start End Blocks Id System  /dev/sda1 * 1 523 4194304 83 Linux  Partition 1 does not end on cylinder boundary.  /dev/sda2 523 784 2097152 82 Linux swap / Solaris  Partition 2 does not end on cylinder boundary.  /dev/sda3 784 2610 14672345 5 Extended  /dev/sda5 784 1421 5121671 83 LinuxCommand (m for help): w  The partition table has been altered!Calling ioctl() to re-read partition table.WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.  The kernel still uses the old table. The new table will be used at  the next reboot or after you run partprobe(8) or kpartx(8)  Syncing disks.

保存新建分区,提示"设备或资源忙",当时就在/dev/sda硬盘上做的操作,以为该提示为正常现象,所以忽略了,继续下一步操作。

2、通过partprobe重载分区表,避免重启系统

[root@stduy /]# partprobe   Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (设备或资源忙). As a result, it may not reflect all of your changes until after reboot.  Warning: 无法以读写方式打开 /dev/sr0 (只读文件系统)。/dev/sr0 已按照只读方式打开。  Warning: 无法以读写方式打开 /dev/sr0 (只读文件系统)。/dev/sr0 已按照只读方式打开。  Error: 无效的分区表 - /dev/sr0 出现递归分区。

重载分区出现的上述信息中,当时对于警告提示"设备或资源忙,需要重启系统才能使更改生效"直接忽略,以为是正常现象。但是对于错误信息"Error: 无效的分区表 - /dev/sr0 出现递归分区。"就有点茫然了,不过,既然提示"无效的分区表",那我查下分区信息。

3、使用fdisk -l 命令查看分区信息

[root@stduy /]# fdisk -l  Disk /dev/sda: 21.5 GB, 21474836480 bytes  255 heads, 63 sectors/track, 2610 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: 0x000b604c Device Boot Start End Blocks Id System  /dev/sda1 * 1 523 4194304 83 Linux  Partition 1 does not end on cylinder boundary.  /dev/sda2 523 784 2097152 82 Linux swap / Solaris  Partition 2 does not end on cylinder boundary.  /dev/sda3 784 2610 14672345 5 Extended  /dev/sda5 784 1421 5121671 83 Linux

查看分区信息,正常啊,并且刚才新建的扩展分区/dev/sda3和逻辑分区/dev/sda5都在。于是直接对新建的分区/dev/sda5进行格式化。

4、格式化新建的逻辑分区/dev/sda5

[root@stduy /]# mkfs -t ext3 /dev/sda5  mke2fs 1.41.12 (17-May-2010)

无法对 /dev/sda5 进行 stat 调用 --- 没有那个文件或目录
The device apparently does not exist; did you specify it correctly?

格式化时,提示"没有那个文件或目录"。这就奇怪了,操作是根据参考书上一步一步来的,怎么就不行了呢?于是百度Linux下新建分区的一些信息,希望可以的找到类似的错误,借鉴解决办法。找了一圈下来,倒是有个类似的错误,但是没有给出解决办法。

重新分析新建分区并重载分区表的过程,对于"设备或资源忙"的提示,因为当时就是在/dev/sda这块硬盘上操作的,提示"设备或资源忙"应该是正常的,重启下应该就可以了。但是重启后,还是找不到/dev/sda5,但是fdisk -l 查看是有的。于是怀疑是不是重载分区表时的"Error: 无效的分区表 - /dev/sr0 出现递归分区。"错误信息导致的呢?

查看了下/dev下的sr0

[root@stduy dev]# ls -lh | grep sr0  lrwxrwxrwx. 1 root root 3 8月 5 00:12 cdrom -> sr0  lrwxrwxrwx. 1 root root 3 8月 5 00:12 cdrw -> sr0  lrwxrwxrwx. 1 root root 3 8月 5 00:12 dvd -> sr0  lrwxrwxrwx. 1 root root 3 8月 5 00:12 dvdrw -> sr0  lrwxrwxrwx. 1 root root 3 8月 5 00:12 scd0 -> sr0  brw-rw----. 1 root cdrom 11, 0 8月 5 00:12 sr0

从上面的结果看,sr0是光驱设备,百度了下/dev/sr0这个设备,也所是光驱。于是管它重载分区表失败是不是由于"Error: 无效的分区表 - /dev/sr0 出现递归分区。"引起的,先把光驱移除了再说,反正是虚拟机上。

把虚拟机上的光驱设备移除后,重新启动系统,再重新新建分区,并重新执行partprobe命令重载分区表,错误信息"Error: 无效的分区表 - /dev/sr0 出现递归分区。"没有了,只是警告提示"设备或资源忙"还在。这时直接格式化新建的逻辑分区/dev/sda5还是提示"没有那个文件或目录"。于是重启系统,再格式化/dev/sda5,这回成功了。

也就是,之前新建分区格式化失败,是由于虚拟机的光驱/dev/sr0设备导致了分区表递归。另外由于是在同一块硬盘上操作,所以必须要重启系统才能使新建的分区写入分区表生效。

那鸟哥的私房菜中,说的预留一块容量用于分区练习,鸟哥是怎么成功的呢?

于是又找了一些Linux磁盘管理相关的视频和资料,发现,他们使用fdisk新建分区都是使用的多块硬盘实现的。再重新回去看鸟哥的私房菜,发现鸟哥预留的硬盘是/dev/hdc,那么鸟哥的环境中肯定还有/dev/hda和/dev/hdb,那么鸟哥试验也是在多快硬盘的基础上完成的。

那我再给虚拟机分配一块硬盘试试。于是关闭系统,在虚拟机上又给系统分配了一块5G的虚拟磁盘空间。再开机进入系统重新对新加的磁盘空间进行分区、格式化等操作。

步骤还是和上面一样,分区、重载分区表、查看分区、格式化,这里不再按步骤,直接给出完成的操作记录。

[root@stduy ~]# fdisk -l   Disk /dev/sda: 21.5 GB, 21474836480 bytes  255 heads, 63 sectors/track, 2610 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: 0x000b604c   Device Boot Start End Blocks Id System  /dev/sda1 * 1 523 4194304 83 Linux  Partition 1 does not end on cylinder boundary.  /dev/sda2 523 784 2097152 82 Linux swap / Solaris  Partition 2 does not end on cylinder boundary.  /dev/sda3 784 2610 14672345 5 Extended  /dev/sda5 784 2610 14672313+ 83 Linux   Disk /dev/sdb: 5368 MB, 5368709120 bytes  255 heads, 63 sectors/track, 652 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: 0x00000000   [root@stduy ~]# fdisk /dev/sdb  Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel  Building a new DOS disklabel with disk identifier 0x851e79cc.  Changes will remain in memory only, until you decide to write them.  After that, of course, the previous content won't be recoverable.   Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)   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): p   Disk /dev/sdb: 5368 MB, 5368709120 bytes  255 heads, 63 sectors/track, 652 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: 0x851e79cc   Device Boot Start End Blocks Id System   Command (m for help): n  Command action  e extended  p primary partition (1-4)  p  Partition number (1-4): 1  First cylinder (1-652, default 1):   Using default value 1  Last cylinder, +cylinders or +size{K,M,G} (1-652, default 652):   Using default value 652   Command (m for help): p   Disk /dev/sdb: 5368 MB, 5368709120 bytes  255 heads, 63 sectors/track, 652 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: 0x851e79cc   Device Boot Start End Blocks Id System  /dev/sdb1 1 652 5237158+ 83 Linux   Command (m for help): w  The partition table has been altered!   Calling ioctl() to re-read partition table.  Syncing disks.  [root@stduy ~]# partprobe /dev/sdb  [root@stduy ~]# mkfs -t ext4 /dev/sdb1  mke2fs 1.41.12 (17-May-2010)

文件系统标签=操作系统:Linux块大小=4096 (log=2)分块大小=4096 (log=2)Stride=0 blocks, Stripe width=0 blocks327680 inodes, 1309289 blocks65464 blocks (5.00%) reserved for the super user
***个数据块=0Maximum filesystem blocks=134217728040 block groups32768 blocks per group, 32768 fragments per group8192 inodes per groupSuperblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736
正在写入inode表: 完成

Creating journal (32768 blocks): 完成  Writing superblocks and filesystem accounting information: 完成  This filesystem will be automatically checked every 36 mounts or180 days, whichever comes first.   Use tune2fs -c or -i to override.

这回不管是新建分区,还是重载分区表都没有警告或错误提示了。成功实现在不重启系统的情况下添加硬盘并对新增硬盘进行分区、格式化等操作。

感谢各位的阅读,以上就是"Linux下新建分区并格式化的方法"的内容了,经过本文的学习后,相信大家对Linux下新建分区并格式化的方法这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是,小编将为大家推送更多相关知识点的文章,欢迎关注!

分区表 格式 系统 设备 提示 信息 硬盘 资源 文件 错误 递归 光驱 方法 方式 磁盘 还是 学习 成功 目录 逻辑 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 互联网 大唐科技有限公司 aws服务器 aws 公钥 梅州产品追溯软件开发 网络安全和前端开发哪个难学一些 数据库如何将数据保留小数 数据库43831转换日期 我的世界斗罗服务器手机版下载 网吧电脑无盘服务器 软件开发上线周期的描述 网络技术专业求职信 江苏上门软件开发费用是多少 GEO数据库芯片平台怎么下载 云顶提示无法连接服务器 普陀区全过程网络技术服务哪家好 软件开发费多少算高 达梦新建数据库实例 阿里云的服务器安全设置 文山计算机网络安全技术 网络管理服务器怎么连接 vue服务器怎么传到git 网络安全教育的动画 政府网络安全培训 心得体会 易语言写服务器 制作网络安全口号和标语 上海市国家网络安全宣传 我的世界整蛊服务器的新手玩家 清除服务器经验球指令 成都农商行网络安全态势 网络安全年会副主任致辞 服务器系统如何关闭ftp
0