磁盘分区(20G升50G)

时间:2023-03-09 07:51:27
磁盘分区(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)

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

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

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

问题的描述

磁盘分区(20G升50G)

磁盘分区(20G升50G)

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

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

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

磁盘分区(20G升50G)

磁盘分区(20G升50G)

磁盘分区(20G升50G)

磁盘分区(20G升50G)

磁盘分区(20G升50G)

磁盘分区(20G升50G)

磁盘分区(20G升50G)

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

磁盘分区(20G升50G)

[root@weekend110 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda5 16G .7G 12G % /
tmpfs 931M 232K 931M % /dev/shm
/dev/sda1 194M 30M 155M % /boot
/dev/sda2 .9G .8G % /home
/dev/sr0 .2G .2G % /media/CentOS_6.5_Final
[root@weekend110 ~]# fdisk -l Disk /dev/sda: 21.5 GB, bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0x000491de Device Boot Start End Blocks Id System
/dev/sda1 * Linux
Partition does not end on cylinder boundary.
/dev/sda2 Linux
Partition does not end on cylinder boundary.
/dev/sda3 Linux swap / Solaris
Partition does not end on cylinder boundary.
/dev/sda4 Extended
/dev/sda5 Linux
[root@weekend110 ~]#

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

  重启机器,后,再次执行

磁盘分区(20G升50G)

[root@weekend110 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda5 16G .7G 12G % /
tmpfs 931M 72K 931M % /dev/shm
/dev/sda1 194M 30M 155M % /boot
/dev/sda2 .9G .8G % /home
[root@weekend110 ~]# fdisk -l Disk /dev/sda: 21.5 GB, bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0x000491de   想说的是,一看/dev/sda,就是原来的硬盘。 Device Boot Start End Blocks Id System
/dev/sda1 * Linux
Partition does not end on cylinder boundary.
/dev/sda2 Linux
Partition does not end on cylinder boundary.
/dev/sda3 Linux swap / Solaris
Partition does not end on cylinder boundary.
/dev/sda4 Extended
/dev/sda5 Linux Disk /dev/sdb: 21.5 GB, bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0x00000000
想说的是,一看/dev/sda,就是新增的硬盘。

磁盘分区(20G升50G)

[root@weekend110 ~]# ll /dev/sd*
brw-rw----. root disk , Oct : /dev/sda
brw-rw----. root disk , Oct : /dev/sda1
brw-rw----. root disk , Oct : /dev/sda2
brw-rw----. root disk , Oct : /dev/sda3
brw-rw----. root disk , Oct : /dev/sda4
brw-rw----. root disk , Oct : /dev/sda5
brw-rw----. root disk , Oct : /dev/sdb
[root@weekend110 ~]# fdisk -l /dev/sdb Disk /dev/sdb: 21.5 GB, bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0x00000000 [root@weekend110 ~]#

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

磁盘分区(20G升50G)

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

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

提示说,输入p

磁盘分区(20G升50G)

Command (m for help): n
Command action
e extended
p primary partition (-)
p
Partition number (-):
First cylinder (-, default ):
Last cylinder, +cylinders or +size{K,M,G} (-, default ): +10G Command (m for help):
    在输入结束柱面的这里如果你不知道该输入多大的数字,你可以输入+然后输入你要设的大小。这里我设置10G的主分区。

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

磁盘分区(20G升50G)

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

Disk /dev/sdb: 21.5 GB,  bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0xc0585a2e Device Boot Start End Blocks Id System
/dev/sdb1 + 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)

Command (m for help): n
Command action
e extended
p primary partition (-)
e
Partition number (-):
First cylinder (-, default ):
Last cylinder, +cylinders or +size{K,M,G} (-, default ): Command (m for help): p        //查看当前的分区表 Disk /dev/sdb: 21.5 GB, bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0xc0585a2e Device Boot Start End Blocks Id System
/dev/sdb1 + Linux
/dev/sdb2 Extended Command (m for help):

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

磁盘分区(20G升50G)

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)

Command (m for help): n
Command action
l logical ( or over)
p primary partition (-)
l
First cylinder (-, default ):
Last cylinder, +cylinders or +size{K,M,G} (-, default ): +2G Command (m for help): n
Command action
l logical ( or over)
p primary partition (-)
l First cylinder (-, default ): ^H
Value out of range.
First cylinder (-, default ):
Last cylinder, +cylinders or +size{K,M,G} (-, default ): Command (m for help): p Disk /dev/sdb: 21.5 GB, bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0xc0585a2e Device Boot Start End Blocks Id System
/dev/sdb1 + Linux
/dev/sdb2 Extended
/dev/sdb5 + Linux
/dev/sdb6 + Linux Command (m for help):

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

磁盘分区(20G升50G)

Command (m for help): p

Disk /dev/sdb: 21.5 GB,  bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0xace34bc7 Device Boot Start End Blocks Id System
/dev/sdb1 + Linux
/dev/sdb2 Extended
/dev/sdb5 + Linux
/dev/sdb6 + 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)

Command (m for help): t
Partition number (-):
Hex code (type L to list codes):
Changed system type of partition to (Linux swap / Solaris) Command (m for help): p
Disk /dev/sdb: 21.5 GB, bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0xc0585a2e Device Boot Start End Blocks Id System
/dev/sdb1 + Linux
/dev/sdb2 Extended
/dev/sdb5 + Linux swap / Solaris
/dev/sdb6 + Linux Command (m for help):

6、保存退出

磁盘分区(20G升50G)

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)

[root@weekend110 ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.41. (-May-)
Filesystem label=
OS type: Linux
Block size= (log=)
Fragment size= (log=)
Stride= blocks, Stripe width= blocks
inodes, blocks
blocks (5.00%) reserved for the super user First data block=
Maximum filesystem blocks=
block groups
blocks per group, fragments per group
inodes per group
Superblock backups stored on blocks:
, , , , , , , Writing inode tables: done
Creating journal ( blocks): done
Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every mounts or
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)

[root@weekend110 ~]# mkfs -t ext4 /dev/sdb1
mke2fs 1.41. (-May-)
Filesystem label=
OS type: Linux
Block size= (log=)
Fragment size= (log=)
Stride= blocks, Stripe width= blocks
inodes, blocks
blocks (5.00%) reserved for the super user
First data block=
Maximum filesystem blocks=
block groups
blocks per group, fragments per group
inodes per group
Superblock backups stored on blocks:
, , , , , , , Writing inode tables: done
Creating journal ( blocks): done
Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every mounts or
days, whichever comes first. Use tune2fs -c or -i to override.
[root@weekend110 ~]#

磁盘分区(20G升50G)

[root@weekend110 ~]# mkfs.ext4 /dev/sdb6
mke2fs 1.41. (-May-)
Filesystem label=
OS type: Linux
Block size= (log=)
Fragment size= (log=)
Stride= blocks, Stripe width= blocks
inodes, blocks
blocks (5.00%) reserved for the super user
First data block=
Maximum filesystem blocks=
block groups
blocks per group, fragments per group
inodes per group Superblock backups stored on blocks:
, , , , , , , Writing inode tables: done
Creating journal ( blocks): done
Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every mounts or
days, whichever comes first. Use tune2fs -c or -i to override.
[root@weekend110 ~]#

swap分区格式化要使用

mkswap /dev/sdb5          mkswap,是mkdir swap。

磁盘分区(20G升50G)

[root@weekend110 ~]# mkswap /dev/sdb5
Setting up swapspace version , size = KiB
no label, UUID=d28dfa28--463a-ae0c-b1751786c656
[root@weekend110 ~]#
加载文件
swapon /dev/sdb5
查看是否生效
swapon -s

磁盘分区(20G升50G)

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

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

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

创建挂载文件路径
mkdir sdb1 sdb6

磁盘分区(20G升50G)

[root@weekend110 ~]# mkdir sdb1 sdb6
[root@weekend110 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda5 16G .7G 12G % /
tmpfs 931M 72K 931M % /dev/shm
/dev/sda1 194M 30M 155M % /boot
/dev/sda2 .9G .8G % /home
[root@weekend110 ~]#

磁盘分区(20G升50G)

磁盘分区(20G升50G)

磁盘分区(20G升50G)

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

9.立即生效

partprobe 

磁盘分区(20G升50G)

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

[root@weekend110 ~]# shutdown -r now

Broadcast message from root@weekend110

        (/dev/pts/) at : ...

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

磁盘分区(20G升50G)

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

  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)

[root@weekend110 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda5 16G .7G 12G % /
tmpfs 931M 72K 931M % /dev/shm
/dev/sda1 194M 30M 155M % /boot
/dev/sda2 .9G .8G % /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-.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. (-May-)
/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)

 

[root@weekend110 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda5 16G .7G 12G % /
tmpfs 931M 72K 931M % /dev/shm
/dev/sda1 194M 30M 155M % /boot
/dev/sda2 .9G .3G 524M % /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)

[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. (-May-)
/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 .7G 12G % /
tmpfs 931M 72K 931M % /dev/shm
/dev/sda1 194M 30M 155M % /boot
/dev/sda2 .9G .3G 524M % /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. (-May-)
Filesystem label=
OS type: Linux
Block size= (log=)
Fragment size= (log=)
Stride= blocks, Stripe width= blocks
inodes, blocks
blocks (5.00%) reserved for the super user
First data block=
Maximum filesystem blocks=
block groups
blocks per group, fragments per group
inodes per group
Superblock backups stored on blocks:
, , , , , , , Writing inode tables: done
Creating journal ( blocks): done
Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every mounts or
days, whichever comes first. Use tune2fs -c or -i to override.
[root@weekend110 ~]# mkfs -t ext4 /dev/sdb5
mke2fs 1.41. (-May-)
/dev/sdb5 is mounted; will not make a filesystem here!
[root@weekend110 ~]# mkfs -t ext4 /dev/sdb6
mke2fs 1.41. (-May-)
Filesystem label=
OS type: Linux
Block size= (log=)
Fragment size= (log=)
Stride= blocks, Stripe width= blocks
inodes, blocks
blocks (5.00%) reserved for the super user
First data block=
Maximum filesystem blocks=
block groups
blocks per group, fragments per group
inodes per group
Superblock backups stored on blocks:
, , , , , , , Writing inode tables: done
Creating journal ( blocks): done
Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every mounts or
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 .7G 12G % /
tmpfs 931M 72K 931M % /dev/shm
/dev/sda1 194M 30M 155M % /boot
/dev/sda2 .9G .3G 524M % /home
[root@weekend110 ~]#

  依然,还是解决不了。

磁盘分区(20G升50G)

    

磁盘分区(20G升50G)

[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=,mode=)
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 .7G 12G % /
tmpfs 931M 72K 931M % /dev/shm
/dev/sda1 194M 30M 155M % /boot
/dev/sda2 .9G 151M .3G % /home
/dev/sdb1 .9G 151M .3G % /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)磁盘分区(20G升50G)磁盘分区(20G升50G)磁盘分区(20G升50G)磁盘分区(20G升50G)磁盘分区(20G升50G) 

磁盘分区(20G升50G)

磁盘分区(20G升50G)

磁盘分区(20G升50G)