linux下使用fdisk工具为磁盘分区格式化
本文主要讲述使用fdisk工具对磁盘进行分区和格式化的方法
首先要明确分区是针对磁盘进行的操做,磁盘分区会创建分区表,类似vda,sda的是磁盘,vda1,sda1的是分区
1.1. 查看分区挂载情况
df -h
1.2.查看服务器挂载的磁盘
fdisk -l fdisk -l /dev/vdb
2.1.对vdb磁盘进行分区
fdisk /dev/vdb
进入交互式的分区界面,以下是分区操作步骤
m打印菜单 n新建分区 p选择主分区 e选择扩展分区 1选择分区号 选择初始位置,默认为1 选择结束为止,默认为磁盘结尾
分区创建完成,可以列表查看,保存退出
p打印分区表 w写入分区表保存 q退出
2.2.重新载入磁盘分区信息
无返回就是载入磁盘信息成功,针对磁盘进行操作
partprobe /dev/vdb
注意:
使用fdisk工具只是将分区信息写到磁盘,
在格式化分区值前需要使用partprobe让kernel重新读取分区信息,如果不成功则需要重启系统
3.1.对磁盘分区进行格式化
使用ext4文件系统
mkfs.ext4 /dev/vdb1
3.2.格式化完成后续优化配置,取消磁盘自检
tune2fs -c -1 /dev/vdb1
4.1.挂载磁盘分区到指定目录
mkdir -p /data mount /dev/vdb1 /data
4.2.配置开机自动挂载分区
/etc/fstab 增加一行
vim /etc/fstab ------------------------------------------------------- /dev/vdb1 /data ext4 defaults 0 0 -------------------------------------------------------
5.0.以下为实例演示:使用Ubuntu系统
5.1.查看磁盘分区信息
root@zstest:~# df -h Filesystem Size Used Avail Use% Mounted on udev 7.9G 0 7.9G 0% /dev tmpfs 1.6G 3.2M 1.6G 1% /run /dev/vda1 50G 5.7G 41G 13% / tmpfs 7.9G 0 7.9G 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 7.9G 0 7.9G 0% /sys/fs/cgroup tmpfs 1.6G 0 1.6G 0% /run/user/0
5.2.列表查看磁盘信息
root@zstest:~# fdisk -l Disk /dev/vda: 50 GiB, 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 Disklabel type: dos Disk identifier: 0xd6804155 Device Boot Start End Sectors Size Id Type /dev/vda1 * 2048 104855551 104853504 50G 83 Linux Disk /dev/vdb: 50 GiB, 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
5.3.对磁盘vdb进行分区
root@zstest:~# fdisk /dev/vdb Welcome to fdisk (util-linux 2.27.1). 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. Created a new DOS disklabel with disk identifier 0x63c3e6e0. Command (m for help): n Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p): p Partition number (1-4, default 1): First sector (2048-104857599, default 2048): Last sector, +sectors or +size{K,M,G,T,P} (2048-104857599, default 104857599): Created a new partition 1 of type 'Linux' and of size 50 GiB. Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks.
5.4.查看分区信息
root@zstest:~# fdisk -l Disk /dev/vda: 50 GiB, 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 Disklabel type: dos Disk identifier: 0xd6804155 Device Boot Start End Sectors Size Id Type /dev/vda1 * 2048 104855551 104853504 50G 83 Linux Disk /dev/vdb: 50 GiB, 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 Disklabel type: dos Disk identifier: 0x63c3e6e0 Device Boot Start End Sectors Size Id Type /dev/vdb1 2048 104857599 104855552 50G 83 Linux
5.5.重新载入磁盘分区信息
[root@zstest ~]# partprobe /dev/vdb
5.6.对指定磁盘分区进行格式化,使用ext4文件系统
root@zstest:~# mkfs.ext4 /dev/vdb1 mke2fs 1.42.13 (17-May-2015) Creating filesystem with 13106944 4k blocks and 3276800 inodes Filesystem UUID: 047fb8b0-e6ed-42db-bf5c-2a6d388fc34d 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 This filesystem will be automatically checked every 38 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
5.7.根据提示进行操作,取消磁盘自检
root@zstest:~# tune2fs -c -1 /dev/vdb1 tune2fs 1.42.13 (17-May-2015) Setting maximal mount count to -1
5.8.挂载分区到指定目录
mkdir -p /data mount /dev/vdb1 /data
5.9.配置开机自动挂载分区
vim /etc/fstab ------------------------------------------------------- # made by tssc /dev/vdb1 /data ext4 defaults 0 0 -------------------------------------------------------
完毕,呵呵呵呵
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
基于CentOS下搭建 WordPress 个人博客
准备 LNMP 环境 任务时间:30min ~ 60min LNMP 是 Linux、Nginx、MySQL 和 PHP 的缩写,是 WordPress 博客系统依赖的基础运行环境。我们先来准备 LNMP 环境 安装 Nginx 使用yum安装 Nginx: yum install nginx -y 修改/etc/nginx/conf.d/default.conf,去除对 IPv6 地址的监听,可参考下面的示例: 示例代码:/etc/nginx/conf.d/default.conf server { listen 80 default_server; # listen [::]:80 default_server; server_name _; root /usr/share/nginx/html; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { } error_page 404 /404....
- 下一篇
CentOS搭建个人服务脱坑实录
环境:VMware、Centos7 64位 说明:本是个人的爬坑经历所总结出来的,记录一下心得。也给有需要的人提供一些帮助。引用了一些大神的笔记,非常感谢,希望大神们不要介意。 Linux如何查看端口 1 //查看某一端口的占用情况,比如查看8000端口使用情况 2 lsof -i:8000 3 //查看指定的端口号的进程情况,如查看8000端口的情况 4 netstat -tunlp|grep 8000 5 netstat -anp|grep 8000 6 //进一步查看被那个程序占用,或直接用 ps -aux | grep pid 查看 7 ps -aux | grep java 1 netstat -ntlp //查看当前所有tcp端口· 2 netstat -ntulp |grep 80 //查看所有80端口使用情况· 3 netstat -an | grep 3306 //查看所有3306端口使用情况· 1 //查看某个服务占用的进程 2 ps -ef | grep tomcat 3 //查看本机所有java进程 4 jps Centos 7 防火墙命令...
相关文章
文章评论
共有0条评论来说两句吧...