您当前的位置: 首页 >  linux

Linux 磁盘挂载

蔚1 发布时间:2019-09-06 23:30:58 ,浏览量:2

在安装服务器以后,有时候需要格式化并且挂载新的磁盘,那么这篇文章会告诉你答案。

本 Chat 你将会获得以下知识:

  • 如何发现并且格式化新的磁盘;
  • 如何挂载磁盘,重启后也生效。
1、磁盘的格式化 1.1、查看当前文件目录

使用 df -h 命令来查看当前已经挂载的磁盘以及磁盘的信息:

root:~>df -h文件系统        容量  已用  可用 已用% 挂载点/dev/sda3       259G  229G   30G   89% /devtmpfs         32G     0   32G    0% /devtmpfs            32G   16M   32G    1% /dev/shmtmpfs            32G  3.2G   29G   11% /runtmpfs            32G     0   32G    0% /sys/fs/cgroup/dev/sda1       497M  191M  306M   39% /boottmpfs           6.3G     0  6.3G    0% /run/user/0cm_processes     32G  2.7G   29G    9% /run/cloudera-scm-agent/processtmpfs           6.3G   12K  6.3G    1% /run/user/42
1.2、磁盘分区
  • 查找已经安装并且未格式化的磁盘使用命令 fdisk -l 列出所有的磁盘,使用命令的例子以及结果如下:

    root:~>fdisk -l

    磁盘 /dev/sda:299.4 GB, 299439751168 字节,584843264 个扇区Units = 扇区 of 1 * 512 = 512 bytes扇区大小(逻辑/物理):512 字节 / 512 字节I/O 大小(最小/最佳):512 字节 / 512 字节磁盘标签类型:dos磁盘标识符:0x000de8f6

    设备 Boot Start End Blocks Id System/dev/sda1 * 2048 1026047 512000 83 Linux/dev/sda2 1026048 42969087 20971520 82 Linux swap / Solaris/dev/sda3 42969088 584843263 270937088 83 Linux

    磁盘 /dev/sdb:3000.0 GB, 3000034656256 字节,5859442688 个扇区Units = 扇区 of 1 * 512 = 512 bytes扇区大小(逻辑/物理):512 字节 / 512 字节I/O 大小(最小/最佳):512 字节 / 512 字节磁盘标签类型:gptDisk identifier: 69D07AFC-584D-4926-81B8-8DEF8087445F

可以看出 /dev.sdb 还没有格式化以及挂载。

  • 格式化磁盘在 CentOS 7.0 以后 fdisk 也支持了大磁盘的格式话。本文章是再 CentOS 7.4 上进行的。使用 fdisk /dev/sdb 根据帮助提示分区,这里是把 /dev/sdb 分成一个区.

    [root@localhost ~]# fdisk /dev/sdbDevice contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabelBuilding a new DOS disklabel with disk identifier 0x0adfd119.Changes will remain in memory only, until you decide to write them.After that, of course, the previous content won't be recoverable.

    Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

    WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u').

    Command (m for help): mCommand action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition l list known partition types m print this menu n add a new partition o create a new empty DOS partition table p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partition's system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only)

    Command (m for help): nCommand action e extended p primary partition (1-4)pPartition number (1-4): 1First cylinder (1-6527, default 1): Using default value 1Last cylinder, +cylinders or +size{K,M,G} (1-6527, default 6527): Using default value 6527

    Command (m for help): p

    Disk /dev/sdb: 53.7 GB, 3000034656256 bytes255 heads, 63 sectors/track, 6527 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x69D07AFC-584D-4926-81B8-8DEF8087445F

    Device Boot      Start         End      Blocks   Id  System

    /dev/sdb1 1 6527 5859442688 83 Linux

    Command (m for help): wThe partition table has been altered!

    Calling ioctl() to re-read partition table.Syncing disks.

  • 格式化磁盘

命令 mkfs.ext4 /dev/sdb1 分区为 ext4 的文件系统格式。

[root@localhost ~]# mkfs.ext4 /dev/sdb1 mke2fs 1.41.12 (17-May-2010)Filesystem label=OS type: LinuxBlock size=4096 (log=2)Fragment size=4096 (log=2)Stride=0 blocks, Stripe width=0 blocks3276800 inodes, 13107024 blocks655351 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=4294967296400 block groups32768 blocks per group, 32768 fragments per group8192 inodes per groupSuperblock backups stored on blocks:         32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,         4096000, 7962624, 11239424Writing inode tables: done                            Creating journal (32768 blocks): doneWriting superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 28 mounts or180 days, whichever comes first.  Use tune2fs -c or -i to override.
2、挂载磁盘 2.1、手动挂载

手动挂载每次重启都需要执行一次,比较麻烦:

手动挂载步骤:

  • 准备挂载的目录:mkdir /home/datachmod 777 /home/data
  • 使用 mount 命令挂载mount /dev/sdb1 /home/data
2.2、自动挂载

自动挂载不需要重启后在执行,推荐使用:

自动挂载的步骤为:

  • 准备挂载的目录:mkdir /home/datachmod 777 /home/data

  • 挂载步骤:

  1. fdisk -l

  2. 找到要挂载的磁盘(举例/dev/sdb)

  3. 查看磁盘文件

    vim /ext/fstab

    # /etc/fstab# Created by anaconda on Tue Jul 4 05:46:31 2017

    # 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

    #/dev/mapper/cl-root / xfs defaults 0 0UUID=619a7a33-84ff-4b7f-befd-c798c04f68a4 /boot xfs defaults 0 0/dev/mapper/cl-swap swap swap defaults 0 0

  4. 添加新挂载的硬盘

    /dev/sdc /home/data ext4 defaults 0 0

参数说明:

  • 第一列:实际的分区名,也可以是实际的分区的卷标;

  • 第二列:挂载点,最好文件夹已存在并且权限为 777;

  • 第三列:此分区文件系统类型;

  • 第四列:挂载的选项,用于设置挂载的参数。

    常见参数如下:

    • auto 系统自动挂载,默认选项;
    • defaults rw,suid,dev,exec,auto,nouser,ansyc;
    • noauto 开机不自动挂载;
    • nouser 只有超级用户可以挂载;
    • ro 按照只读权限挂载;
    • rw 按照可读可写权限挂载;
    • user 任何用户都可以挂载。
  • 第五列:dump备份设置

    • 1 允许 dump 备份程序备份;
    • 0 忽略备份操作;
  • 第六列:fsck 磁盘检查设置
    • 0 永不检查
  • 目录永远为 1

  • 其他分区从 2 开始,数字越小越先检查。

本文首发于 GitChat,未经授权不得转载,转载需与 GitChat 联系。

阅读全文: http://gitbook.cn/gitchat/activity/5d712efe6b6e7537032ab3a9

您还可以下载 CSDN 旗下精品原创内容社区 GitChat App ,阅读更多 GitChat 专享技术内容哦。

FtooAtPSkEJwnW-9xkCLqSTRpBKX

关注
打赏
1688896170
查看更多评论

蔚1

暂无认证

  • 2浏览

    0关注

    4645博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.0577s