星空5G 导航

在LINUX系统中,分区与格式化硬盘的命令是什么?-

2024-09-12编辑:本站
Linux系统格式化分区用哪个命令~

以下操作针对硬盘小于2T包括2T硬盘
如下为新加一个SCSI硬盘,分区为扩展分区,且只包含1个逻辑分区sdb1,然后格式化为ext3,挂载到/test,增加到/etc/fstab系统启动时自动挂:
1、给硬盘分区
fdisk /dev/sda
Command (m for help): n
Command action
e extended
p primary partition (1-4)
输入:e
Partition number (1-4): 1
First cylinder (1-9729, default 1):回车
Last cylinder or +size or +sizeM or +sizeK (1-9729, default 9729):回车
Command (m for help):w(保存退出)
2、格式化硬盘【5分享】上有教程

parted /dev/sdX (用part命令对3T硬盘进行分区处理)

mklabel gpt (用gpt格式可以将3TB弄在一个分区里)

unit TB
(设置单位为TB)

mkpart primary 0 3 (设置为一个主分区,大小为3TB,开始是0,结束是3)

print (显示设置的分区大小)

quit
(退出parted程序)

mkfs.ext3 /dev/sdX1 (用parted将分区做好后,进行格式化操作,完成后即可挂载使用)

mount /dev/sdX1 /mnt 挂载使用

Linux下常用的分区工具:
fdisk/sfdisk:命令行工具,各种版本和环境都能使用,包含在软件包util-linux中
diskdruid:图形化分区工具,只能在安装REDHAT系统时使用。

第一步:fdisk
[root@novice ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 254 MB, 254017536 bytes
8 heads, 61 sectors/track, 1016 cylinders, total 496128 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 identifier: 0x00000000

Device Boot Start End Blocks Id System

[root@novice ~]# fdisk /dev/sdb

Command (m for help): #在输入上面的命令后会出现左边的提示,输入m就会得到一个帮助菜单,如下:
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
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)
#help虽然是英文的,可都很简单,在这里不再解释。

#现在,我们正式开始分区的操作:
Command (m for help): n #新建分区
Command action
e extended
p primary partition (1-4)
#e/p分别对应扩展分区 /主分区;我们先分四个主分区,每个50M;然后再来增加主分区或扩展分区,看会出现怎样的状况,嘿嘿。
p #分区类型为主分区
Partition number (1-4, default 1): 1 #分区号,在这里我们依次选择1、2、3、4
First sector (2048-496127, default 2048): #指定分区的起始扇区,一般默认,按enter键即可。
Last sector, +sectors or +size{K,M,G} (2048-496127, default 496127): +50M #指定分区的终止扇区,根据前面的提示我们可以做出相应的选择+sectors 或 +size{K,M,G}
Command (m for help): p #用p打印出已建好的分区列表

Disk /dev/sdb: 254 MB, 254017536 bytes
8 heads, 61 sectors/track, 1016 cylinders, total 496128 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 identifier: 0x00000000

Device Boot Start End Blocks Id System
/dev/sdb1 2048 104447 51200 83 Linux

#剩下的三个分区的建立操作同上
#分好四个主分区后的情况如下
Command (m for help): p

Disk /dev/sdb: 254 MB, 254017536 bytes
8 heads, 61 sectors/track, 1016 cylinders, total 496128 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 identifier: 0x00000000

Device Boot Start End Blocks Id System
/dev/sdb1 2048 104447 51200 83 Linux
/dev/sdb2 104448 206847 51200 83 Linux
/dev/sdb3 206848 309247 51200 83 Linux
/dev/sdb4 309248 309298 25+ 83 Linux
#已经建好四个主分区啦,现在我们来看看如果再建主分区或是扩展分区的话会出现怎样的情况:
Command (m for help): n
You must delete some partition and add an extended partition first
#看到了吧,不能再建分区啦!要再建分区的话必须删除some分区,再新建一个扩展分区才行。
#现在,我们删掉一个主分区,来新建扩展分区
Command (m for help): d #删除分区
Partition number (1-4): 4 #选择要删除分区的分区号,我们选第四个

Command (m for help): p #打印,如下,四个分区变成了三个!

Disk /dev/sdb: 254 MB, 254017536 bytes
8 heads, 61 sectors/track, 1016 cylinders, total 496128 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 identifier: 0x00000000

Device Boot Start End Blocks Id System
/dev/sdb1 2048 104447 51200 83 Linux
/dev/sdb2 104448 206847 51200 83 Linux
/dev/sdb3 206848 309247 51200 83 Linux

#新建一个扩展分区
#如果在没有建满三个主分的区的情况下建立扩展分区,相关选项会有些不同。
Command (m for help): n
Command action
e extended
p primary partition (1-4)
e
Selected partition 4
First sector (309248-496127, default 309248): #enter,默认
Using default value 309248
Last sector, +sectors or +size{K,M,G} (309248-496127, default 496127): #enter,默认,使用剩余空间
Using default value 496127

Command (m for help): p

Disk /dev/sdb: 254 MB, 254017536 bytes
8 heads, 61 sectors/track, 1016 cylinders, total 496128 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 identifier: 0x00000000

Device Boot Start End Blocks Id System
/dev/sdb1 2048 104447 51200 83 Linux
/dev/sdb2 104448 206847 51200 83 Linux
/dev/sdb3 206848 309247 51200 83 Linux
/dev/sdb4 309248 496127 93440 5 Extended

#接下来,我们在新建的扩展分区里再新建两个逻辑分区,因为已经有了三个主分区,这里不会再显示是建立逻辑分区还是主分区的提示!
Command (m for help): n
First sector (311296-496127, default 311296): #enter
Using default value 311296
Last sector, +sectors or +size{K,M,G} (311296-496127, default 496127): +50M

Command (m for help): n
First sector (415744-496127, default 415744): #enter
Using default value 415744
Last sector, +sectors or +size{K,M,G} (415744-496127, default 496127): #enter
Using default value 496127

Command (m for help): p

Disk /dev/sdb: 254 MB, 254017536 bytes
8 heads, 61 sectors/track, 1016 cylinders, total 496128 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 identifier: 0x00000000

Device Boot Start End Blocks Id System
/dev/sdb1 2048 104447 51200 83 Linux
/dev/sdb2 104448 206847 51200 83 Linux
/dev/sdb3 206848 309247 51200 83 Linux
/dev/sdb4 309248 496127 93440 5 Extended
/dev/sdb5 311296 413695 51200 83 Linux
/dev/sdb6 415744 496127 40192 83 Linux
#上面的列表,就是我们今天分区的成果啦!接下来保存退出,重启计算机,就可以进行下一步的mkfs操作啦!如果忘记了相关的操作命令,记得按m!!!
Command (m for help): w #保存
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

另:在建好分区后,我们还可以更改相关分区的文件系统类型
#如,我们要把第二个主分区改成Linux下的交换分区,操作如下
Command (m for help): t #更改文件系统类型
Partition number (1-6): 2 #选择第二个分区
Hex code (type L to list codes): L #选择要更改的文件系统编码,可以按L来查看相关编码信息。
0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
............
16 Hidden FAT16 64 Novell Netware af HFS / HFS+ fb VMware VMFS
17 Hidden HPFS/NTF 65 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 70 DiskSecure Mult b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 75 PC/IX bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 80 Old Minix be Solaris boot ff BBT
1e Hidden W95 FAT1
Hex code (type L to list codes): 82 #查找到linux swap的编码为82
Changed system type of partition 2 to 82 (Linux swap / Solaris)
Command (m for help): p
..............
Device Boot Start End Blocks Id System
/dev/sdb1 2048 104447 51200 83 Linux
/dev/sdb2 104448 206847 51200 82 Linux swap / Solaris
/dev/sdb3 206848 309247 51200 83 Linux
/dev/sdb4 309248 496127 93440 5 Extended
/dev/sdb5 311296 413695 51200 83 Linux
/dev/sdb6 415744 496127 40192 83 Linux
#最后别忘了保存!如果你须要的话!
#扩展分区不能直接使用,逻辑分区只能建立在扩展分区上!

第二步:mkfs(mkfs时分区的格式最好与fdisk设定的分区格式一致,不然.......)
mkfs支持ext2 ext3 vfa msdos jfs reiserfs等文件系统。
用法1:mkfs -t
例: mkfs -t ext3 /dev/sdb2

用法2:mkfs.
例:mkfs,vfat /dev/sdb3

mke2fs支持ext2/ext3文件系统
用法:mke2fs [-j]
例:mke2fs -j /dev/sdb5
# 更多更具体的用法请参照相关命令的man手册

下面,接着实验:
例一
[root@novice ~]# mkfs -t ext3 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
12824 inodes, 51200 blocks
2560 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=52428800
7 block groups
8192 blocks per group, 8192 fragments per group
1832 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961

Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 34 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

第三部:挂载
挂载:mount
例:mount /dev/sdb1 /mnt /sdb1

卸载:umonut
例:umount /dev/sdb1

  • 在LINUX系统中,分区与格式化硬盘的命令是什么?
  • 答:fdisk/sfdisk:命令行工具,各种版本和环境都能使用,包含在软件包util-linux中 diskdruid:图形化分区工具,只能在安装REDHAT系统时使用。第一步:fdisk[root@novice ~]# fdisk -l /dev/sdb Disk /dev/sdb: 254 MB, 254017536 bytes 8 heads, 61 sectors/track, 1016 cylinders, total 496128 sectors Units = sec...

  • 如何在Linux中使用Gparted进行硬盘分区和格式化?
  • 答:apt-get install gparted来安装Gparted。至于命令行的格式化,Linux中常用的有mkfs命令,如mkfs.ext3、mkfs.vfat、mkfs.ntfs和mkfs.xfs等。例如,格式化/dev/sda1为Ext3文件系统,命令为 mkfs.ext3 /dev/sda1在添加新硬盘和分区时,首先了解Linux的设备命名规则。IDE设备如hda、hdb,而SCSI设备则为sda...

  • Linux系统下添加新硬盘,分区,格式化相关步骤
  • 答:  比如我们一般的系统都有一个主分区用来引导系统,这个分区对应我们常说的C区,在linux下命名是hda1。后面我们分三个逻辑分区对应常说的D、E、F,在linux下命名是hda5、hda6、hda7 给硬盘分区   在slackware下有两个分区软件fdisk和cfdisk   例如我们已经有一...

  • Deepin Linux如何格分区、格式化新硬盘?
  • 答:Deepin Linux系统上分区、格式化硬盘都非常简单,因为有图形化的界面操作程序,不需要额外在终端执行命令了。具体参考如下步骤。点击任务栏的启动器,找到分区编辑器。运行分区编辑器,会提示用户输入当前登录用户的密码来进行授权。打开分区编辑器后,选择要分区的硬盘,我这里是2TB的机械硬盘 选择好要操作的...

  • linux中分区linux下分区
  • 答:在Windows下,虚拟内存是一个文件:pagefile.sys;而Linux下,虚拟内存需要使用独立分区,这样做的目的据说是为了提高虚拟内存的性能。3、/home:是用户文件夹所在的地方。如果独立划分/home,即使Ubuntu不能启动,也可以用LiveCD启动来取得自己的文件资料。4、/boot:包含了操作系统的内核和在启动系统过程...

  • linux如何格式化linux下格式化
  • 答:linux下格式化磁盘命令?磁盘分割完毕后自然就是要进行文件系统的格式化,格式化的命令非常的简单,使用mkfs(makefilesystem)命令。1.尽管磁盘分为多个分区,但仍无法使用.需要在每个分区上对其进行格式化.所谓格式化实际上就是安装文件系统.Windows下的文件系统包括Fat32,NTFS和CentOS.文件系统是ext,以前的...

  • Linux系统分区
  • 答:Linux默认可分为3个分区,分别是boot分区、swap分区和根分区。boot分区 在linux中,boot是存储内核及在引导过程中使用文件的分区,是启动linux时使用的一些核心文件;在boot中包括了系统Kernel的配置文件、启动管理程序GRUB的目录、启动时的模块供应的主要来源Initrd文件和vmlinuz文件。/boot分区就是操作系统的...

  • 安装linux系统对硬盘分区时,必须有的两种分区类型是什么?
  • 答:安装Linux系统对硬盘分区时,必须有两种分区类型: 根分区和交换分区。根分区就是root分区,所有的东西都在这个分区内。 /swap分区是交换分区,是一定磁盘空间(分区或文件),用于将部分内存中的数据换下来,以腾出内存空间用于其他需求。在一个系统中,物理内存快使用完时,操作系统会使用交换分区。当...

  • linux服务器分区怎么分linux服务器分区
  • 答:在Linux操作系统中,除/boot目录外的其它所有目录都对应于该分区.因此,用户可通过访问除/boot目录外的其它所有目录来访问该分区。linux乌班图如何分区?安装的时候自动分区,或者选择手动分区都可以,一般'/'和/home目录不要挂载到一个硬盘分区上就可以了。ubuntutemp分区作用?Ubuntu是Linux的一种。1.在...

  • linux磁盘格式化命令linux磁盘格式化
  • 答:linux系统怎么格式化win10?我们以Windows10操作系统为例。假设之前也安装过Linux系统,例如Ubuntu 所使用的分区并不是Windows可以直接使用的。那么现在如果需要利用这部分硬盘空间,需要做相应的操作。首先,右击Windows系统中的“这台电脑”点击“管理”2 然后点击存储、磁盘管理 3 如果有一些非Windows可以直接...

    相关内容

    首页 新知 身健
    返回顶部

    © 星空5G w.xkyn.com