Linux下分割槽詳解之--Fdisk

wuweilong發表於2012-05-06

Linux下分割槽詳解之--Fdisk

作者:吳偉龍

1、             透過Fdisk檢視系統分割槽詳細資訊:

Fdisk –l   詳解:

[root@jetsenLin ~]# fdisk -l

 

Disk /dev/sda: 10.7 GB, 10737418240 bytes

255 heads, 63 sectors/track, 1305 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

註釋:這個硬碟的大小是10.7GB,有255個磁面,63個扇區,1305磁柱(cylinders)

每個 cylinder(磁柱)的容量是 8225280 bytes=8225.280 K(約為)=8.225280M(約為);

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          13      104391   83  Linux

/dev/sda2              14        1305    10377990   8e  Linux LVM

 

idSystem 表示的是一個意思,id看起來不太直觀,我們要在fdisk 一個分割槽時,透過指定id來確認分割槽型別;比如 7表示的就NTFS 分割槽;這個在fdisk 中要透過t功能來指定。下面的部分會提到;

 

Disk /dev/sdb: 21.4 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

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

說明: 硬碟分割槽的表示:在Linux 是透過hd*x sd*x 表示的:

其中 * 表示的是abc ... ...

另外 x 表示的數字 123 ... ...

hd大多是IDE硬碟;sd大多是SCSI或移動儲存; 引導(Boot):表示引導分割槽,在上面的例子中 sda1 是引導分割槽;

Start (開始):表示的一個分割槽從X cylinder(磁柱)開始;

End (結束):表示一個分割槽到 Y cylinder(磁柱)結束;

 

2、             學會使用fdisk幫助功能:

[root@jetsenLin ~]# fdisk /dev/sda

 

The number of cylinders for this disk is set to 1305.

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   --建立一個新的空白DOS分割槽表

   p   print the partition table                ---列印分割槽表

   q   quit without saving changes            ---退出不儲存設定

   s          ---

   t              ---改變分割槽的ID

   u                ---改變顯示的單位

   v                  ---檢查驗證分割槽表

   w   write table to disk and exit             ---儲存分割槽表

   x   extra functionality (experts only)

 

Command (m for help):

3、             透過Fdisk對磁碟分割槽進行操作:

Fdisk 建立分割槽:

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

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): n          ---輸入m會有幫助資訊出來,輸入n不列印幫助資訊

Command action

   e   extended

   p   primary partition (1-4)      ---指定分割槽型別  e為擴充套件分割槽   p為主分割槽

p

Partition number (1-4): 1           ---定義分割槽數量   --主分割槽最多隻能有四個

First cylinder (1-2610, default 1): 1   ---設定起始分割槽的位置

Last cylinder or +size or +sizeM or +sizeK (1-2610, default 2610):

Using default value 2610            ---設定結束分割槽的位置

 

Command (m for help): w           ---儲存剛才的配置資訊。

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

Syncing disks.

[root@jetsenLin ~]#

 

 Fdisk 刪除分割槽:

 

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

 

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)

 

Command (m for help): d      ---d 是代表刪除,並且會列出當前磁碟的分割槽數。

Selected partition 1

 

Command (m for help): p      ----p 是代表刪除後,顯示磁碟還有幾個剩餘的分割槽。

 

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    ----已經沒有分割槽了

 

Command (m for help): w                  ----儲存剛才的操作並且生效

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

 

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.  

The kernel still uses the old table.

The new table will be used at the next reboot.

這裡報了一錯誤,分割槽表正在使用,刪除再下次啟動生效

Syncing disks.        ---同步新的磁碟資訊

[root@jetsenLin ~]# fdisk -l /dev/sdb

 

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

 

透過fdisk 命令來建立一指定大小的分割槽並增加一個分割槽

Fdisk n

建立分割槽:

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

 

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)

 

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): 1   --指定起始柱面號

Last cylinder or +size or +sizeM or +sizeK (1-2610, default 2610): 1024 ---指定終止柱面號

 

Command (m for help): w            ---儲存分割槽配置資訊

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

 

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.

The kernel still uses the old table.

The new table will be used at the next reboot.

Syncing disks.

增加分割槽:

[root@jetsenLin ~]# fdisk /dev/sdb      -----增加分割槽

 

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)

 

Command (m for help): n       ---分割槽型別

Command action

   e   extended

   p   primary partition (1-4)    ---還是指定主分割槽

p

Partition number (1-4): 1          ---分割槽號,我指定1

. 

提示分割槽號1已經存在,刪除後操作

Command (m for help): n          --我們重新建立分割槽

Command action

   e   extended

   p   primary partition (1-4)     --指定分割槽型別

p

Partition number (1-4): 2          ---因為分割槽1已經存在,所以我們指定分割槽2,可透過。

First cylinder (1025-2610, default 1025):       ---指定起始礠柱號,預設是上一分割槽後一號。

Using default value 1025

Last cylinder or +size or +sizeM or +sizeK (1025-2610, default 2610): 2000   --指定終止礠柱號。

 

Command (m for help): w                   ---儲存分割槽配置

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

 

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.

The kernel still uses the old table.

The new table will be used at the next reboot.

Syncing disks.

[root@jetsenLin ~]#

 

透過fdisk 命令來來修改現有分割槽型別

   Fdisk 透過t引數來指定

 檢視分割槽型別

[root@jetsenLin ~]# fdisk -l /dev/sdb   檢視分割槽資訊,型別是Linuxid83

 

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        1024     8225248+  83  Linux

/dev/sdb2            1025        2000     7839720   83  Linux

 

修改分割槽型別

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

 

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)

 

Command (m for help): t                              ---進入修改分割槽型別

Partition number (1-4): 1                              ---指定需要修改的分割槽號

Hex code (type L to list codes): 6                        ---指定分割槽號為6,也就是FAT16

注意:檢視分割槽型別的程式碼,在這裡可以輸入L檢視就可以了

Changed system type of partition 1 to 6 (FAT16)

 

Command (m for help): w                              ---儲存

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

 

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.

The kernel still uses the old table.

The new table will be used at the next reboot.

 

WARNING: If you have created or modified any DOS 6.x

partitions, please see the fdisk manual page for additional

information.

Syncing disks.

 

[root@jetsenLin ~]# fdisk -l /dev/sdb        ---我們看到已經FAT16,並且ID也改成6了。

 

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        1024     8225248+   6  FAT16

/dev/sdb2            1025        2000     7839720   83  Linux

[root@jetsenLin ~]#

 

 

4、             對分割槽進行格式化及載入:

對分割槽進行格式化的命令如下等,mkfs後面所接的代表的是將要格式化成的檔案系統型別:

mkfs.bfs

mkfs.ext2

mkfs.ext3

mkfs.jfs

mkfs.msdos

mkfs.vfat

mkfs.cramfs

mkfs.minix

mkfs.reiserfs

mkfs.xfs

 

格式化分割槽:

 [root@jetsenLin ~]# mkfs.ext4 /dev/sdb1          ---格式化分割槽型別為ext4

mke4fs 1.41.5 (23-Apr-2009)

Filesystem label=                  ---我們沒有指定卷標,就沒有

OS type: Linux                    ---作業系統型別

Block size=4096 (log=2)             --單個塊的大小

=4096 (log=2)          --片大小

1310720 inodes, 5241198 blocks

262059 blocks (5.00%) reserved for the super user

First data block=0     

Maximum filesystem blocks=0

160 block groups

32768 blocks per group, 32768 fragments per group

8192 inodes per group

Superblock backups stored on blocks:

        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,

        4096000

 

Writing inode tables: done                           

Creating journal (32768 blocks): done

Writing superblocks and filesystem accounting information: done

 

This filesystem will be automatically checked every 27 mounts or

180 days, whichever comes first.  Use tune4fs -c or -i to override.

 

掛載磁碟:(臨時掛載)

[root@jetsenLin ~]# mkdir /data             --建立掛載目錄點

[root@jetsenLin ~]# mount  /dev/sdb1 /data  --/dev/sdb1 掛載到/data

 

驗證是否成功掛載

[root@jetsenLin ~]# df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/mapper/VolGroup00-LogVol00

                      7.7G  3.1G  4.2G  43% /

/dev/sda1              99M   12M   82M  13% /boot

tmpfs                 506M     0  506M   0% /dev/shm

/dev/sdb1              20G   16K   20G   1% /data     --我們看到已經成功掛載了。

[root@jetsenLin ~]#

 

掛載磁碟:(永久掛載)

   透過vi編輯器編輯/etc/fstab檔案,內容如下,(紅色部分是剛新增上去的):

 

掛載路徑              掛載的分割槽          檔案系統  掛載引數     是否要備份   自檢順序

/dev/VolGroup00/LogVol00 /                       ext3    defaults        1 1

LABEL=/boot             /boot                   ext3    defaults        1 2

tmpfs                   /dev/shm                tmpfs   defaults        0 0

devpts                  /dev/pts                devpts  gid=5,mode=620  0 0

sysfs                   /sys                    sysfs   defaults        0 0

proc                    /proc                   proc    defaults        0 0

/dev/VolGroup00/LogVol01 swap                    swap    defaults        0 0

/data                   /dev/sdb1                ext4    default         0 0

 

第四列掛載引數:透過檢視man mount 來檢視

第五列是否要備份:(0為不備份,1為要備份, 一般情況下不用做備份)

第六列自檢程式  0為不自檢,12為要自檢,如果是根分割槽要設定1,其它分割槽只能是2

 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/20674423/viewspace-722812/,如需轉載,請註明出處,否則將追究法律責任。

相關文章