美文网首页
centos单目录挂载多块硬盘

centos单目录挂载多块硬盘

作者: 岑吾 | 来源:发表于2022-01-26 00:12 被阅读0次

    同一目录无法重复挂载,后挂载的会覆盖之前挂载的磁盘。但是现在需要将2块磁盘并行挂载到同一目录。

    基本概念

    • PV(Physical Volume)- 物理卷
      物理卷在逻辑卷管理中处于最底层,它可以是实际物理硬盘上的分区,也可以是整个物理硬盘,也可以是raid设备。
    • VG(Volumne Group)- 卷组
      卷组建立在物理卷之上,一个卷组中至少要包括一个物理卷,在卷组建立之后可动态添加物理卷到卷组中。一个逻辑卷管理系统工程中可以只有一个卷组,也可以拥有多个卷组。
    • LV(Logical Volume)- 逻辑卷
      逻辑卷建立在卷组之上,卷组中的未分配空间可以用于建立新的逻辑卷,逻辑卷建立后可以动态地扩展和缩小空间。系统中的多个逻辑卷可以属于同一个卷组,也可以属于不同的多个卷组
    • PE(Physical Extent)- 物理块

    操作步骤

    1. 查看磁盘

    使用fdisk -l查看是否有空余的磁盘可用。可以看到有二块4T磁盘分别为:/dev/sdb 、/dev/sdc

    2. 创建分区

    分别为2块硬盘创建分区,需要注意的是,与挂载单块磁盘不同,创建分区后需要修改分区类型。

    fdisk /dev/sdb
    # 依次输入n 回车 回车 回车 t l 31 w
    
    fdisk /dev/sdc
    # 依次输入n 回车 回车 回车 t l 31 w
    
    • n:创建分区,回车选择默认分区和大小使用全部硬盘
    • t:修改分区类型,回车选择默认分区
    • l:列出所有分区类型,
    • 31:指Linux LVM,不同版本前的数字不一样,从l显示的列表中找到Linux LVM类型就行了。
    • w:保存并退出
    [root@zngw ~]# fdisk /dev/sdc
    WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
    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.
    
    
    Command (m for help): n
    Partition number (1-128, default 2): 
    First sector (34-7814037134, default 2048): 
    Last sector, +sectors or +size{K,M,G,T,P} (2048-7814037134, default 7814037134): 
    Created partition 1
    
    
    Command (m for help): t
    Selected partition 1
    Partition type (type L to list all types): l
      1 EFI System                     C12A7328-F81F-11D2-BA4B-00A0C93EC93B
      2 MBR partition scheme           024DEE41-33E7-11D3-9D69-0008C781F39F
      3 Intel Fast Flash               D3BFE2DE-3DAF-11DF-BA40-E3A556D89593
      4 BIOS boot                      21686148-6449-6E6F-744E-656564454649
      5 Sony boot partition            F4019732-066E-4E12-8273-346C5641494F
      6 Lenovo boot partition          BFBFAFE7-A34F-448A-9A5B-6213EB736C22
      7 PowerPC PReP boot              9E1A2D38-C612-4316-AA26-8B49521E5A8B
      8 ONIE boot                      7412F7D5-A156-4B13-81DC-867174929325
      9 ONIE config                    D4E6E2CD-4469-46F3-B5CB-1BFF57AFC149
     10 Microsoft reserved             E3C9E316-0B5C-4DB8-817D-F92DF00215AE
     11 Microsoft basic data           EBD0A0A2-B9E5-4433-87C0-68B6B72699C7
     12 Microsoft LDM metadata         5808C8AA-7E8F-42E0-85D2-E1E90434CFB3
     13 Microsoft LDM data             AF9B60A0-1431-4F62-BC68-3311714A69AD
     14 Windows recovery environment   DE94BBA4-06D1-4D40-A16A-BFD50179D6AC
     15 IBM General Parallel Fs        37AFFC90-EF7D-4E96-91C3-2D7AE055B174
     16 Microsoft Storage Spaces       E75CAF8F-F680-4CEE-AFA3-B001E56EFC2D
     17 HP-UX data                     75894C1E-3AEB-11D3-B7C1-7B03A0000000
     18 HP-UX service                  E2A1E728-32E3-11D6-A682-7B03A0000000
     19 Linux swap                     0657FD6D-A4AB-43C4-84E5-0933C84B4F4F
     20 Linux filesystem               0FC63DAF-8483-4772-8E79-3D69D8477DE4
     21 Linux server data              3B8F8425-20E0-4F3B-907F-1A25A76F98E8
     22 Linux root (x86)               44479540-F297-41B2-9AF7-D131D5F0458A
     23 Linux root (ARM)               69DAD710-2CE4-4E3C-B16C-21A1D49ABED3
     24 Linux root (x86-64)            4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709
     25 Linux root (ARM-64)            B921B045-1DF0-41C3-AF44-4C6F280D3FAE
     26 Linux root  (IA-64)             993D8D3D-F80E-4225-855A-9DAF8ED7EA97
     27 Linux reserved                 8DA63339-0007-60C0-C436-083AC8230908
     28 Linux home                     933AC7E1-2EB4-4F13-B844-0E14E2AEF915
     29 Linux RAID                     A19D880F-05FC-4D3B-A006-743F0F84911E
     30 Linux extended boot            BC13C2FF-59E6-4262-A352-B275FD6F7172
     31 Linux LVM                      E6D6D379-F507-44C2-A23C-238F2A3DF928
     32 FreeBSD data                   516E7CB4-6ECF-11D6-8FF8-00022D09712B
     33 FreeBSD boot                   83BD6B9D-7F41-11DC-BE0B-001560B84F0F
     34 FreeBSD swap                   516E7CB5-6ECF-11D6-8FF8-00022D09712B
     35 FreeBSD UFS                    516E7CB6-6ECF-11D6-8FF8-00022D09712B
     36 FreeBSD ZFS                    516E7CBA-6ECF-11D6-8FF8-00022D09712B
     37 FreeBSD Vinum                  516E7CB8-6ECF-11D6-8FF8-00022D09712B
     38 Apple HFS/HFS+                 48465300-0000-11AA-AA11-00306543ECAC
     39 Apple UFS                      55465300-0000-11AA-AA11-00306543ECAC
     40 Apple RAID                     52414944-0000-11AA-AA11-00306543ECAC
     41 Apple RAID offline             52414944-5F4F-11AA-AA11-00306543ECAC
     42 Apple boot                     426F6F74-0000-11AA-AA11-00306543ECAC
     43 Apple label                    4C616265-6C00-11AA-AA11-00306543ECAC
     44 Apple TV recovery              5265636F-7665-11AA-AA11-00306543ECAC
     45 Apple Core storage             53746F72-6167-11AA-AA11-00306543ECAC
     46 Solaris boot                   6A82CB45-1DD2-11B2-99A6-080020736631
     47 Solaris root                   6A85CF4D-1DD2-11B2-99A6-080020736631
     48 Solaris /usr & Apple ZFS       6A898CC3-1DD2-11B2-99A6-080020736631
     49 Solaris swap                   6A87C46F-1DD2-11B2-99A6-080020736631
     50 Solaris backup                 6A8B642B-1DD2-11B2-99A6-080020736631
     51 Solaris /var                   6A8EF2E9-1DD2-11B2-99A6-080020736631
     52 Solaris /home                  6A90BA39-1DD2-11B2-99A6-080020736631
     53 Solaris alternate sector       6A9283A5-1DD2-11B2-99A6-080020736631
     54 Solaris reserved 1             6A945A3B-1DD2-11B2-99A6-080020736631
     55 Solaris reserved 2             6A9630D1-1DD2-11B2-99A6-080020736631
     56 Solaris reserved 3             6A980767-1DD2-11B2-99A6-080020736631
     57 Solaris reserved 4             6A96237F-1DD2-11B2-99A6-080020736631
     58 Solaris reserved 5             6A8D2AC7-1DD2-11B2-99A6-080020736631
     59 NetBSD swap                    49F48D32-B10E-11DC-B99B-0019D1879648
     60 NetBSD FFS                     49F48D5A-B10E-11DC-B99B-0019D1879648
     61 NetBSD LFS                     49F48D82-B10E-11DC-B99B-0019D1879648
     62 NetBSD concatenated            2DB519C4-B10E-11DC-B99B-0019D1879648
     63 NetBSD encrypted               2DB519EC-B10E-11DC-B99B-0019D1879648
     64 NetBSD RAID                    49F48DAA-B10E-11DC-B99B-0019D1879648
     65 ChromeOS kernel                FE3A2A5D-4F32-41A7-B725-ACCC3285A309
     66 ChromeOS root fs               3CB8E202-3B7E-47DD-8A3C-7FF2A13CFCEC
     67 ChromeOS reserved              2E0A753D-9E48-43B0-8337-B15192CB1B5E
     68 MidnightBSD data               85D5E45A-237C-11E1-B4B3-E89A8F7FC3A7
     69 MidnightBSD boot               85D5E45E-237C-11E1-B4B3-E89A8F7FC3A7
     70 MidnightBSD swap               85D5E45B-237C-11E1-B4B3-E89A8F7FC3A7
     71 MidnightBSD UFS                0394EF8B-237E-11E1-B4B3-E89A8F7FC3A7
     72 MidnightBSD ZFS                85D5E45D-237C-11E1-B4B3-E89A8F7FC3A7
     73 MidnightBSD Vinum              85D5E45C-237C-11E1-B4B3-E89A8F7FC3A7
     74 Ceph Journal                   45B0969E-9B03-4F30-B4C6-B4B80CEFF106
     75 Ceph Encrypted Journal         45B0969E-9B03-4F30-B4C6-5EC00CEFF106
     76 Ceph OSD                       4FBD7E29-9D25-41B8-AFD0-062C0CEFF05D
     77 Ceph crypt OSD                 4FBD7E29-9D25-41B8-AFD0-5EC00CEFF05D
     78 Ceph disk in creation          89C57F98-2FE5-4DC0-89C1-F3AD0CEFF2BE
     79 Ceph crypt disk in creation    89C57F98-2FE5-4DC0-89C1-5EC00CEFF2BE
     80 OpenBSD data                   824CC7A0-36A8-11E3-890A-952519AD3F61
     81 QNX6 file system               CEF5A9AD-73BC-4601-89F3-CDEEEEE321A1
     82 Plan 9 partition               C91818F9-8025-47AF-89D2-F030D7000C2C
    
    Partition type (type L to list all types): 31
    Changed type of partition 'Linux filesystem' to 'Linux LVM'
    
    Command (m for help): w
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    Syncing disks.
    

    3. 查看创建的分区

    fdisk -l查看分区类型为Linux LVM则表示成功。

    4. 创建PV

    pvcreate /dev/sdb1 /dev/sdc1
      Physical volume "/dev/sdb1" successfully created.
      Physical volume "/dev/sdc1" successfully created.
    

    5. 查看PV

    pvdisplay
      --- Physical volume ---
      PV Name               /dev/sda2
      VG Name               centos
      PV Size               <110.79 GiB / not usable 4.00 MiB
      Allocatable           yes 
      PE Size               4.00 MiB
      Total PE              28361
      Free PE               1
      Allocated PE          28360
      PV UUID               TboH4i-K5H1-xgAc-OJ30-yd3p-43KD-hJSkyf
       
      "/dev/sdb1" is a new physical volume of "<3.64 TiB"
      --- NEW Physical volume ---
      PV Name               /dev/sdb1
      VG Name               
      PV Size               <3.64 TiB
      Allocatable           NO
      PE Size               0   
      Total PE              0
      Free PE               0
      Allocated PE          0
      PV UUID               5fPy7S-IuHG-50Cb-HwGC-TF7f-tWsY-XkwfZi
       
      "/dev/sdc1" is a new physical volume of "<3.64 TiB"
      --- NEW Physical volume ---
      PV Name               /dev/sdc1
      VG Name               
      PV Size               <3.64 TiB
      Allocatable           NO
      PE Size               0   
      Total PE              0
      Free PE               0
      Allocated PE          0
      PV UUID               bCyGex-lzGo-04NX-V4fO-k5Fy-nQGZ-pYihEJ
    

    6. 创建VG 卷组

    lvm_data是vg组的名字,可以自定义

    vgcreate lvm_data /dev/sdb1 /dev/sdc1
      Volume group "lvm_data" successfully created
    

    7. 创建LV 逻辑卷

    -L是指定大小(可以从fdisk -l中查看每个硬盘大小累加)、-n是自定义lv的名称

    lvcreate -L 7450G -n lvmdata_1 lvm_data
      Logical volume "lvmdata_1" created.
    

    8. 查看分区

    到这里分区就创建完成了,后面的步骤和挂载单块磁盘一样

    fdisk -l
    
    Disk /dev/mapper/lvm_data-lvmdata_1: 7999.4 GB, 7999376588800 bytes, 15623782400 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
    

    9. 格式化

    mkfs.ext4 /dev/mapper/lvm_data-lvmdata_1
    

    10. 挂载到目录

    将分区挂载到需要保存文件的目录即可。

    mount /dev/mapper/lvm_data-lvmdata_1 /data
    

    11. 设备开机自动挂载

    vim /etc/fstab
    
    /dev/mapper/lvm_data-lvmdata_1 /data ext4 defaults 0 0
    
    • 第一列: 设备或磁盘分区

    • 第二列: 挂载点

    • 第三列: 设备类型或文件系统类型

    • 第四列:
      挂载选项,这里用来填写设置选项,各个选项用逗号隔开。详细选项请用命令 man mount 来查看。这里有个非常重要的关键字需要了解一下:defaults,它代表包含了选项rw,suid,dev,exec,auto,nouser和 async。

    • 第五列: dump选项,此处为1的话,表示要将整个<file sysytem>里的内容备份;为0的话,表示不备份。现在很少用到dump这个工具,在这里一般选0。

    • 第六列: 该选项用来指定如何使用fsck来检查硬盘。如果这里填0,则不检查;挂载点为 / 的(即根分区),必须在这里填写1,其他的都不能填写1。

    11. 检查结果

    df -h
    Filesystem                      Size  Used Avail Use% Mounted on
    ... 省略部分
    /dev/mapper/lvm_data-lvmdata_1  7.3T   93M  6.9T   1% /data
    

    删除逻辑卷

    umount /dev/mapper/lvm_data-lvmdata_1
    lvremove /dev/mapper/lvm_data-lvmdata_1
    vgremove lvm_data
    pvremove /dev/sdb
    pvremove /dev/sdc
    

    相关文章

      网友评论

          本文标题:centos单目录挂载多块硬盘

          本文链接:https://www.haomeiwen.com/subject/tosmhrtx.html