1. Introduction
This guide is based on an example with two IDE hard disks. It means that you will more than likely need to change the drive, partition names and partition sizes to match your own setup and needs.
Warning: This document is not intended to be an LVM2 tutorial. It serves as a supplement to the Gentoo installation procedure as described in the Handbook, Part 1. Make sure you read the Gentoo Installation Manual before you start your installation process. |
Note: For a complete LVM HOWTO point your browser to http://tldp.org/HOWTO/LVM-HOWTO |
If you do a fresh install of Gentoo, you will need to use a bootable CD with LVM2 support such as a Gentoo Installation CD. You can find the Installation CDs for an x86 architecture on our mirrors under /releases/x86/current/installcd. Other architectures might be supported as well.
If you install LVM2 on a currently running system with some spare hard disk space, you will need to enable the LVM2 module (dm-mod). This module is available in gentoo-sources. Compiling your kernel and getting LVM2 to work is covered later in this guide.
Not all 2.4 kernels provided by Gentoo support LVM2!
Our example system has two IDE hard disks and will be partitioned as follows:
- /dev/hda1 -- /boot
- /dev/hda2 -- (swap)
- /dev/hda3 -- /
- /dev/hda4 -- Will be used by LVM2
- /dev/hdb1 -- Will be used by LVM2
Important: Pay attention to the partition names as it is easy to confuse the a's and b's, and the partition numbers. One false move could wipe out the wrong partition. You have been warned!
OK, time to start...
Follow the handbook, but with the following amendments to chapter 4. Preparing the Disks:
Use fdisk as described in the handbook, but use the partition scheme mentioned above as an example. It is only an example, adapt it to your own needs.
Create a small physical /boot partition (hda1). In this example, /boot will be not managed by LVM2. This partition will contain your bootloader and your kernel(s). A 64MB partition should be well enough for quite a few kernel generations.
Create a swap partition (hda2).
Create a / (root) partition (hda3). If you are interested in trying to put your root partition under LVM management (which we do not recommend), see the resources section at the end of this guide for a link to a mini-howto on how to do this. The size of the root partition need not be large if you will keep /opt /usr /home /var and /tmp in an LVM2 Volume Group (vg). In this case, 1GB should be sufficient.
Note: It is not recommended to put the following directories in an LVM2 partition: /etc, /lib, /mnt, /proc, /sbin, /dev, and /root. This way, you would still be able to log into your system (crippled, but still somewhat usable, as root) if something goes terribly wrong. |
Assuming the /boot, swap and root partitions do not use the whole physical disk, create a fourth partition on this disk and set it to type 8e (Linux LVM). If you have more physical drives you would like to use with LVM, create one partition on each and give them the same type (8e).
Note: Considering the huge size of current disks, you might consider splitting your hard disks into smaller partitions instead of creating a big partition that will be added to an LVM2 volume group in one block. LVM2 makes it easy to extend your volumes after all. This leaves you some unallocated partitions you might need to use outside of an LVM2 group. In short, don't use your disk space until you know you need it. As an example, one contributor had split his 160 Gb hard disk into 8 partitions of 20 Gb each. |
Create the filesystems on /dev/hda1 and /dev/hda3, and create and activate the swap on /dev/hda2 as described in the handbook.
Load the LVM2 dm-mod module.
Code Listing 2.1: Loading the LVM2 module |
# modprobe dm-mod |
Before scanning and activating LVM, you might want to edit /etc/lvm/lvm.conf to exclude some devices. By default, LVM2 will scan all devices, even your CDROM which can generate error messages. In the following example, the line that allows scanning of all devices is replaced by one that rejects every device but our two IDE disks.
Code Listing 2.2: Activating LVM |
(Avoid scanning all devices but our disks) |
Prepare the partitions.
Code Listing 2.3: Preparing the partitions |
# pvcreate /dev/hda4 /dev/hdb1 |
Setup a volume group. A volume group is the result of combining several physical units into a single logical device.
In our example, /dev/hda1, /dev/hda2 and /dev/hda3 are the /boot, swap and root partitions so we need to combine /dev/hda4 and /dev/hdb1. It can be done with a single command, but, as an example, we will create our volume group and extend it.
Code Listing 2.4: Creating and extending a volume group |
(Create a volume group named vg) again and later as well) Volume group "vg" successfully extended |
Create the logical volumes. Logical volumes are the equivalent of partitions you would create using fdisk in a non LVM2 environment. In our example, we create the following partitions:
Directory | Size |
/usr | 10 GB |
/home | 5 GB |
/opt | 5 GB |
/var | 10 GB |
/tmp | 2 GB |
Since we are going to use LVM2, we should not worry too much about partition sizes because they can always be expanded as needed.
Note: As Terje Kvernes commented, it is easier to increase the size of a partition then to shrink it. You might therefore want to start with smaller partitions and increase their size as needed. |
Code Listing 2.5: Creating and extending logical volumes |
# lvcreate -L10G -nusr vg |
Create filesystems on the logical volumes the same way you would on a regular partition. We use ext3 on the logical volumes but any filesystem of your choice will work:
Code Listing 2.6: Creating the filesystems |
# mke2fs -j /dev/vg/usr |
Mount your partitions as described in the handbook and mount your LVM2 logical volumes as if they were partitions. Replace the usual /dev/hdxx with /dev/vg/logical_volumename.
Code Listing 2.7: Mounting your logical volumes |
(Make sure you have mounted your root partition as described in the handbook first) |
Note: The rest of the installation handbook is mostly unchanged so we shall not walk you through it again except to point out differences. |
When configuring your kernel, make sure to configure your kernel to support LVM2 (not all 2.4 kernels do). Select the LVM2 module as follows:
Code Listing 2.8: Selecting the LVM2 module in a 2.4.x kernel |
Multi-device support (RAID and LVM) ---> |
Code Listing 2.9: Selecting the LVM2 module in a 2.6.x kernel |
Device Drivers ---> |
The compiled module is called dm-mod.ko
After you have built your kernel and installed its modules, add the following line to your /etc/modules.autoload.d/kernel-{KV} where {KV} represents your kernel version (2.4 or 2.6) so that the LVM2 module gets loaded when your machine is booted:
Code Listing 2.10: Adding the LVM2 module into /etc/modules.autoload.d/kernel-2.6 |
# nano -w /etc/modules.autoload.d/kernel-2.6 |
Now, install the lvm2 package.
Important: Make sure your /usr/src/linux link points to the kernel sources you are using because the lvm2 ebuild depends on the device-mapper ebuild which will check the presence of a required source file under /usr/src/linux/include/linux. |
Code Listing 2.11: Emerging the LVM2 package |
# emerge lvm2 |
Edit /etc/lvm/lvm.conf as described earlier. The file you previously edited is part of your installation environment and will disappear after the next reboot. This time, you edit the real one inside your new Gentoo install.
When editing your /etc/fstab file, follow the handbook and add your LVM2 logical volumes as needed. Again, here are a few lines needed for our example:
Code Listing 2.12: Extract of /etc/fstab |
/dev/hda1 /boot ext3 noauto,noatime 1 2 |
When you reach the end of the installation part of the handbook, don't forget to umount all your LVM2 logical volumes as well and for a good measure run the following command before you reboot:
Code Listing 2.13: Shutting down LVM2 |
# vgchange -a n |
Restart your machine and all partitions should be visible and mounted.
If you have interrupted the Gentoo installation at one point and want to continue, you need to create the volume device nodes first:
Code Listing 3.1: Reactivating the volumes |
# vgscan --mknodes |
Installation CDs with less recent tools might need to reactivate the volumes instead:
Code Listing 3.2: Reactivating the volumes |
(Deactivate all volumes first) |
- The official LVM2 home page
- The LVM Howto
- Daniel Robbins's articles on LVM for IBM's DeveloperWorks: Part 1 and Part 2
- How to boot your root FS off of LVM1: http://www.the-infinite.org/archive/docs/lvm/howto-boot-off-root-lv.txt
Thanks Thilo Bangert and Terje Kvernes for their help and comments on this document.
GET UBUNTU
To get Ubuntu, click on the following link:
http://www.ubuntu.com/getubuntu/download
For this installation I recommend you simply choose the Desktop Edition of Ubuntu.
Start now by selecting the closest location to you in the dropdown.
Scroll down and ensure 32bit version is selected.
Select Begin Download.
Once finished, locate the downloaded file; it will be named something similar to
ubuntu-9.04-desktop-i386.iso
To create a bootable disk from the .iso, you may wish to use the useful tool named Burn. Go to the following link to get this tool, or simply choose a burner of your preference:
http://burn-osx.sourceforge.net/Pages/English/home.html
No, you do NOT have to use this tool, but it has several advantages and I include it in the process simply as an example of the ISO burning process. The nice thing about Burn is that you simply download, install, and open. PLUS, often the biggest issue with an install is an improperly burned ISO, and this tool helped me get quick and correct burns each time.
In Burn, go to the copy tab as shown below:
Now just Drag the .iso file you downloaded to where it says, "Drop discs and images here."
Insert a blank cd.
Select Burn.
Ensure Maximum possible is selected.
Select Burn.
Once complete, this is the Ubuntu Linux boot disk you will need for the next steps.
DOWNLOAD VIRTUALBOX
Virtual box is a fantastic and enterprise capable virtualizer for Mac hardware. For those not familiar with virtualizers, this tool allows you to install Ubuntu in a shared manner with another Operating System such as MacOS or Windows.
You may wish to find out more about this SUN Microsystem's tool, as it is very useful for many virtualizing scenerios. Best of all, it is one of the only virtualization tools that is also Open Source Software.
To get VirtualBox simply go to this link:
http://www.virtualbox.org/wiki/Downloads
Under VirtualBox Binaries, where it says VirtualBox 3.0.0 for OS X hosts, select "Intel Macs"
Open the VirtualBox disk image and run the installer
ADVANCED TIP: If you're a more advanced user, it's important to let you know that rather than burning the ISO to CDROM, then using the CD to install into Virtualbox, the CDROM drive in virtual box can be configured to point at the ISO file, eliminating the need to burn a disk.
START THE INSTALLATION
When you're ready, open VirtualBox from the Applications folder on your Mac.
Begin the following series of steps:
Register (optional)
Select the "New" icon in the toolbar.
A new window will open.
Select Next.
Enter a Name for the virtual machine e.g. Ubuntu Linux.
Change Operating System to Linux.
Change Version to Ubuntu.
Obviously you can apply this method to other Linux flavours if you wish.
Select Next.
Select amount of RAM to be used on the virtual machine.
(384 recommended, I recommend 512 if you have 1GB RAM on your Mac).
Select Next.
Ensure Boot Hard Disk (Primary Master) is selected.
Select "Create new hard disk."
Now you need to again Select Next and once more Select Next.
Choose "Dynamically expanding storage" ("Fixed-size storage" creates a fixed hard drive for Ubuntu, but "Dynamically expanding storage" only uses as much hard drive space as it needs to install and will thereafter expand as needed).
Select Next.
The Name you chose for the Virtual Machine earlier should now show under Location; if not then enter the same name as before under Location e.g. Ubuntu Linux, and select the amount of maximum space that the hard drive can use.
TIP: This will automatically be something like 8 GB but you can change it depending on your requirements. Or just leave it as it is and move on.
Select Next.
Now Select Finish.
Finally Select Finish once more.
You should now see something similar to this:
When you're ready, please press the "Start" icon at the top.
Now start this process:
Select OK.
Select Next.
Ensure CD/DVD-ROM Device and Host Drive are selected (should be the default).
Select Next.
Insert previously created Ubuntu Linux bootable disk.
Select Finish.
At this point the disk will start booting.
Select English or your preferred language.
If a screen appears regarding the mouse or keyboard, take note of the host key; something like the Left Command key (also shown at the bottom right of the VirtualBox window). This is important so please don't forget what it indicates.
Now select the checkbox "Don't show this message again" and select Capture (This will make the mouse change automatically when you select the virtual system.)
Select Install Ubuntu.
At this point you should get the following loading screen, which is Ubuntu starting:
INITIAL UBUNTU SETUP
Once finished loading (this may take a few minutes), ensure your language is selected once again on the left panel and select Forward.
Select your Time Zone on the map or by your region and city.
Select Forward.
Choose keyboard layout depending on the type of keyboard you have (to test, simply type digits into the typing box, ensuring that it enters the correct digits as on your keyboard).
Select Forward.
Choose "Use the entire disk."
Select Forward.
Fill in your name, account username, password (minimum eight digits recommended), and computer name for network visibility.
Choose whether to log in automatically or require a password to log in.
(I recommend that you do require a password, just take note of what you choose).
Select Forward.
Now, please Select Install.
It should show the following installing system box with a status on the installation.
Be patient, as this is nearly the final step, but unfortunately takes time. It can take anywhere from 10 minutes to an hour to install, depending on your system. Look at it this way, now is a perfect time to grab a tasty snack, sit back and enjoy an episode of your favourite TV show.
You can check on the status of the installation, as shown below:
When completed, please Select Restart Now (you should not restart the Mac itself, the VirtualBox will merely restart Ubuntu for you within the program).
It will say on the Ubuntu restart "Please remove the disc, close the tray (if any) and press ENTER to continue"; when this happens, the eject button in OS X will not work therefore in the VirtualBox window, select Devices (on the top toolbar in OS X).
Select Unmount CD/DVD-ROM and press ENTER.
Now you will be able to eject the disk from the computer.
Enter your Username and Password (the one you should have noted earlier!).
TIP: If you need more details with regard to Users and user privileges in Ubuntu, you may wish to review this article: http://www.reallylinux.com/docs/usersubuntu.shtml
Ubuntu will open and the Update Manager should automatically open (if not, it can be found in System/Administration).
Select Install Updates (this may take a while depending on your internet speed).
OUTSTANDING!You should now have a virtual machine Ubuntu running inside OS X.
(Optional to increase graphics performance)
Whilst in Ubuntu,
Select Devices at the top of the screen again
Select Install Guest Additions
This will open on your Ubuntu desktop as something similar to VBOXADDITIONS_3.0.0_49315
Double click it to open
Double click autorun.sh
Select Run
Enter your password
It will open a terminal window and may take a couple of minutes to complete
Once finished, it will say, "Successfully installed the VirtualBox Guest Additions."
Press ENTER
Restart Ubuntu
Go to System/Preferences/Display to customize the screen size.
CONGRATUALTIONS and I give you a hearty welcome to Linux!
For further help with Linux, look over the list of the other articles here on the reallylinux.com website, as there are plenty more beginner articles to get you started.
TROUBLESHOOTING
The process is fairly straightforward, but in case you encounter an issue, I try to provide some tips for the more common anomalies.
If you get this message,
Select "Do not show this message again" and select OK
To change the mouse back and forth simply click the Linux window to use Linux. To change back to Mac OS X, press the host key once (as indicated at the bottom right of the Linux window)
If you get a black screen on the Linux window, simply double click to restore session.
Note: to close VirtualBox, in the open Ubuntu window, select your name on the menubar and select shutdown; when it says Aborted or Powered Off under your Ubuntu Linux boot in the VirtualBox program, it is safe to close VirtualBox. To run in the future, simply open VirtualBox, select your operating system e.g. Ubuntu Linux and select Start
If the installation fails for some reason or another, select the operating system name, while in VirtualBox, and then select Discard. Unfortunately, if a complete fail occurs, you will need to restart the installation process. Make sure your ISO burn is correct.
You may also wish to review the article Exploring Linux with Ubuntu.