Linux (Radhat) Basic learning-system storage devices and system partitioning

Source: Internet
Author: User

1. System storage device 1. Identification of the local storage device
 fdisk -l      ##真实存在的设备,入插的u盘等 cat /proc/partitions   ##系统识别的设备信息 blkid          ##系统可使用的设备、 df          ##系统正在挂载的设备


Blkid


Cat/proc/partitions:


Df:

2. Mounting and unloading of the device

1. Device Name

/dev/xdx    ##dev/hd0  /dev/hd1  /dev/sda  /dev/sdb  /dev/sdb1  /dev/sda1  /dev/sda2/dev/sr0    ##光驱/dev/mapper/*   ##虚拟设备

2. Mount Uninstall

mount 设备 挂载点mount /dev/sdb1 /mnt        ##挂载sdb1到/mntumount /mnt | /dev/sdb1     ##卸载mount -o ro /dev/sdb1 /mnt  ##只读挂载mount               ##查看挂载信息mount -o remount,rw /dev/sdb1 | mnt ##重新读写挂载
3. Resolve the device being busy (this device is being used by a program.) )

Method 1:fuser-kvm/mnt
Method 2:lsof/mnt (view those programs running on the device) and then end the running process: kill-9 PID

2. Disk Partitioning


1. The information recorded in the 512 bytes of the disk 0 Track 1 sector is as follows

512  =  446      +     64       +    2mbr(主引导记录):446字节         mpt(分区表):64字节     55aa(硬盘有效性标示):2字节


Hard disk partition Table

The information for a partition occupies 16 bytes in the partition table, so a maximum of 4 partitions are recorded in the partitioned table.
Other types of partitions can no longer be partitioned in the primary partition, so each primary partition is equivalent to a logical disk. If you need more than 4 partitions, you need to divide the extended partition.


Attention:

(1). The extended partition cannot be used directly and must be partitioned into logical partitions. All logical partitions are part of the extended partition. Extended partition cannot be viewed in "My Computer", "Computer", only the primary and logical partitions can be seen
(2). A hard disk primary partition has at least 1, a maximum of 4, and an extended partition can have up to 1. There cannot be more than 4 primary partitions + extended partitions. A logical partition can have several.
(3). The information for the primary and extended partitions is in the MBR hard disk partition table (DPT), while the information for the logical drive is located in the starting sector of the extended partition.
(4). After dividing the main partition, the rest can be divided into extended partitions, usually the rest of the sections are divided into extended partitions, or not into extended partitions, but the rest of the part is wasted
(5). Logical disks consisting of primary and logical partitions are called drives or volumes
(6). The active partition is a partition that has bootstrap (boot system) capability after power on the system, and a master boot in the master boot record on the active partition, and whenever the system starts, the program is called into memory to boot (boot) to save the operating system on the hard disk.

3. Partitioning of partitions 1. Viewing devices: Fdisk-l

2. Enter the partition: FDISK/DEV/VDB

Command (m for help): m         ##查看帮助(有哪些命令)Command action     a   toggle a bootable flag     b   edit bsd disklabel     c   toggle the dos compatibility flag     d   delete a partition     ##删除分区     g   create a new empty GPT partition table     G   create an IRIX (SGI) partition table     l   list known partition types ##列出系统可用的分区类型     m   print this menu     n   add a new partition        ##新建分区     o   create a new empty DOS partition table     p   print the partition table  ##显示分区     q   quit without saving changes    ##退出     s   create a new empty Sun disklabel     t   change a partition‘s system id ##修改分区功能id     u   change display/entry units     v   verify the partition table     w   write table to disk and exit   ##保存更改到分区表中     x   extra functionality (experts only)
3. Create a new partition
Command (m for help): n         ##新建分区

    Command (m for help): p   ##查看磁盘分区

Command (m for help): wq        ##保存退出,如果安q表示放弃更改退出

partprobe   手动同步分区表(当划分分区保存后,出现Wornning警告,这时需要我们退出分区划分,在shell中手动同步分区)


1. To divide more than 4 partitions, after dividing the 3 primary partitions, partition the extended partitions, divide all the remaining space into the extended partition, and partition the logical partitions in the extended partition.


2. After partitioning the system, you cannot use it directly, and you need to format the partition and use the file system to manage the partition space.

ps:文件系统     名字     版本      最大容量    单个文件最大容量    理论最大读取速度    理论最大写入速度(1)ext3     rhel5       (2)ext4     rhel6       1EB         16TB    (3)xfs      rhel7       18EB         9EB        7G/s(实际1G左右)4G/s(实际400M左右)

(use partition/DEV/VDB1 as an example)

4. Formatting

MKFS.XFS/DEV/VDB1 # #格式化 (formatted/DEV/VDB1) for XFS file system

Blkid # #查看

5. Mounting
mount /dev/vdb5  /mnt           ##临时挂载

Can be mounted to/mnt (actually entering the disk partition) for administrative operations

After writing on disk, the/mnt remains intact.


Permanent Mount

编辑文件:vim /etc/fstab             

设备            挂载点      文件系统       挂载参数           是否备份    是否检测devic        mountpoint    ftype   defaults(mountpoint)     0/1       0/1/dev/vdb1   /mnt            xfs         defaults            0          0

If you write an error in this file, it will not boot properly.
Solution: Boot, will require the input root password, enter the system text interface, then go to write the wrong content commented out, or modify the error in/etc/fstab.

Effective: mount-a (makes the attached policy in/etc/fstab active)

4.swap Partition Management

(The operation is described below with partition/DEV/VDB2)

Creation of 1.SWAP partitions
(1)划分分区并设定标签为82,或者直接把已有的分区设定标签为82。保存退出。(82表示swap分区)



To modify a partition label:



To view the results of the modification:



Save exit:

(2)mkswap /dev/vdb2 ##格式化swap分区

(3)swapon -a /dev/vdb2  ##临时挂载swap分区(4)swapon -s    ##查看swap分区



To mount the SAWP partition permanently:

 vim /etc/fstab

Mount-a (detects/etc/fstab file, so automatic mount takes effect)

Deletion of 2.swap partitions
vim /etc/fstab  ##删除(或者注释掉)文件中的分区信息swapoff /dev/vdb2   ##删除swapon -s       ##查看

5. Quotas

Quotas are for partitions, not for users.

Create a new mount directory: mkdir/pub (Mount disk partition usage)

mount -o usrquota /dev/vdb1 /pub    ##临时挂载,加上配额参数打开,默认是关闭的,加-o开启chmod 777 /pub      ##挂载后再修改权限。edquota -u student  ##打开配置配额文件(以student为例子)

Disk quotas for user student (uid 1000):     设备       已存在文件大小      软额度     最大额度 存在文件数量Filesystem         blocks          soft       hard       inodes         soft     hard    /dev/vdb1         0                 0         100000         0           0        0

Save exit.
(The example gives student a space size of 100000kb about 90 m)


Permanent Mount:

编辑文件:vim /etc/fstab

Mount-a (detects/etc/fstab file, so automatic mount takes effect)


Test:

Student Users:


No more than the allocated space limit, normal


Exceeded the allocated space limit, error.
Error: Dd:erro writing ' pub/studentfile ':D ISK quota exceeded

6. Disk encryption and decryption 1. Disk encryption
fdisk  /dev/vdb             ##创建新的分区(也可以直接使用已经创建好的分区)cryptsetup luksFormat /dev/vdb3     ##加密设备(z注意,在redhat中确认加密时,要输入大写的YES,小写没用。这里是个小bug)

cryptsetup open /dev/vdb3 mysteryfile(这个名字任意)   ##打开加密的分区,在/dev/mapper/下生成一个临时连接westos,连接到真正的设备。

mkfs.xfs  /dev/mapper/mysteryfile       ##格式化分区为xfs格式(格式化后才能写入内容,只用个好死花一次,后面打开加密设备使用时则不需要格式化了)

mount /dev/mapper/westos  /mnt/     ##挂载到/mnt目录

Once the mount is complete, the encrypted partition can be manipulated.

umount /mnt/                ##卸载cryptsetup close westos         ##关闭加密分区


1. The first time you open an encrypted disk partition, you need to format the file system on the partition for file management operations
2. Then you need to operate the encrypted disk partition, first open the encrypted partition, and then mount it. Otherwise, it cannot be manipulated because of partition encryption.

2. Automatic mount of encrypted disk
(1)编辑文件:vim /etc/crypttab    解密后设备管理文件   设备       加密字符存放文件           filename          /dev/vdb3      /root/lukspsfile(2)编辑加密字符文件(设备/dev/vdbx的解密密码)vim /root/lukspsfile(3)设置存放密码的文件为600权限chmod 600 /root/lukspsfile(4)关联设备和密码文件cryptsetup luksAddKey /dev/vdb1  /root/lukspsfile(5)自动挂载编辑文件:vim /etc/fstab    /dev/mapper/filename    /mnt    xfs defaults    0 0

Mount-a detect/etc/fstab file, make automatic mount effective

3. Encryption Erase
(1)编辑文件:vim /etc/fstab(去除开机自启代码)(2)> /etc/crypttab(清空文件)(3)rm -fr /root/lukspsfile(删除密码文件)(4)umount /mnt/(卸载加密的磁盘分区)(5)cryptsetup close westos(关闭加密磁盘分区)(6)mkfs.xfs  /dev/vdb1(重新格式化分区的文件系统)

Linux (Radhat) Basic learning-system storage devices and system partitioning

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.