In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "what is the method of disk management and mounting hard disk under linux". In daily operation, I believe that many people have doubts about the method of disk management and mounting hard disk under linux. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "what is the method of disk management and mounting hard disk under linux". Next, please follow the editor to study!
This is probably the most practical linux hard disk mount article introduced so far, in more detail. Due to work reasons, usually use more. The main purpose is to let more people know that it is not so difficult to mount a disk under linux.
There are several common file systems, the old file system ext file system (ext2, ext3, ext4).
In the Redhat7 series, an excellent xfs file system is recommended, which has surpassed the ext file system in performance. XFS file system is a file system developed by Silicon Valley Graphics Company (Silicon Graphic Inc, referred to as 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 as well as robust.
There is also a btrfs (B-tree file system usually pronounced as Buffer FS, Better FS, B-tree FS) file system is also excellent, Redhat7 installation comes with.
Btrfs has many features. For example: write snapshot, snapshot snapshot, built-in RAID (often referred to as disk array), subvolume (subvolume), the core idea is design.
Fault tolerance, repair, and ease of management. The maximum capacity volume for btrfs is 16EB, and the single maximum file is 16EB.
Note: the whole process of this article is to install the selection language is the simplified Chinese version, so do not be surprised to see the Chinese character display.
With a picture at the beginning, the article depends on compilation. It's a joke, it's just to amuse everyone. The following picture has already pointed out the core content of this article.
Suggestion: for testing, you can use a virtual machine with linux (Redhat series or Ubuntu environment) to test.
1. Check the partition of the system
Fdisk parameter description
Delete the existing hard disk partition, and you will be prompted which serial number needs to be deleted.
Delete partition: d
New partition: n
View partition information: P
Save partition change information: W
Do not save and exit: Q
Get help information: M
1. List the partition table
List the partition table, and you can see from the options listed below that the original disk / dev/sda:21.5 GB was allocated at the initial installation of the linux operating system. Another disk is my new disk sdb, which is used for testing and demonstration.
Fidsk-l [root@cnwangk /] # fdisk-l disk / dev/sda:21.5 GB, 21474836480 bytes 41943040 sector Units = sector of 1 * 512 = 512 bytes sector size (logical / physical): 512byte / 512byte I size (min / best): 512byte / 512byte 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 860364841943039 16669696 5 Extended/dev/sda5 860569641943039 16668672 83 Linux disk / dev/sdb:10.7 GB 10737418240 bytes 20971520 sector Units = sector of 1 * 512 = 512 bytes sector size (logical / physical): 512byte / 512byte I Zero size (min / optimal): 512byte / 512byte disk label type: dos disk identifier: 0x95df3b22 device Boot Start End Blocks Id System/dev/sdb2 10485760 20971519 5242880 83 Linux
Enter the fdisk command directly, and the Chinese version will prompt for help information and how to use it.
Fdisk [options] change partition table # such as new disk sdbfdisk / dev/sdbfdisk [options]-l list partition table fdisk-s give partition size (number of blocks)
Second, establish linux file system
1. Xfs file system
As shown below, I will create a new xfs file system, pointing to a new disk file path / dev/sdb. It is also the default recommended format for Redhat7 series.
Mkfs.xfs / dev/sdb
To make a simple note: the xfs file system provides a backup partition tool xfsdump for users to use. The advantage is that users can backup the data on the xfs file system without the help of third-party software. The backup process is as follows:
Xfsdump / backup/dump_sdc1 / sdc1
2. Btrfs file system
As shown below, I will create a new btrfs file system, pointing to a new disk file path / dev/sdb, and finally demonstrate the configuration of the btrfs file system.
Mkfs.btrfs / dev/sdb
3. Ext file system
Before Redhat6 and before, the ext file system was used. Later, the xfs file system is recommended in Series 7.
Mkfs.ext4 / dev/sdb
3. Create a path to mount
1. Create a mounted file data
Use the mkdir command to create a data directory for subsequent mounts of the new disks.
Mkdir / data
Check the created mount path data, which is initially empty
Ls / data
2. Use disk
Write a simple shell script as a demonstration
Echo-e "echo" hello linux "\ necho" create btrfs filesystem "> > / data/data.sh
After writing a simple shell script, the test views and executes the script
# check the file under the data disk again [root@cnwangk /] # ls / data/data.shsh / data/data.sh# run the script [root@cnwangk /] # sh / data/data.sh hello linuxcreate btrfs filesystem
You can see from the above that a basic disk management will lead to the use of some basic commands, such as ls, mkdir, echo, and so on. The audience of this article needs to master some basic command knowledge of linux. Of course, you can see this article, which also shows that you still have some foundation.
4. Use fdisk to partition / dev/sdb
1. Partition command fdisk
Use fdisk to partition the new disk / dev/sdb. I previously demonstrated that I had used primary partition 2, but now the demonstration is a logical extension partition, using the parameter e.
New partition: n
New primary partition: P
Extended partition: e
Note: you can customize the size, or you can enter using the default size and sector.
Fdisk / dev/sdb [root@cnwangk /] # fdisk / dev/sdb Welcome to fdisk (util-linux 2.23.2). The changes remain in memory until you decide to write them to disk. Think twice before using the write command. Command (enter m for help): n # new partition, p primary partition, e extended partition Partition type: P primary (1 primary, 0 extended, 3 free) e extendedSelect (default p): e partition number (1 primary 3 extended 4, default 1): 1 starting sector (2048-20971519, default is 2048): the default value 2048Last sector will be used, + sector or + size {K or G} (2048-10485759) Default is 10485759): use the default value 10485759 partition 1 has been set to Extended type, size set to 5 GiB command (enter m for help): P # view unsaved partition information disk / dev/sdb:10.7 GB with parameter p at this time, 10737418240 bytes 20971520 sector Units = sector of 1 * 512 = 512 bytes sector size (logical / physical): 512byte / 512byte I size (min / best): 512byte / 512byte disk label type: dos disk identifier: 0x95df3b22# view new partition device information device 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): W # enter w parameter to save Enter 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: busy equipment or resources. The kernel still uses the old table. The new table will be used atthe next reboot or after you run partprobe (8) or kpartx (8) is synchronizing the disk.
5. Establish btrfs file system
1. Establish a file system
Create a new btrfs file system, execute this command after determining the partition, and finally mount the disk.
Mkfs.btrfs / dev/sdb2
You can also use the following command
Mkfs-t btrfs / dev/sdb2
Mount the file system
1. Mount the command mount
Then the btrfs file system is established above, and then mounted to the newly created data directory. Although the mount is successful, it is only temporarily effective. Rebooting will drop the disk and mount the hard disk. The volume label will also be displayed as a long string of letters plus numbers, similar to this kind of s1k544y55fsa445dda44sd4545eff4 string. The reason is that Linux still takes the file system as the core. There is no concept of catalogue, it is just easy for everyone to understand, and we are used to calling it this way.
1.1.Using mount to mount, you will see sdb2 because a partition sdb1 has been created before.
Mount / dev/sdb2 / data
1.2.Uninstall using umount
Umount / dev/sdb2 / data
2. Write to fstab file
2.1. permanent entry into force needs to be written to the / etc/fstab file, and the data is appended to the fstab file using the echo command.
# the first parameter / dev/sdb can also be written into the UUID information here # the first parameter, the second parameter, the third parameter, the fourth parameter, the fifth parameter echo / dev/sdb1 / data btrfs defaults 00 > > / etc/fstabecho / dev/sdb2 / data btrfs defaults 00 > > / etc/fstab
Enter 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 "
2.3.Of course, you can check the uuid of the disk file using the command that comes with btrfs.
[root@cnwangk /] # btrfs filesystem showLabel: 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
7. Permanent write to configuration file
1. Configuration file fstab display
Note: resolve the problem of restarting and dropping the disk. It is important to emphasize that once there is an error exception in the parameters written to the configuration file, there is a high probability that the server will not be able to start, so you should be careful when modifying it. It is best to make a backup before doing the operation.
As shown in my / ect/fstab configuration file, you can see that / dev/sdb2 is the partitioned configuration of the new disk I tested, using the file system format of btrfs.
# / 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 0UUID=7d56f743-a42d-42e2-876e-d839cc583fa7 / boot xfs defaults 0 0UUID=953b1070-a13a-4b67-ac63-cc376c1dee8d / home xfs defaults 0 0UUID=b075b6d0-4d37-4f18-ae59-bf380862b440 swap swap Defaults 0 0/dev/sdb2 / data btrfs defaults 0 0
2. Detailed explanation of some parameters.
Write the volume label information to the / etc/fstab file (the default recommended format of the Redhat7 series is xfs, as can be seen from the display given in my article)
First parameter: / dev/sdb1 (original disk partition path)
The second parameter: / data (the newly created mount disk file path, the Linux core is a file system, so it is a file path)
The third parameter: btrfs (mounted disk file system format)
The fourth parameter: defaults
Fifth parameter: 0
# the first parameter / dev/sdb can also be written into UUID information here.
# first parameter, second parameter, third parameter, fourth parameter, fifth parameter.
Echo / dev/sdb1 / data btrfs defaults 0 0 > > / etc/fstab
3. Modify the configuration file
You can directly edit the file and add disk mount information: vim / etc/fstab
Write to the / etc/fstab configuration file. Xfs or btrfs are recommended for the file system, depending on the actual situation:
/ dev/sdb2 / data ext4 defaults 0 0/dev/sdb2 / data xfs defaults 0 0/dev/sdb2 / data btrfs defaults 0 0
Restart takes effect: reboot or shutdown-r now
Verify that the mount is successful, and after rebooting the system, you can see that my newly mounted disk / dev/sdb2 has taken effect and written to the fstab configuration file.
Df-h [root@cnwangk /] # df-h File system capacity used available mount point devtmpfs 907M 0907m 0% / devtmpfs 917M 0917M 0% / dev/shmtmpfs 917M 9.3M 908m 2% / runtmpfs 917M 0917M 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% / boottmpfs 184M 0 184M 0% / run/user/0
VIII. Disk management
In fact, the above partition of the hard disk has been used to format partition mkfs, partition fdisk, belongs to the basic disk management. There is also the most commonly used df, which is used to view disk space consumption; the mount and umount commands mount and unmount the disk. What I mainly want to introduce are the following third-party ssm management tools.
Don't be confused with the framework composition ssm (Spring Springmvc Mybatis) in Javaweb when you see this ssm.
1. Ssm management tools
Ssm (System Storage Manager) manages logical volumes. There is no installation by default. You need to install it manually, download the rpm package or install it directly from the yum source online:
# provide yum online installation method yum-y install system-storage-manager.noarch
After installation, use the ssm command as follows to show the 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- -Pool Type Devices Free Used Total- -btrfs_sdb2 btrfs 1 5.00 GB 5.00 GB 5.00 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 /-
2. Disk commands that come with linux
For example, check the disk space status, plus the parameter-h is displayed in the form of (K, M, G). Although df can be presented in many forms, the-h parameter is most frequently used in personal work. The following is shown with the parameter-h as an example:
Df-h [root@cnwangk /] # df-h File system capacity used available mount point devtmpfs 907M 0907m 0% / devtmpfs 917M 0917M 0% / dev/shmtmpfs 917M 9.3M 908m 2% / runtmpfs 917M 0917M 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% / boottmpfs 184M 0 184M 0% / run/user/0
Add the-a parameter after the df command to show all file system disk usage, so the output is not posted here, and the display is too long.
At this point, the study on "what is the method of disk management and mounting hard disk under linux" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.