Page 1 of 3 123 LastLast
Results 1 to 10 of 25

Thread: How To LVM in Mythbuntu

  1. #1
    Join Date
    Oct 2007
    Location
    Sioux Falls, SD
    Beans
    25
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Talking How To LVM in Mythbuntu

    Hello, Here is my first contribution to the cause! I am not sure if this is the best spot for this type of a thing, but at least it may help someone!

    After installing Mythubuntu RC I manually configured lvm.

    What is lvm?

    It lets you span partitions into on large volume so that one can add more space later on.

    In the below example we have two disks sda sdb and we want to create a lvm partition on sdb and include sda3 in that lvm so that the /var/lib directory is mounted on lvm partition. This means that /var/lib will span sdb1 and sda3. When I installed Mythbuntu I manually created the partitions and sda1 mounts / (root) and sda2 is swap with sda3 as the /var/lib partition. This was similar to the way Feisty installs were done in the old days. It is also important that the sdb partition be large enough to hold all of /var/lib
    df -h will display the used space in mounted partitions. In my case I deleted all the recordings so that I could fit it on sdb only around 20 GB in my case.
    Code:
    df -h
    Steps:
    All connections to myth box should use sudo after terminal is open:
    Code:
    sudo -i

    1. Open a terminal window or SSH into myth box.
    2. Get LVM2 from apt-get
      Code:
      apt-get install lvm2
    3. Reboot Note: I had to anyway because it messed with the kernel or boot or something
      Code:
      shutdown -r now
    4. setup an lvm partition. Note: this example assumes that the sdb disk is empty!
      Remember that fdisk can really mess up your existing partitions so know what you are doing before you start doing this stuff! You have been warned!!!!
      Code:
      fdisk /dev/sdb
    5. At Command (m for help): type n
    6. At Command action
      e extended
      p primary partition (1-4) type p
    7. At Partition number (1-4): type 1
    8. At First cylinder (1-19457, default 1): (press Enter for default)
    9. At Last cylinder or +size or +sizeM or +sizeK (1-19457, default 19457): (Press Enter for default)
    10. At Command (m for help): type t
    11. At Hex code (type L to list codes): type 8e
    12. At Command (m for help): type w
    13. Create the physical volume.
      Code:
      pvcreate /dev/sdb1

    Great we have a physical lvm partition sdb1 created!

    1. Now we have to create the lvm stuff for the volume.
      Note: Example below is for about 500 GB use the power of two to go to larger table sizes. use 16M for example is for over 1 TB volumes
      Code:
      vgcreate -s 8M vg /dev/sdb1
    2. Get the vg lvm volume size
      Code:
      vgdisplay vg | grep "Total PE"
      Display shows on my pc:
      Total PE 9543
      Use that value in cmd below replace 9543 with your value.

      Code:
      lvcreate -l 9543 vg -n lib
    3. This starts the device mapper on startup. Not sure if this is needed or not, but will not hurt anything.
      Code:
      modprobe dm-mod 
      echo dm-mod >> /etc/modules
    4. format the partition as xfs Note: LVM partitions created as XFS are difficult to size down, so note that it may not be possible to make smaller very easy, at least that is what I heard on the net. Anyway why would you want to remove space from your lvm. I can only see it getting bigger so that I can store more stuff on it.
      Code:
      mkfs.xfs -f /dev/vg/lib
    5. Make a mount point and mount.
      Code:
      mkdir /mnt/sdb1
      mount /dev/vg/lib /mnt/sdb1
      Note: It may be wise to stop myth back-end and mysql at this point, but I did not but do not do this step or following steps why recording anything.
    6. copy all from /var/lib into mounted sdb1.
      Code:
      cp -p -r /var/lib/* /mnt/sdb1
    7. Make a copy of fstab
      Code:
      cp /etc/fstab /etc/fstab.backup
    8. Fix fstab to mount lvm vg-lib as /var/lib
      Code:
      nano /etc/fstab
    9. Comment out your current /var/lib in fstab
      line looks like #UUID=3aa29488-1c13-4042-a246-3f317aa7ddf7 /var/lib xfs defaults in my fstab
    10. Add the new mount-point for xfs lvm partition in fstab file. Iplaced it at the bottom of the file.
      Code:
      /dev/mapper/vg-lib /var/lib xfs defaults 0 1
      save the fstab file.

      Here is my fstab when done.
      # /etc/fstab: static file system information.
      #
      # <file system> <mount point> <type> <options> <dump> <pass>
      proc /proc proc defaults 0 0
      # /dev/sda1
      UUID=682462da-1414-48a7-8614-21c45ba68529 / ext3 defaults,erro$
      # /dev/sdb1
      # UUID=d790b268-b2af-4380-92f4-e1a8192fbd65 /var/lib xfs defaults $
      # /dev/sda2
      UUID=f9e95dd5-155e-4100-b34c-0725ccfc92d9 none swap sw $
      /dev/scd0 /media/cdrom0 udf,iso9660 user,noauto,exec 0 0
      /dev/scd1 /media/cdrom1 udf,iso9660 user,noauto,exec 0 0

      # mount lvm vg-lib as /var/lib
      /dev/mapper/vg-lib /var/lib xfs defaults 0 1
    11. reboot the system and confirm var/lib is there. If it is not then set the fstab back so
      that you can recopy it to /mnt/sdb1
      Code:
      ls /var/lib
      Almost done!
      Now add the space taken up by sda3 to the volume group.
    12. fix sda3 with fdisk.
      Code:
      fdisk /dev/sda
    13. At Command (m for help): type d
    14. At Partition number (1-4): type 3
    15. At Command (m for help): type n
    16. At Command action
      e extended
      p primary partition (1-4): type p
    17. At Partition number (1-4): type 3
    18. At First cylinder (1-19457, default 1): (press Enter for default)
    19. At Last cylinder or +size or +sizeM or +sizeK (1-19457, default 19457): (Press Enter for default)
    20. At Command (m for help): type t
    21. At Partition number (1-4): type 3
    22. At Hex code (type L to list codes): type 8e
      Changed system type of partition 3 to 8e (Linux LVM)
    23. At Command (m for help):type w
    24. Finish creating the partition
      Code:
      pvcreate /dev/sda3
    25. Extend the vg lvm partition
      Code:
      vgextend vg /dev/sda3
      vgdisplay
      note the line:
      Free PE / Size 2925 / 11.43 GB
    26. extend the vg lvm by the amount indicated above in my case 2925 so that is the +2925 below it is important to use your value not mine.
      Code:
      lvextend -l+2925 /dev/vg/lib
    27. extend xfs
      Code:
      xfs_growfs /var/lib
    28. confirm sizes
      Code:
      df -h
    29. reboot
      Code:
      shutdown -r now
    Last edited by apauna; October 21st, 2007 at 07:49 AM. Reason: forgot to mention sudo -i and fstab

  2. #2
    Join Date
    Oct 2005
    Location
    Austin, TX
    Beans
    2,983
    Distro
    Ubuntu Development Release

    Re: How To LVM in Mythbuntu

    Awesome tutorial. I'm going to sticky this, and we'll see if we can sneak it into our install manual.

  3. #3
    Join Date
    Oct 2007
    Beans
    12

    Re: How To LVM in Mythbuntu

    Nice guide, I don't suppose you know how to recover from a drive failing in the volume, or adding new drives to the volume do you?

  4. #4
    Join Date
    Oct 2007
    Beans
    12

    Re: How To LVM in Mythbuntu

    stupid me, you already show how to add a drive to a LVM volume.

  5. #5
    Join Date
    Oct 2007
    Location
    Sioux Falls, SD
    Beans
    25
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: How To LVM in Mythbuntu

    Quote Originally Posted by davemorris View Post
    stupid me, you already show how to add a drive to a LVM volume.
    Failing drive in the lvm is something I have not spent any time on as of yet.

    Try http://codeworks.gnomedia.com/archiv.../lvm_recovery/

    I will do some more research on this, but I think it really depends on how the data spans across the partitions in the LVM. In the above all that is affected is /var/lib, so the system remains semi bootable

  6. #6
    Join Date
    Nov 2006
    Beans
    67

    Re: How To LVM in Mythbuntu

    thnx

  7. #7
    Join Date
    Sep 2007
    Location
    Las Vegas, Nevada
    Beans
    243
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: How To LVM in Mythbuntu

    Could you elaborate on this part?

    Now we have to create the lvm stuff for the volume.
    Note: Example below is for about 500 GB use the power of two to go to larger table sizes. use 16M for example is for over 1 TB volumes
    I have two 320 GB hard drives that I want to setup as an LVM. When I installed mythbuntu I setup my partitions as you had described on my first drive. I used 10 GB for / and 2048 for Swap and the rest for /var/lib. So for my 600 something GB LVM partition would I use 8M like you did? Should I use the same command here?
    Code:
    vgcreate -s 8M vg /dev/sdb1
    Also for the following step it says to format as XFS. I had formatted /var/lib with JFS. Will this be a problem?

    format the partition as xfs Note: LVM partitions created as XFS are difficult to size down, so note that it may not be possible to make smaller very easy, at least that is what I heard on the net. Anyway why would you want to remove space from your lvm. I can only see it getting bigger so that I can store more stuff on it.
    And finally my last question. I know this one is a really obvious newb question but how do I stop the backend and mysql?

    Note: It may be wise to stop myth back-end and mysql at this point, but I did not but do not do this step or following steps why recording anything.
    Jonathan Brown
    The best part of waking up is not Folgers in your cup...it's knowing that Chuck Norris didn't kill you in your sleep.

  8. #8
    Join Date
    Oct 2007
    Location
    Sioux Falls, SD
    Beans
    25
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: How To LVM in Mythbuntu

    Hello Meph1st0,

    I have two 320 GB hard drives that I want to setup as an LVM. When I installed mythbuntu I setup my partitions as you had described on my first drive. I used 10 GB for / and 2048 for Swap and the rest for /var/lib. So for my 600 something GB LVM partition would I use 8M like you did? Should I use the same command here?
    In your case I would use.
    Code:
    vgcreate -s 16M vg /dev/sdb1
    This would let you add more partitions later and not have to worry much about what you started vgcreate with. It is possible to fix this later, but less messing around is always better.

    Also for the following step it says to format as XFS. I had formatted /var/lib with JFS. Will this be a problem?
    I assume you are referring to your original /var/lib partition and not the one that will be mounted as /var/lib when you complete this process. As long as that is true you will be fine all that is going to happen is data on that /var/lib will be copied from /var/lib onto starting lvm partition and the format of the partition does not have any affect on the data that it contains. /var/lib will be absorbed into the lvm later in the process. see second step 12
    fix sda3 with fdisk.
    In my case this was the original var lib and was re-partitioned below that step and added to the lvm.

    lvm partition can be may types ext3 was the first one I used, but for performance I chose xfs type.

    here is some more info on lvm and xfs
    http://wiki.randompage.org/index.php/DistOS:Linux:LVM

  9. #9
    Join Date
    Sep 2007
    Location
    Las Vegas, Nevada
    Beans
    243
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: How To LVM in Mythbuntu

    I ran into a problem. After I tried mounting the LVM volume to /mnt/sdb1 (second step number 5) I got an error message on the desktop (not in the xterm).

    Saying it couldn't mount due to an NTFS volume named "replacement".

    I installed Gparted through the synaptec installer to look at the volume. The device named /dev/mapper/vg-lib has the following error message.

    xfs_db: /dev/mapper/vg-lib contains a mounted filesystem.

    fatal error -- couldn't initialize XFS library

    /sdb used to be used as an NTFS formatted drive for windows. During the Mythbuntu install, I had deleted the partition but didn't create any. It looks like it's still able to see my ntfs partition.

    Can I just undo everything I've done (remove my Physical Volume, Volume Group and Logical Volume) and start over? Or is there an easy fix to this?
    Jonathan Brown
    The best part of waking up is not Folgers in your cup...it's knowing that Chuck Norris didn't kill you in your sleep.

  10. #10
    Join Date
    Sep 2007
    Location
    Las Vegas, Nevada
    Beans
    243
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: How To LVM in Mythbuntu

    Nevermind, I think I was able to get through this. My df -h shows:

    <code>Filesystem Size Used Avail Use% Mounted on
    /dev/sda1 9.2G 1.5G 7.3G 17% /
    varrun 506M 216K 506M 1% /var/run
    varlock 506M 0 506M 0% /var/lock
    udev 506M 104K 506M 1% /dev
    devshm 506M 0 506M 0% /dev/shm
    lrm 506M 34M 472M 7% /lib/modules/2.6.22-14-generic/volatile
    /dev/mapper/vg-lib 585G 81G 504G 14% /var/lib</code>

    and /var/lib is there with all the files as far as I can tell.

    except now I can't connect to the mythconverg databse. Please refer to the following post: http://ubuntuforums.org/showthread.php?t=591891

    I don't want to dirty up this thread any more than I already have.
    Jonathan Brown
    The best part of waking up is not Folgers in your cup...it's knowing that Chuck Norris didn't kill you in your sleep.

Page 1 of 3 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •