Linux under Disk Management

Source: Internet
Author: User
Tags uuid

Set Password
mkpasswd
Mkpasswd-s 0
Mkpasswd-s 0-1 15 Specifies the length of the password

1. View the capacity of a disk or directory
DF View Disk partition usage
Do not add parameters in K units
Df-i inode number, df-h with G or t or M
Df-m shown in M units

Du view the directory or file capacity
Do not add parameters in units of K display
-S list sum-a lists all files and directories
-K in units of-m in meters
-h most suitable unit most commonly used combination-sh Du-sh/root
Extended LS-LH See size compared to Du


2. Partitioning and formatting of disks
Fdisk-l viewing disks and partitions, greater than 2T with GPT
Fdisk/dev/sdb entering the partition list
Device name m lists commonly used commands, which are commonly used
' P ', print partition out
' n ', create a new partition
' d ', delete partition
' W ', Save exit
' Q '. Exit


Fdisk/dev/sdb

Command (M for help): N
Command Action
E Extended
P primary partition (1-4)
P
Partition number (1-4): 1
First cylinder (1-1044, default 1):
Using Default value 1
Last cylinder, +cylinders or +size{k,m,g} (1-1044, default 1044): +1g

Command (M for help): P

disk/dev/sdb:8589 MB, 8589934592 bytes
255 heads, Sectors/track, 1044 cylinders
Units = Cylinders of 16065 * 8225280 bytes
Sector size (logical/physical): bytes/512 bytes
I/O size (minimum/optimal): bytes/512 bytes
Disk IDENTIFIER:0XF729B1A2

Device Boot Start End Blocks Id System
/DEV/SDB1 1 1060258+ Linux

can only have primary partition + extended partition <=4, extended partition can only be divided into one, primary partition and logical partition
Logical partition starting from 5
Device Boot Start End Blocks Id System
/DEV/SDB1 1 654 5253223+ 5 Extended Extended partition
/DEV/SDB5 1 1060227 the Linux logical partition

2, 3, 4 is for the primary partition.

Fdisk-l/dev/sdb Viewing SDB partitions

MKE2FS, formatted. This command is better than the following.
Mkfs.ext2, MKFS.EXT3, MKFS.EXT4
-T File system format ext3 EXT4
-b Specifies each chunk size and currently supports 1024, 2048, and 4096
-L Partition Label
Default Blocks (5.00%) reserved for the Super User//A part of the space reserved by the superuser for special purposes when formatting
-M can change this ratio, such as mke2fs-m 0.1/dev/sdb1//means that only 0.1% is reserved


Mke2fs-t EXT4/DEV/SDB5 Formatting
Mke2fs-b 2048-l aming-t EXT4/DEV/SDB5
Mke2fs-b 2048-l aming-m 0.1-t EXT4/DEV/SDB5


3. Mount and Unmount disk partitions
Mount does not have any options and parameters to view the already mounted condition
Mount Format mount-t type/dev/sda5/mnt
MOUNT-T specifies the mount partition format, such as-t ext3
Umount/dev/sda5 or Umount/mnt
Umount-l forced uninstall, can also be forced to unload in the mounted directory

[[email protected] aming]# umount/aming If the uninstall operation is not available in the mounted directory
Umount:/aming:device is busy.

Mount-o followed by various options, such as Remount,ro,noatime, the following options:

"Async/sync": Async indicates that it is out of sync with disk and memory, and the system writes memory data to disk at intervals, while sync synchronizes memory and disk data at all times;
"Auto/noauto": Boot automatically mounted/not automatically mounted;
"Default": Set the Mount definition according to the default value of most permanent file systems, it contains RW, suid, dev, exec, auto, nouser, async
"Ro": Mount by read-only permission;
"RW": Mount according to readable writable permission;

"Exec/noexec": Allow/not allow executable file execution, but do not mount the root partition as a noexec, then can not use the system, even mount command can not be used, then only to re-do the system;
"User/nouser": Allow/Do not allow other users to mount the partition outside the root, for security purposes, please use nouser;
"Suid/nosuid": Allow/Disallow partition has suid attribute, general setting nosuid;
"Usrquota": Start the Consumer disk quota mode, disk quota related content in the following chapters will be introduced;
"Grquota": Start the group disk quota mode;


MOUNT-A will mount all partitions according to/etc/fstab ============
How the UUID is coming, using the command blkid
Blkid command can not be followed by the device name, list all
Mount Uuid= "..."/mnt
The advantage of using UUID is that multiple disks, if the slot location is changed on the server, the device name will change, but the UUID is unique
======================
Mount/dev/sdb5/aming
Mount-oremount,ro/dev/sdb5/aming this represents re-mount read-only
[[email protected] aming]# Touch 1.txt
Touch:cannot Touch ' 1.txt ': Read-only file system
=======================

Mkdir/aming
Mount/dev/sdb5/aming
[Email protected]/]# df-h
Filesystem Size used Avail use% mounted on
/dev/sda3 18G 990M 16G 6%/
Tmpfs 740M 0 740M 0%/dev/shm
/DEV/SDA1 93M 24M 65M 27%/boot
/dev/sda2 2.0G 3.0M 1.9G 1%/swap
/DEV/SDB5 988M 1.3M 985M 1%/aming

mke2fs-t ext4/dev/sdb2
[[email  Protected]/]# mkdir/data
[[email protected]/]# Mount/dev/sdb2/data /
[[email protected]/]# df-h
filesystem size used Avail use% mounted on
/dev/sda3 18G 990M 16G 6%/
tmpfs 740M 0 740M 0%/dev/shm
/dev/sda1 93M 24M 65M 27%/boot
/dev/sda2 2.0G 3.0M 1.9G 1%/swap
/DEV/SDB5 988M 1.3M 985M 1%/aming
/dev/sdb2 988M 1.3M 935M 1%/data


Note that if SDB5 and SDB2 are simultaneously mounted under/aming, the SDB2 will cover the SDB5
DEV/SDB5 988M 1.3M 985M 1%/aming
/DEV/SDB2 988M 1.3M 935M 1%/aming

The Touch/aming/11.txt data has been written to the SDB2 disk.
Unount/aming
ls/aming/, there's nothing under there.
mount/dev/sdb2/data/
ls/data/



Cat/etc/filesystems viewing Supported file systems
Ext4
Ext3
Ext2
Nodev proc
Nodev devpts
iso9660
Vfat
HfS
Hfsplus

================
Method One
Let him mount it automatically.
[Email protected]/]# Vim/etc/fstab
/dev/sdb5/aming EXT4 Defaults 0 0 Add this line under the profile and the boot will automatically mount.
[[email protected]/]# mount-a let him automatically mount ========

[Email protected]/]# df-h
Filesystem Size used Avail use% mounted on
/dev/sda3 18G 990M 16G 6%/
Tmpfs 740M 0 740M 0%/dev/shm
/DEV/SDA1 93M 24M 65M 27%/boot
/dev/sda2 2.0G 3.0M 1.9G 1%/swap
/DEV/SDB5 988M 1.3M 985M 1%/aming


Method Two
[[Email protected] ~] #vim/etc/rc.local in this configuration file in this line, the boot will automatically mount
mount/dev/sdb2/data/This data directory must exist first

===========================================
[[email protected]/]# Blkid view UUID
The role of the/etc/fstab file
After the disk is manually mounted, the mount information must be written to the/etc/fstab file, or it will still need to be mounted again the next time the boot starts.
When the system is powered on, it will actively read the contents of the/etc/fstab file, and mount the disk according to the configuration in the file. So we just need to write the disk's mount information to this file and we don't have to mount it manually after each boot.
Each partition is formatted with a UUID as its unique identification number. Use the UUID to mount the words without worrying about the problem of confusion.


4. configuration file/etc/fstab
The first column is the identity of the partition, can label, can also UUID, of course (/DEV/SDA1);
The second column is the mount point;
The third column is the format of the partition;
The fourth column is mount of some mount parameters, in general, directly write defaults can;
The number in the fifth column indicates whether or not the dump was backed up, so here is 1, otherwise 0; The sixth column is the self-test disk at boot time. All means detection, 0 means no detection,/partition must be set to 1, and the entire fstab only allow a 1, 1:2 priority, so first detect 1, and then detect 2, if there are multiple partitions need to boot detection then all set to 2 bar, 1 testing will be at the same time to detect 2.


Swap is when the system is out of memory and the data is temporarily stored in swap

5. LVM Configuration
LVM is a mechanism for managing disk partitions in a Linux environment, a logical layer that is built on top of hard disks and partitions and under a file system to improve the flexibility of disk partition management. Supports dynamic expansion of disk space.
First create two partitions from an empty hard disk SDB sdb1 1G, Sdb2 2G.
1) Creating a logical volume
PVCREATE/DEV/SDB1/DEV/SDB2//Create physical volume
Pvdisplay//Can list physical volumes that have been created
Vgcreate VGDATA/DEV/SDB1/DEV/SDB2//Create a volume group Vgdata and join the two physical volumes you just created to the volume group
Vgdisplay//Can list already-built volume groups
# The default PE size is 4mb,pe is the smallest storage unit for the volume group. You can modify the size by the –s parameter.

Lvcreate-l 500m-n lvdata1 vgdata//Split 500M to new logical volume LVDATA1
Lvdisplay//List the current logical volume

MKFS.EXT4/DEV/VGDATA/LVDATA1//Format logical volumes
Mount/dev/vgdata/lvdata1/aming//Mount logical volumes

2) extending the logical volume
Logical Volume LVDATA1 is not enough, how can we give him more space?
Lvextend–l +500m/dev/vgdata/lvdata1//Add 500M space to lvdata1.
RESIZE2FS/DEV/VGDATA/LVDATA1//Synchronizing file systems


3) Extended Volume group
We can also extend the volume group if the volume group is not available. Let's create a new partition called/DEV/SDB3.
Vgextend vgdata/dev/sdb3//Add SDB3 to the volume group Vgdata

4) Reduce the size of the logical volume
Uninstall-E2fsck detects the remaining space-resize2fs synchronizing the file system and uses the Lvreduce command to reduce the logical volume
Note: The file system size and logical volume size must be consistent. If the logical volume is larger than the file system, space is wasted because some areas are not formatted as file systems.

Umount/data1
E2fsck-f/dev/mapper/vgdata-lvdata1
Resize2fs/dev/mapper/vgdata-lvdata1 700M
Lvreduce-l 700m/dev/vgdata/lvdata1
Mount/dev/vgdata/lvdata1/data1

5) How to transfer data when a disk or partition is damaged
Pvmove transfer of spatial data--vgreduce command removes a bad disk or partition from the volume group Vgdata Remove--pvremove command removes the bad disk or partition from the system--remove or repair the disk
Pvmove/dev/sdb1
Vgreduce VGDATA/DEV/SDB1
Pvremove/dev/sdb1

6) Delete the entire logical volume
Umount unload the logical volume and modify the configuration file/etc/fstab (if previously changed)-Lvremove Delete the logical volume LVDATA1--Vgremove Delete the volume group Vgdata--Pvremove The physical volume Convert to normal partition
Umount/dev/vgdata/lvdata1
Lvremove/dev/vgdata/lvdata1
Vgremove Vgdata
Pvremove/dev/sdb2
Pvremove/dev/sdb3

what you want to expand your learning is:
Storage-related NAS, SAN, DAS, RAID
Disk structure, related concepts Header,sectors,cylinders
Virtualization Related: Xen and KVM

Linux under Disk 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.