RHCSA test preparation --General flow until using a physical drive as a data storage area on Linux OS (Basic)

RHCSA test preparation --General flow until using a physical drive as a data storage area on Linux OS (Basic)

Introduction On the Linux OS, there are commands for various disk operations, depending on the distribution.

In the case of Windows OS, it seems that the operation to the disk is a very high hurdle for Linux beginners because it is easy to do most of the work from "disk management". image.png

In this article, I will introduce the work flow and the commands that appear in each process, assuming a scenario of "adding one HDD drive to a computer and saving data in that drive".

Basic flow Following the following flow, this article will introduce the work of commands.
  1. Physically mount the drive
  2. Make sure the physical drive is recognized at the hardware level
  3. Make sure the physical drive is recognized at the OS level
  4. Create a partition on the physical drive
  5. Format the partition created above
  6. Mount the partition formatted above to a specific directory on the OS
  7. Confirm that the corresponding file system can be used even after restarting.

1. Physically mount the drive This is the process of physically connecting to the housing. I think that there are connection standards such as USB, SATA, SCSI, SAS, etc., but please connect the one supported by your chassis. The connection method and the number of devices that can be installed should be checked in the product specification guide.

This is an excerpt from an article about a model called Dell OptiPlex 7050. OptiPlex 7050 Small Form Factor-Owner's Manual

image.png

2. Make sure the physical drive is recognized at the hardware level Speaking of this, it means physically connecting the HDD or SSD to an interface such as USB / SATA / SAS, not a Linux-specific operation. In the case of a physical environment, make sure that the drive is recognized on the BIOS screen.

In my environment, Linux is running on a virtual machine configured on the virtual environment, so in the figure below, it is confirmed that 3 virtual hard drives are installed as "VMware Virtual SCSI Hard Drive (0: x)". It's done.

This time, we will work on saving data for "VMware Virtual SCSI Hard Drive 0: 1". image.png The appearance of the BIOS screen will change depending on the product you have, so if you don't know how to check it, you can ask the support of the product vendor or rely on Google image search.

3. Confirm that the physical drive is recognized at the OS level The major way to determine if the OS can recognize the physical drive is to see if the "device file" of the physical drive exists under "/ dev".
ls -la /dev | grep sd 
Commentary/A command to search for files and directories that contain the letters sd under dev

In the figure below, three hard drives are recognized. The image is as follows. LinuxOS L [HDD # 1 sda] "Partition sda1 / Partition sda2 / Partition sda3" L [HDD # 2 sdb] "No partition" L [HDD # 3 sdc] "No partition" image.png Also, the "lsblk" command makes it easier to understand the interaction between drives and partitions from a hierarchical perspective as shown above. I'll say it after writing it, but this is easier to check than the above method. image.png The description starting with this sd is an identifier that is usually assigned to a drive that is communicating with a connection standard such as SCSI / SATA / USB. There are other patterns, but please refer to the following page for them. [Chapter 3 Overview of Persistent Naming Attributes --Red Hat](https://access.redhat.com/documentation/ja-jp/red_hat_enterprise_linux/8/html/managing_storage_devices/assembly_overview-of-persistent-naming-attributes_managing- storage-devices) [Device File-Wikipedia](https://ja.wikipedia.org/wiki/%E3%83%87%E3%83%90%E3%82%A4%E3%82%B9%E3%83%95% E3% 82% A1% E3% 82% A4% E3% 83% AB) fdisk --LinuC Aegis

4. Create a partition on the physical drive To place data on a physical drive, you need to partition it and specify a format for storing data on it.

There are several partitioning commands in the Linux OS. The following are typical ones. [Fdisk] command-create and delete partition [Gdisk] command-Create and delete GPT-compatible partition [Parted] command-create and delete GPT-compatible partition

At this point, many beginners are wondering "Which one should I use?", But at the time of posting this article, "parted" is a good choice. The reason is that drives like HDDs and SSDs are now treated as either MBR format or GPT format and connected to the system. fdisk is a dedicated command for MBR format drives. gdisk is a dedicated command for GPT format drives. parted supports both. I personally recommend parted because parted is the latest command and there are many turns.

From here, I will illustrate the flow up to creating a partition using parted. First, in the figure below, I reconfirmed the recognition of the current drive with lsblk, and confirmed that the second drive confirmed by the BIOS was recognized as "sdb".

parted /dev/sdb print
Explanation Command to check the drive information of sdb,Also available by replacing sdb with another device

image.png If you look at the third line from the bottom, it says "Partition Table: unknown". This is an uninitialized drive. First, perform initialization processing in GPT format. image.png In the above figure, initialization is completed in GPT format with "parted / dev / sdb mklabel". In the second line from the top of the above figure, "New disk label type?", Press the tab key twice to display a list of formats that can be specified, which is convenient. In the 4th line from the bottom of the above figure, the GPT characters could be confirmed by the "print" command executed again.

Then create a partition. Work with the following command. image.png

This time, by ending with mkpart, I entered the partition name / type / size specification interactively. When asked for the format type, you can check the type as shown above by pressing the tab key twice. To specify the size, enter the partition start position and end position on the drive, but enter the start position in% and specify the end position as a unit. You can also specify the unit for the start position, but if you set this as the start position from 0, the following warning will be displayed. image.png A search for this error message "Warning: The resulting partition is not properly aligned for best performance." Has resulted in many reports. This is a warning to specify the sector start position with the recently introduced 4K drive in mind. This article was used as a reference as the root cause. [What to do if parted gives a performance warning](https://www.xmisao.com/2013/09/27/parted-warning-the-resulting-partition-is-not-properly-aligned-for -best-performance.html) This time, we will introduce a general drive expansion method, so we will not pursue this point in depth.

The simplest way to avoid the above error is to specify the starting position at 0%. Note that the 0% specification cannot be used when creating the second and subsequent partitions on one drive. In this case, enter a number that is close to the size of the previous partition. In the figure below, the second partition is created and the start position is specified as "10.1G". The layout is beautiful. image.png

At this point, the rest is formatting and mounting. Proceed to the next step.

5. Format the partition created above Formatting itself is not as difficult as creating a partition. In the figure below, sdb1 and sdb2 are formatted with ext4. ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/680306/5acfa4a2-09cb-564e-2c8d-d39994f9bc44.png)

mkfs. ○○ format command. The corresponding file system name is entered in ○○. It was confirmed that the description of ext4 was added to the two partitions. image.png

6. Mount the partition formatted above to a specific directory on the OS The last is mounting the partition. In the case of Windows OS, each partition has a drive character, and each is the root of each drive character. For Linux OS, the user mounts the partition in any directory under /.

This time, I created directories named test01 and test02 under / mnt. image.png

In the figure below, mount is executed and lsblk is used to confirm that the two partitions are mounted in the directories under / mnt. image.png

You can now save the file. I created empty files named rhcsa and rhce in each directory. image.png

7. Confirm that the corresponding file system can be used even after restarting Up to this point, I've done a lot of work from adding more drives to making it possible to save files, but in reality, the file system is unmounted when it is restarted. Therefore, the rhcsa and rhce files mentioned earlier cannot be confirmed in the figure below. ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/680306/5d48facc-eb86-dbf5-eab0-0f08266a5e97.png)

After remounting, I checked with ls and confirmed that the file was alive. image.png

In order for a particular file system to be automatically mounted in the specified directory after a reboot, it must be listed in a configuration file called "/ etc / fstab".

Added lines for automatic mounting to the 2nd and 3rd lines from the bottom in the figure below. (Edited in vi / etc / fstab.) On the far left is the partition identifier called UUID that sdb1 and sdb2 have. After that, the mount specification location and file system information will be posted, but please refer to the following for the description rules. Linux bean knowledge 175 "/ etc / fstab"-LinuC The meaning of the numbers in / etc / fstab-@IT image.png

You can check the UUID for each partition with lsblk -f. image.png

That's all for the work. After that, the file system specified by fstab will be mounted automatically even if you reboot.

Bonus: I'm afraid of editing errors in fstab If there is a problem with the description, the following screen will be displayed when the OS starts. At first glance, you will be completely panicked. ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/680306/0c12587e-49ad-8ea2-041b-041825ad0742.png)

If it is a reboot after editing fstab, do not panic and check the fstab file on the CLI screen. At the first prompt, you will be able to type the command after entering the root password.

If you check with cat / etc / fstab, do you know what is wrong? image.png

In the above figure, I deleted "UUID =" from the beginning of the second line from the bottom and tried to cause a pseudo failure. You can also modify with the vi command from this screen. Here is the state after the correction. image.png

After that, save it and restart it.

Recommended Posts

RHCSA test preparation --General flow until using a physical drive as a data storage area on Linux OS (Basic)
RHCSA test preparation --General flow until using a physical drive as a data storage area on Linux OS (Basic)
MySQL installation on Aws Linux 2 and test data preparation
RHCSA Test Preparation --Storage Function VDO Overview and Usage (Basic)