Archive for November, 2013

7 November, 2013 — Hosting

How to Extended a Linux Logical Volume

I recently upgraded the disk space on one of my Linux VPS servers and once the upgrade was done the space was still not added to the server… after a search around on the internet I found that I needed to Extend the Logical Volume of the VPS to add the extra 40GB of HDD space.

Below is a step by step guide of how to do this. Extending your LV should not delete any data however I can’t be held responsible if this does happen. However removing space from your LV will result in data loss. This guide is only extending the LV so you shouldn’t run into any trouble.

Please comment below if you have any questions regarding this!

Show Me How!

First, check the drives on the server with fdisk -l:

# fdisk -l
Disk /dev/hda: 85.8 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
  Device Boot      Start        End      Blocks  Id  System
/dev/hda1  *          1          33      265041  83  Linux
/dev/hda2              34        164    1052257+  82  Linux swap / Solaris
/dev/hda3            165        5221    40620352+  8e  Linux LVM
Disk /dev/sda: 85.8 GB, 85899345920 bytes
16 heads, 63 sectors/track, 166440 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
  Device Boot      Start        End      Blocks  Id  System
/dev/sda1              1      83220    41942272+  8e  Linux LVM
We will first add the extra 40GB from the system drive (hda). Start to modify the partition table with fdisk, specifying the drive “hda”
# fdisk /dev/hda
The number of cylinders for this disk is set to 10443.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
  (e.g., DOS FDISK, OS/2 FDISK)
Command (m for help):
 At this prompt, you can type “p” to display the current partitioning:
Command (m for help): p
Disk /dev/hda: 85.8 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
  Device Boot      Start        End      Blocks  Id  System
/dev/hda1  *          1          33      265041  83  Linux
/dev/hda2              34        164    1052257+  82  Linux swap / Solaris
/dev/hda3            165        5221    40620352+  8e  Linux LVM
Command (m for help):
We want to add another partition so type “n” then “p” and specify partition “4” as 1, 2 and 3 are used. The next two prompts can be left blank to use the default.
Command (m for help): n
Command action
  e  extended
  p  primary partition (1-4)
p
Selected partition 4
First cylinder (5222-10443, default 5222):
Using default value 5222
Last cylinder or +size or +sizeM or +sizeK (5222-10443, default 10443):
Using default value 10443
Command (m for help):
Now, we change the partition we created to LVM. Type “t” at the prompt, specify partition 4 and then put in the code “8e” to set it to Linux LVM.
Command (m for help): t
Partition number (1-4): 4
Hex code (type L to list codes): 8e
Changed system type of partition 4 to 8e (Linux LVM)
Command (m for help):
Type “p” to make sure the partition is there and set to Linux LVM.
Command (m for help): p
Disk /dev/hda: 85.8 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
  Device Boot      Start        End      Blocks  Id  System
/dev/hda1  *          1          33      265041  83  Linux
/dev/hda2              34        164    1052257+  82  Linux swap / Solaris
/dev/hda3            165        5221    40620352+  8e  Linux LVM
/dev/hda4            5222      10443    41945715  8e  Linux LVM
Command (m for help):
Type “w” at the prompt to write the changes. This may give you a notice that you need to reboot. If this is the case, simply type “reboot” at the command line.
Command (m for help): w
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.
Syncing disks.
# reboot
Broadcast message from root (pts/0) (Thu Oct 31 13:47:39 2013):
The system is going down for reboot NOW!
When the server has come back up, log back in and at the command prompt, check the Physical Volume by typing “pvdisplay”
# pvdisplay
  — Physical volume —
  PV Name              /dev/hda3
  VG Name              VolGroup00
  PV Size              38.74 GB / not usable 20.31 MB
  Allocatable          yes (but full)
  PE Size (KByte)      32768
  Total PE              1239
  Free PE              0
  Allocated PE          1239
  PV UUID              OEY2Ya-0SCL-t8M6-n3yR-lWs7-Kr1z-8UraBM
  — Physical volume —
  PV Name              /dev/sda1
  VG Name              VolGroup00
  PV Size              40.00 GB / not usable 31.25 MB
  Allocatable          yes (but full)
  PE Size (KByte)      32768
  Total PE              1279
  Free PE              0
  Allocated PE          1279
  PV UUID              lXOcRG-1TLW-rpHj-Xzwb-3W9o-49jV-MLMf8N
We now want to add the new partition with pvcreate and specifying the new partition:
# pvcreate /dev/hda4
  Writing physical volume data to disk “/dev/hda4”
  Physical volume “/dev/hda4” successfully created
We can confirm this is added with pvdisplay.
# pvdisplay
  — Physical volume —
  PV Name              /dev/hda3
  VG Name              VolGroup00
  PV Size              38.74 GB / not usable 20.31 MB
  Allocatable          yes (but full)
  PE Size (KByte)      32768
  Total PE              1239
  Free PE              0
  Allocated PE          1239
  PV UUID              OEY2Ya-0SCL-t8M6-n3yR-lWs7-Kr1z-8UraBM
  — Physical volume —
  PV Name              /dev/sda1
  VG Name              VolGroup00
  PV Size              40.00 GB / not usable 31.25 MB
  Allocatable          yes (but full)
  PE Size (KByte)      32768
  Total PE              1279
  Free PE              0
  Allocated PE          1279
  PV UUID              lXOcRG-1TLW-rpHj-Xzwb-3W9o-49jV-MLMf8N
  “/dev/hda4” is a new physical volume of “40.00 GB”
  — NEW Physical volume —
  PV Name              /dev/hda4
  VG Name
  PV Size              40.00 GB
  Allocatable          NO
  PE Size (KByte)      0
  Total PE              0
  Free PE              0
  Allocated PE          0
  PV UUID              rHvm5B-MA1d-shpx-3dxp-QCoq-Xhhl-x8KWax
You can view the current volume group with “vgdisplay” to get the VG name
# vgdisplay
  — Volume group —
  VG Name              VolGroup00
  System ID
  Format                lvm2
  Metadata Areas        3
  Metadata Sequence No  6
  VG Access            read/write
  VG Status            resizable
  MAX LV                0
  Cur LV                1
  Open LV              1
  Max PV                0
  Cur PV                3
  Act PV                3
  VG Size              78.69 GB
  PE Size              32.00 MB
  Total PE              3798
  Alloc PE / Size      3798 / 78.69 GB
  Free  PE / Size      0 / 0
  VG UUID              H7RyAi-ZTUo-hH0t-nnGi-IBRN-qeMl-umrblW
Extend the Volume Group to include the new partition
# vgextend VolGroup00 /dev/hda4
  Volume group “VolGroup00” successfully extended
Next, we want to check the Logical Volume with lvdisplay. (Note that I had gone back and added the other partition before continuing here),
# lvdisplay
  — Logical volume —
  LV Name                /dev/VolGroup00/LogVol00
  VG Name                VolGroup00
  LV UUID                sorbDy-tdpk-dqdp-YAfe-OSrs-zDHS-PUvG4K
  LV Write Access        read/write
  LV Status              available
  # open                1
  LV Size                118.69 GB
  Current LE            3798
  Segments              3
  Allocation            inherit
  Read ahead sectors    auto
  – currently set to    256
  Block device          253:0
Take note of the “LV Name” and then we can extend the logical volume using “lvextend”. We can specify the size however by using 100%FREE, it will use all available space.
# lvextend -l +100%FREE /dev/VolGroup00/LogVol00
  Extending logical volume LogVol00 to 158.69 GB
  Logical volume LogVol00 successfully resized
Finally, we resize to the file system so the space is usable with “resize2fs” which can take a few minutes to complete
# resize2fs /dev/VolGroup00/LogVol00
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing required
Performing an on-line resize of /dev/VolGroup00/LogVol00 to 41598976 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVol00 is now 41598976 blocks long.
You can confirm the space is usable by running “df -h” again.
# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                      154G  69G  78G  47% /
/dev/hda1            251M  86M  153M  36% /boot
tmpfs                500M    0  500M  0% /dev/shm
/usr/tmpDSK          549M  21M  500M  4% /tmp
The extra space is now usable on your server.
Comment below if you have any questions regarding this!
.
5 November, 2013 — Development

Center a Block Element Without Knowing its Width

Centering an element may seem quite simple thinking that “text-align:center” will solve the problem. Or maybe set “width” and “margin: 0 auto”, but what happens when you need to center a block element with variable width?

W3C tells us that we can use “margin: 0 auto” to center tables so why shouldn’t we use display: table to center a fluid div:

#my-element {
  display: table;
  margin: 0 auto;
}

This can solve many problems and does a good job in some cases but you must be aware that “display: table” is not working when using our “beloved” Internet Explorer (IE5.5, IE 6, IE 7) so don’t count on this for main design elements (especially if this ruins your design).

I hope this was useful for you! If you have any comments or suggestions, do not hesitate to post them in the comments section.

Photo Credit: Zzpza