"Linux Learning Notes" Chapter 4th Linux Disk Management

Source: Internet
Author: User
Tags uuid

4.1DF Command
DFView file system disk space usage.
The total file system disk size (KB) used is available used%mount point (Directory)
Linux disks cannot be accessed directly and must have a mount point.
Parameters:
- HThe appropriate units can be displayed based on the disk size.
With TMPFS for temporary file system, reboot will automatically disappear.
/DEV/SHM represents memory, which accounts for half of physical memory.
- I.View the number and usage of the inode under the partition.
After the partition is created, the partition size and the number of inode are pre-allocated after formatting. When the inode is full, it cannot be written into the data, even if there is a surplus of disk space.
- Mis displayed in M units.
FreeTo view the remaining space, add - MThe parameters are displayed in M units.

4.2DU command
The du parameter dir/filename view the file size.
Parameters:
- S view only the sum of the directories you have written, not the subdirectories.
- H automatic adjustment unit.
Common du-sh dir/filename
There can be only one file per block.

4.3 Disk partitioning (top)
The server supports hot-swappable disks.
fdisk-l Lists all the disks and partition tables in the system.
The fdisk-l device name displays information for the appropriate device.
In the virtual machine, the newly added disk partition,fdisk-l does not display the newly added disk, the description is not recognized, requires reboot Restart, and then fdisk-l view.
Without the- l option, thefdisk device name enters the mode of partitioning the disk. According to the prompt, input m, can get help information, if the input error, you need to press Ctrl+u to delete the wrong input.
n Add new partition.
p lists the partition print.
W Save write.
d Delete the partition delete.
Enter n to create the partition, an option appears:
p Primary partition
e Extended partition
MBR partition, up to 2T, up to 4 primary partitions, to partition multiple partitions, divide the first 3 primary partitions, the last partition into an extended partition, and the extended partition can continue to be partitioned into multiple logical partitions. Primary partition + Extended partition <=4.
After entering the command, follow the prompts to set the partition number and start sector, end sector (+ sector or +size{k,m,g}).
When the 4 primary partitions are finished, you will be prompted not to create a new partition, and to build another partition, you need to delete a partition first.
When 4 partitions are created, you will be prompted to add logical partition 5 if you have an extended partition and then create a new partition. Complete the creation according to the appropriate prompts.

4.4 Disk partitioning (bottom)
d Delete the partition, if you delete the primary partition, the partition number is left blank, if you delete the logical partition, the following will be up, the partition number is not empty.
After you create or delete a partition, you need to press W to save, and if you do not save, press Q to exit and the current operation will not be saved.
If you create an extended partition, the primary partition + extended partition \<4, and then you will be prompted when you create the partition:
P creates the primary partition.
L Create a logical partition.
The primary or extended partition number can be discontinuous, but the logical partition number must start at 5 and be contiguous.
An extended partition can divide space, but it is the logical partition in which the space is actually occupied, so that the extended partition cannot write data or format it.

4.5 disk formatting (top)
The Windows system supports NTFS, FAT format.
The file formats supported by the Linux system can be viewed cat/etc/filesystems . CENTOS6 and Previous versions use the EXT format, starting with CENTOS7 and changing to the XFS format. But can be formatted as EXT format.
After creating the partition, format it and use the mke2tf command.
MKE2FS parameter device name
Parameters:
- T format Specifies the format of the file system format (EXT4/3/2, etc., MKE2FS does not support formatting to XFS format. )。 If you do not specify a format, the default is ext2 format (you can use the Blkid command mentioned later to view the device file format that is not mounted).
the-B size specifies the block sizes (b). Du-sh looked at the total size of the block, and DU-SB looked at the actual size of the file, and ls-l look at the size of the same.
mkfs.ext4<=>mke2fs-t ext4 (3,2 similar).
When the file format is already present, reformatting is prompted with the-F option to force formatting.
MKE2FS does not support formatting to the XFS format, but it can be used with MKFS.XFS to meet the requirements of format in XFS format.
After formatting, using mount cannot be seen because it has not been mounted to any mount point.
Blkid [device name] to see devices that are not yet mounted

4.6 Disk formatting (bottom)
MKE2FS parameter device name
Parameters:
- m size Specifies the percentage of partition reserve size (1 for 1%).
When a single file system is storing large files such as video music, the block size can be set larger to speed up reading.
-I size specifies how many bytes correspond to an inode, at least one block size to correspond to an inode (if not specified, the default 4 blocks corresponds to an inode).

4.7 Disk mount (top)
A disk can be formatted directly without partitioning.
mount device name/uuid mount point mount device (for example:mount/dev/sdb/mnt/).
umount device name/mount point unmount disk.
If the target is busy within the mount point, the disk cannot be uninstalled.
If you want to unmount the disk within the mount point, you can use the
umount-l mount point parameter l means lazy to quit.

4.8 Disk mount (bottom)
Mount-o Specific Options
- o specific option (manmount View specific options, find in man:/defaults You can see the options that defaults contains, and the option to add no to the table to reverse the meaning. While async antisense Sync,sync memory is synchronized to disk at any time, it will add to the burden, default async, not real-time synchronization, sync once in a while).
System files/etc/fstab Configure the disk partitions mounted on system startup (man Fstab), 6 columns:
Uuid/Device name mount point partition format mount option (default defaults) whether to back up (0/1) Set Priority detection (0 (not detected)/1 (Advanced: Root)/2 (Low level: other).
Mounting can also be a way to write the UUID to the config file/etc/fstab.

4.9 Adding swap space manually
When the current swap space is not allocated enough, you need to manually increase the swap space.
DD If=/dev/zero Of=/tmp/newdisk bs=1m count=100
DD command to manipulate disk space; If specified read location,/dev/zero is the Linux system to 0, can continuously generate 0;of specified (the previous 0) to write the location; BS specifies the block size; count specifies the number of blocks in the specified position.
After the creation is complete, you can view it du-sh/tmp/newdisk .
After you create the virtual disk, you need to format it.
Swap is a unique file system that requires the use of the Mkswap command
mkswap-f/tmp/newdisk formatting
After the format is complete, the disk space needs to be loaded into the current swap space.
Swapon/tmp/newdisk will load the disk space into the swap space.
The permissions are not secure at this point, but can still be loaded, and for security reasons, modify the permissions as recommended.
You can unmount the disk space when you're not using it.
swapoff/tmp/newdisk unmount the disk.
rm-f/tmp/newdisk Remove the disk.

4.10LVM Explanation (UP)
Disk partition reorganization redistribution.
Disk: Physical Disk.
Partition: Created as a physical volume.
Reorganization: A volume group (a combination of physical volumes).
Redistribution: Logical Volume LVM (Logical Volume).
Finally, the logical volume LVM is formatted and mounted for use.
Prepare a disk,fdisk/dev/sdb View information.
Create a three partition. You can find that the partition ID is 83,system Linux, the description is normal partition, to use LVM, you need to press T, according to the prompt, instead of 8e, when p print out, you can find the ID into the 8e,system into Linux LVM.
Once the disk partition is ready to be created as a physical volume, using the pvcreate command, the LVM package (yum install-y LVM) needs to be installed first.
Search the installation package according tothe command: Yum provides "//command"
Yum provides "//pvcreate" can search for the installation package and version required by the Pvcreate command.
If the system does not generate the corresponding file after creation, thels/dev/sdb1 cannot be queried. Run the partprobe command, and then ls/dev/sdb1 to see. The file can be generated automatically after the creation is complete.
The partprobe disk partition command cannot be used on mounted disks, and you need to cancel the mount before you can create a physical volume.
partprobe/dev/sdb1 Create physical volumes (2, 3, and similar).

4.11LVM Explanation (medium)
After the physical volume creation is complete:
PvdisplayView all physical volume information in the system.
PVsYou can also view all the current physical volumes.
vgcreate Volume Group name Physical Volume 1 [physical volume 2] ...Create a volume group.
vgcreate vg1/dev/sdb1/dev/sdb2
VgdisplayView Volume group information.
VGsYou can also view volume group information.
lvcreate-l size-n lvname vgname
- LSpecifies the size.
- NSpecifies the name Lvname.
Divided from the vgname inside.
lvcreate-l 100m-n lv1 vg1From the vg1 inside the LV1, the size of 100M.
After the creation is complete, the logical volume LVM is formatted.
Mkfs.ext4/dev/vg1/lv1Format the LV1.
mount/dev/vg1/lv1/mnt/Mount/dev/vg1/lv1, Mount point/mnt/.
To enlarge a logical Volume:
lvresize-l SIZE LVMSpecifies the new size and capacity of LVM. The mount should be canceled before expansion.
umount/mnt/Cancels the mount.
lvresize-l 200m/dev/vg1/lv1Extend the/DEV/VG1/LV1 to 200M.
e2fsck-f/dev/vg1/lv1Check the disk to see if there are any errors.
Resize2fs/dev/vg1/lv1Update the logical volume information, and then mount it after the update to identify the new size.
mount/dev/vg1/lv1/mnt/Mount.
Reduced logical volumes (XFS format does not support scaling):
umount/mnt/Cancels the mount.
e2fsck-f/dev/vg1/lv1Check the disk to see if there are any errors.
resize2fs/dev/vg1/lv1 100MUpdate the logical volume information.
lvresize-l 100m/dev/vg1/lv1Reduce the/DEV/VG1/LV1 to 100M.
LvdisplayOrLVsView, you can see that the new logical volume is 100M, when the content of the file is not larger than the total volume of the logical volume, the shrink will not cause the file within the logical volume to be lost, you can view the comparison verification before and after the indent.
mount/dev/vg1/lv1/mnt/Mount.
e2fsck,resize2fs commands can only be used for file systems in ext format.

4.12LVM Explanation (bottom)
Format to XFS format:
umount/mnt/ to cancel the mount.
mkfs.xfs-f dev/vg1/lv1 formatted in XFS format.
mount/dev/vg1/lv1/mnt/ Mount.
lvresiize-l 300m/dev/vg1/lv1 expansion to 300M (XFS format expansion without uninstallation)
The xfsgrowfs/dev/vg1/lv1 must be mounted at the time of the command operation.
df-h View, you can see that the size has been enlarged to 300M.
The logical volume space cannot be larger than the volume group space, and the volume group needs to be expanded before the logical volume can be scaled up after the volume group space has been consumed by the logical volume.
vgextend vg1/dev/sdb3 adds/dev/sdb3 into VG1
vgdisplay View Volume group information, you can see that the VG1 capacity has increased the size of the/DEV/SDB3.
The logical volume is then expanded.

4.13 Disk Failure Small case
If there is a problem mounting the disk, can not be mounted to the mount point, when starting to find the system can not enter. Enter the root password as prompted. Enter an interface similar to normal landing. Edit the/etc/fstab to delete the error mount information you added. Save exit and restart.

"Linux Learning Notes" Chapter 4th Linux Disk Management

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.