Using FDISK to expand partition capacity under Linux

Source: Internet
Author: User

Guide The servers we manage may be running out of disk space as the volume of business grows, such as: the lack of hard disk space for shared file servers, when we need to increase disk space to meet online business, or when we are using Linux, Sometimes because of improper partition when installing the system, there is not enough partition space, and some of the excess partition space can be used to dynamically adjust the partition size using the Fdisk partition tool;
Expand disk Space

Hard disk space is 20G, using vsphere client to increase disk size, need to increase 10G space;

After the expansion, restart the system, again using Fdisk-l view, you will find that the hard disk space becomes larger;

[Email protected] ~]# fdisk-ldisk/dev/sda:32.2 GB, 32212254720 bytes255 heads, + sectors/track, 3916 cylindersunits = Cylinders of 16065 * 8225280 = bytessector size (logical/physical): bytes/512 bytesi/o size (minimum/optimal): bytes/512 bytesdisk identifier:0x0005210c   Device Boot      Start         End      Blocks   Id  system/dev/ SDA1   *           1      204800  linuxpartition 1 does not end on cylinder boundary./dev/sda2              26< c13/>1301    10240000  linux/dev/sda3            1301        1497 1572864 the  Linux swap/ SOLARIS/DEV/SDA4            1497        2611     8952832   ,  linux[[email protected] ~]# Df-htfilesystem     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

re-create partition, adjust partition information

This experiment mainly to/dev/sda4 this partition expansion, if it is a production environment, please save the backup to other partitions in advance, although the size of the extended partition will not result in data loss, for security purposes, please do a good job in advance backup;
Let's start by simulating some of the data:

[[email protected] data]# mkdir test[[email protected] data]# echo "We are linuxer" > Linuxprobe[[email protected] Data ]# lltotal 24-rw-r--r--. 1 root root    21:59 linuxprobedrwx------. 2 root root 16384 May 15:07 lost+founddrwxr-xr-x. 2 root root
   
    4096 may 21:51 Test[[email protected] ~]# umount/dev/sda4          
    #卸载磁盘分区
   

If the disk is busy, use Fuser to locate the program that will be using the disk and end it;

Fuser-m-v/datafuser-m-v-i-k/data

Use the Fdisk tool to remove the/DEV/SDA4 partition first and then create a new partition, noting that the starting Magnetic column number is the same as the original (the key step to ensure the data is not lost), and the end of the magnetic column number is the default carriage return using all disks.

[Email protected] ~]# fdisk/dev/sdawarning:dos-compatible mode is deprecated. It ' s strongly recommended to switch off the mode (command ' C ') and change display units to sectors (Comman d ' u '). Command (M for help): P#查看分区表信息disk/dev/sda:32.2 GB, 32212254720 bytes255 heads, sectors/track, 3916 cylindersunits = cylinders of 16065 * 512 = 822 5280 bytessector Size (logical/physical): bytes/512 bytesi/o size (minimum/optimal): + bytes/512 Bytesdisk ident      ifier:0x0005210c Device Boot Start End Blocks Id system/dev/sda1 * 1 26 204800 linuxpartition 1 does not end on cylinder boundary./dev/sda2-1301 10240000 Nux/dev/sda3 1301 1497 1572864 1497 Linux swap/solaris/dev/sda4 2611 8 952832 Linuxcommand (M for help): D#删除分区Partition number (1-4): 4#删除第四个Command (M for help): P#再次查看分区信息,/DEV/SDA4 has been removeddisk/dev/sda:32.2 GB, 32212254720 bytes255 heads, sectors/track, 3916 cylindersunits = cylinders of 16065 * 512 = 822 5280 bytessector Size (logical/physical): bytes/512 bytesi/o size (minimum/optimal): + bytes/512 Bytesdisk ident      ifier:0x0005210c Device Boot Start End Blocks Id system/dev/sda1 * 1 26 204800 linuxpartition 1 does not end on cylinder boundary./dev/sda2-1301 10240000 Nux/dev/sda3 1301 1497 1572864, Linux Swap/solariscommand (M for help): N#创建新的分区Command Action E Extended P primary partition (1-4) p #创建为主分区Selected partition 4First cylinder (1497-3 916, default 1497):#经对比, exactly the same as the previous disk column, by defaultUsing default value 1497Last 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 bytes255 heads, sectors/track, 3916 cylindersunits = cylinders of 16065 * 512 = 822 5280 bytessector Size (logical/physical): bytes/512 bytesi/o size (minimum/optimal): + bytes/512 Bytesdisk ident      ifier:0x0005210c Device Boot Start End Blocks Id system/dev/sda1 * 1 26 204800 linuxpartition 1 does not end on cylinder boundary./dev/sda2-1301 10240000 Nux/dev/sda3 1301 1497 1572864 1497 Linux swap/solaris/dev/sda4 3916 19 436582 Linuxcommand (M for help): WP#保存并退出, if you create an error, simply exit Do not saveThe 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 is being used atthe next reboot or after you run Partprobe (8) or KPARTX (8) Syncing disks.


After re-creating the partition, a reboot is required;

[[Email protected] ~]# init 6[[email protected] ~]# e2fsck-f/dev/sda4                #检查分区信息[[email protected] ~]# Resize2 Fs-p/dev/sda4             #调整分区大小
re-mount, view partition size, data
[Email protected] ~]# mount/dev/sda4/data[[email protected] ~]# df-ht[[email protected] ~]# Cat/data/linuxprobewe is  Linuxer

Using FDISK to expand partition capacity under Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.