fdisk
Perform hard disk partitioning, a formatting method. Use fdisk to perform main partition and extended partition on the hard disk. After creating an extended partition, you can create a logical partition.
fdisk -l
view all hard disks and partitions of the system
[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 specified partition
View the information of the specified partition
[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 Disk name (/ dev / sda) #Create or modify the partition structure of the disk
参数:
p:打印分区表
n:新建一个新分区
d:删除一个分区
m:输出菜单
q:退出不保存
w:把分区写进分区表,保存并退出
Create a primary partition
[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
Note: If an error is reported Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot. Can perform partprobe to solve or restart.
Create Extended Partition
[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.
Create logical partition
[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.
Check the partition information
partprobe
格式:partprobe 磁盘名 #将磁盘的最新分区状况发送给内核
Warning prompt: If prompted Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot. There is no need to restart, so as to solve the problem of equipment occupation.
mkfs
Format: mkfs option partition name
-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
Expand a command
mke2fs sets the file type, block size and inode number
eg:**mke2fs -t ext4 –b4096 –i4096 /dev/sdb1**
Format: mke2fs option partition name
-t file system: specify which file system type is formatted as ext3, ext4, xfs
-b bytes are not supported yet : specify the size of each block when formatting
-i bytes: specify how many words Assign an inode number to the section
When using -i to specify the number of partition inodes, you must also specify the block size
Steps to configure disk information
-
Partition first, give file format
-
Create a mount point
mkdir –p /disk/movie
-
Mount
mount /dev/sdb1 /disk/movie
-
View
mount #查看已挂载的所有设备 df -h #查看分区占用百分比
-
Automount-/ etc / fstab
First column: device file name (UUID)
查看UUID的方式: dumpe2fs -h 分区名称 ls –l /dev/disk/by-uuid/ 或者命令blkid
Second column: Mount point
Third column: File system type
Fourth column: Mount special options
Fifth column: Whether to back up: 0 Do not back up 1 Daily backup #Back up
Sixth column: Whether to check disk status: 0 Do not check 1 Check at startup 2 Check at startup