Detailed explanation of fdisk command of linux disk partition

1. What is a partition?
    Partitioning is to divide a hard drive into several logical drives. Partitioning is to use consecutive blocks of the hard drive as an independent magnetic hard drive. The partition table is an index of a hard disk partition, and the partition information will be written into the partition table.
2. Why are there multiple partitions?

  • Prevent data loss: If the system has only one partition, then this partition is damaged, and the user will lose all data.

  • Increase the efficiency of disk space usage: partitions can be formatted with different block sizes. If there are many 1K files, and the hard disk partition block size is 4K, then 3K space will be wasted for each file stored. At this time, we need to take the average of these file sizes to divide the block size.

  • Data explosion to the limit will not cause system hangs: Separating user data and system data can prevent user data from filling up the entire hard disk and causing system hangs.

3. The usage of the partition tool fdisk is introduced. The
   fdisk command parameters are introduced
   p, and the partition table is printed.
   n. Create a new partition.
   d. Delete a partition.
   q. Exit without saving.
   w. Write the partition into the partition table, save and exit.
Example:
   [root@localhost ~]# fdisk /dev/hdd   

   Press the "p" key to print the partition table

   This hard disk has not been partitioned yet
   . Press the "n" key to create a new partition.

  Two menus appear, e means extended partition, p means main partition,
  press "p" key, and prompt: "Partition number (1-4): "Select main partition number and
  input "1" means the first main partition.

   Press Enter directly to indicate 1 cylinder to start partitioning.

   Prompt for the last cylinder or size.
   Enter +5620M and press Enter to
   indicate that the first partition is 5G space.
   Press "p" to view the partition



Such a primary partition is divided.
Next, divide the second primary partition, and give the remaining space to the second primary partition.
Press the "n"
key to add a new partition
, press the "p" key to set the main partition,
enter "2" to set the main partition number to 2,
and press Enter twice to distribute the remaining space to the second main partition.
Press the "p" key to print the partition table


Press "w" to save and exit. 
Readers can divide the appropriate partition according to their own hard disk size.

4.
   Before using the hard disk, the partition must be formatted and mounted.
   [root@localhost ~]#mkfs.ext3 /dev/hdd1
   [root@localhost ~]#mkfs.ext3 /dev/hdd2
   create mount directory
   [root@localhost ~]#mkdir /hdd1 /hdd2
   mount /dev/hdd1 /dev/hdd2
   [root@localhost ~]#mount /dev/hdd1 /hdd1
   [root@localhost ~]#mount /dev/hdd2 /hdd2View
   [
   root@localhost ~]#df -h
   Filesystem Size Used Avail Use% Mounted on
   /dev/hda3 7.5G 2.8G 4.3G 40% /
   /dev/hda1 99M 17M 78M 18% /boot
   tmpfs 62M 0 62M 0% /dev/shm
   /dev/hdd1 2.5G 68M 2.3G 3% /hdd1
   /dev/hdd2 2.5G 68M 2.3G 3% /hdd2

Now write data to the /hdd1 directory and store it on the hard disk /dev/hdd

 

Details of fdisk -l display information

Details of fdisk -l display information

[[email protected] ~]# fdisk -l 
Disk /dev/sda: 10.7 GB, 10737418240 bytes 
255 heads, 63 sectors/track, 1305 cylinders 
Units = cylinders of 16065 * 512 = 8225280 bytes 
Sector size (logical/physical): 512 bytes / 512 bytes 
I/O size (minimum/optimal): 512 bytes / 512 bytes 
Disk identifier: 0x00044938 
  Device Boot      Start        End      Blocks  Id  System 
/dev/sda1  *          1        638    5120000  83  Linux 
Partition 1 does not end on cylinder boundary. 
/dev/sda2            638        893    2048000  83  Linux 
Partition 2 does not end on cylinder boundary. 
/dev/sda3            893        1020    1024000  82  Linux swap / Solaris 
Partition 3 does not end on cylinder boundary. 
/dev/sda4            1020        1306    2292736    5  Extended 
/dev/sda5            1021        1306    2291712  83  Linux

Analysis :
Disk /dev/sda: 10.7 GB, 10737418240 bytes
The block device name is /dev/sda, the size of this device is 10.7GB, this number is not very precise, my system is 10GB; 10737418240 bytes This is after converting into bytes size, namely: 10737418240/1024/1024/1024=10GB (Note: bytes=B, means "byte", bit=b, means "bit")
255 heads, 63 sectors/track, 1305 cylinders
255 heads: means The number of heads is 255
63 sectors/track: means that there are 63 sectors on each track
1305 cylinders: means that there are 1305 cylinders in total, and a cylinder is the smallest unit of a partition
Units = cylinders of 16065 * 512 = 8225280 bytes

16065=255*63 Because each head is on the same cylinder, 63 represents the number of sectors on each track, and the product of these two numbers represents the number of sectors on a cylinder; so 16065*512 means The size of a cylinder is 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
means that the size of a sector is 512 bytes

Summary : So size of one disk = size of one cylinder * total number of cylinders = number of heads * number of sectors on each track * size of one sector * total number of cylinders

That is : disk size=8225280*1305=10733990400bytes=9.99GB=255*63*512*1305
The above example shows that our disk has only 1305 cylinders, but 1306 cylinders appear in the partition information below, which is not necessary Care too much, the data displayed by linux will not be very accurate.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326228217&siteId=291194637