虚拟机磁盘分区(20G升50G)

不多说,直接上干货!

 

 

本博文的主要内容有

  .磁盘分区的概述

  .常用的磁盘管理工具

      ./下分5G,给/home扩容

    .系统自带的fdisk和parted这两款工具

  .磁盘空间管理

 

 

 

前言

  系统自带的fdisk和parted这两款工具,可以为我们提供更方便地对磁盘空间进行查看和管理的能力,也可以使用带-l选项的fdisk命令来查看某块磁盘上更新详细的信息。

  

 

 

磁盘分区的概述

  磁盘由两个分区组成,即分为主分区和扩展分区,扩展分区又可由多个逻辑分区组成。

   我们在安装linux系统时,若使用自动分区的方式进行磁盘分区,系统则将自动将分成两个分区,即根分区/和交换分区swap。交换分区的作用是充当虚拟内存,主要是物理内存不足时用于暂时对数据进行保存,并在需要时进行调用。由于交换分区只能用于暂时数据的存储,因此系统还必须有一股分区用于长期存储文件及数据。

  Linux系统下的磁盘类型有IDE和SCSI这两种。当然,这些磁盘设备也被映射到一个系统文件上。对于这两种磁盘的命名方式,IDE的命名方式采用/dec/hdx(x代表磁盘快),而其下的分区则是/dec/hdxy(y代表该磁盘块上的分区号).SCSI则采用/dev/sdx,其下的分区是/dev/sdxy。

 

  对于Linux的磁盘分区,至少要有/分区、boot分区和swap分区。否则,安装会受阻,考虑到实际的工作环境及后期对磁盘的维护(如后期磁盘空间需要扩容,在Linux系统下安装Oracle数据库)等。Linux磁盘分区的格式建议是LVM格式,而设计Oracle的安装时,swap分区往往与物理内存对应,因此在实际的工作环境下安装系统时应该做好分区工作。

 

 

 

 

  推荐

虚拟机磁盘分区(20G升50G)_第1张图片

            下载地址:http://pan.baidu.com/s/1c2iLrji

 

    磁盘管理工具是系统管理员需要经常使用的软件,是完成磁盘管理的重要手段。常用的磁盘管理工具包括:fdisk、Partition Magic、parted、mkfs和e2fsck。

           使用partprobe重载分区也只能是对不同的硬盘才能及时生效。对于同一块硬盘,修改过分区信息后,必须重启系统才能使修改过的分区信息生效。(比如,SCSI硬盘和IDE硬盘。)

 

 

 

 

 

 

问题的描述

虚拟机磁盘分区(20G升50G)_第2张图片

 

虚拟机磁盘分区(20G升50G)_第3张图片

  可以看出,我的虚拟机里的这个系统,因之前,在安装分区时,未考虑周到,/home的容量太小了,现在,我想,希望从/下分5G容量给/home?

或者,新建一磁盘,来进行对分区的扩容。(实则,是想从/dev/sdb扩容5G到/dev/sda下的/home)。求解!!!

 

 

 

   流程:添加磁盘   ->   使用fdisk创建磁盘分区   ->  使用parted工具创建分区     ->    挂载磁盘分区到系统 

虚拟机磁盘分区(20G升50G)_第4张图片

 

虚拟机磁盘分区(20G升50G)_第5张图片

 

虚拟机磁盘分区(20G升50G)_第6张图片

 

虚拟机磁盘分区(20G升50G)_第7张图片

 

虚拟机磁盘分区(20G升50G)_第8张图片

 

虚拟机磁盘分区(20G升50G)_第9张图片

 

虚拟机磁盘分区(20G升50G)_第10张图片

 

 

 

  1、使用fdisk -l查询当前系统分区情况

虚拟机磁盘分区(20G升50G)_第11张图片

 

复制代码

[root@weekend110 ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda5        16G  3.7G   12G  25% /
tmpfs           931M  232K  931M   1% /dev/shm
/dev/sda1       194M   30M  155M  16% /boot
/dev/sda2       2.9G  2.8G     0 100% /home
/dev/sr0        4.2G  4.2G     0 100% /media/CentOS_6.5_Final
[root@weekend110 ~]# fdisk -l

 

Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x000491de

 

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          26      204800   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              26         409     3072000   83  Linux
Partition 2 does not end on cylinder boundary.
/dev/sda3             409         536     1024000   82  Linux swap / Solaris
Partition 3 does not end on cylinder boundary.
/dev/sda4             536        2611    16669696    5  Extended
/dev/sda5             536        2611    16668672   83  Linux
[root@weekend110 ~]#

复制代码

  可以看到新增加的sda磁盘还没有分区!!!

 

  重启机器,后,再次执行

虚拟机磁盘分区(20G升50G)_第12张图片

复制代码

[root@weekend110 ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda5        16G  3.7G   12G  25% /
tmpfs           931M   72K  931M   1% /dev/shm
/dev/sda1       194M   30M  155M  16% /boot
/dev/sda2       2.9G  2.8G     0 100% /home
[root@weekend110 ~]# fdisk -l

 

Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x000491de

  想说的是,一看/dev/sda,就是原来的硬盘。

 

 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          26      204800   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              26         409     3072000   83  Linux
Partition 2 does not end on cylinder boundary.
/dev/sda3             409         536     1024000   82  Linux swap / Solaris
Partition 3 does not end on cylinder boundary.
/dev/sda4             536        2611    16669696    5  Extended
/dev/sda5             536        2611    16668672   83  Linux

 

Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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
想说的是,一看/dev/sda,就是新增的硬盘。

复制代码

 

 

 

 

 

虚拟机磁盘分区(20G升50G)_第13张图片

复制代码

[root@weekend110 ~]# ll /dev/sd*
brw-rw----. 1 root disk 8, 0 Oct 18 20:04 /dev/sda
brw-rw----. 1 root disk 8, 1 Oct 18 20:04 /dev/sda1
brw-rw----. 1 root disk 8, 2 Oct 18 20:04 /dev/sda2
brw-rw----. 1 root disk 8, 3 Oct 18 20:04 /dev/sda3
brw-rw----. 1 root disk 8, 4 Oct 18 20:04 /dev/sda4
brw-rw----. 1 root disk 8, 5 Oct 18 20:04 /dev/sda5
brw-rw----. 1 root disk 8, 16 Oct 18 20:04 /dev/sdb
[root@weekend110 ~]# fdisk -l /dev/sdb

Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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@weekend110 ~]#

复制代码

 

  可见,该新增的磁盘/dec/sdb,上没有创建任何分区。

 

 

虚拟机磁盘分区(20G升50G)_第14张图片

复制代码

[root@weekend110 ~]# clear
[root@weekend110 ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xace34bc7.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

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

Command (m for help): m
Command action
a toggle a bootable flag       //设置可引导的标记
b edit bsd disklabel      //修改bsd磁盘的标签
c toggle the dos compatibility flag    //设置dos的兼容性
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    //创建一个新的、空的DOS分区表
p print the partition table    //显示当前的分区表
q quit without saving changes    //退出操作、不保存修改
s create a new empty Sun disklabel    //创建一个新的、空的Sun磁盘标签
t change a partition's system id    //更改系统分区id号
u change display/entry units    //更改显示记录
v verify the partition table    //对分区表进行验证
w write table to disk and exit    //退出并保存所做的修改
x extra functionality (experts only)    //特殊功能

Command (m for help):

复制代码

 

 

 

 

 

 

2.创建主分区

       因为,新增磁盘,是sdb。

fdisk /dev/sdb
输入n

虚拟机磁盘分区(20G升50G)_第15张图片

复制代码

[root@weekend110 ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xf5778f69.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
 
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
 
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').
 
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)

复制代码

 
提示说,输入p

虚拟机磁盘分区(20G升50G)_第16张图片

复制代码

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1): 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +10G
 
Command (m for help):

复制代码

    在输入结束柱面的这里如果你不知道该输入多大的数字,你可以输入+然后输入你要设的大小。这里我设置10G的主分区。

     输入p查看分区信息,可以看到刚创建的sdb1主分区。

虚拟机磁盘分区(20G升50G)_第17张图片

复制代码

Command (m for help): p        //查看当前分区表


Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0xc0585a2e


   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1306    10490413+  83  Linux

Command (m for help):


Command (m for help): w       //保存退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@weekend110 ~]#

复制代码

 

 

3、创建扩展分区

虚拟机磁盘分区(20G升50G)_第18张图片

复制代码

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
e
Partition number (1-4): 2
First cylinder (1307-2610, default 1307): 1307
Last cylinder, +cylinders or +size{K,M,G} (1307-2610, default 2610): 2610


Command (m for help): p        //查看当前的分区表

Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0xc0585a2e


   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1306    10490413+  83  Linux
/dev/sdb2            1307        2610    10474380    5  Extended

 
Command (m for help):

复制代码

  图片上通过红色标注了操作步骤。可以看到当前已创建了sdb2扩展分区,柱面从1037-2610,即将剩下的所有空间创建为扩展分区。

 

 

虚拟机磁盘分区(20G升50G)_第19张图片

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@weekend110 ~]#

 

 

 

4.创建逻辑分区

虚拟机磁盘分区(20G升50G)_第20张图片

复制代码

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (1307-2610, default 1307): 1307
Last cylinder, +cylinders or +size{K,M,G} (1307-2610, default 2610): +2G


Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l

First cylinder (1569-2610, default 1569): 1560^H
Value out of range.
First cylinder (1569-2610, default 1569): 1569
Last cylinder, +cylinders or +size{K,M,G} (1569-2610, default 2610): 2610

 

Command (m for help): p


Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0xc0585a2e

 

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1306    10490413+  83  Linux
/dev/sdb2            1307        2610    10474380    5  Extended
/dev/sdb5            1307        1568     2104483+  83  Linux
/dev/sdb6            1569        2610     8369833+  83  Linux

Command (m for help):

复制代码

    总共创建了两个逻辑分区,逻辑分区默认从5开始,第一个逻辑分区大小2G,用来做交换分区用,剩下全部给sdb6.

 

虚拟机磁盘分区(20G升50G)_第21张图片

复制代码

Command (m for help): p

Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0xace34bc7

Device Boot Start End Blocks Id System
/dev/sdb1 1 1306 10490413+ 83 Linux
/dev/sdb2 1307 2610 10474380 5 Extended
/dev/sdb5 1307 1568 2104483+ 83 Linux
/dev/sdb6 1569 2610 8369833+ 83 Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@weekend110 ~]#

复制代码

 

 

 

5、修改文件类型ID

  因为默认分区id都是83即linux文件类型,现在将sdb5的文件类型ID改成82即交换分区。

虚拟机磁盘分区(20G升50G)_第22张图片

复制代码

Command (m for help): t
Partition number (1-6): 5
Hex code (type L to list codes): 82
Changed system type of partition 5 to 82 (Linux swap / Solaris)

 

Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0xc0585a2e

 

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1306    10490413+  83  Linux
/dev/sdb2            1307        2610    10474380    5  Extended
/dev/sdb5            1307        1568     2104483+  82  Linux swap / Solaris
/dev/sdb6            1569        2610     8369833+  83  Linux


Command (m for help):

复制代码

 

 

6、保存退出

虚拟机磁盘分区(20G升50G)_第23张图片

复制代码

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)

 

Command (m for help): w
The partition table has been altered!


Calling ioctl() to re-read partition table.
Syncing disks.
[root@weekend110 ~]#

复制代码

 

 

 

7.格式化分区
  接下来要对sdb的每一个分区进行格式化,
  注意:扩展分区不需要进行格式

虚拟机磁盘分区(20G升50G)_第24张图片

复制代码

[root@weekend110 ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655776 inodes, 2622603 blocks
131130 blocks (5.00%) reserved for the super user

First data block=0
Maximum filesystem blocks=2688548864
81 block groups
32768 blocks per group, 32768 fragments per group
8096 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

 

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

 

This filesystem will be automatically checked every 25 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@weekend110 ~]#


[root@weekend110 ~]# mkfs.ext4 /dev/sdb1
或者
[root@weekend110 ~]# mkfs -t ext4 /dev/sdb1
是等价的。

复制代码

 

 

虚拟机磁盘分区(20G升50G)_第25张图片

复制代码

[root@weekend110 ~]# mkfs -t ext4 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655776 inodes, 2622603 blocks
131130 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2688548864
81 block groups
32768 blocks per group, 32768 fragments per group
8096 inodes per group
Superblock backups stored on blocks: 
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

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

This filesystem will be automatically checked every 23 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@weekend110 ~]#

复制代码

 

 

 

 虚拟机磁盘分区(20G升50G)_第26张图片

复制代码

[root@weekend110 ~]# mkfs.ext4 /dev/sdb6
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
523264 inodes, 2092458 blocks
104622 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2143289344
64 block groups
32768 blocks per group, 32768 fragments per group
8176 inodes per group

Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

 

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

 

This filesystem will be automatically checked every 25 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@weekend110 ~]#

复制代码

 

 

swap分区格式化要使用

mkswap /dev/sdb5          mkswap,是mkdir swap。

 虚拟机磁盘分区(20G升50G)_第27张图片

[root@weekend110 ~]# mkswap /dev/sdb5
Setting up swapspace version 1, size = 2104476 KiB
no label, UUID=d28dfa28-7303-463a-ae0c-b1751786c656
[root@weekend110 ~]#

 

 

加载文件
swapon /dev/sdb5
查看是否生效
swapon -s

虚拟机磁盘分区(20G升50G)_第28张图片

[root@weekend110 ~]# swapon /dev/sdb5
[root@weekend110 ~]# swapon -s
Filename                                Type            Size    Used    Priority
/dev/sda3                               partition       1023992 0       -1
/dev/sdb5                               partition       2104472 0       -2
[root@weekend110 ~]#

  可以看到sda3,和sdb5这两个swap分区。

 

 

8.挂载分区
   这里直接使用修改文件的方式永久挂载

创建挂载文件路径
mkdir sdb1 sdb6

虚拟机磁盘分区(20G升50G)_第29张图片

复制代码

[root@weekend110 ~]# mkdir sdb1 sdb6
[root@weekend110 ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda5        16G  3.7G   12G  25% /
tmpfs           931M   72K  931M   1% /dev/shm
/dev/sda1       194M   30M  155M  16% /boot
/dev/sda2       2.9G  2.8G     0 100% /home
[root@weekend110 ~]#

复制代码

 

 

虚拟机磁盘分区(20G升50G)_第30张图片

虚拟机磁盘分区(20G升50G)_第31张图片

虚拟机磁盘分区(20G升50G)_第32张图片

复制代码

#
# /etc/fstab
# Created by anaconda on Mon Jul 18 18:45:01 2016
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=f664c4a8-f9ea-4999-b914-4071e8efdff2 /                       ext4    defaults        1 
UUID=2da787fb-94f8-4f6a-8d75-15d66628c818 /boot                   ext4    defaults        1 2
UUID=77fd7f45-c1e6-4014-a21e-75fe308e7edd /home                   ext4    defaults        1 2
UUID=98519c68-56ea-450e-b2e7-ca329d379e05 swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
/dev/sdb1               /sdb1                   ext4    defaults        0 0
/dev/sdb5               swap                    swap    defaults        0 0
/dev/sdb6               /sdb6                   ext4    defaults        0 0

复制代码

 

 

 

9.立即生效

partprobe 

虚拟机磁盘分区(20G升50G)_第33张图片

复制代码

[root@weekend110 ~]# partprobe
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy).  As a result, it may not reflect all of your changes until after reboot.
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdb (Device or resource busy).  As a result, it may not reflect all of your changes until after reboot.
Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.
Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.
Error: Invalid partition table - recursive partition on /dev/sr0.
[root@weekend110 ~]#

复制代码

 

  在我的虚拟机上面无法立即生效,重启机器。

shutdown -r now

虚拟机磁盘分区(20G升50G)_第34张图片

复制代码

[root@weekend110 ~]# shutdown -r now

Broadcast message from root@weekend110

        (/dev/pts/0) at 23:58 ...

The system is going down for reboot NOW!
[root@weekend110 ~]#

复制代码

 

虚拟机磁盘分区(20G升50G)_第35张图片

  没生效,那是因为,遇到了

  Error: Invalid partition table - recursive partition on /dev/sr0.

 

 

参考博客:

http://www.mincoder.com/article/3454.shtml 

  决方法:执行partprobe 命令

  partprobe包含在parted的rpm软件包中。

  partprobe可以修改kernel中分区表,使kernel重新读取分区表。 

  因此,使用该命令就可以创建分区并且在不重新启动机器的情况下系统能够识别这些分区。

 

 

 

 

虚拟机磁盘分区(20G升50G)_第36张图片

复制代码

[root@weekend110 ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda5        16G  3.7G   12G  25% /
tmpfs           931M   72K  931M   1% /dev/shm
/dev/sda1       194M   30M  155M  16% /boot
/dev/sda2       2.9G  2.8G     0 100% /home

[root@weekend110 ~]# partprobe
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy).  As a result, it may not reflect all of your changes until after reboot.
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdb (Device or resource busy).  As a result, it may not reflect all of your changes until after reboot.
Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.
Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.
Error: Invalid partition table - recursive partition on /dev/sr0.
[root@weekend110 ~]# rpm -q parted
parted-2.1-21.el6.x86_64
[root@weekend110 ~]# partprobe
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy).  As a result, it may not reflect all of your changes until after reboot.
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdb (Device or resource busy).  As a result, it may not reflect all of your changes until after reboot.
Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.
Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.
Error: Invalid partition table - recursive partition on /dev/sr0.
[root@weekend110 ~]# mkfs -t ext4 /dev/sr0
mke2fs 1.41.12 (17-May-2010)
/dev/sr0 is entire device, not just one partition!
Proceed anyway? (y,n) y
/dev/sr0: Read-only file system while setting up superblock
[root@weekend110 ~]# partprobe
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy).  As a result, it may not reflect all of your changes until after reboot.
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdb (Device or resource busy).  As a result, it may not reflect all of your changes until after reboot.
Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.
Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.
Error: Invalid partition table - recursive partition on /dev/sr0.

[root@weekend110 ~]#

复制代码

  出现这个问题,我查阅了一些资料,如http://www.linuxdiyf.com/viewarticle.php?id=312338

  主要是因为是使用的虚拟机,如果是直接在Linux系统上,不会出现这个问题。

 

  如:http://bbs.51cto.com/thread-1118884-1.html

  在虚拟机中把光驱移除后,重新进入虚拟机新建分区,并通过partprobe重载分区,就没有/dev/sr0 出现递归分区的错误信息了。

虚拟机磁盘分区(20G升50G)_第37张图片

 

复制代码

[root@weekend110 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda5 16G 3.7G 12G 25% /
tmpfs 931M 72K 931M 1% /dev/shm
/dev/sda1 194M 30M 155M 16% /boot
/dev/sda2 2.9G 2.3G 524M 82% /home
[root@weekend110 ~]# partprobe
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy). As a result, it may not reflect all of your changes until after reboot.
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdb (Device or resource busy). As a result, it may not reflect all of your changes until after reboot.

复制代码

  但是仍然提示重载分区不成功,提示设备或资源忙,需要重启生效。
  直接格式化新建的分区,提示找不到新建的/dev/sdb分区。
  重启系统后,在格式化新建的分区/dev/sdb,成功。

 

虚拟机磁盘分区(20G升50G)_第38张图片

复制代码

[root@weekend110 ~]# partprobe
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy). As a result, it may not reflect all of your changes until after reboot.
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdb (Device or resource busy). As a result, it may not reflect all of your changes until after reboot.
[root@weekend110 ~]# mkfs -t ext4 /dev/sdb        //分区格式化
mke2fs 1.41.12 (17-May-2010)
/dev/sdb is entire device, not just one partition!
Proceed anyway? (y,n) y
/dev/sdb is apparently in use by the system; will not make a filesystem here!

复制代码

 

 

再次尝试,

复制代码

[root@weekend110 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda5 16G 3.7G 12G 25% /
tmpfs 931M 72K 931M 1% /dev/shm
/dev/sda1 194M 30M 155M 16% /boot
/dev/sda2 2.9G 2.3G 524M 82% /home
[root@weekend110 ~]# partprobe
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy). As a result, it may not reflect all of your changes until after reboot.
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdb (Device or resource busy). As a result, it may not reflect all of your changes until after reboot.
[root@weekend110 ~]# mkfs -t ext4 /dev/sdb1      //格式化主分区
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655776 inodes, 2622603 blocks
131130 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2688548864
81 block groups
32768 blocks per group, 32768 fragments per group
8096 inodes per group
Superblock backups stored on blocks: 
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

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

This filesystem will be automatically checked every 39 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@weekend110 ~]# mkfs -t ext4 /dev/sdb5
mke2fs 1.41.12 (17-May-2010)
/dev/sdb5 is mounted; will not make a filesystem here!
[root@weekend110 ~]# mkfs -t ext4 /dev/sdb6
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
523264 inodes, 2092458 blocks
104622 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2143289344
64 block groups
32768 blocks per group, 32768 fragments per group
8176 inodes per group
Superblock backups stored on blocks: 
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

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

This filesystem will be automatically checked every 36 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@weekend110 ~]# partprobe
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy). As a result, it may not reflect all of your changes until after reboot.
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdb (Device or resource busy). As a result, it may not reflect all of your changes until after reboot.
[root@weekend110 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda5 16G 3.7G 12G 25% /
tmpfs 931M 72K 931M 1% /dev/shm
/dev/sda1 194M 30M 155M 16% /boot
/dev/sda2 2.9G 2.3G 524M 82% /home
[root@weekend110 ~]#

复制代码

 

  依然,还是解决不了。

虚拟机磁盘分区(20G升50G)_第39张图片

    

 

 

虚拟机磁盘分区(20G升50G)_第40张图片

复制代码

[root@weekend110 ~]# mount /dev/sdb1 /home      //挂载分区/dev/sdb1到挂载点/home
[root@weekend110 ~]# mount
/dev/sda5 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
/dev/sda2 on /home type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/sdb1 on /home type ext4 (rw)
[root@weekend110 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda5 16G 3.7G 12G 25% /
tmpfs 931M 72K 931M 1% /dev/shm
/dev/sda1 194M 30M 155M 16% /boot
/dev/sda2 9.9G 151M 9.3G 2% /home
/dev/sdb1 9.9G 151M 9.3G 2% /home
[root@weekend110 ~]#

复制代码

   至于,删除磁盘分区,为什么呢?

  答:在实际工作中,我们需要创建的分区来存放不同的数据和文件。当这些数据不再需要时,这个专门存储这些数据和文件的分区几乎没有存在的意义。而对于这些没有存在意义的分区,则需要将其删除,方便管理分区。

  删除磁盘分区,很简单,这里不多赘述。

 

 

 

 

 

 

 

      后面我在自己实验室里,尝试成功。如下

如何在ubuntu系统里面用新加装的硬盘对系统进行扩容

 

 

 

 

 

磁盘空间管理

  不论是操作系统的磁盘空间有多大,在使用过程中可用空间总会不断减小,虽然在磁盘空间已满的情况下可把数据另存到其他的磁盘,但在实际的生产环境下,数据是连续的,因此对于某个位置下的数据,是不能将其中的某些部分移到其他的磁盘中存放的。

  要保证数据的连续性,而磁盘的可用空间又不断减少,虽然可用加磁盘,但并不能保证数据的连续性。而且对于海量的数据,仅靠单个磁盘的空间是不能存储的,即使使用多块磁盘拼接在一起形成RIAD即廉价磁盘冗余阵列,固定的磁盘空间也并不能无限地存储不断增长的数据。

  对于这个问题,在Linux系统中可以使用逻辑卷的方式来解决。Linux系统支持对逻辑卷空间不断地扩展,并且实现在线的方式扩展。

 

 

1、磁盘分区扩容

2、扩展交换分区空间

 

 参考博客:  

        http://www.3fwork.com/b902/002559MYM000559/

        http://www.linuxdiyf.com/viewarticle.php?id=312338

        http://www.mincoder.com/article/3454.shtml 

        http://bbs.51cto.com/thread-1118884-1.html

 

 

 

 

 

 

 

欢迎大家,加入我的微信公众号:大数据躺过的坑        人工智能躺过的坑

 

 

 

同时,大家可以关注我的个人博客

   http://www.cnblogs.com/zlslch/   和     http://www.cnblogs.com/lchzls/      http://www.cnblogs.com/sunnyDream/   

   详情请见:http://www.cnblogs.com/zlslch/p/7473861.html

 

  人生苦短,我愿分享。本公众号将秉持活到老学到老学习无休止的交流分享开源精神,汇聚于互联网和个人学习工作的精华干货知识,一切来于互联网,反馈回互联网。
  目前研究领域:大数据、机器学习、深度学习、人工智能、数据挖掘、数据分析。 语言涉及:Java、Scala、Python、Shell、Linux等 。同时还涉及平常所使用的手机、电脑和互联网上的使用技巧、问题和实用软件。 只要你一直关注和呆在群里,每天必须有收获

 

      对应本平台的讨论和答疑QQ群:大数据和人工智能躺过的坑(总群)(161156071) 

 

你可能感兴趣的:(Linux学习笔记)