条件:
我的硬盘是两个。其中一个500G仍然有相当一部分没有分区
一. 可先用fdisk -l来查看硬盘的情况:
[root@chen Desktop]# fdisk -l
Disk /dev/sda: 320.1 GB, 320072933376 bytes #这个硬为320G安装有windows 7的系统
255 heads, 63 sectors/track, 38913 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
Device Boot Start End Blocks Id System
/dev/sda1 * 1 3927 31542272 7 HPFS/NTFS #主分区,也是windows系统的系统分区。
/dev/sda2 3928 38913 281025045 f W95 Ext'd (LBA) #这个分区是一个光驱
/dev/sda5 3928 11831 63488848+ 7 HPFS/NTFS
/dev/sda6 11832 19735 63488848+ 7 HPFS/NTFS
/dev/sda7 19736 29297 76806733+ 7 HPFS/NTFS
/dev/sda8 29298 38913 77240488+ 7 HPFS/NTFS
Disk /dev/sdc: 500.1 GB, 500107862016 bytes #这个盘有500G,就是安装redhat enterprise 6.2的系统。
255 heads, 63 sectors/track, 60801 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
Device Boot Start End Blocks Id System
/dev/sdc1 21673 60802 314305536 5 Extended #扩展分区,sdc5,sdc7,sdc6都是它的逻辑分区。
Partition 1 does not end on cylinder boundary.
/dev/sdc2 * 1 26 204800 83 Linux
Partition 2 does not end on cylinder boundary.
/dev/sdc3 26 11500 92160000 83 Linux
/dev/sdc4 11500 19148 61440000 83 Linux
/dev/sdc5 25497 29322 30720000 b W95 FAT32 #硬盘安装Linux时所用的fat32分区,ISO就在里面。
/dev/sdc6 21673 22195 4194304 82 Linux swap / Solaris #交换分区(swap)
/dev/sdc7 22195 24153 15731565 83 Linux
Partition table entries are not in disk order
二. 可以看出我的500G的硬盘分为四个主分区sdc1,sdc2,sdc3,sdc4。其中sdc1为扩展分区,sdc5,sdc6和sdc7就是从 sdc1中取的空间的(就是sdc1包函了三个分区sdc5,sdc6和sdc7)。而其它的分区分别是“/”,“/home"等。
从fdisk -l可查看出sdc硬盘还有很大空间,因为扩展分区adc1的的柱面是从21673到60802。而sdc5,sdc6,sdc7才用了21673到29322。
1,可以用fdisk /dev/sdc到硬盘中进行操作:
Command (m for help):
2,可以输入P查看sdc的分区。
Command (m for help):P
Disk /dev/sdc: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 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
Device Boot Start End Blocks Id System
/dev/sdc1 21673 60802 314305536 5 Extended
Partition 1 does not end on cylinder boundary.
/dev/sdc2 * 1 26 204800 83 Linux
Partition 2 does not end on cylinder boundary.
/dev/sdc3 26 11500 92160000 83 Linux
/dev/sdc4 11500 19148 61440000 83 Linux
/dev/sdc5 25497 29322 30720000 b W95 FAT32
/dev/sdc6 21673 22195 4194304 82 Linux swap / Solaris
/dev/sdc7 22195 24153 15731565 83 Linux
3,删除一个分区
Command (m for help): d
Partition number (1-7): 7 #删除分区7
!!!注意:删除分区时要小心,如果您删除了扩展分区,扩展分区之下的逻辑分区都会删除;如果知道自己操作错了,请不要惊慌,用q不保存退出
4,重新创建分区7;
Command (m for help): n
First cylinder (22195-60802, default 22195):
Using default value 22195 #直接回车不选首柱,则默认承接上一个分区的最后一柱。
Last cylinder, +cylinders or +size{K,M,G} (22195-25496, default 25496): 25497 #最后一柱的大小
Value out of range. #超出值了,与别的分区撞上了。
Last cylinder, +cylinders or +size{K,M,G} (22195-25496, default 25496): 25496
5,分完区注意保存:
Command (m for help): w
The partition table has been altered!
!!!注意:保存之前,保证没有出错。
6,查看分区情况并退出:
Command (m for help): p
Disk /dev/sdc: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 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
Device Boot Start End Blocks Id System
/dev/sdc1 21673 60802 314305536 5 Extended
Partition 1 does not end on cylinder boundary.
/dev/sdc2 * 1 26 204800 83 Linux
Partition 2 does not end on cylinder boundary.
/dev/sdc3 26 11500 92160000 83 Linux
/dev/sdc4 11500 19148 61440000 83 Linux
/dev/sdc5 25497 29322 30720000 b W95 FAT32
/dev/sdc6 21673 22195 4194304 82 Linux swap / Solaris
/dev/sdc7 22195 25496 26519212+ 83 Linux
Partition table entries are not in disk order
Command (m for help): q #退出
三, 对新分的区进行格式化:
1.(有时可能出现以下情况)
[root@chen Desktop]# mkfs.ext4 /dev/sdc7
mke2fs 1.39 (29-May-2006)
Could not stat /dev/sdc7--- No such file or directory
The device apparently does not exist; did you specify it correctly?
(以下方法参照别人的文档,经本人验证,可行)
(1)执行下partprobe命令
partprobe包含在parted的rpm软件包中。partprobe可以修改kernel中分区表,使kernel重新读取分区表。因此,使用该命令就可以创建分区并且在不重新启动机器的情况下系统能够识别这些分区。
(2) 查看包是否已安装:
[root@chen Desktop]# rpm -qa parted
parted-2.1-17.el6.x86_64
(有时做完这些步骤时仍不能格式化,提示重启,则重启)
2.执行格式化命令:
[root@chen Desktop]# mkfs.ext4 /dev/sdc7
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
983488 inodes, 3932891 blocks
196644 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4030726144
121 block groups
32768 blocks per group, 32768 fragments per group
8128 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 31 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
完工。