linux格式化时设备或资源忙,Linux下使用fdisk命令和partprobe命令,在不重启系统的状况下新建分区并格式化...

因为工做的须要,最近一段时间一直在学习Linux。学习一门新的知识,我是喜欢根据谋一本书或者某一个学习视频系统的学习,这样能够对学习的新知识有一个系统全面的认识和了解。因此学习以前,没了一本鸟哥的私房菜作为参考书,开始系统的学习Linux。node

根据鸟哥的建议,安装虚拟机时,预留了一块空的容量用来练习分区使用。因此在虚拟机上安装Linux系统分区时,只划分了一块4G的容量挂载到根目录“/”下,还有就是只划分了一个2G的swap分区。还有14G的容量没有分配。app

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

具体操做以下所示:学习

一、使用fdisk新建分区ui

(。。。。)分区操做记录没有保存下来,执行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.orm

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

二、经过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 出现递归分区。ip

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

三、使用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进行格式化。

四、格式化新建的逻辑分区/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.

这回无论是新建分区,仍是重载分区表都没有警告或错误提示了。成功实如今不重启系统的状况下添加硬盘并对新增硬盘进行分区、格式化等操做。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值