Home  >  Article  >  Operation and Maintenance  >  Formatting the Linux system partition of the Alibaba Cloud host and mounting the data disk

Formatting the Linux system partition of the Alibaba Cloud host and mounting the data disk

缘亦
缘亦Original
2021-09-09 22:53:111942browse

In addition to the free system disk in Alibaba Cloud, the second cloud disk purchased is not automatically mounted by default and needs to be manually configured and mounted.

Use [Management Terminal] or remote connection tool, enter the user name root and password to log in to the Linux system.

1. Run the fdisk -l command to view the data disk. Before partitioning and formatting the data disk, you cannot see the data disk using the "df -h" command. You can use the "fdisk -l" command to view it.

After executing the command, if /dev/vdb does not exist, it means there is no data disk. Confirm whether the data disk is mounted.

2. Execute the following commands in sequence to create a single-partition data disk:

(1) Run fdisk -u /dev/vdb: partition data disk.

(2) Enter p: Check the partition status of the data disk. In this example, the data disk has no partitions.

(3) Enter n: Create a new partition.

(4) Enter p: Select the partition type as the primary partition.

Description In this example, a single-partition data disk is created, so only the primary partition needs to be created. If you want to create more than four partitions, you should create at least one extended partition, i.e. select e (extended).

(5) Enter the partition number and press Enter. In this example, only one partition is created, enter 1.

(6) Enter the first available sector number: press Enter to adopt the default value of 2048.

(7) Enter the last sector number: This example only creates one partition, press Enter to adopt the default value.

(8) Enter p: View the planned partitioning of the data disk.

(9) Enter w: start partitioning and exit after partitioning.

[root@ecshost~ ]# fdisk -u /dev/vdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x3e60020e.
 
Command (m for help): p
Disk /dev/vdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x3e60020e
Device Boot Start End Blocks Id System
 
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039):
Using default value 41943039
Partition 1 of type Linux and of size 20 GiB is set
 
Command (m for help): p
 
Disk /dev/vdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x3e60020e
Device Boot Start End Blocks Id System
/dev/vdb1 2048 41943039 20970496 83 Linux
 
Command (m for help): w
The partition table has been altered!
 
Calling ioctl() to re-read partition table.
Syncing disks.

3. Run the command fdisk -lu /dev/vdb to view the new partition.

If the following information appears, it means that the new partition /dev/vdb1 is created successfully.

[root@ecshost~ ]# fdisk -lu /dev/vdb
 
Disk /dev/vdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x3e60020e
 
Device Boot Start End Blocks Id System
/dev/vdb1 2048 41943039 20970496 83 Linux

4. Run the command mkfs.ext4 /dev/vdb1 to create a file system on the new partition.

In this example, create an ext4 file system. You can also choose to create other file systems according to your own needs. For example: if you need to share files between Linux, Windows and Mac systems, you can use mkfs.vfat to create a VFAT file system.

Note: The time required to create a file system depends on the size of the data disk.

[root@ecshost~ ]# mkfs.ext4 /dev/vdb1
 
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
1310720 inodes, 5242624 blocks
262131 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2153775104
160 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,
4096000
 
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

5. (Recommended) Run the command cp /etc/fstab /etc/fstab.bak to back up the etc/fstab file.

6. Run the command echo /dev/vdb1 /data0 ext4 defaults 0 0 >> /etc/fstab to write new partition information to /etc/fstab.

Note: The Ubuntu 12.04 system does not support barriers. You need to run the command echo '/dev/vdb1 /data0 ext4 barrier=0 0 0' >> /etc/fstab.

If you want to mount the data disk to a folder separately, for example, to store web pages alone, replace /data0 in the command with the required mount point path.

7. Run the command cat /etc/fstab to view the new partition information in /etc/fstab.

[root@ecshost~ ]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Wed Dec 12 07:53:08 2018
#
# 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=d67c3b17-255b-4687-be04-f29190d37396 / ext4 defaults 1 1
/dev/vdb1 /mnt ext4 defaults 0 0

8. Run the command mount /dev/vdb1 /data0 to mount the file system.

9. Run the command df -h to check the current disk space and usage.

The information about the new file system appears, indicating that the mounting is successful.

<div><br class="Apple-interchange-newline">[root@ecshost~ ]# df -h

Filesystem Size Used Avail Use% Mounted on
/dev/vda1 40G 1.6G 36G 5% /
devtmpfs 234M 0 234M 0% /dev
tmpfs 244M 0 244M 0% /dev/shm
tmpfs 244M 484K 244M 1% /run
tmpfs 244M 0 244M 0% /sys/fs/cgroup
tmpfs 49M 0 49M 0% /run/user/0
/dev/vdb1 20G 45M 19G 1% /mnt</div>
12345678910    [root@ecshost~ ]# df -h Filesystem Size Used Avail Use% Mounted on/dev/vda1 40G 1.6G 36G 5% /devtmpfs 234M 0 234M 0% /devtmpfs 244M 0 244M 0% /dev/shmtmpfs 244M 484K 244M 1% /runtmpfs 244M 0 244M 0% /sys/fs/cgrouptmpfs 49M 0 49M 0% /run/user/0/dev/vdb1 20G 45M 19G 1% /mnt

10. Finally reboot, restart the server.

Recommended: "linux video tutorial"

The above is the detailed content of Formatting the Linux system partition of the Alibaba Cloud host and mounting the data disk. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn