wenjian

Centos7挂载新加4T硬盘到/home目录
以下操作均在Centos7 86*64环境下运行。1.查看硬盘fdisk -l[root@wenjian ~]# ...
扫描右侧二维码阅读全文
29
2019/04

Centos7挂载新加4T硬盘到/home目录

以下操作均在Centos7 86*64环境下运行。

1.查看硬盘

fdisk -l
[root@wenjian ~]# fdisk -l

Disk /dev/sda: 480.1 GB, 480103981056 bytes, 937703088 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: 0x00084581

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048        4095        1024   83  Linux
/dev/sda2   *        4096     2101247     1048576   83  Linux
/dev/sda3         2101248   937701375   467800064   8e  Linux LVM
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.

Disk /dev/sdb: 4000.8 GB, 4000787030016 bytes, 7814037168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: gpt
Disk identifier: 72C397DE-0531-4587-B9CC-7814959FE598


#         Start          End    Size  Type            Name

Disk /dev/mapper/vg-root: 469.5 GB, 469489418240 bytes, 916971520 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 /dev/mapper/vg-swap: 8455 MB, 8455716864 bytes, 16515072 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 /dev/mapper/vg-tmp: 1073 MB, 1073741824 bytes, 2097152 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
发现硬盘为/dev/sdb 大小4T

2.如果此硬盘以前有过分区,则先对磁盘格式化:

mkfs -t ext4 /dev/sdb
[root@wenjian ~]# mkfs -t ext4 /dev/sdb
mke2fs 1.42.9 (28-Dec-2013)
/dev/sdb is entire device, not just one partition!
Proceed anyway? (y,n) y   #按Y确定
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
244195328 inodes, 976754646 blocks
48837732 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=3124756480
29809 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, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
        102400000, 214990848, 512000000, 550731776, 644972544

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done 
此命令会对整个磁盘格式化

3.对新磁盘进行分区,由于fdisk仅支持2T以内磁盘分区,但该磁盘大于2T,所以使用parted进行GPT格式分区:

# parted /dev/sdb

(parted) help                # 可以查看帮助信息

(parted) mklabel gpt              # 执行命令mklabel gpt,把sdb改成gpt大分区格式

Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you

want to continue?

Yes/No? yes

(parted) mkpart primary 0 4001GB      # 创建分区

Warning: The resulting partition is not properly aligned for best performance.

Ignore/Cancel? cancel            # 注意,此处提示为磁盘为对齐,会影响性能,所以在此处要进行对齐

4.查看磁盘参数:

# cat /sys/block/sdb/queue/optimal_io_size

0

# cat /sys/block/sdb/queue/minimum_io_size

4096

# cat /sys/block/sdb/alignment_offset

0

# cat /sys/block/sdb/queue/physical_block_size

4096

如果optimal_io_size不为0,暂定是1048576,则可以用optimal_io_size的值加上alignment_offset的值,

然后除以physical_block_size的值,就是起始扇区的位置了,如上面的例子中,可以用这个公式算出来起始扇区的设定值:

(1048576 + 0) / 512 = 2048

如果optimal_io_size为0,那么我们最好直接使用起始扇区的默认值2048。

5. 最后在分区的时候使用以下的命令进行分区就可以了,不会报warning:

(parted) mkpart primary 2048s 100%

(parted) print

Model: ATA WDC WD40EFRX-68N (scsi)
Disk /dev/sdb: 4001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name     Flags
 1      1049kB  4001GB  4001GB               primary

(parted) align-check optimal 1                 # 此命令会检查对齐与否

1 aligned

(parted) quit

6.查看磁盘情况:

# fdisk -l

再次格式化磁盘:

# mkfs.ext4 -F /dev/sdb

挂载新磁盘到/home

# cd /mnt

# mkdir home

# mount /dev/sdb /mnt/home

# cp -a /home/* home

# rm -rf /home/*

# umount /dev/sdb

7.设置自动挂载/home

# vim /etc/fstab
在最后一行加:

/dev/sdb                /home                   ext4    defaults        1 2
# 保存退出

:wq

8. 查看是否挂载/home

# df -h

Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root  100G  5.4G   95G   6% /
devtmpfs                  32G     0   32G   0% /dev
tmpfs                     32G   29M   32G   1% /dev/shm
tmpfs                     32G   12M   32G   1% /run
tmpfs                     32G     0   32G   0% /sys/fs/cgroup
/dev/sda2               1014M  221M  794M  22% /boot
/dev/sda1                200M  9.8M  191M   5% /boot/efi
/dev/mapper/centos-home   74G   52M   74G   1% /home
tmpfs                    6.3G   56K  6.3G   1% /run/user/1000
未挂载!

9. 挂载fstab中未挂载的磁盘

# mount -a

10. 再次查看是否挂载/home

# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root  100G  5.4G   95G   6% /
devtmpfs                  32G     0   32G   0% /dev
tmpfs                     32G   29M   32G   1% /dev/shm
tmpfs                     32G   12M   32G   1% /run
tmpfs                     32G     0   32G   0% /sys/fs/cgroup
/dev/sda2               1014M  221M  794M  22% /boot
/dev/sda1                200M  9.8M  191M   5% /boot/efi
/dev/sdb                 3.6T  140M  3.4T   1% /home
tmpfs                    6.3G   56K  6.3G   1% /run/user/1000

挂载成功!

Last modification:April 29th, 2019 at 01:46 pm
如果觉得我的文章对你有用,请随意赞赏

Leave a Comment