Linux使用大于2T的新硬盘
如果有大于2T的硬盘,且只分一个区,Linux需要以gpt格式支持大于2T的单个分区。
(1)查看各盘状态
[root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 7.8T 0 disk └─sda1 8:1 0 7.8T 0 part sdb 8:16 0 7.8T 0 disk └─sdb1 8:17 0 7.8T 0 part sdc 8:32 0 7.8T 0 disk └─sdc1 8:33 0 7.8T 0 part sdd 8:48 0 7.8T 0 disk sde 8:64 0 7.8T 0 disk └─sde1 8:65 0 7.8T 0 part sdf 8:80 0 7.8T 0 disk sdg 8:96 0 1T 0 disk ├─sdg1 8:97 0 1G 0 part /boot └─sdg2 8:98 0 1023G 0 part ├─centos-root 253:0 0 50G 0 lvm / ├─centos-swap 253:1 0 15.8G 0 lvm [SWAP] └─centos-home 253:2 0 957.2G 0 lvm /home sr0 11:0 1 1024M 0 rom
[root@localhost ~]# fdisk -l WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion. 磁盘 /dev/sdb:8589.9 GB, 8589934592000 字节,16777216000 个扇区 Units = 扇区 of 1 * 512 = 512 bytes 扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节 磁盘标签类型:gpt Disk identifier: 093D8E7F-4FE9-4C45-A2DB-57F0BF02D2B6 # Start End Size Type Name 1 2048 16777213951 7.8T Microsoft basic primary WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion. 磁盘 /dev/sdc:8589.9 GB, 8589934592000 字节,16777216000 个扇区 Units = 扇区 of 1 * 512 = 512 bytes 扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节 磁盘标签类型:gpt Disk identifier: 1A2EBF8C-D78F-42E7-91B3-19CA77441DE5
(2)对未分区的sdf进行分区
[root@localhost ~]# parted /dev/sdf GNU Parted 3.1 使用 /dev/sdf Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) mklabel gpt (parted) mkpart primary 1 -1 (parted) q 信息: You may need to update /etc/fstab.
(3)将分区格式化,以xfs为例
[root@localhost ~]# mkfs.xfs /dev/sdf1 meta-data=/dev/sdf1 isize=512 agcount=8, agsize=268435455 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=2094005760, imaxpct=5 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=521728, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0
(4)新建文件夹测试挂载
mkdir /root/test1
mount /dev/sdf1 /root/test1
(5)查看挂载情况
[root@localhost ~]# df -h 文件系统 容量 已用 可用 已用% 挂载点 devtmpfs 16G 0 16G 0% /dev tmpfs 16G 0 16G 0% /dev/shm tmpfs 16G 13M 16G 1% /run tmpfs 16G 0 16G 0% /sys/fs/cgroup /dev/mapper/centos-root 50G 15G 36G 29% / /dev/mapper/centos-home 957G 37M 957G 1% /home /dev/sdg1 1014M 185M 830M 19% /boot overlay 50G 15G 36G 29% /var/lib/docker/overlay2/f1b4e9c7099fee0b73e90f5697bd338eaafa1c71f453c07871afc02634a313b3/merged overlay 50G 15G 36G 29% /var/lib/docker/overlay2/c05113d53e79a1f2c4f223626d878d3d42cff480d4196eba6516dbc2118f24af/merged overlay 50G 15G 36G 29% /var/lib/docker/overlay2/e6d6e3aee6a7fde4a6ea538b033228d056b8116d1e1ee4929ef6bc2df760c3a7/merged overlay 50G 15G 36G 29% /var/lib/docker/overlay2/4c34596a65f19a01cf515fed0a166fc63622d2b1d6460a576a4b090ea5de426f/merged overlay 50G 15G 36G 29% /var/lib/docker/overlay2/8ee814f4addcc893e612227eb53d77650a1f53d99d16f6ca5d7e76a7f238b08d/merged tmpfs 3.2G 0 3.2G 0% /run/user/0 tmpfs 3.2G 12K 3.2G 1% /run/user/42 /dev/sdf1 7.8T 33M 7.8T 1% /root/test1
(6)要实现开机自动挂载,需要将挂载的脚本写入到/etc/fstab文件中。
vi /etc/fstab /dev/sdf1 /sedata/data/admin/pub_data/s6 xfs defaults 0 0
(7)为了避免插入新盘后,设备名称改变,可以采用uuid的方式挂载。
查询uuid:
[root@localhost ~]# lsblk -d -fs
NAME FSTYPE LABEL UUID MOUNTPOINT
sda1 xfs c3fa8892-68c0-40e2-9eb0-e4e397039582 /sedata/data/admin/pub_data/s1
sdb1 xfs 0c76c479-874a-4ba9-ad61-60e1e7e83b74 /sedata/data/admin/pub_data/s3
sdc1 xfs e8b9a6f0-ccff-4089-8f38-1f61959af30f /sedata/data/admin/pub_data/s4
sdd1 xfs 76db62af-4091-40b4-a87e-0817a634b0da
sde1 xfs 3cbad81d-b090-4e49-bc0a-3d0ee04ea571
sdf1 xfs d799e0c8-5ad1-41a7-a6ad-b4fda89f6b54 /boot
挂载:
# # /etc/fstab # Created by anaconda on Mon Nov 30 19:03:22 2020 # # 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=d799e0c8-5ad1-41a7-a6ad-b4fda89f6b54 /boot xfs defaults 0 0 /dev/mapper/centos-home /home xfs defaults 0 0 /dev/mapper/centos-swap swap swap defaults 0 0 UUID=c3fa8892-68c0-40e2-9eb0-e4e397039582 /sedata/data/admin/pub_data/s1 xfs defaults 0 0 UUID=0c76c479-874a-4ba9-ad61-60e1e7e83b74 /sedata/data/admin/pub_data/s3 xfs defaults 0 0 UUID=e8b9a6f0-ccff-4089-8f38-1f61959af30f /sedata/data/admin/pub_data/s4 xfs defaults 0 0 UUID=76db62af-4091-40b4-a87e-0817a634b0da /sedata/data/admin/pub_data/s5 xfs defaults 0 0 UUID=3cbad81d-b090-4e49-bc0a-3d0ee04ea571 /sedata/data/admin/pub_data/s6 xfs defaults 0 0
(8)除了/etc/fstab的挂载,推荐采用一种更优的挂载方案。使用systemd提供的挂载选项,可以完美地解决以前使用/etc/fstab时一些痛点,比如避免fstab误操作导致系统无法启动。此外systemd.mount还可以让那些要求在网络可用时的文件系统在网络已经可用的情况下才去挂载,还可以定义等待网络可用的超时时间,从而避免在开机过程中长时间卡住。
vi /etc/systemd/system/usr-cqismdata.mount
usr-cqismdata.mount文件内容。注意:文件名一定要与Where中的路径对应,否则会报错。
[Unit] Description=Mount sda1
[Mount] What=/dev/sda1 Where=/usr/cqismdata
Type=xfs
Options=defaults,nofail,discard,noatime
[Install]
WantedBy = multi-user.target
管理挂载服务
systemctl status usr-cqismdata.mount systemctl enable usr-cqismdata.mount systemctl disable usr-cqismdata.mount systemctl start usr-cqismdata.mount systemctl stop usr-cqismdata.mount
(9)挂载samba共享目录,usr-cqismdata-share.mount文件内容如下:
[Unit] Description= mount a samba share Requires=network-online.target After=network-online.target systemd-resolved.service Wants=network-online.target systemd-resolved.service [Mount] What=//192.168.10.50/samba/share Where=/usr/cqismdata/share Type=cifs # 下面是samba服务的账号、密码、挂栽权限等配置 Options=username=smbAdmin,password=123456,dir_mode=0777,rw,file_mode=0777,uid=65534,gid=65534 # 挂载超时时间
TimeoutSec=30 [Install] WantedBy=multi-user.target
附:对于已安装软件的目录扩容,可采用软链接的方案。如:
cd /software/data ln -s /xxx/sda1 #新硬盘挂载目录