Custom Partitioning on ArchLinux with Linode
By Phil on Friday, January 9 2009, 15:31 - Computing - Permalink
Partitioning schemes are a hot topic and everyone has their own preference. Including me. I'm not going to tell you how you should partition your Linux setup, but I will tell you how to do it in ArchLinux on a Linode. I used LVM and will be using LVM in this post.
A What? Linode?
Linode offer VPS. If you don't know what VPS is, ask Wikipedia. Since my shared hosting was up for renewal in less than a month, I decided to look around and see if I could find a better deal. There was some things I wasn't happy with at my shared hosting, particularly the lack of shell access to my account. There were a lot of other niggly things too. I came to the conclusion that doing it all myself would make me much happier.
The Problem
So I purchased a Linode to replace my existing shared hosting service. Their prices are reasonable, and they offer ArchLinux as an O/S option. I use ArchLinux on my Work Desktop, Home Desktop, 2 x Laptops and my home File Server. I'm comfortable with ArchLinux so it made sense to use Arch on my web server.
After opening my account, and ponied up my USD$20, I was immediately logged in and being asked where I would phsyically like to locate my Linode since there are 4 data centers across the US that I could choose from. A quick transfer test from work, home and a friends place showed that the Atlanta facility offered the best performance for my locations.
As easy as that, I now had a Virtual Machine in Atlanta, GA. Cool!
Having a look around the Linode Management Console, I quickly found the option to create a VM with ArchLinux as the O/S. Done. Boot. Login.
As I said, I'm familiar with ArchLinux, so I poked around to discover the 'physical' attributes of the box and the peculiarities of the installation. This is where I hit my first wall:
root ~ # df -h Filesystem Size Used Avail Use% Mounted on /dev/xvda 1008M 506M 493M 51% / none 175M 0 175M 0% /dev/shm
Well that's annoying. I get 2 partitions -- a root and a swap. This would have to be rectified.
The Solution
This is how I ended up solving my problem. There's probably other ways, but this is what I did.
Create a Virtual Disk
From the Linode Dashboard, click Deploy Linux Distribution
and select ArchLinux
. The disk we will create here will ultimately end up being the / for your installation. In the meantime, it's going to hold everything so it has to be at least the minimum size required for ArchLinux (436mb). I made mine 500mb. You should be able to resize this at a later date, but I haven't bothered to do that. Setup your swap and root password, then Create Profile
.
Rename the Virtual Disk
Back in the Linode Dashboard, click "Image Options" next to the disk that was created for your Linode and rename it to something easy to identify. I called mine "arch-root" and will refer to it as that throughout this post.
Create a Virtual Disk for the LVM Physical Volume
Select "Create a new Disk Image" from the dashboard. Label the disk as arch-lvm
or something else you can easily identify. I will be referring to it as arch-lvm
. Choose whatever size works for you. I used 5408mb for my Linode (8 websites, including PostgreSQL and MySQL databases, plus a mail server and DNS server). Make sure you select unformatted / raw
as the Filesystem Type.
Boot Rescue LiveCD
Linode includes a setup for a LiveCD called Finnix. This assists you in being able to resuce your Linux install if something goes wrong, as well as being handy for other maintenance tasks that are better done from outside the environment on the disk. We need to create a second configuration profile for Finnix so we can boot it and do our partitioning. Click 'Create New Configuration Profile' in the dashboard, and set the following options:
- Label:
Finnix LiveCD
- Kernel:
Recovery - Finnix (Kernel)
- Memory:
Max
- Run Level:
Default
- Drive Setup: /dev/xvda =
Recovery - Finnix (iso)
- Drive Setup: /dev/xvdb =
arch-root
- Drive Setup: /dev/xvdc =
arch-lvm
- Uncompressed initrd image:
Recovery - Finnix (initrd)
Leave everything else as default and click Save Profile
. Now you can boot this configuration by clicking Boot
next to it profile in the dashboard.
Create the LVM
Finnix doesn't give you an SSH server to login to, so you need to login to the Console provided by Linode. Look on the Console
tab in the dashboard if you're unsure how to do this.
Once you are logged in to the console, you should be at a root prompt. From here we can setup our LVM. A strange quirk about Linode is that we don't treat the virtual disks like physical disks -- we treat them as a partition. So instead of creating a partition table and partition on /dev/xvdc called /dev/xvdc1, we just create the LVM Physical Volume directly on /dev/xvdc.
So let's get the LVM Setup. I'm not going to guide you through LVM here, there's plenty of other guides on the interwebs for that. This is based on how I custom partition. Suit yourself, just remember what you do here, because the rest of my guide will be using the scheme I've got here
pvcreate /dev/xvdc vgcreate lvmData /dev/xvdc lvcreate -L 256M --name home lvmData lvcreate -L 512M --name tmp lvmData lvcreate -L 512M --name var lvmData lvcreate -L 1G --name srv lvmData lvcreate -L 2G --name usr lvmData
Format the LVM Volumes
Needs to be done. I'm not going to argue with you. Use whatever file system tickles your fancy here. Personally I'm not much of a fan of ext3, but it supports growing and shrinking which fits well with our LVM setup.
mkfs -t ext3 /dev/lvmData/home mkfs -t ext3 /dev/lvmData/tmp mkfs -t ext3 /dev/lvmData/var mkfs -t ext3 /dev/lvmData/srv mkfs -t ext3 /dev/lvmData/usr
Mount the Arch disk and LVM volumes
Now we need to mount everything so we can shuffle all our files about to their proper places
mount /dev/xvdb /mnt mkdir -p /new/{home,tmp,var,srv,usr} mount /dev/lvmData/home /new/home mount /dev/lvmData/tmp /new/tmp mount /dev/lvmData/var /new/var mount /dev/lvmData/srv /new/srv mount /dev/lvmData/usr /new/usr
So now we have our default Linode Arch installation mounted to /mnt and all our LVM volumes mounted to their respective directories within /new/
Move the Data
We only want to copy here, as we need to keep the files on the original disk temporarily so we can chroot in to it later.
cp -a /mnt/home/* /new/home/ cp -a /mnt/tmp/* /new/tmp/ cp -a /mnt/var/* /new/var/ cp -a /mnt/srv/* /new/srv/ cp -a /mnt/usr/* /new/usr/
Update Arch config files and mkinitcpio
So now that our data has been moved, we just need to update the fstab file in Arch so it will know where to find everything.
mount -o bind /dev /mnt/dev mount -o bind /sys /mnt/sys mount -o bind /proc /mnt/proc chroot /mnt/
We are now inside a chroot environment of our Arch installation (faking that we booted Arch and not Finnix, without actually having to boot Arch). Edit /etc/fstab
and add our new mount points:
# LVM Mount Points /dev/mapper/lvmData-home /home ext3 defaults 0 0 /dev/mapper/lvmData-tmp /tmp ext3 defaults 0 0 /dev/mapper/lvmData-usr /usr ext3 defaults 0 0 /dev/mapper/lvmData-srv /srv ext3 defaults 0 0 /dev/mapper/lvmData-var /var ext3 defaults 0 0
Fix rc.conf so Arch know's we're using LVM now. Change USELVM
to yes
''Update: The lvm2 package is missing from the Linode Arch image, so you need to exit the chroot, unmount everything in /new to /mnt and then re-enter the chroot to install lvm2:
pacman -Syf lvm2
Cleanup
That's it! Everything should be good to rock'n'roll so we can cleanup and reboot. First, exit our chroot:
exit
Then cleanup the original directories that we've moved to the LVM:
rm -Rf /mnt/home/* rm -Rf /mnt/tmp/* rm -Rf /mnt/var/* rm -Rf /mnt/srv/* rm -Rf /mnt/usr/*
Don't forget the /* on the end of the rm commands. We only want to remove the contents of the directories, not the directories themselves. Next, we can unmount everything...
umount /mnt/dev umount /mnt/sys umount /mnt/proc umount /mnt umount /new/home umount /new/tmp umount /new/var umount /new/srv umount /new/usr shutdown -r now
Back in the Linode Dashboard, you should be able to boot your Arch Linux configuration and enjoy your new custom partitioning