1. Manage storage devices
1. Discover the devices in the system
fdisk -l to view the real devices in the system
cat /proc/partitions to view the devices recognized by the system in the system
blkid The device with id information discovered by the system and used by the system
Devices found and mounted
df -h
df -H
Second, the understanding of the device name
/dev/sda1 sata hard disk, or iscsi network storage (v represents virtual hard disk, h represents ide hard disk, usually in old-fashioned computers) a1 represents the first partition in the first hard disk
/dev/cdrom optical drive
/dev/mapper/* virtual devices in the system
3. The use of equipment
The device must use the directory to read the contents of the device,
so the device needs to be mounted when it is in use
1. Mount the device
blkid identifies available devices
mount /dev/sdb1 /mnt mounts the first partition under the second hard disk in the system to mnt
mount -o ro /dev/sdb1 /mnt/ read-only mounts the second hard disk under the first partition to /mnt
mount -o remount,rw /mnt Change the mount parameter of the device to rw when the device is used
2. Device unmount
umount device (mount point) umount /dev/vsb1 (/mnt)
FBI warning: ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
When the device is unmounted, the following conditions appear, indicating that the device is being used by a program in the system
umount: /mnt: target is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1 ))
The general reason is because the current path is at this mount point, or there is a process in this directory
4. Partition management
1. The mbr master boot record is 446 bytes . 2. The mtp
main partition table is 64 bytes
. 3. The validity mark of the hard disk "55aa" occupies 2 bytes
. If you use the mbr partition
method, there can be up to 4 primary partitions on the hard disk
.
####Partition division##
fdisk -l Find devices currently available for partitioning
fdisk /dev/vdb
Welcome to fdisk (util-linux 2.23.2).
Create a new primary partition
After creating a new partition, you need to synchronize the partition table partprobe ##Sync the partition table
mkfs.xfs /dev/vdb1 ##Format
mount /dev/vdb1 /mnt ##Temporary mount
vim /etc/fstab ##永久挂载
devic mountpoint ftype defaults(mountpoint) 0 0
/dev/vdb1 /mnt xfs defaults 0 0
mount -a #Make the mount policy recorded in /etc/fstab take effect
5. Set the partition mode to gtp
Create a new partition to see the effect
Six, swap partition
swapon -s to see if there is a syapon partition
Create a new partition and change the partition id to Linux swap / Solaris
[root@node2 ~]# mkswap /dev/vdb1 Set the /dev/vdb1 partition as a linux swap
Setting up swapspace version 1, size = 1023996 KiB
no label, UUID=28c3c77b-91f3-4098-9736-2d694a870c22
[root @node2 ~]# swapon -a /dev/vdb1 Start /dev/vdb1 partition swap device
[root@node2 ~]# swapon -s Show swap partition
Filename Type Size Used Priority
/dev/vdb1 partition 1023996 0 -1
Permanently change to vim /etc/fstab
mount -a reread
delete swap partition
swapoff /dev/vdb1
Delete the configuration in the configuration file
Seven, partition quota
Check whether the quota is enabled by mount (noquota means not enabled, usrquota means enable quota).
If it shows that the quota is not enabled, you need to unmount it and mount it again, and enable the quota when mounting
mount -o usrquota /dev/vdb1 /mnt/ mount and enable quota
edquota -u student
Disk quotas for user student (uid 1000):
Filesystem blocks soft hard inodes soft hard
/dev/vdb1 0 0 20480 0 0 0
This modification is a temporary modification, if the permanent setting needs to modify the /etc/fstab file
/dev/vdb2 /mnt xfs defaults,usrquota 0 0
Test: give 777 permissions to the /mnt directory before testing, and then switch to the student user
Switch to student user testing
[student@node2 ~]$ dd if=/dev/zero of=/mnt/studentfile bs=1M count=30
dd: error writing ‘/mnt/studentfile’: Disk quota exceeded
21+0 records in
20+0 records out
20971520 bytes (21 MB) copied, 0.00945847 s, 2.2 GB/s
Eight, disk encryption
1 Disk encryption
fdisk /dev/vdb Create a new disk
cryptsetup luksFormat /dev/vdb1 Set disk encryption for this disk and set a password (password needs to be more than 8 digits)
cryptsetup open /dev/vdb1 westos Open this encrypted disk
mkfs.xfs /dev/ mapper/westos format disk
mount /dev/mapper/westos /mnt/ mount the disk
umount /mnt/ unmount disk
cryptsetup close westos Close the encrypted disk
2. Encrypted disk will start automatically
[root@node2 ~]# vim /root/diskpass write disk password
[root@node2 ~]# chmod 600 /root/diskpass Set disk permissions to only superusers
[root@node2 ~]# vim /etc/crypttab Write the disk name, disk device, and the file where the disk password is located
westos /dev/vdb1 /root/diskpass
[root@node2 ~]# vim /etc/fstab Modify the configuration file
/dev/mapper/westos /mnt xfs defaults 0 0
[root@node2 ~]# cryptsetup luksAddKey /dev/vdb1 /root/diskpass tells the system to specify the password of the encrypted disk
Enter any passphrase:
[root@node2 ~]# reboot
[root@node2 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3704528 6769372 36% /
devtmpfs 469344 0 469344 0% /dev
tmpfs 484932 80 484852 1% /dev/shm
tmpfs 484932 12760 472172 3% /run
tmpfs 484932 0 484932 0% /sys/fs/cgroup
/dev/mapper/westos 506540 25656 480884 6% /mnt
3. Self-starting and clearing of encrypted disks
[root@node2 ~]# vim /etc/fstab delete the settings in the configuration file
[root@node2 ~]# umount /mnt/ unmount and mount
[root@node2 ~]# vim /etc/crypttab delete the contents Specify
[root@node2 ~]# rm -fr /root/diskpass to delete the password file
[root@node2 ~]# cryptsetup close westos to close the encrypted disk
[root@node2 ~]# mkfs.xfs /dev/vdb1 to format the encrypted disk
mkfs .xfs: /dev/vdb1 appears to contain an existing filesystem (crypto_LUKS).
mkfs.xfs: Use the -f option to force overwrite.
[root@node2 ~]# mkfs.xfs /dev/vdb1 -f encrypts this format need to add -f
Nine, disk array
1. Array type
0: 1/2 + 1/2 ## write fast
1:1+1 ##Reading speed is fast
5: 0 + 1 ##At least 3 disks, such as 2 0s, 1 1
2, raid array
watch -n 1 cat /proc/mdstat Monitoring command
cat /proc/mdstat View raid device status
Create three disks and modify the id to be a disk in Linux raid auto mode
Create mode
option -C
-l level
-n number of running devices
-a "yes|no" automatically create device files for it
-c specify data block size
-x specify the number of free disks, the free disk can be used after the working disk is damaged automatic replacement
mdadm -C /dev/md0 -a yes -l 1 -n 2 -x 1 /dev/vdb{2,3,5} create /dev/md0 device
mdadm -D /dev/md0 View the specified raid device information
mkfs.xfs /dev/md0 format
mount /dev/md0 /mnt/ mount
mdadm /dev/md0 -f /dev/vdb2 forcibly destroy a disk
mdadm /dev/md0 -r /dev/vdb2 delete a disk
mdadm /dev/md0 -a /dev/vdb2 add a disk
unmount array
umount /mnt/ remove mount
mdadm -S /dev/md0 stop array
Delete these raid mode disks
partprobe rereads the partition table