Google the SiteQuicksearchCategoriesSyndicate This BlogCreative CommonsBlog Administration |
Friday, January 5. 2007Moving munk.me.uk to a new HDD - filesystem layout
Well after having been on FreeBSD 4.x for as long as I can remember (4years now I guess), it's finally time to move to FreeBSD 6.x! For ages I've been saying as soon as I get a larger HDD I'd upgrade the system and santa kindly delivered a shiny new 250Gb Maxtor DiamondMax 10, so it's time to sort it out and make the move.
Funny now I think about it, for me upgrading to a larger capacity HDD has always been a fairly rare occasion. Back in 2000 or so I remember moving from a measily 1.6Gb to a whopping 20Gb HDD and thinking that was way too much. In a way it's a good thing to not have a lot of space - it makes you more tidy and less likely to spam crap all over the filesystem. Of course on the other hand not having a lot of space also sucks if you want to store a lot of stuff (duh). This is kind of how it's been with my FreeBSD server for the last 4yrs or so - I've only had a 40Gb drive and in that time I've hosted over 100 users at the same time, dozens of domains, ran a load of services, and never really had a lot to complain about re lack of space. The main reason for the change I guess is the increased use of broadband/bittorrent which I really need more space to save files to disk for. I'm gonna document the filesystem layout of the new HDD here, no doubt it'll only be me that ever reads this again (and you if you're reading this heh :o). File System Layout I spent quite a while thinking about how best to partition/slice up the new 250Gb disk, mainly because my server is running 24/7 and various applications really do kane the filesystem when accessing data (ie apache and mysql for two). I want to try and partition the disk so that it's more efficient for apache and mysql to read/write from/to the disks. The other deliberation I went through whilst thinking about the file system layout was where to mount partitions for backups, music, videos and windows application installers. Of course this could be anywhere really - /backups /music /videos /windows for example - but I don't really like spamming the root level filesystem with lots of folders that only add clutter. I had a quick look at the Filesystem Hierarchy Standard which is a standard aimed at encouraging clean and consistent filesystem layouts on Unix type OSs and eventually ended up with the following layout: CODE: G=Gigabytes
fdisk: ====== Name Size Partition Type ==== ==== ============== ad1s1 59G freebsd ad1s2 89G freebsd ad1s3 49G freebsd ad1s4 33G freebsd disklabel: ========== Partition Mount Size (approx.) ========= ===== ============== ad1s1: ------ ad1s1a / 0.5G ad1s1b swap 2G ad1s1d /tmp 1G ad1s1e /var/db/mysql 20G ad1s1f /var/www 10G ad1s1g /var/ 10G ad1s1h /usr 20G ad1s2: ------ ad1s2d /home 40G ad1s2e /var/backups 50G ad1s3: ------ ad1s3d /var/media 50G ad1s4: ------ ad2s4d /var/win32 35G Saturday, November 18. 2006Let root see all files with locate
The locate utility on linux was one of the first tools I hit when I made the move to FreeBSD a few years back - knowing where files are is half the battle when you're trying to configure things and find documentation on how to do it. The trouble with locate though as jdarnold mentions in his article 'Locate This!' is that if you build the locate database as 'root', you end up exposing everything to any user that runs the locate command. The other problem he mentions is the locate db is only updated weekly on FreeBSD by default via the periodic system which isn't really enough if you use your system regularly.
I remember thinking along the same lines a while back and after reading through the man pages the solution I found was to create two separate databases - one for root and one for regular users. The 'regular' db is updated on a weekly basis as per the default on FreeBSD via periodic, whereas the other 'root' locate db is built daily in a crontab so I can get the latest up to date details on which files are where. To get the root db built first you need to create a crontab entry - i put this in /etc/crontab: CODE: 39 2 * * * root env -i LOCATE_CONFIG=/root/locate/conf/locate.rc /usr/libexec/locate.updatedb > /dev/null 2>&1 This tells the locate.updatedb script to use a separate configuration file - /root/locate/conf/locate.rc - for building root's locate db. The content of /root/locate/conf/locate.rc look like this: CODE: FCODES="/root/locate/db/locate.database.root" which indicates that this db should be built in /root/locate/db/locate.database.root instead of the default locate in /var/db/locate.database. You can safely run the command as root on the commandline to initialize your new db: CODE: root@users /root# env -i LOCATE_CONFIG=/root/locate/conf/locate.rc /usr/libexec/locate.updatedb Once the database is built you can move on to test the new db works ok: CODE: root@users /root# locate -d /root/locate/db/locate.database.root .cshrc.root /root/.cshrc.root This file is only readable by root, so it seems to work ok. To make things easier, add a shell alias in root's .cshrc file aliasing 'locate' to the command 'locate -d /root/locate/db/locate.database.root': CODE: root@users /root# grep locate $cshrc alias locate locate -d /root/locate/db/locate.database.root With the "-d /root/locate/db/locate.database.root" switch, locate will use the db at /root/locate/db/locate.database.root instead of the default /var/db/locate.database and root will be able to use locate to find any files in the filesystem, not just those that are world readable. Finally, one way to update the regular locate db as root but without making it list every world readable file is to perform the following: CODE: #!/bin/sh # make sure db file exists: touch /var/db/locate.database # then change ownership to the nobody user: chown nobody /var/db/locate.database # make it writeable by nobody and readable by everyone else: chmod 644 /var/db/locate.database # then move on to update the db... # first make sure we're in the / folder where the db update starts: cd / # then finally run the updatedb command as the 'nobody' user: echo "/usr/libexec/locate.updatedb" | su - -fm nobody This is basically what the 310.locate periodic script does and results in a locate db that contains only files that are readable by the 'nobody' user - essentially all 'world readable' files. Comparing the sizes of the root db against the nobody db: CODE: root@users /# ls -al /var/db/locate.database /root/locate/db/locate.database.root -rw-r--r-- 1 root wheel 4070484 Nov 18 02:45 /root/locate/db/locate.database.root -rw-r--r-- 1 nobody wheel 3280409 Nov 18 11:41 /var/db/locate.database You can see the size difference there, not as many entries in nobody's db as root's. Just to double check: CODE: root@users /root# locate .cshrc.root /root/bin/ktrace.out /root/ktrace.out /usr/local/etc/snort/ktrace.out root@users /root# echo "locate ktrace.out" | su - -fm nobody /usr/local/etc/snort/ktrace.out So from that you can see that 'nobody' can see the ktrace.out files located in /root - apart from root of course :) Sorted. Tuesday, November 14. 2006FreeBSD 6.2 To Include Security Event Auditing
Just read an interesting article about the addition of 'Security Event Auditing' in FreeBSD 6.2. Until now FreeBSD hasn't had any really useful security auditing other than using 'accounting' to log all syscalls which at best was confusing when it came to working out who did what when and how.
At one time I installed a kernel module lrexec to log all system exec calls, but this was also quite a handful to configure scripts so they reported only on certain users. Hopefully this new security auditing daemon will make security auditing a lot easier on FreeBSD. Read the article for more info on what's new: Security Event Auditing in FreeBSD 6.2 Also of interest is the new addition to the FreeBSD handbook on security auditing: FreeBSD Handbook: Security Event Auditing Tuesday, September 5. 2006Samba Upgrade to 3.0.23c and Login Failures
I just went to upgrade Samba to the latest FreeBSD port release - 3.0.23c. The portupgrade went smoothly but when I went to restart the samba daemon, I found I was locked out of the network shares on the FreeBSD machine when trying to login/access them from Windows.
Reading in /usr/ports/UPDATING revealed the problem: CODE: 20060904: AFFECTS: users of net/samba3 AUTHOR: timur@gnu.org Reviosion of Samba 3.0.23c port had changed location of the directory, where Samba stores it's smbpasswd files from $PREFIX/private to a more common $PREFIX/etc/samba. You need to move *.tdb files from an old to new location and remove old directory if you use tdbsam backend for Samba user authentication. The location of the samba password dbs changed! Small sigh of relief, moved the db files over and everything worked as normal. Pays to read /usr/ports/UPDATING! Monday, September 4. 2006Solving permission problems with parsepath.pl
parsepath.pl is a brilliant perl script for fixing permissions problems on Unix based platforms by Jeremy Mates. Probably the most common type of permission problem from a sysadmin/webmaster's viewpoint is uploading a file to a directory in a website's document root folder and then trying to access the file or script in a web browser only to get the dreaded 403 error message:
Forbidden Most time the solution is very simple, just change the permissions on 'test.php' to make sure the user the webserver runs as can read the file correctly - the simplest and most common method being to change the mode of the file to '755': CODE: chmod 755 test.php Unfortunately sometimes it's not that easy and many times you see users asking 'I'm getting 'access denied' errors even though I've changed the perms to 755'. The problem is that one of the subdirectories that the 'test.php' file lives in has permissions set so that the webserver can't read the file properly. Now that's where the headache comes in :) However, parsepath.pl can take the headache out of fixing permissions problems. Say you have a website document root directory tree /usr/local/www/web/www.munk.me.uk/foo/bar and you upload a web script 'test.php' into that directory. You try and access the file in a webbrowser but get the 403 permission denied error above. First off you check the permissions on the file itself: CODE: [23:58:17] root@users /usr/local/www/web/www.munk.me.uk/foo/bar# ; ls -l total 0 -rwxr-xr-x 1 www www 0 Sep 4 23:39 test.php That looks ok, with permissions 755 and the owner/group set to 'www' the webserver user 'www' should be able to read the file ok. So in this case the problem must be with the permissions on one of the parent subdirectories. The old method of working out the perms would be either to trawl one by one through each directory checking the perms on each subdirectory or to change the permissions recursively on the document root folder so all subfolders have the read bit set for the webserver user/group. With parsepath.pl things are a lot simpler though - just run the following command: CODE: [0:03:21] root@users /usr/local/www/web/www.munk.me.uk/foo/bar# parsepath.pl user=www +r test.php ! group=www +rx fails: d 0700 root:www /usr/local/www/web/www.munk.me.uk/foo ! unix-other +rx fails: d 0750 root:wheel /usr/local/www/web/www.munk.me.uk/foo/bar With this command parsepath.pl recurses through each subdirectory below the file/path you feed it on the commandline and tells you the permissions problems - if any - for the user 'www' (the user=www argument) to read (the +r argument) the file 'test.php'. In the output, we're told that permissions to read the test.php by the user www fails on two counts: CODE: # the group bit on the folder 'foo' doesn't have the +rx flag set: ! group=www +rx fails: d 0700 root:www /usr/local/www/web/www.munk.me.uk/foo # the other bit on the folder 'bar' doesn't have the +rx flag set: ! unix-other +rx fails: d 0750 root:wheel /usr/local/www/web/www.munk.me.uk/foo/bar With this information it's easy enough to go in and make the changes necessary to fix the problem using 'chmod g+rx foo foo/bar'. There are other ways of invoking parsepath.pl though. Running it just with a file/path as an argument it'll tell you the permissions on each subdirectory under it: CODE: [0:10:33] root@users /usr/local/www/web/www.munk.me.uk/foo/bar# > parsepath.pl /usr/local/www/web/www.munk.me.uk/foo/bar/test.php % /usr/local/www/web/www.munk.me.uk/foo/bar/test.php d 0755 root:wheel / d 0755 root:wheel /usr d 0755 root:wheel /usr/local d 0755 root:wheel /usr/local/www d 0770 www:wheel /usr/local/www/web d 0750 www:www /usr/local/www/web/www.munk.me.uk d 0700 root:www /usr/local/www/web/www.munk.me.uk/foo d 0750 root:wheel /usr/local/www/web/www.munk.me.uk/foo/bar f 0755 root:www /usr/local/www/web/www.munk.me.uk/foo/bar/test.php which can is better to see a whole tree in one go. No permissions were harmed in the making of this article! I'll include the parsepath.pl script in the extended article just in case the original ever gets lost - big credit of course goes to the author of the script, Jeremy Mates. His site is actually very interesting from a sysadmin's point of view containing lots of interesting admin scripts and thoughts on system administration in general - spent quite a while grazing through his stuff there - cheers Jeremy. Continue reading "Solving permission problems with parsepath.pl"
(Page 1 of 8, totaling 36 entries)
» next page
|

