Hard disk partitioning (FDISK). Working with a new hard drive using FDISK

To determine the condition of the hard drive of the purchased PC, you should:

1) try to boot from the hard drive, for which turn on the computer if there is no floppy disk in drive A. If any operating system has booted, then the hard drive is already prepared for operation and you do not need to resort to the FDISK utility. If the download fails, then you need to go to step 2.

2) check if the hard drive is configured, i.e. Does it have DOS partitions? To do this, you need to boot from the boot diskette, enter the FDISK command (the diskette must have the FDISK utility) and select the “Display information about available partitions” option in the main menu. If the result indicates that there are no partitions, then configuration of the hard drive is required. Otherwise, it is possible to reconfigure (change the number and/or size of partitions and logical drives) using the same utility. In any of the described cases, you can complete the preparation of the hard drive for operation by high-level formatting all logical drives using the FORMAT command (very often, formatting disks is carried out later during the installation of the operating system). If you want to format before installing the OS, then one of the floppy disks must have the FORMAT utility. If the FDISK utility does not start, you need to go to step 3.

3) perform low-level formatting of the hard drive using a special utility supplied with the PC. Low-level formatting of a hard drive involves the formation of sectors (taking into account the interleaving coefficient), which consists of writing sector labels to the tracks and checking their good quality (the physical ability to write information to them). Defective sectors are marked in a special way. After low-level formatting, you should run the FDISK command and, if necessary, format the logical drives. The inability to low-level format a disk means that the PC hardware is faulty or the cables are poorly connected.

Thus, preparing a hard drive for operation “from scratch” is carried out in three stages: 1) low-level formatting of the hard drive; 2) configuring the hard drive; 3) high-level formatting of all logical drives created on it (this item is optional). Low-level formatting of modern hard drives is done at the factory. Repeated low-level formatting of such disks is not required, and is a very dangerous operation, since it can lead to the loss of service information. Low-level reformatting of legacy hard drives can be performed using the CALIBRATE utility from the NORTON UTILITIES kit. It is useful to perform this procedure approximately once a year to restore the sector marks and at the same time test the quality of the disk surface. The need to separate low-level and high-level formatting of a hard drive over time is explained by the fact that after low-level formatting it is necessary to configure it. The algorithm for configuring a hard drive to work in a Windows environment is as follows:


1) creating a main DOS partition with a logical disk in it;

2) creating an additional DOS partition (if necessary, for example, there is a need to install 2 OS on the computer: Windows 98 and Windows NT and work with different file systems);

3) formation of logical disks in an additional DOS partition (if it was created in step 2);

4) setting the indicator that the main DOS partition is active.

For normal operation of the hard drive, it is necessary that it have a partition table (sometimes called partition although strictly speaking, partition- these are the disk partitions themselves). If it is absent, the operating system does not have access to the hard drive (“does not see” the hard drive). The partition table contains information about the physical characteristics of the disk: the number of sides, the number of tracks and sectors per track, as well as information about partitions and logical drives.

Disk partitions

When working under MS-DOS, each hard drive can have the following partitions:

  • Primary DOS partition: required. In this section, a single system logical drive is formed (usually named C:)
  • Extended DOS partition: present only when the hard drive has two or more logical drives.
  • Non-DOS partition: formed if you work with two or more operating systems. This partition is given to other operating systems for use and is invisible to MS-DOS.

FDISK Team

To execute this command, you must have a boot floppy disk made in Windows 98SE, preferably in Russian. Although the operating system comes with an external command FDISK, but in English.

After booting the computer from the floppy disk, enter the command

The main menu will appear on the screen:

FDISK Options
(
FDISK options)
Current fixed disk drive: 1
(Current HDD drive: 1)
Choose one of the following:
(
Choose one of the options :)
1.Create DOS partition or Logical DOS Drive
(
1. Create a DOS partition or DOS logical disk.)
2.Set active partition
(
2. Set the active partition.)
3.Delete partition or Logical DOS Drive
(
3. Delete a DOS partition or logical drive.)
4.Display partition information
(
4. View partition information.)
5.Change current fixed disk drive
(5. Change the current hard disk drive.)
Enter choice:
(Enter your choice:)
Press Esc to exit FDISK
(Press Esc to exit)

Note: If there is only one hard drive installed in the computer, then option 5 is not issued.

Hard drive partitioning

To partition a hard drive, you must perform the following operations:

  • Make the reconfigurable drive active (if necessary)
  • Delete all existing partitions on the hard drive.
  • Create new sections you need.
  • If necessary, create logical drives.
  • If necessary, assign an active partition (it will boot from)
  • Format the resulting logical drives.

Removing existing partitions

If your disk has already been configured, you will first have to remove the previous partition. To do this, select item 3 of the main menu. The following will appear on the screen:

Delete DOS Partition or Logical DOS Drive
(Removing DOS partitions or logical drives)
Current fixed disk drive: 1
(Current drive: 1)
Choose one of the following:
(Choose one of the options:)
1. Delete Primary DOS Partition
(1. Delete primary DOS partition)
2. Delete Extended DOS Partition
(2. Delete extended DOS partition)
3. Delete Logical DOS Drive(s) in the Extended DOS
(3. Remove logical drives from extended DOS partition)
4. Delete Non-DOS Partition
(4. Delete non-DOS partition)

The order of your actions:

  • Delete the non-DOS partition (if it exists)
  • Remove logical drives from the extended DOS partition (if this partition exists), and when deleting you will need to confirm your intentions several times and enter the drive label.
  • Delete the extended DOS partition itself (if you had one), and when deleting you will need to confirm your intentions several times.
  • Delete the primary DOS partition, and when deleting you will need to confirm your intentions several times and enter the disk label.

Now the previous split is deleted and you can create a new one.

Create a new split

After deleting the previous partition, you need to create a new one. To do this, select option 1 from the main menu.

Create DOS partition or Logical DOS Drive
(Creating DOS partitions or logical drives)
Current fixed disk drive: 1
(Current drive: 1)
Choose one of the following:
(Choose one of the options:)
1. Create Primary DOS Partition
(1. Create a primary DOS partition)
2. Create Extended DOS Partition
(2. Create an extended DOS partition)
3. Create Logical DOS Drive(s) in Extended DOS Partition
(3. Create logical drives in the extended DOS partition)

First you need to create a primary DOS partition. Select option 1. You will be asked the question:

Do you wish to use the maximum available size for a Primary DOS Partition and make the partition active
(Y/N...............?
(Do you want to use all disk space for the primary DOS partition and make this partition active?)
If you answer yes, then one logical disk will be created on your entire hard drive, from which the operating system will be loaded.
In this case, the hard drive partitioning is complete. If you want to split your hard drive into several logical ones, then you must answer in the negative. The following request will be displayed on the screen:

Enter partition size in Mbytes or percent of disk space (%) to create a Primary DOS Partition.................:
(Enter the size of the primary DOS partition in MB or as a percentage of disk space.)
After you create the primary partition, you will need to create an extended DOS partition.( Create Extended DOS Partition)

A message will appear on the screen:

Enter partition size in Mbytes or percent of disk space (%) to create an Extended DOS Partition.........:
(Enter the size of the extended DOS partition in MB or as a percentage of disk space.)
If you do not need to leave space for working with another operating system (not MS-DOS), then you must specify all the disk space remaining free, which is what is offered by default.
After you have created an extended DOS partition, you need to split it into logical drives.( Create Logical DOS Drive(s) in Extended DOS Partition)
Enter Logical drive size in Mbytes or percent of disk space (%)...
(Enter the logical disk size in MB or percentage of disk space.)
If you want to create two logical ones (one is the primary DOS partition, the other is the full size of the extended DOS partition), then you need to accept the default maximum size suggested. Otherwise, enter your size and repeat this operation for the next logical drive.

After dividing the hard drive into partitions and logical drives, you need to install the active partition (the computer will boot from it).

Setting the active partition

To boot from a hard drive, the primary DOS partition must be active. Select option 2 from the main menu and enter the partition number from which you will boot:

Enter the number of the partition you want to make active......:
(Enter the partition number you want to make active)

When partition information is displayed, the active partition is marked with the letter A.

After completing these steps, partitioning the hard drive is complete. All that remains is to format the resulting logical drives.

Note: If none of the partitions are made active, then it is impossible to boot from the hard drive. In this case, no messages are displayed.

Formatting the hard drive

Formatting a hard drive has some features. First, drive C: must be made system.

Secondly, you will have to format the hard drive after booting from a floppy disk. After booting from the floppy disk, enter the command:

A warning will be displayed on the screen that you are formatting the hard drive:

Warning: all data on non-removable disk
Drive D: will be lost!

A follow-up question will be asked:

If your answer is positive, the hard drive will be formatted and the operating system will be transferred to it.

After this, you will be able to boot from the hard drive, transfer the files you need (operating system) to it, and, if necessary, format the remaining logical drives (of course, you no longer need to set the S parameter). The process of reconfiguring the hard drive is completely completed.

fdisk [-BIaipstu] [-b loader ] [-1234] [ disk] fdisk -f The configuration file [-itv] [ disk ]

PROLOGUE To BIOS was able to boot the kernel, certain conventions must be followed. Sector zero of the disk must contain the boot code, slice table, and magic number. Using slices BIOS, the disk may be split into several parts. BIOS reads the zero sector and checks the magic number. The boot code from sector zero then checks the slice table to find a slice marked "active." It then reads the boot program from the active slice, and if the slice is marked bootable, runs it. In DOS, there can be multiple slices, one of which is which will be active. fdisk for DOS allows you to divide disk space into slices and mark one of them as active. DESCRIPTION Utility fdisk for serves the same purposes as its similar utility for DOS. The first call form is used to display information about slice parameters or to edit it interactively. The second is for writing a slice table using a configuration file The configuration file; it is intended to be used by other scripts or programs. fdisk supports the following options: -a Only change the active slice. Ignored in combination with option -f. -b loader Use the boot code from the bootloader file. Default is /boot/mbr. -B Change the boot code in sector zero of the disk. Ignored in combination with option -f. -f The configuration file Set slice parameters from file The configuration file. Using the configuration file, only the parameters of explicitly specified slices are changed, but if the -i option is also specified, then before reading the configuration file, all existing slices are deleted (marked as unused, " unused"). When specifying " - " (minus sign) standard input will be used as the configuration file. For a description of the configuration file format, see the section below CONFIGURATION FILE.

WARNING: Unlike interactive mode, when using the option -f changes are made without asking for confirmation. Be careful!
-i Initialize sector zero of the disk. Before editing, existing slices will be marked as unused (" unused"). (Compare with option -u). -I Initialize the slice table in the sector 0 one FreeBSD slice for the entire disk. -p Print slice table in configuration file format fdisk and go out; cm. CONFIGURATION FILE below. -s Print brief information and exit. -t Test mode: changes will not be written to disk. Typically used in conjunction with the option -f to find out what would have been written to the slice table. Includes option -v. -u Edit the disk slice table in sector 0. Ignored in combination with the option -f. -v Print verbose messages. In combination with -f, fdisk prints the writable slice table. -1234 Operate on only one slice. Ignored in combination with option -f. As an argument disk it is acceptable to specify simply the disk name (for example, da0), and the full path to it. If no argument is given, fdisk attempts to determine the default drive name from the name of the device on which the root file system resides. When called without arguments, the table of slices from the sector is printed 0 . It looks something like this: ******* Working on device /dev/ad0 ******* parameters extracted from in-core disklabel are: cylinders=769 heads=15 sectors/track=33 (495 blks/ cyl) parameters to be used for BIOS calculations are: cylinders=769 heads=15 sectors/track=33 (495 blks/cyl) Warning: BIOS sector numbering starts with sector 1 Information from DOS bootblock is: The data for partition 1 is: sysid 165,(FreeBSD/NetBSD/386BSD) start 495, size 380160 (185 Meg), flag 0 beg: cyl 1/ sector 1/ head 0; end: cyl 768/ sector 33/ head 14 The data for partition 2 is: sysid 164,(unknown) start 378180, size 2475 (1 Meg), flag 0 beg: cyl 764/ sector 1/ head 0; end: cyl 768/ sector 33/ head 14 The data for partition 3 is: The data for partition 4 is: sysid 99,(ISC UNIX, other System V/386, GNU HURD or Mach) start 380656, size 224234 (109 Meg ), flag 80 beg: cyl 769/ sector 2/ head 0; end: cyl 197/ sector 33/ head 14 The disk is divided into three slices that completely cover it. The second slice partially overlaps the end of the first. (Used for debugging purposes). sysid is used to label the slices. FreeBSD reserves a magic number for itself 165 in decimal number system (A5 in hexadecimal). start and size fields containing the starting address and slice size in sectors. flag 80 indicates that this is the active slice. The cyl, sector and head fields are used to indicate the start and end addresses of the slice (cylinder, sector and head, respectively). Note: these numbers are calculated based on the disk geometry assumed by the BIOS and are stored in the boot sector. Flags -i And -u indicate to the program that the slice table should be changed. If the flag -f was not specified, work with the utility will occur in dialog mode. In this case, no changes will be written to disk unless you explicitly request it. Fdisk will show each slice and ask if you want to edit it. If the answer is yes, fdisk will sequentially move from field to field, displaying the old value and requesting a new one. When you are finished editing the slice, fdisk will display information about it and ask if you agree with the entered values, and if the answer is yes, it will move on to the next slice. Calculate values ​​correctly cyl, sector, And head can be difficult, so they are calculated automatically by default. However, if necessary, you can set them yourself. Once all the slices have been processed, you will be prompted to change the "active" slice. Finally, when all the new data has been collected, the program will ask for confirmation to write to sector zero. Difference between flags -u And -i thing is -u edits (updates) the parameters of existing slices, whereas -i used to "initialize" them (old values ​​are ignored). If the first slice is edited, then -i will configure it to cover the entire disk and make it active. NOTES When automatically calculating the starting cylinder, head, etc. uses a set of values ​​that reflect the geometry of the disk based on the data BIOS. By default, these values ​​are taken from the drive label in the kernel ( in-core disk label), But fdisk provides the opportunity to change them. This allows you to create a boot block that can work with drives that use address translation via BIOS. When manually marking the disk, make sure that the FreeBSD slices start at the cylinder boundary. Changing the parameters of an existing slice is likely to result in the loss of data stored on that slice. It makes sense to run it several times fdisk interactively to see all the changes it makes. It is safe provided you answer no to the last question, " Should we write new partition table?". There are a number of configuration subtleties that the utility fdisk detects, but which are not described in detail in this man page. CONFIGURATION FILE When using the option -f the disk slice table can be written using the values ​​specified in the file The configuration file. The format of this file is quite simple, each line is either a comment or a specification, as shown below: # comment lines starting with # are comments and are ignored. g spec1 spec2 spec3 Set the BIOS geometry used to calculate slice parameters. Three values ​​must be specified, with a letter in front of each number:
  • cnum- Set the number of cylinders to num.
  • hnum- Set the number of heads equal num.
  • snum- Set the number of sectors per track to num.
The values ​​can be specified in any order, because The first letter clearly defines what meaning is meant. However, in any case, all three values ​​must be specified. This line must precede lines specifying slice parameters. Values ​​can be in the following ranges: 1<= число цилиндров 1 <= число головок <= 256 1 <= число секторов на дорожке < 64 Число цилиндров должно быть меньше либо равным 1024 . This is not strictly necessary, but if you specify a number greater than 1024 , a warning will be issued. Please note that FreeBSD boot slices containing the root ("/") filesystem must be located first 1024 cylinders, otherwise loading problems may occur. This limitation does not apply to non-loaded slices. An example of disk geometry (all options are identical) with 1019 cylinders, 39 heads and 63 sectors on the track: g c1019 h39 s63 g h39 c1019 s63 g s63 h39 c1019 p slice type start length Set the slice with number slice (1-4 ) type type, initial sector start and size length sectors. Only those slices whose parameters are specified by such lines will undergo changes; the remaining slices will retain their previous parameters. However, if the existing slice table is incorrect or the option is specified -i, all existing slices will be deleted (marked as unused), and the layout will need to be set accordingly p lines. When specifying parameters for multiple slices, you must specify multiple lines p, one for each slice. These lines must follow the line specifying the geometry, if such a line is present in the file. For FreeBSD slices the value is type equals 165 . Specifying a null type is similar to deleting a slice (by marking it "unused"), but the fields start And length in this case also arbitrary values ​​must be assigned, for example, 0 . Note: If necessary, the start offset will be rounded up to the head boundary and the end offset will be rounded down to the cylinder boundary. Example: to delete 4th slice and make it "unused": p 4 0 0 0 Example: to set 1st slice as FreeBSD slice starting with 1 -th sector of size 2503871 sectors (these values ​​will be rounded up and down so that the slice falls on the boundaries of the head and cylinder, respectively): p 1 165 1 2503871 a slice Make a slice slice active. This line can be located anywhere in the file, but there can only be one such line in the entire file. Example: to make active 1 th slice: a 1 FILES /boot/mbr Default bootloader code. SEE ALSO boot0cfg(8), bsdlabel(8), newfs(8) PROBLEMS The default loader code does not always correctly recognize all slice types, particularly those introduced since MS-DOS 6.x. This utility could be more user friendly. Most FreeBSD newbies don't understand the difference between a "slice" and a "partition", which leads to problems. Using this utility, it is impossible to allocate the entire disk for use by FreeBSD. To do this you need to use the utility bsdlabel(8).

Thank you for translating this part. To be continued...

About the authors

Daniel Robbins

Daniel Robbins is the founder of the Gentoo community and creator of the Gentoo Linux operating system. Daniel resides in New Mexico with his wife Mary and two energetic daughters. He is also the founder and CEO of Funtoo, and has written numerous technical articles for IBM developerWorks, Intel Developer Services, and C/C++ Users Journal.

Chris Houser

Chris Houser has been a UNIX advocate since 1994, when he joined the administrative team at Taylor University (Indiana, USA), where he received a bachelor's degree in computer science and mathematics. He has since worked in a variety of areas, including web applications, video editing, UNIX drivers, and cryptographic security. Currently working at Sentry Data Systems. Chris has also contributed to many free projects such as Gentoo Linux and Clojure, and co-authored the book The Joy of Clojure

  • block devices
  • Add tags

    fdisk is the general name for system utilities for managing hard disk partitions. They are widespread and available on almost any operating system, but they work differently. Use a text-based user interface.

    Warning: Don't create, delete or modify partitions unless you know what you're doing!

    FDISK utility in Unix/Linux

    With FDISK utility you can view, create, resize, delete, copy and move partitions on your hard drive. And I will give clear examples of use.

    Viewing partitions in Unix/Linux

    Let's start with the easiest thing - viewing sections. Use the "-l" option with the FDISK command to view available partitions on Linux (on Unix systems - this option may not work. Tested on Mac OS X). All available partitions in Linux are displayed by the name of their device. For example: /dev/sda, /dev/sdb or /dev/sdc.

    So, let's run the command:

    The conclusion we get is the following:

    You can find out some useful information about a specific block device. For example, the following command will display all partitions for /dev/sda:

    If you have different device names, simply write the device name as /dev/sdb or /dev/sdc and so on.

    Displaying available commands via FDISK

    If you would like to see all the commands that are available for FDISK, then simply use the following command by mentioning the name of the hard drive, for example /dev/sda, as shown below:

    output all available commands for FDISK for example for /dev/sda

    Type 'm' to see a list of all available FDISK commands that will help with the /dev/sda hard drive. After entering 'm' on the screen, you will see all the available options for FDISK that you can use for the /dev/sda device (this device is taken as an example):

    WARNING: DOS-compatible mode is not recommended. Highly recommended
    turn off the mode (command 'c') and change units for the sector (command 'u').

    Valid options when working with fdisk

    • a:- This option is used to toggle the boot flag.
    • b:- This option is used to edit the BSD disk label.
    • c:- This option is used to toggle the dos compatibility flag.
    • d:- This option is used to delete a partition.
    • g:- This option creates a new, empty GPT partition table.
    • G:- This option is used to create an IRIX partition table (SGI).
    • l:- This option is used to display known partition types (Linux swap, Linux, GPT, Solaris, and so on).
    • m:- This option is used to display available commands (menus).
    • n:- This option is used to add a new section.
    • o:- This option is used to create a new empty DOS partition table.
    • p:- This option is used to display partition tables.
    • q:- This option is used to exit the menu but without saving any changes.
    • s: - This option creates a new and empty Sun disk label.
    • t:- This option is used to change the type of “System ID” of the partition (you can take it from the output of the “l” option).
    • u:- This option is used to change display/input blocks.
    • v:- This option is used to check partition tables.
    • w:- This option is used to record everything changed and then exit.
    • x:- This option is used to call additional functionality (for experts only).

    Displaying all partitions (sections) in Unix/Linux

    To list your block device's partition table, use:

    # fdisk /dev/sda

    After which, you find yourself in a menu (you can perform various operations with partitions in it), we are only interested in viewing, so we enter the “p” option:

    Create a partition table (disklabel) in Unix/Linux

    If you have an empty block device and you want to make markup on it for installing a future OS, then first you should select the future markup.

    Here are the main tables for marking:

    • MBR (msdos)

    To create your block device's partition table, use:

    # fdisk /dev/sda

    This action selected the block device /dev/sda and to create a new partition table on it, use one of the options:

    • g - To create a new, empty GPT partition table.
    • o - To create a new, empty DOS partition table.

    And let's move on to creating sections.

    Create a new partition in Unix/Linux

    And so, let’s say you have free space on one of the devices (for me it’s /dev/sda) and you need to create a new partition (for example, to install the OS). Then you should run the utility as follows (Type the following command to enter the control mode of a specific block device):

    # fdisk /dev/sda

    After entering command mode, press "n" to create a new partition in /dev/sda with a specific size.

    After pressing "n", you are asked to select the type of the future partition:

    • p — For " primary", i.e. create a primary partition.
    • e - For “extended”, i.e. create an extended partition.

    I would like to note the following: “primary” partitions can be created up to 4 pieces, and all the rest will be “extended” (i.e. extended partitions). Since for me this is only the 1st section, I select the “p” option. As I said earlier, this is my first, primary partition and for it, I must indicate the number (partition number), logically indicate 1 (But you can choose 1-4, since there are only 4). To create a full-fledged partition, you need to specify a sector (the beginning of the cylinder position for the partition being created), they tell me what it will be - 2048 (selected the standard value), and also, you need to indicate where this sector will end (the end of the cylinder position for the partition being created) - I am offered to indicate the standard value, but it does not suit me, because it will create 1 partition of maximum length (at For me it's 21 GB - test machine). At this stage, you can indicate the end of the sector in kilobytes (K), megabytes (M), gigabytes (G). Suppose I want to create the first 5GB partition, then I should enter “+5G” (or “+5000M” and so on).

    You can also create several sections. The actions will be the same.

    Please keep in mind that after creating a new partition, you must run the 'w' command for all actions to be saved. Well, after that, restart the OS to make sure that the partition has been created.

    Formatting partitions in Unix/Linux

    After the partitions have been created, formatting must be done. But before moving on to this action, you need to decide on the file system (FS).

    I will use the mkfs utility to format the partition. This utility supports the following FS:

    • ext2: # mkfs.ext2 /dev/sda1
    • ext3: # mkfs.ext3 /dev/sda4
    • ext4: # mkfs.ext4 /dev/sda4
    • fat: # mkfs.fat /dev/sda4
    • minix: # mkfs.minix /dev/sda4
    • msdos: # mkfs.msdos /dev/sda4
    • vfat: # mkfs.vfat /dev/sda4
    • xfs: # mkfs.xfs /dev/sda4

    We select the type of pharmaceutical substance and proceed to pharmaceutical preparation.

    Check partition size in Unix/Linux

    After formatting a new partition, you can check the size of the partition using the “s” flag and the FDISK command. This way you can check the size of any specific device. For example:

    # fdisk -s /dev/sda3 5285413

    The size is displayed in blocks.

    To output in gigabytes (GB), use:

    # echo "`fdisk -s /dev/sda2`/(2^20)" | bc # echo "`fdisk -s /dev/sda1`/(2^20)" | bc # echo "`fdisk -s /dev/sda`/(2^20)" | bc

    Looks usable.

    Enable/Disable loading flag (*) from partition in Unix/Linux

    When marking, I usually allocate 100MB for the partition in which the bootloader will be stored. And for this purpose, it is necessary to indicate that it will be downloaded from it. And therefore, you need to indicate the desired section. Let's start:

    # fdisk /dev/sda

    The first step is to view the available partitions to see the current partition table. As you remember, this is the “p” option. In my screenshot below, you can see that the boot partition is on the /dev/sda1 disk (you can see that this is the boot flag - the asterisk ‘*’), as shown below:

    To enable the boot flag, use the “a” option. After clicking, you will need to enter the number of the partition that will be loaded (for example, 1st) and put everything back in place.

    Delete a partition in Unix/Linux

    If you would like to remove a specific partition (i.e. /dev/sda4) from a specific block device (i.e. - /dev/sda). You must do:

    # fdisk /dev/sda

    Then, enter 'd' to enter the delete partition menu. After entering, they ask you to enter the number of the section that I want to delete. Suppose I need to delete the 4th partition, then I enter “4”. That's it, the section has been deleted. Enter 'w' to record all changes! New changes will only work after the next system reboot. This can be easily understood from the below output.

    Warning: Be careful when performing this step because using the 'd' option will completely remove the partition from the system and you may lose all data on the partition!

    Using fdisk in bash scripts

    If you know the commands well, you can write a small bash script or simply use this construction in the shell shell, which would emulate the user’s work:

    Fdisk /dev/hda<< EOF n p 1 a 1 t c w EOF

    I will not explain what these letters do, because I described all the options above.

    The topic is "How to use FDISK command on Linux", I tried my best to cover almost all the basic commands of fdisk, but still FDISK contains many other commands you can use them by typing "x". For more details, enter the command 'man Fdisk' in a terminal.