Setting up LVM on Suse Linux

2009/07/24 at 02:34 3 Kommentare

All my computers run on Suse Linux these days, but admittedly, I’m a Windows guy. That is, I believe that installation things should run out-of-the-box, and when they don’t, I get angry. Lately, I got angry when setting up a new laptop computer, and Suse’s Yast came up with ridiculous suggestions about partitioning my hard drive. To cut it short, I had to set up my hard disk manually, something that I am (or rather, was) very much afraid of, because I didn’t want to destroy the working Windows setup that existed on that computer. (It’s a company-owned computer, and in case something goes terribly wrong hardware-wise I’d like to be able to boot into the company-supported Windows installation. Otherwise, I won’t use the Windows installation at all.)

So what Suse Linux 11.1 suggested was to create a home partition of 7 GB, and a root partition of 5 GB. I don’t know about you, but to me, this is just ridiculous. After sizing down the Windows partition to 30 GB, I had 120 GB left on my hard drive. So what’s the point of using 12 GB for Linux? I can’t help to think that there’s a Suse bug that forgets about the trailing zero, so that 120 GB left becomes 12 GB left. Anyway, I talked to some friends on IRC who recommended to partition my drive manually, and since I was feeling brave I did.

Why did I want to use LVM over traditional partitioning, however? Suse Yast’s suggestions for traditional partitioning were reasonable, and I could have easily changed the original suggestion to fit my needs. But I wanted LVM. LVM stands for Logical Volume Management. As Wikipedia says, LVM “is a method of allocating space on mass storage devices that is more flexible than conventional partitioning schemes. In particular, a volume manager can concatenate, stripe together or otherwise combine partitions into larger virtual ones that can be resized or moved, possibly while it is being used.” I don’t (yet) care about all the magic you can do with LVM, I care about the flexibility.

To give an example: With traditional partitioning, and a 150 GB hard drive, you might assign 50 GB to the operating system and applications, and 100 GB to your working data (like documents, images, etc.). Then, at some point, you might find out that you need 70 GB for your OS and applications, but you’re only using 30 GB for your working data, or you’d like to have an extra partition for your web or log files. With traditional partitioning, you’re stuck, because there’s no easy and reliable way to change partition sizes. With LVM, you just assign as much space as you need initially, and then expand that as your needs grow.

You can do all sorts of magic with LVM, like backing up MySQL using file system snapshots, but that’s beyond the scope of this article. This is just about setting up a working LVM environment.

First thing I did in Suse Yast, when it came to preparing the hard drive, was to switch to “LVM partitioning” (which resulted in the ridiculous suggestion mentioned above), then to “expert mode” (creating the hard drive setup, instead of changing Suse’s suggestion).

Partitioning the hard drive

Partitioning the hard drive

I sized down the Windows NTFS partition to 30 GB. Before, I had checked the disk usage under Windows, which reported that about 10 GB out of 150 GB available were currently used. To make sure, I looked at the Windows system settings and ran the defrag tool to analyze the hard disk. As expected on a newly installed Windows system, there was no defragmentation. Better safe than sorry, I ran chkdsk. Then I made sure that Windows had been shut down properly, and booted from the Suse DVD. (It’s a good idea to make sure Windows hasn’t even started booting. I ran into problems when Windows had started booting for like two seconds before killing it with CTRL+ALT+DEL, but that short period was enough to initialize the NTFS file system, which then refused to be sized down by Suse Yast, claiming Windows hadn’t been shut down properly.)

In case you don’t know, Linux calls modern SATA disk drives /dev/sda (older IDE drives are called /dev/hda), where the “a” stands for the first disk. If you have more than one disk, they’d be called /dev/sdb, /dev/sdc, etc.; your DVD drive will probably be /dev/sdc. Partitions are named by appending a number to the disk drive name, for example /dev/sda1 for the first partition on the first hard drive, or /dev/sdb3 for the third partition on the second hard drive.

Once the intial 150 GB Windows partition had been resized by clicking “change size” in Yast and pulling the slider to 30 GB, I added a new partition. I made it a primary partition with 100 MB, which Suse converted to 94.13 MB. Suse was smart enough to assume that this would be my boot partition, and thus suggested that it should be mounted on /boot. I had to type in “100 MB”, because otherwise Suse would have assumed that I mean GB. 100 MB is enough for all the stuff under /boot, because it will never host data, but just meta-information.

screenshot.yast.lvm-2

Creating the LVM volumes

So this leaves all the rest for LVM. LVM is where your data will live, no matter what those data are. It could be the operating system, the web server, the database server, the applications you’re using, the documents you’re working with, your photos and videos, and so forth. What I did was assign the rest of the hard drive to dev/sda3, Linux LVM.

Basically, there are three “areas” that you need:

  1. A swap partition.
  2. A root partition.
  3. A home partition.

In LVM, all those partitions are “logical volumes”. I created a “master volume”, calling it “system”, and assigning it to use all the space left on the /dev/sda3 drive.

Under that volume, I created three logical volumes, labeled:

  1. home: 30 GB (file system: ext3, mounted on /home)
  2. root: 20 GB (file system: ext3, mounted on /)
  3. swap: 10 GB (“file sytem”: swap, mounted on “swap”)
Resizing LVM volumes

Resizing LVM volumes

When copying over data from another computer, I found that /home should be bigger, 50 GB. You can do this by running Yast > System > Partitioning. If you get an error saying the partition/volume you’re trying to resize is already mounted, exit the window manager you’re running (e.g. KDE), then issue “init 1″ on the command line. If the partition/volume you’re about to resize is still mounted (check with “mount” on the command line), unmount it (e.g. “umount /dev/system/home”). Then you should be able to change the size by running Yast in text GUI mode (the same Yast interface, just less colorful, and you’ll have to use the keyboard instead of the mouse). When done, issue “init 5″ to return to KDE or whatever window manager you’re using.

By the way: Why do I want a swap file that’s significantly bigger than my physical memory (in case of my new laptop, 3 GB RAM)? It’s because I’ve been hit by Linux not being able to suspend to disk because of insufficient disk space in the swap partition. I’d assume that if you have 3 GB RAM then 3 GB disk space should be sufficient to store everything in RAM to disk when suspending to disk, but I’ve seen operations fail because of that assumption, and because disk space is cheap I prefer to be on the safe side. Maybe the extra disk space is needed because Linux can’t clean up and reclaim the disk space quickly enough when it suspends a box to disk.

Epilogue:  As you can see, I took some screen shots with my camera, wrongfully assuming that you can’t take screen shots from installation screens. (As said above, I’m originally a Windows guy.) But you can. As Lenz pointed out, there’s a way for Yast to take screen shots, although most people don’t know it. Well, at least I will know, next time. :-)

About these ads

Entry filed under: Computer, English, Linux, Open Source. Tags: .

Firefox Extensiomania Darslicing

3 Kommentare

  • 1. Setting up LVM on Suse Linux - Technology  |  2009/07/26 um 10:00

    […] I wrote a little article about this which you can find here, in an effort to save others some time. The article is about setting up LVM with Suse Yast, but you […]

  • 2. vigneras  |  2009/07/29 um 21:13

    I just wrote an article about how to “smartly” choose a filesystem layout under linux (using LVM). In my point of view, the problem is not about choosing LVM or not, or about the sizing of the partition (if you use LVM, you are quite free to change the sizing afterwards). It is more about analyzing your needs precisely (even if in the case of laptop with a single hard drive, it seems obvious) and to decide according to that.

    The article may sound useful, it is available at:

    http://www.vigneras.org/pierre/wp/2009/07/21/choosing-the-right-file-system-layout-under-linux/

    • 3. sejh  |  2009/07/30 um 00:55

      Kudos, great article! I’ve learned a lot about file systems and the separation of user needs from the implementation of same. Now I finally know why I’m using RAID5, rather than RAID10, on my 3 TB NAS drive. :-)


Juli 2009
M D M D F S S
« Jun   Aug »
 12345
6789101112
13141516171819
20212223242526
2728293031  

Aktuelle Beiträge

Enter your email address to follow this blog and receive notifications of new posts by email.

Schließe dich 297 Followern an


Folgen

Erhalte jeden neuen Beitrag in deinen Posteingang.

Schließe dich 297 Followern an

%d Bloggern gefällt das: