"Red Hat Linux Basics" Disk partitioning detailed tutorial

Source: Internet
Author: User
Tags disk usage



Experimental content:






1. Disk Partitioning



2. Format File system



3. Mount and unmount the file system



4. Automatic File system mount









Experimental steps:



Once the new hard drive device is hooked up in Linux and the host is booted, the drive is automatically detected and loaded without additional driver installation.






Execute command "fdisk-l" to list all hard disk devices and partition information in the system







As can be seen from my system detected 2 hard drives are "SDA" and "SDB" are in the dev directory, where SDA hard disk to be partitioned.



The SDB hard disk is not yet partitioned.






In the diagram:





    • Device: The name of the unit file that represents the partition.

    • Boot : Indicates whether it is a boot partition. Yes, there is a "*" logo

    • start : Indicates the starting position of the partition on the hard disk (number of cylinders)

    • End: Indicates the ending position of the partition on the hard disk (number of cylinders)

    • Blocks: Indicates the size of the partition, in Blocks (block), the default size is 1024 bytes

    • ID : Indicates the partition corresponding to the system Id number. 83 represents EXT4 partitions in Linux, 82 for swap partitions, and 8e for LVM logical volumes.





Partition the SDB hard drive below






Execute "fdisk/dev/sdb" into the partition management interface











Enter "m" in this mode to view help information for various instructions








Enter "p" to list the partition table, which is empty because it is not yet partitioned








Enter "n" to create a new partition where "e is the extended partition " "p is the primary partition ". When you select a partition number, the primary and extended partitions can only be numbered 1-4! The partition start position is generally recognized by Fdisk by default, and the end position uses "+sizek,m,g"








To create an extended partition, the extended partition can have only one








Create logical partition with logical partition starting partition number 5








Use p to list partitions








Use "t" command can change the partition ID number, if you do not know the ID number can be entered "L" view



Convert SDB6 to swap partition















Delete a partition using "D"








Convert SDB5 to FAT32








Use "w" and "Q" to exit the Fdisk partitioning tool






the W command saves and exits the Fdisk partition tool, and theQ command does not save the direct exit











After changing the partition settings of the hard disk, it is recommended to restart the system or execute the following command:











After partitioning is established in a Linux system, it is necessary to format the partition and mount it to the specified directory for storage.






Use MKFS format EXT4, fat and other different types of file partitioning









Format SDB1 as a EXT4 file system











Format SDB5 as a FAT32 file system











Initializing a swap partition with Mkswap









The newly added swap partition needs to be enabled with the Swapon command, whereas the Swapoff command can stop specifying the swap partition.






Use the FREE-M command to view memory usage












Mount and Unmount file systems






The basic format of the Mount command:






mount [-t file system type] storage device mount point // file system can usually be omitted by the system to automatically identify









Mount the SDB1 partition under the/mnt/directory














Mount USB Drive Device usage is also the same, through fdisk-l can view the USB stick device name






Mount the USB stick to the/OPT directory








Will find a whole "? "is because Linux does not recognize Chinese, you can perform the following command to recognize Chinese:














Setting up automatic file system mounts






If you do not set up automatic mounts, all partitions need to be re-mounted after rebooting the system once.






Use Vim to edit "/etc/fstab" To configure auto mount after boot!











The "/etc/fstab" file contains six fields from left to right as follows:





    • First field: Device name or device volume name

    • Second field: Location of the file system's mount point directory

    • Third field: File system type

    • Fourth field: Mount parameters, for example: defaults, rw, RO, noexec, respectively, as default parameters, writable, readable, disable execution program

    • Fifth field: Indicates whether a dump backup is required for the file system. General set 1 is required, set 0 means ignore

    • Sixth field: Used to determine the order in which disk checks are performed at system startup. 0 means no check, 1 is a priority check, and 2 means second check. The root partition should be set to 1 and the other partition set to 2.





Automatically mount the SDB1 partition to the/MNT directory








Use "Mount-a" to mount all the non-mounted partitions in the Fstab file, automatically mount the edits and execute this command if no error is indicated.











Use "Df-ht" to view disk usage








The left-to-right seven fields represent:





    • First field: File system

    • Second field: type

    • Third field: capacity

    • Fourth field: Used

    • Fifth field: Available

    • Sixth field:% used

    • Seventh field: Mount point





This article from "Sunj" blog, declined reprint!



"Red Hat Linux Basics" Disk partitioning detailed tutorial


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.