三三世界-百宝箱

文章 分类 标签
132 9 250

公告

暂无站点公告

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

三三 2022-02-18 3551 0条评论 服务器配置Linux使用 CentOS7挂载磁盘大硬盘

首页 / 正文

以下操作均在root环境下运行。

1.查看硬盘

fdisk -l

发现硬盘为/dev/sdb 大小4T

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

mkfs -t ext4 /dev/sdb

此命令会对整个磁盘格式化

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

parted /dev/sdb

进入Parted以后

(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。

最后在分区的时候使用以下的命令进行分区就可以了,不会报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

7.再次格式化磁盘:

mkfs.ext4 -F /dev/sdb

8.挂载新磁盘到/home

cd /mnt
mkdir home
mount /dev/sdb /mnt/home
cp -a /home/* home

新机器没有数据的可能会提示错误,无所谓,忽略即可。

rm -rf /home/*
umount /dev/sdb

9.设置自动挂载/home

vim /etc/fstab

**根据自己习惯,可以用nano等。
在最后一行加:**

/dev/sdb /home ext4 defaults 1 2

保存退出

:wq

查看是否挂载/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

未挂载!

挂载fstab中未挂载的磁盘

mount -a

再次查看是否挂载/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

挂载成功!

评论(0)

当前没有评论,还不快来留下第一个脚印吧



最新评论

  • 三三

    @Doug Shume it's ok for me , you can post here.

  • refugiaguenther

    Saved as a favorite, I like your website!

  • josefa

    If some one wishes to be updated with hottest technologies after that he must be visit this site and be up to date daily.

  • Penzu

    Heello would you mind sharing which blog platform you're using? I'm planning to start my own blog in the near future but I'm having a tough time making a decision between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your layout seems different then moost blogs and I'm looking for something completely unique. P.S Apologies forr being off-topic butt I had to ask!

  • Yupoo Fendi

    Thanks to my father who shared with me regarding this webpage, this website is genuinely amazing.

  • Doug Shume

    Hi, I have an overflow of customers that I'd like to send to you but I want to make sure you can handle more leads, let me know if you'd like me to send you more info.

  • SuperWind

    zh.us.to 有效
    kms.03k.org 有效
    kms.chinancce.com
    kms.shuax.com 有效
    kms.dwhd.org 有效
    kms.luody.info 有效
    kms.digiboy.ir 有效
    kms.lotro.cc 有效
    www.zgbs.cc 有效
    cy2617.jios.org 有效

  • 三三

    @         权限问题,试试sudo 再加命令。

  •         

    你好提示Permission denied 怎么办啊

日历

2024年12月

1234567
891011121314
15161718192021
22232425262728
293031    

文章目录

上一张 下一张