Partitioning will allow the installation of several operating systems because it is impossible to have several of them cohabit on the same logical drive. Partitioning also allows the separation of data logically (security, access optimization, ...).
The division of the physical disk into partitioned volumes is recorded in the partition table, stored in the first sector of the disk (MBR: Master Boot Record).
The same physical disk can be divided into a maximum of 4 partitions:
Primary (or main)
Extended
!!! Warning There can be only one extended partition per physical disk. In order to benefit from additional drives, the extended partition can be split into logical partitions
The devices are the files identifying the various hardware detected by the motherboard. These files are stored without /dev. The service which detects new devices and gives them names is called udev.
They are identified by their type.
Storage devices are named hd for IDE hard drives and sd for other media. Then comes a letter that starts with a for the first device, then b, c, ...
Finally we will find a number that defines the partitioned volume: 1 for the first primary partition, ...
!!! Warning Beware, the extended partition, which does not support a file system, still has a number.
There are at least two commands for partitioning a disk: fdisk and cfdisk. Both commands have an interactive menu. cfdisk is more reliable and better optimized, so it is best to use it.
The only reason to use fdisk is when you want to list all logical devices with the -l option.
$ sudo cfdisk /dev/sda
Disk: /dev/sda
Size: 16 GiB, 17179869184 bytes, 33554432 sectors
Label: dos, identifier: 0xcf173747
Device Boot Start End Sectors Size Id Type
>> /dev/sda1 * 2048 2099199 2097152 1G 83 Linux
/dev/sda2 2099200 33554431 31455232 15G 8e Linux LVM
lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk
x Partition type: Linux (83) x
x Attributes: 80 x
xFilesystem UUID: 54a1f5a7-b8fa-4747-a87c-2dd635914d60 x
x Filesystem: xfs x
x Mountpoint: /boot (mounted) x
mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
[Bootable] [ Delete ] [ Resize ] [ Quit ] [ Type ] [ Help ]
[ Write ] [ Dump ]
The preparation, without LVM, of the physical media goes through five steps:
Setting up the physical disk;
Partitioning of the volumes (geographical division of the disk, possibility of installing several systems, ...);
Creation of the file systems (allows the operating system to manage the files, the tree structure, the rights, ...);
Mounting of file systems (registration of the file system in the tree structure);
Volume management creates an abstract layer on top of physical storage, offering advantages over using physical storage directly:
More flexible disk capacity;
Online data movement;
Disks in stripe mode;
Mirrored volumes (recopy);
Volume snapshots (snapshot).
The disadvantage is that if one of the physical volumes becomes out of order, then all the logical volumes that use this physical volume are lost. You will have to use LVM on raid disks.
LVM is available under Linux from kernel version 2.4.
!!! Note LVM is only managed by the operating system. Therefore the BIOS needs at least one partition without LVM to boot.
The physical volumes PVPhysical Volumes (from partitions) are combined into volume groups VG. Each VG represents disk space that can be partitioned into LVLogical Volumes. Extension is the smallest unit of fixed-size space that can be allocated.
The mkfs command allows you to create a Linux file system.
mkfs [-t fstype] filesys
Example:
[root]# mkfs -t ext4 /dev/sda1
Option
Description
-t
Indicates the type of file system to use.
!!! Warning Without a file system it is not possible to use the disk space.
Each file system has a structure which is identical on each partition. A boot block and a super block initialized by the system and then an inode table and a data area initialized by the administrator.
!!! Note The only exception is the swap partition.
The boot block occupies the first block on the disk and is present on all partitions. It contains the program that starts and initializes the system and is therefore only filled in for the boot partition.
The size of the super block table is defined at creation. It is present on each partition and contains the elements necessary for its utilization.
It describes the File System:
Name of the Logical Volume;
Name of the File System;
Type of the File System;
File System Status;
Size of the File System;
Number of free blocks;
Pointer to the beginning of the list of free blocks;
Size of the inode list;
Number and list of free inodes.
A copy is loaded in the central memory as soon as the system is initialized. This copy is updated as soon as it is modified and the system saves it periodically (command sync).
When the system stops, it also copies this table in memory to its block.
The size of the inode table is defined at its creation and is stored on the partition. It consists of records, called inodes, corresponding to the files created. Each record contains the addresses of the data blocks making up the file.
!!! Note An inode number is unique within a file system.
A copy is loaded in the central memory as soon as the system is initialized. This copy is updated as soon as it is modified and the system saves it periodically (command sync).
When the system stops, it also copies this table in memory to its block.
A file is managed by its inode number.
!!! Note The size of the inode table determines the maximum number of files the FS can contain.
Information present in the inode table :
Inode number;
File type and access permissions;
Owner identification number;
Identification number of the owner group;
Number of links on this file;
Size of the file in bytes;
Date the file was last accessed;
Date the file was last modified;
Date of the last modification of the inode (= creation);
Table of several pointers (block table) to the logical blocks containing the pieces of the file.
Its size corresponds to the rest of the available space of the partition. This area contains the catalogs corresponding to each directory and the data blocks corresponding to the contents of the files.
In order to guarantee the consistency of the file system, an image of the superblock and the inode table is loaded into memory (RAM) when the operating system is loaded so that all I/O operations are done through these system tables. When the user creates or modifies files, this memory image is updated first. The operating system must therefore regularly update the superblock of the logical disk (sync command).
These tables are written to the hard disk when the system is shut down.
!!! Danger In the event of a sudden stop, the file system may lose its consistency and cause data loss.
It is possible to check the consistency of a file system with the fsck command.
In case of errors, solutions are proposed to repair the inconsistencies. After repair, files that remain without entries in the inode table are attached to the /lost+found folder of the logical drive.
The /etc/fstab file is read at system startup and contains the mounts to be performed. Each file system to be mounted is described on a single line, the fields being separated by spaces or tabs.
!!! Note Lines are read sequentially (fsck, mount, umount).
Enable or disable backup management (0:not backed up, 1:backed up)
6
Check order when checking the SF with the fsck command (0:no check, 1:priority, 2:not priority)
The mount -a command allows new mounts to be taken into account without rebooting. They are then written to the /etc/mtab file which contains the current mounts.
!!! Warning Only the mount points listed in /etc/fstab will be mounted on reboot.
It is possible to make a copy of the /etc/mtab file or to copy its contents to /etc/fstab.
As in any system, in order to be able to find one's way through the tree structure and the file management, it is important to respect the file naming rules.
Files are coded on 255 characters;
All ASCII characters can be used;
Uppercase and lowercase letters are differentiated;
No notion of extension.
Groups of words separated by spaces must be enclosed in quotation marks:
[root]# mkdir "working dir"
!!! Note While there is nothing technically wrong with creating a file or directory with a space in it, it is generally a "best practice" to avoid this and replace any space with an underscore.
!!! Note The . at the beginning of the file name only serves to hide it from a simple ls.
!!! Warning Under Linux, the extension of a file is not a necessary reference to open or modify it. However, it can be useful for the user.
Examples of extension agreements:
.c : source file in C language;
.h : C and Fortran header file;
.o : object file in C language;
.tar : data file archived with the tar utility;
.cpio : data file archived with the cpio utility;
.gz : data file compressed with the gzip utility;
.tgz : data file archived with the tar utility and compressed with the gzip utility;
In order to communicate with peripherals (hard disks, printers, ...), Linux uses interface files called special files (device file or special file). They allow identification by the peripherals.
These files are special because they do not contain data but specify the access mode to communicate with the device.
The special character mode file is used to transfer data to the device as a stream of one character at a time without using a buffer. These are devices like printer, screen or DAT tapes, ...
The standard output is the screen.
[root]# ls -l /dev/tty0
crw------- 1 root root 8, 0 jan 1 1970 /dev/tty0
The letter c at the beginning of the rights group indicates that it is a special character file.
Pipe files pass information between processes by FIFO (First In, First Out). One process writes transient information to a pipe file and another reads it. After reading, the information is no longer accessible.
Socket files allow bidirectional inter-process communication (on local or remote systems). They use an inode of the file system.
The link file and the source file have the same inode number and the link counter is incremented. It is not possible to link different directories or files from different file systems.
!!! Warning If the source file is destroyed, the counter is decremented and the link file still accesses the file.
Unlike the physical link, the symbolic link involves the creation of a new inode. At the symbolic link level, only a path is stored in the inode table.
The file created contains only an indication of the path to the file. This notion no longer has the limitations of physical links and it is now possible to link directories and files belonging to different file systems.
!!! Warning If the source file is destroyed, the link file can no longer access the file.
!!! Note Permissions apply to user, group and other (ugo) depending on the owner and group.
By default, the owner of a file is the one who creates it. The group of the file is the group of the owner who created the file. The others are those which are not concerned by the previous cases.
The attributes are changed with the chmod command.
Only the administrator and the owner of a file can change the rights of a file.
Recursively modify the permissions of directories and their contents.
There are two methods for making rights changes:
The octal method;
The symbolic method.
!!! Warning The rights of files and directories are not dissociated. For some operations, it will be necessary to know the rights of the directory containing the file. A write-protected file can be deleted by another user as long as the rights of the directory containing it allow this user to perform this operation.
These rights allow execution of a command according to the rights set on the command, and not according to the user's rights.
The command is executed with the identity of the owner (SUID) or the group (SGID) of the command.
!!! Note The identity of the user requesting the execution of the order is no longer taken into account.
This is an additional possibility of access rights assigned to a user when it is necessary for them to have the same rights as the owner of a file or those of the group concerned.
Indeed, a user may have to run a program (usually a system utility) but not have the necessary access rights. By setting the appropriate rights (s at the owner level and/or at the group level), the user of the program has, for the time of its execution, the identity of the owner (or that of the group) of the program.
Example:
The file /usr/bin/passwd is an executable file (a command) with a SUID.
When the user bob runs it, he will have to access the /etc/shadow file, but the permissions on this file do not allow bob to access it.
Having a SUID this command, /usr/bin/passwd, will be executed with the UID of root and the GID of root. The latter being the owner of the /etc/shadow file, he will have read rights.
The setting of SUID and SGID can be done as below with the command chmod:
!!! Note umask modifies the mask until the disconnection.
To keep the value, you have to modify the following profile files: For all users:
/etc/profile
/etc/bashrc
For a particular user:
~/.bashrc
!!! Warning umask -S displays the file rights (without the execute right) of the files that will be created. So it is not the display of the mask used to subtract the maximum value.
!!! Tip The umask command being a bash command, (a type umask returns umask is a shell primitive) you have to search umask in man bash.