Aug
09
2009

Cookbook for Linux filesystems

I added a new 500GB HDD to the Linux home PC. This drive will be dedicated to Samba shares for our home PC that has exhausted its 80GB hard drive. This gave me an opportunity to set up file systems on the Linux machine, a great learning opportunity. I decided to set up a 250GB physical volume called ‘/storage’ that would hold our multimedia files’ and a 250GB logical volume group, 100GB of which would be a ‘/backup’ volume to act as a backup drive for the home PC files (currently being backed up to CD-RW) and a 100GB drive called ‘/junk’ which has no other purpose than giving me a second logical volume in the volume group. Going forward, I’ll create all file systems as logical volumes, because these are easier to resize in the future. But using a physical volume for /storage game me a chance to experience the set up both.
What follows is a cookbook for each scenario, the physical volume /storage and the logical volumes /backup and /junk. I include all of the output of the system during the build. I don’t spend much time explaining the commands. For more information, review the man pages for the specific command, or post questions in the comment section.

[root@sserver ~]# fdisk /dev/sdb
The number of cylinders for this disk is set to 60801.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-60801, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-60801, default 60801): +250000M Note: Should have done this as 256000M to get a 250G partition. duh.

Command (m for help): p

Disk /dev/sdb: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 30395 244147806 83 Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
[root@sserver ~]#

Then reboot the system, and make and mount the volumes.

[root@sserver ~]# mke2fs -j /dev/sdb1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
30523392 inodes, 61036951 blocks
3051847 blocks (5.00%) reserved for the super user See notes below regarding reserved space
First data block=0
Maximum filesystem blocks=4294967296
1863 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 35 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@sserver ~]# mkdir /storage
[root@sserver ~]# mount -t ext3 /dev/sdb1 /storage
[root@sserver ~]# mount | grep storage
/dev/sdb1 on /storage type ext3 (rw)
[root@sserver ~]#
Add a line to /etc/fstab so that the new volume will mount automatically at startup. Done with vi editor
/dev/sdb1 /storage ext3 defaults 1 2

Now, This volume will be used only as a Samba share. As discussed here by Walker, we do not need to reserve block space for the root user or system logs. Here is how to adjust it:

[root@sserver /]# df -h /storage Display volumes for reference
Filesystem Size Used Avail Use% Mounted on
/dev/sdb1 230G 32G 186G 15% /storage
[root@sserver /]# tune2fs -m 0 /dev/sdb1
tune2fs 1.39 (29-May-2006)
Setting reserved blocks percentage to 0% (0 blocks)
[root@sserver /]# df -h /storage
Filesystem Size Used Avail Use% Mounted on
/dev/sdb1 230G 32G 198G 14% /storage

Ta-da! Now, on to a Logical Volumes. Logical volumes take more work to create and are more difficult to understand, but a quick read of Chapter 9 of the of the Redhat Deployment Guide will get you through. However, the deployment guide does not have a quick command line guide for creating LVMs.
I’m going to make a logical volume group VolGroup02, with two logical volumes, LogVol00 and LogVol01, each logical volume will be 100GB. I’ll start with the creation of the physical partition /dev/sdb2 using fdisk.

[root@sserver ~]# fdisk /dev/sdb

The number of cylinders for this disk is set to 60801.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): p
Disk /dev/sdb: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 30395 244147806 83 Linux
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (30396-60801, default 30396): hit enter to take default
Using default value 30396
Last cylinder or +size or +sizeM or +sizeK (30396-60801, default 60801): hit enter to take default
Using default value 60801
Command (m for help): p
Disk /dev/sdb: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 30395 244147806 83 Linux
/dev/sdb2 30396 60801 244236195 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.

Then initialize the physical volume for use by LVM, create the Volume Group and Logical Volumes.

[root@sserver dev]# pvcreate /dev/sdb2
Physical volume “/dev/sdb2″ successfully created
[root@sserver dev]# vgcreate VolGroup02 /dev/sdb2
Volume group “VolGroup02″ successfully created
[root@sserver dev]# vgs VolGroup02 display the new volume group
VG #PV #LV #SN Attr VSize VFree
VolGroup02 1 0 0 wz–n- 232.92G 232.92G
[root@sserver dev]# lvcreate -L 100G -n LogVol00 VolGroup02
Logical volume “LogVol00″ created
[root@sserver dev]# lvcreate -L 100G -n LogVol01 VolGroup02
Logical volume “LogVol01″ created
[root@sserver dev]# lvs /dev/VolGroup02 display the new logical volumes
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
LogVol00 VolGroup02 -wi-a- 100.00G
LogVol01 VolGroup02 -wi-a- 100.00G

Then create the file systems, remove the reserved the space, make and mount the file systems.

[root@sserver /]# mkfs -t ext3 -v /dev/VolGroup02/LogVol00
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
13107200 inodes, 26214400 blocks
1310720 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
800 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 35 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@sserver /]# tune2fs -m 0 /dev/VolGroup02/LogVol00
tune2fs 1.39 (29-May-2006)
Setting reserved blocks percentage to 0% (0 blocks)
[root@sserver /]# mkfs -t ext3 -v /dev/VolGroup02/LogVol01
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
13107200 inodes, 26214400 blocks
1310720 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
800 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 24 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@sserver /]# tune2fs -m 0 /dev/VolGroup02/LogVol00
tune2fs 1.39 (29-May-2006)
Setting reserved blocks percentage to 0% (0 blocks)
[root@sserver backup]# mkdir /backup
[root@sserver backup]# mkdir /junk
[root@sserver backup]# mount /dev/VolGroup02/LogVol00 /backup
[root@sserver backup]# mount /dev/VolGroup02/LogVol01 /junk
[root@sserver backup]# mount | grep VolGroup02
Then add the following to /etc/fstab so the mount automatically at startup:
/dev/VolGroup02/LogVol00 /backup ext3 defaults 1 2
/dev/VolGroup02/LogVol01 /junk ext3 defaults 1 2

[root@sserver ~]# df -h /backup /junk display the new volumes
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup02-LogVol00
99G 188M 99G 1% /backup
/dev/mapper/VolGroup02-LogVol01
99G 188M 99G 1% /junk

And it is almost that easy. I did have some problems at the outset of this endeavor. After I installed the 500GB drive, I re-installed Linux (for an unrelated reason). I had thought that the installation ignored the 500GB drive, however, I learned that the installation process will allocate all unused space into a logical volume. I was confused at first when it would not make the filesystem, citing that it was in use. The folks over at the centos.org forum were able to help me out and get me on track.

tags: , ,
posted in Infrastructure by Mark Stevens

Follow comments via the RSS Feed | Leave a comment | Trackback URL

blog comments powered by Disqus
 
Powered by Wordpress and MySQL. Theme by openark.org (color scheme modified)