You get a bonus - 1 coin for daily activity. Now you have 1 coin

18 - fdisk command

Lecture



The last lecture was devoted to hard drives in general and Linux in particular. Today we will talk about how to split the hard disk into sections, how to format the partition and what file systems are there. In order to create partitions on a new disk, it is quite suitable for us to be *** and fdisk . The com *** and fdisk exists in all Linux distributions , therefore it is in this sense a universal tool. A com *** and fdisk can create and delete partitions, but cannot resize existing partitions. If there is a section A and B of the same size and it is necessary to increase section A due to section B, then *** and fdisk will not be able to do this “on the fly”. You will have to save all the information, delete sections A and B, and then create new sections A and B with the required sizes.

Suppose we have a clean unformatted hard disk / dev / sdc , which we need to split to install a Linux system. Run the fdisk program with the / dev / sdc option. Work in the fdisk program is necessary on behalf of the superuser.

igor @ adm-ubuntu: ~ / linux $ sudo fdisk / dev / sdc

The number of cylinders for this disk is set to 19457.
That's all right, but the value is greater than 1024,
and in separate installations problems may arise with:
1) startup programs (eg old versions of LILO)
2) download and markup programs from other OS
(eg, DOS FDISK, OS / 2 FDISK)

Com *** a (m for reference):

With this command, we start working with our hard disk interactively. The tip tells us that you need to press m for reference. Press the m key and see the list of basic commands:

Team action
a switch boot flag
b bsd disc label editing
c switching dos compatibility flag
d delete section
l List of known file system types
m display of this menu
n add new section
o creating a new empty DOS partition table
p output partition table
q exit without saving changes
s creating a new blank Sun disk label
t change id of partition system
u change screen / content units
v check partition table
w write partition table to disk and exit
x additional functionality (for experts only)

Let's click on the p button to see if there are any partitions on our disk:

Disk / dev / sdc: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors / track, 19457 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0 × 28f12a69

Device Zagr Start End Blocks Id System

We see general information about our disk and see that there are no partitions on the disk. Now press the l button to see which types of file systems are supported by *** and fdisk . The list of file systems is large, interesting for us:

5 - advanced
82 - Linux swap
83 - Linux (ext2 / ext3 / ext4)

Let's start creating sections. Let we have 5 sections. The first partition will be 200 MB in size, and the / boot directory will be stored on it. Next will go to the partition where the rest of the Linux operating system will be installed (select 20 GB), then the swap partition (2 GB), then the extended partition, which will be divided into two identical partitions.

To create a partition, you must press the n key:

Com *** a (m for reference): n
Team action
e advanced
p main section (1-4)

fdisk asks which partition we want to create: extended or primary. We need the main section, so we press p and Enter

Section number (1-4):

Next, you need to specify the partition number so that fdisk knows in which section of the table the section of the MBR section to write information about the partition. Option can be only four (by the number of sections). We will specify in order, so press 1 and Enter

The first cylinder (1-19457, default 1):

Next, fdisk asks you to specify from which cylinder the partition will start and offers the first cylinder by default, that is, the very beginning of our disk. Agree and without entering anything, press Enter

Last cylinder + cylinders or + size {K, M, G} (1-19457, default 19457):

Next, we need to specify what size the section will have. The size can be specified either in cylinders (which is not very convenient for us), or in kilo-, mega-gigabytes, which is much more convenient. Our first section will be 200 MB, so type + 200M and press Enter . Creating a partition is complete, press p to check this:

Com *** a (m for reference): p

Device Zagr Start End Blocks Id System
/ dev / sdc1 1 26 208813+ 83 Linux

We see that the section is created. We create in the same way two more sections. After that, press p to check the sections:

Device Zagr Start End Blocks Id System
/ dev / sdc1 1 26 208813+ 83 Linux
/ dev / sdc2 27 2638 20980890 83 Linux
/ dev / sdc3 2639 2900 2104515 83 Linux

The fourth section we create advanced. After we choose clicking on the e - type advanced, then press Enter accepting all the default values. Thus, we will allocate the remaining space for the extended partition:

Com *** a (m for reference): n
Team action
e advanced
p main section (1-4)
e
Selected section 4
The first cylinder (2901-19457, by default 2901):
The default value of 2901 is used.
Last cylinder + cylinders or + size {K, M, G} (2901-19457, 19457 by default):
The default value of 19457 is used.

Now let's start creating logical partitions on our extended partition. Press n again and see that now the fdisk program works only with the extended partition:

The first cylinder (2901-19457, by default 2901):

The process of creating logical partitions is no different from the process of creating main partitions. As a result, we obtain the following picture by sections:

Device Zagr Start End Blocks Id System
/ dev / sdc1 1 26 208813+ 83 Linux
/ dev / sdc2 27 2638 20980890 83 Linux
/ dev / sdc3 2639 2900 2104515 83 Linux
/ dev / sdc4 2901 19457 132994102+ 5 Advanced
/ dev / sdc5 2901 11179 66501036 83 Linux
/ dev / sdc6 11180 19457 66493003+ 83 Linux

The / dev / sdc3 section should be formatted as a swap partition . Therefore, we need to make changes to the file system type of the / dev / sdc3 partition . To do this, press t , then select the partition and specify the identifier of the new partition type (for swap it is 82):

Com *** a (m for reference): t
Section number (1-6): 3
Hex code (enter L for a list of codes): 82
System type of section 3 changed to 82 (Linux swap / Solaris)

In the same way, you can change the file system types on other partitions. Check the sections com *** th p :

Device Zagr Start End Blocks Id System
/ dev / sdc1 1 26 208813+ 83 Linux
/ dev / sdc2 27 2638 20980890 83 Linux
/ dev / sdc3 2639 2900 2104515 82 Linux swap / Solaris
/ dev / sdc4 2901 19457 132994102+ 5 Advanced
/ dev / sdc5 2901 11179 66501036 83 Linux
/ dev / sdc6 11180 19457 66493003+ 83 Linux

Sections created. Now attention! All the hard disk manipulations that we just did while stored in RAM and no changes were made to the hard disk. In order to make these changes, you need to press the w (write) key. After this, the changes will be irreversible. If you now press the q key instead of w , then the fdisk utility will finish its work and no changes will be applied.

If you use the fdisk command to create a partition into which the Windows boot loader will be installed, then you need to remember to make this partition active using the a command.

After creating partitions and restarting the computer, the sections need to be formatted. For this purpose the com *** a mkfs is intended. To format a partition, you need to specify the file system type and the partition itself:

igor @ adm-ubuntu: ~ $ mkfs -t ext4 / dev / sda

For the most commonly used file systems there are commands like mkfs.ext4, mkfs.ext3, mkfs.vfat and others. That is, the / dev / sda8 partition could be formatted with *** d: sudo mkfs.ext4 / dev / sda8 .

In order to format the partition under the swap-area you need to use the following *** mkswap : mkswap / dev / sdc3 . In order to connect the swap partition, use the com *** and swapon . To disable the swap-area there is a com *** and swapoff . In order for the swap partition to automatically connect when the system is booted, you must specify the appropriate mount line in the / etc / fstab file . In order to see if the swap area is used in the system, you can use the *** *** free command:

igor @ adm-ubuntu: ~ $ free
total used free shared buffers cached
Mem: 1024752 581616 443136 0 16888 158100
- / + buffers / cache: 406628 618124
Swap: 1140544 1792 1138752

We see that in the system under the swap area 1 GB of disk space is used.

For more complex disk partitioning (resizing disk partitions without losing information), you can use the *** n parted com , which is also included by default in most distributions. There is also a graphical version of the utility called gparted . That's all with the hard drive partitions for now. The information obtained should be sufficient for self-partitioning the hard disk into the required number of partitions.

See also

created: 2014-09-13
updated: 2024-11-11
214



Rating 9 of 10. count vote: 2
Are you satisfied?:



Comments


To leave a comment
If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

LINUX operating system

Terms: LINUX operating system