天天看點

CentOS7.X磁盤挂載及取消挂載

磁盤挂載及取消

磁盤挂載

  1. 檢視已經挂載磁盤數
    cat /proc/scsi/scsi | grep Host
    Host:   scsi1         Channel: 00 Id: 00 Lun: 00
    Host:   scsi2         Channel: 00 Id: 00 Lun: 00
    # 或者
    ll /dev/disk/by-path | grep -v part
    lrwxrwxrwx. 1 root root  9 Dec  2 00:25 pci-0000:00:1f.2-ata-2.0 -> ../../sda
    lrwxrwxrwx. 1 root root  9 Dec  2 00:25 pci-0000:00:1f.2-ata-2.0 -> ../../sdb           
  2. 判斷磁盤名
    ll /dev/disk/by-path/
    取到了'../../sdb',
    則磁盤名為:/dev/disk/by-path/../../sdb,即 /dev/sdb           
  3. 删除/dev/sdb所有分區
    fdisk /dev/sdb
    Command (m for help): p(檢視目前分區狀态)
    Command (m for help): d(删除分區)
    Partition number (1-3): 3(選擇要删除的分區)
    Command (m for help): d(删除分區)
    Partition number (1-2): 2(選擇要删除的分區)
    Command (m for help): d(因為隻剩下一個分區,無需選擇直接删除)
    Command (m for help): p(檢視目前分區狀态)
    Command (m for help): w(回車儲存新的分區)           
  4. 格式化磁盤
    fdisk /dev/sdb
    Command(m for help): n(回車建立分區)
    p primary partition(1-4): p(回車建立主分區)
    Partition number (1-4): 1(分區号1-4之間選擇1)
    First cylinder(2048-xxxxx,default 2048):(開始柱面 回車預設選擇最小值)
    Last cylinder(2048-xxxxx,default xxxxx):(結束柱面 選擇上一步中的xxxxx)
    Command(m for help): p(檢視調整後分區表)
    Command(m for help): w(回車儲存新的分區)           
  5. 如果提示“Partition table entries are not in disk order”則執行
    fdisk /dev/sdb
    Command(m for help): x(進入專家模式)
    Command(m for help): f(修複分區表)
    Command(m for help): p(檢視調整後分區表)
    Command(m for help): w(回車儲存新的分區)           
  6. 建立磁盤分區
    mkfs.ext4 /dev/sdb1
    Writing superblocks and filesystem accounting information:(回車)           
  7. 挂載分區中的磁盤到目錄/file1
    # 建立目錄/file1
    # 挂載/dev/sdb1 到目錄 /file1
    mkdir /file1
    mount /dev/sdb1 /file1           
  8. 将挂載資訊寫入fstab,讓系統自動挂載
    # 參數說明
    裝置名: /dev/sdb1(一個磁盤分區)
    挂載點: /file1(系統上的一個目錄)
    裝置類型: ext4(可通過'man fstab'查詢支援類型)
    挂載參數: defaults(參數預設即可)
    dump-freq: 0
    pass-num: 0
    echo "/dev/sdb1 /file1 ext4 defaults 0 0" >> /etc/fstab           
  9. 檢視挂載寫入情況
    cat /etc/fstab           

取消挂載

  1. 安裝psmisc
    yum install psmisc -y           
  2. 取消目錄占用
    fuser -k /file1
    fuser -k /dev/sdb1           
  3. 取消挂載點
    umount /file1
    umount /dev/sdb1           
  4. fdisk /dev/sdb
    Command (m for help): p(檢視目前分區狀态)
    Command (m for help): d(删除分區)
    Partition number (1-2): 1(選擇要删除的分區)
    Command (m for help): d(删除分區)
    Partition number (1-2): 2(選擇要删除的分區)
    Command (m for help): p(檢視目前分區狀态)
    Command (m for help): w(回車儲存新的分區)           
  5. 領支付寶紅包支援作者

繼續閱讀