LVM


Updated: 2004-03-09

Process

Installing from the 0.9.2 2.6.3 ISO, I had to do the following to add a new LVM partition group (PG) to an already existing volume group (VG):

1. Boot the ISO and load my SCSI drivers (aic7xxx)
2. Go to "Shell"
3. # mkdir /tmp/etc && cp -a /etc/* /tmp/etc && mount --bind /tmp/etc /etc
`vgscan` needs write access to /etc/lvm
4. # vgscan
This scans all disks and loads any LVM VGs found.
See vgscan
5. # vgchange -ay
This activates all PGs found.
See vgchange
If the initrd provided below is included on the ISO, steps #4 and #5 will already be taken care of. 6. # lvcreate -L8200 -nSMGLRoot Volume00
This will create a new PG named "SMGLRoot" in the VG "Volume00" (which must already exist) and it will be 8.2G.
To see how much free space you have, run `vgdisplay`. See vgdisplay
I already have an existing LVM setup. See layout
To create a new PG, run:
# pvcreate (e.g. /dev/hdb)
# pvcreate (e.g. /dev/hdb1)
To create a new volume group, run:
# vgcreate <groupname> <partition1> <partition2> ... [-s <s;ize>] (e.g. `vgcreate Volume00 /dev/hdb1 /dev/hdb2`)
7. # vgchange -ay
Need to active the new partitions. This has to be run after any change to the partitions for the changes to take affect.
8. To find which dm node (see #9) each device is assigned to, run `lvdisplay`. See lvdisplay and look for "Block Device", which will have the format "<device ID>:<node #>". Now create /dev/dm-<node#> for each of those. From my lvdisplay, I did:
# ln -sf /dev/Volume00/SMGLRoot /dev/dm-3
# ln -sf /dev/Volume00/Swap /dev/dm-2
Since SMGLRoot was "254:3" and Swap was "254:2"; now the installer can find these devices and read/write to them.
9. Return to the installer. The "Format Partions" screen will now list "dm-*" devices and you can use these to format and install on.
The "Format Partions" lists the actual LVM device (/dev/sdb2 on my layout), which shouldn't be as it'd be bad to try and use that as a partition.
10. I made an initrd with the lvmcreate_initrd script (had to get it from my Fedora system, though Sistina apparently provides it, I couldn't find it) which will need to be added to the boot loader and the kernel configured to use initrd. Download the initrd-lvm-2.6.3.gz (created with `lvmcreate_initrd 2.6.3 -M`) and lvmcreate_initrd which I modified a little (see the ChangeLog notes).
UPDATE: I just had problems booting into a new install of SMGL on this same box using the prior created initrd-lvm. A bunch of versioning errors, so I'm not compiling in module versioning support this time and we'll see if that fixes it, though the first boot worked (but I somehow messed up the screen so I was back at "Mount filesystems" and it hadn't finished setting anything up, so I couldn't log in).

Rough notes

These are a verbatim copy of my notes
2004-03-09	Installing with LVM
Loaded my SCSI drivers (aic7xxx)
/etc needs to be writeable for `vgscan`
# mkdir /tmp/etc && cp -a /etc/* /tmp/etc
# mount --bind /tmp/etc /etc
# vgscan
... List of what disks were scanned
  Found volume group "Volume00" using metadata type lvm1
# vgchange -ay
... List of what disks were scanned
  3 logical volume(s) in volume group "Volume00" now active
To create an LVM disk, run:
# pvcreate /dev/hdb
To create a partition (partition type 0x8e), run:
# pvcreate /dev/hdb1
To create a volume group, run:
# vgcreate <groupname> <partition1> <partition2> ... -s <size>

Active partitions are listed in /dev/<groupname>/ (e.g. /dev/Volume00/)
These are just symlinks to /dev/mapper (e.g. /dev/Volume00/Home -> /dev/mapper/Volume00-Home).

I have, in /dev/Volume00/
FedoraRoot    Home    Swap

`pgscan` said that I have 8.2G free, so I created an 8.2G partition "SMGLRoot":
# lvcreate -L8200 -nSMGLRoot Volume00
I then found that I still had about 192M free, so I removed it and recreated it:
# lvremote /dev/Volume00/SMGLRoot
# lvcreate -L8300 -nSMGLRoot Volume00

When I go to mount filesystems, I get this:
... Unimportant
/dev/sdb2  Size 17816085  Type Linux LVM
/dev/dm-0  Size   Type
/dev/dm-1  Size   Type
/dev/dm-2  Size   Type
/dev/dm-3  Size   Type

The /dev/sdb2 entry should not be listed as that's the LVM "device" and should
not be played with.

# pvs
... List of scanned disks
PV           VG       Fmt   Attr   PSize     PFree
/dev/sdb2  Volume00  lvm1    a-    16.98G    192.00M
This is where I saw I still had 192M free above.

# vgs
... List of devices scanned
VG         #PV  #LV  #SN   Attr   VSize     VFree
Volume00    1    4    0    wz--   16.98G    192.00M
#LV is the number of Logical Volumes in the partition.

# vgdisplay --verbose
Lists all logical volumes. `lvdisplay` also does this.

You can directly mount /dev/Volume00/<partition> just like any other
device.

To find out which /dev/dm* is which LVM device, look for:
Block Device        <number>;<number>
e.g. (with which dm and partition they map to)
Block Device        254:0    <--dm-0   <-- FedoraRoot
Block Device        254:1    <--dm-1   <-- Home
Block Device        254:2    <--dm-2   <-- Swap
Block Device        254:3    <--dm-3   <-- SMGLRoot

When I first tried to format /dev/dm-3 as reiserfs, it failed with:
 stat failed: No such file or directory
That's because /dev/dm* don't exist (I'm not sure how to auto-generate them
yet), so just make symlinks using the above information.

After adding/removing an LVM partition, `vgchange -ay` should be run to make
the changes take effect.

I wanted to see my logical volumes
# lvs
LV              VG           Attr     LSize      Origin   Snap%  Move   Move%
FedoraRoot      Volume00     -wn-a-      4.88G
Home            Volume00     -wn-ao      2.93G
SMGLRoot        Volume00     -wn-a-      8.11G
Swap            Volume00     -wn-a-   1000.00M


The "o" at the end of Attr for Home is because I had Home mounted to copy some files.

I keep getting this error after "Mounting Filesystems":
  swapon: cannot stat /dev//dev/Volume00/Swap: No such file or directory.
It appears that "/dev/" was prepended to all entries as when I go to configure
LILO root= and boot= also have the double "/dev//dev" in them.

To shutdown the LVM system, run:
# vgchange -rn
Much like running `raidstop --all`

Found lvmcreate_initrd on my Fedora box (which says it's from Sistina, the
writers of LVM) as I couldn't find it anywhere in the lvm package, even though
WHATS_NEW refers to it, along with the HOWTO online. I had to modify the script,
though, as /sbin/vgchange and /sbin/vgscan on SMGL systems are just symlinks
to /sbin/lvm, and the script only copied those files as symlinks (no dereferencing,
but that'd just make the initrd bigger) and not the lvm script.

Probably all that needs to be added to the 0.9.2 ISO's initrd is the following
to linuxrc:
/sbin/vgscan /sbin/vgchange -ay