云顶天的世界 云顶天的世界
  • 首页
  • 生活/杂谈
  • 摄影/游记
  • 折腾/玩物
  • 评论/观点
  • 运动/撸铁
  • 工作/笔记
  • 云顶天的朋友
  • 注册
  • 登录
首页 › 工具/软件 › linux挂载硬盘和开机自动挂载硬盘

linux挂载硬盘和开机自动挂载硬盘

云顶天
5年前工具/软件阅读 1,097

新的云计算平台上线,虚拟机全部都要迁移过去,手上的linux服务器比较多,最近几天没干别的就是迁移、检查环境和数据······顺便也有把部分服务器升级到centos7.3

考虑到网站数据和文件越来越大,原来只是存在系统盘的搞法已经有点撑不住了,扩容系统盘也是比较危险的操作,所以趁着这次换平台,干脆给每个服务器都挂一个方便扩容的云硬盘。

记录一下挂盘的命令,毕竟我只是个搞网络的,对系统的熟悉情况其实也就那样,该记录的还是要记录一下。

linux挂载硬盘和开机自动挂载硬盘-云顶天的世界

给所有服务器都挂了一个500G的盘,应该能撑上一段时间了。

第一步、使用命令“fdisk -l”检查硬盘挂载情况。这里可以看到新挂载的硬盘是/dev/vdb 536.9GB。

[root@webserv1 ~]# fdisk -l
Disk /dev/vda: 161.1 GB, 161061273600 bytes, 314572800 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 label type: dos
Disk identifier: 0x000c520b
   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048   314572766   157285359+  83  Linux
Disk /dev/vdb: 536.9 GB, 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

第二步、都是新盘,使用命令”fdisk /dev/vdb”直接开始分区。m查看帮助信息,n显示分区状态,p开始分区,没什么特殊需求后面都按default默认选项填写就行了,最后w写入分区表并退出。

[root@webserv1 ~]# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x490305ff.
Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   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): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-1048575999, default 2048): 2048
Last sector, +sectors or +size{K,M,G} (2048-1048575999, default 1048575999): 1048575999
Partition 1 of type Linux and of size 500 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

第三步、使用命令mkfs -t ext4 /dev/vdb1格式化分区,为什么是vdb1?因为刚才分区了啊~

[root@webserv1 ~]# mkfs -t ext4 /dev/vdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
32768000 inodes, 131071744 blocks
6553587 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2279604224
4000 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
102400000
Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

第四步、创建一个目录,然后把盘挂载到这个目录,之后就可以正常使用了。

[root@webserv1 ~]# mkdir /webdata                   #创建目录/webdata
[root@webserv1 ~]# mount /dev/vdb1 /webdata         #将硬盘vdb1挂载到这个目录
[root@webserv1 ~]# df -h                            #查看挂载情况
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1       148G  1.2G  141G   1% /
devtmpfs         24G     0   24G   0% /dev
tmpfs            24G     0   24G   0% /dev/shm
tmpfs            24G  8.4M   24G   1% /run
tmpfs            24G     0   24G   0% /sys/fs/cgroup
tmpfs           4.8G     0  4.8G   0% /run/user/0
/dev/vdb1       493G   73M  467G   1% /webdata

第五步、每次重启都要mount肯定麻烦,自动挂载必不可少。

直接”vi /etc/fstab”编辑文件,在最后加上下面这段内容

/dev/vdb1 /webdata ext4 defaults 0 0

分别表示挂载的硬盘、目录、文件格式,后面0 0表示开机不检查磁盘,修改完之后就是下面的样子,然后保存退出,重启之后硬盘就会自动挂载了。

vi /etc/fstab
#
# /etc/fstab
# Created by anaconda on Tue Jan 16 10:02:13 2018
#
# 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
#
UUID=b0a16d98-3b8c-400f-948d-0092477704fe /                       ext4    defaults        1 1
#  UUID="2c0388a0-4a7c-4b27-88c7-dd09fc674def /webdata ext4 defaults 1 2
/www/swap    swap    swap    defaults    0 0
/dev/vdb1 /webdata ext4 defaults 0 0
centos linux 网站服务器
赞(0)
闲出鸟的续集来了
上一篇
#健身#最近的运动状态小结
下一篇
最新文章
  • 用vlog记录生活,露脸的那种~刺激吧! 2022年7月6日
  • 坦克300提车一个月,各方面感觉良好,就是不能出去玩 2022年4月25日
  • 这次没有空军了,收获巨大! 2022年4月15日
  • 啊!空军了!找点客观原因 2022年4月9日
  • 祖传鱼竿整备了一下,先钓个胖头鱼 2022年4月6日
标签
linux NAS vlog 健身 减肥 华为 博客 大学 女儿 妈妈 婴儿 孩子 宝宝 宠物 工作 戒烟 房子 手机 折腾 摄影 故障 旅游 旅行 日记 楚玥 模型 汽车 游戏 爸爸 狗 生活 电影 童年 网站 网络 网络测试 群晖 装修 观点 视频 评测 评论 运动 追追 镜头
#第一次#超速被抓拍~
云顶天
2,173 1
五一假期的计划
云顶天
1,093 0
解决linux登陆ipsecvpn之后无法访问本地和互联网的问题
云顶天
3,567 0
难道这就是传说中的科研养鱼?
云顶天
818 0
  • 0
关于云顶天

草木一生,人生一世,总得给留下点什么。博客似乎是个不错的载体,就在这里开始吧!

分类
首页 生活/杂谈 摄影/游记 折腾/玩物 评论/观点 运动/撸铁 工作/笔记 云顶天的朋友
串门
boke112导航 胡言胡语 俍注 读来依然摄影博客 nicetheme 千淘万漉 龙行博客 猫鱼
Copyright © 2018-2023 云顶天的世界. Designed by nicetheme.
  • 首页
  • 生活/杂谈
  • 摄影/游记
  • 折腾/玩物
  • 评论/观点
  • 运动/撸铁
  • 工作/笔记
  • 云顶天的朋友
# 摄影 # # 生活 # # 日记 # # 女儿 # # 健身 #
云顶天
213
文章
140
评论
50
喜欢