Disk and file system management (a)

In Linux servers, when the existing hard drive's partition plan can not meet the requirements, you need to partition your hard drive to re-planning and adjustments, sometimes also need to add a new hard drive to extend your storage space.

We need to use fdisk disk and partition management tools to achieve the above requirements. fdisk is one of the most basic tools of the Linux operating system comes with.

After you mount the new hard disk device and start the host, Linux operating system will automatically detect and load the hard drive, no need to install any additional drivers. Execution "fdisk -l" command to view, confirm that the device name and location of the heart should be pressed Oh . "Fdisk -l" command role is to list information about the current system of all hard disk devices and partitions.
Disk and file system management (a)
For existing partitions, the following information will be output through the list:
Disk and file system management (a)
recognition to the new hard disk device, you can create a new partition on the hard disk. In the Linux operating system, partitioning and formatting process is relatively independent.

Created on the hard disk, delete, change the partition and other operations carried out by the same fdisk command, simply use the hard disk device file as a parameter. For example, the implementation of "fdisk / dev / sdb" command, you can enter the interactive partition management interface.
Disk and file system management (a)
In the user interface, the input operation instruction specific partition, the partition can be done in the management tasks. For example, enter "m" instruction, the specified operation can view various help information:
Disk and file system management (a)
commonly used commands are:

"P" instruction - the hard disk partition is listed in the
Disk and file system management (a)
"n" instructions - New partition
Disk and file system management (a)
end position or size can be used in the form of "+ sizeM" or "+ sizeG" FIG.
"T" instruction - Transform partition type
Disk and file system management (a)
wherein 8e indicates the logical volume, 82 indicates the SWAP (swap), 83 denotes XFS file system type, 86 indicates the NTFS file system types; 5 represents the extended partition.
After completing the operation "q" represents the exit without saving, "w" represents the save and exit ;
after changing the hard disk partition settings (especially those who are using the hard disk), it is recommended to restart the system, or use the command:

[root@localhost ~]# partprobe /dev/sdb
#更新分区信息

In some of the Linux operating system, if you do not update the disk information, it may result in damage to the existing data on your hard disk when you format the partition, serious and even cause system crashes.

Using the Linux operating system
mkfs (create a file system) command to partition formatted for a variety of different types of file systems; and Swap swap partition is formatted using the mkswap command.
mkfs command is located in / sbin / directory, execute the command:

[root@localhost ~]# ls /sbin/mkfs*
#查看当前操作系统内与mkfs命令相关的工具程序

Disk and file system management (a)

Creating XFS file system , use the command:

[root@localhost ~]# mkfs -t xfs /dev/sdb1
或者
[root@localhost ~]# mkfs.xfs /dev/sdb1

Disk and file system management (a)
Create a FAT32 file system , use the command:

[root@localhost ~]# mkfs -t vfat -F 32 /dev/sdb1
或者
[root@localhost ~]# mkfs.vfat -F 32 /dev/sdb1

Disk and file system management (a)

Create a swap file system , use the command:

[root@localhost ~]# mkswap /dev/sdb5

Disk and file system management (a)
For newly added swap, you need to use the swapon command to enable , disable and vice versa using swapoff command specified a swap partition.

[root@localhost ~]# cat /proc/meminfo | grep "SwapTotal"
#查看交换分区空间大小
[root@localhost ~]# swapon /dev/sdb5
#启用交换分区

Disk and file system management (a)
Disk need to mount a directory formatted, the disk space before you can use it, use the command:

[root@localhost ~]# mount /dev/sdb1 /mnt
#具体目录根据需要自己填写

Disk and file system management (a)
Uninstalling using the command:

[root@localhost ~]# umount /dev/sdb1

Such are temporary mount mounted disk, restart the system if you need to remount, we need to write the configuration file:

[root@localhost ~]# vim /etc/fstab 

Disk and file system management (a)
Six fields in the configuration file, configuration information, including from left to right are:
Disk and file system management (a)
Note: If wrong, reboot the system, would not normally enter the system, do not worry about direct input root password before entering the emergency mode, you can modify the profile.
View disk usage, use the command:

[root@localhost ~]# df -hT

df command uses the device as a file or command parameters more commonly used options are "-h" and "-T". "-H" denotes a display unit more comprehensible capacity; "- T" indicates the type of the display corresponding to the file system.
Disk and file system management (a)

Guess you like

Origin blog.51cto.com/14157628/2414516