CentOS8 磁盘管理

简介: 磁盘使用情况、磁盘大小调整
磁盘管理Part1 :
1. 磁盘或者笔记本设备与Linux系统的适配性 :
  1. 不同厂商硬件设备对Linux系统的支持与否,可以查看以下链接:

    RedHat 硬件支持 :

    • Red Hat certified hardware. here
    • Red Hat certified software. here
    • Red Hat certified cloud and service providers. here
    • Certified workstations. here
  2. 不同品牌型号笔记本对Linux系统的支持与否,可查看here
2. Linux系统中的硬件设备

​ 在Linux系统中,硬件设备均被视为“文件”,而大部分硬件设备文件存放于目录/dev之下。以SATA接口的硬盘为例,硬盘的名称形式为/dev/sd[a-d] . 另外,the linux kernel archives 的详细信息可以查看 here

另外,可以借助虚拟机创建虚拟化环境用于linux系统的运行,虚拟化技术可以参考 Fedora Document

3. 磁盘分区

实体机器使用的磁盘名,形如/dev/sd[a-d], 而虚拟机环境下,可能会使用形如/dev/vd[a-p]磁盘名,虚拟机以virtlO接口接入磁盘时,使用virtlO界面时,磁盘文件名形如/dev/vd[a-p], 而SATA/USB/SAS等磁盘接口都是使用SCSI模块来驱动的,因此这些接口的磁盘设备名称都为/dev/sd[a-p]的格式。根据Linux检测到的磁盘顺序对磁盘设备加以命名。

磁盘第一个扇区存储整个磁盘重要信息,这种分区格式称为MBR(Master Boot Record)。随着磁盘容量的增加,部分操作系统已经不能读取大于2G的磁盘文件,因此出现了新的磁盘分区格式GPT(GUID partition table)

磁盘结构图示: 包括: platter/ actuator arm/disk sector/ track/ track sector/ cluster

来源:AaronTTEJ3M

分区表的两种格式:

MSDOS(MBR) 分区表格式:

GUID partition table, GPT 磁盘分区表

4. 磁盘操作命令
  • 1.fdisk : Display or manipulate a disk partition table.
 # fdisk --help

Usage:
 fdisk [options] <disk>      change partition table
 fdisk [options] -l [<disk>] list partition table(s)

Display or manipulate a disk partition table.

Options:
 -b, --sector-size <size>      physical and logical sector size
 -B, --protect-boot            don't erase bootbits when creating a new label
 -c, --compatibility[=<mode>]  mode is 'dos' or 'nondos' (default)
 -L, --color[=<when>]          colorize output (auto, always or never)
                                 colors are enabled by default
 -l, --list                    display partitions and exit
 -o, --output <list>           output columns
 -t, --type <type>             recognize specified partition table type only
 -u, --units[=<unit>]          display units: 'cylinders' or 'sectors' (default)
 -s, --getsz                   display device size in 512-byte sectors [DEPRECATED]
     --bytes                   print SIZE in bytes rather than in human readable format
 -w, --wipe <mode>             wipe signatures (auto, always or never)
 -W, --wipe-partitions <mode>  wipe signatures from new partitions (auto, always or never)

 -C, --cylinders <number>      specify the number of cylinders
 -H, --heads <number>          specify the number of heads
 -S, --sectors <number>        specify the number of sectors per track

 -h, --help                    display this help
 -V, --version                 display version


 # fdisk -l

Disk /dev/sda: 45 GiB, 48318382080 bytes, 94371840 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: dos
Disk identifier: 0x0f689d0d

Device     Boot    Start      End  Sectors Size Id Type
/dev/sda1  *        2048  2099199  2097152   1G 83 Linux
/dev/sda2        2099200 41943039 39843840  19G 8e Linux LVM
/dev/sda3       41943040 94371839 52428800  25G 8e Linux LVM


Disk /dev/mapper/cl-root: 37 GiB, 39724253184 bytes, 77586432 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 /dev/mapper/cl-swap: 2 GiB, 2147483648 bytes, 4194304 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
    1. df : Show information about the file system on which each FILE resides,
      or all file systems by default.

      $ df --help 
      Mandatory arguments to long options are mandatory for short options too.
        -a, --all             include pseudo, duplicate, inaccessible file systems
        -B, --block-size=SIZE  scale sizes by SIZE before printing them; e.g.,
                                 '-BM' prints sizes in units of 1,048,576 bytes;
                                 see SIZE format below
            --direct          show statistics for a file instead of mount point
        -h, --human-readable  print sizes in powers of 1024 (e.g., 1023M)
        -H, --si              print sizes in powers of 1000 (e.g., 1.1G)
        -i, --inodes          list inode information instead of block usage
        -k                    like --block-size=1K
        -l, --local           limit listing to local file systems
            --no-sync         do not invoke sync before getting usage info (default)
            --output[=FIELD_LIST]  use the output format defined by FIELD_LIST,
                                     or print all fields if FIELD_LIST is omitted.
        -P, --portability     use the POSIX output format
            --sync            invoke sync before getting usage info
            --total           elide all entries insignificant to available space,
                                and produce a grand total
        -t, --type=TYPE       limit listing to file systems of type TYPE
        -T, --print-type      print file system type
        -x, --exclude-type=TYPE   limit listing to file systems not of type TYPE
        -v                    (ignored)
            --help     display this help and exit
            --version  output version information and exit
      
      $ df -a 
      
      Filesystem          1K-blocks     Used Available Use% Mounted on
      sysfs                       0        0         0    - /sys
      proc                        0        0         0    - /proc
      devtmpfs              5002356        0   5002356   0% /dev
      securityfs                  0        0         0    - /sys/kernel/security
      tmpfs                 5020460        0   5020460   0% /dev/shm
      devpts                      0        0         0    - /dev/pts
      tmpfs                 5020460    10204   5010256   1% /run
      tmpfs                 5020460        0   5020460   0% /sys/fs/cgroup
      cgroup                      0        0         0    - /sys/fs/cgroup/systemd
      pstore                      0        0         0    - /sys/fs/pstore
      bpf                         0        0         0    - /sys/fs/bpf
      cgroup                      0        0         0    - /sys/fs/cgroup/perf_event
      ...
      cgroup                      0        0         0    - /sys/fs/cgroup/devices
      cgroup                      0        0         0    - /sys/fs/cgroup/net_cls,net_prio
      cgroup                      0        0         0    - /sys/fs/cgroup/pids
      ...
      configfs                    0        0         0    - /sys/kernel/config
      /dev/mapper/cl-root  38782976 23065508  15717468  60% /
      selinuxfs                   0        0         0    - /sys/fs/selinux
      debugfs                     0        0         0    - /sys/kernel/debug
      hugetlbfs                   0        0         0    - /dev/hugepages
      mqueue                      0        0         0    - /dev/mqueue
      systemd-1                   0        0         0    - /proc/sys/fs/binfmt_misc
      /dev/sda1              999320   146144    784364  16% /boot
      sunrpc                      0        0         0    - /var/lib/nfs/rpc_pipefs
      tmpfs                 1004092     1180   1002912   1% /run/user/42
      tmpfs                 1004092     6956    997136   1% /run/user/1000
      gvfsd-fuse                  0        0         0    - /run/user/1000/gvfs
      fusectl                     0        0         0    - /sys/fs/fuse/connections
      
    2. lvs : Display information about logical volumes
    3. parted :

      # parted
      Usage: parted [OPTION]... [DEVICE [COMMAND [PARAMETERS]...]...]
      Apply COMMANDs with PARAMETERS to DEVICE.  If no COMMAND(s) are given, run in
      interactive mode.
      
      OPTIONs:
        -h, --help                      displays this help message
        -l, --list                      lists partition layout on all block devices
        -m, --machine                   displays machine parseable output
        -s, --script                    never prompts for user intervention
        -v, --version                   displays the version
        -a, --align=[none|cyl|min|opt]  alignment for new partitions
      
      COMMANDs:
        align-check TYPE N                        check partition N for TYPE(min|opt)
              alignment
        help [COMMAND]                           print general help, or help on
              COMMAND
        mklabel,mktable LABEL-TYPE               create a new disklabel (partition
              table)
        mkpart PART-TYPE [FS-TYPE] START END     make a partition
        name NUMBER NAME                         name partition NUMBER as NAME
        print [devices|free|list,all|NUMBER]     display the partition table,
              available devices, free space, all found partitions, or a particular
              partition
        quit                                     exit program
        rescue START END                         rescue a lost partition near START
              and END
        resizepart NUMBER END                    resize partition NUMBER
        rm NUMBER                                delete partition NUMBER
        select DEVICE                            choose the device to edit
        disk_set FLAG STATE                      change the FLAG on selected device
        disk_toggle [FLAG]                       toggle the state of FLAG on selected
              device
        set NUMBER FLAG STATE                    change the FLAG on partition NUMBER
        toggle [NUMBER [FLAG]]                   toggle the state of FLAG on partition
              NUMBER
        unit UNIT                                set the default unit to UNIT
        version                                  display the version number and
              copyright information of GNU Parted
      
      
    4. lsblk : List information about block devices.

      # lsblk
      NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
      sda           8:0    0   45G  0 disk 
      ├─sda1        8:1    0    1G  0 part /boot
      ├─sda2        8:2    0   19G  0 part 
      │ ├─cl-root 253:0    0   37G  0 lvm  /
      │ └─cl-swap 253:1    0    2G  0 lvm  [SWAP]
      └─sda3        8:3    0   25G  0 part 
        └─cl-root 253:0    0   37G  0 lvm  /
      sr0          11:0    1 1024M  0 rom  
      
    5. pvs : Display information about physical volumes

       # pvs
        PV         VG Fmt  Attr PSize   PFree 
        /dev/sda2  cl lvm2 a--  <19.00g     0 
        /dev/sda3  cl lvm2 a--  <25.00g <5.00g
      
    6. resize2fs :

      # resize2fs
      resize2fs 1.45.6 (20-Mar-2020)
      Usage: resize2fs [-d debug_flags] [-f] [-F] [-M] [-P] [-p] device [-b|-s|new_size] [-S RAID-stride] [-z undo_file]
      
      
    7. xfs_growfs :

      Usage: xfs_growfs [options] mountpoint
      
      Options:
          -d          grow data/metadata section
          -l          grow log section
          -r          grow realtime section
          -n          don't change anything, just show geometry
          -i          convert log from external to internal format
          -t          alternate location for mount table (/etc/mtab)
          -x          convert log from internal to external format
          -D size     grow data/metadata section to size blks
          -L size     grow/shrink log section to size blks
          -R size     grow realtime section to size blks
          -e size     set realtime extent size to size blks
          -m imaxpct  set inode max percent to imaxpct
          -V          print version information
      
    8. vgdisplay : Display volume group information

        vgdisplay
          [ -A|--activevolumegroups ]
          [ -c|--colon ]
          [ -C|--columns ]
          [ -o|--options String ]
          [ -S|--select String ]
          [ -s|--short ]
          [ -O|--sort String ]
      ...
    9. vgextend : Add physical volumes to a volume group

        vgextend VG PV ...
          [ -A|--autobackup y|n ]
          [ -f|--force ]
          [ -Z|--zero y|n ]
          [ -M|--metadatatype lvm2 ]
          [    --labelsector Number ]
          [    --metadatasize Size[m|UNIT] ]
      ...
      
    10. `lvdisplay : Display information about a logical volume

        lvdisplay
          [ -a|--all ]
          [ -c|--colon ]
          [ -C|--columns ]
          [ -H|--history ]
          [ -m|--maps ]
          [ -o|--options String ]
          [ -O|--sort String ]
          [ -S|--select String ]
      ...
    11. lvextend : Add space to a logical volume

        Extend an LV by a specified size.
        lvextend -L|--size [+]Size[m|UNIT] LV
          [ -l|--extents [+]Number[PERCENT] ]
          [ -r|--resizefs ]
          [ -i|--stripes Number ]
          [ -I|--stripesize Size[k|UNIT] ]
          [    --poolmetadatasize [+]Size[m|UNIT] ]
          [ COMMON_OPTIONS ]
          [ PV ... ]
      
        Extend an LV by specified PV extents.
        lvextend LV PV ...
          [ -r|--resizefs ]
          [ -i|--stripes Number ]
          [ -I|--stripesize Size[k|UNIT] ]
          [ COMMON_OPTIONS ]
      
        Extend a pool metadata SubLV by a specified size.
        lvextend --poolmetadatasize [+]Size[m|UNIT] LV_thinpool
          [ -i|--stripes Number ]
          [ -I|--stripesize Size[k|UNIT] ]
          [ COMMON_OPTIONS ]
          [ PV ... ]
      
        Extend an LV according to a predefined policy.
        lvextend --usepolicies LV_snapshot_thinpool
          [ -r|--resizefs ]
          [ COMMON_OPTIONS ]
          [ PV ... ]
      
    12. du -sch *

      Usage: du [OPTION]... [FILE]...
        or:  du [OPTION]... --files0-from=F
      Summarize disk usage of the set of FILEs, recursively for directories.
      
      
虚拟机中磁盘管理 :
Issue : CentOS8 in the VMware: No space left on device
1. Issue Description :

Initially, 20G Hard Disk(SCSI) was portioned to the CentOS8 in the virtual machine. For disk room occupied by the genome index file , genome reference ,rawdata and so on, and larger room would be required in the downstream analysis, so the disk resize would be rather necessary.

2. Solutions :

extend the logical volume :

NOTE : backup of the virtual machine through snapshots or commands (e.g. cp )

    1. identify the device and confirm the size : fdisk -l :
    2. create a new primary partition :

      • (1) operate on the new device :fdisk /dev/sd[a-p]
      • (2) print the partition table : press p
      • (3) create a new primary partition: press n
      • (4) primary type : press p
      • (5) partition number , depending on the output of the partition table print. :
      • (6) change system's partition ID : t
      • (7) select the newly creation partition :
      • (8) change the Hex Code of the partition for Linux LVM : type 8e
      • (9) write the change to the partition table : press w
    1. reboot the system CentOS8
    2. verify the changes has been written into the partition table and the type of the new partition is 8e : fdisk -l
    3. convert the new partition to a physical volume : pvcreate /dev/sd*
    4. extend the physical volume :

      • (1) df : show information about the file system , identify the high used , low available and Mountpoint
      • (2) vgdisplay: to check the volume group
      • (3) extend physical volume : vgextend VolumeGroup /dev/sd*
    5. verify how many physical extents are available to the VolumeGroup : vgdisplay VolumeGroup | grep "Free"
    6. extend the logical volume :

      lvdisplay : to determine which logical volume to extend

      lvextend -L+*G /dev/VolumeGroup/LogicalVolume :

    7. expand the ext3 filesystem online , inside of logical volume :

      xfs_growfs dir : dir is the volume group mountpoint

    8. verify that the dir file system has the new space available :

      df -h dir

      ----

      reference :

      1.Extending a logical volume in a virtual machine running Red Hat or Cent OS

      2.CentOS Manual Partitioning

目录
相关文章
|
Linux
CentOS卸载LVM磁盘的方法
CentOS卸载LVM磁盘的方法
200 0
|
Linux
CentOS7下使用growpart工具进行磁盘热扩容
CentOS7下使用growpart工具进行磁盘热扩容
922 0
CentOS7下使用growpart工具进行磁盘热扩容
|
Linux
CentOS7 系统磁盘空间不足,如何进行扩容
CentOS7 系统磁盘空间不足,如何进行扩容
1540 0
CentOS7 系统磁盘空间不足,如何进行扩容
|
Linux
CentOS7.X磁盘挂载及取消挂载
CentOS7.X磁盘挂载及取消挂载
7891 0
|
4月前
|
存储 监控 Linux
【一键解锁神秘力量!】CentOS 7 磁盘分区与挂载终极指南 —— 从零到英雄的磁盘管理实战秘籍!
【8月更文挑战第9天】随着业务扩展和技术进步,服务器硬盘容量需求增加。本文通过实例介绍如何在CentOS 7中管理大容量硬盘(如1TB)。首先确认未使用的硬盘(如`/dev/sdb`),然后使用`fdisk`创建分区(一个200GB的日志分区和一个剩余空间的用户文件分区)。接着使用`mkfs.ext4`格式化分区,并创建挂载点(如`/mnt/log`和`/mnt/userfiles`)。最后,通过修改`/etc/fstab`实现分区的永久挂载。注意事项包括备份数据、合理规划分区以及定期监控磁盘使用情况等。这些步骤有助于高效管理和利用磁盘空间。
386 1
|
4月前
|
Linux
阿里云CentOS数据盘挂载(磁盘扩容)
阿里云CentOS数据盘挂载(磁盘扩容)
248 0
|
7月前
|
Linux
centos7实现磁盘挂载,解挂,开机自动挂载,解决挂载文件覆盖问题
centos7实现磁盘挂载,解挂,开机自动挂载,解决挂载文件覆盖问题
445 0
|
Linux
Linux centos7.x系统将/home磁盘分配给/
然后再执行umount /home就可以成功了 , 同时执行以下命令把逻辑卷删除了
102 0
|
Linux
Centos7 系列:磁盘挂载和磁盘扩容(新加硬盘方式)
在Centos 7 系统中,新添加硬盘,并将其挂载到自定义的新目录下;新添加硬盘,并为已有硬盘扩容。
3366 0
Centos7 系列:磁盘挂载和磁盘扩容(新加硬盘方式)
|
Linux 网络安全
阿里云centos 挂载新磁盘
阿里云centos 挂载新磁盘
654 2