linux系統創建主分區、邏輯分區 、設置ext系列分區的參數以及檢測分區

使用到的命令有:fdisk分區管理命令、partx 強制內核更新分區表(通過查看/procs/partitions文件可知道內核沒有更新新創建的分區)、mkfs格式化分區命令、mke2fs格式化etx專用工具、blkid查看分區屬性、fsck測試分區

   linux對不同的磁盤設備的設備文件命名如下:

        IDE: /dev/hd[a-z]

            對IDE分區的命名為/dev/hda1    /dev/hda2 …..

        SCSI, SATA, SAS, USB: /dev/sd[a-z]

            對分區的命令為/dev/sda1  /dev/sda2 …….

        主分區最多可有4個。若分區大于4個,可使用3個主分區加一個擴展分區的方式,再通過在擴展分區上劃分多個邏輯分區。

        常見的文件格式有ext2、ext3、ext4、vfat(兼容windows的fat32)、xfs、btrfs、jfs等。


查看linux的磁盤分區可使用fdis(分區管理命令)

    fdisk /dev/sda (非IDE硬盤)

        m:獲取幫助

        p:顯示分區信息

        q:不保存退出

        n:新建分區

        d:刪除分區

        q:保存退出

         l:顯示分區類型的ID

         t:改變分區類型的ID

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

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

Disk /dev/sda: 16.1 GB, 16106127360 bytes, 31457280 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: 0x000a72d4

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *        2048     1026047      512000   83  Linux

/dev/sda2         1026048    20971519     9972736   8e  Linux LVM

說明:

    1、Disk /dev/sda: 16.1 GB 硬盤的大小是16GB,16106127360 個字節,31457280個扇區。

    2、下半部信息說明

        Device 是分區名稱

        Boot 是否是啟動分區

        Start 起始的扇區

        End 結束的扇區   \\  /dev/sda2結束的扇區是20971519,而硬盤總共有31457280,說明還有硬盤空間沒有被用于創建分區。

        Blocks以1KB為單位,顯示分區的空間;

        ld 為分區類型的ID號

        System 為分區類型

創建分區:(下圖中指定起始扇區與/dev/sda2的結束扇區能對接上)

2.png

    創建邏輯分區

Command (m for help): n

Partition type:

   p   primary (3 primary, 0 extended, 1 free)

   e   extended

Select (default e): e   \\指定新建擴展分區

Selected partition 4

First sector (23068672-31457279, default 23068672): 

Using default value 23068672

Last sector, +sectors or +size{K,M,G} (23068672-31457279, default 31457279): +1G  \\指定擴展分區的大小

Partition 4 of type Extended and of size 1 GiB is set

Command (m for help): n 

All primary partitions are in use

Adding logical partition 5  \\ ID號1-4已經用完,系統直接使用邏輯分區ID的范圍5-15

First sector (23070720-25165823, default 23070720): 

Using default value 23070720

Last sector, +sectors or +size{K,M,G} (23070720-25165823, default 25165823): 24000000  \\這里的結束扇區25165823-23070720=2095103*512/1024/1024=1022.99MB,即1GB,與指定的擴展分區大小相同

Partition 5 of type Linux and of size 453.8 MiB is set \\新建邏輯分區的大小是453.8MB

Command (m for help): n

All primary partitions are in use

Adding logical partition 6

First sector (24002049-25165823, default 24002560): 

Using default value 24002560

Last sector, +sectors or +size{K,M,G} (24002560-25165823, default 25165823):  \\這里的結束扇區ID與上述的相同

Using default value 25165823

Partition 6 of type Linux and of size 568 MiB is set

Command (m for help): p

Disk /dev/sda: 16.1 GB, 16106127360 bytes, 31457280 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: 0x000a72d4

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *        2048     1026047      512000   83  Linux

/dev/sda2         1026048    20971519     9972736   8e  Linux LVM

/dev/sda3        20971520    23068671     1048576   83  Linux

/dev/sda4        23068672    25165823     1048576    5  Extended

/dev/sda5        23070720    24000000      464640+  83  Linux

/dev/sda6        24002560    25165823      581632   83  Linux  \\新建的邏輯分區

Command (m for help): w \\保存退出

 檢查linux是否已經識別出新的分區查看/rroc/paritions文件

[root@localhost ~]# cat /proc/partitions 

major minor  #blocks  name

   8        0   15728640 sda

   8        1     512000 sda1

   8        2    9972736 sda2  \\新創建的/dev/sda3-6沒有還沒有識別出來

  11        0    4228096 sr0

 253        0    8880128 dm-0

 253        1    1048576 dm-1

強制讓內核更新分區

[root@localhost ~]# partx -u /dev/sda 

[root@localhost ~]# cat /proc/partitions 

major minor  #blocks  name

   8        0   15728640 sda

   8        1     512000 sda1

   8        2    9972736 sda2

   8        3    1048576 sda3

   8        4          1 sda4

   8        5     464640 sda5

   8        6     581632 sda6 \\已識別出新分區

  11        0    4228096 sr0

 253        0    8880128 dm-0

 253        1    1048576 dm-1

[root@localhost ~]# 

格式化新建的分區mkfs命令

    把sda6、sda5格式為ext4

[root@localhost ~]# mkfs.ext4 -L test /dev/sda6

mke2fs 1.42.9 (28-Dec-2013)

Filesystem label=test

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

Stride=0 blocks, Stripe width=0 blocks

36400 inodes, 145408 blocks

7270 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=148897792

5 block groups

32768 blocks per group, 32768 fragments per group

7280 inodes per group

Superblock backups stored on blocks: 

32768, 98304

Allocating group tables: done                            

Writing inode tables: done                            

Creating journal (4096 blocks): done

Writing superblocks and filesystem accounting information: done


也可用 ext系列專用的格式化工具mke2fs

[root@localhost ~]# mke2fs -t ext3 -m 5 -L TEST_sda5 -b 4096 /dev/sda5 

mke2fs 1.42.9 (28-Dec-2013)

Filesystem label=TEST_sda5 \\標識符為TEST_sda5

OS type: Linux

Block size=4096 (log=2) \\block為4096

Fragment size=4096 (log=2)

Stride=0 blocks, Stripe width=0 blocks

116224 inodes, 116160 blocks

5808 blocks (5.00%) reserved for the super user \\為管理員預留5%的空間

First data block=0

Maximum filesystem blocks=121634816

4 block groups

32768 blocks per group, 32768 fragments per group

29056 inodes per group

Superblock backups stored on blocks: 

32768, 98304

Allocating group tables: done                            

Writing inode tables: done                            

Creating journal (4096 blocks): done

Writing superblocks and filesystem accounting information: done

查看所有分區的屬性使用blkid

[root@localhost ~]# blkid 

/dev/sda1: UUID="050a347a-4a99-4e80-a6b4-a4ed0a47eaa1" TYPE="xfs" 

/dev/sda2: UUID="dv2Krn-BlSL-4NBt-yduR-BXax-tChJ-V2YpbM" TYPE="LVM2_member" 

/dev/sda5: LABEL="TEST_sda5" UUID="b5b2b12b-236d-4578-845b-a5632ca5eafa" SEC_TYPE="ext2" TYPE="ext3"  

/dev/sda6: LABEL="test" UUID="a0a549a2-0aec-4ff6-bce8-f2dfdfa1539e" TYPE="ext4"  

/dev/sr0: UUID="2015-12-09-23-14-10-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos" 

/dev/mapper/centos-root: UUID="0adba78a-e1e3-4900-87c2-069105c6a1fc" TYPE="xfs" 

/dev/mapper/centos-swap: UUID="2228d7dd-b7ed-44fb-9f68-668fc942a542" TYPE="swap" 

使用fsck命令檢測分區

[root@localhost ~]# fsck.ext3 -frc /dev/sda5   \\ f是強制檢測  c是提示測試進度 r進行交互式檢測

e2fsck 1.42.9 (28-Dec-2013)

Checking for bad blocks (read-only test): done                                                 

TEST_sda5: Updating bad block inode.

Pass 1: Checking inodes, blocks, and sizes

Pass 2: Checking directory structure

Pass 3: Checking directory connectivity

Pass 4: Checking reference counts

Pass 5: Checking group summary information

TEST_sda5: ***** FILE SYSTEM WAS MODIFIED *****

TEST_sda5: 11/116224 files (0.0% non-contiguous), 7837/116160 blocks

[root@localhost ~]# 

原創文章,作者:Net20-deamon,如若轉載,請注明出處:http://www.www58058.com/16306

(0)
Net20-deamonNet20-deamon
上一篇 2016-05-16 16:41
下一篇 2016-05-17 13:35

相關推薦

  • grep正則表達式

    grep:這是一個搜索命令,搜文本并且將文本行顯示出來 (1)grep -i 表示搜索的時候忽略大小寫 (2)grep –colour 表示搜索關鍵字帶顏色 例如:grep –colour ‘root’ /etc/passwd 顯示為在etc的passwd里的 root 選項有顏色 *為了方便我們可以定義個別名,讓他搜索的時候默認顯示為帶顏色 alias…

    Linux干貨 2017-07-29
  • 第一周課程練習

    馬哥教育網絡班22期+第一周課程練習 1、描述計算機的組成及其功能   CPU(運算器和控制器),存儲器(內存和外存),輸入/輸出設備。     (1)運算器:對數據進行加工處理(包括算術運算與邏輯運算);     (2)控制器:負責從存儲器取出一條指令,并指出下一條指…

    Linux干貨 2016-08-15
  • linux安全機制與加密工具使用

    一、加密需要和安全機制 1.不加密流量的易受攻擊性 密碼/數據嗅探 數據操作 驗證操作 相當于郵寄明信片 2.不安全的傳統協議 telnet、FTP、POP3等等;不安全密碼http、sendmail、NFS等等;不安全信息Ldap、NIS、rsh等等;不安全驗證 3.NIST定義的安全屬性:美國國家標準與技術研究院 1) 保密性:  &…

    Linux干貨 2016-09-25
  • Linux文件系統總結(7.4課上作業)

    一、什么是文件系統         文件系統是對一個存儲設備上的數據和元數據進行組織的機制。它使用文件和樹形目錄的抽象邏輯概念代替了硬盤和光盤等物理設備使用的數據塊的概念,用戶使用文件系統來保存數據而不必關心數據實際保存在硬盤(or光盤)的地址為多少數據塊上,只需要記住這個文件的…

    Linux干貨 2016-07-10
  • 正則表達式練習

       grep練習  : 1 、顯示/proc/meminfo 文件中以大小s 開頭的行:  2 、顯示/etc/passwd 文件中不以/bin/bash 結尾的行      3 、顯示用戶rpc 默認的shell        4 、找出/etc…

    Linux干貨 2016-08-10
  • 計算機網絡基礎知識與Linux網絡配置

    本文主要內容是: 1.講述網橋、集線器、二層交換機、三層交換機、路由器的功能、使用場景與區別。 2、IP地址的分類有哪些?子網掩碼的表示形式及其作用 3、計算機網絡的分成模型有哪些(OSI模型和TCP/IP模型),每一層的功能及涉及到的物理設備有哪些。 4、如何給網絡接口配置多個地址,有哪些方式? 5、常用的網絡管理類工具有哪些,并用示例形式描述他們的使用方…

    Linux干貨 2016-11-14
欧美性久久久久