Linux disk management, new disks, partitions, mounting, and linux mounting

Source: Internet
Author: User

Linux disk management, new disks, partitions, mounting, and linux mounting

1. view the Directory and total file size in du-sh
-A: all files and directory sizes are listed. If no options or parameters are added, only the directory (including subdirectories) size is listed.
-C: add the final sum
2. df-h view disk usage
3. lsblk to view system block device information
Blkid: view the uuid of the disk partition

3. free system memory and virtual memory usage
-M options are viewed in the form of M

4. fuser-km/home terminate all processes using this directory

5. mount/dev/sdc1/home to mount sdc1 to the/home node.
Umount/dev/sdc1 uninstall/dev/sdc1

6. fdisk-l list the partition tables of all/specified disk devices
Fdisk/dev/sdc: m p n d w q
M menu
P print the current disk partition
N re-create a new partition: e (extended partition) or p (primary partition)
W.
Q: exit.
D. delete a partition.
Example: fdisk/dev/sdc
P print
N New
Select number: 2
Select p main/e Extension: p
Allocation size: Press enter to allocate all
W save
Partprobe takes effect immediately

Note: a maximum of four primary partitions and one extended partition can be partitioned into logical partitions again under the extended partition.
After partitioning, you can make the new partition take effect without restarting the computer: partprobe

7. Format mkfs
Mkfs. ext2/mkfs. ext3/mke2fs format linux hard disk partition
Mkfs-t ext3/dev/sda1

Common options include:
-B: Set the space occupied by each data block during partitioning. Currently, 1024,204 bytes and 4096 bytes are supported.
-I: Set inode size
-N: set the number of inode. Sometimes the default number of inode is insufficient. Therefore, you must set the number of inode.
-C: Check whether the disk is faulty before formatting. If this option is added, it will be very slow.
-L: default label of the partition
-J: Create partitions in ext3 format. This option is not required if mkfs. ext3 is used.
Example:
Mkfs. ext3/dev/hdb1 directly format/dev/hdb1
Mkfs. ext3-B 4096-I 4096/dev/hdb2
Mkfs. ext3-L label3/dev/hdb3 add tags
E2label/dev/hdb3 is used to view or modify the partition label)

8. fsck check whether there is any bad track on the hard disk
-A: all partitions (this operation will be performed once during the boot process );
-A: the faulty partition is automatically repaired;
-R: When a partition with a bad track is detected, the user is asked to decide whether to fix it.

9. partitions to be mounted when the/etc/fstab system is started
Column: partition tag, mount point, format, Mount parameter, dump, Boot Check Disk
Mount parameters:
Async/sync: async indicates that it is not synchronized with the disk and memory. The system writes the memory data to the disk at intervals, while sync synchronizes the data in the memory and disk from time to time;
Auto/noauto: automatic mounting/not automatic mounting at startup;
Default: Set the Mount definition according to the default values of most permanent file systems. It contains rw, suid, dev, exec, auto, nouser, async;
Ro: mounting Based on read-only permissions;
Rw: Mount data by read/write permissions;
Exec/noexec: Allow/disallow execution of the file, but do not mount the root partition as noexec, so the system cannot be used and the mount command cannot be used, at this time, only the system is re-built;
User/nouser: allows/does not allow other users except root to mount partitions. For security reasons, use nouser;
Suid/nosuid: allows/does not allow partitions to have the suid attribute. Generally, set nosuid;
Usrquota: enable the user's disk quota mode. The disk quota is described in subsequent sections;
Grquota: enable the Group Disk Quota mode;

Example: add a line to/etc/fstab to mount the new partition. For example, the author adds such a line
/Dev/hdb1/test1ext3defaults0 0
Then the partition will be mounted when the system restarts.

9. Attach/detach a disk
Mount: mount
Mount/dev/sdb1/home
-A: All Disks
-O options: mount-o remount, rw, sync, noauto/dev/hdb1/test1
Mount UUID according to uuid (blkid check uuid): mount UUID = "d233432fsf23fdfsf3e"/test1
-T specifies the file system: mount-o remount-t ext3/dev/hdb1/test1

Umount: uninstall
Umount/dev/hdb1: unmount by partition
Umount/test1: unmount Based on the mount point
Umount-l/dev/hdb1: Force uninstall


--------------------------------------------------------
10. Create a swap file
1. use dd to create a 419M file/tmp/newdisk, where if indicates which file to read and/dev/zero is a unique 0 generator in linux, of indicates the file to be output. bs indicates the block size, and count indicates the number of blocks.
Dd if =/dev/zero of =/tmp/newdisk bs = 4 k count = 102400
2. mkswap format the swap partition: mkswap/tmp/newdisk
3. free-m to view memory and virtual partitions
4. Enable partition files in swapon/tmp/newdisk
5. swapoff/tmp/newdisk close partition files


11. Disk quota
Quota quotacheck quotaoff quotaon quotastats edquota setquota warnquota repquota
1. quata display group and user quota
Syntax: quota [-guvs] [user, group]
-G: displays the quota of a group.
-U: displays the quota of a user.
-V: Display meaning
-S: Select inod or hard disk space to display

2. quotacheck is used to scan the quota space of a disk.
Syntax: quotacheck [-auvg]/path
-A: scans all mounted disks with quota support.
-U: scan a user's files and directories.
-G: scan files and directories in a group.
-V: displays the scanning process.
-M: Force Scan

3. edquota is used to edit the quota value of a user or group.
Syntax: edquota [-u user] [-g group] [-t]
Edquota-p user-u user
-U: edit a user's quota
-G: edit the quota of a group.
-T: edit the grace period
-P: copy the quta of a user or group to another user or group.
When you run edquota-u user, the system opens a file:
Column 1. Filesystem: disk partition, such as/dev/hda3
2. blocks: the disk capacity occupied by the current user in the current Filesystem. The unit is Kb.
3. soft/hard: the quota value of the current user in the Filesystem. soft refers to the minimum limit and can exceed this value, however, the disk capacity must be reduced below this value within the grace period. Hard refers to the maximum limit, that is, it cannot exceed this value. When your disk usage is higher than the soft value, the system will warn you that you want to reduce the space used to the soft value within the grace period.
4. inodes: the status of the currently used inode, which does not need to be modified.

4. quotaon starts quota. After quota is edited, it must be started before quota takes effect.
Syntax: quotaon [-a] [-uvg directory]
-A: All set quota boot
-U: Start a user's quota
-G: Start the quota of a group.
-S: displays related information.

5. quotaoff to disable quota
Quotaoff-a disable all quota


Quick review
##################
Add a disk partition:
1. df-sh current disk partition mount point usage
2. fdisk-l list the partition tables of disk devices (total disk volume, allocated)
3. Run fdisk/dev/sdb to partition the disk.
P print
N New
Select ID: 1
Select p main/e Extension: p
Allocation size: Press enter to allocate all
W save
Disk/dev/sdb partition has produced/dev/sdb1
Partprobe takes effect immediately
4. mkfs. ext3/dev/sdb1 directly format/dev/sdb1 or
Mkfs-t ext3/dev/sdb1
5. Add/dev/sdb1/homeext3defaults0 to/etc/fstab.
6. mount/dev/sdb1/home/tt/app mounting
7. lsblk to view system block device information

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.