Management of physical and virtual dimensions
Bytes, kilobytes, megabytes, gigabytes
First, it is imperative to know the conversions of bytes. Unlike what you may think, not 1 Kilobyte is 1000 bytes (10 ^ 3). We are not in fact in our beloved decimal system, or base 10, but we are dealing with the powers of 2 (2 in fact are the types of bits, 1 or 0).
For this we have: 1KB = 1024 bytes 1MB = 1024KB 1GB = 1,024 MB = 1024 GB 1TB (terabyte) How to find then the conversion formulas? It ‘s simple: to move from a larger to a smaller, simply multiply by 1024. For example: dimensione_in_KB = dimensione_in_MB * 1024 On the contrary, to change from a smaller order units compared to a bigger order, is divided by 1024:dimensione_in_MB = dimensione_in_KB / 1024th of course, these operations must be done every time you pass by an order of magnitude. The number 1024 is the result of 2 ^ 10 (2 to 10). We therefore: 1KB = 2 ^ 10 bytes = 1024 bytes 1MB = 2 ^ 20 bytes = 1048576 bytes (1024 KB) 1GB = 2 ^ 30 bytes = 1073741824 bytes (1024 MB, KB 1048576) 1TB = 2 ^ 40 bytes = 1 , 0995116 ^ 12 Bytes (1024 GB, MB 1048576, 1073741824 KB) Well, once explicate this concept we can proceed to analyze the hard drive.Dimensions in physical-geometric level (hard disk) one of the most fascinating things of our computer to understand how the hard disk. I do not dwell on the true structure of a hard disk or on the division into cylinders, and so on. I will only discuss the aspects necessary to us. First, we can say that the disk space is divided into SECTORS , or a portion of bytes not divisible further (as if it were a prime number). A sector, in most cases is large 512 bytes. With what instrument in Linux better manage our hard drive? As a good slackarista my answer is “fdisk”. Then we open a console and give the command “fdisk / dev / nome_harddisk”: #fdisk / dev / hdaThe number of cylinders for this disk is to September 1247. There is nothing wrong With That, but this is larger than 1024, and could in certain setups cause problems with: 1) That software runs at boot time (eg, old versions of LILO) 2) booting and partitioning software from other OSs (eg, DOS FDISK, OS / 2 FDISK) Command (m for help): If your hard drive is fairly new, most likely you will appear that warning. This happens because fdisk warns you that the number of cylinders of your hard drive is 1247 (in my case), which is larger than 1024. In this case it may create some problems to boot because it is known that the BIOS can not read well the cylinder 1024 (so if you put the kernel image and boot software over this cylinder, almost certainly not be able to boot the system). Either way will get the last line. By typing “h [ENTER]” you ottrrete a list of possible actions to do with fdisk / dev / hda. We are interested, first of all, to change the units from cylinders to sectors (as it is the same but more easy to deal with). Then give the command “u [ENTER]”: Command (m for help): u Changing display / entry units to sectorsCommand (m for help): Now let’s see how it is organized in our hard disk partitions. To do that we give the command “p [ENTER]”:Command (m for help): p Disk / dev / hda: 255 heads, 63 sectors, 1247 cylinders Units = sectors of 1 * 512 bytes Device Boot Start End Blocks Id System / dev / hda1 63 16386299 8193118+ 83 Linux / dev / hda2 16,386,300 18,483,452 1048576+ 83 Linux command (m for help): Let’s comment on the output of this command. The first line shows the characteristics of my hard drive: 255 heads, 1247 cylinders, and so on. The second line is very important: it provides the size of a sector, here equal to 512 Bytes. The other lines indicate that there are two partitions on my HD (hda1 and hda2). The first column (device) indicates the device / dev / relative to the partition, the second column indicates whether a partition is bootable or not, the third column (start) indicates the start sector of the partition, the fourth column (end) indicates the sector of the end of a partition. The Blocks column shows the size of the partition BLOCKS; and finally System ID and indicate the type of partition. The aspects that interest us are the columns Start, End and Blocks. Let’s figure it out. Each partition has a beginning and a physical-geometrical order and as we said before the indivisible unity of HD is the industry. A partition must begin then to a field X and end up in another area Y. The next partition will need from sector Y + 1 and get to Z. sector is not necessary that all the HD sectors are incorporated in a partition, but this would be a useless waste of space. Our aim is to find correspondences between start-end of a partition and its size, as well as to create new partitions exactly the desired size. For now we know that: 1 sector = 512 bytes But then we can calcolarci in which byte begins and ends a partition with a simple proportion: 1 sector: 512 bytes = 63 sectors: X bytes = bytes x 63 sectors * 512 bytes = 35256 bytes = 31.5 KB (I divided by 1024bytes –1KB–) As you can see, the calculation performed corresponds to the formula in the second line !! We now know that the hda1 partition start to 31,5KB (relative to the beginning of the harddisk sectors). Let us now to know when it ends: x bytes = 16386299 * 512 = 8389785088/1024 = 8193149.5 KB (equals … 8001.12 MB or 7.8 GB) ends all’8193149,5 ° KB. To calculate the size of this partition just subtract the two dimensions: Size = KB_finali – KB_iniziali = 8,193,149.5 to 31.5 = 8193118 KB Since we have calculated the size of the partition, this should match the number in the “Blocks” column, and indeed it is. Note that the + after the number indicates that the size is given in KB, as we have them we also calculated. Because to calculate the size in KB we divided by 1024 (1KB) we can say that the size of a block is equal to 1KB: 1 block = 1K (1024 bytes) And so we also found the latest report required and to remember. This report, in contrast to that of the sectors, should be valid for each hard drive. Now that we know everything, let’s see how you can deal with the creation of a new partition. First we remove a partition to create a little ‘space: Command (m for help): d Partition number (1-4): 1 Command (m for help): Then let’s say that from that first (great about 7, 8 GB) we were to create a just 5GB. Then give the command “n”: Command (m for help): n Command action and extended p primary partition (1-4) p Partition number (1-4): 1 First sector (63-20033054, default 63): 63 Last sector or + size or + sizeM or + sizeK (63-16386299, default 16386299) , then asks us the number of first asks us if we want to create a primary or extended partition (and I gave “p” primary) partition (and trouble I have given “1”). Then we are asked the start sector. Since the partition is the first, I shall put the beginning of the disk space used to partitions (block 63). Then we are asked to size in various forms: through the final sector, through Bytes size, via size in MB and by size in KB. Here we can do what we want. It ‘s always better to go into specifics but (now that we have the means), and choose whether to indicate the end sector or size in KB (because as 1blocco = 1k then it is useless to give the size in bytes knowing that is adapted to the KB, since 1k becomes the indivisible): Dimensione_in_KB Dimensione_in_GB * = 2 ^ 20 = 1048576 * 5 = 5242880 KB (which is equivalent to GB * 1024 * 1024). It ‘still useless to give the size in sectors, since then always treat and only in size in KB. We respond so well: Last sector or + size or + sizeM or + sizeK (63-16386299, 16386299 default): + 5242880K We see it is now the partition table: Command (m for help): p Disk / dev / hda: 255 heads, 63 sectors, 1247 cylinders Units = sectors of 1 * 512 bytes Device Boot Start End Blocks Id System / dev / hda1 63 10485823 5242880+ 83 Linux / dev / hda2 16,386,300 18,483,452 1048576+ 83 Linux The size is just right. We try to check if the blocks also match: Bytes_iniziali = 3525.5 Bytes Bytes_finali = 5242880 * 1024 = 5,368,709,120 BytesSettore_finale = (5368709120/512) = +63 10485823 OK, matches everything! Our reasoning are right. To save the changes you just give “w [ENTER” to exit and discard the changes to “q [ENTER].” Now that we have handled it from the physical-geometric level (the hard drive) , we’re going to handle it than vIRTUAL (filesystem). virtual level Dimensions (file system) reconsider the structure of the hard disk like the one you just created (with the first partition to 5GB). After you create the underlying infrastructure (physical) hard disk, you must create another layer above this is called FILESYSTEM. The file system is a way of organizing data harddisk. For this there are several types of filesystems. Here we will consider a ext2 / 3, but the dimensional speech is the same for all types of partitions. We have defined the file system as a veil to be placed over the frame of the hard disk. It ‘clear then that this veil can manage the size differently from the hard disk, and most likely there will have also noticed when you try to resize a fs. The filesystem is thus placed at a higher level, that we can define virtual and our task is to define the terms of confrontation and equality between the physical and the virtual harddisk filesystem. The discussion is still once the number of blocks (which determine the size). The filesystem does not think more in terms of sectors and cylinders, because this is useful only at the physical level. The fs is BLOCKS, as was also seen at the physical level with fdisk. We then found our basis of comparison: the BLOCK. While at the physical level, as we have seen, the block was equal to 1KB (1024 bytes), a file system layer can be of a different size (given that transcends physical reality.) Most important is to understand that WHILE THE SIZE REMAINS THE SAME BOTH PHYSICAL LEVEL THAT VIRTUAL, THE NUMBER OF BLOCKS A PHYSICAL LAYER CAN BE DIFFERENT FROM THE NUMBER OF BLOCKS LEVEL VIRTUAL .They ‘important to know the number of blocks from a given size, because all programs for the management of the hard drive and require fs in place of the size in kilobytes, the number of blocks (the utilities for managing ext2, ext3 are an example). In an ext2 / 3 filesystem, one block can be equal to a rule: 1 block = 1KB (1024 bytes) 1 block = 2KB (2048 Bytes) 1 block = 4KB (4096 bytes)How to know the size of a block of its fs ? Normally this is automatically determined by the size of the file system, but can also be specified to the creation of the filesystem. To know your size of a block search for line “Block size: 4096” from the command output “dumpe2fs / dev / tua_partizione -h.” Should one block corresponds to 1KB, then there would be a 1: 1 ratio between the number of physical blocks and that of virtual blocks. In this case we would have to: 5242880 = 5242880 KB_fisici KB_virtuali (BUT THIS IT IS IN ANY EVENT, THE SIZE NOT CHANGE). Blocchi_fisici 5,242,880 = 5,242,880 Blocchi_virtuali. In the third case, however, that we would have one physical block is 4 times smaller than a virtual block. We would therefore have to: 5242880 = 5242880 KB_fisici KB_virtuali (ALWAYS ALWAYS ALWAYS), but 5,242,880 Blocchi_fisici (1KB) = 5242880/4 Blocchi_virtuali (4KB) = 1310720. We then that while the size remains the same, the physical blocks are 4,242,880 while those are virtali 1310720 (four times less.) to test these relationships, we can create a fs on the new 5GB partition created at the end of the previous chapter. Let’s create a fs with a block size of 1KB (thus verifying the first hypothesis): # mke2fs -b 1024 / dev / hda1 5,242,880 not place the output why should I try to give the command, and I do not want to lose all my data. However you should create you the file system without problems. If you try to give a size of an upper block (5242881) you will see that warns you that the file system will be larger partition and asks you whether to continue or not. You obviously you type “n”. So you are sure that you have created a file system that takes all the partition and that the ratio is 1: 1. Now let’s create a fs with the block size of 4096 bytes (4KB): # mke2fs -b 4096 / dev / hda1 1310720 should create you the fs without problems. If you try as before to give a size greater than 1 block (1310721) you will see that warns you again. So we are sure that the ratio to 1: 4 and, above all, mke2fs TAKES AS TOPIC DIMENSION IN BLOCKS ON THE SIZE OF BLOCK THAT IS GOING TO CREATE FOR THE FILE SYSTEM. I’d say we’re done. At the end of this speech, it is crucial to reaffirm that: IF YOU ARE DEALING WITH PROGRAMS THAT OPERATE A PARTICULAR LEVEL (THAT CAN BE THAT PHYSICAL GEOMETRIC OR THE VIRTUAL) MUST SPECIFY THE NUMBER OF BLOCKS WITH RESPECT TO THE SIZE OF UNIT LEVEL OF THE TREATY (typically 1K for physical-geometrical and 1024.2048 or 4096 for that virtual).