zoukankan      html  css  js  c++  java
  • 磁盘的分区、格式化、与挂载

    1、磁盘分区:fdisk 【-l】 设备名称

     -l:输出后面接的设备所有的分区内容。

     1 [root@iZ255cppmtxZ ~]# fdisk -l
     2 
     3 Disk /dev/xvda: 42.9 GB, 42949672960 bytes, 83886080 sectors
     4 Units = sectors of 1 * 512 = 512 bytes
     5 Sector size (logical/physical): 512 bytes / 512 bytes
     6 I/O size (minimum/optimal): 512 bytes / 512 bytes
     7 Disk label type: dos
     8 Disk identifier: 0x0009e68a
     9 
    10     Device Boot      Start         End      Blocks   Id  System
    11 /dev/xvda1   *        2048    83884031    41940992   83  Linux
    12 
    13 Disk /dev/xvdb: 32.2 GB, 32212254720 bytes, 62914560 sectors
    14 Units = sectors of 1 * 512 = 512 bytes
    15 Sector size (logical/physical): 512 bytes / 512 bytes
    16 I/O size (minimum/optimal): 512 bytes / 512 bytes

      从查询结果中可以看出多了一个/dev/xvdb

      用fdisk分区

     1 [root@iZ255cppmtxZ ~]# fdisk /dev/xvdb
     2 Welcome to fdisk (util-linux 2.23.2).
     3 
     4 Changes will remain in memory only, until you decide to write them.
     5 Be careful before using the write command.
     6 
     7 Device does not contain a recognized partition table
     8 Building a new DOS disklabel with disk identifier 0x25a2caf5.
     9 
    10 Command (m for help): 

     输入“m”

     1 Command (m for help): m
     2 Command action
     3    a   toggle a bootable flag
     4    b   edit bsd disklabel
     5    c   toggle the dos compatibility flag
     6    d   delete a partition                            <==删除一个分区
     7    g   create a new empty GPT partition table
     8    G   create an IRIX (SGI) partition table
     9    l   list known partition types
    10    m   print this menu
    11    n   add a new partition                           <==新建一个分区
    12    o   create a new empty DOS partition table
    13    p   print the partition table                     <==在屏幕上显示分区表
    14    q   quit without saving changes                   <==不存储,离开fdisk程序
    15    s   create a new empty Sun disklabel
    16    t   change a partition's system id
    17    u   change display/entry units
    18    v   verify the partition table
    19    w   write table to disk and exit                  <==将刚才的操作写入分区表
    20    x   extra functionality (experts only)
    21 
    22 Command (m for help): 

      接下来正式分区  

     1 Command (m for help): n
     2 Partition type:
     3    p   primary (0 primary, 0 extended, 4 free)
     4    e   extended
     5 Select (default p): p
     6 Partition number (1-4, default 1): 1
     7 First sector (2048-62914559, default 2048): 
     8 Using default value 2048
     9 Last sector, +sectors or +size{K,M,G} (2048-62914559, default 62914559): 
    10 Using default value 62914559
    11 Partition 1 of type Linux and of size 30 GiB is set
    12 
    13 Command (m for help): w
    14 The partition table has been altered!
    15 
    16 Calling ioctl() to re-read partition table.
    17 Syncing disks.

      有fdisk -l查看下现在分区情况

     1 [root@iZ255cppmtxZ ~]# fdisk -l
     2 
     3 Disk /dev/xvda: 42.9 GB, 42949672960 bytes, 83886080 sectors
     4 Units = sectors of 1 * 512 = 512 bytes
     5 Sector size (logical/physical): 512 bytes / 512 bytes
     6 I/O size (minimum/optimal): 512 bytes / 512 bytes
     7 Disk label type: dos
     8 Disk identifier: 0x0009e68a
     9 
    10     Device Boot      Start         End      Blocks   Id  System
    11 /dev/xvda1   *        2048    83884031    41940992   83  Linux
    12 
    13 Disk /dev/xvdb: 32.2 GB, 32212254720 bytes, 62914560 sectors
    14 Units = sectors of 1 * 512 = 512 bytes
    15 Sector size (logical/physical): 512 bytes / 512 bytes
    16 I/O size (minimum/optimal): 512 bytes / 512 bytes
    17 Disk label type: dos
    18 Disk identifier: 0x25a2caf5
    19 
    20     Device Boot      Start         End      Blocks   Id  System
    21 /dev/xvdb1            2048    62914559    31456256   83  Linux

      可以从上图看出多了一个/dev/xvdb1,之所以是xvdb1是因为我们前面指定了1,要是指定2就应该为xvdb2

      如果创建完以后,/proc/partitions查看不到对应的分区,使用parprobe命令刷新一下就可以了。

    2、用mkfs命令格式化分区/dev/xvdb1

     1 [root@iZ255cppmtxZ ~]# mkfs -t ext4 /dev/xvdb1 
     2 mke2fs 1.42.9 (28-Dec-2013)
     3 Filesystem label=
     4 OS type: Linux
     5 Block size=4096 (log=2)
     6 Fragment size=4096 (log=2)
     7 Stride=0 blocks, Stripe width=0 blocks
     8 1966080 inodes, 7864064 blocks
     9 393203 blocks (5.00%) reserved for the super user
    10 First data block=0
    11 Maximum filesystem blocks=4294967296
    12 240 block groups
    13 32768 blocks per group, 32768 fragments per group
    14 8192 inodes per group
    15 Superblock backups stored on blocks: 
    16     32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
    17     4096000
    18 
    19 Allocating group tables: done                            
    20 Writing inode tables: done                            
    21 Creating journal (32768 blocks): done
    22 Writing superblocks and filesystem accounting information:        
    23 done

    3、创建挂载目录并挂载

     1 [root@iZ255cppmtxZ /]# mkdir /data
     2 [root@iZ255cppmtxZ /]# mount /dev/xvdb1 /data/
     3 [root@iZ255cppmtxZ /]# df -h
     4 Filesystem      Size  Used Avail Use% Mounted on
     5 /dev/xvda1       40G  1.5G   36G   5% /
     6 devtmpfs        489M     0  489M   0% /dev
     7 tmpfs           497M     0  497M   0% /dev/shm
     8 tmpfs           497M  6.5M  490M   2% /run
     9 tmpfs           497M     0  497M   0% /sys/fs/cgroup
    10 /dev/xvdb1       30G   44M   28G   1% /data

    4、设置开机自动挂载。

     1 [root@iZ255cppmtxZ /]# vi /etc/fstab 
     2 
     3 
     4 #
     5 # /etc/fstab
     6 # Created by anaconda on Fri Nov 21 18:16:53 2014
     7 #
     8 # Accessible filesystems, by reference, are maintained under '/dev/disk'
     9 # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
    10 #
    11 UUID=6634633e-001d-43ba-8fab-202f1df93339 / ext4 defaults,barrier=0 1 1
    12 /dev/xvdb1                 /data            ext4           defaults 0 0

     注:自动挂载6个字段意义为

    第一列:磁盘设备文件名或设备的Label。

    第二列:挂载点。

    第三列:磁盘分区的文件系统。

    第四列:文件系统参数。基本上,默认情况使用defaults设置即可。。

    第五列:能否被dump设备命令作用。0代表不做dump备份,1代表每天进行dump的操作,2也代表其他不定日期的dump备份操作,通常这个数值不是0就是1.

    第六列:是否已fsck检验扇区。0是不要检验,1表示最早检验(一般只有根目录会设置为1),2也是要检验,不过1会比较早被检验。一般来说根目录设置为1其他的要检验的文件系统都设置为2就好了。

    /etc/fstab是开机时的配置文件,不过,实际文件系统的挂载是记录到/etc/mtab 与/proc/mounts这两个文件当中的。每次我们在改动文件系统的挂载时,也会同时改动这两个文件。但是万一发生你在/etc/fstab中输入的数据有误,导致无法顺利开机成功,而进入单用户维护模式当中,那时候的/可是readonly的状态,当然你就无法修改/etc/fstab,也无法更新/etc/mtab。那怎么办?没关系,可以利用下面这一招:

    1 [root@iZ255cppmtxZ local]# mount -n -o remount,rw /
  • 相关阅读:
    20101029总结
    编程感悟
    编程实现>ASP.NET 3.5开发范例精讲精析>探讨SqlDataSource控件
    GET代替POST?
    php调试工具安装
    php 命令行方式使用
    多为数组转换成一维递归
    mysql优化相关
    操作目录
    递归树
  • 原文地址:https://www.cnblogs.com/liuyisai/p/5320267.html
Copyright © 2011-2022 走看看