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

17 - Linux Hard Drives

Lecture



In this lecture we will talk about such an important element of a computer as a hard disk. Let's see how the hard disk is divided into sections, what types of partitions are and what Linux commands allow you to work with partitions. You already know that a hard disk is a block device. Indeed, at the physical level, a hard disk consists of many blocks. All blocks of fixed size are 512 bytes and this block is called a sector . In the very first sector of the hard disk recorded a special record, which is called the MBR - master boot record . We already spoke about the MBR in the second lecture. I will duplicate for clarity the image showing the structure of the MBR .

  17 - Linux Hard Drives

Picture 1

Note the MBR subkey, which is called the partition table . As you can see, only 64 bytes are allocated for sections in the MBR , and since 16 sections are needed to identify one section, there can be no more than four such sections. Each partition could contain one file system. This operation was called partition formatting. Up to a certain point, four partitions were enough, but with the growth of hard disk volumes, there was a need for more partitions. But they can not be more, since it was originally laid no more than 4 sections. Of the many solutions to this problem, choose the following. Invented a special file system which was called Extended . One of the sections can be assigned to such a file system. Sections that are described in the MBR table are called primary (or primary) partitions ( primary partition ). However, the extended file system (extended) partition is often called the extended partition . At the beginning of the extended section there was its own partition table (we can say that it was a continuation of the MBR table). That is, the extended partition could in turn be divided into sections, which became known as logical partitions . Unlike the static partition table MBR , the partition table of the extended partition is dynamic and contains as many entries about logical partitions as there are at the moment. If you create 4 main partitions on your hard disk, you will not be able to create the fifth partition. If you need more than 4 partitions, then one of the partitions must be extended , which in turn can be divided into the required number of logical partitions.

On Windows systems, there is such a thing as an active hard disk partition. This is the partition that contains the Windows boot loader, and if you install Windows into a partition that is not marked as active (no special flag is set in the partition table), then the operating system will not be able to boot. In Linux, this flag does not matter and the system will boot even if the boot disk is not marked as active.

We already know that the hard disk and its partitions are represented in the system as device files. IDE interface disks are designated as hda , hdb, hdc or hdd . If the drive is connected to the first IDE connector as master , then it will be defined as hda , if as slave , then hdb , etc. Disks with SCSI or SATA interfaces are denoted as sda, sdb, sdc , etc. SATA drives are designated slightly differently than IDE . The name of the SATA drive does not depend on which SATA connector you have connected the drive to. For example, you have six SATA connectors (we number them from 0 to 5). Regardless of which connector to connect the drive, it will be called sda . If you have two or more SATA drives in the system, then the drive that is connected to the connector with the lowest number will be designated as sda , and then in order ( sdb, sdc , etc.). Consider the following. If your SATA drive was always connected, for example, to the second slot (called sda ), and then you connected another drive to the first slot, then the new drive will now be called sda , and your old drive will be called sdb . It is for this reason that it is recommended to write hard disk partitions in the / etc / fstab file through their UUIDs .

How to see what drives u have in the system? There are several options. For example, use the information that you can get executable com *** from dmesg . A com *** and dmesg displays all kernel messages about system hardware devices and hardware changes in the system (events). Such messages begin to form the kernel from the beginning of the boot system during device initialization. If there are a lot of messages and they do not fit everything on the screen, then execute a com *** in dmesg | less to send all the information to the less viewer. Below is an output fragment describing the hard disk:

[1.637632] ata2.00: ATA-7: WDC WD2500KS-00MJB0, 02.01C03, max UDMA / 133
[1.637635] ata2.00: 488397168 sectors, multi 16: LBA48
[1.638258] ata2.00: configured for UDMA / 133
[1.652114] scsi 1: 0: 0: 0: Direct-Access ATA WDC WD2500KS-00M 02.0 PQ: 0 ANSI: 5
[1.652228] sd 1: 0: 0: 0: Attached scsi generic sg0 type 0
[1.652266] sd 1: 0: 0: 0: [sda] 488397168 512-byte logical blocks: (250 GB / 232 GiB)
[1.652306] sd 1: 0: 0: 0: [sda] Write Protect is off
[1.652309] sd 1: 0: 0: 0: [sda] Mode Sense: 00 3a 00 00
[1.652331] sd 1: 0: 0: 0: [sda] Write cache: enabled, read cache: enabled, does not support DPO or FUA
[1.652449] sda: sda1 sda2 sda3 sda4
[1.689646] sda6 sda7 sda8 sda9>

We see that we have a WDC WD2500KS-00M disk, that it is divided into four main partitions - sda1, sda2, sda3 and sda4 , which is an extended partition and in turn is divided into logical partitions sda5, sda6, sda7, sda8, sda9 .

You can also see what kind of hard drives we have by running the *** command at ls -l / dev / [h, s] d? :

igor @ ubuntu: ~ / linux $ ls -l / dev / [s, h] d?
brw-rw—- 1 root disk 8, 0 2009-11-18 22:58 / dev / sda
brw-rw—- 1 root disk 8, 16 2009-11-18 22:58 / dev / sdb

Another com *** a - fdisk with the -l key. It should be executed on behalf of the administrator and show the following information:

igor @ ubuntu: ~ $ sudo fdisk -l

Disk / dev / sda: 250.1 GB, 250059350016 bytes
255 heads, 63 sectors / track, 30401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xd4b146b8

Device Zagr Start End Blocks Id System
/ dev / sda1 * 1 2304 18506848+ 7 HPFS / NTFS
/ dev / sda2 2305 2472 1349460 e W95 FAT16 (LBA)
/ dev / sda3 2473 10263 62581207+ 7 HPFS / NTFS
/ dev / sda4 10264 30401 161758485 f W95 ext. (Lba)
/ dev / sda5 10264 12826 20587266 83 Linux
/ dev / sda6 12827 12947 971901 82 Linux swap / Solaris
/ dev / sda7 12948 18184 42066171 7 HPFS / NTFS
/ dev / sda8 18185 27967 78581916 7 HPFS / NTFS
/ dev / sda9 27968 30401 19551073+ 7 HPFS / NTFS

Disk / dev / sdb: 40.0 GB, 40020664320 bytes
255 heads, 63 sectors / track, 4865 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xb292b292

Device Zagr Start End Blocks Id System
/ dev / sdb1 1,460 37431418+ 83 Linux
/ dev / sdb2 4661 4865 1646662+ 5 Advanced
/ dev / sdb5 4661 4850 1526143+ 82 Linux swap / Solaris
/ dev / sdb6 4851 4865 120456 83 Linux

As you can see, we get information about the disk, its partitions and the file system contained in each partition. Com *** and fdisk designed to manage the partition table of the hard disk. In other words, this com *** allows you to partition the disk - partition it and assign file systems. This team is devoted to the following lecture.

See also

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



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