Linux下使用fdisk扩展分区容量

导读 我们管理的服务器可能会随着业务量的不断增长造成磁盘空间不足的情况,比如:共享文件服务器硬盘空间不足,在这个时候我们就需要增加磁盘空间,来满足线上的业务;又或者我们在使用linux的过程中, 有时会因为安装系统时分区不当导致有的分区空间不足,而有的分区空间过剩的情况,都可以是使用fdisk分区工具来动态调整分区的大小;

扩展磁盘空间

硬盘空间为20G,使用vSphere Client增加磁盘大小,需要再增加10G空间;

扩展完后,重启系统,再次使用fdisk -l查看,会发现硬盘空间变大了;

[[email protected] ~]# fdisk -l
Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 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: 0x0005210c

   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        1301    10240000   83  Linux
/dev/sda3            1301        1497     1572864   82  Linux swap / Solaris
/dev/sda4            1497        2611     8952832   83  Linux
[[email protected] ~]# df -hT
Filesystem     Type   Size  Used Avail Use% Mounted on
/dev/sda2      ext4   9.7G  1.5G  7.7G  16% /
tmpfs          tmpfs  939M     0  939M   0% /dev/shm
/dev/sda1      ext4   194M   34M  151M  19% /boot
/dev/sda4      ext4   8.5G  148M  7.9G   2% /data

重新创建分区,调整分区信息

本次实验主要对/dev/sda4这个分区扩展,如果是生产环境,请提前做好备份保存到其他分区,虽然扩展分区大小不会导致数据丢失,安全起见,请提前做好备份;
首先模拟出一些数据:

[[email protected] data]# mkdir test
[[email protected] data]# echo "we are Linuxer" > linuxprobe
[[email protected] data]# ll
total 24
-rw-r--r--. 1 root root    15 May 23 21:59 linuxprobe
drwx------. 2 root root 16384 May 23 15:07 lost+found
drwxr-xr-x. 2 root root  4096 May 23 21:51 test
[[email protected] ~]# umount /dev/sda4          #卸载磁盘分区

若提示磁盘忙,使用fuser找出将正在使用磁盘的程序并结束掉;

fuser -m -v /data
fuser -m -v -i -k /data

使用fdisk工具先删除/dev/sda4分区,然后创建新分区,注意开始的磁柱号要和原来的一致(是保证数据不丢失的关键步骤),结束的磁柱号默认回车使用全部磁盘。

[[email protected] ~]# fdisk /dev/sda

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): p        #查看分区表信息

Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 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: 0x0005210c

   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        1301    10240000   83  Linux
/dev/sda3            1301        1497     1572864   82  Linux swap / Solaris
/dev/sda4            1497        2611     8952832   83  Linux

Command (m for help): d           #删除分区
Partition number (1-4): 4         #删除第四个

Command (m for help): p       #再次查看分区信息,/dev/sda4已被删除

Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 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: 0x0005210c

   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        1301    10240000   83  Linux
/dev/sda3            1301        1497     1572864   82  Linux swap / Solaris

Command (m for help): n      #创建新的分区
Command action
   e   extended
   p   primary partition (1-4)
p             #创建为主分区
Selected partition 4
First cylinder (1497-3916, default 1497):          #经对比,正好和上一个磁盘柱一致,默认即可
Using default value 1497
Last cylinder, +cylinders or +size{K,M,G} (1497-3916, default 3916):
Using default value 3916              #直接默认就可以

Command (m for help): p               #查看分区表信息

Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 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: 0x0005210c

   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        1301    10240000   83  Linux
/dev/sda3            1301        1497     1572864   82  Linux swap / Solaris
/dev/sda4            1497        3916    19436582   83  Linux

Command (m for help): wp       #保存并退出,如果创建有误,直接退出不要保存即可
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.


重新创建分区后,需要重启一下;

[[email protected] ~]# init 6
[[email protected] ~]# e2fsck -f /dev/sda4                #检查分区信息
[[email protected] ~]# resize2fs -p /dev/sda4             #调整分区大小

重新挂载、查看分区大小、数据

[[email protected] ~]# mount /dev/sda4 /data
[[email protected] ~]# df -hT
[[email protected] ~]# cat /data/linuxprobe
we are  Linuxer

时间: 2024-07-30 10:04:21

Linux下使用fdisk扩展分区容量的相关文章

Linux centos下使用fdisk扩展分区容量大小

扩展磁盘空间 硬盘空间为20G,使用vSphere Client增加磁盘大小,需要再增加10G空间; 扩展完后,重启系统,再次使用fdisk -l查看,会发现硬盘空间变大了: [[email protected] ~]# fdisk -l Disk /dev/sda: 32.2 GB, 32212254720 bytes 255 heads, 63 sectors/track, 3916 cylinders Units = cylinders of 16065 * 512 = 8225280 b

Linux下使用fdisk扩大分区容量(不丢失数据)

环境: 模拟新加一块磁盘,并分区,挂载,永久挂载,然后写入数据,然后对分区扩容,测试扩容后分区里面的内容是否丢失. 查看所有分区: [[email protected] ~]# fdisk -l Disk /dev/sda: 1073.7 GB, 1073741824000 bytes 255 heads, 63 sectors/track, 130541 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size

在Linux下用fdisk创建分区

一.输入 fdisk -l /dev/sda ,观察硬盘之实体使用情形.二.输入 fdisk /dev/sda,可进入分割硬盘模式. 1. 输入 m 显示所有命令列示. 2. 输入 p 显示硬盘分割情形. 3. 输入 a 设定硬盘启动区. 4. 输入 n 设定新的硬盘分割区. 4.1. 输入 e 硬盘为[延伸]分割区(extend). 4.2. 输入 p 硬盘为[主要]分割区(primary). 5. 输入 t 改变硬盘分割区属性. 6. 输入 d 删除硬盘分割区属性. 7. 输入 q 结束不存

linux下使用fdisk进行分区

在linux系统下面经常要使用到fdisk对硬盘进行分区 一.查看系统硬盘信息 [[email protected] ~]# fdisk -l Disk /dev/sda: 214.7 GB, 214748364800 bytes 255 heads, 63 sectors/track, 26108 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 byte

Linux下使用fdisk命令和partprobe命令,在不重启系统的情况下新建分区并格式化

由于工作的需要,最近一段时间一直在学习Linux.学习一门新的知识,我是喜欢根据谋一本书或者某一个学习视频系统的学习,这样可以对学习的新知识有一个系统全面的认识和了解.所以学习之前,没了一本鸟哥的私房菜做为参考书,开始系统的学习Linux. 根据鸟哥的建议,安装虚拟机时,预留了一块空的容量用来练习分区使用.所以在虚拟机上安装Linux系统分区时,只划分了一块4G的容量挂载到根目录“/”下,还有就是只划分了一个2G的swap分区.还有14G的容量没有分配. 在学习磁盘管理时,使用fdisk将剩余的

linux下使用fdisk命令进行磁盘分区

linux下使用fdisk命令进行磁盘分区 目录 分区类型 分区方法表示 文件系统 fdisk命令分区过程 分区类型 主分区:总共最多只能分四个 扩展分区:只能有一个,也算作主分区的一种,也就是说主分区加扩展分区最多有四个.但是扩展分区不能存储数据和格式化,必须再划分成逻辑分区才能使用. 逻辑分区:逻辑分区是在扩展分区中划分的,如果是IDE硬盘,Linux最多支持59个逻辑分区,如果是IDE硬盘,Linux最多支持59个逻辑分区,如果是SCSI硬盘Linux最多支持11个逻辑分区 分区方法表示

linux下增加pdo-mysql扩展

默认的PHP安装,只安装了常用默认模块,一些不常用或少用的,就没有默认安上 可通过如下方法增加,如下以增加pdo-mysql为例 wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgztar zxvf PDO_MYSQL-1.0.2.tgzcd PDO_MYSQL-1.0.2/www/wdlinux/php/bin/phpize./configure --with-php-config=/www/wdlinux/php/bin/php-config --

linux下安装opcache扩展

linux下安装opcache扩展 参考:http://www.php.net/manual/zh/opcache.installation.php 1 2 3 4 5 6 7 wget http://pecl.php.net/get/zendopcache-7.0.2.tgz tar zxvf zendopcache-7.0.2.tgz cd zendopcache-7.0.2 /usr/local/php/bin/phpize ./configure --with-php-config=/u

linux下配置php扩展mssql

前言:linux下配置php扩展mssql,使php通过mssql工具实现和远程win SQL server数据的传递. 有两种方法: 一.第一次编译php时提供mssql支持,即在编译参数上加上--with-mssql=/path 二.对于己安装的php,需把mssql当成一个模块,编译php使其支持,本文主要讲解这种方法: 1.安装配置freetds 下载源码包,并编译安装 #wget  tp://ibiblio.org/pub/Linux/ALPHA/freetds/stable/free