Jaime Frutos Morales's blog

29/01/2010

How to reduce a logical volume in GNU/Linux using LVM

Filed under: Linux, SysAdmin — acidborg @ 14:01

Description: previously, on this post, I explain how to extend a logical volume using LVM. Now, I’m going to explain how to reduce it without data loss (if you aren’t using all the available space, of course). In this example, I’m going to reduce a logical volume called logical_volume1 belonging to the volume group volume_group1 to 85 Gb of disk space. It’s mounted on /mnt/logical_volume1 .

Steps:

  1. Umount the logical volume: umount /mnt/logical_volume1
  2. Make a backup of the logical volume
  3. Check the filesystem integrity: fsck -f -y -v /dev/volume_group1/logical_volume1
  4. Resize the filesystem to something smaller than the final size (around 80GB in this case): resize2fs /dev/volume_group1/logical_volume1 80000M
  5. Check the filesystem integrity again: fsck -f -y -v /dev/volume_group1/logical_volume1
  6. Reduce the logical volume: lvreduce -L 85G /dev/volume_group1/logical_volume1
  7. Resize the filesystem to fit the logical volume: resize2fs /dev/volume_group1/logical_volume1
  8. Check the filesystem to know whether the reduction went fine: fsck -f -y -v /dev/volume_group1/logical_volume1
  9. Mount the logical volume: mount /mnt/logical_volume1

NOTE: if you aren’t careful with the disk space you are using and the final disk space you are going to be using, this operation can cause data loss. I recommend to backup the logical volume before the reduction and to use around 5GB of “safe space” while reducing the filesystem in order to avoid data loss.

27/01/2010

How to backup a logical volume (snapshots) using LVM

Filed under: Linux, SysAdmin — acidborg @ 11:19

Description: a snapshot is a copy of the state of a logical volume at a particular point. It’s created almost immediately, so it’s very useful to backup large logical volumes. In this example, I’m going to create a snapshot of a logical volume called logical_volume1 beloging to the volume group volume_group1.

Steps:

  1. Check the size of the logical volume (LV Size): lvdisplay /dev/volume_group1/logical_volume1
    --- Logical volume ---
    LV Name /dev/volume_group1/logical_volume1
    VG Name volume_group1
    LV UUID AxihqP-Yt8l-5scY-bXNG-Bn5D-K3ms-X7v1Ys
    LV Write Access read/write
    LV Status available
    # open 1
    LV Size 200,00 GB
    Current LE 6400
    Segments 2
    Allocation inherit
    Read ahead sectors auto
    - currently set to 256
    Block device 253:5

    Usually, snapshots are smaller than the original logical volume, but I recommend to use at least the same space.

  2. Create the snapshot: lvcreate -L200G -s -n backup_logical_volume1 /dev/volume_group1/logical_volume1
  3. The -s param tells lvcreate to create a snapshot instead of a normal logical volume.

25/01/2010

How to extend a logical volume in GNU/Linux using LVM

Filed under: Linux, SysAdmin — acidborg @ 13:54

Description: if you have created a logical volume (maybe following my previous post) and you want to increase its size (if you have enough physical space, of course), LVM can do that easily. In this example, I’m going to extend a logical volume called /dev/volume_group1/logical_volume1 mounted on /mnt/logical_volume1 adding 50GB of disk space which are available in the volume group volume_group1.

Steps:

  1. Unmount the logical volume if it’s mounted: umount /mnt/logical_volume1
  2. Extend the logical volume with 50GB: lvextend -L +50G /dev/volume_group1/logical_volume1
  3. Check the volume group: e2fsck -f /dev/volume_group1/logical_volume1
  4. Resize the filesystem on the logical volume (ext3 in this case): resize2fs /dev/volume_group1/logical_volume1
  5. Mount the logical volume again: mount /mnt/logical_volume1

Extending a logical volume it’s a safe operation which doesn’t involve much downtime. This is one of the many advantages of using LVM to manage disk storage.

21/01/2010

How to configure a network bridge in Debian / Ubuntu

Filed under: Linux, SysAdmin, Ubuntu — acidborg @ 12:23

Description: Following yesterday’s post, today I’m going to explain how to do the same in a Debian / Ubuntu system.

Installation:

Install the packages needed: apt-get install bridge-utils

Configuration:


  • Edit /etc/network/interfaces and replace your eth1 config with this:

    auto eth1
    iface eth1 inet manual

    auto br0
    iface br0 inet static
    address 192.168.1.100
    network 192.168.1.0
    netmask 255.255.255.0
    broadcast 192.168.1.255
    gateway 192.168.1.1
    bridge_ports eth1
    bridge_stp off
    bridge_fd 0
    bridge_maxwait 0

  • Restart your network interfaces: /etc/init.d/networking restart

20/01/2010

How to configure a network bridge in Red Hat / Fedora

Filed under: Linux, SysAdmin — acidborg @ 14:20

Description: a network bridge is a forwarding technique very useful when you have to deal with virtualization and you want to give your virtual machines direct access to your real network, without using NAT.

In this example, I’m going to use a bridge (br0) to access a wired network interface (eth1). I use eth1 for the bridge instead of eth0 because I prefer to use the first network interface to access the machine using SSH and fix any problems that could appear while configuring the bridge.

Installation:

Use yum to install the packages needed: yum install bridge-utils

Configuration:

  • Edit /etc/sysconfig/network-scripts/ifcfg-eth1 and write this (changing the HWADDR for the MAC address of your network card):

    DEVICE=eth1
    HWADDR=00:11:22:33:44:55
    ONBOOT=yes
    BRIDGE=br0
  • Edit /etc/sysconfig/network-scripts/ifcfg-br0 with this content (change the IP related fields to fit your needs):

    DEVICE=br0
    TYPE=Bridge
    ONBOOT=yes
    DELAY=0
    BOOTPROTO=static
    BROADCAST=192.168.1.255
    IPADDR=192.168.1.100
    NETMASK=255.255.255.0
    NETWORK=192.168.1.0
    GATEWAY=192.168.1.1
  • Add these lines to /etc/sysctl.conf in order to disable packet filtering in the bridge:

    net.bridge.bridge-nf-call-ip6tables = 0
    net.bridge.bridge-nf-call-iptables = 0
    net.bridge.bridge-nf-call-arptables = 0

    This improves the bridge’s performance. I recommend to use packet filtering in the computers which connect through the bridge, but not in the bridge itself.

  • Apply the syscttl changes: sysctl -p /etc/sysctl.conf
  • Restart your network interfaces: service network restart
Older Posts »

Blog at WordPress.com.