Linux磁盘挂载

  1. 作者QQ:67065435 QQ群:821635552

  2. 本站内容全部为作者原创,转载请注明出处!

注意事项

  1. 假设挂载点为/www

  2. 假设磁盘为/dev/vdc

  3. 假设磁盘只有卷/dev/vdc1

  4. 该方案可能会丢失磁盘所有数据,操作前请先备份

磁盘挂载

磁盘已格式化(用过的磁盘)

  1. 磁盘立即挂载

    mkdir /www
    mount /dev/vdc1 /www
    
  2. 启用开机挂载

    # 获取磁盘ID
    ll /dev/disk/by-path
    
    # lrwxrwxrwx. 1 root root  9 Dec  2 00:25 xxxxxxxxxxxxxxxxxxxxxxxx1 -> ../../sda
    # lrwxrwxrwx. 1 root root  9 Dec  2 00:25 xxxxxxxxxxxxxxxxxxxxxxxx1-part1 -> ../../sda1
    # lrwxrwxrwx. 1 root root  9 Dec  2 00:25 xxxxxxxxxxxxxxxxxxxxxxxx2 -> ../../vdc
    # lrwxrwxrwx. 1 root root  9 Dec  2 00:25 xxxxxxxxxxxxxxxxxxxxxxxx2-part1 -> ../../vdc1
    # 可以看出磁盘/dev/vdc1的ID为
    # /dev/disk/by-path/xxxxxxxxxxxxxxxxxxxxxxxx2-part1
    
    # 开机挂载磁盘(根据磁盘id挂载)
    echo "/dev/disk/by-path/xxxxxxxxxxxxxxxxxxxxxxxx2-part1 /www ext4 defaults 0 0" >> /etc/fstab
    

磁盘未格式化(全新的磁盘)

  1. 磁盘进行分区

    fdisk /dev/vdc
    # 下面是执行过程
    Command(m for help): n(回车)
    
    Partition type:
       p   primary (0 primary, 0 extended, 4 free)
       e   extended
    Select (default p): p(回车)
    
    Partition number (1-4): 1(回车)
    
    First cylinder(2048-xxxxxxxx,default 2048):(回车)
    
    Last cylinder(2048-xxxxxxxx,default xxxxxxxx):(回车)
    
    Command(m for help): wq(回车)
    
  2. 分区错误处理

    # 如果上一步遇到【Partition table entries are not in disk order】错误
    # 则按以下步骤修复磁盘
    fdisk /dev/vdc
    Command(m for help): x(专家模式)
    Command(m for help): f(修复分区)
    Command(m for help): wq(保存分区)
    
  3. 格式化磁盘

    mkfs.ext4 /dev/vdc1
    Writing superblocks and filesystem accounting information:(回车)
    
  4. 磁盘立即挂载

    mkdir /www
    mount /dev/vdc1 /www
    
  5. 启用开机挂载

    # 获取磁盘ID
    ll /dev/disk/by-path
    
    # lrwxrwxrwx. 1 root root  9 Dec  2 00:25 xxxxxxxxxxxxxxxxxxxxxxxx1 -> ../../sda
    # lrwxrwxrwx. 1 root root  9 Dec  2 00:25 xxxxxxxxxxxxxxxxxxxxxxxx1-part1 -> ../../sda1
    # lrwxrwxrwx. 1 root root  9 Dec  2 00:25 xxxxxxxxxxxxxxxxxxxxxxxx2 -> ../../vdc
    # lrwxrwxrwx. 1 root root  9 Dec  2 00:25 xxxxxxxxxxxxxxxxxxxxxxxx2-part1 -> ../../vdc1
    # 可以看出磁盘/dev/vdc1的ID为
    # /dev/disk/by-path/xxxxxxxxxxxxxxxxxxxxxxxx2-part1
    
    # 开机磁盘挂载(根据磁盘id挂载)
    echo "/dev/disk/by-path/xxxxxxxxxxxxxxxxxxxxxxxx2-part1 /www ext4 defaults 0 0" >> /etc/fstab
    

取消挂载

  1. 安装psmisc

    yum install psmisc -y
    
  2. 解除目录占用

    fuser -k /www
    
  3. 取消磁盘挂载

    umount /dev/vdc1
    
  4. 取消开机挂载

    vim /etc/fstab
    
    # 删除挂载/www目录的那一行
    /dev/disk/by-path/xxxxxxxxxxxxxxxxxxxxxxxx2-part1 /www ext4 defaults 0 0
    
    ESC
    :wq
    

参考链接

  1. 开机挂载

  2. 新增挂载

  3. 移动磁盘

  4. 分区类型

  5. 扩容MBR

  6. 扩容GPT

Copyright © 豆包嘿嘿~ 2012-∞ 冀ICP备17033181号 all right reserved,powered by Gitbook修订: 2020-08-19 14:05:41

results matching ""

    No results matching ""