preface
In this article, you will learn about disk mounting in Disk management in Linux. This is probably the most practical Linux hard disk mount article introduced so far, more detailed. Due to work reasons, usually used more. The main goal is just to let more people know that mounting disks under Linux is not so difficult.
There are several common file systems, including the old ext file system (ext2, ext3, ext4).
In the Redhat7 series, we recommend an excellent XFS file system that already beats ext in performance. The XFS file system was developed by Silicon Graphic Inc (SGI) for IRIX, a Unix operating system, and later ported to the Linux operating system. XFS is an advanced journaling file system that has the advantage of being extremely scalable, but also extremely robust.
There is also a BTRFS (Better FS, Buffer FS, b-Tree FS) file system that comes with Redhat7. BTRFS has many features. For example, write snapshot, snapshot of snapshot, built – in RAID (usually called disk array), subvolume, the core concept is fault tolerance, repair, and easy management. The maximum capacity of a BTRFS volume is 16EB, and the maximum capacity of a file is 16EB.
Note: This article uses the installation language of choice is simplified Chinese, so please do not be surprised to see Chinese characters displayed.
The body of the
Start with a picture, and the article depends entirely on editing. I’m just kidding. It’s just for family fun. The picture below illustrates the core of this article.
Suggestion: Perform the test using a Linux (Redhat or Ubuntu) VM.
1. View system partitions
Fdisk Parameter Description Delete an existing disk partition. In this case, a message is displayed indicating the serial number of the disk partition to be deleted.
-
Delete a partition: d
-
Add partition: n
-
Query partition information: p
-
Save partition change information: w
-
Exit without saving: q
-
For help information: m
1. List the partition table
The original disk /dev/sda: 21.5 GB was allocated with the initial installation of the Linux operating system. The other disk is my new disk SDB for the test demo.
fidsk -l
[root@cnwangk /]# fdisk -lDisk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 Sector Units = Sector of 1 x 512 = 512 bytes Sector size (logical/physical) : 512 bytes / 512 bytes I/O size (minimum/best) : 512 bytes / 512 bytes Disk label type: DOS Disk Identifier: 0x0001805E Device Boot Start End Blocks Id System /dev/sda1 * 2048 411647 204800 83 Linux /dev/sda2 411648 4507647 2048000 83 Linux /dev/sda3 4507648 8603647 2048000 82 Linux swap / Solaris /dev/sda4 8603648 41943039 16669696 5 Extended /dev/sda5 8605696 41943039 16668672 83 Linux disk /dev/sda5 10.7 GB, 10737418240 bytes, 20971520 Sector Units = Sector of 1 x 512 = 512 bytes Sector size (logical/physical) : 512 bytes / 512 bytes I/O size (minimum/Best) : 512 bytes / 512 bytes Disk label type: DOS Disk Identifier: 0x95DF3B22 Device Boot Start End Blocks Id System /dev/sdb2 10485760 20971519 5242880 83 LinuxCopy the code
Enter the fdisk command directly, and the Help information and usage method are displayed in the Chinese version
Fdisk [options] < disk > Changes the partition table# For example, SDBFdisk /dev/sdb fdisk [option] -l < disk > Lists the partition table fdisk -s < partition > lists the partition size (number of blocks)Copy the code
Create a Linux file system
1. XFS file system
As shown below, I will create a new XFS file system, pointing to the new disk file path /dev/sdb. It is also the recommended format by default for the Redhat7 series.
mkfs.xfs /dev/sdb
Copy the code
A quick note: XFS file system provides the backup partition utility Xfsdump for users to use. The advantage is that users can back up data on XFS file systems without resorting to third-party software. The backup process is as follows:
xfsdump /backup/dump_sdc1 /sdc1
Copy the code
2. BTRFS file system
As shown below, I will create a new BTRFS file system, pointing to the new disk file path /dev/sdb, and the BTRFS file system configuration is finally shown below.
mkfs.btrfs /dev/sdb
Copy the code
Ext file system
Before Redhat6, and before that, we used ext file system. The XFS file system was recommended for the later series 7.
mkfs.ext4 /dev/sdb
Copy the code
3. Create a mount path
1. Create the mounted file data
Run the mkdir command to create a data directory for mounting the new disk.
mkdir /data
Copy the code
View the created mount path data, which is initially empty
ls /data
Copy the code
2. Use disks
Write a simple shell script as a demonstration
echo -e "echo "hello linux"\necho "create btrfs filesystem"" >> /data/data.sh
Copy the code
After writing a simple shell script, the test views and executes the script
# Check the files in the data disk again
[root@cnwangk /]# ls /data/
data.sh
sh /data/data.sh
Run the script
[root@cnwangk /]# sh /data/data.sh
hello linux
create btrfs filesystem
Copy the code
As can be seen from the above, a basic disk management will lead to the use of some basic commands, such as ls, mkdir, echo and so on. The audience for this article is someone who needs to know some basic Linux commands. Of course, you can see this article, but also that you still have some foundation.
4. Use fdisk to partition /dev/sdb
1. Run the fdisk command
Use fdisk to partition the new disk /dev/sdb. In the previous demonstration, I have used primary partition 2. In the present demonstration, I have used logical extended partition, using parameter e.
- Add partition: n
- Add primary partition: p
- Extended partition: e
- Note: You can customize the size or enter to use the default size and sector.
fdisk /dev/sdb
[root@cnwangk /]# fdisk /dev/sdbWelcome to fdisk (util-Linux 2.23.2). Changes stay in memory until you decide to write them to disk. Think twice before using write commands. Command (enter m for help) : nCreate partition (p); create partition (e)
Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): E Zone IDS (1,3,4) : 1 48-20971519 Start sector (2048 by default) : Default values 2048 Last sector, + sector or +size{K,M,G} (2048-10485759) are used: The default value 10485759 will be used. Partition 1 has been set to Extended type and size to 5. GiB command (enter m for help) : pThe unsaved partition information is displayed with the p parameterDisk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 Sector Units = Sector of 1 * 512 = 512 bytes Sector size (logical/physical) : 512 bytes / 512 bytes I/O size (minimum/Best) : 512 bytes / 512 bytes Disk label type: DOS Disk identifier: 0x95DF3B22The device information about the new partition is displayedDevice Boot Start End Blocks Id System /dev/sdb1 2048 10485759 5241856 5 Extended /dev/sdb2 10485760 20971519 5242880 83 Linux command (enter m for help) : wEnter w to save and q to exit without saving.The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: The device or resource is 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) is synchronizing disks.Copy the code
5. Set up BTRFS file system
1. Create a file system
Create a BTRFS file system, run this command after partitioning, and finally mount the disk.
mkfs.btrfs /dev/sdb2
Copy the code
You can also run the following command
mkfs -t btrfs /dev/sdb2
Copy the code
6. Mount a file system
1. Mount command mount
Then the BTRFS file system is created and mounted to the newly created data directory. Although the mount is successful, but only temporary effect, restart will drop the mounted hard disk. And volume label will display into letters and Numbers of a series of long string, like this s1k544y55fsa445dda44sd4545eff4 string. The reason is that Linux is still centered around the file system. There is no directory this concept, just convenient for everyone to understand, are used to call.
1.1. If you mount sDB2 using mount, you see SDB2 because a partition sdb1 has been created.
mount /dev/sdb2 /data
Copy the code
1.2. Unmount using umount
umount /dev/sdb2 /data
Copy the code
2. Write the fstab file
2.1. Write data to the /etc/fstab file and run the echo command to add data to the fstab file.
/dev/sdb can also be used to write UUID information
# first parameter second parameter third parameter fourth parameter fifth parameter
echo /dev/sdb1 /data btrfs defaults 0 0 >> /etc/fstab
echo /dev/sdb2 /data btrfs defaults 0 0 >> /etc/fstab
Copy the code
2.2. Run the blkid command to view the volume label or UUID
# blkid command
[root@cnwangk /]# blkid
/dev/sda5: UUID="d4708f44-beed-4a9b-bb11-94706e6c0cf5" TYPE="xfs"
/dev/sda1: UUID="7d56f743-a42d-42e2-876e-d839cc583fa7" TYPE="xfs"
/dev/sda2: UUID="953b1070-a13a-4b67-ac63-cc376c1dee8d" TYPE="xfs"
/dev/sda3: UUID="b075b6d0-4d37-4f18-ae59-bf380862b440" TYPE="swap"
/dev/sdb2: UUID="294c0c25-04be-4791-ab06-520c4283cb58" UUID_SUB="a8b7194a-a694-4a8a-bee1-0ab49821e6bb" TYPE="btrfs"
Copy the code
2.3. Of course, you can use the BTRFS command to check the uUID of the disk file
[root@cnwangk /]# btrfs filesystem show
Label: none uuid: 294c0c25-04be-4791-ab06-520c4283cb58
Total devices 1 FS bytes used 192.00KiB
devid 1 size 5.00GiB used 536.00MiB path /dev/sdb2
Copy the code
7. Write the configuration file permanently
1. Display the fstab configuration file
Note: Resolve the problem of rebooting the disk. Note That if parameters written into the configuration file are incorrect, the server may fail to start. Therefore, exercise caution when modifying parameters. It is best to make a backup before performing operations.
In my /ect/fstab configuration file, you can see that /dev/sdb2 is the BTRFS file system configuration for a new disk I tested.
# /etc/fstab
# Created by anaconda on Sun Jan 5 21:10:23 2020
#
# 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
#
UUID=d4708f44-beed-4a9b-bb11-94706e6c0cf5 / xfs defaults 0 0
UUID=7d56f743-a42d-42e2-876e-d839cc583fa7 /boot xfs defaults 0 0
UUID=953b1070-a13a-4b67-ac63-cc376c1dee8d /home xfs defaults 0 0
UUID=b075b6d0-4d37-4f18-ae59-bf380862b440 swap swap defaults 0 0
/dev/sdb2 /data btrfs defaults 0 0
Copy the code
2. Detailed explanation of some parameters
Write volume label information to /etc/fstab file (The default recommended format for Redhat7 series is XFS, as I’ve shown in this article)
- First parameter: /dev/sdb1 (path of the original disk partition)
- Second parameter: /data (new mount disk file path, Linux core is a file system, so it is the file path)
- Parameter 3: BTRFS (Mount disk file system format)
- The fourth argument: Defaults
- The fifth parameter: 0 0
/dev/sdb can also be used to write UUID information
# first parameter second parameter third parameter fourth parameter fifth parameter
echo /dev/sdb1 /data btrfs defaults 0 0 >> /etc/fstab
Copy the code
3. Modify the configuration file
You can edit the following files to add disk mounting information: vim /etc/fstab Write the information to the /etc/fstab configuration file. The XFS or BTRFS file system is recommended.
/dev/sdb2 /data ext4 defaults 0 0
/dev/sdb2 /data xfs defaults 0 0
/dev/sdb2 /data btrfs defaults 0 0
Copy the code
The command takes effect with restart: reboot or shutdown -r now
After the system restarts, you can see that the newly mounted disk /dev/sdb2 has taken effect and has been written into the fstab configuration file.
df -h
[root@cnwangk /]# df -hFile system capacity used Available Used % Mount point devtmpfs 907M 0 907M 0% /dev TMPFS 917M 0 917M 0% /dev/shm TMPFS 917M 9.3m 908M 2% /run TMPFS 917M 0 917M 0% /sys/fs/cgroup /dev/sda5 16G 7.1g 8.9g 45% / /dev/sdb2 5.0g 17M 4.5g 1% /data /dev/sda2 2.0g 34M 2.0g 2% /home /dev/sda1 197M 154M 43M 79% /boot tmpfs 184M 0 184M 0% /run/user/0Copy the code
8. Disk management
In fact, the above hard disk partition has used disk management commands to format partition MKFS, partition fdisk, belongs to the basic disk management. The most common df is used to check disk space usage. The mount and umount commands are used to mount and unmount disks. Mainly want to introduce the following third-party SSM management tools.
See this SSM not to be confused with the framework composition SSM (Spring Spring MVC Mybatis) in Javaweb.
1. SSM management tool
The SSM manages logical volumes. You can download the RPM package or install it online directly from the yum source.
# Install yum online
yum -y install system-storage-manager.noarch
Copy the code
After the installation is complete, run the SSM command to display the installation effect:
[root@cnwangk /]# ssm list----------------------------------------------------------------- Device Free Used Total Pool Mount point -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- / dev/fd0 4.00 KB/dev/sda 20.00 GB/dev/sda1 200.00 MB /boot /dev/sda2 1.95 GB /home/dev/sda3 1.95 GB SWAP /dev/sda4 1.00 KB /dev/sda5 15.90 GB / /dev/sdb 10.00 GB /dev/sdb1 1.00 MB /dev/sdb2 4.48 GB 536.00 MB 5.00 GB btrfs_sdb2 ----------------------------------------------------------------- ----------------------------------------------------- The Pool Type Devices Free informs the Total -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- btrfs_sdb2 BTRFS 1 GB 5.00 5.00 5.00 GB GB -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ----------------------------------------------------------------------------------- Volume Pool Volume size FS FS size Free Type Mount point ----------------------------------------------------------------------------------- btrfs_sdb2 Btrfs_sdb2 5.00 GB BTRFS 5.00 GB 5.00 GB BTRFS /data /dev/sda1 200.00 MB XFS 196.66 MB 42.79 MB /boot /dev/sda2 1.95 GB XFS 1.94 GB 1.91 GB /home/dev /sda5 15.90 GB XFS 15.89 GB 8.87 GB / -----------------------------------------------------------------------------------Copy the code
2, Linux built-in disk command
For example, to view the disk space status, add the -h parameter in the format of K, M, and G. Although df can be presented in a variety of forms, the one most commonly used in personal work is the one with the -h parameter used most frequently. The following uses the -h parameter as an example:
df -h
[root@cnwangk /]# df -hFile system capacity used Available Used % Mount point devtmpfs 907M 0 907M 0% /dev TMPFS 917M 0 917M 0% /dev/shm TMPFS 917M 9.3m 908M 2% /run TMPFS 917M 0 917M 0% /sys/fs/cgroup /dev/sda5 16G 7.1g 8.9g 45% / /dev/sdb2 5.0g 17M 4.5g 1% /data /dev/sda2 2.0g 34M 2.0g 2% /home /dev/sda1 197M 154M 43M 79% /boot tmpfs 184M 0 184M 0% /run/user/0Copy the code
The df command is followed by the -a parameter to display all file system disk usage. The output is not posted here, the display is too long.
df -ah
Copy the code
The above is all the content of this article, I hope to help you with your work. Feel good, take out your one button three link. If I feel that the summary is not in place, I also hope to leave your valuable opinions. I will adjust and optimize the article.
Original is not easy, reprint also please indicate the source, respect the original. This article will be uploaded to Gitee or Github and VX from time to time.
Finally give the mind map, make do with it, just have an impression!