Linux format and Mount data disks
This article describes how to create a single partition data disk with a new data disk and mount the file system. This article applies only to fdisk
partitioning operations on a data disk that is less than 2 terabytes using a command. If you need to partition a data disk larger than 2 TB, refer to another blog post.
You can also configure the data disk in multiple partitions, depending on your business needs. It is recommended to use the tool that comes with the system for partitioning operations.
Operation Notice
The device name of the data disk is assigned by default by the system and is sequentially arranged from/dev/xvdb, and the distribution range includes/dev/xvdb?/dev/xvdz.
Operation Steps
In this example, we create a single partition data disk with a new three GB data disk (device name/dev/xvdb) and mount a ext3 file system. The instance used is an I/O optimization instance, and the operating system is CentOS 6.8.
Remote Connection instance.
Run the fdisk -l
command to see if the instance has a data disk. If you do not see the/DEV/VDB after executing the command, it means that your instance does not have a data disk, and you do not need to format the data disk, please ignore the following article.
If your data disk displays DEV/XVD, it indicates that you are using a non-I/O optimized instance.
Which is any of the letters of A?Z.
Create a single partition data disk and execute the following command in turn:
Run fdisk /dev/vdb
: Partition the data disk.
Enter n
and press ENTER: Create a new partition.
Enter p
and press ENTER: Select Primary partition. Because a single partition data disk is created, only the primary partition needs to be created.
Note: If you are creating more than 4 partitions, you should create at least one extended partition, which is selected e
.
Enter the partition number and press ENTER. Because only one partition is created here, you can enter 1.
Enter the first available sector number: Press ENTER to take the default value of 1.
Enter the last sector number: Because only one partition is created here, press ENTER to take the default value.
Enter wq
and press ENTER to start the partition.
-
[[email protected] ~]# Fdisk/dev/vdbdevice contains neither a valid DOS Partition table, nor Sun, SGI or OSF disklabelbuilding a new DOS Disklabel with disk identifier 0X5F46A8A2. Changes'll remain in memory only, until the decide to write them. After that, of course, the previous content won ' t is recoverable. Warning:invalid flag 0x0000 of partition Table 4 would be a corrected by W (rite) warning:dos-compatible mode is deprecated. It ' s strongly recommended toswitch off the mode (command ' C ') and change display units tosectors (Command ' U '). Command (M for help): Ncommand actione EXTENDEDP Primary partition (1-4) ppartition number (1-4): 1First cylinder (1-41610, Default 1): 1Last cylinder, +cylinders or +size{k,m,g} (1-41610, default 41610): Using default value 41610Command (M for H ELP): Wqthe partition table has been altered! Calling IOCTL () to re-read partition table. Syncing disks.
To view the new partition: Run the command fdisk -l
. If the following information appears, the new partition/DEV/VDB1 has been successfully created.
[Email protected] ~]# fdisk-Ldisk/dev/vda:42.9GB,42949672960bytes255Heads theSectors/track,5221cylindersunits= Cylinders of16065* +=8225280bytessector size (logical/physical): +Bytes/ +Bytesi/o Size (minimum/optimal): +Bytes/ +bytesdisk Identifier:0x00053156Device Boot Start End Blocks Id System/DEV/VDA1 *1 5222 41942016 theLinuxdisk/DEV/VDB:21.5GB,21474836480bytes -Heads theSectors/track,41610cylindersunits= Cylinders of1008* +=516096bytessector size (logical/physical): +Bytes/ +Bytesi/o Size (minimum/optimal): +Bytes/ +bytesdisk Identifier:0X5F46A8A2Device Boot Start End Blocks Id System/dev/vdb11 41610 20971408+ theLinux
Create a file system on the new partition: Run the command mkfs.ext3 /dev/vdb1
.
This example creates a Ext3 file system. You can also choose to create additional file systems for your needs, for example, if you need to share files between Linux, Windows, and MAC systems, you can use Mkfs.vfat to create Vfat file systems. The time it takes to create the file system depends on the data disk size. [[Email protected]~]# mkfs.ext3/dev/VDB1MKE2FS1.41. A( --may- .) Filesystem label=OS type:linuxblock Size=4096(log=2) Fragment size=4096(log=2) Stride=0blocks, Stripe width=0blocks1310720Inodes,5242852blocks262142Blocks (5.00%) reserved forThe Super Userfirst data Block=0Maximum filesystem blocks=4294967296 theblock Groups32768Blocks per group,32768fragments per group8192inodes per groupsuperblock backups stored on blocks:32768,98304,163840,229376,294912,819200,884736,1605632,2654208,4096000Writing inode tables:donecreating Journal (32768blocks): donewriting superblocks and filesystem accounting information:donethis filesystem would be automatically checkedEveryPanax NotoginsengMounts or theDays, whichever comes first. Use Tune2fs-c or-i toOverride.
(recommended) Backup Etc/fstab: Run the command cp /etc/fstab /etc/fstab.bak
.
Write new partition information to/etc/fstab: Run command echo /dev/vdb1 /mnt ext3 defaults 0 0 >> /etc/fstab
.
Note: Ubuntu 12.04 does not support barrier, so the correct command for the system is: echo ‘/dev/vdb1 /mnt ext3 barrier=0 0 0‘ >> /etc/fstab
.
If you need to mount the data disk separately to a folder, such as a separate Web page, replace the above command/mnt with the desired mount point path.
To view the new partition information in/etc/fstab: Run the command cat /etc/fstab
.
[Email protected] ~]# cat/etc/fstab##/etc/fstab# Created by Anaconda on Thu Feb at -: -: A .# # Accessible filesystems, by reference, is maintained under'/dev/disk'# See mans pages Fstab (5), Findfs (8), Mount (8) and/or Blkid (8) forMore Info#uuid=3d083579-f5d9-4df5-9347-8D27925805D4/EXT4 defaults1 1Tmpfs/DEV/SHM TMPFS Defaults0 0devpts/dev/pts devpts gid=5, mode=620 0 0Sysfs/sys SYSFS Defaults0 0proc/PROC proc Defaults0 0/DEV/VDB1/MNT ext3 Defaults0 0
Mount file system: Run command mount /dev/vdb1 /mnt
.
View Current disk space and usage: Run the command df -h
. If the information for the new file system appears, the mount is successful and the new file system can be used.
After the mount operation is complete, you do not need to restart the instance to start using the new file system.
[[email protected] ~]# mount/dev/vdb1/~]# DF-hfilesystem Size used Availuse% mounted on 6%/00/dev/shm1/mnt
Linux format and Mount data disks