8.5. Changing the Size of the LVM-Partitions

WarningRemember to reduce the size of the filesystem.
 

You must remember to reduce the size of the filesystem that is on the volume before you shrink the volume itself, otherwise you will lose data. When shrinking the size of the filesystem, you must know the knew size of the volume, in blocks!!!!

WarningRemember backing up your data before trying to resize your filesystems!
 

It's always smart to read the manual-pages regarding the commands you use. The manual-page for lvreduce, says it all:


tjener:~# man lvreduce
       lvreduce allows you to reduce the size of a logical volume.  Be careful
       when reducing a logical volume's size, because data in the reduced part
       is lost!!!
       You  should  therefore  ensure  that  any  filesystem  on the volume is
       resized before running lvreduce so that the  extents  that  are  to  be
       removed are not in use.

Tip

You should definitely supplement this short introduction to lvm with the full in-depth documentation on LVM which is available from The Linux Documentation Project under the link LVM-HOWTO

At the moment, there are 7 partitions of the lvm type in Skolelinux/Debian-edu. They are grouped in two different vg's, vg_system and vg_data:

  1. /usr, see Section 8.5.1

  2. /skole/tjener/home0, see Section 8.5.2

  3. /skole/backup, see Section 8.5.3

  4. /var, see Section 8.5.4

  5. /var/opt/ltsp/swapfiles, see Section 8.5.5

  6. swap, see Section 8.5.6

  7. /var/spool/squid, see Section 8.5.7

8.5.1. Resizing the /usr Partition

This lv belongs to vg_system. It's present in the profiles mainserver, workstation and thinclientserver.

All installed programs are placed in this partition. If this partition is full, you can't add new packages to the system, other than that the system will function just fine.

The resizing of this partition is a bit tricky.

  1. The tricky part about resizing this partition is that you have to unmount the partition that you are using, which is kind of like sawing off a tree branch that you are sitting on. However, we can manage it by using a neat little trick- switching to the shell ash. First, you need to bring the machine down to runlevel 1 with the command init 1.

    First of all, you need to tell all your users that they have to logout, otherwise they will be forcibly logged out, then type

    init 1

    from the command line.

    You can verify that you now are running under a different runlevel with the command runlevel

    
tjener:~# runlevel
    1 S
    
    You might also see "Unknown" instead of "1 S"

  2. First you need to notice the current size of /usr before you change it, use the command df -h /usr

    
tjener:~#df -h /usr
    Filesystem            Size  Used Avail Use% Mounted on
    /dev/vg_system/lv_usr
                                  1.0G  400M  600M  40%  /usr
    
  3. Then have a look at how much free space there is in vg_system

    vgdisplay /dev/vg_system

    Look for a line such as:

    Free  PE / Size       175 / 5.47 GB
  4. The machine is now in runlevel 1. Login as user root and switch to another shell

    exec /bin/ash

    You will recognize that you are using a different shell by the prompt, which looks like: \h:w\$. If you make a typo in the shell ash, you have to start writing the command all over again, because the BACKSPACE and Arrow keys don't work here. You start all over with CTRL-C

  5. Before you can unmount the partition /usr, you must unmount all other partitions.

    
tjener:~# exec /bin/ash
    \h:\w$ df -h
    Filesystem            Size  Used Avail Use% Mounted on
    /dev/hda1             206M   70M  126M  36% /
    tmpfs                 126M     0  126M   0% /dev/shm
    /dev/mapper/vg_system-lv_usr
                          933M  409M  486M  46% /usr
    /dev/mapper/vg_system-lv_var
                          388M   37M  335M  10% /var
    /dev/mapper/vg_data-lv_home0
                          489M  8.1M  461M   2% /skole/tjener/home0
    /dev/mapper/vg_data-lv_backup
                          669M   17M  619M   3% /skole/backup
    /dev/mapper/vg_system-lv_squid
                          237M  8.1M  217M   4% /var/spool/squid
    none                  126M     0  126M   0% /tmp
    tmpfs                  10M  652K  9.4M   7% /dev
    \h:\w$ umount /var/spool/squid
    \h:\w$ umount /skole/backup
    \h:\w$ umount /skole/tjener/home0
    \h:\w$ umount /var
    \h:\w$ umount /usr
    \h:\w$ df -h
    Filesystem            Size  Used Avail Use% Mounted on
    /dev/hda1             206M   70M  126M  36% /
    tmpfs                  10M  652K  9.4M   7% /dev
    

  6. If you found, when checking the space available in vg_system, something like this:

    vgdisplay /dev/vg_system

    Free  PE / Size       175 / 5.47 GB
    then you have 5.47GB free space that you can use to extend lv_usr

    If you want to increase the size with 1GB, then this is the commands to use:

    e2fsck -fy /dev/vg_system/lv_usr
    lvextend --size +1G /dev/vg_system/lv_usr
    resize2fs /dev/vg_system/lv_usr

    If you want to increase the size with 100MB, then this is the commands to use:

    e2fsck -fy /dev/vg_system/lv_usr
    lvextend --size +100M /dev/vg_system/lv_usr
    resize2fs /dev/vg_system/lv_usr

    If the resize was successful, then you can mount the partition with mount /usr. Then check the new size of the partition with df -h /usr. In this case it should look something like:

    Filesystem            Size  Used Avail Use% Mounted on
    /dev/vg_system/lv_usr
                                  2.0G  400M  1.6G  20%  /usr
    

  7. Now you can restart the machine with init 6, and your users can logon.

8.5.2. Resizing /skole/tjener/home0

This lv belongs to vg_data. It's only present in the profile mainserver

This is the partition where the users' home directories are stored.

The resizing of /skole/tjener/home0 is done pretty much the same way as with /usr. As a matter of fact it's much easier, since it doesn't involve changing to runlevel 1 or changing the shell. I'll briefly mention the relevant commands; see resize /usr for more info.

  1. Login as root, and tell all your users they must logout.

  2. Check the current size of your partition,

    df -h /skole/tjener/home0

  3. Unmount the partition,

    umount /skole/tjener/home0

  4. If you get

    
tjener:~# umount /skole/tjener/home0/
    umount: /skole/tjener/home0: device is busy
    umount: /skole/tjener/home0: device is busy
    
    It might help stopping nfs, since /skole/tjener/home0/ might be nfs-mounted on thinclientserver and workstations.

    
tjener:~# /etc/init.d/nfs-common stop
    Stopping NFS common utilities: statd.
    tjener:~# /etc/init.d/nfs-kernel-server stop
    Stopping NFS kernel daemon: mountd nfsd.
    Unexporting directories for NFS kernel daemon...done.
    

    Then try again to unmount.

    Note

    If you have stopped nfs, remember to start it afterwards, once you are done with resizing and have mounted it again.

  5. Check the amount of available space in the volume group,

    vgdisplay /dev/vg_data

    
tjener:~# vgdisplay /dev/vg_data
      --- Volume group ---
      VG Name               vg_data
      System ID
      Format                lvm2
      Metadata Areas        1
      Metadata Sequence No  6
      VG Access             read/write
      VG Status             resizable
      MAX LV                0
      Cur LV                2
      Open LV               2
      Max PV                0
      Cur PV                1
      Act PV                1
      VG Size               1.94 GB
      PE Size               4.00 MB
      Total PE              496
      Alloc PE / Size       296 / 1.16 GB
      Free  PE / Size       200 / 800.00 MB
      VG UUID               xplJyV-3xRB-H3FU-jO9Q-8CrV-R8mL-ZWxb2R
    
    You can also use

    pvscan

    
tjener:~# pvscan
      PV /dev/hda6   VG vg_data     lvm2 [1.94 GB / 800.00 MB free]
      PV /dev/hda5   VG vg_system   lvm2 [2.73 GB / 692.00 MB free]
      Total: 2 [4.67 GB] / in use: 2 [4.67 GB] / in no VG: 0 [0   ]
    

  6. Resize the partition, in this example it's increased with 100M

    
tjener:~# e2fsck -fy /dev/vg_data/lv_home0
    fsck 1.37 (21-Mar-2005)
    e2fsck 1.37 (21-Mar-2005)
    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/vg_data/lv_home0: 22/103632 files (0.0% non-contiguous), 21334/413696 blocks
    tjener:~# lvextend --size +100M /dev/vg_data/lv_home0
      Extending logical volume lv_home0 to 504.00 MB
      Logical volume lv_home0 successfully resized
    tjener:~# resize2fs /dev/vg_data/lv_home0
    resize2fs 1.37 (21-Mar-2005)
    Resizing the filesystem on /dev/vg_data/lv_home0 to 516096 (1k) blocks.
    The filesystem on /dev/vg_data/lv_home0 is now 516096 blocks long.
    

  7. Mount the partition, mount /skole/tjener/home0

  8. Check the new size of the partition, df -h /skole/tjener/home0

  9. Start nfs again, if you had to stop it.

    tjener:~# /etc/init.d/nfs-kernel-server start
    tjener:~# /etc/init.d/nfs-common start

8.5.3. Resizing /skole/backup

This lv belongs to vg_data. It's only present in the profile mainserver

This is the default partition used for placing the backups made and administered with the Skolelinux/Debian-edu-developed Webmin module slbackup.

Resizing this partition is very similar to resizing /skole/tjener/home0- it belongs to the same vg-group, vg_data.

If you want to increase /skole/backup with 600MB, the command would be

umount /skole/backup
e2fsck -fy /dev/vg_data/lv_backup
lvextend --size +600M /dev/vg_data/lv_backup
resize2fs /dev/vg_data/lv_backup
mount /skole/backup

8.5.4. Resizing /var

This lv belongs to vg_system. It's present in the profiles mainserver and thinclientserver.

The resizing of this partition is done in a similar way to the resizing of /usr, except that you don't need to switch to another shell. But you must remember to unmount the partition /var/opt/ltsp/swapfiles if this is done a machine with the profile Thinclientserver installed. See swapfiles .

You must also remember to umount the partition /var/spool/squid before trying to umount /var, otherwise you just get:


tjener:~# umount /var/
umount: /var: device is busy
umount: /var: device is busy
This means you should be in runlevel 1, use the command init 1.

If you want to increase /var with 400MB, the command would be

umount /var
e2fsck -fy /dev/vg_system/lv_var
lvextend --size +400M /dev/vg_system/lv_var
resize2fs /dev/vg_system/lv_var
mount /var

8.5.5. Resizing /var/opt/ltsp/swapfiles

This lv belongs to vg_system. It's only present in the profile thinclientserver

This partition contains the swapfiles for the thinclients. The size of each of these swapfiles is 32MB.[1][2]

This partition is resized similarly to /skole/tjener/home0.

A reasonable size for this partition would be 32MB times the number of thin clients you plan to have. If you try to boot more thin clients with swapfiles than you have space for in /var/opt/ltsp/swapfiles, then the thin client will not boot.

These swapfiles will be placed in /var/opt/ltsp/swapfiles, with the file names 192.168.0.10.swap, 192.168.0.11.swap,192.168.0.12.swap. If you delete these swapfiles, they will be created again next time the thin client boots.

If you want to increase /var/opt/ltsp/swapfiles with 600MB, the command would be

umount /var/opt/ltsp/swapfiles
e2fsck -fy /dev/vg_system/lv_ltsp_swap
lvextend --size +600M /dev/vg_system/lv_ltsp_swap
resize2fs /dev/vg_system/lv_ltsp_swap
mount /var/opt/ltsp/swapfiles

If there is already thinclients running using such a swapfile, you might have to stop nfs before you manage to umount /var/opt/ltsp/swapfiles

/etc/init.d/nfs-common stop
/etc/init.d/nfs-kernel-server stop

And then when you are done resize, start nfs again

/etc/init.d/nfs-kernel-server start
/etc/init.d/nfs-common start

8.5.6. Swap

This lv belongs to vg_system. It's present in the profiles mainserver, workstation and thinclientserver.

Resize the swap-partition is a bit different than the other partitions, mainly because there is no ext2 filesystem on this partition.

First use free to see the current size of swap


ltspserver05:~# free
             total       used       free     shared    buffers     cached
Mem:        256968      96684     160284          0       5536      48500
-/+ buffers/cache:      42648     214320
Swap:       524280          0     524280

Then turn swap off with the command swapoff


ltspserver05:~# swapoff /dev/vg_system/lv_swap

Then resize the swap-partition, as usual


ltspserver05:~# lvextend --size +200M /dev/vg_system/lv_swap
  Extending logical volume lv_swap to 712,00 MB
  Logical volume lv_swap successfully resized

Then make new swap with the mkswap


ltspserver05:~# mkswap /dev/vg_system/lv_swap
Setting up swapspace version 1, size = 746582 kB
no label, UUID=fd634991-e5ca-4aac-9fe8-a000bde6bc38

Then turn on swap again with the command swapon


ltspserver05:~# swapon /dev/vg_system/lv_swap

Then check if you now have a different swapsize


ltspserver05:~# free
             total       used       free     shared    buffers     cached
Mem:        256968      97036     159932          0       5768      48520
-/+ buffers/cache:      42748     214220
Swap:       729080          0     729080

As you can see, 200MB more swap.

Probably the most interesting would be to make the swap-partition smaller, for that use the same commands as above, but use lvresize -L -300M /dev/vg_system/lv_swap to reduce the size by 300MB


ltspserver05:~# swapoff /dev/vg_system/lv_swap
ltspserver05:~# lvreduce --size -300M /dev/vg_system/lv_swap
  WARNING: Reducing active logical volume to 412,00 MB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv_swap? [y/n]: y
  Reducing logical volume lv_swap to 412,00 MB
  Logical volume lv_swap successfully resized
ltspserver05:~# mkswap /dev/vg_system/lv_swap
Setting up swapspace version 1, size = 432009 kB
no label, UUID=9db01ef6-7623-4e5b-956e-b6fe607aec4f
ltspserver05:~# swapon /dev/vg_system/lv_swap
ltspserver05:~# free
             total       used       free     shared    buffers     cached
Mem:        256968      97576     159392          0       6456      48544
-/+ buffers/cache:      42576     214392
Swap:       421880          0     421880

8.5.7. Resizing /var/spool/squid

This lv belongs to vg_system and it's only present in the profile mainserver. This partition hold the cache belonging to squid, which is a FTP, HTTP and HTTPS proxy cache. This partition is changed the same way as swapfiles. Make sure you stop squid before you try to resize,

/etc/init.d/squid stop

otherwise you only end up with
umount: /var/spool/squid: device is busy

The maximum size of this cache is default set to 100MB; look in the file /etc/squid/squid.conf for the line number 699

# cache_dir ufs /var/spool/squid 100 16 256

If you need a bigger squid-cache, remove the # in front of the line, and change the 100 to desired size. Then you must stop squid, resize the squid-cache and finally start squid again. If you need 500MB for your squid-cache, this line will do that:


cache_dir ufs /var/spool/squid 500 32 256

/etc/init.d/squid stop
squid -z
/etc/init.d/squid start

8.5.8. Adding a New Volume(lv)

For things such as video and picture, as well as users that need extra file space, you might need to create a new volume. Let's pretend you need a volume for our video footage. Let us name it video, and place it in vg_data as /dev/vg_data/lv_video, and mount it at /skole/video

First you need to find out how much space you have available in vg_data

vgdisplay /dev/vg_data

or maybe there is more space in vg_system

vgdisplay /dev/vg_system

Another option that displays the same kind of information is

pvscan

You must create the mount point /skole/video

mkdir /skole/video

Then you create the new volume

lvcreate --size 2G --name lv_video vg_data

In this example, the size is 2GB. Have a look at
lvm-home0 to find out how to resize this. Then you need to make a file system

mke2fs -j /dev/vg_data/lv_video

Then add this new partition, using your favourite texteditor, to /etc/fstab, otherwise this new partition won't be mounted automatically at boot. In our example you add this line at the end of /etc/fstab


/dev/vg_data/lv_video  /skole/video          ext3    defaults                0       2

Now you test your new partition by mounting it manually with mount /skole/video. Have a look at the size with

df -h /skole/video

8.5.8.1. Adding the New Volume to autofs

WarningNot tested with Sarge
 

This has not yet been tested with Sarge.

This warning will go away once it has been tested.

Skolelinux/Debian-edu uses autofs to export partitions to machines that might need them, workstation and thinclientserver needs to be able to mount the users home directories. So, if you have made another home partition, for example /skole/tjener/home1 and /skole/tjener/home2 then you must make sure that they are also exported along with /skole/tjener/home0 via autofs to the needed machines. The necessary information lies in the LDAP-database, so we must add this new information the LDAP-database. This is most easily done by adding this new information to a file, and then adding the contents of this file to our LDAP-database. Let's call this file /root/video.ldif, with these contents:


dn: cn=video,ou=tjener,ou=skole,ou=Automount,dc=skole,dc=skolelinux,dc=no
objectClass: top
objectClass: automount
cn: video
automountInformation: -rw,rsize=8192,wsize=8192,intr tjener:/skole/video
description: /skole/video mount point
This is the info that you want to add, like this:

/etc/init.d/slapd stop
/etc/init.d/nscd stop
slapadd -l /root/video.ldif
/etc/init.d/slapd start
/etc/init.d/nscd start

In addition, this partition must be added to the export file by adding the following line to the file /etc/exports


/skole/video @ltsp-server-hosts(rw,async) @workstation-hosts(rw,async) @server-hosts(rw,async)

	    
After that you must run exportfs -ra

8.5.9. Adding a New Disk to LVM in Skolelinux/Debian-edu

Hook up the new disk to the system. In this example, it becomes /dev/hdb, and we will add it to the volume group vg_data

We will add the whole disk, without partitioning it first.

First lets use the command pvscan to se what we have


tjener:/dev# pvscan
  PV /dev/hda6   VG vg_data     lvm2 [1.94 GB / 800.00 MB free]
  PV /dev/hda5   VG vg_system   lvm2 [2.73 GB / 692.00 MB free]
  Total: 2 [4.67 GB] / in use: 2 [4.67 GB] / in no VG: 0 [0   ]

Then we create a volume group descriptor on the disk, using the command pvcreate


tjener:/dev# pvcreate /dev/hdb
  Physical volume "/dev/hdb" successfully created

Then we add the whole disk /dev/hdb to the volume-group vg_data using the command


tjener:/dev# vgextend vg_data /dev/hdb
  Volume group "vg_data" successfully extended

Then we use pvscan again to verify that we indeed have managed to successfully add /dev/hdb to vg_data


tjener:/dev# pvscan
  PV /dev/hda6   VG vg_data     lvm2 [1.94 GB / 800.00 MB free]
  PV /dev/hdb    VG vg_data     lvm2 [6.83 GB / 6.83 GB free]
  PV /dev/hda5   VG vg_system   lvm2 [2.73 GB / 692.00 MB free]
  Total: 3 [11.50 GB] / in use: 3 [11.50 GB] / in no VG: 0 [0   ]

That looks nice, now we may resize any of the lv-groups lv_home or lv_backup with more than the original 800MB that we had free. Lets se if we can manage to increase /skole/backup with 1000M, which should then make /skole/backup span across two different disks.


tjener:~# umount /skole/backup/
tjener:~# e2fsck -fy /dev/vg_data/lv_backup
tjener:~# resize2fs /dev/vg_data/lv_backup
tjener:~# lvextend --size +1000M /dev/vg_data/lv_backup
tjener:~# mount /skole/backup/
tjener:~# df -h /skole/backup
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_data-lv_backup
                      1.7G   17M  1.6G   2% /skole/backup
tjener:~# pvscan
  PV /dev/hda6   VG vg_data     lvm2 [1.94 GB / 0    free]
  PV /dev/hdb    VG vg_data     lvm2 [6.83 GB / 6.64 GB free]
  PV /dev/hda5   VG vg_system   lvm2 [2.73 GB / 692.00 MB free]
  Total: 3 [11.50 GB] / in use: 3 [11.50 GB] / in no VG: 0 [0   ]

As you can see, /skole/backup is now 1G bigger, and there is 0 Free in /dev/hda6 while there is still place in /dev/hdb for vg_data to grow.

8.5.10. Activating the lvm-volumes from a KNOPPIX cd

Sometimes things go horribly wrong, and your system ends up being really hosed. In such a case it is very often lifesaving having a KNOPPIX cd lying about.

I trust you did download/order a KNOPPIX cd as I suggest you do in Section 6.1

I use KNOPPIX_V4.0 in this example, but any other recent version of KNOPPIX or any similar live-cd should probably also work just as well

Boot up your non-optimal-working system. I prefer to just use runlevel 2 (no GUI), that boots much faster than a full GUI, and I don't need any mouse. So you can either just press Enter to boot full GUI KNOPPIX.

Once you have booted KNOPPIX, make sure you have Internet connectivity, the command ifconfig will tell. If you don't have any ip-address, then run the command netcardconfig and just follow the instructions. You need a functional network because we need to download some packages.

apt-get update

You might see a few error messages at this point, something relating to Ndiswrapper, never mind those.

apt-get install lvm2 lvm-common

Now we may activate the lvm-groups and volumes

modprode dm-mod
lndir /lib/lvm-200/ /usr/sbin/
vgscan
vgchange -a y

If everything went well, you should see some info about KNOPPIX having found your lvm-groups.

Lets assume that you have an IDE disk as master on channel 1, which would you make your disk a hda.

We need to mount it, but first we must make a mountpoint

mkdir /mnt/lvm
mount /dev/hda1 /mnt/lvm

Now you may begin mounting those lvm-partitions you have, like

mount /dev/vg_data/lv_home0 /mnt/lvm/skole/tjener/home0

Now you can use tools such as scp, ssh and tar to transfer files over to another machine. Have a look at Section 9.3 for more info about how to use these tools. For now I'll just say that if you want to transfer the whole content of /skole/tjener/home0, which holds all you users files, over to another linux-machine with ip-address 10.0.2.50 and there place it in /backup, this command will do that

tar czvf - /mnt/lvm/skole/tjener/home0 | ssh root@10.0.2.50 "cat >/backup/home0.tgz"

Notes

[1]

The thin clients must have their MAC address locked to an IP address in /etc/dhcp3/dhcpd.conf in order to get a swapfile.

[2]

The size of these swapfiles, and whether they are enabled or not, is defined in /opt/ltsp/i386/etc/lts.conf. Look for the lines


SWAPFILE_SIZE=32m
USE_NFS_SWAP = Y