1. 程式人生 > >Linux下分割槽詳解之--Fdisk

Linux下分割槽詳解之--Fdisk

Linux下分割槽詳解之--Fdisk

作者:吳偉龍

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

Fdisk –l   詳解:

[[email protected] ~]# fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes

255 heads, 63 sectors/track, 1305 cylinders

Units = cylinders of 16065 * 512 = 8225280bytes

註釋:這個硬碟的大小是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 = 8225280bytes

Disk /dev/sdb doesn't contain a validpartition table

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

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

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

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

是引導分割槽;

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

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

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

[[email protected]~]# fdisk /dev/sda

Thenumber of cylinders for this disk is set to 1305.

There isnothing wrong with that, but this is larger than 1024,

and couldin certain setups cause problems with:

1) softwarethat 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      ---輸出幫助資訊

Commandaction

   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           ---退出不儲存設定

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

   x  extra functionality (experts only)

Command (m for help):

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

Fdisk 建立分割槽:

[[email protected] ~]#fdisk /dev/sdb

Device contains neither a valid DOSpartition table, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel. Changes willremain 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 isset to 2610.

There is nothing wrong with that, but thisis larger than 1024,

and could in certain setups cause problemswith:

1) software that runs at boot time (e.g.,old versions of LILO)

2) booting and partitioning software fromother OSs

  (e.g., DOS FDISK, OS/2 FDISK)

Warning: invalid flag 0x0000 of partitiontable 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.

[[email protected] ~]#

Fdisk 刪除分割槽:

[[email protected] ~]# fdisk /dev/sdb   

The number of cylinders for this disk isset to 2610.

There is nothing wrong with that, but thisis larger than 1024,

and could in certain setups cause problemswith:

1) software that runs at boot time (e.g.,old versions of LILO)

2) booting and partitioning software fromother 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 = 8225280bytes

  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 tablefailed with error 16: Device or resource busy.  

The kernel still uses the old table.

The new table will be used at the nextreboot.

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

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

[[email protected] ~]# fdisk -l /dev/sdb

Disk /dev/sdb: 21.4 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280bytes

  Device Boot      Start         End      Blocks  Id  System

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

Fdisk n

建立分割槽:

[[email protected] ~]# fdisk /dev/sdb

The number of cylinders for this disk isset to 2610.

There is nothing wrong with that, but thisis larger than 1024,

and could in certain setups cause problemswith:

1) software that runs at boot time (e.g.,old versions of LILO)

2) booting and partitioning software fromother 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 tablefailed with error 16: Device or resource busy.

The kernel still uses the old table.

The new table will be used at the nextreboot.

Syncing disks.

增加分割槽:

[[email protected] ~]# fdisk /dev/sdb      -----增加分割槽

The number of cylinders for this disk isset to 2610.

There is nothing wrong with that, but thisis larger than 1024,

and could in certain setups cause problemswith:

1) software that runs at boot time (e.g.,old versions of LILO)

2) booting and partitioning software fromother 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 tablefailed with error 16: Device or resource busy.

The kernel still uses the old table.

The new table will be used at the nextreboot.

Syncing disks.

[[email protected] ~]#

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

   Fdisk 通過t引數來指定

檢視分割槽型別

[[email protected] ~]# 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 = 8225280bytes

  Device Boot      Start         End      Blocks  Id  System

/dev/sdb1               1        1024    8225248+  83  Linux

/dev/sdb2            1025        2000    7839720   83  Linux

修改分割槽型別

[[email protected] ~]# fdisk /dev/sdb

The number of cylinders for this disk isset to 2610.

There is nothing wrong with that, but thisis larger than 1024,

and could in certain setups cause problemswith:

1) software that runs at boot time (e.g.,old versions of LILO)

2) booting and partitioning software fromother OSs

  (e.g., DOS FDISK, OS/2 FDISK)

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

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

Hex code (type L tolist 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 tablefailed with error 16: Device or resource busy.

The kernel still uses the old table.

The new table will be used at the nextreboot.

WARNING: If you have created or modifiedany DOS 6.x

partitions, please see the fdisk manualpage for additional

information.

Syncing disks.

[[email protected] ~]# 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 = 8225280bytes

  Device Boot      Start         End      Blocks  Id  System

/dev/sdb1               1        1024    8225248+   6  FAT16

/dev/sdb2            1025        2000    7839720   83  Linux

[[email protected] ~]#

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

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

mkfs.bfs

mkfs.ext2

mkfs.ext3

mkfs.jfs

mkfs.msdos

mkfs.vfat

mkfs.cramfs

mkfs.minix

mkfs.reiserfs

mkfs.xfs

格式化分割槽:

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

mke4fs 1.41.5(23-Apr-2009)

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

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

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

1310720 inodes, 5241198blocks

262059 blocks (5.00%)reserved for the super user

First data block=0     

Maximum filesystem blocks=0

160 block groups

32768 blocks per group, 32768fragments 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 (32768blocks): done

Writing superblocks andfilesystem accounting information: done

This filesystem will beautomatically checked every 27 mounts or

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

掛載磁碟:(臨時掛載)

[[email protected] ~]# mkdir/data             --建立掛載目錄點

[[email protected] ~]#mount  /dev/sdb1 /data  --/dev/sdb1 掛載到/data

驗證是否成功掛載

[[email protected] ~]# 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     --我們看到已經成功掛載了。

[[email protected] ~]#

掛載磁碟:(永久掛載)

通過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/LogVol01swap                    swap    defaults        0 0

/data                   /dev/sdb1                ext4    default         0 0

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

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

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

相關推薦

Linux分割槽--Fdisk

Linux下分割槽詳解之--Fdisk 作者:吳偉龍 1、            通過Fdisk檢視系統分割槽詳細資訊: Fdisk –l   詳解: [[email protected]

Linux分割槽 Parted

通常我們用的比較多的一般都是fdisk工具來進行分割槽,但是現在由於磁碟越來越廉價,而且磁碟空間越來越大;而fdisk工具他對分割槽是有大小限制的,它只能劃分小於2T的磁碟。但是現在的磁碟空間很多都已經是遠遠大於2T了,甚至達到2.5T和3T,那要怎麼辦能,有兩個方法,其一是通過卷管理來實現

linux基礎3-磁碟和檔案系統相關 LINUX支援哪些檔案系統 linux磁碟分割槽 圖文(fdisk;mkfs)

一 dumpe2fs :    在Linux使用過程中,我們如果要了解檔案系統的配置情況,可以使用dumpe2fs檢視ext2/ext3/ext4格式的檔案系統資訊。 命令格式: dumpe2fs [選項] 裝置 常用選項: -h  僅列出超級塊中的資訊

Linuxlog

日誌檔案的預設路徑是:/var/log 下面是日誌檔案的路徑及其包含的資訊: /var/log/syslog:它和/etc/log/messages日誌檔案不同,它只記錄警告資訊,常常是系統出問題的資訊。 /var/log/messages:包括整體系統資訊,其中也包含系統啟動期間的日誌

Linux核心程序三:flush-x:y

上一篇文章《裝置檔案與裝置號》當然不是突然穿插而來的自言自語,而是理解本文的前提,下面來看。是一類程序,這在系列的上一篇文章裡已經講到過,系統的絕大部分的bdi裝置都會有對應的flush-x:y核心程序,而這個x:y是對應bdi裝置的裝置號。 先看一下系統當前掛載的檔案系統

linux/unix命令sed

ps:我只能說別說你會sed。。。這篇綜合很多sed文件寫成。 1. 功能說明:利用script來處理文字檔案。 語  法:sed [-hnV][-e(script)][-f (script檔案) ][文字檔案] 補充說明:sed可依照script的指令,來處理、編輯文字檔

linux磁碟分割槽

        在學習 Linux 的過程中,安裝 Linux 是每一個初學者的第一個門檻。在這個過程中間,最大的困惑莫過於給硬碟進行分割槽。雖然,現在各種發行版本的 Linux 已經提供了友好的圖形互動介面,但是很多的人還是感覺無從下手。這其中的原因主要是不清楚 Linu

Linux訊號

訊號:當我們按下Ctrl+'C' /"D"/"\"/"Z"等組合鍵時,程序為什麼會停止下來,實際上是我們給程序發出了訊號,例如,我們在除錯的過程中,程式異常終止時,常常會受到SIGSEGV訊號,那麼核心是如何來管理這些訊號的呢? 當有訊號產生時,程序PCB會維護兩個訊號集

Linux的壓縮壓縮命令及實例

tar命令 壓縮解壓 建立 存在 sdi 創建 指定 處理 解壓縮 實例:壓縮當前目錄的內容為xxx.zip文件 zip -r xxx.zip ./* 解壓zip文件到當前目錄 unzip filename.zip ======================

linux命令(at)

關閉 服務啟動 安全問題 分隔 sta 設定 tmp 指示 命令的使用 在Linux下,有兩個命令可以用來作為計劃任務而執行,at:一次性定時任務計劃執行crontab :每天定時任務計劃執行以下僅說一下一次性任務計劃執行(at)要使用一次性任務計劃,linux必須要有負責

linux命令df(6/19)

AS true 設置 符號鏈接 disk var aci 實例 logs df命令作用是列出文件系統的整體磁盤空間使用情況。可以用來查看磁盤已被使用多少空間和還剩余多少空間。 df命令顯示系統中包含每個文件名參數的磁盤使用情況,如果沒有文件名參數,則顯示所有當前已掛載文件系

Linux 啟動init執行過程

Linux 啟動詳解之init 1.init初探 init是Linux系統操作中不可缺少的程式之一。init程序,它是一個由核心啟動的使用者級程序,然後由它來啟動後面的任務,包括多使用者環境,網路等。 核心會在過去曾使用過init的幾個地方查詢它,它的正確位置

Linux 命令 stat 命令

Linux 命令詳解之 stat 命令【updating…】 1. 簡介 NAME stat - display file or file system status 2. 引數 3. 實戰 stat test.sh File: ‘test.sh

Linux核心中RAID5原始碼基本架構與資料結構

Linux核心中RAID5的基本架構與資料結構解析 眾所周知,早年的計算機儲存資料現在磁帶上,然後發展到了磁碟,然而僅僅是單個盤,速度和效能都不是很好,然是,要知道人類的聰明才智是連ET都想不到的,前輩們不斷的猜想,實驗來提高計算機的效能,於是磁碟陣列問世

linux命令ls命令

ls命令概述 ls命令用於顯示檔案目錄列表,和Windows系統下DOS命令dir類似。當執行ls命令時,預設顯示的只有非隱藏檔案的檔名、以檔名進行排序及檔名代表的顏色顯示。當不加引數時,預設列出當前

Linux DTS(Device Tree Source)裝置樹二(dts匹配及發揮作用的流程篇)

本系列導航: 有上一篇文章,我們瞭解了dts的背景知識和相關基礎,這次我們對應實際裝置進行一下相關分析。 DTS裝置樹的匹配過程 一個dts檔案確定一個專案,多個專案可以包含同一個dtsi檔案。找到該專案對應的dts檔案即找到了該裝置樹的根節點。 kernel

高通平臺msm8953 Linux DTS(Device Tree Source)裝置樹二(DTS裝置樹匹配過程)

本系列導航:有上一篇文章,我們瞭解了dts的背景知識和相關基礎,這次我們對應實際裝置進行一下相關分析。DTS裝置樹的匹配過程一個dts檔案確定一個專案,多個專案可以包含同一個dtsi檔案。找到該專案對應的dts檔案即找到了該裝置樹的根節點。kernel\arch\arm\bo

解決ajax跨域的方法原理Cors方法

詳細 不同 htm 渲染 jsonp del 需要 methods href 1、神馬是跨域(Cross Domain) 對於端口和協議的不同,只能通過後臺來解決。 一句話:同一個ip、同一個網絡協議、同一個端口,三者都滿足就是同一個域,否則就是 跨域問題了。而為

javascript設計模式命令模式

這一 clas 例子 別了 logs 操作 book 技術 概念   每種設計模式的出現都是為了彌補語言在某方面的不足,解決特定環境下的問題。思想是相通的。只不過不同的設計語言有其特定的實現。對javascript這種動態語言來說,弱類型的特性,與生俱來的多態性,導致某些設

Linux啟動流程

linux 詳解 啟動流程 grub mbr 內核 linux啟動流程第一部分 Linux啟動基礎知識1.1 linux centos6.8啟動流程圖 BIOS加電自檢à加載MBRà加載啟動grubà加載內核à啟動/sbin/i