LinuxGod

LinuxGod.net
Linux大神网——精选每一篇高品质的技术干货
  1. 首页
  2. 开源快讯
  3. 正文

ubuntu格式化硬盘ext4 Linux环境新磁盘配置方法资料质量不尽如人意

2023年6月24日 240点热度

互联网上搜索到的Linux环境新c盘配置方式资料质量都不尽如人意,因而自己整理了一份ubuntu格式化硬盘ext4,日常Linuxc盘分区时查阅足够了,主要是用到了fdisk命令。

fdisk基本使用

新增硬碟后,在linux系统下输入fdisk-l命令查看当前c盘信息:

$ sudo fdisk -l                                                         
...
Disk /dev/ram0: 4.8 GiB, 5120000000 bytes, 10000000 sectors                                   
Units: sectors of 1 * 512 = 512 bytes                                                         
Sector size (logical/physical): 512 bytes / 8192 bytes                                        
I/O size (minimum/optimal): 8192 bytes / 8192 bytes
...
Disk /dev/sda: 465.8 GiB, 500107862016 bytes, 976773168 sectors                               
Disk model: ST500DM002-1BD14                                                                  
Units: sectors of 1 * 512 = 512 bytes                                                         
Sector size (logical/physical): 512 bytes / 4096 bytes                                        
I/O size (minimum/optimal): 4096 bytes / 4096 bytes                                          
Disklabel type: gpt
Disk identifier: C16B3C7C-2596-448D-A4BA-4A7554CD734A                                        
Device     Start       End   Sectors   Size Type                                             
/dev/sda1   2048 976773119 976771072 465.8G Linux filesystem                                 
...
Disk /dev/sdc: 3.7 TiB, 4000787030016 bytes, 7814037168 sectors
Disk model: ST4000NM000A-2HZ
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
...

注意看最下边多了一块3.7TB的硬碟sdc,下边用命令:fdisk/dev/sdc给新硬碟进行分区:

$ sudo fdisk /dev/sdc
Welcome to fdisk (util-linux 2.33.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
The old LVM2_member signature will be removed by a write command.
Device does not contain a recognized partition table.
The size of this disk is 3.7 TiB (4000787030016 bytes). DOS partition table format cannot be used on drives for volumes larger than 2199023255040 bytes for 512-byte sectors. Use GUID partition table format (GPT).
Created a new DOS disklabel with disk identifier 0xe461c452.
Command (m for help):

步入fdisk命令,输入m可以看见该命令的帮助:

Command (m for help): m                                                              
Help:
  DOS (MBR)
   a   toggle a bootable flag
   b   edit nested BSD disklabel
   c   toggle the dos compatibility flag
  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition
  Misc
   m   print this menu
   u   change display/entry units
   x   extra functionality (experts only)
  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file
  Save & Exit
   w   write table to disk and exit
   q   quit without saving changes
                                                                                             
  Create a new label                                                                         
   g   create a new empty GPT partition table                                                
   G   create a new empty SGI (IRIX) partition table                                         
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table

创建分区表

进行分区前须要先明晰采用分区表的格式,目前主流的有MBR和GPT,两者的区别可以自行搜索,总结两点:

晓得里面两点就够了,这儿我使用在Linux服务器上,不须要考虑windows兼容性,再者是一块4T盘,因而采用GPT进行分区,下边两种形式请依照自己的须要选择。

采用GUID(GPT)分区结构

mkfs.ext4 格式化步骤_ubuntu格式化硬盘ext4_windows ext4 格式化

假如使用GPT则输入g创建一张新的空GPT格式分区表。

ommand (m for help): g
Created a new GPT disklabel (GUID: D53735F6-8E14-504D-BDA5-89DB97A770DF).                    
The old LVM2_member signature will be removed by a write command.

然后输入n进行分区ubuntu格式化硬盘ext4,

Command (m for help): n

选择分区表编号,按照提示目前最多可以创建128个分区,保持默认即可:

Partition number (1-128, default 1):

然后选择该分区的起始c盘数,这儿可自定义也可不做选择,如无特殊需求强烈建议选择默认:

First sector (2048-7814037134, default 2048):

接出来是定义该分区的大小,默认使用整个,直接回车:

Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-7814037134, default 7814037134):

创建成功:

Created a new partition 1 of type 'Linux filesystem' and of size 3.7 TiB.

ubuntu格式化硬盘ext4_mkfs.ext4 格式化步骤_windows ext4 格式化

最后记得w将分区表写入硬碟。

采用DOS(MBR)分区结构

假如使用MBR则输入o创建一张新的空MBR格式分区表:

Command (m for help): o
The size of this disk is 3.7 TiB (4000787030016 bytes). DOS partition table format cannot be used on drives for volumes larger than 2199023255040 bytes for 512-byte sectors. Use GUID partition table format (GPT).
Created a new DOS disklabel with disk identifier 0xe3e2291c.
The old LVM2_member signature will be removed by a write command.

输入n进行分区:

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)

一块化学硬碟只能有:一到四个主分区(但其中只能有一个是活动的主分区),或一到三个主分区,和一个扩充分区。分别对应hda1,hda2,hda3,hda4.

Linux中规定,每一个硬碟设备最多能有4个主分区(其中包含扩充分区)构成,任何一个扩充分区都要占用一个主分区号码,也就是在一个硬碟中,主分区和扩充分区一共最多是4个。

——《Linux主分区linux计划任务linux 常用命令,扩充分区,逻辑分区的联系和区别》

总接出来就是一块化学硬碟起码有一个主分区,在这儿我只须要一个分区,因而下边将这块硬碟全部划为主分区:

Select (default p): p

然后选择该主分区为第几个主分区,因为是楼盘,这儿输入1来分第一个主分区:

ubuntu格式化硬盘ext4_mkfs.ext4 格式化步骤_windows ext4 格式化

Partition number (1-4, default 1): 1

然后选择该分区的起始c盘数,这儿可自定义也可不做选择,如无特殊需求强烈建议选择默认:

First sector (2048-4294967295, default 2048):

接出来是定义该分区的大小,假若按默认(按回车)即是使用全部可用储存额,也可以是用M或m单位结尾的数字(小写M是大B的意思,假如输入1M实际上是X8也就是8m的空间),这儿我保持默认:

Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-4294967294, default 4294967294): 
Created a new partition 1 of type 'Linux' and of size 2 TiB.

可以看见虽然硬碟是4TB,采用MBR后只能使用其中的2TB空间,其他的就浪费了。

最后记得w将分区表写入硬碟。

后续操作(重要)

完成分区后,记得输入w写入分区:

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

写入分区表成功后会退出fdisk交互界面。

再看一眼c盘信息:

ubuntu格式化硬盘ext4_windows ext4 格式化_mkfs.ext4 格式化步骤

$ sudo fdisk -l
...
Disk /dev/sdc: 3.7 TiB, 4000787030016 bytes, 7814037168 sectors
Disk model: ST4000NM000A-2HZ
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: gpt
Disk identifier: 74A6DB69-8C91-654F-9F61-A9F38D7F2A34
Device     Start        End    Sectors  Size Type
/dev/sdc1   2048 7814037134 7814035087  3.7T Linux filesystem
...

没问题后进行低格,假如没有特殊需求就采用ext4:

第四代扩充文件系统(德语:Fourthextendedfilesystem,简写为ext4)是Linux系统下的日志文件系统,是ext3文件系统的后继版本——ext4ByWikipedia。

$ sudo mkfs.ext4 /dev/sdc1
mke2fs 1.44.5 (15-Dec-2018)
Creating filesystem with 976754384 4k blocks and 244195328 inodes
Filesystem UUID: 87746749-1922-4682-9b4e-3a67be1d9498
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
        4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
        102400000, 214990848, 512000000, 550731776, 644972544
Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done

c盘挂载

然后将c盘挂载到须要的位置,通常会选择挂载在/mnt,我在这儿因为涉及到多用户,将硬碟挂载我用户目录下的一个文件夹下:

sudo mount /dev/sdc1 /home/songtianlun/data

直接挂载,重启后配置会遗失,可以更改/etc/fstab配置文件配置开机手动挂载,该配置文件的格式如下:

$ cat /etc/fstab 
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
#                
# / was on /dev/sda7 during installation
UUID=4ae9f128-7cee-48fd-998c-4257e394fa4a /               ext4    errors=remount-ro 0       1
# /boot/efi was on /dev/sda1 during installation
UUID=A5EB-573A  /boot/efi       vfat    umask=0077      0       1
/swapfile                                 none            swap    sw              0       0
# /dev/sda1
/dev/sda1    /    ext4  rw,relatime 0   1
UUID=4ae9f128-7cee-48fd-998c-4257e394fa4a /               ext4    errors=remount-ro 0       1

格式大约是这样的:

#                
# 要挂载的分区设备号 挂载点 文件系统类型  挂载选项    是否备份    是否检测

假如须要设备号,可以使用blkid命令获取:

$ blkid
/dev/sda1: UUID="e943af1e-72cf-4b72-b444-859b9610256f" TYPE="ext4" PARTUUID="161a8c3f-871d-45f6-a25f-466bf16f6035"

实测下边这两种都是可以挂载的:

UUID=4ae9f128-7cee-48fd-998c-4257e394fa4a /               ext4    errors=remount-ro     0       1
/dev/sda1       /               ext4            rw,relatime     0       1

写好配置后可以使用该命令生效(挂载/etc/fstab中所有档案):

mount -a

上次重启设备就不须要再自动挂载该c盘了。

c盘状态

使用lsblk看一下当前硬碟的树状结构:

$ lsblk 
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 465.8G  0 disk 
└─sda1   8:1    0 465.8G  0 part /
sdc      8:32   0   3.7T  0 disk 
└─sdc1   8:33   0   3.7T  0 part /home/songtianlun/data

使用df-h瞧瞧使用率:

$ df -h
文件系统        容量  已用  可用 已用% 挂载点
/dev/sda1       459G  8.6G  427G    2% /
...
/dev/sdc1       3.6T   89M  3.4T    1% /home/songtianlun/data

参考文献

本作品采用 知识共享署名 4.0 国际许可协议 进行许可
标签: linux分区 linux服务器 linux系统 硬盘 硬盘存储
最后更新:2023年6月24日

Linux大神网

每日更新,欢迎收藏♥ 不积跬步无以至千里,加油,共勉。

点赞
< 上一篇
下一篇 >

Linux大神网

每日更新,欢迎收藏♥
不积跬步无以至千里,加油,共勉。

最新 热点 随机
最新 热点 随机
车市新战局:汽车操作系统会复制智能手机的历史吗? Linux文件系统种类 如何卸载用源码包安装的软件?在线视频教程推荐 「职位」ASP.、PHP、Linux服务器集群开发 Torvalds:Linux内核开发的创新前景充满了热情 Linux文件系统的结构从终端窗口探索Linux目录树结构 卸载软件命令Linux.You linux软件开发如何入门?学习Linux步骤及学习方法介绍 14年Linux发行版的有趣历史观点 Linux中不像Windows可以直接在控制面板中卸载? 2018年波及众多Linux发行版的性能对比会更加深入 如何用源码包安装的软件?name的方法总结 Linux之父李纳斯托瓦兹开发的Linux只是一个内核 Linux系统中的apt和apt-get的区别及解决办法! Linux系统发行版的一种方法,除此以外 MacM1上安装Docker和CentOS,您需要遵循的步骤 linux光驱启动怎么设置 常见的几种设置方法,你知道几个? 关于ESXi主机磁盘空间回收的具体操作步骤及步骤 Linux设置显示中文和设置字体设置中文一个都不能少 如何在Linux系统中使用命令查看Linux发行版版本信息
嵌入式Linux操作系统学习规划+LINUX路线,主攻江苏电信天翼校园客户端故障指引及解决办法(101)英特尔GMAGMA950显卡驱动程序/WIN8/8.1电信校园网宽带用USB数据线共享给电脑无线上网国防科大开源操作系统:它只是一个吉祥的象征10个常用Linux文本查看命令及其详细说明和使用示例Linux嵌入式系统内核裁剪与定制方法的介绍情况淘宝教育热卖C语言编程开发C++程序设计零基础入门课程从CPU、内存、硬盘、显卡等这些方面安装Linux系统的最低配置Linux通过chkconfig设置开机启动服务创建的几种常见方式(技术分析)Linux多线程的使用与操作系统的区别通常rar命令由一个主命令加若干选项(可选)构成RedHatLinux中自动运行程序中的应用linux 读写文件 关于Linux内核的神秘面纱,你知道几个?使用wget实用程序的有用命令行工具的使用怎么设置linux开机项自启动?方式是怎样的?嵌入式Linux应用层与驱动层要想学习关于Linux内核的交叉编译步骤和方法:步骤、方法STM32嵌入式linux开发流程及应用程序分析-STMlinux下有哪些文件在介绍lsof命令实用用法介绍?
Linux中修改文件权限的命令、创建者所在组、所有人 贝锐官网向日葵LinuxX系统安装路径下载及下载 Linux一模一样远程连接编辑的操作图是什么? Java安装JDK.8.0-171(JavaDevelopmentKit)安装 库是什么?库的分类、分类库、动态库 嵌入式Linux应用开发完全手册代码2.能写简单汇编代码 我试图将从java作业获得的时间信息与linux性能监视工具 Linux自主访问控制机制模块详细解析之自动运行程序 linux下一些常用的关机/重启命令,你知道吗? UNIX网络编程卷1:套接字联网API第3版pdf百度网盘下载地址 详解Linux安装JDK步骤,轻松配置开发环境 Linux操作系统提权漏洞的解决办法有哪些?-八维教育 proc的缩写与内核相关的文件-上海怡健医学 Linux集群设置免密操作ssh分发的注意事项! 快速解决Java服务线上CPU问题,掌握排查思路! Linux中进程间通信有多少方式,分别是什么? LinuxDNS服务器,如何安装、配置和维护它? 一下,网络编程环境高级编程(第二版) Linux版本(1)RedHatLinux内核0.02版正式诞生 文件永久删除还能找回来吗?关于Win和Mac系统的恢复方法
标签聚合
虚拟机 linux系统 文件目录 应用 软件 linux服务器 内核 文件 操作 命令
书籍
课程
技术群
技术干货大合集↓
  • 2023年9月 / 70篇
  • 2023年8月 / 93篇
  • 2023年7月 / 94篇
  • 2023年6月 / 90篇
  • 2023年5月 / 93篇
  • 2023年4月 / 90篇
  • 2023年3月 / 129篇
  • 2023年2月 / 84篇
  • 2023年1月 / 161篇
  • 2022年12月 / 187篇
  • 2022年11月 / 76篇
友情链接:

Linux书籍 | Linux命令 | Linux系统 | RHCE红帽认证 | Linux软件 | Linux教程 | CentOS系统 | Linux内核 | Linux服务器 | Linux大神 | IT资源

COPYRIGHT © 2023 linuxgod.net ALL RIGHTS RESERVED.