Linux磁盘扩容(具体实例)

编程

# 关闭虚拟机实例,在虚拟机设置里增加磁盘容量
# 具体方法,接着往下

Xshell for Xmanager Enterprise 5 (Build 0544)
Copyright (c) 2002-2015 NetSarang Computer, Inc. All rights reserved.

Type `help" to learn how to use Xshell prompt.
[c:~]$ 

Connecting to 192.168.234.101:22...
Connection established.
To escape to local shell, press "Ctrl+Alt+]".

Last login: Thu Nov 21 14:18:06 2019 from 192.168.234.10
# 列出所有分区信息
[root@oralinux66 ~]# fdisk -l

# 这部分可以看做是一块物理磁盘
Disk /dev/sda: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00003748
# 表示该物理磁盘的分区,两个分区,不言而喻
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        4178    33041408   8e  Linux LVM

# 下面两部分的物理介质实质上都是上述的物理磁盘
# 这部分可以看做是当前系统占用了上述物理磁盘的主要部分(文件存储)
# 扩容,扩的就是文件存储的主要部分
# 所以Linux下的扩容,分为:1.增加物理磁盘;2.新建分区;3.格式化分区;4.将分区加入虚拟卷组;5.将分区加到文件存储的主要部分;6.刷新文件存储的主要部分
Disk /dev/mapper/vg_oralinux66-lv_root: 30.4 GB, 30396121088 bytes
255 heads, 63 sectors/track, 3695 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

# 这部分可以看做是当前系统占用了上述物理磁盘的部分(交换空间)
Disk /dev/mapper/vg_oralinux66-lv_swap: 3435 MB, 3435134976 bytes
255 heads, 63 sectors/track, 417 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

[root@oralinux66 ~]# fdisk /dev/
Display all 207 possibilities? (y or n)
# 操作该物理磁盘
[root@oralinux66 ~]# fdisk /dev/sda

WARNING: DOS-compatible mode is deprecated. It"s spanly recommended to
         switch off the mode (command "c") and change display units to
         sectors (command "u").

# 显示该物理磁盘分区情况
Command (m for help): p

Disk /dev/sda: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00003748

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        4178    33041408   8e  Linux LVM

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
   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)

# 显然,n-添加一个分区
Command (m for help): n  
Command action
   e   extended
   p   primary partition (1-4)
# 创建主分区
p
# 上述有两个分区了,选择3,表示创建第三分区
Partition number (1-4): 3
First cylinder (4178-7832, default 4178): 
Using default value 4178
Last cylinder, +cylinders or +size{K,M,G} (4178-7832, default 7832): 
Using default value 7832
# 写表并退出
Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@oralinux66 ~]# fdisk -l

Disk /dev/sda: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00003748
# 多了分区3
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        4178    33041408   8e  Linux LVM
/dev/sda3            4178        7832    29356108   83  Linux

Disk /dev/mapper/vg_oralinux66-lv_root: 30.4 GB, 30396121088 bytes
255 heads, 63 sectors/track, 3695 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/mapper/vg_oralinux66-lv_swap: 3435 MB, 3435134976 bytes
255 heads, 63 sectors/track, 417 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

# 重启虚拟器实例
# 重启虚拟器实例
# 重启虚拟器实例

[root@oralinux66 ~]# 
Connection closed by foreign host.

Disconnected from remote host(U_oracle) at 16:51:03.

Type `help" to learn how to use Xshell prompt.
[c:~]$ 

Connecting to 192.168.234.101:22...
Connection established.
To escape to local shell, press "Ctrl+Alt+]".

Last login: Thu Nov 21 16:43:01 2019 from 192.168.234.10
[root@oralinux66 ~]# fdisk -l

Disk /dev/sda: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00003748

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        4178    33041408   8e  Linux LVM
/dev/sda3            4178        7832    29356108   83  Linux

Disk /dev/mapper/vg_oralinux66-lv_root: 30.4 GB, 30396121088 bytes
255 heads, 63 sectors/track, 3695 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/mapper/vg_oralinux66-lv_swap: 3435 MB, 3435134976 bytes
255 heads, 63 sectors/track, 417 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

[root@oralinux66 ~]# df -T /dev/sda3
Filesystem     Type 1K-blocks  Used Available Use% Mounted on
-              -      1009616   200   1009416   1% /dev
[root@oralinux66 ~]# df -T /dev/sda2
Filesystem     Type 1K-blocks  Used Available Use% Mounted on
-              -      1009616   200   1009416   1% /dev
[root@oralinux66 ~]# mkfs
mkfs          mkfs.cramfs   mkfs.ext2     mkfs.ext3     mkfs.ext4     mkfs.ext4dev  mkfs.msdos    mkfs.vfat     
[root@oralinux66 ~]# mkfs -t mkfs.ext4 /dev/sda3
mkfs.mkfs.ext4: No such file or directory
# 选择格式化分区3,使用ext4格式
[root@oralinux66 ~]# mkfs -t ext4 /dev/sda3
mke2fs 1.43-WIP (20-Jun-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1835008 inodes, 7339027 blocks
366951 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
224 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
   32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
   4096000

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done   

[root@oralinux66 ~]# 
[root@oralinux66 ~]# 
[root@oralinux66 ~]# pvcreate /dev/sda3
  Physical volume "/dev/sda3" successfully created
[root@oralinux66 ~]# lvm
# 用于将物理硬盘分区初始化为物理卷,以便LVM使用
lvm> pvcreate /dev/sda3
  Physical volume "/dev/sda3" successfully created
# 获取VG Name
lvm> pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               vg_oralinux66
  PV Size               31.51 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              8066
  Free PE               0
  Allocated PE          8066
  PV UUID               bjNDod-d1vx-7xdi-iamU-CnSH-IbnJ-KKeqnE
   
  "/dev/sda3" is a new physical volume of "28.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sda3
  VG Name               
  PV Size               28.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               lr9eYq-b1Ko-9PD3-g0eb-WM9K-xduy-HCDRDf
   
lvm> ^C
[root@oralinux66 ~]# lvm
# 用于动态扩展LVM卷组,它通过向卷组中添加物理卷来增加卷组的容量
lvm> vgextend vg_oralinux66 /dev/sda3
  Volume group "vg_oralinux66" successfully extended
lvm> ^Z
[1]+  Stopped                 lvm
[root@oralinux66 ~]# fdisk -l

Disk /dev/sda: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00003748

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        4178    33041408   8e  Linux LVM
/dev/sda3            4178        7832    29356108   83  Linux

Disk /dev/mapper/vg_oralinux66-lv_root: 30.4 GB, 30396121088 bytes
255 heads, 63 sectors/track, 3695 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/mapper/vg_oralinux66-lv_swap: 3435 MB, 3435134976 bytes
255 heads, 63 sectors/track, 417 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

[root@oralinux66 ~]# lvm
lvm> lvextend -L +28G /dev/mapper/vg_oralinux66-lv_root
  Insufficient free space: 7168 extents needed, but only 7166 available
# 容量加入到文件存储部分,真正实现扩容
lvm> lvextend -L +27G /dev/mapper/vg_oralinux66-lv_root
  Size of logical volume vg_oralinux66/lv_root changed from 28.31 GiB (7247 extents) to 55.31 GiB (14159 extents).
  Logical volume lv_root successfully resized
lvm> resize2fs /dev/mapper/vg_oralinux66-lv_root
  No such command "resize2fs".  Try "help".
lvm> ^Z
[2]+  Stopped                 lvm
# 重新加载逻辑卷的大小才能生效
[root@oralinux66 ~]# resize2fs /dev/mapper/vg_oralinux66-lv_root
resize2fs 1.43-WIP (20-Jun-2013)
Filesystem at /dev/mapper/vg_oralinux66-lv_root is mounted on /; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 4
The filesystem on /dev/mapper/vg_oralinux66-lv_root is now 14498816 blocks long.

[root@oralinux66 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_oralinux66-lv_root
                       55G   27G   26G  51% /
tmpfs                 998M  247M  752M  25% /dev/shm
/dev/sda1             477M   65M  384M  15% /boot
[root@oralinux66 ~]# 

 

以上是 Linux磁盘扩容(具体实例) 的全部内容, 来源链接: utcz.com/z/511011.html

回到顶部