Linux分区命令-fdisk&mkfs,磁盘配置步骤

fdisk

进行硬盘分区,一种格式化方式,用fdisk可以对硬盘进行主分区、扩展分区。在创建扩展分区后,可以创建逻辑分区。

fdisk -l
查看系统所有硬盘及分区

[root@xxx /gogo]# :fdisk -l

Disk /dev/sda: 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: 0x000d2163

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    41943039    19921920   8e  Linux LVM

fdisk -l 指定分区
查看指定分区的信息

[root@xxx /gogo]# :fdisk -l /dev/sdb6

Disk /dev/sdb6: 5365 MB, 5365563392 bytes, 10479616 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

fdisk 磁盘名称(/dev/sda) #创建或修改磁盘的分区结构

    参数:
	p:打印分区表
	n:新建一个新分区
	d:删除一个分区
	m:输出菜单
	q:退出不保存
	w:把分区写进分区表,保存并退出

创建主分区

[root@xxx /gogo]# :fdisk /dev/sdc
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 0xc2957253.
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): 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +10G
Partition 1 of type Linux and of size 10 GiB is set

Command (m for help): W
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
You have new mail in /var/spool/mail/root

注:若报错Device or resource busy. The kernel still uses the old table.The new table will be used at the next reboot。可以执行partprobe解决或者重启。

创建扩展分区

[root@xxx /gogo]# :fdisk /dev/sdc
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.


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

Command (m for help): w
The partition table has been altered!

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

创建逻辑分区

[root@xxx /gogo]# :fdisk /dev/sdc
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.


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

Command (m for help): w
The partition table has been altered!

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

查看一下分区信息
Linux分区命令-fdisk&mkfs,磁盘配置步骤_第1张图片
partprobe

 格式:partprobe 磁盘名 	#将磁盘的最新分区状况发送给内核

警告提示:若提示Device or resource busy. The kernel still uses the old table.The new table will be used at the next reboot。也可不必重启,从而解决设备占用的问题。

mkfs

格式:mkfs 选项 分区名称

-t	文件系统,指定文件系统类型ext3、ext4、xfs。若不指定-t,默认是ext3

mkfs命令非常简单易用,不过不能调整分区的默认参数(比如块大小是4096)
一些文件类型
[root@xxx /gogo]# :mkfs
mkfs         mkfs.btrfs   mkfs.cramfs  mkfs.ext2    mkfs.ext3    mkfs.ext4    mkfs.minix   mkfs.xfs

指定sdc2分区为ext4文件格式等...
[root@xxx /gogo]# :mkfs.ext4 /dev/sdc2
[root@xxx /gogo]# :mkfs.xfs /dev/sdc5

扩展一个命令

mke2fs 设置文件类型,block大小以及inode数

eg:**mke2fs -t  ext4 –b4096 –i4096 /dev/sdb1**	

格式:mke2fs 选项 分区名称
-t 文件系统:指定格式化成哪种文件系统类型ext3、ext4,暂不支持xfs
-b 字节:指定格式化时,每个block 的大小
-i 字节:指定多少字节分配一个inode号
使用-i 指定分区的inode数量时,必须同时指定block的大小

配置磁盘信息步骤

  1. 先分区,赋予文件格式

  2. 建立挂载点

    mkdir –p /disk/movie	
    
  3. 挂载

    mount	/dev/sdb1	/disk/movie
    
  4. 查看

    mount			#查看已挂载的所有设备
    df	-h			#查看分区占用百分比
    
  5. 自动挂载–/etc/fstab
    Linux分区命令-fdisk&mkfs,磁盘配置步骤_第2张图片

    第一列:设备文件名(UUID)

        查看UUID的方式:
    	dumpe2fs -h	分区名称
    	ls –l /dev/disk/by-uuid/
    	或者命令blkid
    

    第二列:挂载点
    第三列:文件系统类型
    第四列:挂载特殊选项
    第五列:是否备份: 0 不备份 1 每天备份 #备份
    第六列:是否检查磁盘状态: 0 不检查 1 启动时检查 2 启动后检查

你可能感兴趣的:(网络安全)