天天看點

磁盤分區管理

1.裝置的識别 

/dev/sda    ###系統中的第一塊序列槽硬碟  (sata序列槽) 

/dev/hda    ###系統中第一快并口硬碟  (IDE) 

/dev/hdb    ###系統中第二快并口硬碟 

/dev/cdrom    ###系統光驅 

/dev/mapper/xxx    ###虛拟裝置  

2.裝置的使用 

mount    裝置    挂載點    ###挂載 

mount /dev/sda1  /mnt  ###把系統中的第一快硬碟的第一個分區挂載到/mnt下 

umount    裝置|挂載點    ###解除安裝裝置  

blkid            ###顯示所有可用裝置的id資訊 

df     -h(2的n次方) -H(10的n此方)            ####檢視挂載資訊 

du    -h(顯示機關)    -s(隻統計目錄本身) 

file|dir    ####統計檔案大小 

3.當裝置解除安裝出現以下問題時 

[root@foundation0 ~]# umount /mnt/ umount: /mnt: target is busy.         (In some cases useful info about processes that use          the device is found by lsof(8) or fuser(1))  

  用 fuser    裝置|挂載點

      lsof    裝置|挂載點 

    來找到占用裝置的程序

4.什麼時mbr?

    MBR是Main Bootable Record,即主引導記錄,它記錄了整個硬碟的分區資訊。在硬碟做分區動作時,儲存在被激活的分區(一般是将C區激活)裡。格式化不能清除MBR,隻有重新分區裡才以新的MBR資訊替換掉原有的。 

5.分區

[root@diskctrl ~]# fdisk  /dev/vdb        ##劃分/dev/vdb 

Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.

Be careful before using the write command.

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            ##删除裝置

   g   create a new empty GPT partition table

   G   create an IRIX (SGI) partition table

   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):n

Partition type:p            ##指定劃分裝置的分區類型

   p   primary (0 primary, 0 extended, 4 free)

   e   extended

Partition number (1-4, default 1):1    ##指定使用的分區表号

First sector (2048-20971519, default 2048):enter    ##分區起始快,選擇預設

Using default value 2048

Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +1G ##裝置大小指定

Command (m for help): p            ##顯示分區表

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk label type: dos

Disk identifier: 0x7c2200a8

   Device Boot      Start         End      Blocks   Id  System

/dev/vdb1            2048     2099199     1048576   83  Linux        ##被劃分出來的分區

Command (m for help):  wq                        ##儲存更改方式并退出

[root@diskctrl ~]# partprobe             ##同步分區表

[root@diskctrl ~]# cat /proc/partitions     ##檢視系統能識别的分區

major minor  #blocks  name

 253        0   10485760 vda

 253        1   10484142 vda1

 253       16   10485760 vdb

 253       17    1048576 vdb1

mkfs.ext4   /vdb1  建立檔案系統

6.如何使用建立立的分區

vim /etc/fstab 實作永久挂載

/dev/vdb1  /mnt  ext4  defaults  0  0

7.裝置删除

解除安裝

删除 /etc/fstab中裝置的自動挂載條目

用fdisk删除分區

8.swap分區的管理

swapon -s        ##檢視系統中的swap分區

建立swap分區

mkswap    /dev/vdb1    ###把/dev/vdb1格式化成swap格式

swapon -a /dev/vdb1    ##激活

vim /etc/fstab        ##開機自動激活

/dev/vdb1    swap    swap    defautls    0 0

本文轉自willis_sun 51CTO部落格,原文連結:http://blog.51cto.com/willis/1846984,如需轉載請自行聯系原作者