Creating and Mounting a File System
Scenarios
After the logical volume is created, you need to create a file system on the logical volume and mount the file system on the corresponding directory. This section shows how to create an ext4 file system on a logical volume and mount the file system on /Data1.
Procedure
- Log in to the ECS as user root.
- Run the following command to create a file system:
mkfs.File system format Logical volume path
In this example, run the following command:
mkfs.ext4 /dev/vgdata/lvdata1
Information similar to the following is displayed:
[root@ecs-lvmtest ~]# mkfs.ext4 /dev/vgdata/lvdata1 mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 983040 inodes, 3932160 blocks 196608 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2151677952 120 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done
- Run the following command to create a mounting directory:
mkdir Mounting directory
In this example, run the following command:
mkdir /Data1
- Run the following command to mount the file system on the directory:
mount Logical volume path Mounting directory
In this example, run the following command:
mount /dev/vgdata/lvdata1 /Data1
- Run the following command to query the file system mounting information:
mount | grep Mounting directory
In this example, run the following command:
mount | grep /Data1
Information similar to the following is displayed:
[root@ecs-lvmtest ~]# mount | grep /Data1 /dev/mapper/vgdata-lvdata1 on /Data1 type ext4 (rw,relatime,data=ordered)
In the command output, dev/mapper/vgdata-lvdata1 indicates the file system path. Take note of this path, which will be used in 6.
- Perform the following operations to enable automatic mounting of the file system at the system start:
If this is not configured, you need to manually mount the file system every time the ECS is restarted.
- Run the following command to query the file system UUID:
In this example, run the following command to query the UUID of dev/mapper/vgdata-lvdata1:
blkid /dev/mapper/vgdata-lvdata1
Information similar to the following is displayed:
[root@ecs-lvmtest ~]# blkid /dev/mapper/vgdata-lvdata1 /dev/mapper/vgdata-lvdata1: UUID="c6a243ce-5150-41ac-8816-39db54d1a4b8" TYPE="ext4"
In the command output, the UUID is c6a243ce-5150-41ac-8816-39db54d1a4b8.
- Run the following command to open the /etc/fstab file:
vi /etc/fstab
Information similar to the following is displayed:[root@ecs-lvmtest ~]# vi /etc/fstab # # /etc/fstab # Created by anaconda on Tue Nov 7 14:28:26 2017 # # 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=27f9be47-838b-4155-b20b-e4c5e013cdf3 / ext4 defaults 1 1 UUID=2b2000b1-f926-4b6b-ade8-695ee244a901 /boot ext4 defaults 1 2
- Press i to enter editing mode.
- Move the cursor to the end of the file and press Enter. Then add the following information:
UUID=c6a243ce-5150-41ac-8816-39db54d1a4b8 /Data1 ext4 defaults 0 0
The file content is described as follows:
- Column 1: indicates the UUID. Enter the UUID queried in 1.
- Column 2: indicates the file system's mounting directory. Enter mounting directory /Data1 created in 3.
- Column 3: indicates the file system format. Enter file system format ext4 configured in 2.
- Column 4: indicates the mounting option. In this example, defaults is used.
- Column 5: indicates the backup option. Enter either 1 (the system automatically backs up the file system) or 0 (does not back up the file system). In this example, 0 is used.
- Column 6: indicates the scanning option. Enter either 1 (the system automatically scans the file system at system start) or 0 (does not scan the file system). In this example, 0 is used.
- Press Esc, enter :wq!, and press Enter.
The system saves the modifications and exits the vi editor.
- Run the following command to query the file system UUID:
- Perform the following operations to verify automatic mounting:
- Run the following command to unmount a file system:
In this example, run the following command:
umount /dev/vgdata/lvdata1
- Run the following command to reload all the content in the /etc/fstab file:
mount -a
- Run the following command to query the file system mounting information:
mount | grep Mounting directory
In this example, run the following command:
mount | grep /Data1
If information similar to the following is displayed, the automatic mounting function takes effect:
[root@ecs-lvmtest ~]# mount | grep /Data1 /dev/mapper/vgdata-lvdata1 on /Data1 type ext4 (rw,relatime,data=ordered)
- Run the following command to unmount a file system:
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.