Centos7 分区、挂载和卸载

Centos7 分区、挂载和卸载

[root@host-172-22-14-77 ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/cl_host–172–22–0--110-root 17G 1.4G 16G 8% /
devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs 3.7G 0 3.7G 0% /dev/shm
tmpfs 3.7G 8.4M 3.6G 1% /run
tmpfs 3.7G 0 3.7G 0% /sys/fs/cgroup
/dev/xvda1 1014M 157M 858M 16% /boot
tmpfs 730M 0 730M 0% /run/user/0
[root@host-172-22-14-77 ~]# fdisk -l

磁盘 /dev/xvda:107.4 GB, 107374182400 字节,209715200 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000e117b

设备 Boot      Start         End      Blocks   Id  System

/dev/xvda1 * 2048 2099199 1048576 83 Linux
/dev/xvda2 2099200 41943039 19921920 8e Linux LVM

磁盘 /dev/mapper/cl_host–172–22–0--110-root:18.2 GB, 18249416704 字节,35643392 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

磁盘 /dev/mapper/cl_host–172–22–0--110-swap:2147 MB, 2147483648 字节,4194304 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

**

[root@host-172-22-14-77 ~]# fdisk /dev/xvda

**
欢迎使用 fdisk (util-linux 2.23.2)。

更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
在这里插入图片描述

命令(输入 m 获取帮助):m
命令操作
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)

命令(输入 m 获取帮助):p //打印分区信息,可以看到当前并没有分区

磁盘 /dev/xvda:107.4 GB, 107374182400 字节,209715200 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000e117b

设备 Boot      Start         End      Blocks   Id  System

/dev/xvda1 * 2048 2099199 1048576 83 Linux
/dev/xvda2 2099200 41943039 19921920 8e Linux LVM

命令(输入 m 获取帮助):n //创建一个新的分区
Partition type:
p primary (2 primary, 0 extended, 2 free) //输入p为创建逻辑分区
e extended //输入e为创建扩展分区
Select (default p): p
分区号 (3,4,默认 3):3 //划分逻辑分区
起始 扇区 (41943040-209715199,默认为 41943040):
将使用默认值 41943040
Last 扇区, +扇区 or +size{K,M,G} (41943040-209715199,默认为 209715199):
将使用默认值 209715199
分区 3 已设置为 Linux 类型,大小设为 80 GiB

命令(输入 m 获取帮助):p //再次查看可以看到该磁盘已经有1个分区了

磁盘 /dev/xvda:107.4 GB, 107374182400 字节,209715200 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000e117b

设备 Boot      Start         End      Blocks   Id  System

/dev/xvda1 * 2048 2099199 1048576 83 Linux
/dev/xvda2 2099200 41943039 19921920 8e Linux LVM
/dev/xvda3 41943040 209715199 83886080 83 Linux

命令(输入 m 获取帮助):w //保存分区
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
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)
正在同步磁盘。
[root@host-172-22-14-77 ~]# fdisk -l

磁盘 /dev/xvda:107.4 GB, 107374182400 字节,209715200 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000e117b

设备 Boot      Start         End      Blocks   Id  System

/dev/xvda1 * 2048 2099199 1048576 83 Linux
/dev/xvda2 2099200 41943039 19921920 8e Linux LVM
/dev/xvda3 41943040 209715199 83886080 83 Linux

磁盘 /dev/mapper/cl_host–172–22–0--110-root:18.2 GB, 18249416704 字节,35643392 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

磁盘 /dev/mapper/cl_host–172–22–0--110-swap:2147 MB, 2147483648 字节,4194304 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

[root@host-172-22-14-77 ~]# mkfs.ext4 /dev/xvda3 //格式化文件系统
mke2fs 1.42.9 (28-Dec-2013)
无法对 /dev/xvda3 进行 stat 调用 — 没有那个文件或目录

The device apparently does not exist; did you specify it correctly?
[root@host-172-22-14-77 ~]# partprobe //上述报错是因为分区没有保存,手动保存
[root@host-172-22-14-77 ~]# mkfs.ext4 /dev/xvda3
mke2fs 1.42.9 (28-Dec-2013)
Discarding device blocks: 完成
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
5242880 inodes, 20971520 blocks
1048576 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=2168455168
640 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

Allocating group tables: 完成
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

[root@host-172-22-14-77 ~]# mkdir /data
[root@host-172-22-14-77 ~]# mount /dev/xvda3 /data //临时挂载
[root@host-172-22-14-77 ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/cl_host–172–22–0--110-root 17G 1.4G 16G 8% /
devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs 3.7G 0 3.7G 0% /dev/shm
tmpfs 3.7G 8.4M 3.6G 1% /run
tmpfs 3.7G 0 3.7G 0% /sys/fs/cgroup
/dev/xvda1 1014M 157M 858M 16% /boot
tmpfs 730M 0 730M 0% /run/user/0
/dev/xvda3 79G 57M 75G 1% /data

使用blkid查看uuid

[root@host-172-22-14-77 ~]# vi /etc/fstab //永久挂载

/dev/mapper/cl_host–172–22–0--110-root / xfs defaults 0 0
UUID=70c8537a-8ab5-4f04-a69a-4de00a85e4ad /boot xfs defaults 0 0
/dev/mapper/cl_host–172–22–0--110-swap swap swap defaults 0 0
UUID=80c8537a-8ab5-4f04-a69a-4de00a85e4ad /data ext4 defaults 0 0 //这部分是新增的

reboot

在这里插入图片描述

如果卸载分区请使用umount
临时卸载,重启恢复 umount /dev/xvda3
永久卸载 修改/etc/fstab中的/dev/xvda3行设置

  • 0
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值