Skip to main content

Increasing Server Partition size

Submitted by daniel on

When online servers are setup, for some reason the allocated partitions on the hard drive may need to be adjusted manually to take advantage of the the amount of space available. These instructions are specific to Centos but similar likely applies to other Linux distros.

We can look at what the current partitions and there allocated size by using the df command. the -h flag sets the out put to be human readable

df -h
Filesystem             Size  Used Avail Use% Mounted on
devtmpfs               7.8G     0  7.8G   0% /dev
tmpfs                  7.9G     0  7.9G   0% /dev/shm
tmpfs                  7.9G  817M  7.1G  11% /run
tmpfs                  7.9G     0  7.9G   0% /sys/fs/cgroup
/dev/md1               4.0G  353M  3.6G   9% /
/dev/mapper/vg00-usr   4.8G  3.4G  1.2G  75% /usr
none                   7.9G   84K  7.9G   1% /tmp
/dev/mapper/vg00-var    15G  1.3G   13G  10% /var
/dev/mapper/vg00-home  4.8G   11M  4.6G   1% /home
tmpfs                  1.6G     0  1.6G   0% /run/user/996
tmpfs                  1.6G     0  1.6G   0% /run/user/0

I can see at a glance that the partitions we are only using a fraction of the available disk space.

Notice how the var usr and home partitions are prefixed by the volume group, in this case vg00

You can also use the fdisk command to get a bit more info. e.g.

fdisk -l

Disk /dev/sdb: 2000.4 GB, 2000398934016 bytes, 3907029168 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
Disk label type: dos
Disk identifier: 0x0398f66a

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     8390655     4194304   fd  Linux raid autodetect
/dev/sdb2         8390656    12584959     2097152   82  Linux swap / Solaris
/dev/sdb3        12584960  3907029167  1947222104   fd  Linux raid autodetect

Disk /dev/sda: 2000.4 GB, 2000398934016 bytes, 3907029168 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
Disk label type: dos
Disk identifier: 0x08c9aa95

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048     8390655     4194304   fd  Linux raid autodetect
/dev/sda2         8390656    12584959     2097152   82  Linux swap / Solaris
/dev/sda3        12584960  3907029167  1947222104   fd  Linux raid autodetect

Disk /dev/md1: 4294 MB, 4294901760 bytes, 8388480 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


Disk /dev/md3: 1994.0 GB, 1993955344384 bytes, 3894444032 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


Disk /dev/mapper/vg00-usr: 5368 MB, 5368709120 bytes, 10485760 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


Disk /dev/mapper/vg00-var: 16.1 GB, 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


Disk /dev/mapper/vg00-home: 5368 MB, 5368709120 bytes, 10485760 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

It appears here that both /dev/sdb and /dev/sda loo identical with an allocation of 2000.4 GB, 2000398934016 bytes, 3907029168 sectors. Not sure why this is but may be because it is set up as a raid (parallel) configuration.

We can also use the parted command to output this in a more succinct way:

 parted /dev/sdb unit GB print free
Model: ATA TOSHIBA MG04ACA2 (scsi)
Disk /dev/sdb: 2000GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system     Flags
        0.00GB  0.00GB  0.00GB           Free Space
 1      0.00GB  4.30GB  4.29GB  primary  ext3            raid
 2      4.30GB  6.44GB  2.15GB  primary  linux-swap(v1)
 3      6.44GB  2000GB  1994GB  primary                  raid

ok so let have look at the /var partition. I would like to increase this specifically.

 df -h /var
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg00-var   15G  1.3G   13G  10% /var

Notice how the var bit is prefixed with the volume group, in this case vg00

I can also use this info in combination with the vgdisplay command to display volume group information

 vgdisplay -v vg00
  --- Volume group ---
  VG Name               vg00
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  6
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               1.81 TiB
  PE Size               4.00 MiB
  Total PE              475395
  Alloc PE / Size       6400 / 25.00 GiB
  Free  PE / Size       468995 / <1.79 TiB
  VG UUID               EiTXR0-ootQ-mmyC-tbg7-6ssZ-2psB-XVDUcf
   
  --- Logical volume ---
  LV Path                /dev/vg00/usr
  LV Name                usr
  VG Name                vg00
  LV UUID                26cSdc-4fWe-pxUh-IeSz-git4-bfJn-hNNj5T
  LV Write Access        read/write
  LV Creation host, time , 
  LV Status              available
  # open                 1
  LV Size                5.00 GiB
  Current LE             1280
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
   
  --- Logical volume ---
  LV Path                /dev/vg00/var
  LV Name                var
  VG Name                vg00
  LV UUID                NyXA5x-7VGf-bvRB-SdE3-hXjz-ICjH-TEioLX
  LV Write Access        read/write
  LV Creation host, time , 
  LV Status              available
  # open                 1
  LV Size                15.00 GiB
  Current LE             3840
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/vg00/home
  LV Name                home
  VG Name                vg00
  LV UUID                l0eN9s-D7kl-ugcP-HCOR-TCTx-TuHi-NWMFCe
  LV Write Access        read/write
  LV Creation host, time , 
  LV Status              available
  # open                 1
  LV Size                5.00 GiB
  Current LE             1280
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2
   
  --- Physical volumes ---
  PV Name               /dev/md3     
  PV UUID               cdHy3n-2eQk-y8k5-Avlv-sQxb-1a0c-ZIUnG7
  PV Status             allocatable
  Total PE / Free PE    475395 / 468995
df -h /var/
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg00-var   15G  1.3G   13G  10% /var

We can use this info to extend the Logical volume using the lvextend command to add space to a logical volume. e.g.

lvextend -L +10GB /dev/vg00/var 

We are nearly done. finally we need to resize2fs command to actually make the change. e.g

resize2fs /dev/vg00/var

Finally you can check the changes using the df command:

 df -h /var/
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg00-var   15G  1.3G   13G  10% /var

 

Add new comment

Filtered HTML

  • Web page addresses and email addresses turn into links automatically.
  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.