[root@CentOS ~]# ls /dev/sdb* 查看第2块磁盘的设备文件
/dev/sdb /dev/sdb1 /dev/sdb2 /dev/sdb4 /dev/sdb5
[root@CentOS ~]# fdisk -l /dev/sdb 查看当前第2块磁盘的信息
Disk /dev/sdb: 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: 0xc70316d2
Device Boot Start End Blocks Id System
/dev/sdb1 1 654 5253223+ 83 Linux
/dev/sdb2 655 1960 10490445 5 Extended
/dev/sdb4 1961 2353 3156772+ 83 Linux
/dev/sdb5 655 1047 3156741 83 Linux
[root@CentOS ~]# df -Th 查看磁盘的挂载情况
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg_centos2-lv_root ext4 18G 4.6G 12G 28% /
tmpfs tmpfs 116M 0 116M 0% /dev/shm
/dev/sda1 ext4 485M 35M 426M 8% /boot
/dev/sdb1 ext4 5.0G 139M 4.6G 3% /lu
[root@CentOS ~]# fdisk /dev/sdb 对sdb进行分区
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): n
Command action
l logical (5 or over)
p primary partition (1-4)
p
Selected partition 3
First cylinder (2354-2610, default 2354):
Using default value 2354
Last cylinder, +cylinders or +size{K,M,G} (2354-2610, default 2610):
Using default value 2610
Command (m for help): p
Disk /dev/sdb: 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: 0xc70316d2
Device Boot Start End Blocks Id System
/dev/sdb1 1 654 5253223+ 83 Linux
/dev/sdb2 655 1960 10490445 5 Extended
/dev/sdb3 2354 2610 2064352+ 83 Linux 新增加的主分区
/dev/sdb4 1961 2353 3156772+ 83 Linux
/dev/sdb5 655 1047 3156741 83 Linux
Partition table entries are not in disk order
Command (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/sdb1已被挂载,无法修改分区
[root@CentOS ~]# mkfs.ext4 /dev/sdb3
mke2fs 1.41.12 (17-May-2010)
无法对 /dev/sdb3 进行 stat 调用 --- 没有那个文件或目录
The device apparently does not exist; did you specify it correctly?
[root@CentOS ~]# ls /dev/sdb* 此时尚未有对应的设备文件
/dev/sdb /dev/sdb1 /dev/sdb2 /dev/sdb4 /dev/sdb5
[root@CentOS ~]# umount /lu
卸载/dev/sdb1后,使用partprobe 命令将分区方案写入内核中,如果没有卸载,将不能执行partprobe这个命令
[root@CentOS ~]# partprobe /dev/sdb
[root@CentOS ~]# ls /dev/sdb* partprobe命令执行后,生成设备文件
/dev/sdb /dev/sdb1 /dev/sdb2 /dev/sdb3 /dev/sdb4 /dev/sdb5
[root@CentOS ~]# mount /dev/sdb3 /lu 不能挂载,是因为没有对该分区格式化
mount: you must specify the filesystem type
[root@CentOS ~]# mkfs.ext4 /dev/sdb3 格式化分区
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
129024 inodes, 516088 blocks
25804 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=528482304
16 block groups
32768 blocks per group, 32768 fragments per group
8064 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
正在写入inode表: 完成
Creating journal (8192 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 27 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@CentOS ~]# mount /dev/sdb3 /lu 再次挂载,则没有问题
[root@CentOS ~]#
如果现在删除先前新建的主分区/dev/sdb3,但是删除之前它还处于挂载状态。
新建一个逻辑分区/dev/sdb6,
[root@CentOS ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 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: 0xc70316d2
Device Boot Start End Blocks Id System
/dev/sdb1 1 654 5253223+ 83 Linux
/dev/sdb2 655 1960 10490445 5 Extended
/dev/sdb4 1961 2353 3156772+ 83 Linux
/dev/sdb5 655 1047 3156741 83 Linux
/dev/sdb6 1048 1440 3156741 83 Linux 逻辑分区
[root@CentOS ~]# ls /dev/sdb*
/dev/sdb /dev/sdb1 /dev/sdb2 /dev/sdb3 /dev/sdb4 /dev/sdb5
[root@CentOS ~]# mkfs.ext4 /dev/sdb6
mke2fs 1.41.12 (17-May-2010)
无法对 /dev/sdb6 进行 stat 调用 --- 没有那个文件或目录
The device apparently does not exist; did you specify it correctly?
[root@CentOS ~]# partprobe /dev/sdb
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdb (设备或资源忙). As a result, it may not reflect all of your changes until after reboot.
由于sdb已挂载,所以不成功
[root@CentOS ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg_centos2-lv_root ext4 18G 4.6G 12G 28% /
tmpfs tmpfs 116M 0 116M 0% /dev/shm
/dev/sda1 ext4 485M 35M 426M 8% /boot
/dev/sdd1 ext4 9.9G 151M 9.3G 2% /mail
/dev/sdd2 ext4 20G 172M 19G 1% /software
/dev/sdd5 ext4 5.0G 139M 4.6G 3% /movie
/dev/sdd6 ext4 14G 164M 13G 2% /photo
/dev/sdb3 ext4 2.0G 35M 1.9G 2% /lu 此时/dev/sdb3分区已经删除
[root@CentOS ~]# umount /lu
[root@CentOS ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg_centos2-lv_root ext4 18G 4.6G 12G 28% /
tmpfs tmpfs 116M 0 116M 0% /dev/shm
/dev/sda1 ext4 485M 35M 426M 8% /boot
/dev/sdd1 ext4 9.9G 151M 9.3G 2% /mail
/dev/sdd2 ext4 20G 172M 19G 1% /software
/dev/sdd5 ext4 5.0G 139M 4.6G 3% /movie
/dev/sdd6 ext4 14G 164M 13G 2% /photo
[root@CentOS ~]# partprobe /dev/sdb
卸载对应的磁盘分区后,则没有问题
[root@CentOS ~]#
总结:
在linux分区常见问题:
1.不能挂载磁盘一般是因为没有格式化
[root@CentOS ~]# mount /dev/sdb3 /lu
mount: you must specify the filesystem type
1.不能格式化是因为设备文件没有生成
[root@CentOS ~]# mkfs.ext4 /dev/sdb3
mke2fs 1.41.12 (17-May-2010)
无法对 /dev/sdb3 进行 stat 调用 --- 没有那个文件或目录
The device apparently does not exist; did you specify it correctly?
[root@CentOS ~]# ls /dev/sdb* 此时尚未有对应的设备文件
/dev/sdb /dev/sdb1 /dev/sdb2 /dev/sdb4 /dev/sdb5
2.扩展分区,有设备文件
[root@CentOS ~]# mkfs.ext4 /dev/sdb2
mke2fs 1.41.12 (17-May-2010)
mkfs.ext4: inode_size (128) * inodes_count (0) too big for a
filesystem with 0 blocks, specify higher inode_ratio (-i)
or lower inode count (-N).
3.假如这个磁盘在使用,新建分区后不会生成设备文件
要想生成设备文件就执行partprobe /dev/sd* 这条命令
partprobe /dev/sd*这个命令不能执行是因为对应的磁盘其他分区已挂载
将那个磁盘的分区卸载,即可执行
4.假如这个分区已挂载,然后删除这个分区,也会影响到partprobe /dev/sd* 命令的执行(对应磁盘分区写入内核中),df -Th 还是可以看到该分区挂载
本文出自 “爱迷彩的linux一员” 博客,请务必保留此出处http://menglinux.blog.51cto.com/8733806/1398700