XI partitioning disk storage structure (II)

6.6 Adding a swap partition

SWAP (swap) is a partition on the hard disk divided in advance by a certain space, then the memory will be temporarily used data temporarily stored to the hard disk in order to free up physical memory space technology to make more active use of the Service , which is designed to solve the real physical memory shortage. However, due to the swap partition, after all, it is through hard disk device to read and write data, so the speed is certainly true only when the physical memory is exhausted resources will be called the swap partition slower than physical memory.

Creation of swap partitions and mount mentioned earlier and use the storage devices are very similar. In front of / dev / sdb partition storage devices operate, it is necessary to talk about the division of recommended swap partition: In a production environment, the size of the swap partition is generally 1.5 to 2 times the actual physical memory, in order to make everyone more clearly sensitive to changes in the swap space, where a size is taken as the primary partition 5GB swap resources. After the partition is created to save and exit to:

[root@linuxprobe ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xb3d27ce1.
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extendedSelect (default p): p
Partition number (2-4, default 2): 
First sector (4196352-41943039, default 4196352) : Here hit Enter
Using default value 4196352
Last sector, +sectors or +size{K,M,G} (4196352-41943039, default 41943039): +5G
Partition 2 of type Linux and of size 5 GiB is set
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xb0ced57f
 Device Boot Start End Blocks Id System
/dev/sdb1 2048 4196351 2097152 83 Linux
/dev/sdb2 4196352 14682111 5242880 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

SWAP using formatting commands dedicated to the partition mkswap, for new primary partition to format:

[root@linuxprobe ~]# mkswap /dev/sdb2
Setting up swapspace version 1, size = 5242876 KiB
no label, UUID=2972f9cb-17f0-4113-84c6-c64b97c40c75

Ready to use swapon SWAP partition device mounted to the formal system. We can use the free -m command to view the swap partition size changes (increased by the 2047MB 7167MB):

[root@linuxprobe ~]# free -m
total used free shared buffers cached
Mem: 1483 782 701 9 0 254
-/+ buffers/cache: 526 957
Swap: 2047 0 2047
[Root @ linuxprobe ~] # swapon / dev / sdb2
[root@linuxprobe ~]# free -m
total used free shared buffers cached
Mem: 1483 785 697 9 0 254
-/+ buffers/cache: 530 953
Swap: 7167 0 7167

In order to make the new swap device is still effective after the restart, need to follow the following format information is written to the configuration file, and remember to save:

[root@linuxprobe ~]# vim /etc/fstab
#
# /etc/fstab
# Created by anaconda on Wed May 4 19:26:23 2017
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/rhel-root / xfs defaults 1 1
UUID=812b1f7c-8b5b-43da-8c06-b9999e0fe48b /boot xfs defaults 1 2
/dev/mapper/rhel-swap swap swap defaults 0 0
/dev/cdrom /media/cdrom iso9660 defaults 0 0 
/dev/sdb1 /newFS xfs defaults 0 0 
/dev/sdb2 swap swap defaults 0 0 
6.7 capacity disk quota

The book had mentioned earlier, the Linux system is designed to allow many people to use and perform their tasks together, thus becoming a multi-user, multi-tasking operating system. However, the hardware resources are fixed and limited, if some users continue to create a file stored on a Linux system or a movie, hard disk space will one day be filled. In view of this situation, root administrator will need to use disk space quotas to restrict the service by the user or a user group for the largest number of specific folders can be used a maximum hard disk space or file once it is no longer allowed to reach this maximum continue to use. The maximum number of files you can use the quota command disk quota management capacity, thereby limiting the available capacity of the hard disk or user can create. The quota command as well as soft and hard limits of functions.

Soft limit : When reaching the soft limit will prompt the user, while still allowing users to continue to use a limited amount.

Hard limit : when the user is prompted reaches the hard limit, and forced termination operation by the user.

RHEL 7 has a quota system disk capacity quotas service packages installed, but not enabled by default storage device has the support of the quota, then you need to manually edit the configuration file, so that RHEL 7 system / boot directory disk quotas technology can support quota . In addition, we learned early Linux systems, or systems using RHEL 6 has experienced readers, here in need of special attention. Early Linux system to get the hard disk capacity device supports quota quota service, using usrquota parameters, while RHEL 7 system used is uquota parameters. After restarting the system using the mount command to see, you can find / boot directory disk quotas quota has supported the technology:

[root@linuxprobe ~]# vim /etc/fstab
#
# /etc/fstab
# Created by anaconda on Wed May 4 19:26:23 2017
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/rhel-root / xfs defaults 1 1
UUID=812b1f7c-8b5b-43da-8c06-b9999e0fe48b /boot xfs defaults,uquota 1 2
/dev/mapper/rhel-swap swap swap defaults 0 0
/dev/cdrom /media/cdrom iso9660 defaults 0 0 
/dev/sdb1 /newFS xfs defaults 0 0 
/dev/sdb2 swap swap defaults 0 0 
[root@linuxprobe ~]# reboot
[root@linuxprobe ~]# mount | grep boot
/dev/sda1 on /boot type xfs (rw,relatime,seclabel,attr2,inode64,usrquota)

Next, create a user tom to check quota of disk capacity quota effects and increase the rights of other people write for / boot directory, to ensure that users can write data correctly:

[root@linuxprobe ~]# useradd tom
[root@linuxprobe ~]# chmod -Rf o+w /boot

1. xfs_quota command

xfs_quota command is a specific XFS file system disk capacity to manage quota quota service designed to command in the format of "xfs_quota [parameters] file quota system." Which, -c parameter is used to set the command to be executed as a parameter; -x parameter is the expert mode, so that operation and maintenance personnel can carry out more complex configuration of the quota service. Next we use xfs_quota command to set the user tom quota quota of disk capacity / boot directory. Specific quota controls include: soft limit and hard disk usage restrictions are 3MB and 6MB; create the file number of soft and hard limits are 3 and 6.

[root@linuxprobe ~]# xfs_quota -x -c 'limit bsoft=3m bhard=6m isoft=3 ihard=6 tom' /boot
[root@linuxprobe ~]# xfs_quota -x -c report /boot
User quota on /boot (/dev/sda1)   Blocks
User ID Used Soft Hard Warn/Grace
---------- --------------------------------------------------
root 95084 0 0 00 [--------]
tom 0 3072 6144 00 [--------]

When configured in the above-described hard and soft limits, try switching to the normal user, respectively, and then try to create a volume of 8MB and 5MB files. It can be found by the system limitations when creating a file 8MB of:

[Root @ linuxprobe ~] # are - this
[tom@linuxprobe ~]$ dd if=/dev/zero of=/boot/tom bs=5M count=1
1+0 records in
1+0 records out
5242880 bytes (5.2 MB) copied, 0.123966 s, 42.3 MB/s
[tom@linuxprobe ~]$ dd if=/dev/zero of=/boot/tom bs=8M count=1
dd: error writing ‘/boot/tom’: Disk quota exceeded
1+0 records in
0+0 records out
6291456 bytes (6.3 MB) copied, 0.0201593 s, 312 MB/s

2. edquota command

quota quota edquota command for editing the user, the format of "edquota [parameters] [user]." After setting the quota of disk capacity quotas for users, you can use the edquota command needed to modify the value limit. Which, -u parameter indicates which should be set for the user; -g parameter indicates which user group to be set up for. edquota command is invoked Vi or Vim editor to make root administrator to modify the details to be restricted. Below the disk usage of a user's hard tom limit from 5MB to enhance 8MB:

[root@linuxprobe ~]# edquota -u tom
Disk quotas for user tom (uid 1001):
 Filesystem blocks soft hard inodes soft hard
 /dev/sda1 6144 3072 8192 1 3 6
[Root @ linuxprobe ~] # are - this
Last login: Mon Sep 7 16:43:12 CST 2017 on pts/0
[tom@linuxprobe ~]$ dd if=/dev/zero of=/boot/tom bs=8M count=1
1+0 records in
1+0 records out
8388608 bytes (8.4 MB) copied, 0.0268044 s, 313 MB/s
[tom@linuxprobe ~]$ dd if=/dev/zero of=/boot/tom bs=10M count=1
dd: error writing ‘/boot/tom’: Disk quota exceeded
1+0 records in
0+0 records out
8388608 bytes (8.4 MB) copied, 0.167529 s, 50.1 MB/s
6.8 soft and hard way links

When you finish learning all leading hard disk management knowledge of this chapter, teacher Trent Liu finally can safely explain the Linux system in the "shortcut" the. On Windows systems, a shortcut that points to the original file is a link file that allows users to access the original files from different locations; Once the original file is deleted or cut elsewhere, will lead to failure linked files. However, this seemingly simple things in Linux systems can not the same.

The presence of soft and hard links connecting the two files in the Linux system.

Hard link (hard link): it can be understood as a "pointer points to the original inode file", the system is not allocated to a separate file and its inode. So, hard-linked files with original file is actually the same file, just different names. We each add a hard link, the file inode number of connections will increase 1; and only when the file inode number of connections is 0, considered completely delete it. In other words, due to the hard link is actually a pointer to the original file's inode, so even if the original file is deleted, you can still be accessed via a hard link files. It should be noted that, due to technical limitations, we can not cross-linked files directory partition.

Soft links (also referred to as a symbolic link [symbolic link]): contains only the pathname linked, it is possible to link the directory file, the file system may be cross linked. However, when the original file is deleted, the linked file will be broken, and from that point on Windows systems "shortcut" has the same properties.

ln command

ln command is used to create the link file, the format is "ln [options] target", as shown in its available parameters and the role of Table 6-6. When using the ln command, whether to add the -s parameter, it will create different properties of the two "shortcut." So if there is no solid theoretical knowledge and practical experience to pave the way, although it is possible to complete the experiment was a success, but will never understand why success.

Table 6-6 ln command parameters available and the role of

parameter effect
-s Create a "symbolic link" (Without the -s parameter, the default create a hard link)
-f Forced to create a file or directory links
-i Ask first before covering
-v Show the process of creating links

 

To better understand the different types of soft links, hard links, then create a soft link similar to the Windows system shortcuts. Thus, when the original file is deleted, you can not read the new link to the file.

[root@linuxprobe ~]# echo "Welcome to linuxprobe.com" > readme.txt
[Root @ linuxprobe ~] # ln -s readme.txt readit.txt
[root@linuxprobe ~]# cat readme.txt 
Welcome to linuxprobe.com
[Root @ linuxprobe ~] # cat readit.txt 
Welcome to linuxprobe.com
[root@linuxprobe ~]# ls -l readme.txt 
-rw-r--r-- 1 root root 26 Jan 11 00:08 readme.txt
[root@linuxprobe ~]# rm -f readme.txt 
[Root @ linuxprobe ~] # cat readit.txt 
cat: readit.txt: No such file or directory

Then for one original file to create a hard link, which is equivalent to creating a pointer for the hard disk storage location of the original file, this way, this newly created hard links no longer rely on the original file name and other information, nor delete the original file because the result can not be read. At the same time you can see to create a hard link, hard link to the original file number increased to 2.

[root@linuxprobe ~]# echo "Welcome to linuxprobe.com" > readme.txt
[Root @ linuxprobe ~] # n readme.txt readit.txt
[root@linuxprobe ~]# cat readme.txt 
Welcome to linuxprobe.com
[Root @ linuxprobe ~] # cat readit.txt 
Welcome to linuxprobe.com
[root@linuxprobe ~]# ls -l readme.txt 
-rw-r--r-- 2 root root 26 Jan 11 00:13 readme.txt
[root@linuxprobe ~]# rm -f readme.txt 
[Root @ linuxprobe ~] # cat readit.txt 
Welcome to linuxprobe.com

 

 

 

 

This section of the review

1. What are the similarities and differences / home directory with the / root directory and storing the file?

A: These two directories are used to store the user's home directory data, however, / root directory is stored in the root administrator's home directory data.

2. If the file name of a device is / dev / sdb, you can confirm that it is the second device on the motherboard slot it?

答:不一定,因为设备的文件名称是由系统的识别顺序来决定的。

3.如果硬盘中需要5个分区,至少需要几个逻辑分区?

答:可以选用创建3个主分区+1个扩展分区的方法,然后把扩展分区再分成2个逻辑分区,即有了5个分区。

4./dev/sda5是主分区还是逻辑分区?

答:逻辑分区。

5.哪个服务决定了设备在/dev目录中的名称?

答:udev设备管理器服务。

6.用一句话来描述挂载操作。

答:当用户需要使用硬盘设备或分区中的数据时,需要先将其与一个已存在的目录文件进行关联,而这个关联动作就是“挂载”。

7.在配置quota磁盘容量配额服务时,软限制数值必须小于硬限制数值么?

答:不一定,软限制数值可以小于等于硬限制数值。

8.若原始文件被改名,那么之前创建的硬链接还能访问到这个原始文件么?

答:可以。

 

Guess you like

Origin www.cnblogs.com/doudou3680/p/12043741.html