对linux下 fdisk 中 primary , extented, logical 分区的理解

磨砺技术珠矶,践行数据之道,追求卓越价值

回到上一级页面: PostgreSQL杂记页     回到顶级页面:PostgreSQL索引页

首先,由于 历史上的原因,各个操作系统为共存的需要而约定俗成。一个物理磁盘最多有4个主分区。

http://www.express.nec.co.jp/linux/distributions/knowledge/system/fdisk.html

可以是这样:

比如第一块物理磁盘,它一般会有启动分区部分用来包含系统。其余的可以作其他用途。

它可能最多包含四个主分区:

     第一区:主分区(被设为活动者,启动时,此分区被引导)

     第二区:主分区

     第三区:主分区

     第四区:主分区

也可能是这样:

     第一区: 主分区

     第二区: 扩展分区

     而扩展分区 又分为  : 逻辑分区1 , 逻辑分区2,逻辑分区3 ,逻辑分区4....

第一块物理硬盘中,主分区是必须的,因为要引导系统嘛,这是没有办法的事。

对第二块物理硬盘, 可以有几种方法去使用:

     1  主分区 + 扩展分区(里面分成逻辑分区1,逻辑分区2...),
         此方式下,此处主分区似乎有点不伦不类。当然也是可以当作数据区使用。

     2  仅有一个 主分区,拿来直接当数据区用也是可以的。

     3  完全是扩展分区。(里面分成逻辑分区1,逻辑分区2...)

  要注意: 仅有扩展分区,不进一步划分逻辑分区,是不能拿来做文件系统的。

下面就以第三种情况来试验一下:

 

[root@localhost ~]# fdisk -l

Disk /dev/sda: 12.8 GB, 12884901888 bytes
255 heads, 63 sectors/track, 1566 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1566 12474472+ 8e Linux LVM

Disk /dev/sdb: 12.8 GB, 12884901888 bytes
255 heads, 63 sectors/track, 1566 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdb doesn't contain a valid partition table

 

在第二块物理硬盘上建立扩展分区:

[root@localhost ~]# fdisk /dev/sdb

The number of cylinders for this disk is set to 1566.
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)

Command (m for help): n
Command action
e extended
p primary partition (1-4)
e
Partition number (1-4): 1
First cylinder (1-1566, default 1): 
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1566, default 1566): 
Using default value 1566

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# fdisk -l

Disk /dev/sda: 12.8 GB, 12884901888 bytes
255 heads, 63 sectors/track, 1566 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1566 12474472+ 8e Linux LVM

Disk /dev/sdb: 12.8 GB, 12884901888 bytes
255 heads, 63 sectors/track, 1566 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 1566 12578863+ 5 Extended

此时如果直接建文件系统会失败:

[root@localhost ~]# mkfs /dev/sdb1
mke2fs 1.39 (29-May-2006)
/dev/sdb1: Invalid argument passed to ext2 library while setting up superblock
[root@localhost ~]#

[root@localhost ~]# mkfs /dev/sdb
mke2fs 1.39 (29-May-2006)
/dev/sdb is entire device, not just one partition!
Proceed anyway? (y,n) n

[root@localhost ~]#

对/dev/sdb 继续运用 fdisk, 此时会出现 l 与 p 选项,不要理会p, 用l (logical)

[root@localhost ~]# fdisk /dev/sdb1

Unable to read /dev/sdb1
[root@localhost ~]# fdisk /dev/sdb

The number of cylinders for this disk is set to 1566.
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)

Command (m for help): p

Disk /dev/sdb: 12.8 GB, 12884901888 bytes
255 heads, 63 sectors/track, 1566 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 1566 12578863+ 5 Extended

Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (1-1566, default 1): 1
Last cylinder or +size or +sizeM or +sizeK (1-1566, default 1566): +8G

上面选 +8G 做一个8G的逻辑分区后,再做一个:

Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (975-1566, default 975): 
Using default value 975
Last cylinder or +size or +sizeM or +sizeK (975-1566, default 1566): 
Using default value 1566

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# 
[root@localhost ~]# fdisk -l

Disk /dev/sda: 12.8 GB, 12884901888 bytes
255 heads, 63 sectors/track, 1566 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1566 12474472+ 8e Linux LVM

Disk /dev/sdb: 12.8 GB, 12884901888 bytes
255 heads, 63 sectors/track, 1566 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 1566 12578863+ 5 Extended
/dev/sdb5 1 974 7823592 83 Linux
/dev/sdb6 975 1566 4755208+ 83 Linux

此时可以作文件系统了,注意由于是逻辑分区,所以从第5开始计数:/dev/sdb5  /dev/sdb6

[root@localhost ~]# mkfs /dev/sdb5
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
979200 inodes, 1955898 blocks
97794 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2004877312
60 block groups
32768 blocks per group, 32768 fragments per group
16320 inodes per group
Superblock backups stored on blocks: 
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Writing inode tables: done 
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 28 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost ~]# mkfs /dev/sdb6
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
595552 inodes, 1188802 blocks
59440 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1220542464
37 block groups
32768 blocks per group, 32768 fragments per group
16096 inodes per group
Superblock backups stored on blocks: 
32768, 98304, 163840, 229376, 294912, 819200, 884736

Writing inode tables: done 
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 37 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost ~]# cd /
[root@localhost /]# ls
bin etc lib64 misc opt sbin sys tmp
boot home lost+found mnt proc selinux test usr
dev lib media net root srv tftpboot var
[root@localhost /]# mkdir /test01
[root@localhost /]# mkdir /test02
[root@localhost /]# mount /dev/sdb5 /test01
[root@localhost /]# mount /dev/sdb6 /test02
[root@localhost /]# cd /test01
[root@localhost test01]# ls
lost+found
[root@localhost test01]# cd /test02
[root@localhost test02]# 

 

回到上一级页面: PostgreSQL杂记页     回到顶级页面:PostgreSQL索引页

磨砺技术珠矶,践行数据之道,追求卓越价值

 

posted @ 2012-10-19 14:02  健哥的数据花园  阅读(15385)  评论(0编辑  收藏  举报