Linux basic commands-disk and file system management

Source: Internet
Author: User

I. Detection of New Hard Disks
 
[Root @ localhost ~] # Fdisk-l list all hard disk devices and their partition information in the current system
 
The list information has the following parameters:
 
Device: the name of the Device file in the partition.
Boot: whether it is a Boot partition. If it is a Boot partition, It is identified "*".
Start: Start position of the partition in the hard disk (number of cylinders)
End: the End position of the partition in the hard disk.
Blocks: The partition size, in blocks. The default value is 1024 bytes.
Id: ID marker of the partition type
System: partition type
[Root @ localhost ~] # Fdisk/dev/sdb
Cmmand (m for help ):
 
M (HELP)
P (list partitions in the hard disk)
N (new partition) → sub-parameter: p (new primary partition 1-4) e (new extended partition 1-4) Next create a logical partition in the extended partition l
D (delete partition)
| T (Change partition type) Input 1-5 (depending on dev/sdb5) can be seen, then 82 or 83 (82 is the ID corresponding to the file system SWAP and EXT3
W and q (exit fdisk partition tool) w save and quit, q exit and do not save
[Root @ localhost ~] # Partprobe/dev/sdb re-detect the partition changes in the/dev/sdb Disk
 
Ii. File System Management
 
In linux, after using the fdisk command to partition, you must format the partition and mount it to the specified directory in the system, and then use it to store files, directories, and other data.
 
1. Create a File System
 
Mkfs-t ext3/dev/sdb1 // equivalent to executing mkfs. ext3/dev/sdb1 (create an ext3 File System in the/dev/sdb1 partition)
Mkswap/dev/sdb5 (create an swap file system on the specified partition and convert the/dev/sdb5 format to a swap file system)
Free | grep-I swap (use the free command to observe the changes in the swap space)
Swapon/dev/sdb5 (enable new swap partition)
Swapoff/dev/sdb5 (disable swap partition)
2. Mount and detach a File System
 
Mount [-t file system type] storage device mount point
Mount/dev/cdrom/media/cdrom (insert the RHEL5 disc and mount it to/meida/cdrom)
Mount/dev/sdc1/media/usbdsk (insert a USB flash disk and mount it to/media/usbdsk. The mount point must be created in advance)
Mount (you can also directly enter the information of the mounted partitions in the System)
Mount-o loop *****. iso/media/ubuntu (mount the downloaded ISO image file to/media/ubuntu)
Umount/media/usbdsk (unmount the USB flash drive file system mounted to the/media/usbdsk directory)
Eject and eject-t (for optical drive devices, the former is the pop-up bracket, and the latter is the reclaim bracket)
 
Cat/etc/fstab (the/etc/fstab file can be regarded as the configuration file of the mount command. The system automatically reads the content of this file every time the system starts up, and automatically mounts the specified file system)
 
The first field: device name or volume name
Second Field: Location of the mount point directory of the file system
Third Field: File System Type
Fourth field: Hanging on Parameters
The fifth field indicates whether the file system needs dump backup. If it is set to 1, the file system needs to ignore
The sixth field: determines the sequence of disk checks when the system starts. If the value is 0, no check is performed. If the value is 1, check is performed first. If the value is 2, check is performed)
For example, modify the/etc/fstab file and add the configuration line for automatically mounting the/dev/sdb1 partition.
[Root @ localhost ~] # Vi/etc/fstab // Add the following content to the last line of the file
/Dev/sdb1/mailbox ext3 default 0 0
 
Df-hT [/etc/sdb1] (view disk usage, default unit: KB)
 
3. Set the disk quota
 
First, understand the disk quota scope, restriction object, restriction type (disk capacity, file quantity), and restriction method (soft limitation, hard limitation ).. The following are the main steps:
 
1. Mount the file system in a way that supports the quota Function
2. Check the disk quota and generate the quota File
3. Edit the quota function for users and group accounts
4. Enable the disk quota function of the file system
5. Verify the disk quota Function
6. View user or partition quota usage
 
1. [root @ localhost ~] # Mount-o usrquota, kgquota/dev/sdb1/mailbox (mount the/dev/sdb1 partition to the/mailbox directory to add user quotas and group quotas)
[Root @ localhost ~] # Vi/etc/fstab
/Dev/sdb1/mailbox ext3 default, usrquota, maid 0 0
(The preceding command is used to mount the partition automatically after each boot, and supports the disk quota function)
 
2. quotacheck-augcv (checks the disk quota information of all partitions in the current system and creates a quota file in the available File System)
-A: scans all partitions (if not selected, a partition must be specified)
-U and-g: Indicate the user and group quota information respectively.
-C: Indicates creating a new quota file.
-V: displays detailed information during command execution.
[Root @ localhost ~] # Ls-l/mailbox/aquota. * (confirm the user quota file and group quota file in the/mailbox File System)
 
3. [root @ localhost ~] # Edquota-u zhangsan (used to edit user quota settings)
[Root @ localhost ~] # Edquota-g users (used to edit group quota settings)
[Root @ localhost ~] # Edquota-t (modify the grace period)
Filesystem: indicates the file system corresponding to the configuration record of the row, that is, the quota range.
Blocks: indicates the disk capacity currently used by the user.
Inodes: Number of Files Owned by the user
Soft: the soft limit value corresponding to the disk capacity in column 3rd. The default unit is KB! The soft limit value of the number of files in column 6th. The default value is
Hard: there are also two. Hard limit value of the undisk capacity in column 4th and hard limit number of files in column 7th
 
You only need to modify the corresponding soft and hard! Then use wq to save and exit!
 
 
4. quotaon-ugv/mailbox (enable the/mailbox file system user and group Disk Quota function)
 
5. Verify the disk quota Function
[Root @ localhost ~] # Dd if =/dev/zero of =/mailbox/ddtest. data bs = 1 M count = 4 (copy data from the device file/dev/zero to ddtest. data File, read four data blocks of 1 MB)
[Zhangsan @ localhost ~] $ Dd if =/dev/zero of =/mailbox/myfile bs = 1 M count = 6 (similar to the previous sentence)
 
6. quota-u zhangsan
Quota-g users
[Root @ localhost ~] # Requota/mailbox/(check the quota of the/mailbox File System)
 
Iv. LVM logical volume Management
 
Purpose: dynamically adjust the disk capacity while keeping the existing data unchanged, which improves the flexibility of disk management.
 
LVM is divided into: physical volume (PV), volume group (VG), logical volume (LV)
Used to convert to a common partition of a physical volume, we recommend that you first use the fdisk tool to change the ID mark Number of the partition type to 8e, and the volume group is composed of one or more physical volumes, and the logical volume is created on the volume group and physical Volume does not matter
 
1. pv physical volume Management
Pvscan: used to scan physical volumes created in the current system and display relevant information
Pvcreate: converts a partition or entire hard disk to a physical volume.
[Root @ localhost ~] # Pvcreate/dev/sdb1/dev/sdb2/dev/sdb3
Pvdisplay: displays details of a physical volume (specify a physical volume)
Pvremove: Restores a physical volume to a common partition or disk.
 
2. VG volume Group Management
Vgscan: scans the currently created LVM volume group
Vgcreate: creates one or more physical volumes as one volume group.
-- [Root @ localhost ~] # Vgcreate wycvs/dev/sdb1/dev/sdb2
Vgdisplay: displays detailed information about each volume group in the system (you must specify the volume group)
Vgremove: deletes a specified volume group.
Vgextend: expands the disk space of the volume group.
-- [Root @ localhost ~] # Vgextend wycsy/dev/sdb2
 
3. LV logical volume Management
Lvscan: scans logical volumes created in the current system
Lvcreate: separates space from a specified volume group and creates logical volumes.
-- Lvcreate-L capacity size-n logical volume name volume group name
Lvdisplay: displays detailed information about a logical volume (you must specify the logical volume)
Lvextend: dynamically scalable logical volume space
-- Lvextend-L + size/dev/volume group name/logical volume name
Lvremove: deletes a specified logical volume.
 
 
 
First come and end! Supplement the problem!
 
This article is from the "Tiandao reward Qin-chang Shuangyang" blog

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.