linux硬盘分区命令

作者&投稿:养伟 (若有异议请与网页底部的电邮联系)
Linux查看分区的命令是什么~

一、df -lh 命令
df 是来自于coreutils 软件包,系统安装时,就自带的;我们通过这个命令可以查看磁盘的使用情况以及文件系统被挂载的位置;
[root@localhost ~]# df -l
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 4956316 3565088 1135396 76% /
tmpfs 241320 12 241308 1% /dev/shm
/dev/sda6 4806904 2523708 2039012 56% /media/disk
/dev/sda1 4956284 3529796 1170656 76% /media/_
/dev/sda5 4845056 2581484 2019388 57% /media/disk-1
可以看到系统挂在sda3上,另外还挂了sda6/sda1/sda5三个系统。


二、fdisk -l 命令
fdisk 是一款强大的磁盘操作工具,来自util-linux软件包,我们在这里只说他如何查看磁盘分区表及分区结构;通过-l 参数,能获得机器中所有的硬盘的分区情况;
[root@localhost ~]# fdisk -l
Disk /dev/sda: 40.0 GB, 40000000000 bytes
255 heads, 63 sectors/track, 4863 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x62a9f8d0
Device Boot Start End Blocks Id System
/dev/sda1 * 1 637 5116671 83 Linux
/dev/sda2 638 891 2040255 82 Linux swap / Solaris
/dev/sda3 892 1528 5116702+ 83 Linux
/dev/sda4 1529 2744 9767520 5 Extended
/dev/sda5 1529 2136 4883728+ 83 Linux
/dev/sda6 2137 2744 4883728+ 83 Linux
sda1

是MBR(主引导记录)所在的分区;sda2是交换分区;sda4是扩展分区,包括了sda5,sda6两个逻辑分区。系统划分分区的时候只能划分4个主
分区(扩展分区也算主分区),我在上面分了3个主分区+1个Extended分区,5.6是逻辑分区。所以才会有sda1.2.3.4.5.6。如果你只
划分了1个主分区+1个扩展分区,那么逻辑分区就从sda5开始了,sda1.2.5.6...


三、cfdisk -Ps命令 (注意P是大写)
cfdisk 也是一款不错的分区工具;在有些发行版中,此工具已经从util-linux包中剔除;cfdisk 简单易用是他的特点;
查看磁盘分区的用法 cfdisk -Ps 磁盘设备名 只有一个硬盘也可以用 cfdisk -Ps
例1:[root@localhost ~]# cfdisk -Ps
Partition Table for /dev/sda
First Last
# Type Sector Sector Offset Length Filesystem Type (ID) Flag
-- ------- ----------- ----------- ------ ----------- -------------------- -------
1 Primary 0 10233404 63 10233405 Linux (83) Boot
2 Primary 10233405 14313914 0 4080510 Linux swap / So (82) None
3 Primary 14313915 24547319 0 10233405 Linux (83) None
4 Primary 24547320 44082359 0 19535040 Extended (05) None
5 Logical 24547320 34314839 63 9767520 Linux (83) None
6 Logical 34314840 44082359 63 9767520 Linux (83) None
Logical 44082360 78124094 0 34041735 Free Space None
例2:[root@localhost ~]# cfdisk -Ps /dev/sda
Partition Table for /dev/sda
First Last
# Type Sector Sector Offset Length Filesystem Type (ID) Flag
-- ------- ----------- ----------- ------ ----------- -------------------- ----
1 Primary 0 10233404 63 10233405 Linux (83) Boot
2 Primary 10233405 14313914 0 4080510 Linux swap / So (82) None
3 Primary 14313915 24547319 0 10233405 Linux (83) None
4 Primary 24547320 44082359 0 19535040 Extended (05) None
5 Logical 24547320 34314839 63 9767520 Linux (83) None
6 Logical 34314840 44082359 63 9767520 Linux (83) None
Logical 44082360 78124094 0 34041735 Free Space None


四、parted 命令
parted
功能不错的分区工具;在Fedora 8中有带,可以自己安装上;调用方法简单,parted 默认是打开的设备是/dev/hda
,也可以自己指定;比如 parted /dev/hda 或/dev/sda 等;退出的方法是 quit
输入parted命令后要等会儿才会出现下面的内容:
[root@localhost ~]# parted
GNU Parted 1.8.6
使用 /dev/sda
Welcome to GNU Parted! Type ’help’ to view a list of commands.
(parted)
在光标那里输入p回车出现下面内容:
Model: ATA Maxtor 5T040H4 (scsi)
Disk /dev/sda: 40.0GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End S ize Type File system 标志
1 32.3kB 5240MB 5239MB 主分区 ext3 启动
2 5240MB 7329MB 2089MB 主分区 linux-swap
3 7329MB 12.6GB 5240MB 主分区 ext3
4 12.6GB 22.6GB 10.0GB 扩展分区
5 12.6GB 17.6GB 5001MB 逻辑分区 ext3
6 17.6GB 22.6GB 5001MB 逻辑分区 ext3
(parted)


在光标后面输入quit退出。
五、sfdisk -l
[root@localhost ~]# sfdisk -l
Disk /dev/sda: 4863 cylinders, 255 heads, 63 sectors/track
Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0
Device Boot Start End #cyls #blocks Id System
/dev/sda1 * 0+ 636 637- 5116671 83 Linux
/dev/sda2 637 890 254 2040255 82 Linux swap / Solaris
/dev/sda3 891 1527 637 5116702+ 83 Linux
/dev/sda4 1528 2743 1216 9767520 5 Extended
/dev/sda5 1528+ 2135 608- 4883728+ 83 Linux
/dev/sda6 2136+ 2743 608- 4883728+ 83 Linux

六、也可以使用 应用程序>系统工具>磁盘使用分析器 来查看磁盘使用情况。

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

1.返回到Linux系统的命令终端,再次输入 fdisk -l 命令,就可以看到新添...
2.输入fdisk /dev/sdb 开始对新添加的硬盘进行分区操作。
3.输入n 按回车键,然后再输入 p ,按回车键。 n 表示新建一个分区,p ...
4.输入Partition number(即:分区号),按回车键。如果在 /dev/sdb ...
5.等待分区创建完成,输入 w 保存磁盘分区,并退出磁盘分区命令。


linux系统中\/dev\/sda3表示什么。急
\/dev\/sda3表示的是硬盘分区。\/dev\/sda是指接在SATA、SCSI第一个接口上的硬盘。\/dev\/sda是指整个硬盘,实际使用中一般都会有分区,也就是\/dev\/sda1, \/dev\/sda2这样的。有一些分区已经挂载了,使用df命令,可以看到各个分区分区被挂载到哪个目录,然后ls查看想要查的目录。使用fdisk命令查看分区的三种...

虚拟机里的linux 硬盘分区问题,在线等
1.fdisk \/dev\/sdb 说明: 硬盘分区的表示:在Linux 是通过hd*x 或 sd*x 表示的,其中 * 表示的是a、b、c ... ... x表示的数字 1、2、3 ... ... hd大多是IDE硬盘;sd大多是SCSI或移动存储;n :增加分区的命令 p :主分区 1 :因为你还没有第一个 直接回车 :1开始 ...

Linux硬盘GPT分区和MBR分区
而且,如果没有EFI的支持的话,以上系统也只能将GPT分区的硬盘当成数据盘,不能从GPT分区的硬盘启动; 3、要从GPT分区的硬盘启动,则主板使用EFI、硬盘使用GPT分区、操作系统支持GPT和EFI这三个条件缺一不可。目前比较新的64位Linux系统和Win8系统都是支持EFI的,所以都是需要从GPT分区的硬盘启动的。现在的电脑主板已经...

Linux系统分区
所谓根分区,说白了就是系统分区,是root分区,所有的东西都放在这里面。Linux是一个树形文件系统,根分区就是它的root节点,任何的目录文件都会挂在根节点以下。Linux只有一个根。你可以给你的硬盘进行分区,但是,分区设备一定挂载到linux根目录下的指定位置,如\/usr,\/var,\/home等。如果要对分区进行...

Linux下添加新硬盘,分区并设置启动自动挂载
根据以上提示开始对新的硬盘进行分区操作,由于截图比较麻烦所以呢我把命里copy出来了,需要操作的部分我会标记出来 [root@Linux ~]#fdisk \/dev\/sdb  \/\/根据提示,对新硬盘进行分区操作Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabelBuilding a new DOS ...

linux 分区是什么意思
通常通过在Linux安装时创建分区,使用磁盘分区工具手动划分硬盘,或通过技术支持解决分区问题。您可以使用命令行工具或图形用户界面工具进行分区。使用fdisk或gdisk等命令行工具可以在不降低系统性能的情况下创建分区。或您可以使用gParted等图形用户界面工具来更简单地管理分区。无论您的级别如何,值得注意的是...

linux系统上如何格式化硬盘?
请点击输入图片描述 2 在终端上面输入命令:sudo fdisk -l 回车。然后找到\/dev\/sda \/dev\/sdb这样子的英文。这里电脑上面的硬盘,其中sda则是第一个硬盘,sdb是第二个硬盘。请点击输入图片描述 3 格式化硬盘分区:在终端输入命令:图片里面的命令回车。其中sudo mkfs -t 理解为固定格式即可,ntfs则是...

Linux磁盘管理
-S:不包括子目录下的统计,与-s存在差别;-k:以KBytes列出容量显示;-m:以MBytes列出容量显示。fdisk命令 fdisk是Linux的磁盘分区表操作工具。语法:fdisk[-l]装置名称 参数:-l:输出后面接的装置所有的分区内容。若仅有fdisk -l时,则系统将会把整个系统内能够搜寻到的装置的分区均列出来。

linux硬盘扩展分区linux硬盘扩展
怎么扩充vbox虚拟机linux磁盘空间?1.扩展VBOX中的硬盘分配大小; 2.在虚拟Linux中增加并挂载新分区. 如何取得vdi文件的UUID: 查看虚拟机文件:虚拟机名.vbox> 找到行:HardDiskuuid="{d07126c5-4b89-4eb7-89c7-725bbb92d0b0}"location="CentOSVirtualHardDisk.vdi"format="VDI"type="Normal"\/> ...

安装linux系统时怎么手动分区
1、首先打开linux系统。再用fdisk -l查询磁盘信息。2、然后创建一个磁盘分区。命令为fdisk 磁盘设备名称。3、然后按m查看命令解析。再按n创建磁盘。4、然后用p命令创建主分区。再设置分区的序列号。5、然后设置磁盘的大小。再用t更改磁盘的分区格式。

振兴区15324786308: Linux如何给硬盘分区?
言别盐酸: 一、查看当前的磁盘分区1使用root用户登录到Linux系统.Linux如何添加磁盘分区2右键点击计算机桌面空白处,点击“Open Teminal”,打开命令终端.Linux如何添加磁盘分区3输入 fdisk -l 命令,查看当前系统的磁盘分区.Linux如何添加磁盘...

振兴区15324786308: 如何在Linux操作系统中新建磁盘分区 -
言别盐酸: Linux下可以用fdisk命令新建分区,方法如下:1、首先用fdisk -l命令查看硬盘信息,硬盘有剩余空间就可以对其进行分区.2、假设/dev/sdb 没有使用,用 fdisk /dev/sdb [不会用请进入命令后根据提示键入m获得帮助]3、有扩展分区和主分区,逻...

振兴区15324786308: 在linux系统中下面哪个命令可用来建立分区 -
言别盐酸: Linux下常用的分区工具: fdisk/sfdisk:命令行工具,各种版本和环境都能使用,包含在软件包util-linux中 diskdruid:图形化分区工具,只能在安装REDHAT系统时使用.第一步:fdisk [root@novice ~]# fdisk -l /dev/sdb Disk /dev/sdb: 254 MB, ...

振兴区15324786308: linux中磁盘分区的命令是什么?
言别盐酸:fdisk这个命令

振兴区15324786308: linux中添加新硬盘并进行分区和格式化的命令
言别盐酸: 将你的硬盘接到主板上后,开机进系统fdisk -l 查看新加入的硬盘类型,如:hdb or sdb然后fdisk /dev/hdb后面的命令,自己man去吧.

振兴区15324786308: red hat linux如何进行手工分区? -
言别盐酸: linux手工分区有很多中,我就不一一说了,我说的是最简单的,普遍的...分区:1、 挂载点 :/boot (引导分区) 文件格式:ext3 (默认) 指定大小:100MB~150MB (redhat默认一般为100MB)2、 挂载点 : (挂载点为空,此为交换分区) 文件...

振兴区15324786308: linux如何对硬盘分区
言别盐酸: 使用fdisk命令对硬盘进行分区

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网