沧海笑的艺术人生

沧海一声笑, 滔滔两岸潮,浮沉随浪只记今朝
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

linux下使用fdisk分区 (转载小惠惠)

Posted on 2006-05-30 14:29  沧海笑  阅读(1925)  评论(0编辑  收藏  举报
linux下使用fdisk分区

在linux下,使用fdisk对硬盘分区:先删除原有分区,然后创建新的分区


1) 删除分区

[root@standby root]# fdisk /dev/sdc

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

Disk /dev/sdc: 36.4 GB, 36401479680 bytes
255 heads, 63 sectors/track, 4425 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot    Start       End    Blocks   Id  System
/dev/sdc1             1       250   2008093+  83  Linux
/dev/sdc2           251       500   2008125   83  Linux
/dev/sdc3           501       750   2008125   83  Linux
/dev/sdc4           751      4425  29519437+   5  Extended
/dev/sdc5           751      1000   2008093+  83  Linux
/dev/sdc6          1001      4425  27511281   83  Linux

Command (m for help): d
Partition number (1-6): 1

Command (m for help): d
Partition number (1-6): 2

Command (m for help): d
Partition number (1-6): 3

Command (m for help): d
Partition number (1-6): 4

Command (m for help): p

Disk /dev/sdc: 36.4 GB, 36401479680 bytes
255 heads, 63 sectors/track, 4425 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot    Start       End    Blocks   Id  System

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

Calling ioctl() to re-read partition table.
Syncing disks.


2) 创建分区

[root@standby root]# fdisk /dev/sdc

The number of cylinders for this disk is set to 4425.
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/sdc: 36.4 GB, 36401479680 bytes
255 heads, 63 sectors/track, 4425 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   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-4425, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-4425, default 4425): +500

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

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

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Selected partition 4
First cylinder (1002-4425, default 1002):
Using default value 1002
Last cylinder or +size or +sizeM or +sizeK (1002-4425, default 4425): +2048M

Command (m for help): n
You must delete some partition and add an extended partition first

Command (m for help): d
Partition number (1-4): 4

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

Command (m for help): n
First cylinder (1002-4425, default 1002):
Using default value 1002
Last cylinder or +size or +sizeM or +sizeK (1002-4425, default 4425): +2048M

Command (m for help): n
First cylinder (1252-4425, default 1252):
Using default value 1252
Last cylinder or +size or +sizeM or +sizeK (1252-4425, default 4425): +2048M

Command (m for help): n
First cylinder (1502-4425, default 1502):
Using default value 1502
Last cylinder or +size or +sizeM or +sizeK (1502-4425, default 4425):
Using default value 4425

Command (m for help): n
No free sectors available

Command (m for help): p

Disk /dev/sdc: 36.4 GB, 36401479680 bytes
255 heads, 63 sectors/track, 4425 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot    Start       End    Blocks   Id  System
/dev/sdc1             1       501   4024251   83  Linux
/dev/sdc2           502       751   2008125   83  Linux
/dev/sdc3           752      1001   2008125   83  Linux
/dev/sdc4          1002      4425  27503280    5  Extended
/dev/sdc5          1002      1251   2008093+  83  Linux
/dev/sdc6          1252      1501   2008093+  83  Linux
/dev/sdc7          1502      4425  23486998+  83  Linux

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

Calling ioctl() to re-read partition table.
Syncing disks.

 

分区建好后有两种方法:使用文件系统,使用裸设备

1) 使用文件系统

创建文件系统
[root@standby root]# mkdir /test
[root@standby root]# mkfs  /dev/sdc3
mke2fs 1.32 (09-Nov-2002)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
251392 inodes, 502031 blocks
25101 blocks (5.00%) reserved for the super user
First data block=0
16 block groups
32768 blocks per group, 32768 fragments per group
15712 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912

Writing inode tables: 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@standby root]# mount /dev/sdc3 /test

改权限
[root@standby root]# ls -ltr  /test
total 16
drwx------    2 root     root        16384 Jun 20 21:51 lost+found

[root@standby root]# chown  -R  oracle.dba  /test
[root@standby root]# chmod 755 /test

[root@standby root]# ls -ltr  /test
total 16
drwx------    2 oracle   dba         16384 Jun 20 21:51 lost+found

创建表空间
SQL> create tablespace chen
  2  datafile '/test/chen.dbf' size 10M;

Tablespace created.

向表空间增加数据文件
SQL> alter tablespace chen
  2  add datafile '/test/chen2.dbf' size 10M;

Tablespace altered.

可以看到表空间chen的大小是20m了
SQL>     select t.tablespace_name, round(sum(bytes/(1024*1024)),0) ts_size
  2      from dba_tablespaces t, dba_data_files d
  3      where t.tablespace_name = d.tablespace_name
  4      group by t.tablespace_name;

TABLESPACE_NAME                                                 TS_SIZE
------------------------------------------------------------ ----------
CHEN                                                                 20
EYGLE                                                                10
SYSTEM                                                              250
UNDOTBS1                                                            200
USERS                                                                25


2) 使用裸设备

可以看到已有的绑定
[root@standby root]# raw -qa
/dev/raw/raw1:  bound to major 8, minor 17
/dev/raw/raw2:  bound to major 8, minor 18
/dev/raw/raw3:  bound to major 8, minor 19
/dev/raw/raw4:  bound to major 8, minor 20
/dev/raw/raw5:  bound to major 8, minor 34

绑定裸设备
[root@standby test]# raw /dev/raw/raw6 /dev/sdc1
/dev/raw/raw6:  bound to major 8, minor 33

ditional information: 1

改权限
[root@standby root]# chown -R oracle.dba /dev/raw
[root@standby root]# chmod 755 /dev/raw

创建表空间
SQL> create tablespace jin
  2  datafile '/dev/raw/raw6' size 10M;

Tablespace created.