Linux add disk and create partition management

Source: Internet
Author: User
Tags disk usage

Detect and confirm a new hard drive

Execute the "fdisk-l" command to view and confirm the device name and location of the new drive.
The purpose of the FDISK-L command is to list information about all hard disk devices and their partitions in the current system.
For example: [[email protected] ~] #fdisk-L
Omitted...........
Device Boot Start End Blocks Id System
/DEV/SDA1 1 104291 Linux
Omitted............
Existing partitions will be sent out through the list of messages.
? Device: The unit file name of the partition.
? Boot: Whether it is a boot partition. Yes, there
is the "" identity.
? Start: The partition's starting position in the hard disk (number of cylinders).
? End: The ending position (number of cylinders) of the partition on the hard disk.
? Blocks: The size of the partition, in Blocks (block), the default block size is 1024 bytes.
? ID: The system ID number that corresponds to the partition. 83 represents the EXT4 partition in Linux, and 8e represents an LVM logical volume.
? System: Partition type.

Planning partitions on your hard disk
For example: Execute the "fdisk/dev/adb" command to enter into the interactive partition management interface.
in the operator interface, after the command (M for help): Prompt
? After entering the "m" instruction, you can view the Help information for the various operation instructions
? Use the "P" directive to list detailed partitioning conditions, the same as the "fdisk-l" command.
? Use the "n" directive to create partitions, including primary and extended partitions. Follow the prompts to continue typing "p" select Create Primary partition, enter "E" to select Create Extended partition. You can then select the partition ordinal, start position, end position, or partition size to complete the creation of the new partition. When you select a partition, the ordinal number of the primary and extended partitions can only be 1~4. The partition start location is generally recognized by Fdisk by default, and the end position or size can be in the form of "+sizem" or "+sizeg", such as "+20g" to set the capacity of the partition to 20G.
? Use the "D" directive to delete the specified partition and continue to enter the number of partitions to be deleted as prompted.
? Use the "T" directive to change the ID number of the partition. You need to specify the target partition ordinal, and the new system ID number, in turn. Different types of file systems correspond to different ID numbers, represented by 16 decimal numbers, which can be entered as "L" instructions in the Fdisk interactive environment. The most commonly used EXT4, swap file systems have an ID number of 83, 82, and the ID number for the NTFS file system in Windows is typically 86.
? " W "and" Q "Instructions--Exit the Fdisk partition tool, where the" w "instruction will save the partition operation, and the" q "instruction will not save the partition operation on the hard disk.
For example, executing the "PARTPROBE/DEV/SDB" command will re-detect partition changes on the disk.
Create file system
The process of creating a file system is also the process of formatting partitions, using the MKFS (make Filesystem, create file System) command tool in a Linux system to format different types of partitions such as EXT4, fat, etc. The swap swap partition can be formatted using the Mkswap command.

Use the MKFS Command program format:
MKFS-T file system type partition device
For example, the partition/DEV/SDB1 is formatted as a EXT4 file system.
Mkfs-t EXT4/DEV/SDB1 or MKFS.EXT4/DEV/SDB1
For example, to create a FAT32 file system, you can specify the type with the "-t vfat" option and add the "-F 32" option to specify the version of Fat. The partition/DEV/SDB6 will be formatted as a FAT32 file system (by adding the/DEV/SDB6 partition with the Fdisk tool and setting the ID number to B).
Mkfs-t vfat-f 32/dev/sdb6 or Mkfs.vfat-f 32/DEV/SDB6
For example, create a partition/DEV/SDB5 as a swap partition. Mkswap/dev/sdb5
For example, the following actions show the process of enabling, stopping, and/DEV/SDB5 the interchange partition, and the change in total swap space.
Cat/proc/meminfo | grep "Swaptotal:"//view the size of the total swap space
SWAPON/DEV/SDB5//Enable swap partition/DEV/SDB5
Cat/proc/meminfo | grep "Swaptotal:"//confirm that the swap space size has increased
SWAPOFF/DEV/SDB5//Deactivate swap partition/DEV/SDB5

Mount and Unmount file systems
Mount File System

Basic usage format for mount command: Mount [-T file system type] storage device mount point
For example, mount the optical device to the/media/cdrom directory.
Mount/dev/cdrom/media/cdrom

For example, mount the/DEV/SDB1 partition under the newly created/mailbox directory.
Mkdir/mailbox
Mount/dev/sdb1/mailbox
When you use the Mount command without any parameters or options, information about the individual partitions (file systems) that are mounted on the current system is displayed, and the most recently mounted file system appears on the last side.
Using the ". ISO" image file, use the Mount Mount command with the "-O loop" option.

For example, Mount-o-loop rhel-server-6.5-x86_64-dvd.iso/media/mnt//Mounts to the/MEDIA/MNT directory.

Uninstalling the file system
For example, uninstall the previously mounted Linux partition, CD-ROM device, respectively.
Umount/mailbox//unload the corresponding partition by mount point directory
Umount/dev/cdrom//unmount discs via device files
Setting up automatic file system mounts
The system's/etc/fstab file can be considered a configuration file for the Mount command, which stores the static mount data of the file system. The default Fstab file includes the mount configuration of the root partition, the/boot partition, the swap partition, and the pseudo-file system such as Proc, TMPFS, and so on.

[[Email protected] ~] #cat/etc/fstab
...//Omit some information
TMPFS/DEV/SHM TMPFS Defaults 0 0
In the "/etc/fstab" file, each row records the Mount configuration information for one partition or device, including six fields from left to right (separated by spaces or tabs), and the meanings of each section are described below.
? 1th field: Device name or device volume label name.
? 2nd field: The location of the file system's mount point directory.
? 3rd field: File system type, such as Ext4/swap.
The 4th field: The parameters that can be used after the mount parameter, which is the "-o" option for the. For example, defaults, rw, RO, noexec, respectively, indicate default parameters, writable, read-only, and disable execution of the program.
? 5th field: Indicates whether the file system requires a dump backup. It is usually set to 1 to indicate the need, set to 0 o'clock will be ignored by dump.
? 6th field: This number is 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.

For example, you will add a configuration record that automatically mounts the partition/dev/sdb1.
[Email protected] ~]# Vim/etc/fstab
...//Omit part of the content
/dev/sdb1/mailbox EXT4 Defaults 0 0

View disk usage
[[Email protected] ~] #df-ht
File system type capacity used% mount point available
/DEV/SDB1 ext4 99M 11M 83M 12%/boot

Common LVM Management commands

Create Order:
1. Physical volume 2.VG Volume Group 3. LV Logical Volume

For example:
Physical volume PVCREATE/DEV/SDB1/DEV/SB2/DEV/SDB3//convert these partitions into physical volumes
VG Volume Group Vgcreate WEB_DOCUMENT/DEV/SDB1/DEV/SDB2//Create a volume group named Web_document with physical volumes, DEV/SDB1, and/DEV/SDB2.
Lvcreate-l 10g-n benet web_document//Create a logical volume named Web_document in the Benet volume group.

Format of the logical volume of the LV: the size of the lvcreate-l capacity-N Logical Volume name volume group name
Basic format for extended logical volumes using LV: lvextend-l + size/dev/Volume group name/Logical volume name
Example: Lvextend-l +10g/dev/web_document/benet
Set disk quotas
Steps
For example:

    1. Mounts The file system
      re-mount the Mbox logical volume (remount parameter) in a way that supports the quota feature, and adds quota support.
      Mount-o remount,usrquota,grpquota/dev/mail_store/mbox/mailbox
      During configuration debugging, you can use the "-O Usrquota,grpquota" The Mount command of the option mounts the specified partition to increase support for user, group quota functionality.
      Mount//view is mounted successfully
      Chmod 777/mailbox///For subsequent testing, allowing any user to write data
    2. to detect disk quotas and generate quota files
      QUOTACHECK-AUGCV// All file systems in the system are scanned and quota files are created in the file system that supports quotas.
      on the list above, the option "-a" means that all partitions are scanned, "-U" and "-G" respectively indicate the detection of user and group quota information, "-C" means the creation of a new quota file, "-V" indicates that details are displayed during the execution of the command. When the "-a" option is not used, a partition must be specified as a directory parameter (device file or mount point directory).
    3. Edit quota settings for user and group accounts
      Quota settings are the most important part of implementing disk quotas, and using the Edquota command with the "-U", "-g" option allows you to edit the user or group's quota settings.

Example: Quota Editing for user Zhangsan
[Email protected] ~]# edquota-u Zhangsan
Disk quotas for User Zhangsan (UID 501):
Filesystem blocks soft hard inodes soft hard
/dev/mapper/mail_store-mbox 0 0 0 0 0 0
The configuration records are divided from left to right into seven fields, and the meanings of each field are as follows.
? Filesystem: Represents the file system (partition) of the bank's configuration record, which is the scope of the quota.
Blocks: Indicates that the user is currently using the disk capacity, the default is KB, the value is automatically calculated by the Edquota program, without modification.
Inodes: Indicates the number of files that the user currently owns (that is, the number of I nodes), which is also calculated automatically by the Edquota program.
Soft: The Soft in column 3rd corresponds to the soft limit value for disk capacity, the default is KB, and the soft in column 6th corresponds to the soft limit value for the number of files, which is the default unit.
Hard: In the 4th column, it corresponds to a rigid limit value for disk capacity, the default is KB, and the hard number in the 7th column is the rigid limit value of the file count, which is the default unit.

  1. To start the disk quotas feature of the file system
    The disk functions for starting and shutting down the file system are performed using the Quotaon, Quotaoff command, which requires the instruction device file name or the mount point directory of the file system as the command parameter. The Quotaon command uses the same options as the Quotacheck option.
    For example, enable the user, group disk quota feature for the/mailbox file system, and display information about the process of the command execution.
    [[Email protected] ~] #quotaon –ugv/mailbox (Note: This single boot mount point, preceded by "-a" multiple mount points)
    /dev/mapper/mail_store-mbox [/mailbox]: group quotas turned on
    /dev/mapper/mail_store-mbox [/mailbox]: User quotas turned on

  2. Verify disk Quotas Feature
    You can use the DD conversion tool to quickly see the results during the test. The DD command is a device conversion and replication command that uses the if= option to specify the input device (or file), the "of=" option to specify the output device (or file), the "bs=" option to specify the size of the read data block, and "count=" to specify the number of read data blocks.
    For example, a test file named Ddtest.data can be written to the/mailbox directory with a size of 4MB (four reads, each 1MB), and the source is the device file "/dev/zero".
    [[Email protected] ~] #dd if=/dev/zero of=/mailbox/ddtest.data bs=1m count=4//write Data
    [[Email protected] ~] #ls-lh/mailbox/ddtest.data//Show if write is successful

  3. View quota usage for users or partitions
    To understand quota usage for users or groups in the file system, you can use the Quota command, the Repquota command. The quota command can be used with the "-U", "-g" option to view the quota usage of the specified users and groups respectively, while the Repquota command is primarily for the specified file system output quota usage report, and when combined with the "-a" option, you can view the Quota usage report for all available partitions.
    Example: Quota–u Zhangsan//view quotas for user Zhangsan
    QUOTA-G users//view quotas for the Users group
    Repquota/mailbox//View quotas for a specified file system

Linux add disk and create partition management

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.