分类: LINUX
2013-10-25 09:35:25
1,you can use "fdisk -l" to see how much block there have.
Disk /dev/sde: 1973 MB, 1973420032 bytes
255 heads, 63 sectors/track, 239 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/sde1 1 132 1060258+ c W95 FAT32 (LBA)
/dev/sde2 133 239 859477+ 83 Linux
2,now you can use "fdisk /dev/sde"to fdisk the device.
3,next you can press "p" to see ,how block is there,and use "d" to delete the block.and use "n"to create block. and use "t" to chance the filesystem type.
4,use "partprobe" to make the partion into effect.
5,and now you can mkfs....... the filesystem.
以下转载:
理论知识:一块磁盘最多有4个分区,包括(主分区+扩展分区),扩展分区不能直接使用,需进行分区为逻辑分区,其数字从5开始。
首先在未开机前添加一块磁盘,然后开机。
[root@wangbin ~]# fdisk –l // 查看磁盘分区情况
Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 25 200781 83 Linux //系统引导分区
/dev/sda2 26 286 2096482+ 82 Linux swap / Solaris //交换分区
/dev/sda3 287 5221 39640387+ 83 Linux
Disk /dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 1217 9775521 83 Linux
/dev/sdb2 1218 2434 9775552+ 83 Linux
Disk /dev/sdc: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdc doesn't contain a valid partition table // /dev/sdc磁盘没有有效的分区表,说明没有进行分区。
[root@wangbin ~]# fdisk /dev/sdc //对 /dev/sdc进行分区
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.
The number of cylinders for this disk is set to 2610.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): m //输入m得到帮助信息
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition // 删除分区
l list known partition types
m print this menu
n add a new partition //增加分区
o create a new empty DOS partition table
p print the partition table //打印分区
q quit without saving changes //不保存退出
s create a new empty Sun disklabel
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 (experts only)
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-2610, default 2610): +500M
Command (m for help): p
Disk /dev/sdc: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdc1 1 62 497983+ 83 Linux
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (63-2610, default 63):
Using default value 63
Last cylinder or +size or +sizeM or +sizeK (63-2610, default 2610): +500M
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (125-2610, default 125):
Using default value 125
Last cylinder or +size or +sizeM or +sizeK (125-2610, default 2610): +500M
Command (m for help): n
Command action
e extended
p primary partition (1-4)
e
Selected partition 4
First cylinder (187-2610, default 187):
Using default value 187
Last cylinder or +size or +sizeM or +sizeK (187-2610, default 2610):
Using default value 2610
Command (m for help): p
Disk /dev/sdc: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdc1 1 62 497983+ 83 Linux
/dev/sdc2 63 124 498015 83 Linux
/dev/sdc3 125 186 498015 83 Linux
/dev/sdc4 187 2610 19470780 5 Extended //扩展分区
Command (m for help): n
First cylinder (187-2610, default 187):
Using default value 187
Last cylinder or +size or +sizeM or +sizeK (187-2610, default 2610): +500M
Command (m for help): n
First cylinder (249-2610, default 249):
Using default value 249
Last cylinder or +size or +sizeM or +sizeK (249-2610, default 2610): +500M
Command (m for help): n
First cylinder (311-2610, default 311):
Using default value 311
Last cylinder or +size or +sizeM or +sizeK (311-2610, default 2610): +500M
Command (m for help): p
Disk /dev/sdc: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdc1 1 62 497983+ 83 Linux
/dev/sdc2 63 124 498015 83 Linux
/dev/sdc3 125 186 498015 83 Linux
/dev/sdc4 187 2610 19470780 5 Extended
/dev/sdc5 187 248 497983+ 83 Linux
/dev/sdc6 249 310 497983+ 83 Linux
/dev/sdc7 311 372 497983+ 83 Linux
Command (m for help): d
Partition number (1-7): 7
Command (m for help): p
Disk /dev/sdc: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdc1 1 62 497983+ 83 Linux
/dev/sdc2 63 124 498015 83 Linux
/dev/sdc3 125 186 498015 83 Linux
/dev/sdc4 187 2610 19470780 5 Extended
/dev/sdc5 187 248 497983+ 83 Linux
/dev/sdc6 249 310 497983+ 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@wangbin ~]# partprobe //使分区生效
Warning: Unable to open /dev/hdc read-write (Read-only file system). /dev/hdc has been opened read-only.
[root@wangbin ~]# fdisk -l /dev/sdc //查看/dev/sdc的分区
Disk /dev/sdc: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdc1 1 62 497983+ 83 Linux
/dev/sdc2 63 124 498015 83 Linux
/dev/sdc3 125 186 498015 83 Linux
/dev/sdc4 187 2610 19470780 5 Extended
/dev/sdc5 187 248 497983+ 83 Linux
/dev/sdc6 249 310 497983+ 83 Linux
[root@wangbin ~]# mkfs.ext3 /dev/sdc1 对/dev/sdc1进行格式化
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
124928 inodes, 497980 blocks
24899 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67633152
61 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 38 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@wangbin ~]# mkfs.ext3 /dev/sdc2 //对/dev/sdc2进行格式化
[root@wangbin ~]# mkfs.ext3 /dev/sdc3 //对/dev/sdc3进行格式化
[root@wangbin ~]# mkfs.ext3 /dev/sdc5 //对/dev/sdc5进行格式化
[root@wangbin ~]# mkfs.ext3 /dev/sdc6 //对/dev/sdc6进行格式化
[root@wangbin ~]# mkdir -p /sdc/sdc1 //创建/sdc/sdc1目录
[root@wangbin ~]# mkdir -p /sdc/sdc2
[root@wangbin ~]# mkdir -p /sdc/sdc3
[root@wangbin ~]# mkdir -p /sdc/sdc5
[root@wangbin ~]# mkdir -p /sdc/sdc6
[root@wangbin ~]# mount /dev/sdc1 /sdc/sdc1 //将/sdc/sdc1挂载到/dev/sdc1
[root@wangbin ~]# mount /dev/sdc2 /sdc/sdc2
[root@wangbin ~]# mount /dev/sdc3 /sdc/sdc3
[root@wangbin ~]# mount /dev/sdc5 /sdc/sdc5
[root@wangbin ~]# mount /dev/sdc6 /sdc/sdc6
[root@wangbin ~]# vi /etc/fstab //修改配置文件,使磁盘自动挂载
/dev/sdc1 /sdc/sdc1 ext3 defaults 0 0
/dev/sdc2 /sdc/sdc2 ext3 defaults 0 0
/dev/sdc3 /sdc/sdc3 ext3 defaults 0 0
/dev/sdc5 /sdc/sdc5 ext3 defaults 0 0
/dev/sdc6 /sdc/sdc6 ext3 defaults 0 0
[root@wangbin ~]# reboot
Broadcast message from root (pts/1) (Tue Feb 3 22:56:12 2009):
The system is going down for reboot NOW!
[root@wangbin ~]# df –hT //查看磁盘的挂载情况
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda3 ext3 37G 4.7G 31G 14% /
/dev/sda1 ext3 190M 12M 170M 7% /boot
tmpfs tmpfs 506M 0 506M 0% /dev/shm
/dev/sdc1 ext3 471M 11M 437M 3% /sdc/sdc1
/dev/sdc2 ext3 471M 11M 437M 3% /sdc/sdc2
/dev/sdc3 ext3 471M 11M 437M 3% /sdc/sdc3
/dev/sdc5 ext3 471M 11M 437M 3% /sdc/sdc5
/dev/sdc6 ext3
471M 11M 437M
3% /sdc/sdc6
添加便签:mkfs.msdos -F 32 /dev/sdc1 -n LABEL1 或:mkfs.ext3 -L LABEL2 /dev/sdc2