Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Disk Management under linux

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Preface: this article records the author in the study of linux disk management summary, only to do learning records use.

To understand the disk management method under linux, first of all, you have to have a clear understanding of the hard disk and the expression of the hard disk under linux.

1. About hard disk?

Hard disk is generally divided into IDE hard disk, SCSI hard disk and SATA hard disk (serial hard disk). Most hard disks in use today are SCSI and SATA hard disks.

2. What is the expression of hard disk and its partition under Linux?

(1)Under Linux, IDE interface devices are called hd, SCSI and SATA interface devices are called sd. (Now it is SCSI or SATA interface hard disk, so it is usually sd)

(2)Therefore, the first hard disk is called sda, the second hard disk is called sdb, and so on.

Linux specifies that there can only be four primary partitions on a hard disk, named sda1, sda2, sda3, and sda4. Logical partitions are identified starting with 5, and for each additional logical partition, 1 is added to the last partition number. There is no limit to the number of logical partitions.

3. What is the storage principle of hard disk?

From the storage principle, hard disk and magnetic tape are the same, hard disk is a few stacked magnetic disk, read data, disk rotation at a constant speed, there is a small magnetic head for reading and writing. Magnetic heads write data by changing the arrangement of magnetic material on the disk. It is worth noting that the magnetic head does not touch the disk surface when reading and writing data, but floats very close to the disk surface. If, for some reason, the head touches the disk, it can have devastating consequences, which is one reason why the host cannot be moved during operation.

Now that we've covered hard disks, let's look at file systems.

4 What is a file system?

A file system is a way of organizing physical space, usually created when formatting a hard disk. For example, how do you store a file? How do you represent a directory? How do I know where a particular file is stored on my hard drive? These problems can be solved by file system.

5 What are the common file systems?

(1) Under Windows, there are two common file systems: NTFS and FAT.

(2) Under Linux, the current mainstream file systems are ext4fs and ReiserFS file systems, both of which are journaling file systems. Of course, Linux also has minix, ext2, ext3 and other file systems.

(3) ext4fs file system is based on ext3fs file system, adding log function. The ext4fs file system reserves a dedicated area for log files, and when a file is written, the changes are first written to the log file, followed by a record marking the end of the log entry. The actual changes to the file system will not be made until the above operations are completed. This allows you to recover the file system using logs when the system crashes. Avoid data loss.

6. About swap.

(1)Swap is not a file system, it is called swap partition, is a special hard disk space. When the actual memory is insufficient, the operating system will take some temporarily unused data from memory and put it in the swap partition, thus making enough memory space for the currently running program.

(2)The advantage of this approach is that, through scheduling by the operating system, the memory space actually available to the application will far exceed the physical memory of the system.

(3)Hard disk space is much cheaper than RAM, so this approach is very economical and affordable.

(4)Frequent reads and writes to the hard disk can significantly slow down the system, which is the biggest limitation of using swap partitions.

After understanding the file system, we also need to understand the device representation method under linux, and then we can mount the device (file system).

7. How is the device represented under Linux?

(1) All devices under Linux are operated as files. Each device is mapped into a special file called a "device file."

(2)These device files are placed in the dev directory of the root directory. This is/dev.

(3)Among them, most of these files are block device files and character device files. Block device files can be read and written randomly, and character device files can only receive "character streams" in sequence.

8. Mount the device using the mount command:

(1)First, create a new destination directory for the device you want to mount. We mount devices in this target directory.

(2)Mount the device using the mount command. Format: mount [optional] device target directory. This command mounts the device in the target directory. After successful mounting, we can read the device-related files in the target directory. For example, insert the CD into the computer, manually mount the CD, mount it in the directory we specified (/mnt/cdrom), you can use the following command:

sudo mkdir /mnt/cdrom ##Create a new destination directory

sudo mount /dev/cdrom /mnt/cdrom ##Mount the CD to the directory/mnt/cdrom

(3)We can specify the file system type of the device to mount with the-t option.

Common file system representations:

Ext2: Ext2 file system for Linux.

Ext3: Ext3 file system for Linux.

ext4: Ext4 file system for Linux.

vfat: Represents Windows FAT16/FAT32 file system.

ntfs: Represents the NTFS file system for Windows.

iso9660: Represents the standard file system for CD-ROM discs.

If no type is specified, mount automatically detects the file system on the device and mounts it with the appropriate type. Therefore, in most cases, the-t option is not necessary.

(4)Optional-r Specifies that the device is mounted in read-only mode.

(5)Optional-w Mount the device in read-write mode. - w is the default option.

(6)For other uses of mount please refer to the manual instructions.

9. Use umount to uninstall the device:

(1)Uninstalling a device using umount is simple, just follow it with a device name. For example, unloading a disc: umount /dev/cdrom.

(2)It is worth noting that file systems (devices) can only be unmounted if they are not in use. When the current directory is the directory where the mounted device is located, unmounting is not allowed even if no reading or writing has been done to the device.

10. Check disk usage: df.

(1)df The command collects and collates important statistics about all currently mounted file systems. You can use df to view all mounted devices (file systems) on the current disk.

(2)df The-t parameter of is used to display a specific file system.

Checking and repairing file systems: fsck.

(1)fsck can quickly fix small exceptions that occur in the file system and roll back the log to the last normal state. fsck receives the partition number to specify the file system to check.

(2)The fsck command with the-p option reads the fstab file to determine which file systems to check, and checks file systems in ascending numerical order in the order specified by the last field of each record.

Create a file system on disk using mkfs.

(1)mkfs itself does not perform the work of creating a file system, but calls related programs, such as mkdosfs, mke2fs, mkfs.minix, etc., to format the disk.

(2)Specify the file system with the-t argument, and mkfs invokes a specific program to format the disk.

Common file systems:

minix: The earliest file system used by Linux.

ext3: ext3 file system.

ext4: ext4 file system. (default)

mkdos: FAT file system.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report