linux-fdisk (reproduced)

fdisk -l
  can list all partitions, including unmounted partitions and usb devices. I usually use this to find the location of the partitions that need to be mounted, such as a USB flash drive.
  Examples explain how to use fdisk partitions in Linux: http ://linux.chinaitlab.com/set/39459.html
  Notes: fdisk -l lists all partitions
  1. Introduction of fdisk;
  fdisk - Partition table manipulator for Linux, translated into Chinese means disk partition table operation tool; I didn't translate it very well, and I didn't read the Chinese document; in fact, it is a partition tool;
  fdsik can divide the disk into several areas, and can also specify the file system of the partition for each partition, such as linux, fat32, linux, linux swap, fat16 and the file system of the Unix-like operating system, etc.; of course, when we use fdisk to partition the disk, it is not an end point. We also need to format the partition. The file system required; such a partition can be used; this and fdisk in DOS is similar;
  note: first make a logical partition on a physical hard disk using the fdisk tool. Then allocate the corresponding file system to the logical partition. Only such partitions can be used. Hey, how can I judge what its file system is after using the df command/.
  Second, plan your hard disk partitions reasonably;
  before operating partitions, we need to understand a little bit of hard disk partition theory, such as the calculation of hard disk capacity and partition size; yes How to plan partitions of a hard disk, please refer to the following documents, thank you;
  "Planning Your Hard Disk Partitions Reasonably" ------- I am deeply impressed!
  3. fdisk -l View hard disk and partition information;
  Through "Planning Your Hard Disk Partitions Reasonably", we know that the total number of primary partitions (including extended partitions) cannot exceed four; and extended partitions cannot be surrounded by primary partitions; according to this principle, we divide hard disk partitions to compare It is much easier; it can also reduce unnecessary troubles in the future;
  1. Check the number of hard disks and partitions on the machine through fdisk -l;
  [root@localhost beinan]# fdisk -l
  The following is the first hard disk hda
  Disk /dev/hda: 80.0 GB, 80026361856 bytes
  255 heads, 63 sectors/track, 9729 cylinders
  Units = cylinders of 16065 * 512 = 8225280 bytes
  Device Boot Start End Blocks Id System
  /dev/hda1 * 1 765 6144831 7 HPFS/NTFS master Partition
  /dev/hda2 766 2805 16386300 c W95 FAT32 (LBA) Primary Partition
  /dev/hda3 2806 9729 55617030 5 Extended Extended Partition
  /dev/hda5 2806 3825 8193118+ 83 Linux Logical Partition
  /dev/hda6 3826 5100 06 102414
  /dev/hda7 5101 5198 787153+ 82 Linux swap / Solaris logical partition
  /dev/hda8 5199 6657 11719386 83 Linux logical partition
  /dev/hda9 6658 7751 8787523+ 83 Linux logical partition
  /dev/hda10 7752 9729 15888253+
  The following is the second hard disk sda
  Disk /dev/sda: 1035 MB, 1035730944 bytes
  256 heads, 63 sectors/track, 125 cylinders
  Units = cylinders of 16128 * 512 = 8257536 bytes
  Device Boot Start End Blocks Id System
  /dev/sda1 1 25 201568+ c W95 FAT32 (LBA) primary partition
  /dev/sda2 26 125 806400 5 Extended extended partition
  /dev/sda5 26 50 201568+ 83 Linux
  /dev/sda6 51 76 200781 83 Linux
  Through the above information, we know that there are two hard disks (or mobile hard disks) mounted on this machine, one of which is hda and the other is sda; if we want to view a single hard disk, we can use fdisk -l /dev/hda1 or fdisk - l /dev/sda1 to operate; the hard disk identification output by fdisk -l shall prevail;
  hda has three main partitions (including extended partitions), namely main partitions hda1 hda2 and hda3 (extended partitions); logical partitions are hda5 to hda10 ;
  Among them, sda has two main partitions (including extended partitions), which are hda1 and hda2 (extended partitions); logical partitions are sda5 hda6;
  total hard disk capacity = total capacity of primary partitions (including extended partitions)
  Extended partition capacity = total logical partition capacity Capacity
  Through the above example, we can know that hda=hda1+hda2+hda3, where hda3=hda5+hda6+hda7+hda8+hda9+hda10 ......
  What is the function of logical partition?
  2. Explanation of some values ​​of fdisk -l;
  Disk /dev/hda: 80.0 GB, 80026361856 bytes
  255 heads, 63 sectors/track, 9729 cylinders
  Units = cylinders of 16065 * 512 = 8225280 bytes
  This hard disk is 80G and has 255 magnetic planes; 63 sectors; 9729 magnetic cylinders; the capacity of each cylinder (magnetic cylinder) is 8225280 bytes=8225.280 K (approximately)=8.225280M (approximately); partition sequence boot start end capacity partition type ID Partition type
  Device Boot Start End Blocks Id System
  /dev/hda1 * 1 765 6144831 7 HPFS/NTFS
  /dev/hda2 766 2805 16386300 c W95 FAT32 (LBA)
  /dev/hda3 2806 9729 55617030 5 Extended
  /dev/hda5 2806 3825 8193118+ Linux
  /dev/hda6 3826 5100 10241406 83 Linux
  /dev/hda7 5101 5198 787153+ 82 Linux swap / Solaris
  /dev/hda8 5199 6657 11719386 83 Linux
  /dev/hda9 6658 7751 8787523+
  8582 83 Linux
  description:
  Representation of hard disk partition: In Linux, it is represented by hd*x or sd*x, where * represents a, b, c …… …… The numbers 1, 2, 3 represented by x …… …… hd is mostly IDE hard disk; sd is mostly SCSI or removable storage;
  boot (Boot): indicates the boot partition, in the above example hda1 is the boot partition;
  Start (start): indicates that a partition starts from the X cylinder (magnetic cylinder) ;
  End (end): Indicates the end of a partition to the Y cylinder (magnetic column);
  id and System represent the same meaning, id does not seem intuitive, we need to confirm the partition type by specifying id when fdisk a partition; for example, 7 means NTFS partition; this needs to be specified in fdisk through the t function . The following parts will be mentioned;
  Blocks (capacity): This is my translation, in fact, it is not accurate, the meaning is indeed the meaning of capacity, and its unit is K; the value of a partition capacity is derived from the following formula ;
  Blocks = (the corresponding partition End value - the corresponding partition Start value) x the capacity of the unit cylinder (magnetic column)
  So we calculate the size of the Blocks of hda1:
  hda1 Blocks=(765-1)x8225.280=6284113.92 K = 6284.113. 92M
  Note: The conversion unit is calculated from the decimal provided by the hard disk manufacturer. If the operating system binary is used, the partition capacity should be smaller. The obtained value is the same as the /dev/hda1 we saw through fdisk -l. The values ​​are roughly equivalent, because the conversion methods are different, so it is impossible to be as accurate as possible; plus a little loss during partitioning, sometimes there is a large or small value;
  when we look at the partition size or file, It is more intuitive to use decimal to calculate; the calculation method is to push byte forward to three decimal places to be K, the value of K unit to push forward to three decimal places is M, and M to push forward to three decimal places to be G... ...... Generally poor
  3. Estimate whether a storage device is completely divided; we
  estimate whether a hard disk is completely divided, we only need to look at the cylinders (cylinders) in the output of fdisk -l, the End and the next partition of the previous partition. Whether the Start of a partition is a continuous number, also look at the beginning of fdisk -l of each hard disk device, and look at the value of his cylinders;
  For example, for hda device, we see 9729 cylinders; we can see through the partition table of hda that the value of End of the previous partition + 1 is the value of Start of the next partition; for example, the value of Start of hda2 is that of End of hda1 The value is +1, which proves that there is no blank partition between hda1 and hda2, they are continuous, and so on; in hda10, we see that the value of End is 9729, and there are also 9729 cylinders in the header information of fdisk -l, which proves that this hard disk Fully partitioned;
  Disk /dev/sda: 1035 MB, 1035730944 bytes
  256 heads, 63 sectors/track, 125 cylinders
  Units = cylinders of 16128 * 512 = 8257536 bytes
  Device Boot Start End Blocks Id System
  /dev/sda1 1 25 201568+ c W95 FAT32 (LBA)
  /dev/sda2 26 125 806400 5 Extended
  /dev/sda5 26 50 201568+ 83 Linux
  /dev/sda6 51 76 200781 83 Linux
  Let's see if the sda ​​mobile storage is completely divided; sda has 125 cylinders (cylinders), consisting of a main partition and an extended partition; in the extended partition, we see that the value of End is 125, and this The cylinder of the mobile hard disk is also 125, which means that it is impossible to add any primary partition to this hard disk; according to what we said above, there is no undivided space between sda1, sda2, sda5 and sda6, but the End of the cylinders (cylinder) of sda6 The value is 76, and the total cylinders (cylinders) of sda are 125. From this, it seems that sda has an undivided area behind sda6;
  as for how much undivided space there is in sda, we can calculate it; the total capacity of the extended partition It is 806400K, which is about 806.400M, and the combined size of logical partitions sda5 and sda6 is about 400M, so there is still about 400M of undivided space, and it can only be divided into chain logical partitions;
  4. fdisk for hard disks and partitions operation, enter the stage of fdisk operating on the hard disk;
  we can partition the hard disk, provided you understand fdisk -l; through fdisk -l, we can find out the number of all hard disks and device names in the machine; for example, the above For example, we will see two devices, one is /dev/hda and the other is /dev/sda;
  the command format of fdisk operating hard disk is as follows:
  [root@localhost beanan]# fdisk device
  For example, we know through fdisk -l /dev/hda or /dev/sda device; if we want to add or delete some partitions, we can use
  [root@localhost beanan]# fdisk /dev/hda
  or
  [root@localhost beanan]# fdisk /dev/sda
  Note In the following examples, we will take the /dev/sda device as an example to explain how to use fdisk to operate actions such as adding and deleting partitions;
  1. Description of fdisk;
  when we enter the operation of the corresponding device through the fdisk device , you will find the following prompts; take the fdisk /dev/sda device as an example, the same as below;
  [root@localhost beanan]# fdisk /dev/sda
  Command (m for help): Press m here, and the help will be output;
  Command action
  a toggle a bootable flag
  b edit bsd disklabel
  c toggle the dos compatibility flag
  d delete a partition Note: This is an action to delete a partition;
  l list known partition types Note: l is to list the partition types for us to set the corresponding Type of partition;
  m print this menu Note: m is to list help information;
  n add a new partition Note: add a partition;
  o create a new empty DOS partition table
  p print the partition table Note: p lists the partition table;
  q quit without saving changes Note: Exit without saving;
  s create a new empty Sun disklabel
  t change a partition's system id Note: t Change the partition type;
  u change display/entry units
  v verify the partition table
  w write table to disk and exit Note: Write the partition table to the hard disk and exit;
  x extra functionality (experts only) Note : extended applications, expert functions;
  in fact, we only use Chinese-annotated ones, and we don’t use other functions (oh, mainly because I don’t know how to use them, otherwise I’ll show off earlier); x extended functions are not commonly used; In general, you only need to know dlmpqtw;
  the following is an example operation to describe in detail, there is no example, there is no way, and novices can't understand it;
  2. To list the partitions of the currently operating hard disk, use p;
  Command (m for help) : p
  Disk /dev/sda: 1035 MB, 1035730944 bytes
  256 heads, 63 sectors/track, 125 cylinders
  Units = cylinders of 16128 * 512 = 8257536 bytes
  Device Boot Start End Blocks Id System
  /dev/sda1 1 25 201568+ c W95 FAT32 (LBA)
  /dev/sda2 26 125 806400 5 Extended
  /dev/sda5 26 50 201568+ 83 Linux
  /dev/sda6 51 76 200781 83 Linux
  3. Delete a partition through the d command of fdisk;
  Command (m for help): p Note: List partitions;
  Disk /dev/ sda: 1035 MB, 1035730944 bytes
  256 heads, 63 sectors/track, 125 cylinders
  Units = cylinders of 16128 * 512 = 8257536 bytes
  Device Boot Start End Blocks Id System
  /dev/sda1 1 25 201568+ c W95 FAT32 (LBA)
  /dev /sda2 26 125 806400 5 Extended
  /dev/sda5 26 50 201568+ 83 Linux
  /dev/sda6 51 76 200781 83 Linux
  Command (m for help): d Note: Execute delete partition designation;
  Partition number (1-6): 6 Note: I want to delete sda6, just enter 6 here;
  Command (m for help): p Note: Check the hard disk partition again to see if it has been deleted?
  Disk /dev/sda: 1035 MB, 1035730944 bytes
  256 heads, 63 sectors/track, 125 cylinders
  Units = cylinders of 16128 * 512 = 8257536 bytes
  Device Boot Start End Blocks Id System
  /dev/sda1 1 25 201568+ c W95 FAT32 (LBA)
  /dev/sda2 26 125 806400 5 Extended
  /dev/sda5 26 50 201568+ 83 Linux
  Command (m for help):
  Warning: Be careful when deleting a partition, please look at the serial number of the partition, if you delete the extended partition, the logical partition under the extended partition will be deleted; so operate Be careful; if you know you have made a mistake, don't panic, use q to exit without saving; remember! ! ! ! When the partition operation is wrong, do not enter w to save and exit! ! !
  4. Add a partition through the n command of fdisk;
  Command (m for help): p
  Disk /dev/sda: 1035 MB, 1035730944 bytes
  256 heads, 63 sectors/track, 125 cylinders
  Units = cylinders of 16128 * 512 = 8257536 bytes
  Device Boot Start End Blocks Id System
  /dev/sda1 1 25 201568+ c W95 FAT32 (LBA)
  /dev/sda2 26 125 806400 5 Extended
  /dev/sda5 26 50 201568+ 83 Linux
  Command (m for help): n Note: add a partition;
  Command action
  l logical (5 or over) Note: add logical partition, partition number It should be greater than 5; why should it be greater than 5, because there is already sda5;
  p primary partition (1-4) Note: add a primary partition; the number is from 1-4; but both sda1 and sda2 are occupied, so it can only start from 3 ;
  p
  Partition number (1-4): 3
  No free sectors available Note: Failed, why failed?
  Note: I tried to add a primary partition and it seems to have failed, why did it fail? Because we see that the main partition + extended partition have used up the entire disk, look at the value of End of the extended partition, and look at the 125 cylinders in the output information of p; it is better to look at the previous part; it is mentioned there;
  so We can only add logical partitions;
  Command (m for help): n
  Command action
  l logical (5 or over)
  p primary partition (1-4)
  l Note: Enter l here to enter the stage of logical partitioning;
  First cylinder (51-125, default 51): Note: This is the Start value of the partition; it is better to press Enter directly here, if you enter a non-default number, it will cause a waste of space;
  Using default value 51
  Last cylinder or +size or +sizeM or +sizeK (51-125, default 125): +200M Note: This is to define the size of the partition, +200M means the size is 200M; of course, you can also calculate it according to the size of the unit cylinder indicated by p, Then specify the value of End. Look back and see how it is calculated; it is still more intuitive to use the method of +200M to add. If you want to add a partition with a size of about 10G, please input +10000M;
  Command (m for help):
  5. Specify the partition type through the t command of fdisk;
  Command (m for help): t Note: Use t to specify the partition type ;
  Partition number (1-6): 6 Note: Which partition type should be changed? I specified 6, which is actually sda6
  Hex code (type L to list codes): L Note: Enter L here to view the id of the partition type;
  Hex code (type L to list codes): b Note: If I want this partition to be of W95 FAT32 type, and I can see that b means yes by checking L, so I enter b;
  Changed system type of partition 6 to b (W95 FAT32) Note: System information, the change is successful; whether it is a change , please use p to view;
  Command (m for help): p
  Disk /dev/sda: 1035 MB, 1035730944 bytes
  256 heads, 63 sectors/track, 125 cylinders
  Units = cylinders of 16128 * 512 = 8257536 bytes
  Device Boot Start End Blocks Id System
  /dev/sda1 1 25 201568+ c W95 FAT32 ( LBA)
  /dev/sda2 26 125 806400 5 Extended
  /dev/sda5 26 50 201568+ 83 Linux
  /dev/sda6 51 75 201568+ b W95 FAT32
  6. To exit fdisk, use q or w;
  where q is to exit without saving, w is save and exit;
  Command (m for help): w
  or
  Command (m for help): q
  7. An example of adding a partition; in
  this example, we will add two 200M primary partitions, and the other are extended partitions. We add two 200M logical partitions to the partition;
  Command (m for help): p Note: List the partition table;
  Disk /dev/sda: 1035 MB, 1035730944 bytes
  256 heads, 63 sectors/track, 125 cylinders
  Units = cylinders of 16128 * 512 = 8257536 bytes
  Device Boot Start End Blocks Id System
  Command (m for help): n Note: Add partition;
  Command action
  e extended
  p primary partition (1-4)
  p Note: Add primary partition;
  Partition number (1-4): 1 Note: Add main partition 1;
  First cylinder (1-125, default 1): Note: Enter directly, the starting position of main partition 1; The default is 1, the default is fine; Using default value 1
  Last cylinder or +size or +sizeM or +sizeK (1-125, default 125): +200M Note: Specify the partition size, use +200M to specify the size as 200M
  Command (m for help): n Note: Add new Partition;
  Command action
  e extended
  p primary partition (1-4)
  p Note: Add primary partition
  Partition number (1-4): 2 Note: Add primary partition 2;
  First cylinder (26-125, default 26):
  Using default value 26
  Last cylinder or +size or +sizeM or +sizeK (26-125, default 125): +200M Note: Specify the partition size, use +200M to specify the size as 200M
  Command (m for help): n
  Command action
  e extended
  p primary partition (1-4)
  e Note: Add extended partition;
  Partition number (1-4): 3 Note: Specify 3, because the main partition has been divided into two, this is also the main partition, starting from 3;
  First cylinder (51-125, default 51): Note: Press Enter directly;
  Using default value 51
  Last cylinder or +size or +sizeM or +sizeK (51-125, default 125): Note: Press Enter directly, put all the rest of the space Give both extended partitions;
  Using default value 125
  Command (m for help): p
  Disk /dev/sda: 1035 MB, 1035730944 bytes
  256 heads, 63 sectors/track, 125 cylinders
  Units = cylinders of 16128 * 512 = 8257536 bytes
  Device Boot Start End Blocks Id System
  /dev/sda1 1 25 201568+ 83 Linux
  /dev/sda2 26 50 201600 83 Linux
  /dev/sda3 51 125 604800 5 Extended
  Command (m for help): n
  Command action
  l logical (5 or over)
  p primary partition (1 -4)
  l Note: Add logical partition;
  First cylinder (51-125, default 51):
  Using default value 51
  Last cylinder or +size or +sizeM or +sizeK (51-125, default 125): +200M Note: Add A partition with a size of 200M;
  Command (m for help): n
  Command action
  l logical (5 or over)
  p primary partition (1-4)
  l Note: Add a logical partition;
  First cylinder (76-125, default 76 ):
  Using default value 76
  Last cylinder or +size or +sizeM or +sizeK (76-125, default 125): +200M Note: Add a partition with a size of 200M;
  Command (m for help): p list the partition table;
  Disk /dev/ sda: 1035 MB, 1035730944 bytes
  256 heads, 63 sectors/track, 125 cylinders
  Units = cylinders of 16128 * 512 = 8257536 bytes
  Device Boot Start End Blocks Id System
  /dev/sda1 1 25 201568+ 83 Linux
  /dev/sda2 26 50 201600 83 Linux
  /dev/sda3 51 125 604800 5 Extended
  /dev/sda5 51 75 201568+ 83 Linux
  /dev/sda6 76 100 201568+ 83 Linux
  Then we use the t command to change the partition type as mentioned above;
  don't forget w Save and exit;
  5. Format and load the partition;
  Prompt first; use commands such as mkfs.bfs mkfs.ext2 mkfs.jfs mkfs.msdos mkfs.vfatmkfs.cramfs mkfs.ext3 mkfs.minix mkfs.reiserfs mkfs.xfs to format the partition, for example, I want to format sda6 as an ext3 file system, then enter;
  [root@localhost beanan]# mkfs.ext3 /dev/sda6
  If I want to load sda6 to the current system to access files, there should be a mount command, but first you have to create a mount directory; such as /mnt /sda6;
  [root@localhost beanan]# mkdir /mnt/sda6
  [root@localhost beanan]# mount /dev/sda6 /mnt/sda6
  [root@localhost beanan]# df -lh
  Filesystem capacity used, available, used% mount Mount point
  /dev/hda8 11G 8.4G 2.0G 81% /
  /dev/shm 236M 0 236M 0% /dev/shm
  /dev/hda10 16G 6.9G 8.3G 46% /mnt/hda10
  /dev/sda6 191M 5.6M 176M 4% /mnt/sda6
  so that we can enter the /mnt/sda6 directory and access files;

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326913838&siteId=291194637