Technology
If you find yourself in a situation where you have run out of drive space and your applications are failing as a result, you can run the following command to remove the reserve blocks on the drive and make some space.
Replace /dev/devicename with the partition you need to make space on, such as /dev/hda1 or /dev/sda5, etc.
This is not a permanent solution. You will want to find the reason why drive is full and make some space or add more space by adding another drive.
This handy little command can help in finding the largest files on the server.
NOTE: RAID expansions can take a few hours to complete, especially if done on-line. This assumes that new drives have been added to the RAID array and a rebuild of the array has been done. You will need to follow these steps to have the OS recognize the new space.
1. Confirm fdisk -l shows the new size of the array. It should NOT match what df -h shows since the final steps have not been completed. Ex:
Disk /dev/cciss/c0d0: 734.0 GB, 734054703104 bytes
255 heads, 63 sectors/track, 89243 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/cciss/c0d0p1 * 1 13 104391 83 Linux
/dev/cciss/c0d0p2 14 274 2096482+ 83 Linux
/dev/cciss/c0d0p3 275 405 1052257+ 82 Linux swap
/dev/cciss/c0d0p4 406 53309 424951380 5 Extended
/dev/cciss/c0d0p5 406 53309 424951380+ 83 Linux
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/cciss/c0d0p5 267G 148G 119G 24% /
/dev/cciss/c0d0p1 99M 12M 83M 12% /boot
none 1014M 0 1014M 0% /dev/shm
/dev/cciss/c0d0p2 2.0G 79M 1.8G 5% /tmp
2. Run 'fdisk /dev/sda' or 'fdisk /dev/cciss/c0d0'. The device that you choose depends on the configuration. The fdisk -l will have shown you which one to choose. Ex.
The number of cylinders for this disk is set to 89243.
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):
3. Print the partition table with 'p'. Very Important–Make note of the 'Start' cylinder of the Extended partition. You will need this in order to create the new partition. Ex.
Disk /dev/cciss/c0d0: 734.0 GB, 734054703104 bytes
255 heads, 63 sectors/track, 89243 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/cciss/c0d0p1 * 1 13 104391 83 Linux
/dev/cciss/c0d0p2 14 274 2096482+ 83 Linux
/dev/cciss/c0d0p3 275 405 1052257+ 82 Linux swap
/dev/cciss/c0d0p4 406 53309 424951380 5 Extended
/dev/cciss/c0d0p5 406 53309 424951380+ 83 Linux
4. Delete the Extended partition with 'd'. Enter the partition number when asked. Ex.
Partition number (1-5): 4
5. Print the partition table again with 'p'. Verify that the Extended partition has been deleted. Ex.
Disk /dev/cciss/c0d0: 734.0 GB, 734054703104 bytes
255 heads, 63 sectors/track, 89243 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/cciss/c0d0p1 * 1 13 104391 83 Linux
/dev/cciss/c0d0p2 14 274 2096482+ 83 Linux
/dev/cciss/c0d0p3 275 405 1052257+ 82 Linux swap
6. You will now recreate the new Extended partition with 'n'. Enter 'e' for extended partition. Enter the Start cylinder that you made note of from above.
Command action
e extended
p primary partition (1-4)
e
Selected partition 4
First cylinder (406-89243, default 406): 406
Last cylinder or +size or +sizeM or +sizeK (406-89243, default 89243):
Using default value 89243
7. Create a primary partition on the new Extended partition with 'n'. Use the start cylinder noted above. Again, get this number correct or data loss can occurr. Ex.
First cylinder (406-89243, default 406): 406
Last cylinder or +size or +sizeM or +sizeK (406-89243, default 89243):
Using default value 89243
8. Print the partition table with 'p' and verify the new Extended and Primary partitions are there and they show the correct size. Ex.
Disk /dev/cciss/c0d0: 734.0 GB, 734054703104 bytes
255 heads, 63 sectors/track, 89243 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/cciss/c0d0p1 * 1 13 104391 83 Linux
/dev/cciss/c0d0p2 14 274 2096482+ 83 Linux
/dev/cciss/c0d0p3 275 405 1052257+ 82 Linux swap
/dev/cciss/c0d0p4 406 89243 713591235 5 Extended
/dev/cciss/c0d0p5 406 89243 713591203+ 83 Linux
9. If everything looks good, write the changes and exit fdisk with 'w'. Ex.
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.
10. Reboot the server.
11. Once the server comes back up you will need to perform this final command 'ext2online /'. This will take a few minutes depending on the size of the expansion. Ex.
resize2fs /dev/cciss/c0d0p5
12. When the above command completes, run df -h and make sure the partitions are all showing the correct size of the new RAID array. If so, you are done. Ex.
Filesystem Size Used Avail Use% Mounted on
/dev/cciss/c0d0p5 670G 148G 488G 24% /
/dev/cciss/c0d0p1 99M 12M 83M 12% /boot
none 1014M 0 1014M 0% /dev/shm
/dev/cciss/c0d0p2 2.0G 78M 1.8G 5% /tmp
Since I am apparently unable to remember how to do a simple sort, I'm going to throw it into my blog so I can refer to it later.
In this particular case, I was attempting to pull out all of the "from=" entries in the server's mail logs. I won't go into the details of the awk command, but I will paste my entire command here anyway, including the sorts:
The summary of the above command is this:
I cat the mail log on the server and using awk I pull out the 6th column (columns separated by spaces) and then I apply the sort. The first sort does a general sort on that column. The 'uniq -c' does a count of the number of times a unique entry appears from the first sort. The final 'sort -n' sorts the output of the uniq command in numerical order so it is easier to read.
If you encounter the following error when running the Urchin stats update it can easily be corrected.
"Unable to open database for writing since it has been archived"
The error occurs whenever Urchin has archived its log tracking databases. The fix for this is pretty simple.
1. Navigate to /usr/local/urchin/data/reports/[profile]
2. Unznip the [date]-archive.zip files
3. Move the archived files out of the way (to another directory).
4. Change ownership of the unzipped files to the urchin user
5. Re-run the statistics and they should show up
That's it. Easy Fix.
Lets suppose you have a shared httpdocs directory on your server in which you would like to have your developers gain access. However, there is going to be more than one developer and each one will have their own login credentials. This becomes a problem because of file ownership permissions. If one developer has uploaded a file, the others are not going to be able to access it.
Along comes setfacl to the rescue.
Let's assume with have two users and the usernames they login as are john and jane. You want john and jane to both be able to upload files to the directory as well as access each others files.
Since there are different ways to approach this, I am going to use what I call the "per user" version. In this version, you add each user individually.
To add the username john:
To add the username jane:
If there are existing files in the httpdocs directory that you want them both to have access to, you would run this recursively with the -R flag.
So now that the files and the directory are set to allow john and jane access, you want to set the directory so that any new files that are created are set with default facls that allow john and jane access. This is similar to the above commands except you add the -d flag as well. It should look like this:
For john
For jane
You can see the results of the setfacl with getfacl. The output of getfacl httpdocs would look something similar to this:
# file: httpdocs
# owner: directory_owner
# group: group_of_owner
user::rwx
user:john:rwx
user:jane:rwx
group::r-x
mask::rwx
other::—
default:user::rwx
default:user:john:rwx
default:user:jane:rwx
default:group::r-x
default:mask::rwx
defaul:other::—
That's it. John and Jane can access all files in the folder as well as create files that are then accessible by both of them.
