美文网首页
day18-磁盘管理(1)

day18-磁盘管理(1)

作者: 恩楠 | 来源:发表于2019-08-19 13:36 被阅读0次

    添加磁盘
    在虚拟机中添加一个1T和4T的磁盘

    添加磁盘
    可以通过查看/dev下面的设备或者lsblk命令确认磁盘是否添加成功
    [root@ennan ~]# ll /dev/sd*
    brw-rw----. 1 root disk 8,  0 Aug 19 19:32 /dev/sda
    brw-rw----. 1 root disk 8,  1 Aug 19 19:32 /dev/sda1
    brw-rw----. 1 root disk 8,  2 Aug 19 19:32 /dev/sda2
    brw-rw----. 1 root disk 8,  3 Aug 19 19:32 /dev/sda3
    brw-rw----. 1 root disk 8, 16 Aug 19 19:32 /dev/sdb
    brw-rw----. 1 root disk 8, 32 Aug 19 19:32 /dev/sdc
    # /dev/seb /dev/sdc为新添加的磁盘
    
    [root@ennan ~]# lsblk 
    NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sda      8:0    0   20G  0 disk 
    ├─sda1   8:1    0    1G  0 part /boot
    ├─sda2   8:2    0  800M  0 part [SWAP]
    └─sda3   8:3    0 18.2G  0 part /
    sdb      8:16   0    1T  0 disk 
    sdc      8:32   0    4T  0 disk 
    sr0     11:0    1  4.3G  0 rom  
    # /dev/seb /dev/sdc为新添加的磁盘
    

    创建分区
    通过fdisk创建主分区

    [root@ennan ~]# 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 0xaa8a2dfe.
    
    Command (m for help): n
    Partition type:
       p   primary (0 primary, 0 extended, 4 free)
       # p为主分区
       e   extended
       # e为扩展分区
    Select (default p): 
    Using default response p
    Partition number (1-4, default 1): 
    First sector (2048-2147483647, default 2048): 
    Using default value 2048
    Last sector, +sectors or +size{K,M,G} (2048-2147483647, default 2147483647): +10G  #选择创建的分区大小
    Partition 1 of type Linux and of size 10 GiB is set
    
    Command (m for help): p
    
    Disk /dev/sdb: 1099.5 GB, 1099511627776 bytes, 2147483648 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: 0xaa8a2dfe
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sdb1            2048    20973567    10485760   83  Linux
    

    创建扩展分区

    Command (m for help): n       
    Partition type:
       p   primary (1 primary, 0 extended, 3 free)
       e   extended
    Select (default p): e
    Partition number (2-4, default 2): 
    First sector (20973568-2147483647, default 20973568): 
    Using default value 20973568
    Last sector, +sectors or +size{K,M,G} (20973568-2147483647, default 2147483647): 
    Using default value 2147483647
    Partition 2 of type Extended and of size 1014 GiB is set
    
    Command (m for help): p
    
    Disk /dev/sdb: 1099.5 GB, 1099511627776 bytes, 2147483648 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: 0xaa8a2dfe
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sdb1            2048    20973567    10485760   83  Linux
    /dev/sdb2        20973568  2147483647  1063255040    5  Extended
    

    创建逻辑分区

    Command (m for help): n
    Partition type:
       p   primary (1 primary, 1 extended, 2 free)
       l   logical (numbered from 5)
    Select (default p): l
    Adding logical partition 5
    First sector (20975616-2147483647, default 20975616): 
    Using default value 20975616
    Last sector, +sectors or +size{K,M,G} (20975616-2147483647, default 2147483647): +20G
    Partition 5 of type Linux and of size 20 GiB is set
    
    Command (m for help): p
    
    Disk /dev/sdb: 1099.5 GB, 1099511627776 bytes, 2147483648 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: 0xaa8a2dfe
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sdb1            2048    20973567    10485760   83  Linux
    /dev/sdb2        20973568  2147483647  1063255040    5  Extended
    /dev/sdb5        20975616    62918655    20971520   83  Linux
    

    保存分区信息

    Command (m for help): w
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    Syncing disks.
    

    查看分区信息

    [root@ennan ~]# lsblk 
    NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sda      8:0    0   20G  0 disk 
    ├─sda1   8:1    0    1G  0 part /boot
    ├─sda2   8:2    0  800M  0 part [SWAP]
    └─sda3   8:3    0 18.2G  0 part /
    sdb      8:16   0    1T  0 disk 
    ├─sdb1   8:17   0   10G  0 part 
    ├─sdb2   8:18   0    1K  0 part 
    └─sdb5   8:21   0   20G  0 part 
    sdc      8:32   0    4T  0 disk 
    sr0     11:0    1  4.3G  0 rom 
    

    格式化磁盘

    [root@ennan ~]# mkfs.xfs /dev/sdb1
    # 将/dev/sdb1格式化为xfs格式
    meta-data=/dev/sdb1              isize=512    agcount=4, agsize=655360 blks
             =                       sectsz=512   attr=2, projid32bit=1
             =                       crc=1        finobt=0, sparse=0
    data     =                       bsize=4096   blocks=2621440, imaxpct=25
             =                       sunit=0      swidth=0 blks
    naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
    log      =internal log           bsize=4096   blocks=2560, version=2
             =                       sectsz=512   sunit=0 blks, lazy-count=1
    realtime =none                   extsz=4096   blocks=0, rtextents=0
    [root@ennan ~]# mkfs.xfs /dev/sdb5
    # 将/dev/sdb5格式化为xfs格式
    meta-data=/dev/sdb5              isize=512    agcount=4, agsize=1310720 blks
             =                       sectsz=512   attr=2, projid32bit=1
             =                       crc=1        finobt=0, sparse=0
    data     =                       bsize=4096   blocks=5242880, imaxpct=25
             =                       sunit=0      swidth=0 blks
    naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
    log      =internal log           bsize=4096   blocks=2560, version=2
             =                       sectsz=512   sunit=0 blks, lazy-count=1
    realtime =none                   extsz=4096   blocks=0, rtextents=0
    

    挂载

    [root@ennan ~]# mkdir /sdb1
    [root@ennan ~]# mkdir /sdb5
    [root@ennan ~]# mount /dev/sdb1 /sdb1
    [root@ennan ~]# mount /dev/sdb5 /sdb5
    

    查看挂在后的空间

    [root@ennan ~]# df -h
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/sda3        19G   19G   33M 100% /
    devtmpfs        476M     0  476M   0% /dev
    tmpfs           487M     0  487M   0% /dev/shm
    tmpfs           487M  7.7M  479M   2% /run
    tmpfs           487M     0  487M   0% /sys/fs/cgroup
    /dev/sda1      1014M  127M  888M  13% /boot
    tmpfs            98M     0   98M   0% /run/user/0
    /dev/sdb1        10G   33M   10G   1% /sdb1
    /dev/sdb5        20G   33M   20G   1% /sdb5
    

    相关文章

      网友评论

          本文标题:day18-磁盘管理(1)

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