linux硬盘分区,LVS分区扩容,挂载mount

前言:前段时间gitlab服务器挂了,看了一下日志,提示空间满了。 df -m看了一下硬盘,满了。所以想来操作加一块盘上来。

完成下面的操作后: 硬盘使用30%

root@ubuntu:/home/liwei# df -m
Filesystem                  1M-blocks  Used Available Use% Mounted on
udev                             1951     0      1951   0% /dev
tmpfs                             395    12       383   3% /run
/dev/mapper/ubuntu--vg-root     78004 21704     52836  30% /
tmpfs                            1972     2      1971   1% /dev/shm
tmpfs                               5     0         5   0% /run/lock
tmpfs                            1972     0      1972   0% /sys/fs/cgroup
/dev/sda1                         472   160       288  36% /boot
tmpfs                               1     0         1   0% /run/lxcfs/controllers
tmpfs                             395     1       395   1% /run/user/112
tmpfs                             395     0       395   0% /run/user/0

下面我们进入正题:

1.fdisk -l 察看所有分区

Disk /dev/sda: 60 GiB, 64424509440 bytes, 125829120 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: 0xe868d67b

Device     Boot    Start       End  Sectors  Size Id Type
/dev/sda1  *        2048    999423   997376  487M 83 Linux
/dev/sda2        1001470  62912511 61911042 29.5G  5 Extended
/dev/sda3       62912512 125829119 62916608   30G 8e Linux LVM
/dev/sda5        1001472  62912511 61911040 29.5G 8e Linux LVM

Partition table entries are not in disk order.


Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 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: 0xe4879f9e

Device     Boot Start      End  Sectors Size Id Type
/dev/sdb1        2048 41943039 41940992  20G 83 Linux


Disk /dev/mapper/ubuntu--vg-root: 77.5 GiB, 83231768576 bytes, 162562048 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/ubuntu--vg-swap_1: 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

2.fdisk /dev/sdb1 对分区进行分区,使用m参看命令(PS:/sdb1,自己来看,判断对哪个进行分区,或者使用m命令,按F看有没有空间剩余)

Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): 


Help:

  DOS (MBR)
   a   toggle a bootable flag
   b   edit nested BSD disklabel
   c   toggle the dos compatibility flag

  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition

  Misc
   m   print this menu
   u   change display/entry units
   x   extra functionality (experts only)

  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file

  Save & Exit
   w   write table to disk and exit
   q   quit without saving changes

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table


Command (m for help): F

3.n 新建分区,p为主分区,一路回车。

4.t选择分区分类,输入8e代表逻辑分区,w保存。

下面有一个类型对照表:

Command (m for help): l

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris        
 1  FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-
 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden or  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     85  Linux extended  c7  Syrinx         
 5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data    
 6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility   
 8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt         
 9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access     
 a  OS/2 Boot Manag 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O        
 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor      
 c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad hi ea  Rufus alignment
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         eb  BeOS fs        
 f  W95 Ext'd (LBA) 54  OnTrackDM6      a6  OpenBSD         ee  GPT            
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        ef  EFI (FAT-12/16/
11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f0  Linux/PA-RISC b
12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f1  SpeedStor      
14  Hidden FAT16 <3 61  SpeedStor       ab  Darwin boot     f4  SpeedStor      
16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      f2  DOS secondary  
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fb  VMware VMFS    
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fc  VMware VMKCORE 
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fd  Linux raid auto
1c  Hidden W95 FAT3 75  PC/IX           bc  Acronis FAT32 L fe  LANstep        
1e  Hidden W95 FAT1 80  Old Minix       be  Solaris boot    ff  BBT            

硬盘分区设置完成以后,一般需要将系统重启以使设置生效,如果不想重启系统,可以使用“partprobe”命令使操作系统获知新的分区表情况。

例:执行partprobe命令重新探测“/dev/sdb”磁盘中分区情况的变化。

5.格式化分区:mkfs -V -t ext4 -c /dev/sdb1

命令:

mkfs

格式:

 mkfs –t 文件系统类型 分区设备

参数:

 -t : 给定档案系统的型式,Linux 的预设值为 ext2
 -c : 在制做档案系统前,检查该partition 是否有坏轨
 -V : 详细显示模式

例:
将/dev/sdb1格式化为ext4文件系统,同时检查是否有坏轨存在,并且将过程详细列出来 :

mkfs -V -t ext4 -c /dev/sdb1

将/dev/sdb5格式化为fat32文件系统。

  [root@localhost ~]# mkfs -t vfat /dev/sdb5

在这之前可以使用 df -Th 来看一下所需要扩展的分区的类型,是ext4,所以选择ext4

`pvcreate  /dev/sdb1`

建为物理卷

6.pvs察看可用的LVS卷组, 组名,lvdisplay + 组名可以看出卷的详细信息

root@ubuntu:/home/liwei# pvs
  PV         VG        Fmt  Attr PSize  PFree 
  /dev/sda3            lvm2 ---  30.00g 30.00g
  /dev/sda5  ubuntu-vg lvm2 a--  29.52g     0 
  /dev/sdb1  ubuntu-vg lvm2 a--  20.00g     0 

vgextend ubuntu-vg /dev/sdb1 来扩展组

7.使用cat /etc/fstab 来查看需要扩容的分卷名称。

root@ubuntu:/home/liwei# cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
/dev/mapper/ubuntu--vg-root /               ext4    errors=remount-ro 0       1
# /boot was on /dev/sda1 during installation
UUID=1df9dfd2-3dd9-4621-b6c7-580785db146b /boot           ext2    defaults        0       2
/dev/mapper/ubuntu--vg-swap_1 none            swap    sw              0       0
/dev/fd0        /media/floppy0  auto    rw,user,noauto,exec,utf8 0       0

我们需要扩容的是dev/mapper/ubuntu--vg-root

8.使用lvextend -L +20G /dev/mapper/ubuntu--vg-root /dev/sdb1来进行扩容

这条命令的意思是,给/dev/mapper/ubuntu--vg-root添加20G的容量,使用/dev/sdb1的空间来扩容。

9.使用/sbin/resize2fs /dev/mapper/ubuntu--vg-root 把新分配的空间进行生效