CentOS挂载新硬盘
2024-10-16 13:31:09
1.查看当前硬盘使用状况:
df -h
root@VM_160_34_centos:~> df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 .9G .5G .1G % /
2.查看新硬盘
fdisk -l
root@VM_160_34_centos:~> fdisk -l Disk /dev/xvda: MB, bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0xcd6e8236 Device Boot Start End Blocks Id System
/dev/xvda1 * + Linux Disk /dev/xvdb: 53.7 GB, bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0x00000000 Disk /dev/xvdb doesn't contain a valid partition table Disk /dev/xvdc: MB, bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0x00000000 Disk /dev/xvdc doesn't contain a valid partition table
这结果很明显让人烦躁,一坨屎一样,下面我们过滤一下
命令:
fdisk -l |grep Disk
结果:
root@VM_160_34_centos:~> fdisk -l |grep Disk
Disk /dev/xvdb doesn't contain a valid partition table
Disk /dev/xvdc doesn't contain a valid partition table
Disk /dev/xvda: MB, bytes
Disk identifier: 0xcd6e8236
Disk /dev/xvdb: 53.7 GB, bytes
Disk identifier: 0x00000000
Disk /dev/xvdc: MB, bytes
Disk identifier: 0x00000000
这个看起来让人舒心多了,
结果中:
提示这个
Disk /dev/xvdb doesn't contain a valid partition table
Disk /dev/xvdc doesn't contain a valid partition table
这两行应该就是说还没有挂载上去的硬盘了.
新添加的硬盘的编号为
/dev/xvdb
/dev/xvdc
3.硬盘分区
- 进入fdisk模式
fdisk /dev/xvdb
root@VM_160_34_centos:~> fdisk /dev/xvdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x7ca79642.
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 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):
- 输入n进行分区
Command (m for help): n
Command action
e extended
p primary partition (-)
p
这里有两个选项:
p: 主分区 linux上主分区最多能有4个
e: 扩展分区 linux上扩展分区只能有1个,扩展分区创建后不能直接使用,还要在扩展分区上创建逻辑分区。
这里我选择的p。
- 选择分区个数
Partition number (-):
可以选择4个分区,这里我只分成1个分区
- 设置柱面,这里选择默认值就可以,直接按回车过去
First cylinder (-, default ):
Using default value
Last cylinder, +cylinders or +size{K,M,G} (-, default ):
Using default value
- 输入w,写入分区表,进行分区
Command (m for help):w
Command (m for help): w
The partition table has been altered! Calling ioctl() to re-read partition table.
Syncing disks.
整个过程如下:
root@VM_160_34_centos:~> fdisk /dev/xvdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x7ca79642.
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 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): n
Command action
e extended
p primary partition (-) Last login: Fri Jun :: from 112.90.239.105
root@VM_160_34_centos:~>
Display all possibilities? (y or n)
root@VM_160_34_centos:~>
root@VM_160_34_centos:~> fdisk /dev/xvd
xvda xvda1 xvdb xvdc
root@VM_160_34_centos:~> fdisk /dev/xvdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xc925c1ae.
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 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): n
Command action
e extended
p primary partition (-)
p
Partition number (-):
First cylinder (-, default ):
Using default value
Last cylinder, +cylinders or +size{K,M,G} (-, default ):
Using default value Command (m for help): w
The partition table has been altered! Calling ioctl() to re-read partition table.
Syncing disks.
4.格式化分区
将新分区格式化为ext3文件系统
- 如果创建的是主分区
#mkfs -t ext3 /dev/xvdb
root@VM_160_34_centos:~> mkfs -t ext3 /dev/xvdb
mke2fs 1.41. (-May-)
Filesystem label=
OS type: Linux
Block size= (log=)
Fragment size= (log=)
Stride= blocks, Stripe width= blocks
inodes, blocks
blocks (5.00%) reserved for the super user
First data block=
Maximum filesystem blocks=
block groups
blocks per group, fragments per group
inodes per group
Superblock backups stored on blocks:
, , , , , , , , ,
, , Writing inode tables: done
Creating journal ( blocks): done
Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every mounts or
days, whichever comes first. Use tune2fs -c or -i to override.
5. 挂载硬盘
- 创建挂载点
在根目录下创建storage目录
#mkdir /storage
- 将/dev/xvdb挂载到/storage下
#mount /dev/xvdb /storage
- 设置开机启动自动挂载
新创建的分区不能开机自动挂载,每次重启机器都要手动挂载。
设置开机自动挂载需要修改/etc/fstab文件
#vi /etc/fstab
在文件的最后增加一行
/dev/xvdb /storage ext3 defaults
过程如下:
root@VM_160_34_centos:~> mkdir /storage
root@VM_160_34_centos:~> mount /dev/xvdb /storage
root@VM_160_34_centos:~> vi /etc/fstab /dev/xvda1 / ext3 noatime,acl,user_xattr
/dev/xvdc swap swap defaults
proc /proc proc defaults
sysfs /sys sysfs noauto
debugfs /sys/kernel/debug debugfs noauto
devpts /dev/pts devpts mode=,gid=
/dev/xvdb /storage ext3 defaults
~
~
~
~
~
"/etc/fstab" 7L, 536C written
root@VM_160_34_centos:~> clear
结果:
root@VM_160_34_centos:/storage> ll /
total
dr-xr-xr-x root root May : bin
dr-xr-xr-x root root May boot
drwxr-xr-x root root Dec : data
drwxr-xr-x root root Jun : dev
drwxr-xr-x root root Jun : etc
drwxr-xr-x root root Jun : home
dr-xr-xr-x root root Jun lib
dr-xr-xr-x root root Jun lib64
drwx------ root root May lost+found
drwxr-xr-x root root Sep media
drwxr-xr-x root root Sep mnt
drwxr-xr-x root root Sep opt
dr-xr-xr-x root root Jun proc
dr-xr-x--- root root Jun : root
dr-xr-xr-x root root Jun sbin
drwxr-xr-x root root May selinux
drwxr-xr-x root root Sep srv
drwxr-xr-x root root Jun : storage
drwxr-xr-x root root Jun sys
drwxrwxrwt root root Jun : tmp
drwxr-xr-x root root May usr
drwxr-xr-x root root Jul var
root@VM_160_34_centos:/storage> fdisk -l |grep Disk
Disk /dev/xvdb doesn't contain a valid partition table
Disk /dev/xvdc doesn't contain a valid partition table
Disk /dev/xvda: MB, bytes
Disk identifier: 0xcd6e8236
Disk /dev/xvdb: 53.7 GB, bytes
Disk identifier: 0x00000000
Disk /dev/xvdc: MB, bytes
Disk identifier: 0x00000000
root@VM_160_34_centos:/storage> df -lh
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 .9G .5G .1G % /
/dev/xvdb 50G 180M 47G % /storage
教程到此结束!
最新文章
- *POJ 1222 高斯消元
- node环境配置安装(nvm)
- Diamond Armor - The most expensive Suit: 2.8 Mio Swiss Francs
- table的样式定义
- Ubuntu下安装Android SDK(图文教程)
- 利用object.defineProperty实现数据与视图绑定
- 聊聊js里面容易忽视的一些东西(1)
- [.Net Core] 简单使用 Mvc 内置的 Ioc
- javascript实现双向数据绑定
- 函数式编程之-初窥F#
- 06-HTML-表格标签
- Ubuntu快捷键、Ubuntu终端常用命令
- vmware中连接U盘
- Django的STATIC_ROOT和STATIC_URL以及STATICFILES_DIRS
- Matlab Gauss quadrature
- HTTP协议(TCP/IP)
- PAT 1050 String Subtraction
- Trustin Lee
- SetProcessWorkingSetSize 降低程序运行内存
- [Ubuntu] 关于使用 root 账号登录
热门文章
- 深入理解计算机系统第二版习题解答CSAPP 2.11
- [转]Oracle Stored Procedures Hello World Examples
- Leetcode 104. Maximum Depth of Binary Tree(二叉树的最大深度)
- PHP 使用get_class_methods()和array_diff() 兩個相同的類中方法差集
- Navicate DataModel 注册码
- smarty中的变量使用
- c# xml 解析取值
- ASP连接MYSQL数据库
- 配置WindowsLiveWriter,写cnblogs博客
- Sqlserver基于流程控制