Mount operation of Linux disk
Mrwhite86 2021-06-04 11:30:11

The goal is :

To mount a directory :/home
To mount a disk :/dev/sdd

1、 Check disk usage

[root@localhost ~]# df -h
file system Capacity Already used You can use Already used % Mount point
devtmpfs 475M 0 475M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.7M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/mapper/centos-root 17G 1.5G 16G 9% /
/dev/sda1 1014M 137M 878M 14% /boot
/dev/sdb1 102M 1.6M 93M 2% /mnt
tmpfs 98M 0 98M 0% /run/user/0

2、 List information about all available block devices

[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 1G 0 disk
├─sdb1 8:17 0 109M 0 part /mnt
├─sdb2 8:18 0 1K 0 part
├─sdb5 8:21 0 407M 0 part
└─sdb6 8:22 0 500.8M 0 part
sdc 8:32 0 1G 0 disk
sdd 8:48 0 2G 0 disk
sr0 11:0 1 973M 0 rom 

3、 List all partition tables

[root@localhost ~]# fdisk -l
disk /dev/sda:21.5 GB, 21474836480 byte ,41943040 Sectors
Units = A sector of 1 * 512 = 512 bytes
Sector size ( Logic / Physics ):512 byte / 512 byte
I/O size ( Minimum / The best ):512 byte / 512 byte
Disk label type :dos
Disk identifier :0x000adbf3
equipment Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
disk /dev/sdb:1073 MB, 1073741824 byte ,2097152 Sectors
Units = A sector of 1 * 512 = 512 bytes
Sector size ( Logic / Physics ):512 byte / 512 byte
I/O size ( Minimum / The best ):512 byte / 512 byte
Disk label type :dos
Disk identifier :0x66a51583
equipment Boot Start End Blocks Id System
/dev/sdb1 2048 225279 111616 83 Linux
/dev/sdb2 225280 2088449 931585 5 Extended
/dev/sdb5 227328 1060863 416768 83 Linux
/dev/sdb6 1062912 2088449 512769 83 Linux
disk /dev/sdc:1073 MB, 1073741824 byte ,2097152 Sectors
Units = A sector of 1 * 512 = 512 bytes
Sector size ( Logic / Physics ):512 byte / 512 byte
I/O size ( Minimum / The best ):512 byte / 512 byte
disk /dev/sdd:2147 MB, 2147483648 byte ,4194304 Sectors
Units = A sector of 1 * 512 = 512 bytes
Sector size ( Logic / Physics ):512 byte / 512 byte
I/O size ( Minimum / The best ):512 byte / 512 byte
disk /dev/mapper/centos-root:18.2 GB, 18249416704 byte ,35643392 Sectors
Units = A sector of 1 * 512 = 512 bytes
Sector size ( Logic / Physics ):512 byte / 512 byte
I/O size ( Minimum / The best ):512 byte / 512 byte
disk /dev/mapper/centos-swap:2147 MB, 2147483648 byte ,4194304 Sectors
Units = A sector of 1 * 512 = 512 bytes
Sector size ( Logic / Physics ):512 byte / 512 byte
I/O size ( Minimum / The best ):512 byte / 512 byte 

4、 Format disk : Use ext4, choice y

[root@localhost ~]# mkfs.ext4 /dev/sdd
mke2fs 1.42.9 (28-Dec-2013)
/dev/sdd is entire device, not just one partition!
Go ahead anyway ? (y,n) y
File system tags =
OS type: Linux
Block size =4096 (log=2)
Block size =4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
131072 inodes, 524288 blocks
26214 blocks (5.00%) reserved for the super user
The first data block =0
Maximum filesystem blocks=536870912
16 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Allocating group tables: complete
Are written to the inode surface : complete
Creating journal (16384 blocks): complete
Writing superblocks and filesystem accounting information: complete 

5、 New springboard Directory

[root@localhost ~]# mkdir /new

6、 Mount the springboard Directory , And look at

[root@localhost ~]# mount /dev/sdd /new
[root@localhost ~]# df -h
file system Capacity Already used You can use Already used % Mount point
devtmpfs 475M 0 475M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.7M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/mapper/centos-root 17G 1.5G 16G 9% /
/dev/sda1 1014M 137M 878M 14% /boot
/dev/sdb1 102M 1.6M 93M 2% /mnt
tmpfs 98M 0 98M 0% /run/user/0
/dev/sdd 2.0G 6.0M 1.8G 1% /new

7、 Copy the data

[root@localhost ~]# cp -r /home/* /new

8、 Make room for the original disk ( Optional ):

[root@localhost ~]# rm -rf /home/*

9、 Mount target directory , You will find /home/ The catalog files have all been transferred , At this time /home The catalog is equivalent to /new Hard link to directory

[root@localhost ~]# mount /dev/sdd /home

10、 Unmount the gangplank directory , There may be problems that cannot be deleted , have access to umont -fl Forced unloading , And check the mount

[root@localhost home]# umount /new
[root@localhost home]# df -h
file system Capacity Already used You can use Already used % Mount point
devtmpfs 475M 0 475M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.7M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/mapper/centos-root 17G 1.5G 16G 9% /
/dev/sda1 1014M 137M 878M 14% /boot
/dev/sdb1 102M 1.6M 93M 2% /mnt
tmpfs 98M 0 98M 0% /run/user/0
/dev/sdd 2.0G 6.1M 1.8G 1% /home

11、 Delete the springboard Directory

[root@localhost home]# rm -rf /new

12、 Add boot mount Directory , And look at

[root@localhost new]# echo "/dev/sdd /home ext4 defaults 0 0" >> /etc/fstab
[root@localhost new]# vi /etc/fstab
#
# /etc/fstab
# Created by anaconda on Fri Jan 1 23:24:52 2021
#
# 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
#
/dev/mapper/centos-root / xfs defaults 0 0
UUID=bbe947b7-46c4-487a-8446-b9c05107a6c0 /boot xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
/dev/sdb1 /mnt ext4 defaults 0 0
/dev/sdd /home ext4 defaults 0 0

 

Please bring the original link to reprint ,thank
Similar articles

2021-08-09

2021-08-09