26day磁盤管理體

5.1MBR

含義

    Master Boot Record  主引導(dǎo)記錄
    
位置

    磁盤的開頭
    
    0磁頭 0磁道 1扇區(qū) 512字節(jié)前446字節(jié)
    
    0頭 0道 1扇區(qū) 512字節(jié)前446字節(jié)

5.2 分區(qū)類型(關(guān)系)

5.2.1主分區(qū)

    primary
    1個主分區(qū)要占用16個字節(jié)分區(qū)表
    在一個磁盤中 最多有4個主分區(qū)
    一般必須有
5.2.2擴(kuò)展分區(qū)
    extended
    磁盤最多只有四個分區(qū)
    擴(kuò)展分區(qū)無法直接使用
    1個主分區(qū)要占用16個字節(jié)分區(qū)表
    一個磁盤只能創(chuàng)建一個擴(kuò)展分區(qū)
    數(shù)據(jù)必須放在擴(kuò)展分區(qū)的邏輯分區(qū)
5.2.3邏輯分區(qū)
    logic al
    需要先創(chuàng)建擴(kuò)展分區(qū)
    存放數(shù)據(jù)
    11個最多

5.3分區(qū)的命名規(guī)則

5.3.1硬盤的名字
    sata/sas/scsi
        /dev/sd??
        第一塊硬盤
            /dev/sda
            /
        第四塊硬盤
            /dev/sdd
    云服務(wù)器(阿里云)
        /dev/vda
        /dev/vdb
5.3.2分區(qū)的名字
    主分區(qū)或擴(kuò)展分區(qū)
        1-4
        /dev/sda1
    邏輯分區(qū)
        從5開始(>=5)
        /sdv/sda5
5.3.3習(xí)題
    第3塊sata磁盤的第2個主分區(qū)

        /sdv/sdc2  
    第6塊sas磁盤的第2個邏輯分區(qū)
          /sdv/sdf6

5.4分區(qū)實戰(zhàn)

5.4.1分區(qū)命令
    fdisk
        -l 查看磁盤的分區(qū)的信息(小寫字母L)
        fdisk內(nèi)部信息
            p
                print 顯示磁盤分區(qū)信息
            n
                new 創(chuàng)建分區(qū)
            d
                delete 刪除磁盤分區(qū)
            w
                write 保存并退出
            q或ctrl+c
                退出不保存
            t
                改變分區(qū)類型
    parted
5.4.2創(chuàng)建2個分區(qū)1個10MB的主分區(qū)

創(chuàng)建一個使用所有剩余空間的擴(kuò)展 

分區(qū) 1個20MB的邏輯分區(qū)

5.4.3 創(chuàng)建1個使用磁盤所有容量的分區(qū)如/dev/sdb 并掛載到/mnt上

    #第一個里程碑-創(chuàng)建分區(qū)
    
        fdisk
        
        保存
        
    #第二個里程碑-格式化 創(chuàng)建文件系統(tǒng)
    
        mkfs.xfs
        
    #創(chuàng)建弟3個里程碑-掛載
    
        卸載umount  /mnt
        
        臨時掛載
        
            mount /dev/sbd1/mnt
            
                掛載
                
        永久掛載
        
            方法1
            
                /etc/rc/local
                
            方法2
            
                /etc/fstab
                
                    自動掛載
```



查看磁盤
    [root@oldboyedu59 ~]# fdisk -l |grep 'sd[a-z]:'
Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 sectors

Disk /dev/sdb: 106 MB, 106954752 bytes, 208896 sectors

Disk /dev/sdc: 106 MB, 106954752 bytes, 208896 sectors

Disk /dev/sdd: 3221.2 GB, 3221225472000 bytes, 6291456000 sectors
Changes will remain in memory only, until you decide to write them.

你進(jìn)行的修改默認(rèn)存放在內(nèi)存中,直到你決定保存這些修改的時候.
:wq
保存退出

Be careful before using the write command.

保存之前小心點!

Device does not contain a recognized partition table

設(shè)備 沒有 包含 磁盤分區(qū)表。

Building a new DOS disklabel with disk identifier 0x6df46197.

用磁盤標(biāo)識符0x6df46197構(gòu)建一個新的DOS磁盤標(biāo)簽。

DPT= disk  partition table  

磁盤分區(qū)表

Invalid partition type `e'

分區(qū)類型無效

mkfs.xfs /dev/sdb1
mkfs.xfs: /dev/sdb1 appears to contain an existing filesystem (ext4).

這個磁盤分區(qū)中 已經(jīng)包含了1個文件系統(tǒng)(已經(jīng)格式化過了)

mkfs.xfs: Use the -f option to force overwrite.

如果強(qiáng)制格式化使用-f

[root@cuihua ~]# mount /dev/sdb1 /mnt
mount: /dev/sdb1 is write-protected, mounting read-only
mount: unknown filesystem type '(null)'
   未知的文件系統(tǒng)(沒有格式化)
[root@guanggege ~]# mount  /dev/sdb1  /mnt/
mount: special device /dev/sdb1 does not exist

特殊文件(設(shè)備文件) 不存在

[root@oldboyedu59 ~]# mkfs.xfs  /dev/sdb1 
mkfs.xfs: /dev/sdb1 contains a mounted filesystem

sdb1磁盤分區(qū) 包含 1個已經(jīng)掛載的文件系統(tǒng) (磁盤分區(qū)已經(jīng)掛載)

Usage: mkfs.xfs

/* blocksize */     [-b log=n|size=num]

/* metadata */      [-m crc=0|1,finobt=0|1,uuid=xxx]

/* data subvol */   [-d agcount=n,agsize=n,file,name=xxx,size=num,

                (sunit=value,swidth=value|su=num,sw=num|noalign),
                
                sectlog=n|sectsize=num
                
/* force overwrite */   [-f]

/* inode size */    [-i log=n|perblock=n|size=num,maxpct=n,attr=0|1|2,

                projid32bit=0|1]
                
/* no discard */    [-K]

/* log subvol */    [-l agnum=n,internal,size=num,logdev=xxx,version=n

                sunit=value|su=num,sectlog=n|sectsize=num,
                
                lazy-count=0|1]
/* label */     [-L label (maximum 12 characters)]

/* naming */        [-n log=n|size=num,version=2|ci,ftype=0|1]

/* no-op info only */   [-N]

/* prototype file */    [-p fname]

/* quiet */     [-q]

/* realtime subvol */   [-r extsize=num,size=num,rtdev=xxx]

/* sectorsize */    [-s log=n|size=num]

/* version */       [-V]

            devicename
<devicename> is required unless -d name=xxx is given.

<num> is xxx (bytes), xxxs (sectors), xxxb (fs blocks), xxxk (xxx KiB),

      xxxm (xxx MiB), xxxg (xxx GiB), xxxt (xxx TiB) or xxxp (xxx PiB).
<value> is xxx (512 byte blocks).
7. [root@oldboy ~]# mkfs.xfs /dev/sdb1 -f
agsize (2560 blocks) too small, need at least 4096 blocks
                磁盤分區(qū)太小了 無法格式化 

Usage: mkfs.xfs

[root@oldboyedu ~]# mount /dev/sdb1 /mnt/
mount: /dev/sdb1 is already mounted or /mnt busy

磁盤分區(qū) 已經(jīng) 掛載或/mnt

/dev/sdb1 is already mounted on /mnt

Command (m for help): p                                  

Disk /dev/sdb: 106 MB, 106954752 bytes, 208896 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: 0x6df46197

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n

Partition type:

   p   primary (0 primary, 0 extended, 4 free)  
   
       主分區(qū) 
       
   e   extended、
   
       擴(kuò)展分區(qū) 
       
Select (default p): 

         默認(rèn)就是 p 
Partition number (1-4, default 1):       
分區(qū)號                 默認(rèn) 

First sector (2048-208895, default 2048): 
磁盤分區(qū)中第1個扇區(qū)(從哪里開始)   默認(rèn) 

Using default value 2048

Last sector, +sectors or +size{K,M,G} (2048-208895, default 208895): 

磁盤分區(qū)中最后1個扇區(qū) 

Last sector, +sectors or +size{K,M,G} (2048-208895, default 208895): +10M

Partition 1 of type Linux and of size 10 MiB is set

創(chuàng)建了分區(qū)號是1的 10MB的分區(qū) 

Command (m for help): p

Disk /dev/sdb: 106 MB, 106954752 bytes, 208896 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: 0x6df46197


   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048       22527       10240   83  Linux

10MB 

Command (m for help): n

Partition type:

   p   primary (1 primary, 0 extended, 3 free)
   
   e   extended
   
Select (default p): e

Partition number (2-4, default 2): 

First sector (22528-208895, default 22528): 

Using default value 22528

Last sector, +sectors or +size{K,M,G} (22528-208895, default 208895): 

Using default value 208895

Partition 2 of type Extended and of size 91 MiB is set

Command (m for help): n

Partition type:

   p   primary (1 primary, 1 extended, 2 free)
   
   l   logical (numbered from 5)
   
Select (default p): e

Invalid partition type `e'

Command (m for help): n

Partition type:

   p   primary (1 primary, 1 extended, 2 free)
   
   l   logical (numbered from 5)
   
Select (default p): l

Adding logical partition 5

First sector (24576-208895, default 24576): 

Using default value 24576

Last sector, +sectors or +size{K,M,G} (24576-208895, default 208895): +20M

Partition 5 of type Linux and of size 20 MiB is set

Command (m for help): p

Disk /dev/sdb: 106 MB, 106954752 bytes, 208896 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: 0x6df46197

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048       22527       10240   83  Linux
/dev/sdb2           22528      208895       93184    5  Extended
/dev/sdb5           24576       65535       20480   83  Linux

創(chuàng)建2個分區(qū) 1個10MB的主分區(qū) 創(chuàng)建1個使用所有剩余空間的擴(kuò)展 分區(qū) 1個20MB的邏輯分區(qū)

第1個里程碑-創(chuàng)建分區(qū)

Command (m for help): p

Disk /dev/sdb: 106 MB, 106954752 bytes, 208896 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: 0x6df46197

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n

Partition type:

   p   primary (0 primary, 0 extended, 4 free)
   
   e   extended
   
Select (default p): 

Using default response p

Partition number (1-4, default 1): 

First sector (2048-208895, default 2048): 

Using default value 2048

Last sector, +sectors or +size{K,M,G} (2048-208895, default 208895): 

Using default value 208895

Partition 1 of type Linux and of size 101 MiB is set

第2個里程碑-格式化 創(chuàng)建文件系統(tǒng) mkfs make filesystem

[root@oldboyedu59 ~]# mkfs.xfs /dev/sdb1 

meta-data=/dev/sdb1              isize=512    agcount=4, agsize=6464 blks

         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
         
data     =                       bsize=4096   blocks=25856, imaxpct=25

         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1

log      =internal log           bsize=4096   blocks=855, version=2

         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

第3個里程碑-掛載

[root@oldboyedu59 ~]# df -h

Filesystem      Size  Used Avail Use% Mounted on

/dev/sda3        99G  1.8G   97G   2% /

devtmpfs        980M     0  980M   0% /dev

tmpfs           991M     0  991M   0% /dev/shm

tmpfs           991M  9.6M  981M   1% /run

tmpfs           991M     0  991M   0% /sys/fs/cgroup

/dev/sda1       197M  105M   93M  54% /boot

tmpfs           199M     0  199M   0% /run/user/0

[root@oldboyedu59 ~]# mount /dev/sdb1  /mnt/

[root@oldboyedu59 ~]# df -h

Filesystem      Size  Used Avail Use% Mounted on

/dev/sda3        99G  1.8G   97G   2% /

devtmpfs        980M     0  980M   0% /dev

tmpfs           991M     0  991M   0% /dev/shm

tmpfs           991M  9.6M  981M   1% /run

tmpfs           991M     0  991M   0% /sys/fs/cgroup

/dev/sda1       197M  105M   93M  54% /boot

tmpfs           199M     0  199M   0% /run/user/0

/dev/sdb1        98M  5.3M   93M   6% /mnt

第4個里程碑-永久掛載

#1./etc/rc.local 

#2./etc/fstab 

[root@oldboyedu59 ~]# cat /etc/fstab 

UUID=1e827748-cc43-4b1d-8bbc-9a85c239782d /            xfs         defaults        0    0

UUID=29a4ef75-7502-48df-b31c-c7c10264a7c8 /boot        xfs         defaults        0    0

UUID=60c45f5e-c78d-41fe-aa92-93d10de6def3 swap         swap        defaults        0    0

第1列:UUID或設(shè)備名稱               第2列        第3列        第4列         第5列        第6列

查詢系統(tǒng)的磁盤與對應(yīng)的uuid          第2列  掛載點(入口) 第3列 文件系統(tǒng)類型  第4列  掛載參數(shù)    第5列 是否進(jìn)行備份     第6列是否開機(jī)自動檢查
[root@oldboyedu59 ~]# tail -1  /etc/fstab 

/dev/sdb1                                /data                    xfs     defaults        0 0


Welcome to emergency mode 歡迎進(jìn)入緊急模式/維護(hù)模式

磁盤故障或/etc/fstab

Give  root password for manintenance

給出root密碼進(jìn)入維護(hù)模式

(或按ctrl +d 繼續(xù) )




field 列 字段 域 
failed 失敗 

CentOS7    默認(rèn)的是xfs
CentOS6  5 默認(rèn) ext系列



      fdisk              parted 
共同 磁盤分區(qū)            磁盤分區(qū) 

區(qū)別 支持2TB以內(nèi)硬盤     大于2TB磁盤 

     支持MBR分區(qū)表       MBR GPT(支持更大的硬盤和更多的主分區(qū)) 


parted (實時生效)

p   print                                顯示磁盤信息

mktable  mklabel make partition table    創(chuàng)建磁盤分區(qū)表 MBR GPT

mkpart           make partition          創(chuàng)建磁盤分區(qū)

rm               刪除磁盤分區(qū) 

q                quit                    退出磁盤分區(qū) 

創(chuàng)建1個主分區(qū) 10M 

(parted) p                    

Error: /dev/sdc: unrecognised disk label   #無法識別的 

Model: VMware, VMware Virtual S (scsi)          

Disk /dev/sdc: 107MB

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

Partition Table: unknown                   #未知

Disk Flags: 

(parted) mktable gpt                      

(parted) p                             

Model: VMware, VMware Virtual S (scsi)

Disk /dev/sdc: 107MB

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

Partition Table: gpt

Disk Flags: 

Number  Start  End  Size  File system  Name  Flags

(parted) mkpart primary   0   10              

Warning: The resulting partition is not properly aligned for best performance.

Ignore/Cancel? i                                    

(parted) p                                      

Model: VMware, VMware Virtual S (scsi)

Disk /dev/sdc: 107MB

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

Partition Table: gpt

Disk Flags: 

Number  Start   End     Size    File system  Name     Flags
 1      17.4kB  10.0MB  9983kB               primary

primary 主分區(qū)

extended 擴(kuò)展分區(qū)

logical 邏輯分區(qū)

partition 分區(qū)

partition table 分區(qū)表

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容