Linux新增磁盤分區

磁盤的分區

       主分區與擴展分區最多可以有4個(分區表64字節,每分區占16字節);

       擴展分區最多只能有一個;

       邏輯分區是由擴展分區持續分出來的分區;

       能夠被格式化后作為數據訪問的分區為主要分區與邏輯分區,擴展分區無法格式化;

       邏輯分區的數量以操作系統而不同,在Linux系統中,IDE硬盤最多有59個邏輯分區(5-63),SATA硬盤則有11個邏輯分區(5-15);

各接口的磁盤在Linux中的文件名分別為

       /dev/sd[a-p][1-15]:為SCSI,SATA,USB,Flash等接口的磁盤文件名;

      /dev/hd[a-d][1-63]:為IDE接口的磁盤文件名;

文件系統分類

       Windows :NTFS、FAT32

       Linux:ext2、ext3、ext4、xfsreiserfs、nfsiso9660、jfsbrtfs


 小結:通過以上內容,我們簡單了解了磁盤的組成、分區、接口的磁盤命名及文件系統的分類。下面我們來具體看下磁盤分區、格式化及磁盤掛載所使用到的命令。


[root@ti0203a400-1401 /]# fdisk -l              //查看磁盤


Disk /dev/sda: 53.7 GB, 53687091200 bytes

255 heads, 63 sectors/track, 6527 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

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

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

Disk identifier: 0x000152be


   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          26      204800   83  Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2              26        5125    40960000   83  Linux

/dev/sda3            5125        5380     2048000   82  Linux swap / Solaris


[root@ti0203a400-1401 /]# fdisk /dev/sda                    //開始創建磁盤分區


WARNING: DOS-compatible mode is deprecated. It's strongly recommended to

         switch off the mode (command 'c') and change display units to

         sectors (command 'u').


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


Disk /dev/sda: 53.7 GB, 53687091200 bytes

255 heads, 63 sectors/track, 6527 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

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

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

Disk identifier: 0x000152be


   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          26      204800   83  Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2              26        5125    40960000   83  Linux

/dev/sda3            5125        5380     2048000   82  Linux swap / Solaris


Command (m for help): n                        //新建一個分區

Command action

   e   extended

   p   primary partition (1-4)

p                                                        //創建主分區

Selected partition 4                         //分區號

First cylinder (5380-6527, default 5380):                //(開始柱面-可默認)                 

Using default value 5380

Last cylinder, +cylinders or +size{K,M,G} (5380-6527, default 6527): +5G                   //磁盤大小


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


Disk /dev/sda: 53.7 GB, 53687091200 bytes

255 heads, 63 sectors/track, 6527 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

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

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

Disk identifier: 0x000152be


   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          26      204800   83  Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2              26        5125    40960000   83  Linux

/dev/sda3            5125        5380     2048000   82  Linux swap / Solaris

/dev/sda4            5380        6033     5246248+  83  Linux


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 or after you run partprobe(8) or kpartx(8)

Syncing disks.

[root@ti0203a400-1401 /]# df -h

Filesystem      Size  Used Avail Use% Mounted on

/dev/sda2        39G  3.3G   34G   9% /

tmpfs           491M   92K  491M   1% /dev/shm

/dev/sda1       190M   55M  126M  31% /boot

[root@ti0203a400-1401 /]# cat /proc/partitions            //查看分區表是否加載

major minor  #blocks  name


   8        0   52428800 sda

   8        1     204800 sda1

   8        2   40960000 sda2

   8        3    2048000 sda3

   8        4    5246248 sda4                                             //如果沒有加載就執行下面指令重新讀取加載

[root@ti0203a400-1401 /]# partx -a /dev/sda          // RHEL6讓內核重新讀取硬盤分區表:

BLKPG: Device or resource busy

error adding partition 1

BLKPG: Device or resource busy

error adding partition 2

BLKPG: Device or resource busy

error adding partition 3

BLKPG: Device or resource busy

error adding partition 4

[root@ti0203a400-1401 /]# mkfs -t ext4 /dev/sda4              //格式化新建磁盤

mke2fs 1.41.12 (17-May-2010)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

Stride=0 blocks, Stripe width=0 blocks

328000 inodes, 1311562 blocks

65578 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=1346371584

41 block groups

32768 blocks per group, 32768 fragments per group

8000 inodes per group

Superblock backups stored on blocks: 

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


Writing inode tables: done                            

Creating journal (32768 blocks): 

done

Writing superblocks and filesystem accounting information: 

done


This filesystem will be automatically checked every 20 mounts or

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

[root@ti0203a400-1401 /]# 

[root@ti0203a400-1401 /]# mkdir -p /testdir                                             //創建磁盤掛載目錄

[root@ti0203a400-1401 /]# mount -t ext4  /dev/sda4 /testdir/                 //掛載磁盤

[root@ti0203a400-1401 /]# df -h                                                               //查看磁盤是否識別并掛載

Filesystem      Size  Used Avail Use% Mounted on

/dev/sda2        39G  3.3G   34G   9% /

tmpfs           491M   92K  491M   1% /dev/shm

/dev/sda1       190M   55M  126M  31% /boot

/dev/sda4       4.8G   11M  4.6G   1% /testdir

[root@ti0203a400-1401 /]# ls /testdir/

lost+found

[root@ti0203a400-1401 /]# 






轉載:

http://miclesvic.blog.51cto.com/2152735/1344202











原創文章,作者:jxmsn,如若轉載,請注明出處:http://www.www58058.com/16100

(0)
jxmsnjxmsn
上一篇 2016-05-29 15:20
下一篇 2016-05-30 14:51

相關推薦

  • LAMP 通過使用腳本的方式安裝并部署Discuz

    該腳本有很多輔助的部分,主要是為了讓腳本在中途運行失敗可以多次運行,所產生的結果是預期的,與第一運行并成功的結果是一樣的。初次攝入bash腳本有很多不足,敬請指正。 所需要的軟件 apr-1.5.2.tar.bz2 apr-util-1.5.4.tar.bz2 Discuz_X3.2_SC_UTF8.zip freetype-2.5.4.tar.gz htt…

    Linux干貨 2016-04-05
  • LVS NAT模型

    LVS NAT NAT模式顧名思義就是對地址進行轉換 通過訪問前端外網的VIP調度到后端兩臺真實主機 拓撲圖如下                      &n…

    2017-05-15
  • SED基本用法和在文本中的使用

    sed命令行格式為: sed [-nefri] ‘command’ 輸入文本/文件 常用選項: -n∶取消默認的輸出,使用安靜(silent)模式。在一般 sed 的用法中,所有來自 STDIN的資料一般都會被列出到屏幕上。但如果加上 -n 參數后,則只有經過sed 特殊處理的那一行(或者動作)才會被列出來 -e∶進行多項編輯,…

    Linux干貨 2017-05-05
  • n28 第二周作業

    n28 第二周作業

    Linux干貨 2017-12-09
  • 從Linux小白到大?!c狼共舞的日子2

    馬哥教育網絡班21期+第2周課程練習 1、Linux上的文件管理類命令都有哪些,其常用的使用方法及其相關示例演示。 cp:copy,復制文件 cp SRC DEST   SRC為文件     如果目錄不存在:新建DEST,并將SRC中內容填充至DEST中     如果目…

    Linux干貨 2016-07-17
  • lvs筆記之nat&dr模型簡單實現

    lvs筆記之nat&dr模型簡單實現 lvs筆記之nat&dr模型簡單實現 lvs 集群 實現 負載均衡 nat lvs筆記之nat&dr模型簡單實現 ipvsadm使用說明 lvs-nat的簡單實現 踩過的坑1 lvs-dr實現 總結 ipvsadm使用說明     -A: 添加一個…

    2017-01-03
欧美性久久久久