首页 > 系统相关 >linux磁盘分区、格式化和挂载

linux磁盘分区、格式化和挂载

时间:2022-09-29 15:12:12浏览次数:80  
标签:磁盘分区 格式化 512 htl dev fstab linux test01 root

这篇文档主要是记录新加磁盘常用的操作。时间久了就会变得陌生。还是需要记录起来。

 

1. 查看磁盘空间基本使用情况

[root@htl-test01 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 3.7G 0 3.7G 0% /dev
tmpfs 3.7G 0 3.7G 0% /dev/shm
tmpfs 3.7G 504K 3.7G 1% /run
tmpfs 3.7G 0 3.7G 0% /sys/fs/cgroup
/dev/vda1 40G 2.3G 36G 7% /
tmpfs 747M 0 747M 0% /run/user/0

2. 查看磁盘挂载配置情况

[root@htl-test01 ~]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Mon Sep 14 07:14:22 2020
#
# 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=9f2d3e15-a78a-4f3d-8385-0165b4b67864 / ext4 defaults 1 1
[root@htl-test01 ~]#

3. 查看磁盘分区(空间)情况

[root@htl-test01 ~]# fdisk -l

Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 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: 0x000bb9c1

Device Boot Start End Blocks Id System
/dev/vda1 * 2048 83886046 41941999+ 83 Linux

Disk /dev/vdb: 53.7 GB, 53687091200 bytes, 104857600 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

[root@htl-test01 ~]#

4. 查看磁盘分区(文件系统)的情况

[root@htl-test01 ~]# lsblk -f
NAME FSTYPE LABEL UUID MOUNTPOINT
vda
└─vda1 ext4 9f2d3e15-a78a-4f3d-8385-0165b4b67864 /
vdb
[root@htl-test01 ~]#

5.  对磁盘进行分区操作

[root@htl-test01 ~]# 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 0x66ce43b2.

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-104857599, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599):
Using default value 104857599
Partition 1 of type Linux and of size 50 GiB is set

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

Calling ioctl() to re-read partition table.
Syncing disks.
[root@htl-test01 ~]#

6.  查看上一步分区操作的结果

[root@htl-test01 ~]#lsblk -f
NAME FSTYPE LABEL UUID MOUNTPOINT
vda
└─vda1 ext4 9f2d3e15-a78a-4f3d-8385-0165b4b67864 /
vdb
└─vdb1

7.  对新的分区进行格式化

[root@htl-test01 ~]# 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
3276800 inodes, 13106944 blocks
655347 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2162163712
400 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

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

[root@htl-test01 ~]#

8.  将新的分区进行挂载

[root@htl-test01 ~]# mkdir -p /disk
[root@htl-test01 ~]# mount /dev/vdb1 /disk/
[root@htl-test01 ~]# lsblk -f
NAME FSTYPE LABEL UUID MOUNTPOINT
vda
└─vda1 ext4 9f2d3e15-a78a-4f3d-8385-0165b4b67864 /
vdb
└─vdb1 ext4 998fcad6-967f-4042-b11d-c4f526de52b5 /disk

[root@htl-test01 ~]#

9.  将新分区信息写入配置文件

[root@htl-test01 ~]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Mon Sep 14 07:14:22 2020
#
# 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=9f2d3e15-a78a-4f3d-8385-0165b4b67864 / ext4 defaults 1 1
[root@htl-test01 ~]# vi /etc/fstab
[root@htl-test01 ~]#

10.  查看分区信息,并使之生效

[root@htl-test01 ~]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Mon Sep 14 07:14:22 2020
#
# 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=9f2d3e15-a78a-4f3d-8385-0165b4b67864 / ext4 defaults 1 1
UUID=998fcad6-967f-4042-b11d-c4f526de52b5 /disk ext4 defaults 0 0

[root@htl-test01 ~]# mount -a

 至此,新加磁盘的操作已完成,可开始正常使用。即使操作系统重启也会有效。 

 

 

参考:linux添加硬盘及分区格式化

 

标签:磁盘分区,格式化,512,htl,dev,fstab,linux,test01,root
From: https://www.cnblogs.com/orange-CC/p/16741637.html

相关文章

  • linux 安装Redis以及使用
    安装redisyuminstallredis 安装完毕后,使用下面的命令启动redis服务设置redis为开机自动启动chkconfigredison 进入redis服务#进入本机redisredis-cli......
  • 7. HTML-- 文本格式化
    1.前言一些HTML标签除了具有一定的语义(含义)外,还有默认的样式,例如<b>(加粗)、<em>(倾斜)等,通过这些标签我们无需借助CSS就可以为网页中的内容定义样式。在这些具有语义和......
  • Vscode中点击自动eslint格式化和prettier搭配
    eslint规则只是限制我们在写代码时候的标准化,尤其是在团队开发中成员的代码一致性,如果大家都是自己的标准,那么写出的项目将没有办法进行阅读,不利于后期的二次开发vscode自......
  • linux尝试wine以及国产常用软件总结
    建议不要折腾,可以尝试https://www.spark-app.store/或者deepin。有专业的人做,还是交给专业的人,自己就不要浪费时间了。实际上这并不是linux的错,也不是linux不好用,而是国产......
  • Postgresql基于Linux各种安装方法
    说明目前PostGreSQL最新版本为11.3,​​9.3及之前版本​​以不再受官方支持.从RHEL/CentOS/SL/OL6开始都自带PG数据库,下表是不同的操作系统版本对应的数据库版本:操作系统版......
  • Linux安全之提权命令
    **​​sudo​​​**是 ​​linux​​​ 系统管理指令,是允许系统管理员让普通用户执行一些或者全部的 ​​root​​​ 命令的一个工具,如 ​​halt​​​,​​reboot​​......
  • Linux系统strac命令
    strace:监控程序的执行状况在linux空间下,运行一个程序时,操作系统会将应用程序封装一个进程的形式,参与操作系统的调度,可以使用strace跟踪程序运行的情况。 基本功能......
  • Ubuntu更改名称的语法 | Ubuntu Linux更改文件名称 后缀 批量
    ubuntu下如何批量修改文件后缀名://正确的方法是在命令行中输入rename's/\.JPG/.jpg/'*.JPG//【注意】在单引号中的最后一个'/'符号不能少!//意思是:把当前文......
  • 【从零开始的Linux服务器管理】为服务器添加新用户
    任务背景这是一个非常常见的任务,当有新的用户要使用服务器,作为服务器管理员,都需要为服务器添加新用户,使新用户能够正常使用服务器的各项资源。需要完成的任务包含两项,一......
  • Linux 操作必备 150 个命令,速度收藏~
    链接:https://www.cnblogs.com/bananaaa/p/7774467.htmllinux命令是对Linux系统进行管理的命令。对于Linux系统来说,无论是中央处理器、内存、磁盘驱动器、键盘、鼠标,还......