linux中fdisk分區命令使用詳解

來源:互聯網
上載者:User

在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


指令:fdisk

用途:觀察硬碟之實體使用情形與分割硬碟用。

使用方法:

      一、在 console 上輸入 fdisk -l /dev/sda ,觀察硬碟之實體使用情形。

      二、在 console 上輸入 fdisk /dev/sda,可進入分割硬碟模式。

        1. 輸入 m 顯示所有命令列示。

        2. 輸入 p 顯示硬碟分割情形。

        3. 輸入 a 設定硬碟啟動區。

        4. 輸入 n 設定新的硬碟分割區。

         4.1. 輸入 e 硬碟為[延伸]分割區(extend)。

         4.2. 輸入 p 硬碟為[主要]分割區(primary)。

        5. 輸入 t 改變硬碟分割區屬性。

        6. 輸入 d 刪除硬碟分割區屬性。

        7. 輸入 q 結束不存入硬碟分割區屬性。

        8. 輸入 w 結束並寫入硬碟分割區屬性

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.