自建NAS如何使用大于2TB的硬盘(从分区开始)

Posted kyeup

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了自建NAS如何使用大于2TB的硬盘(从分区开始)相关的知识,希望对你有一定的参考价值。

目录

自建NAS如何使用大于2TB的硬盘(从分区开始)


需求说明:
自建NAS,自备了两块3T的硬盘,如何操作才能正常的使用?
思路说明:

  • 按照自己的需求对两块3T硬盘分区;
  • 对分区进行格式化;
  • 挂载到某一目录(需设置开机自动挂载)
  • 上传文件测试;

    硬盘分区

    最常见的分区如下所示:
#系统
[email protected]:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 9.4 (stretch)
Release:    9.4
Codename:   stretch
[email protected]:~$ sudo fdisk -l
[sudo] kyeup 的密码:
Disk /dev/sda: 74.5 GiB, 80026361856 bytes, 156301488 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
Disklabel type: gpt
Disk identifier: E57E46D1-111A-4C41-BAFD-62AA237015D1

Device         Start       End   Sectors  Size Type
/dev/sda1       2048   1050623   1048576  512M EFI System
/dev/sda2    1050624 148615167 147564544 70.4G Linux filesystem
/dev/sda3  148615168 156301311   7686144  3.7G Linux swap


Disk /dev/sdc: 2.7 TiB, 3000592982016 bytes, 5860533168 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 /dev/sdb: 2.7 TiB, 3000592982016 bytes, 5860533168 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
[email protected]:~$ sudo fdisk /dev/sdb

Welcome to fdisk (util-linux 2.29.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
The size of this disk is 2.7 TiB (3000592982016 bytes). DOS partition table format can not be used on drives for volumes larger than 2199023255040 bytes for 512-byte sectors. Use GUID partition table format (GPT).

Created a new DOS disklabel with disk identifier 0x4d35f874.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-4294967295, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-4294967294, default 4294967294):   

Created a new partition 1 of type ‘Linux‘ and of size 2 TiB.

Command (m for help): p
Disk /dev/sdb: 2.7 TiB, 3000592982016 bytes, 5860533168 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
Disklabel type: dos
Disk identifier: 0x4d35f874

Device     Boot Start        End    Sectors Size Id Type
/dev/sdb1        2048 4294967294 4294965247   2T 83 Linux

Command (m for help): q

根据上面的提示:

The size of this disk is 2.7 TiB (3000592982016 bytes). DOS partition table format can not be used on drives for volumes larger than 2199023255040 bytes for 512-byte sectors. Use GUID partition table format (GPT).
Device     Boot Start        End    Sectors Size Id Type
/dev/sdb1        2048 4294967294 4294965247   2T 83 Linux

MBR 分区表类型最大支持2T,对于大于2T的硬盘需要使用GPT分区。另外,fdisk只对mbr分区有效,故而使用==parted分区==。

MBR(Master Boot Record)

  主引导记录,是传统的分区机制,应用于绝大多数使用Bios的PC设备

  MBR支持32位和64位系统。

  MBR支持分区数量有限。

  MBR只支持不超过2T的硬盘,超过2T的硬盘将只能用2T空间(有第三方解决方法)。
GPT(GUID Partition Table)

  全局唯一标识分区表,是一个较新的分区机制,解决了MBR很多缺点。

  支持超过2T的磁盘(64位寻址空间)。fdisk最大只能建立2TB大小的分区,创建一个大于2TB的分区使用parted。

  向后兼容MBR。

  必须在支持uEFI的硬件上才能使用(Intel提出,用于取代BIOS)。

  必须使用64位系统。

  Mac、Linux系统都能支持GPT分区格式。

  Windows 7/8 64bit、Windows Server 2008 64bit支持GPT。

  以上就是Linux系统MBR和GPT分区的区别,总得来说GPT比MBR更先进,但是MBR的兼容性比GPT要好。

[email protected]:/sys/block$ sudo parted /dev/sdb
GNU Parted 3.2
Using /dev/sdb
Welcome to GNU Parted! Type ‘help‘ to view a list of commands.
(parted) p                                                                
Model: ATA WD30EZRZ-64D85Y0 (scsi)
Disk /dev/sdb: 3001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags: 

Number  Start  End  Size  File system  Name  Flags

(parted) mkpart                                                           
Partition name?  []? fun1
File system type?  [ext2]? ext4
Start? 0%
End? 1T
(parted) p                                                                
Model: ATA WD30EZRZ-64D85Y0 (scsi)
Disk /dev/sdb: 3001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name  Flags
 1      1049kB  1000GB  1000GB  ext4         fun1

(parted) mkpart                                                           
Partition name?  []? fun2                                                 
File system type?  [ext2]? ext4
Start? 1T                                                                 
End? 100%                                                                 
(parted) p                                                                
Model: ATA WD30EZRZ-64D85Y0 (scsi)
Disk /dev/sdb: 3001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name  Flags
 1      1049kB  1000GB  1000GB  ext4         fun1
 2      1000GB  3001GB  2001GB  ext4         fun2

(parted) quit
Information: You may need to update /etc/fstab.

[email protected]:~$ sudo parted /dev/sdc
GNU Parted 3.2
Using /dev/sdc
Welcome to GNU Parted! Type ‘help‘ to view a list of commands.
(parted) p                                                                
Model: ATA WD30EFRX-68EUZN0 (scsi)
Disk /dev/sdc: 3001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags: 

Number  Start  End  Size  File system  Name  Flags

(parted) mkpart                                                           
Partition name?  []? work1                                                
File system type?  [ext2]? ext4
Start? 0%                                                                 
End? 1T                                                                   
(parted) mkpart                                                           
Partition name?  []? work2
File system type?  [ext2]? ext4                                           
Start? 1T                                                                 
End? 100%                                                                 
(parted) p                                                                
Model: ATA WD30EFRX-68EUZN0 (scsi)
Disk /dev/sdc: 3001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name   Flags
 1      1049kB  1000GB  1000GB  ext4         work1
 2      1000GB  3001GB  2001GB  ext4         work2

(parted) quit                                                             
Information: You may need to update /etc/fstab.

[email protected]:~$ sudo fdisk -l
Disk /dev/sda: 74.5 GiB, 80026361856 bytes, 156301488 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
Disklabel type: gpt
Disk identifier: E57E46D1-111A-4C41-BAFD-62AA237015D1

Device         Start       End   Sectors  Size Type
/dev/sda1       2048   1050623   1048576  512M EFI System
/dev/sda2    1050624 148615167 147564544 70.4G Linux filesystem
/dev/sda3  148615168 156301311   7686144  3.7G Linux swap


Disk /dev/sdc: 2.7 TiB, 3000592982016 bytes, 5860533168 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
Disklabel type: gpt
Disk identifier: 16CD8258-758E-4FE4-B198-DF40ABE49BE3

Device          Start        End    Sectors   Size Type
/dev/sdc1        2048 1953124351 1953122304 931.3G Linux filesystem
/dev/sdc2  1953124352 5860532223 3907407872   1.8T Linux filesystem


Disk /dev/sdb: 2.7 TiB, 3000592982016 bytes, 5860533168 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
Disklabel type: gpt
Disk identifier: BD41449F-41EB-43DB-B797-185363963AE1

Device          Start        End    Sectors   Size Type
/dev/sdb1        2048 1953124351 1953122304 931.3G Linux filesystem
/dev/sdb2  1953124352 5860532223 3907407872   1.8T Linux filesystem

Start? 0%
End? 1T
(parted) mkpart
Partition name? []? work2
File system type? [ext2]? ext4
Start? 1T
End? 100%
注意此处是0% 100%

对分区进行格式化

[email protected]:~$ sudo fdisk -l
Disk /dev/sda: 74.5 GiB, 80026361856 bytes, 156301488 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
Disklabel type: gpt
Disk identifier: E57E46D1-111A-4C41-BAFD-62AA237015D1

Device         Start       End   Sectors  Size Type
/dev/sda1       2048   1050623   1048576  512M EFI System
/dev/sda2    1050624 148615167 147564544 70.4G Linux filesystem
/dev/sda3  148615168 156301311   7686144  3.7G Linux swap


Disk /dev/sdc: 2.7 TiB, 3000592982016 bytes, 5860533168 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
Disklabel type: gpt
Disk identifier: 16CD8258-758E-4FE4-B198-DF40ABE49BE3

Device          Start        End    Sectors   Size Type
/dev/sdc1        2048 1953124351 1953122304 931.3G Linux filesystem
/dev/sdc2  1953124352 5860532223 3907407872   1.8T Linux filesystem


Disk /dev/sdb: 2.7 TiB, 3000592982016 bytes, 5860533168 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
Disklabel type: gpt
Disk identifier: BD41449F-41EB-43DB-B797-185363963AE1

Device          Start        End    Sectors   Size Type
/dev/sdb1        2048 1953124351 1953122304 931.3G Linux filesystem
/dev/sdb2  1953124352 5860532223 3907407872   1.8T Linux filesystem
[email protected]:~$ sudo mkfs.ext4 /dev/sdb1
mke2fs 1.43.4 (31-Jan-2017)
创建含有 244140288 个块(每块 4k)和 61038592 个inode的文件系统
文件系统UUID:a5fc03f1-255b-4561-b3b2-9c17c324d935
超级块的备份存储于下列块: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
    4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
    102400000, 214990848

正在分配组表: 完成                            
正在写入inode表: 完成                            
创建日志(262144 个块)完成
写入超级块和文件系统账户统计信息: 已完成   

[email protected]:~$ sudo mkfs.ext4 /dev/sdb2
mke2fs 1.43.4 (31-Jan-2017)
创建含有 488425984 个块(每块 4k)和 122109952 个inode的文件系统
文件系统UUID:b4e66cc9-f7c0-489b-beda-8e5a481c61e0
超级块的备份存储于下列块: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
    4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
    102400000, 214990848

正在分配组表: 完成                            
正在写入inode表: 完成                            
创建日志(262144 个块)完成
写入超级块和文件系统账户统计信息: 已完成     

[email protected]:~$ sudo mkfs.ext4 /dev/sdc1
mke2fs 1.43.4 (31-Jan-2017)
创建含有 244140288 个块(每块 4k)和 61038592 个inode的文件系统
文件系统UUID:b568092d-ccba-47ca-ba38-af90db375983
超级块的备份存储于下列块: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
    4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
    102400000, 214990848

正在分配组表: 完成                            
正在写入inode表: 完成                            
创建日志(262144 个块)完成
写入超级块和文件系统账户统计信息: 已完成   

[email protected]:~$ sudo mkfs.ext4 /dev/sdc2
mke2fs 1.43.4 (31-Jan-2017)
创建含有 488425984 个块(每块 4k)和 122109952 个inode的文件系统
文件系统UUID:837dfafb-3cff-4c15-9bea-33cc18abc3bb
超级块的备份存储于下列块: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
    4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
    102400000, 214990848

正在分配组表: 完成                            
正在写入inode表: 完成                            
创建日志(262144 个块)完成
写入超级块和文件系统账户统计信息: 已完成    

挂载到某一目录(需设置开机自动挂载)

[email protected]:~$ sudo blkid
/dev/sda1: UUID="8982-B086" TYPE="vfat" PARTUUID="b5461768-be0f-4ff2-bccb-44ebc7f84a5d"
/dev/sda2: UUID="17dbffb4-ff98-4ba4-b0c0-270d0ac12f07" TYPE="ext4" PARTUUID="4be18a0f-4d18-47a5-8c94-580251b97803"
/dev/sda3: UUID="effcd1ac-b4ed-4c62-894c-66aca5fc61f2" TYPE="swap" PARTUUID="4a1dfc34-9c37-4345-8516-7e5d868eaef6"
/dev/sdc1: UUID="b568092d-ccba-47ca-ba38-af90db375983" TYPE="ext4" PARTLABEL="work1" PARTUUID="e57513c5-a3d4-4b5d-a4a7-0ab1980f153b"
/dev/sdc2: UUID="837dfafb-3cff-4c15-9bea-33cc18abc3bb" TYPE="ext4" PARTLABEL="work2" PARTUUID="0a993b35-34b6-49fc-80e3-aac086304ff0"
/dev/sdb1: UUID="a5fc03f1-255b-4561-b3b2-9c17c324d935" TYPE="ext4" PARTLABEL="fun1" PARTUUID="00edb0eb-153a-41bd-9aa8-99749c1dac4a"
/dev/sdb2: UUID="b4e66cc9-f7c0-489b-beda-8e5a481c61e0" TYPE="ext4" PARTLABEL="fun2" PARTUUID="dc10cdd3-4d52-47f7-be6d-85e04f7c1acd"
#新建挂载的目录 
[email protected]:~$ sudo mkdir /fun1 /fun2 /work1 /work2
#编辑 /etc/fstab
[email protected]:~$ sudo cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use ‘blkid‘ to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sda2 during installation
UUID=17dbffb4-ff98-4ba4-b0c0-270d0ac12f07 /               ext4    errors=remount-ro 0       1
# /boot/efi was on /dev/sda1 during installation
UUID=8982-B086  /boot/efi       vfat    umask=0077      0       1
# swap was on /dev/sda3 during installation
UUID=effcd1ac-b4ed-4c62-894c-66aca5fc61f2 none            swap    sw              0       0

UUID=a5fc03f1-255b-4561-b3b2-9c17c324d935       /fun1   ext4    defaults    0      0

UUID=b4e66cc9-f7c0-489b-beda-8e5a481c61e0       /fun2   ext4    defaults    0      0

UUID=b568092d-ccba-47ca-ba38-af90db375983       /work1  ext4    defaults    0      0

UUID=837dfafb-3cff-4c15-9bea-33cc18abc3bb       /work2  ext4    defaults    0      0
[email protected]:~$ sudo mount -a
[email protected]:~$ df -h
文件系统        容量  已用  可用 已用% 挂载点
udev            1.8G     0  1.8G    0% /dev
tmpfs           362M  5.5M  356M    2% /run
/dev/sda2        69G  3.5G   62G    6% /
tmpfs           1.8G     0  1.8G    0% /dev/shm
tmpfs           5.0M  4.0K  5.0M    1% /run/lock
tmpfs           1.8G     0  1.8G    0% /sys/fs/cgroup
/dev/sda1       511M  132K  511M    1% /boot/efi
tmpfs           362M     0  362M    0% /run/user/1000
/dev/sdb1       916G   77M  870G    1% /fun1
/dev/sdb2       1.8T   77M  1.7T    1% /fun2
/dev/sdc1       916G   77M  870G    1% /work1
/dev/sdc2       1.8T   77M  1.7T    1% /work2

上传文件测试;

[email protected]:/fun2$ ls /fun[12] /work[12]
/fun1:
lost+found

/fun2:
lost+found

/work1:
lost+found

/work2:
lost+found
[email protected]:/fun1$ sudo mkdir movie
[email protected]:/fun1$ ls
lost+found  movie
[email protected]:~$ sudo chown kyeup:kyeup /fun1/movie/
[email protected]:/fun1/movie$ mkdir study

补充

在分区的时候一定格外注意:

[email protected]:~$ sudo parted /dev/sdc
GNU Parted 3.2
Using /dev/sdc
Welcome to GNU Parted! Type ‘help‘ to view a list of commands.
(parted) mktable                                                          
New disk label type? work1
parted: invalid token: work1
New disk label type? gpt                                                  
(parted) mkpart
Partition name?  []? work1                                                
File system type?  [ext2]? ext4                                           
Start? 0                                                                  
End? 1T                                                                   
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? i                                                          
(parted) mkpart
Partition name?  []? work2                                                
File system type?  [ext2]? ext4                                           
Start? 1T                                                                 
End? 100%                                                                 
(parted) p                                                                
Model: ATA WD30EFRX-68EUZN0 (scsi)
Disk /dev/sdc: 3001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name   Flags
 1      17.4kB  1000GB  1000GB  ext4         work1
 2      1000GB  3001GB  2001GB  ext4         work2

在start的时候,不能输入 0 或者 1,在网上大多采用这种方法,但是在后面的格式化中出现:

[email protected]:~$ sudo mkfs.ext4 /dev/sdb1
mke2fs 1.43.4 (31-Jan-2017)
/dev/sdb1 未对齐,偏移了 3072 个字节。
这可能导致性能下降,建议重新进行分区。
创建含有 244140620 个块(每块 4k)和 61038592 个inode的文件系统
文件系统UUID:d16b9bfe-8485-4795-a4ef-aeb6bf2d914e
超级块的备份存储于下列块: 
  32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
  4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
  102400000, 214990848

正在分配组表: 完成                            
正在写入inode表: 完成                            
创建日志(262144 个块)完成
写入超级块和文件系统账户统计信息: 已完成   

所以出现了“4K对齐”的问题,网上有解决办法,但是试过不行之有效,所以最好的办法是使用百分比(%)的方式划分。

希望大家遇到此类问题能很快的解决!o(∩_∩)o














以上是关于自建NAS如何使用大于2TB的硬盘(从分区开始)的主要内容,如果未能解决你的问题,请参考以下文章

使用parted对大于2TB的硬盘分区

如何在 Linux 中添加一块大于 2TB 的新磁盘?

Windows Server 2008 R2 怎么安装2T以上的硬盘

20170714L08-00老男孩Linux运维实战培训-DELL R710新服务器多硬盘Raid5后容量大于2TB如何分区讲解

Linux创建2TB以上分区,以及正确的对齐磁盘

Linux硬盘分区 fdisk 和 parted命令详解