ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

Linux分区挂载

2020-03-27 10:05:05  阅读:250  来源: 互联网

标签:分区 bytes dev Linux 挂载 512 1048575999 size


  1. 以root用户登录待挂载服务器。
  2. 查看磁盘情况。

    # fdisk -l

    系统显示如下类似信息:

    Disk /dev/vda: 500 GiB, 536870912000 bytes, 1048576000 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
    Disklabel type: dos
    Disk identifier: 0x00027c9e
     
    Device     Boot    Start      End  Sectors Size Id Type
    /dev/vda1  *        2048  2105343  2103296   1G 83 Linux
    /dev/vda2        2105344 18876415 16771072   8G 8e Linux LVM
    /dev/vda3       18876416 62914559 44038144  21G 8e Linux LVM
     
     
    Disk /dev/mapper/root-root: 21 GiB, 22540189696 bytes, 44023808 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 /dev/mapper/swap-swap: 8 GiB, 8581545984 bytes, 16760832 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

    上述示例,系统有一个空间500G的磁盘,盘符为/dev/vda,该磁盘已存在三个分区/dev/vda1(空间为1G)、/dev/vda2(空间为8G)、/dev/vda3(空间为21G)。则需将剩余的470G空间划分为两个分区。

  3. 对磁盘/dev/vda进行分区。

    # fdisk /dev/vda

    系统显示如下类似信息:

    1. 在提示信息后输入n,表示新建分区:
      Welcome to fdisk (util-linux 2.28).
      Changes will remain in memory only, until you decide to write them.
      Be careful before using the write command.
      
      Command (m for help): n
    2. 在提示信息后输入e,表示新建extend分区:
      Partition type
         p   primary (3 primary, 0 extended, 1 free)
         e   extended (container for logical partitions)
      
      Select (default e): e
      说明:

      操作系统默认划分4个primary分区,本示例只剩一个primary分区free。此时需先新建一个extend分区/dev/vda4,然后将该extend分区划分为两个logical分区/dev/vda5和/dev/vda6。

      如果磁盘小于等于两个primary分区,则可直接在此基础上再划分2个primary分区,即此处可选p

    3. 开始创建分区4。 在第二行后执行回车,表示选择分区4的起始位置接着上一分区的末尾;在第三行后执行回车,表示选择分区4的终止位置为/dev/vda磁盘的末尾。
      Selected partition 4
      First sector (62914560-1048575999, default 62914560):
      Last sector, +sectors or +size{K,M,G,T,P} (62914560-1048575999, default 1048575999): 
    4. 系统显示如下类似信息,创建的分区4大小为470G。继续输入n创建分区:
      Created a new partition 4 of type 'Extended' and of size 470 GiB
      
      Command (m for help): n
    5. 开始创建分区5。

      在第二行后执行回车,表示选择分区5的起始位置接着上一分区的末尾;在第三行后输入+200G,表示选择分区5的终止位置由起始位置开始偏移200G。

      All primary partitions are in use.
      Adding logical partition 5
      First sector (62916608-1048575999, default 62916608): 
      Last sector, +sectors or +size{K,M,G,T,P} (62916608-1048575999, default 1048575999): +200G
    6. 系统显示如下类似信息,创建的分区5大小为200G。继续输入n创建分区:
      Created a new partition 5 of type 'Linux' and of size 200 GiB.
      
      Command (m for help): n
    7. 开始创建分区6。

      在第二行后执行回车,表示选择分区6的起始位置接着上一分区的末尾;在第三行后执行回车,表示选择分区6的终止位置为/dev/vda磁盘的末尾。

      All primary partitions are in use.
      Adding logical partition 6
      First sector (482349056-1048575999, default 482349056): 
      Last sector, +sectors or +size{K,M,G,T,P} (482349056-1048575999, default 1048575999):
    8. 系统显示如下类似信息,创建的分区6大小为270G。输入p查看新建分区:
      Created a new partition 5 of type 'Linux' and of size 200 GiB.
      
      Command (m for help): p
    9. 系统显示如下类似信息,输入w保存新建分区:
      Disk /dev/vda: 500 GiB, 536870912000 bytes, 1048576000 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
      Disklabel type: dos
      Disk identifier: 0x00027c9e
      
      Device     Boot     Start        End   Sectors  Size Id Type
      /dev/vda1  *         2048    2105343   2103296    1G 83 Linux
      /dev/vda2         2105344   18876415  16771072    8G 8e Linux LVM
      /dev/vda3        18876416   62914559  44038144   21G 8e Linux LVM
      /dev/vda4        62914560 1048575999 985661440  470G  5 Extended
      /dev/vda5        62916608  482347007 419430400  200G 83 Linux
      /dev/vda6       482349056 1048575999 566226944  270G 83 Linux
      
      Command (m for help): w
      保存并退出新建分区模式,系统显示如下类似信息:
      The partition table has been altered.
      Calling ioctl() to re-read partition table.
      Re-reading the partition table failed.: Device or resource busy
       
      The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8)
  4. 通知系统分区表的变化。

    # partprobe

  5. 查看文件信息及类型。
    1. # file /dev/vda5 系统显示如下类似信息表示分区内容正确。
      /dev/vda5: block special (253/5)
    2. # file /dev/vda6 系统显示如下类似信息表示分区内容正确。
      /dev/vda5: block special (253/5)
      说明:

      如果信息显示异常,步骤2.通知系统分区表的变化。可尝试使用reboot命令替换。

  6. 格式化磁盘。

    # mkfs.ext4 /dev/vda5

    # mkfs.ext4 /dev/vda6

  7. 建立挂载目录。

    # mkdir /data01

    # mkdir /data02

  8. 将磁盘挂载到指定目录。

    # mount /dev/vda5 /data01

    # mount /dev/vda6 /data02

  9. 配置磁盘分区自动挂载。

    # vi /etc/fstab

    增加如下类似配置后按:wq!保存退出。

    /dev/vda5                    /data01           ext4       defaults              0 0
    /dev/vda6                    /data02           ext4       defaults              0 0
  10. 查看挂载是否成功。

    #df -hT

    系统显示如下类似信息表示挂载成功:
    Filesystem            Type      Size  Used Avail Use% Mounted on
    devtmpfs              devtmpfs   16G  8.0K   16G   1% /dev
    tmpfs                 tmpfs      16G   80K   16G   1% /dev/shm
    tmpfs                 tmpfs      16G   18M   16G   1% /run
    tmpfs                 tmpfs      16G     0   16G   0% /sys/fs/cgroup
    /dev/mapper/root-root xfs        21G  3.1G   18G  15% /
    /dev/vda1             ext4      979M   57M  855M   7% /boot
    tmpfs                 tmpfs     3.2G   16K  3.2G   1% /run/user/483
    tmpfs                 tmpfs     3.2G     0  3.2G   0% /run/user/0
    /dev/vda5             ext4      500G   60M  499G   1% /data01
    /dev/vda6             ext4    500G   60M  499G   1% /data02

标签:分区,bytes,dev,Linux,挂载,512,1048575999,size
来源: https://www.cnblogs.com/sxck/p/12579447.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有