Business Internet and Telephony, since 1985

Easy LVM - Installing Linux Entirely on LVM Partitions

Printer-friendly versionPrinter-friendly versionSend by emailSend by email Share this

In this article we examine just how simple and quick it can be to install Linux entirely within logical volumes using LVM.

This includes swap and boot partitions, the latter of which will be required since everything else, including your root and home partitions we will be formatted with the high performance XFS filesystem.

The entire process shouldn't take more than 5 minutes using this cookbook, dedicating about two minutes of that time prior to the OS install and about three minutes of post install configuration prior to rebooting a live Linux system...

The value and benefits of using LVM to manage your partitions will be left for the reader to discover. It is assumed that you wouldn't be reading this unless you already understand that snapshots, extending and moving partitions and implementing RAID using LVM itself are greatly simplified and really handy aspects of wanting doing this in the first place.

Or maybe just because you know that LVM is kewl :)

For the purposes of this tutorial we will be using a 300 GigaByte Hard Drive, and we're going to slice it up according to the following specifications. Adjust your command lines as necessary as required:

A 300 GigaByte Hard Drive (/dev/sda)

Four partitions, consisting of a 1GByte boot partition (/boot), a 4GByte SWAP partition, a 40GByte root partition (/root), and the rest will be allocated to our home partition (/home).

We're going to call this machine 'boner'. The significance of knowing the hostname of this machine is strictly administrative in nature, but one of the reasons you're incorporating Logical Volume Management in the first place is to simplify administration of your storage management, so the hostname of this machine figures into our naming conventions where our Volume Groups are concerned - especially if we're going to be moving and managing several machines later.

Again, adjust as necessary and consult the man pages for the various commands if you're not sure how to tweak for your particular needs.

Let's get started!

1.) Boot from the Slackware64 -current DVD and login as root.

2.) Run fdisk

# fdisk /dev/sda

Create one big primary partition consisting of your entire drive. You do this basically by typing 'n' for a new partition, then 'p' to specify that you want a primary partition, and hitting return a couple of time to answer the questions asking you for the starting and ending points of the partition.

Type 'a' to toggle the bootable flag on partition 1

Type 't' to change the partition type on partition 1 to that of '8e' (Linux LVM).

Now enter 'w' to write out the partition table you've just specified and exit fdisk.

That was easy wasn't it?

2.) Now let's create the volumes

# pvcreate /dev/sda1
# vgcreate bonervg /dev/sda1
# lvcreate -L 1G -n boot bonervg
# lvcreate -L 4G -n swap bonervg
# lvcreate -L 40G -n root bonervg
# lvcreate -l 100%FREE -n home bonervg
# mkswap /dev/bonervg/swap
# setup

Go ahead and install your operating system as you normally would. When you add your swap partition you'll note that is is automagically detected (Nice!).

Format your partitions and choose their mount points according to the following schema:

	/dev/bonervg/root	/		xfs
	/dev/bonervg/boot	/boot	        ext3
	/dev/bonervg/swap	swap	        swap
	/dev/bonervg/home	/home	xfs

When asked where you want lilo installed choose to install lilo on the MBR.

After exiting setup, DO NOT REBOOT!!! We still have to take out three more minutes to create an initrd to boot from our LVM aware kernel, edit lilo.conf to tell it to use the initrd, and run lilo.

We perform these next and final steps in a chroot'd environment.

Do the following:

# chroot /mnt

This next command is a little tricky, in that you have a couple of choices to make. First, let's do a dry run to see why.

# /usr/share/mkinitrd/mkinitrd_command_generator.sh -r

This will generate an mkinitrd command line automagically for you, that 'should' be along the lines of what you want. the modules that are needed to boot will be included, with possibly one exception that I like to include, which is the 'ext3' module.

At the time of this writing, the generic kernel included with Slackware64 -current is 2.6.38.7, and the mkinitrd_command_generator.sh script will generate a command line for you that is applicable to whatever kernel version you need to point to at the time you perform an install of Slackware64 -current.

So with consideration to the above, if you don't want to include the 'ext3' module in your initial ramdisk, simply run the following:

# $( /usr/share/mkinitrd/mkinitrd_command_generator.sh -r )

Which will run the correct command and generate your initial ramdisk.

Otherwise, you can manually type in the command yourself including the 'ext3' module, which will resemble something similar to the following (note that the modules are listed with a colon as the delimiter):

# mkinitrd -c -k 2.6.38.7 -f xfs -r /dev/bonervg/root -m mptbase:mptscsih:mptspi:exportfs:xfs:ext3 -L -u -o /boot/initrd.gz

The only difference between what the script generated and what I used was the addition of the "ext3 module, which is safer IMO, considering /boot is on an Extended 3 filesystem ;)

Now let's edit /etc/lilo.conf and make change the "Linux bootable partition config" from:

image = /boot/vmlinuz
	root = /dev/bonervg/root
	label = Linux
	read-only

To:

image = /boot/vmlinuz-generic-2.6.38.7
	initrd = /boot/initrd.gz
	root = /dev/bonervg/root
	label = Linux
	read-only

Remembering that the kernel image on the 'image=' line should reflect a valid kernel image (What running 'mkinitrd_command_generator.sh' told you it would be). Notice that we've added an 'initrd =' line to this section!

On the very first line of lilo.conf, I recommend you place a single directive in form of the word, "compact" (without quotes). This will greatly enhance your boot time.

Save your /etc/lilo.conf and finally:

# lilo
# exit
# reboot

The command 'lilo', wrote out the the new config from /etc/lilo.conf to your MBR, and you exited out of the chroot environment with the 'exit' command (Note: Your prompt won't look any different, but an 'ls' between the two environments will definitely show you the difference between the two).

The 'reboot' command... well let's hope that was self-evident enough, based upon the events that occurred after you entered it. Now let's sit back and wait for a couple of minutes...

Once your newly installed GNU/Linux operating system has booted for the first time, log in and take a look at your filesystem table, and you'll understand why we used 'bonervg' for our volume group label:

# cat /etc/fstab:

/dev/bonervg/swap   swap        swap     defaults                0   0
/dev/bonervg/root   /           xfs      defaults                1   1
/dev/bonervg/boot   /boot       ext3     defaults                1   2
/dev/bonervg/home   /home       xfs      defaults                1   2
#/dev/cdrom         /mnt/cdrom  auto     noauto,owner,ro         0   0
/dev/fd0            /mnt/floppy auto     noauto,owner            0   0
devpts              /dev/pts    devpts   gid=5,mode=620          0   0
proc                /proc       proc     defaults                0   0
tmpfs               /dev/shm    tmpfs    defaults                0   0

It should become even more apparent once you start moving around and using LVM when you have several machines - it's just a convention that I personally use to keep things straight so I'm sure I'm working on the correct machine's volumes. This becomes even more significant when you're using a SAN and virtual machines in a clustered environment, incorporate shared volumes such as /usr/local or /home, or incorporate things like NIS or LDAP into your enterprise (if you do that sort of thing).

We could just as easily have used 'vg' or 'disk' instead of 'bonervg', but using a convention similar to the one we used in this tutorial should help make sure that you don't confuse one machine's logical volumes for another. LVM is kewl because you can just move stuff around at will, take snapshots, resize and create virtual disks that span volumes in RAID environment, etc.

Unlike many other Linux distributions, Slackware is more adeptly suited for use as a server in an enterprise environment that most others. Especially when you consider the extraordinary stability and speed you now have at your fingertips.

We work with a lot of different Linux distributions here at NorthTech, From CentOS to Debian and their (usually lesser) cousins to source based distros such as Gentoo and Sorcerer, but for sheer performance and stability, plus the ability to remain able to take advantage of the latest software as it emerges, there is no other binary package based distribution that even comes close to comparing with Slackware.

For additional software that you install on your system, you're actually going to download and compile it from source anyway (with SlackBuild scripts that create binary packages for you), so you have a sweet blend of a binary and source based distro which will remain current, relevant, and in service as the version numbers of the operating system climb over the years.

I've endeavored to create a mini-HowTo in cookbook fashion, that you can just cut/paste and leave out all of the explanatory fluff once you give it an initial read. Doing that will literally yield a procedural document that actually does only take two minutes before running setup, and three minutes following that process.

We hope that this article has been a relevant and useful tutorial for your particular needs, and feel free to comment back if you have any questions, or anything to add.

Enjoy :)