为什么需要分区?
优化I/O性能
实现磁盘空间配额限制
提高修复速度
隔离系统和程序
安装多个OS
采用不同文件系统
给vagrant拉起来的机器加一块硬盘
通过VBoxManage 工具给虚拟机增加硬盘.
2022-07-22 15:49:31
#1、 创建50GB 的vdi硬盘 VBoxManage createvdi --filename "/gpmaster/gpseg-1_down/VirtualBox VMs/meta_meta_1651042401911_2096/meta-50g.vdi" --size 51200 #2、将第一步创建的硬盘attach到虚拟机上 VBoxManage storageattach meta_meta_1651042401911_2096 --storagectl SATA --port 0 --device 0 --type hdd --medium "/gpmaster/gpseg-1_down/VirtualBox VMs/meta_meta_1651042401911_2096/meta-50g.vdi" # 3、如果第二步报错: sata控制器未开启先执行以下命令开启再执行第二步(必须关机状态) VBoxManage storagectl meta_meta_1651042401911_2096 --name SATA --add sata --controller IntelAhci --bootable on
[1]lsblk查看新加的硬盘
[root@meta /etc/prometheus]#df -Th Filesystem Type Size Used Avail Use% Mounted on devtmpfs devtmpfs 7.8G 0 7.8G 0% /dev tmpfs tmpfs 7.8G 180K 7.8G 1% /dev/shm tmpfs tmpfs 7.8G 156M 7.7G 2% /run tmpfs tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup /dev/sda1 xfs 40G 39G 1.5G 97% / tmpfs tmpfs 1.6G 0 1.6G 0% /run/user/0 [root@meta /etc/prometheus]#fdisk -l /dev/sdb Disk /dev/sdb: 53.7 GB, 53687091200 bytes, 104857600 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 [root@meta /etc/prometheus]#lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 40G 0 disk `-sda1 8:1 0 40G 0 part / sdb 8:16 0 50G 0 disk
[2]fdisk格式化硬盘
[root@meta /etc/prometheus]#fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.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 Building a new DOS disklabel with disk identifier 0x1daa8e3b. Command (m for help): m Command action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition g create a new empty GPT partition table G create an IRIX (SGI) partition table l list known partition types m print this menu n add a new partition o create a new empty DOS partition table p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partition's system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only) Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 1): 1 #几个分区 First sector (2048-104857599, default 2048):# 扇区起始位置 Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599):# 扇区结束位置 Using default value 104857599 Partition 1 of type Linux and of size 50 GiB is set Command (m for help): p Disk /dev/sdb: 53.7 GB, 53687091200 bytes, 104857600 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: 0x1daa8e3b Device Boot Start End Blocks Id System /dev/sdb1 2048 104857599 52427776 83 Linux Command (m for help): w # 保存 The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@meta /etc/prometheus]# [root@meta /etc/prometheus]#lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 40G 0 disk `-sda1 8:1 0 40G 0 part / sdb 8:16 0 50G 0 disk `-sdb1 8:17 0 50G 0 part
[3]重新载入磁盘分区信息
[root@meta /etc/prometheus]#partprobe /dev/sdb # 重新载入磁盘分区信息 [root@meta /etc/prometheus]#
[4] 格式化磁盘
要是用 mkfs.xfs而不是xfs_growfs
[5]创建目录并挂载
⚡ root@pigsty2-179 ~ df -TH Filesystem Type Size Used Avail Use% Mounted on devtmpfs devtmpfs 34G 0 34G 0% /dev tmpfs tmpfs 34G 0 34G 0% /dev/shm tmpfs tmpfs 34G 8.9M 34G 1% /run tmpfs tmpfs 34G 0 34G 0% /sys/fs/cgroup /dev/sda1 xfs 43G 3.7G 40G 9% / tmpfs tmpfs 6.8G 0 6.8G 0% /run/user/0 ⚡ root@pigsty2-179 ~ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 600G 0 disk ├─sda2 8:2 0 560G 0 part └─sda1 8:1 0 40G 0 part / ⚡ root@pigsty2-179 ~ mkdir /data ⚡ root@pigsty2-179 ~ ⚡ root@pigsty2-179 ~ mount /dev/sda2 /data ⚡ root@pigsty2-179 ~ ⚡ root@pigsty2-179 ~ df -TH Filesystem Type Size Used Avail Use% Mounted on devtmpfs devtmpfs 34G 0 34G 0% /dev tmpfs tmpfs 34G 0 34G 0% /dev/shm tmpfs tmpfs 34G 8.9M 34G 1% /run tmpfs tmpfs 34G 0 34G 0% /sys/fs/cgroup /dev/sda1 xfs 43G 3.7G 40G 9% / tmpfs tmpfs 6.8G 0 6.8G 0% /run/user/0 /dev/sda2 xfs 602G 34M 601G 1% /data
[6] 开机自动挂载
blkid 获取
blkid /dev/sda2 /dev/sda2: UUID="ed42543b-8f1b-4473-9c01-720e6e41b2fe" TYPE="xfs"
fstab增加配置自动挂载重启硬盘自动挂载好了
挂载参数优化
#more /etc/fstab # # /etc/fstab # Created by anaconda on Wed Jul 21 17:33:20 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/rootvg-root / xfs defaults 0 0 UUID=3aa14848-bfe7-4360-8149-8af67abdcd44 /boot xfs defaults 0 0 UUID=9DEB-A905 /boot/efi vfat umask=0077,shortname=winnt 0 0 /dev/mapper/rootvg-homelv /home xfs defaults 0 0 /dev/mapper/rootvg-optlv /opt xfs defaults 0 0 /dev/mapper/rootvg-tmplv /tmp xfs defaults 0 0 /dev/mapper/rootvg-usrlv /usr xfs defaults 0 0 /dev/mapper/rootvg-varlv /var xfs defaults 0 0 /dev/mapper/rootvg-swap swap swap defaults 0 0 /dev/datavg/gpmasterlv /gpmaster xfs nodev,noatime,nobarrier,inode64,allocsize=16m 0 0 /dev/rootvg/defectlv /ods_defect xfs nodev,noatime,nobarrier,inode64,allocsize=16m 0 0 /dev/rootvg/edclv /ods_edc xfs nodev,noatime,nobarrier,inode64,allocsize=16m 0 0 /dev/rootvg/mainlv /ods_main xfs nodev,noatime,nobarrier,inode64,allocsize=16m 0 0
/etc/fstab 文件是一个用于配置文件系统挂载的系统文件。该文件包含了每个文件系统的挂载点,文件系统类型,挂载选项以及挂载设备的信息。这些挂载选项是用于设置文件系统的特定行为的。
nodev:该选项表示该文件系统中不允许挂载设备文件。这意味着在该文件系统中不能创建设备文件,并且也不能将设备挂载到该文件系统上。
noatime:该选项表示在访问文件时不更新文件的访问时间。这意味着在该文件系统中,每次访问文件时,文件的最后访问时间不会更新。这可以减少文件系统的写入次数,从而提高磁盘性能。
nobarrier:该选项表示在向文件系统写入数据时不使用屏障。屏障是一种写入优化技术,用于保证数据写入的有序性。但是,在某些情况下,使用屏障会导致性能降低,因此可以使用 nobarrier 选项来禁用屏障。
inode64:该选项表示使用 64 位 inode 编号。inode 是一个数据结构,用于储存文件的元数据
allocsize 设置缓冲I / O端的文件预分配的大小时,延迟分配写出时。此选项的页面大小(通常4KiB)到1GiB,包括有效值,功率为2的增量。
xfs_growfs 和 mkfs.xfs区别
mkfs.xfs格式化没有做lvm的磁盘
[root@meta /etc/prometheus]#mkfs.xfs -f /dev/sdb1 # 不同文件系统使用不同的格式化命令 meta-data=/dev/sdb1 isize=512 agcount=4, agsize=3276736 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=13106944, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=6399, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0
xfs_growfs格式化做了lvm的磁盘
– update 2022年11月4日09:45:33
umount报 target is busy
[root@meta /tmp]#df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 7.8G 0 7.8G 0% /dev tmpfs 7.8G 180K 7.8G 1% /dev/shm tmpfs 7.8G 792M 7.0G 10% /run tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup /dev/sda1 40G 21G 20G 51% / /dev/sdb1 50G 13G 38G 26% /prometheus tmpfs 1.6G 0 1.6G 0% /run/user/0 [root@meta /tmp]#mount /dev/sdb1 /prometheus
[root@meta /data/prometheus/data]#umount -v /dev/sdb1 umount: /data: target is busy. (In some cases useful info about processes that use the device is found by lsof(8) or fuser(1))
解决
对付系统文件正忙的另一种方法是执行延迟卸载: [root@meta /data/prometheus/data]#umount -vl /data/ umount: /data (/dev/sdb1) unmounted 延迟卸载(lazy unmount)会立即卸载目录树里的文件系统,等到设备不再繁忙时才清理所有相关资源