Linux磁盤管理

一、磁盤管理總體分類 

1)磁盤結構 

2)分區類型 

3)管理分區

4)管理文件系統 

5)掛載設備

6)管理虛擬內存

………………………………………………………………………………………………………………………

重要分類模塊詳解

………………………………………………………………………………………………………………………

1、磁盤常用術語

head:磁頭    track:磁道    sector:扇區    cylinder:柱面  


2、分區種類 

1)主引導記錄(MBR)

    MBR: Master Boot Record,1982年,使用32位表示扇區數,分區不超過2T如何分區:按柱面0磁道0扇區:512bytes 446bytes: boot loader 64bytes:分區表 16bytes: 標識一個分區 2bytes: 55AA 4個主分區;3主分區+1擴展(N個邏輯分區)

2)GPT 

    GPT:GUID patition table (GUID分區表) 支持128個分區,使用64位,支 持8Z( 512Byte/block )64Z ( 4096Byte/block)使用128位UUID 表示磁盤和分區 GPT分區表自動備份在頭 和尾兩份,并有CRC校驗位UEFI (統一擴展固件接口)硬件支持GPT

3、常用分區管理工具

lsblk命令:

    lsblk – list block devices

演示:

[root@centos6 ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0     11:0    1  3.7G  0 rom
sda      8:0    0  120G  0 disk
├─sda1   8:1    0  200M  0 part /boot
├─sda2   8:2    0   80G  0 part /
├─sda3   8:3    0   20G  0 part /testdir
├─sda4   8:4    0    1K  0 part
├─sda5   8:5    0    4G  0 part [SWAP]
└─sda6   8:6    0    5G  0 part
sdb      8:16   0  120G  0 disk
sdc      8:32   0   20G  0 disk
sdd      8:48   0   20G  0 disk
sde      8:64   0   20G  0 disk
[root@centos6 ~]#

fdisk命令:

     fdisk – Partition table manipulator for Linux

     fdisk -cu device  fdisk device 

    常用子命令: 

   d   delete a partition  #刪除分區表

   l   list known partition types #列出分區類型

   m   print this menu    #打印幫助信息

   n   add a new partition #添加一個新的分區

   p   print the partition table #打印分區表

   q   quit without saving changes #不保存退出

   t   change a partition's system id #改變一個分區的系統ID

   w   write table to disk and exit #將分區表寫入系統


partx/partprobe命令:通知內核重新讀取硬盤分區表信息

   partx -a /dev/device 例如:partx -a /dev/sda1 

   kpartx -a /dev/device -f:force 

   刪除分區:

    partx -d –nr # /dev/device #號表示刪除的第幾塊分區    

    partx -d –nr 7 /dev/sda

   CentOS5.x CentOS7.x使用:partprobe命令即可  

    查看內核是否已經識別新的分區:cat /proc/partitations 

………………………………………………………………………………………………………………………

演示:

………………………………………………………………………………………………………………………

[root@centos6 ~]# fdisk -l /dev/sda
Disk /dev/sda: 128.8 GB, 128849018880 bytes
255 heads, 63 sectors/track, 15665 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: 0x000813f2
   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       10469    83886080   83  Linux
/dev/sda3           10469       13080    20971520   83  Linux
/dev/sda4           13080       15666    20765696    5  Extended
/dev/sda5           13081       13603     4194304   82  Linux swap / Solaris
/dev/sda6           13604       13865     2104515   83  Linux
/dev/sda7           13866       13997     1060258+  83  Linux
[root@centos6 ~]# cat /proc/partitions
major minor  #blocks  name
   8        0  125829120 sda
   8        1     204800 sda1
   8        2   83886080 sda2
   8        3   20971520 sda3
   8        4          1 sda4
   8        5    4194304 sda5
   8       16  125829120 sdb
   8       32   20971520 sdc
   8       48   20971520 sdd
   8       64   20971520 sde
[root@centos6 ~]# partx -a /dev/sda
sda   sda1  sda2  sda3  sda4  sda5
[root@centos6 ~]# partx -a /dev/sda
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
BLKPG: Device or resource busy
error adding partition 5
[root@centos6 ~]# partx -a /dev/sda
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
BLKPG: Device or resource busy
error adding partition 5
BLKPG: Device or resource busy
error adding partition 6
BLKPG: Device or resource busy
error adding partition 7
[root@centos6 ~]# !cat
cat /proc/partitions
major minor  #blocks  name
   8        0  125829120 sda
   8        1     204800 sda1
   8        2   83886080 sda2
   8        3   20971520 sda3
   8        4          1 sda4
   8        5    4194304 sda5
   8        6    2104515 sda6
   8        7    1060258 sda7
   8       16  125829120 sdb
   8       32   20971520 sdc
   8       48   20971520 sdd
   8       64   20971520 sde
[root@centos6 ~]#

………………………………………………………………………………………………………………………

二、創建文件系統

mkfs命令:創建一個linux文件系統

    mkfs – build a Linux file system 

用法:

    mkfs.fs_type /dev/device  #fs_type{ext4 xfs btrfs vfat}

    mkfs.fs_type /dev/device -L 'LABEL' #指定卷標  

………………………………………………………………………………………………………………………

演示:

[root@centos6 ~]# mkfs.ext4 /dev/sda6 -L 'MYDATE'
mke2fs 1.41.12 (17-May-2010)
文件系統標簽=MYDATE
操作系統:Linux
塊大小=4096 (log=2)
分塊大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
131648 inodes, 526128 blocks
26306 blocks (5.00%) reserved for the super user
第一個數據塊=0
Maximum filesystem blocks=541065216
17 block groups
32768 blocks per group, 32768 fragments per group
7744 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
正在寫入inode表: 完成
Creating journal (16384 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 27 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@centos6 ~]# blkdi
-bash: blkdi: command not found
[root@centos6 ~]# blkid
/dev/sda2: UUID="240533cf-b37f-4460-974f-702bab867da5" TYPE="ext4"
/dev/sda1: UUID="4e245c68-a392-4ce9-9a99-5d32d8d43872" TYPE="ext4"
/dev/sda3: UUID="86aa7b74-24df-4043-ba83-f3b41a99ce0e" TYPE="ext4"
/dev/sda5: UUID="f8ef48ef-b141-48e5-9735-ff9089bd54ba" TYPE="swap"
/dev/sda6: UUID="b153fa9a-5b82-4bbc-b580-9170ab88b4a6" TYPE="ext4" LABEL="MYDATE"
[root@centos6 ~]#

………………………………………………………………………………………………

mke2fs命令:創建ext系列文件系統

    mke2fs – create an ext2/ext3/ext4 filesystem

選項:

    -t{ext2|ext3|ext4} #指定文件類型

    -b{1024|2048|4096} #指定塊大小

    -L 'LABEL' #指定卷標

    -j #相當于mke2fs -t ext3,mkfs.ext3 = mkfs -t ext3 = mke2fs -j = mke2fs -t ext3 

    -i #: 為數據空間中每多少個字節創建一個inode;此大 小不應該小于block的大小 

    -N #: 為數據空間創建杜少而過inode   

    -m #: 為管理員預留的空間占總空間的百分比,默認為5%


blkid命令: 

     blkid – command-line utility to locate/print block device attributes

選項: 

    -U:UUID #按UUID來查找到相應的設備

    -L:LABEL #按卷標查找到相應的設備名       

e2label命令: 

    用法:e2label device LABEL 

          e2lable deveice   


tune2fs命令:重新設定文件系統的超級塊可調參數的屬性值  

 選項: 

     -L 'LABEL':修改卷標

     -j 將ext2升級到ext3   

     -o 調整文件系統掛載選項,acl,取消為^acl   

     -m #:修預留給管理員的空間百分比                


dumpe2fs命令: 

     -h:查看超級塊信息(分組信息),分區用分組管理

    例如:dumpe2fs -h /dev/sda8   tune2fs -l /dev/sda8   


文件修復和檢測: 

常發生于死機或者非正常關機之后,常發生于死機或者非正常關機之后 

fsck: File System 

Check fsck.FS_TYPE 

fsck -t FS_TYPE 


演示:

………………………………………………………………………………………………

[root@centos6 ~]# mke2fs -t ext4 -b 2048 -L 'MAN' -m 1 /dev/sda8
mke2fs 1.41.12 (17-May-2010)
文件系統標簽=MAN
操作系統:Linux
塊大小=2048 (log=1)
分塊大小=2048 (log=1)
Stride=0 blocks, Stripe width=0 blocks
804864 inodes, 6438032 blocks
64380 blocks (1.00%) reserved for the super user
第一個數據塊=0
Maximum filesystem blocks=544210944
393 block groups
16384 blocks per group, 16384 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816, 1327104,
2048000, 3981312, 5619712
正在寫入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 30 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@centos6 ~]# mount /dev/sda8 /mnt
[root@centos6 ~]# tune2fs -l  /dev/sda8
tune2fs 1.41.12 (17-May-2010)
Filesystem volume name:   MAN
Last mounted on:          <not available>
Filesystem UUID:          8528b2b5-4dc3-48c9-91f5-a0d096442b36
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize
Filesystem flags:         signed_directory_hash
Default mount options:    (none)
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              804864
Block count:              6438032
Reserved block count:     64380
Free blocks:              6297100
Free inodes:              804853
First block:              0
Block size:               2048
Fragment size:            2048
Reserved GDT blocks:      512
Blocks per group:         16384
Fragments per group:      16384
Inodes per group:         2048
Inode blocks per group:   256
Flex block group size:    16
Filesystem created:       Mon Aug 22 22:43:55 2016
Last mount time:          Mon Aug 22 22:44:44 2016
Last write time:          Mon Aug 22 22:44:44 2016
Mount count:              1
Maximum mount count:      30
Last checked:             Mon Aug 22 22:43:55 2016
Check interval:           15552000 (6 months)
Next check after:         Sat Feb 18 22:43:55 2017
Lifetime writes:          262 MB
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:          256
Required extra isize:     28
Desired extra isize:      28
Journal inode:            8
Default directory hash:   half_md4
Directory Hash Seed:      c5fdca9f-fd8e-4a75-8301-39a64f0e9f3c
Journal backup:           inode blocks
[root@centos6 ~]# blkid /dev/sda8
/dev/sda8: LABEL="MAN" UUID="8528b2b5-4dc3-48c9-91f5-a0d096442b36" TYPE="ext4"
[root@centos6 ~]# blkid -U "8528b2b5-4dc3-48c9-91f5-a0d096442b36"
/dev/sda8
[root@centos6 ~]# blkid -L MAN
/dev/sda8
[root@centos6 ~]#
[root@centos6 ~]# e2label /dev/sda8 HUMAN
[root@centos6 ~]# e2label /dev/sda8
HUMAN
[root@centos6 ~]# tune2fs -L 'BABY'  /dev/sda8
tune2fs 1.41.12 (17-May-2010)
[root@centos6 ~]# tune2fs -o acl /dev/sda8
tune2fs 1.41.12 (17-May-2010)
[root@centos6 ~]# tune2fs -l /dev/sda8
tune2fs 1.41.12 (17-May-2010)
Filesystem volume name:   BABY
Last mounted on:          <not available>
Filesystem UUID:          8528b2b5-4dc3-48c9-91f5-a0d096442b36
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize
Filesystem flags:         signed_directory_hash
Default mount options:    acl
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              804864
Block count:              6438032
Reserved block count:     64380
Free blocks:              6297100
Free inodes:              804853
First block:              0
Block size:               2048
Fragment size:            2048
Reserved GDT blocks:      512
Blocks per group:         16384
Fragments per group:      16384
Inodes per group:         2048
Inode blocks per group:   256
Flex block group size:    16
Filesystem created:       Mon Aug 22 22:43:55 2016
Last mount time:          Mon Aug 22 22:44:44 2016
Last write time:          Mon Aug 22 23:01:13 2016
Mount count:              1
Maximum mount count:      30
Last checked:             Mon Aug 22 22:43:55 2016
Check interval:           15552000 (6 months)
Next check after:         Sat Feb 18 22:43:55 2017
Lifetime writes:          262 MB
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:	          256
Required extra isize:     28
Desired extra isize:      28
Journal inode:            8
Default directory hash:   half_md4
Directory Hash Seed:      c5fdca9f-fd8e-4a75-8301-39a64f0e9f3c
Journal backup:           inode blocks
[root@centos6 ~]# tune2fs -m 5 /dev/sda8
tune2fs 1.41.12 (17-May-2010)
Setting reserved blocks percentage to 5% (321901 blocks)
[root@centos6 ~]# tune2fs -l /dev/sda8

………………………………………………………………………………………………

三、掛載文件系統 

mount命令:   

用法: 

    mount DEVICE MOUNT_POINT 

    mount [-fnrsvw] [-t vfstype] [-o options] device dir 

掛載方式:

1)設備文件 例如:mount /dev/sda5 /mnt 

2)卷標 例如:mount -L 'MYDATE' /mnt  

3)UUID 例如:mount -U '40d51666-7a52-4613-bac9-0a1f27afeee8'/mnt   

    選項: 

    -t:指定文件類型 

    -r:只讀掛載

    -w:讀寫掛載 

    -n:不更新/etc/mtab   

    -a:自定掛載/etc/fstab定義的設備

    -L:卷標   

    -U:uuid 

    -B:綁定目錄到另一個目錄上 

查看內核最終到的掛載的所有設備:cat /proc/mounts 

-o options:(掛載文件系統的選項),多個選項使用逗號分隔 async:異步模式 sync:同步模式,內存更改時,同時寫磁盤 atime/noatime:包含目錄和文件 diratime/nodiratime:目錄的訪問時間戳 auto/noauto:是否支持自動掛載,是否支持-a選項 exec/noexec:是否支持將文件系統上運行應用程序 dev/nodev:是否支持在此文件系統上使用設備文件 suid/nosuid:不否支持suid和sgid權限 remount:重新掛載 ro:只讀 rw:讀寫 user/nouser:是否允許普通用戶掛載此設備,默認管理員才能掛載 acl:啟用此文件系統上的acl功能  Defaults:相當于rw, nosuid, dev, exec, auto, nouser, async


umount命令: 

    umount  DEVICE  

    umount MOUNT_POINT    

    

………………………………………………………………………………………………

四、掛載至配置文件

/etc/fstab 每行定義一個要掛載的文件系統說明

[root@centos6 ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Thu Aug 11 03:07:57 2016
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=240533cf-b37f-4460-974f-702bab867da5 /            ext4    defaults        1 1
UUID=4e245c68-a392-4ce9-9a99-5d32d8d43872 /boot          ext4    defaults        1 2
UUID=86aa7b74-24df-4043-ba83-f3b41a99ce0e /testdir         ext4    defaults        1 2
UUID=f8ef48ef-b141-48e5-9735-ff9089bd54ba swap           swap    defaults        0 0
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
#要掛載的設備或為文件系統         #掛載點         #文件類型   #選項             #轉儲 #自檢                  
[root@centos6 ~

………………………………………………………………………………………………

本文出自小耳朵,小編乏了,洪荒之力已用完,覺得文章還可以記得點贊哦:)!!!

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

(0)
alrenalren
上一篇 2016-08-29 08:49
下一篇 2016-08-29 08:52

相關推薦

  • 第十七周 作業–結合圖形描述lvs原理

        LVS是Linux Virtual Server的簡寫,意即Linux虛擬服務器,是一個虛擬的服務器集群系統。本項目在1998年5月由章文嵩博士成立,是中國國內最早出現的自由軟件項目之一。   Lvs有三種模式分別是lvs-nat、lvs-dr、lvs-tun。下面分別介紹lvs-nat、lvs-dr…

    Linux干貨 2016-12-07
  • 批量部署lxc虛擬機

    前言:lxc是一種操作系統層虛擬化(Operating system–level virtualization)技術,為Linux內核容器功能的一個用戶空間接口。它將應用軟件系統打包成一個軟件容器(Container),內含應用軟件本身的代碼,以及所需要的操作系統核心和庫。通過統一的命名空間和共用API來分配不同軟件容器的可用硬件資源,創造出應用程…

    Linux干貨 2016-03-20
  • 2016年8月6日作業練習

    練習: 1、顯示/proc/meminfo文件中以大小s開頭的行;(要求:使用兩種方式) [root@localhost ~]# grep -i "^[sS]" /proc/meminfo SwapCached:      &nb…

    Linux干貨 2016-08-07
  • awk學習筆記

    一、linux的文本處理器三劍客   文本過濾器:grep、egrep、fgrep   行編輯器:sed(模式空間;保持空間)   報表生成器:awk(格式化文本輸出)gawk awk的工作流程: 從文本中讀取一行內容,根據指定的分隔符;將讀入的一行內容分隔成字段,然后格式化輸出指定的字段 二、awk的命令相關的參數及用法 &n…

    Linux干貨 2015-06-23
  • Linux文本處理三劍客之一grep

            終于又到了一周一篇博客的日子 在這學習已經三周了,慢慢養成了寫博客的好習慣,也慢慢的懂得了怎么寫博客。這周給我印象最深刻的就是正則表達式,原本打算要寫前幾天所學的內容,但是昨天學到正則表達式讓我有點懵,所以我今天會用一天的時間去給大家詳細講解正則表達式,爭取讓那些和我一樣困解的人能夠豁然開朗,也正是因為…

    2017-07-29
  • 第二周博客作業

    1.Linux上的文件管理類命令都有那些,其常用的使用方法及其相關示例演示。
    2.Bash的工作特性之命令執行狀態返回值和命令行展開所涉及的內容及其示例演示。
    3.請使用命令行展開功能來完成以下的練習。
    4.文件的元數據信息有哪些,分別表示什么含義,如何查看?如何修改文件的時間戳信息。
    5.如何定義一個命令的別名,如何在命令中引用另一個命令的執行結果?
    6.顯示/var目錄下所有以1開頭,以一個小寫字母結尾,且中間至少出現一位數字(可以有其他字符)的文件或目錄。
    7.顯示/etc目錄下,以任意一個數字開頭,且以非數字結尾的文件或目錄。
    8.顯示/etc目錄下,以非字母開頭,后面跟了一個字母以及其他任意長度任意字符的文件或目錄。
    9.在/tmp目錄下創建以tgile開頭,后跟當前日期和時間的文件,文件名形如:tfile-2016-05-27-09-32-22
    10.復制/etc目錄下所有以p開頭,以非數字結尾的文件或目錄到/tmp/mytest1目錄中。
    11.復制/etc目錄下所有以.d結尾的文件或目錄到/tmp/mytest2目錄中。
    12.復制/etc目錄下所有以l或m或n開頭,以.conf結尾的文件至/tmp/mytest3目錄中。

    2018-03-22
欧美性久久久久