Home >Database >Mysql Tutorial >How to mount Linux system disk?
For Linux systems, the methods of mounting disks are actually similar, so this article takes the CentOS system as an example to introduce the Linux system disk mounting method, most of the previous The content comes from Tianyiyun’s forum.
1.Check the disk status
Use the command fdisk -l # to list all disk information
[root@qxyw ~]# fdisk -l Disk /dev/xvda: 42.9 GB, 42949672960 bytes255 heads, 63 sectors/track, 5221 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x0008a9a5Device Boot Start End Blocks Id System/dev/xvda1 1 523 4194304 82 Linux swap / Solaris Partition 1 does not end on cylinder boundary./dev/xvda2 * 523 5222 37747712 83 Linux Disk /dev/xvde: 322.1 GB, 322122547200 bytes255 heads, 63 sectors/track, 39162 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000
2. Create a partition
fdisk /dev/xvde # Partition the xvde hard disk
n # Create a new partition
p # Create a primary partition (e is the extended partition)
1 # 1 means the first A primary partition
Enter # Start partitioning from the first cylinder
Enter # Indicates that the entire xvde is written into the first partition (if you need to divide the sdb into multiple partitions, enter + partition size at this time)
P # Check the created partition
w # Save and exit
[root@qxyw ~]# fdisk /dev/xvde Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0x590ca8b1. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1First cylinder (1-39162, default 1): Using default value 1Last cylinder, +cylinders or +size{K,M,G} (1-39162, default 39162): Using default value 39162Command (m for help): p Disk /dev/xvde: 322.1 GB, 322122547200 bytes255 heads, 63 sectors/track, 39162 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x590ca8b1Device Boot Start End Blocks Id System/dev/xvde1 1 39162 314568733+ 83 Linux Command (m for help): w The partition table has been altered!Calling ioctl() to re-read partition table. Syncing disks.
3.Create the partition file system and format it Convert disk
# mkfs.ext4 /dev/xvde1 # Format xvde1 in ext4 format
[root@qxyw ~]# mkfs.ext4 xvde1 mke2fs 1.41.12 (17-May-2010) Could not stat xvde1 --- No such file or directory The device apparently does not exist; did you specify it correctly?[root@qxyw ~]# mkfs.ext4 /dev/xvde1 mke2fs 1.41.12 (17-May-2010) Filesystem label=OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks19660800 inodes, 78642183 blocks3932109 blocks (5.00%) reserved for the super user First data block=0Maximum filesystem blocks=4294967296 2400 block groups32768 blocks per group, 32768 fragments per group8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872, 71663616Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 25 mounts or180 days, whichever comes first. Use tune2fs -c or -i to override.
4. Under the home directory Create the folder mysql and mount the device to /home/mysql.
[root@qxyw home]# mount /dev/xvde1 /home/mysql [root@qxyw home]# df -h Filesystem Size Used Avail Use% Mounted on/dev/xvda2 36G 2.4G 32G 7% /tmpfs 3.9G 0 3.9G 0% /dev/shm/dev/xvde1 296G 191M 281G 1% /home/mysql
If there is a file in the original folder, the file will disappear after being mounted and the lost+found folder will appear. Don’t worry at this time. You can use the umount command to unmount it. .
The reason is this.
This involves the VFS (virtual file system) mechanism of Linux. After logging in, each directory and file you see is the VFS directory tree constructed in the memory when the kernel is loaded, instead of directly seeing the actual directory tree on the hard disk.
According to my rough understanding of , when you mount a device to a VFS mount point (such as /home), the system Point the mount point /home in VFS to the device you last mounted. Then when you access the mount point now, you will see the device you last mounted here. The previously mounted device is still there, but the mount point /home no longer points to the previous device. You can unmount the original device and mount it to a new mount point for access.
5.Write disk UUID to fstab
[root@qxyw ~]# blkid /dev/xvda1: UUID="5546dd0c-ef40-451b-b266-df8ef3a49967" TYPE="swap" /dev/xvda2: UUID="77fc0962-b3cf-400a-8903-0632e077fa09" TYPE="ext3" /dev/xvde1: UUID="1d17945b-c369-42de-85a8-47217d24d3e5" TYPE="ext4"
2) Add the disk information of xvde1 in the last line through vim /etc/fstab
# # /etc/fstab # Created by anaconda on Thu Jan 12 02:47:21 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=77fc0962-b3cf-400a-8903-0632e077fa09 / ext3 defaults 1 1UUID=5546dd0c-ef40-451b-b266-df8ef3a49967 swap swap defaults 0 0tmpfs /dev/shm tmpfs defaults 0 0devpts /dev/pts devpts gid=5,mode=620 0 0sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0 UUID=d17945b-c369-42de-85a8-47217d24d3e5 /home/mysql ext4 defaults 0 0
6. Transfer the contents under /var/lib/mysql/ to /home/mysql/, and create a mysql link under /var/lib/, The actual directory is actually /home/mysql
[root@qxyw /]# cd home[root@qxyw home]# mkdir mysql [root@qxyw home]# mv /var/lib/mysql/* /home/mysql[root@qxyw home]# ln /home/mysql /var/lib/mysql
7. Verify it and check the disk usage through the df command. Then enter the mysql command to create the database test1... After execution, the database test1 will appear in the /home/mysql/ folder. In addition, use the df command to check the disk usage. You will find that the usage of /dev/xvde1 is increasing.
[root@qxyw mysql]# df Filesystem 1K-blocks Used Available Use% Mounted on/dev/xvda2 37155392 2417608 32850400 7% /tmpfs 4018012 0 4018012 0% /dev/shm/dev/xvde1 309633052 217092 293687524 1% /home/mysql
The above is the detailed content of How to mount Linux system disk?. For more information, please follow other related articles on the PHP Chinese website!