Linux System Administration

Now the problem is, how the heck do you create the new filesystems, and how do you copy the files over? This month's article will help you do that.

When you installed Linux for the first time, you made at least one filesystem to store Linux on. If you're like me at all, you quickly decided you needed more drive space. Now the problem is, how the heck do you create the new filesystems, and how do you copy the files over? This month's article will help you do that. I'm also going to go into describing the /etc/inittab file, a rather important file that gets loaded when you boot your system. When making a filesystem for expanding your system space, there are a few things you have to consider. Where do you want your new fielsystem located? Making a larger /usr directory may be what you need, but expanding your /usr/X386 directory may be a better idea. Remember that not all filesystems have to come off the / (root) directory. You can mount any directory to any filesystem, but don't put any of the following on a different filesystem other than /: /etc /dev /lib /sbin /bin /conf. Each of these directories are needed during boot-up, and other filesystems are mounted *after* Linux has booted. This could make booting up Linux a difficult or impossible task. Let's assume that you want to make your user partitions bigger, and that you have your user's home directories in the /user directory, currently on the / (root) partition. Here's what you do. NOTES: IDE drives are /dev/hda and /dev/hdb. SCSI drives use /dev/sda through /dev/sde. Your particular setup may look different than my sample setup. Please read all the instructions and be sure you understand what is going on before you start!! If you are confused, look at the manual pages for the commands that I reference. They are a great help.

Make the partition you want to use.

Go into fdisk (`fdisk' followed by the drive name—/dev/hda, /dev/hdb, etc). Make a new partition by using the n command. You will now be asked for a partition type (extended, primary, or logical). Answer with the partition type you want to use. Now, you have to give a starting cylinder. For simplicity, just type in the first number you see in the list. After this, you must now type in the size of the partitions in 1K blocks. You can also type in a number followed by M to specify that the number is 1Meg blocks. So an answer of 30M would make a 30Meg partition. Your new partition should now be set up. Type p to list your partitions and write down the block size of the partition you just created. You'll need this in your next step. Quit fdisk (with the w command), and you may want to reboot your machine at this time to make sure that the partitions are read correctly. In my setup, I have a new drive I just installed, and I'm going to make a logical partition on my second hard drive (/dev/hdb):

#fdisk /dev/hdb
Command (m for help): n
First cylinder (205-731): 205
Last cylinder or +size or +sizeM or +sizeK (205-731): +30M
Warning: partition 5 has an odd number of sectors.
Command (m for help): w
The partition table has been altered!
Calling BLKRRPART ioctl() to reread partition table
Syncing disks
Reboot your system to ensure partition table is updated
Make the filesystem

The command to make a Second Extended Filesystem is mke2fs. I'm using EXT2FS (as it is commonly called) because it provides a lot of features now, plus has the ability for future support built in. For example, it supports a clean bit where if you unmount a filesystem successfully, you won't get bugged later on to do a filesystem check. It makes booting up Linux much faster. There is also the ability to support a compressed filesystem, where files are automatically compressed. This is not coded into the filesystem yet, but when the kernel supports it, you'll have a compressed filesystem. But back to making your filesystem. Type the command: mke2fs -c <partition> <size in blocks> where <partition> is the hard drive partition you wish to format and <blocks> is the number of 1K blocks that you wrote down in the previous step. The -c tells mke2fs to automatically check for bad blocks. This will help avoid surprises when the hard drive tries writing to a bad block later on.

In my case:

#mke2fs -c /dev/hdb5 31019
{Various data about number of inodes, number of blocks, etc} #
Make a copy of partition you want to move

The best way to do this is to use the tar (tape archive) command. A tar file will store important information like file ownership, permissions, and file dates that a copy command would lose. Find out the size of the files you're copying with the du -s <directory> command, where <directory> is the directory you want to move to the new partition. The -s option will give a grand total of all the files and directories. I want disk usage of the /user directory, so df -s /user will tell me how much space the /user directory currently takes up:

#df -s /user
11906 #

As this number is in 1K blocks, I know that my /user direc-tory and all the user files under that take up just under 12Meg. Luckily, my root partition has 15Meg free (you can check your free space with the df command). Use the following command to make a tar file of your /user directory: tar -cvf <tar file> <directory>, where <tarfile> tells what you want to call the tar file and <directory> is the directory you want to tar up. For me, this would be:

#cd / #tar -cvf /user.tar /user user user/root user/root/.bashrc
{list of files} #

The c option tells tar you want to create a tar file, the v option tells tar to tell you what files it's adding to the tar file, and the f option tells tar that the next thing it sees is a file to create. Now, if you're in the root directory and type ls -la user.tar you should see something like:

#ls -la user.tar -rw-r-r-   1 root     root        12103680 Mar  1 01:41
user.tar #

White Paper
Linux Management with Red Hat Satellite: Measuring Business Impact and ROI

Linux has become a key foundation for supporting today's rapidly growing IT environments. Linux is being used to deploy business applications and databases, trading on its reputation as a low-cost operating environment. For many IT organizations, Linux is a mainstay for deploying Web servers and has evolved from handling basic file, print, and utility workloads to running mission-critical applications and databases, physically, virtually, and in the cloud. As Linux grows in importance in terms of value to the business, managing Linux environments to high standards of service quality — availability, security, and performance — becomes an essential requirement for business success.

Learn More

Sponsored by Red Hat

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState