Linux运维学习-磁盘管理之磁盘分区/格式化/挂载

fdisk命令 

fdisk命令:用于观察硬盘实体使用情况,也可对硬盘分区

参数:

-b<分区大小>:指定每个分区的大小;

-l:列出指定的外围设备的分区表状况;

-s<分区编号>:将指定的分区大小输出到标准输出上,单位为区块;

-u:搭配"-l"参数列表,会用分区数目取代柱面数目,来表示每个分区的起始地址;

-v:显示版本信息。

对磁盘/dev/sdb分区:交互式

[root@localhost ~]# fdisk /dev/sdb
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 0x93aac219.

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
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   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)

Command (m for help):

创建主分区:

查看分区信息:

Command (m for help): p   

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0x93aac219

   Device Boot      Start         End      Blocks   Id  System


创建主分区:

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

Command (m for help): p

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0x93aac219

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     2099199     1048576   83  Linux

Command (m for help):

创建逻辑分区:

查看分区信息:

Command (m for help): p

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0x94c8b371

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): 


创建扩展分区:
逻辑分区建立在扩展分区之上,所以要先建立扩展分区

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): e
Partition number (1-4, default 1): 4
First sector (2048-41943039, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +2G
Partition 4 of type Extended and of size 2 GiB is set

Command (m for help): 
Command (m for help): p

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0x94c8b371

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb4            2048     4196351     2097152    5  Extended

Command (m for help):


创建逻辑分区:

Command (m for help): n  
Partition type:
   p   primary (0 primary, 1 extended, 3 free)
   l   logical (numbered from 5)
Select (default p): l
Adding logical partition 5
First sector (4096-4196351, default 4096): 
Using default value 4096
Last sector, +sectors or +size{K,M,G} (4096-4196351, default 4196351): +1G
Partition 5 of type Linux and of size 1 GiB is set

Command (m for help): 
Command (m for help): p

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0x94c8b371

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb4            2048     4196351     2097152    5  Extended
/dev/sdb5            4096     2101247     1048576   83  Linux

Command (m for help):

创建交换分区(swap):

交换分区使用主分区还是逻辑分区都可

查看分区信息:

Command (m for help): p

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0x94c8b371

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb4            2048     4196351     2097152    5  Extended
/dev/sdb5            4096     2101247     1048576   83  Linux

Command (m for help): 


改变分区system id:

Command (m for help): t
Partition number (4,5, default 5): 5
Hex code (type L to list all codes): L

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris        
 1  FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-
 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     85  Linux extended  c7  Syrinx         
 5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data    
 6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility   
 8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt         
 9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access     
 a  OS/2 Boot Manag 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O        
 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor      
 c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad hi eb  BeOS fs        
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         ee  GPT            
 f  W95 Ext'd (LBA) 54  OnTrackDM6      a6  OpenBSD         ef  EFI (FAT-12/16/
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        f0  Linux/PA-RISC b
11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f1  SpeedStor      
12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f4  SpeedStor      
14  Hidden FAT16 <3 61  SpeedStor       ab  Darwin boot     f2  DOS secondary  
16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      fb  VMware VMFS    
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE 
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fd  Linux raid auto
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fe  LANstep        
1c  Hidden W95 FAT3 75  PC/IX           be  Solaris boot    ff  BBT            
1e  Hidden W95 FAT1 80  Old Minix      
Hex code (type L to list all codes): 82
Changed type of partition 'Linux' to 'Linux swap / Solaris'

Command (m for help): 
Command (m for help): p

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0x94c8b371

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb4            2048     4196351     2097152    5  Extended
/dev/sdb5            4096     2101247     1048576   82  Linux swap / Solaris

Command (m for help): 

mkfs命令

mkfs命令:创建文件系统

参数:

-t<文件系统类型>:指定要建立何种文件系统;

-v:显示版本信息与详细的使用方法;

-V:显示简要的使用方法;

-c:在制做档案系统前,检查该partition是否有坏轨

[root@localhost ~]# fdisk -l /dev/sdb

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0x94c8b371

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1         4196352     6293503     1048576   83  Linux
/dev/sdb4            2048     4196351     2097152    5  Extended
/dev/sdb5            4096     2101247     1048576   82  Linux swap / Solaris

Partition table entries are not in disk order
[root@localhost ~]#
创建/dev/sdb1的文件系统为XFS:

[root@localhost ~]# mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1              isize=512    agcount=4, agsize=65536 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=262144, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@localhost ~]# 
[root@localhost ~]# 
[root@localhost ~]# lsblk -f /dev/sdb1
NAME FSTYPE LABEL UUID                                 MOUNTPOINT
sdb1 xfs          09c07f46-8ce3-4268-81b2-648e96ff42c4 
[root@localhost ~]# 

mkswap命令

mkswap命令:创建swap文件系统

参数:

-c:建立交换区前,先检查是否有损坏的区块;

-f:在SPARC电脑上建立交换区时,要加上此参数;

-v0:建立旧式交换区,此为预设值;

-v1:建立新式交换区。

[root@localhost ~]# fdisk -l /dev/sdb

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0x94c8b371

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1         4196352     6293503     1048576   83  Linux
/dev/sdb4            2048     4196351     2097152    5  Extended
/dev/sdb5            4096     2101247     1048576   82  Linux swap / Solaris

Partition table entries are not in disk order
[root@localhost ~]# 
建立交换分区文件系统类型为swap:

[root@localhost ~]# mkswap /dev/sdb5
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=72ddff37-9504-4f35-a7d0-ba5a04d7ea7b
[root@localhost ~]# 
[root@localhost ~]# lsblk -f /dev/sdb5
NAME FSTYPE LABEL UUID                                 MOUNTPOINT
sdb5 swap         72ddff37-9504-4f35-a7d0-ba5a04d7ea7b 
[root@localhost ~]# 

mount命令

mount命令:用于挂载

参数:

-V:显示程序版本;

-l:显示已加载的文件系统列表;

-h:显示帮助信息并退出;

-v:冗长模式,输出指令执行的详细信息;

-n:加载没有写入文件“/etc/mtab”中的文件系统;

-r:将文件系统加载为只读模式;

-a:加载文件“/etc/fstab”中描述的所有文件系统。

[root@localhost ~]# mkdir /backup1
[root@localhost ~]# 

将/dev/sdb1挂载到/backup1目录:

[root@localhost ~]# mount /dev/sdb1 /backup1/
[root@localhost ~]# 
[root@localhost ~]# df -hT /dev/sdb1
Filesystem     Type  Size  Used Avail Use% Mounted on
/dev/sdb1      xfs  1014M   33M  982M   4% /backup1
[root@localhost ~]# 

swapon命令

swapon命令:加载交换分区

[root@localhost ~]# swapon -s
Filename				Type		Size	Used	Priority
/dev/dm-1                              	partition	2097148	0	-1
[root@localhost ~]# 
[root@localhost ~]# swapon /dev/sdb5
[root@localhost ~]# 
[root@localhost ~]# swapon -s
Filename				Type		Size	Used	Priority
/dev/dm-1                              	partition	2097148	0	-1
/dev/sdb5                              	partition	1048572	0	-2
[root@localhost ~]# 

df命令

df命令:查看挂载情况

 

[root@localhost ~]# df -h
Filesystem             Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root   17G  1.2G   16G   7% /
devtmpfs               902M     0  902M   0% /dev
tmpfs                  912M     0  912M   0% /dev/shm
tmpfs                  912M  8.6M  904M   1% /run
tmpfs                  912M     0  912M   0% /sys/fs/cgroup
/dev/sda1             1014M  139M  876M  14% /boot
tmpfs                  183M     0  183M   0% /run/user/0
/dev/sdb1             1014M   33M  982M   4% /backup1
[root@localhost ~]# 

参数:

-a或--all:包含全部的文件系统;

--block-size=<区块大小>:以指定的区块大小来显示区块数目;

-h或--human-readable:以可读性较高的方式来显示信息;

-H或--si:与-h参数相同,但在计算时是以1000 Bytes为换算单位而非1024 Bytes;

-i或--inodes:显示inode的信息;

-k或--kilobytes:指定区块大小为1024字节;

-l或--local:仅显示本地端的文件系统;

-m或--megabytes:指定区块大小为1048576字节;

--no-sync:在取得磁盘使用信息前,不要执行sync指令,此为预设值;

-P或--portability:使用POSIX的输出格式;

--sync:在取得磁盘使用信息前,先执行sync指令;

-t<文件系统类型>或--type=<文件系统类型>:仅显示指定文件系统类型的磁盘信息;

-T或--print-type:显示文件系统的类型;

-x<文件系统类型>或--exclude-type=<文件系统类型>:不要显示指定文件系统类型的磁盘信息;

--help:显示帮助;

--version:显示版本信息 

blkid命令

blkid命令:查看设备UUID和文件系统类型

[root@localhost ~]# blkid
/dev/sdb1: UUID="09c07f46-8ce3-4268-81b2-648e96ff42c4" TYPE="xfs" 
/dev/sdb5: UUID="72ddff37-9504-4f35-a7d0-ba5a04d7ea7b" TYPE="swap" 
/dev/sda1: UUID="fe73ca4f-9600-43bb-a323-bd6fe2c0e83f" TYPE="xfs" 
/dev/sda2: UUID="3qUrn1-1Epa-VUpA-XYcY-G8L4-kqIs-z016AL" TYPE="LVM2_member" 
/dev/sr0: UUID="2016-10-19-18-32-06-00" LABEL="RHEL-7.3 Server.x86_64" TYPE="iso9660" PTTYPE="dos" 
/dev/mapper/rhel-root: UUID="b4469d2e-e64d-426a-884f-d460a53b2823" TYPE="xfs" 
/dev/mapper/rhel-swap: UUID="9d1cd0f5-3b72-490f-baf0-3e11c94671f8" TYPE="swap" 
[root@localhost ~]# 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值