Linux 在线增加原有硬盘容量

需求说明:

现在有一个硬盘单独挂载到了某个分区下面,但是容量满了又不能将内容迁移走,这样就只能增加原来硬盘的容量,原来分区容量10G,现在需要将硬盘扩大到15G,将容量加到分区内,这里面涉及到危险的操作就是要修改分区表

测试说明:

Ubuntu 14.10   文件系统类型:ext4 

原先容量10G,写入文件后,将硬盘扩展至15G

#df –h

Filesystem      Size  Used Avail Use% Mounted on

/dev/sda1        57G  1.9G   53G   4% /

none            4.0K     0  4.0K   0% /sys/fs/cgroup

udev            988M  4.0K  988M   1% /dev

tmpfs           201M  492K  200M   1% /run

/dev/sdb1       9.8G   37M  9.2G   1% /data

 

# 取消挂载

# umount /data

# 删除分区并重新建立分区

# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.25.1).

Changes will remain in memory only, until you decide to write them.

Be careful before using the write command.

Command (m for help): d

Selected partition 1

Partition 1 has been deleted.

 

Command (m for help): p

Disk /dev/sdb: 15 GiB, 16106127360 bytes, 31457280 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: 0x41b124e6

 

Command (m for help): n

Partition type

   p   primary (0 primary, 0 extended, 4 free)

   e   extended (container for logical partitions)

Select (default p): p

Partition number (1-4, default 1):

First sector (2048-31457279, default 2048):

Last sector, +sectors or +size{K,M,G,T,P} (2048-31457279, default 31457279):

 

Created a new partition 1 of type 'Linux' and of size 15 GiB.

 

Command (m for help): p

Disk /dev/sdb: 15 GiB, 16106127360 bytes, 31457280 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: 0x41b124e6

Device     Boot Start      End  Sectors Size Id Type

/dev/sdb1        2048 31457279 31455232  15G 83 Linux

Command (m for help): w

The partition table has been altered.

Calling ioctl() to re-read partition table.

Syncing disks.

 

扩展分区大小

# resize2fs /dev/sdb1 14.9G

resize2fs 1.42.10 (18-May-2014)

resize2fs: Invalid new size: 14.9G

# 如果是下面的情况就会报错,扩展容量不能大于总block

root@ubuntu:~# resize2fs /dev/sdb1 15G

resize2fs 1.42.10 (18-May-2014)

The containing partition (or device) is only 3931904 (4k) blocks.

You requested a new size of 3932160 blocks.

#检查文件系统正确性

root@ubuntu:~# e2fsck -f /dev/sdb1

e2fsck 1.42.10 (18-May-2014)

Pass 1: Checking inodes, blocks, and sizes

Pass 2: Checking directory structure

Pass 3: Checking directory connectivity

Pass 4: Checking reference counts

Pass 5: Checking group summary information

/dev/sdb1: 1836/655360 files (0.2% non-contiguous), 83256/2621184 blocks

# 将分区挂载到相应目录

# mount /dev/sdb1 /data

# df –h

root@ubuntu:~# df -h

Filesystem      Size  Used Avail Use% Mounted on

/dev/sda1        57G  1.9G   53G   4% /

none            4.0K     0  4.0K   0% /sys/fs/cgroup

udev            988M  4.0K  988M   1% /dev

tmpfs           201M  492K  200M   1% /run

/dev/sdb1        15G   38M   14G   1% /data

 

 硬盘扩展完成,请查看文件内容是否变动

 

转载于:https://my.oschina.net/FrankXin/blog/808983

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值