1, Introduction to disk partition
- Primary partition
- The basic partition is also called the primary partition. The total number of boot partition, each disk partition, primary partition and extended partition cannot be greater than four.
- The basic partition can be used immediately after it is created, but there is an upper limit on the number of partitions.
- Extension partition
- Each disk can only be divided into one extended partition
- The extended partition can be divided into any block logical partition
- The extended partition cannot be used directly after it is created. You need to create a logical partition in the extended partition
- Logical partition
- A logical partition is a partition created within an extended partition
- The logical partition is equivalent to a piece of storage medium and is completely independent of the main partition of other logical partitions
2, Disk type introduction
- linux
- The drive identifier is hdx
- Up to 64 partitions of IDE hard disk
- Where "hdx ~" indicates the type of equipment where the partition is located, hd indicates ide, x indicates which disk, ~ indicates partition number
- SCSI HardDisk
- The drive identifier is sdx
- Where "sdx ~" indicates the type of equipment where the partition is located, sd indicates sde, x indicates which disk, and ~ indicates the partition number
- hda1,hda2,hda3,hda5,hda6
- Linux stipulates that each hard disk can have up to 4 primary partitions (including extended partitions). Any occupied partition must occupy the partition number
- Primary partition (including extended partition number): 1 ~ 4 ends. For example: hda1, hda2, hda3
- Logical partition: 5 ~ 16 ends. For example: hda5, hda6
- hda,hdb,hdc,hdd
- Add an alphabetical name after the disk
- a is the basic disk, b is the basic slave disk, c is the auxiliary master disk, and d is the auxiliary slave disk
3, disk command use
Purpose: To observe the physical use of the hard disk and split the hard disk
usage method:
1, Enter fdisk -l /dev/sda on the console to observe the physical usage of the hard disk.
2, Enter fdisk /dev/sda on the console to enter the split hard disk mode.
Parameters: 1. input m Displays a list of all commands. 2. input p Displays the partition of the hard disk. 3. input a Set the boot area of the hard disk. 4. input n Set a new hard disk partition. 4.1. input e Hard disk is[extend]Partition(extend). 4.2. input p Hard disk is[main]Partition(primary). 5. input t Change the partition properties of the hard disk. (used when making exchange partition) 6. input d Delete the hard disk partition attribute. 7. input q End not saving the partition attribute of the hard disk. 8. input w End and write hard disk partition properties 9. input l View partition conversion types. # 1. Enter disk fdisk /dev/sda # 2. Lists the current partition table p # 3. Add new partition n # 4. Select the starting block address and press enter directly. It is OK by default enter # 5. Enter the size of the partition to be added, + 200M, + 1G, which can be recognized +2G # 6. Sure enter # 6. Write and exit w # It is very important to update the current partition table to the kernel, otherwise your partition will not be visible until it is restarted partprobe # Format new partition mkfs.ext3 /dev/sda6 # mount mount /dev/sda6 /data
4, Partition conversion type:
5, Format partition command
5.1 command: select the command according to the format required
mkfifo mkfs mkfs.exfat mkfs.ext4 mkfs.minix mkfs.ubifs mkfontdir mkfs.bfs mkfs.ext2 mkfs.fat mkfs.msdos mkfs.vfat mkfontscale mkfs.cramfs mkfs.ext3 mkfs.jffs2 mkfs.ntfs Case: mkfs.ext3 /dev/sdb2
5.2 command: mke2fs
- Introduction: mke2fs command is a special tool for managing ext series file systems.
- Format used: mke2fs [options] disk drive letter
- For example: mke2fs -t ext4 -b 8192 /dev/sdb5
Parameters: -t fs-type:Specify the file system type, such as ext2,ext3,ext4 And so on)/etc/mke2fs.conf Read the default configuration from the file; -b block-size: Set the of the hard disk block size. -L 'LABEL':Set volume label; -j: establish ext3 File system, mkfs.ext3 It comes with this option; -N: set up inode Number of nodes; -m: Set the percentage of blocks reserved for the file system; -c: Process hard disk self-test before creating file system; Case: mke2fs -t ext4 -L 'testdisk' /dev/sdb1 Other partition commands
6, Notify the system of changes to the partition table
Command: partprobe Parameters: • -d,—dry-run The operating system is not actually notified to print the content summary • -h,—Help displays this help and exits • -v,—Version output version information and exit other: If the device file generation fails, you can use the following command to generate it again partx -a /dev/XXX Note: if it still fails, please restart the system.
7, View UUID and type of device partition
Command: blkid Command: blkid Equipment name
8, Swap partition creation command
Linux mkswap The command is used to set the swap area(swap area). mkswap You can set disk partitions or files to Linux Exchange area. Syntax: mkswap [-cf][-v0][-v1][Equipment name or document][Swap size] Parameters: • -c Before establishing the exchange area, check whether there are damaged blocks. • -f stay SPARC This parameter should be added when establishing a switching area on the computer. • -v0 Create a legacy exchange area, which is the default. • -v1 Establish a new exchange area. • [Swap size] Specifies the size of the swap area, in 1024 bytes.
Open SWAP partition
Linux swapon Command for activation Linux Swap space in the system, Linux The virtual memory exchange area must be established to manage the system. Syntax: /sbin/swapon -a [-v] /sbin/swapon [-v] [-p priority] specialfile ... /sbin/swapon [-s] Parameters: • -h Please help me • -V Display version message • -s Displays a short device message • -a Automatically start all SWAP device • -p To set priority, you can choose a number between 0 and 32767. Or in /etc/fstab Add inside pri=[value] ([value]It's 0~32767 Middle number),Then you can easily use it directly swapon -a To start them and have priority settings ``` close SWAP partition Linux swapoff The command is used to close the system swap area(swap area). swapoff Actually swapon The symbolic connection can be used to close the switching area of the system. Syntax: swapoff [equipment] Parameters: • -a take/etc/fstab All settings in the file are swap Your device is turned off • -h Help information • -V Version information example 1,display partition information # sfdisk -l Disk /dev/sda: 1305 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+ 12 13- 104391 83 Linux /dev/sda2 13 1304 1292 10377990 8e Linux LVM /dev/sda3 0 - 0 0 0 Empty /dev/sda4 0 - 0 0 0 Empty Disk /dev/sdb: 652 cylinders, 255 heads, 63 sectors/track sfdisk: ERROR: sector 0 does not have an msdos signature /dev/sdb: unrecognized partition No partitions found 2,Close the swap partition. # swapoff /dev/sda2 ```