Sunday, April 28, 2013
My poor, forgotten blog.
I have abandoned you for almost a year. Perhaps I will post more VirtualBox and Linux goodies on you so I can forget about you for another year.
I may or may not reply to comments. I apologize for the tardiness.
Wednesday, April 18, 2012
PHP usergroup parser (/etc/group)
Either I'm too lazy to have searched for an existing method, or there isn't one.
So long as your system isn't confined by open_basedir or something like that, this should work. Personally, I need this to get the names of the groups by their numeric ID without having to use a bunch of calls to filegroup() or by using DirectoryIterator::getGroup, although now that I take a closer look at the latter it seems like a better and better idea. Originally, I was going to use stat() and parse the results from what my script finds in /etc/group.
I might still use this for something or other, or perhaps not. Either way, here it is for your using and viewing pleasure.
The script will read the contents of /etc/group and return an array where the keys are the user group names and the value is their numeric id. That's just how I whipped it up though it would probably make more sense to have it the other way around.
So long as your system isn't confined by open_basedir or something like that, this should work. Personally, I need this to get the names of the groups by their numeric ID without having to use a bunch of calls to filegroup() or by using DirectoryIterator::getGroup, although now that I take a closer look at the latter it seems like a better and better idea. Originally, I was going to use stat() and parse the results from what my script finds in /etc/group.
I might still use this for something or other, or perhaps not. Either way, here it is for your using and viewing pleasure.
The script will read the contents of /etc/group and return an array where the keys are the user group names and the value is their numeric id. That's just how I whipped it up though it would probably make more sense to have it the other way around.
<?php
$g = file_get_contents('/etc/group');
$g = explode("\n", $g);
$c = count($g) - 1;
$groups = array();
$x = 0;
foreach ($g as $row) {
if ($x === $c) {break;}
$row = explode(':', $row);
$groups[$row[0]] = intval($row[2]);
$x++;
}
echo json_encode($groups);
?>
Sunday, April 15, 2012
Change MySQL root password
After initially installing MySQL on any platform your root user usually has no password. To set it from the command line issue the command:
That's pretty basic stuff, but what if you get locked out of your server from having a typo in the password set, forgetting the password, etc, etc?
First, you need to stop the mysql daemon from running.
Then start the daemon again without the grant tables (the tables containing permissions and user data), and if you are on a live server, you may want to start it without networking since without the grant tables ANYONE can access ANY database from ANYWHERE.
Note: If you are running as root user on your system you will need to add the --user=USER argument to the following command, where user is the user that mysqld will run as (usually mysql)
Now you can log in to mysql without a password or user:
Now you just need to update the root user password using mysql:
Then flush the privileges table:
After that is done, you need to stop mysqld and restart it normally. You will now be able to gain access to the root user with the password you have set.
# mysqladmin -u root password NEWPASSWORD
That's pretty basic stuff, but what if you get locked out of your server from having a typo in the password set, forgetting the password, etc, etc?
First, you need to stop the mysql daemon from running.
Then start the daemon again without the grant tables (the tables containing permissions and user data), and if you are on a live server, you may want to start it without networking since without the grant tables ANYONE can access ANY database from ANYWHERE.
Note: If you are running as root user on your system you will need to add the --user=USER argument to the following command, where user is the user that mysqld will run as (usually mysql)
# mysqld --skip-grant-tables --skip-networking [--user=mysql] &
Now you can log in to mysql without a password or user:
# mysql
Now you just need to update the root user password using mysql:
mysql> UPDATE mysql.user SET Password=PASSWORD('NewPass') WHERE User='root';
Then flush the privileges table:
mysql> FLUSH PRIVILEGES;
After that is done, you need to stop mysqld and restart it normally. You will now be able to gain access to the root user with the password you have set.
Thursday, March 29, 2012
Installing Fedora 16 from Hard Drive
Okay!
To start, this post will assume that:
- You are using the grub boot loader. That's it.
For reference, I use different partitions. My disk is partitioned in this manner:
The sizes are probably off, irrelevant, I know.
Now, go download the Fedora 16 ISO image. *NOT* the LiveCD image, the entire install DVD.
After you have this, mount it:
I might mention here that if you have your /boot on a separate partition as I do, you will need to ensure that it is not very small. I have mine at 4GB, the default size was 100Mb so I had to grow the partition to fit the Fedora vmlinuz image, which is ~128MB alone. You can check by typing
You may not need 4GB. I will leave it up to you to do the math. If you have your entire installation on one partition, including /boot then I guess you don't have to worry.
ANYWAYS, carrying on.
Being in the mounted directory, you will see a folder named `isolinux`, cd into this directory.
Be sure that you have your boot partition mounted and copy these two files into boot, ensuring that you rename them so you don't overwrite anything that might be there already. If you do that, I LAUGH AT YOU BECAUSE YOU CLEARLY DIDN'T READ WHAT I JUST TOOK THE TIME TO WRITE.
Let that be a lesson because you can't undo it and you've just overwritten your working OS with an installation image. If that's okay with you, just reboot and it should boot right into the install. If not, HAHAHA.
Do this:
Now people would say that "oh, you should edit your grub configuration!", but you know what? I find it complicating and annoying to have to add it into your grub menu. Just boot it from your grub command line, which you can access by pressing 'c' at the grub menu:
The second command might take a little bit to load the image, but it will. Don't be so impatient!
That's it. Enjoy.
Any problems aside from "I didn't read the instructions and I baleted my working operating system, WHAT DO?" I will be more than glad to help.
To start, this post will assume that:
- You are using the grub boot loader. That's it.
For reference, I use different partitions. My disk is partitioned in this manner:
Device Mount Point Size Description
/dev/sda1 /boot 4 GB Used to hold kernel and fs images.
/dev/sda2 ~320GB Extended partition labeled canister to hold logical devices
/dev/sda3 ~130GB ext4 filesystem
/dev/sda4 / ~90 GB Partition that holds Arch Linux, which I use as a fallback.
The sizes are probably off, irrelevant, I know.
Now, go download the Fedora 16 ISO image. *NOT* the LiveCD image, the entire install DVD.
After you have this, mount it:
# mkdir -v /mnt/iso
# mount Fedora-16-i386-DVD.iso /mnt/iso
# cd /mnt/iso
I might mention here that if you have your /boot on a separate partition as I do, you will need to ensure that it is not very small. I have mine at 4GB, the default size was 100Mb so I had to grow the partition to fit the Fedora vmlinuz image, which is ~128MB alone. You can check by typing
df -hYou may not need 4GB. I will leave it up to you to do the math. If you have your entire installation on one partition, including /boot then I guess you don't have to worry.
ANYWAYS, carrying on.
Being in the mounted directory, you will see a folder named `isolinux`, cd into this directory.
Be sure that you have your boot partition mounted and copy these two files into boot, ensuring that you rename them so you don't overwrite anything that might be there already. If you do that, I LAUGH AT YOU BECAUSE YOU CLEARLY DIDN'T READ WHAT I JUST TOOK THE TIME TO WRITE.
Let that be a lesson because you can't undo it and you've just overwritten your working OS with an installation image. If that's okay with you, just reboot and it should boot right into the install. If not, HAHAHA.
Do this:
# cd isolinux
# cp vmlinuz /boot/f16install-vmlinuz
# cp initrd.img /boot/f16install-initrd.img
Now people would say that "oh, you should edit your grub configuration!", but you know what? I find it complicating and annoying to have to add it into your grub menu. Just boot it from your grub command line, which you can access by pressing 'c' at the grub menu:
grub> kernel=/f16install-vmlinuz
grub> initrd=/f16install-initrd.img
grub> boot
The second command might take a little bit to load the image, but it will. Don't be so impatient!
That's it. Enjoy.
Any problems aside from "I didn't read the instructions and I baleted my working operating system, WHAT DO?" I will be more than glad to help.
GRUB shell on arch linux
My previous post mentioned how to boot from a rootfs shell. From what I am experiencing, I screwed up the grub configuration, so when I boot my computer I am entered directly into a grub shell. To get into the rootfs shell so I can boot arch linux ,I issue the following:
It then proceeds to boot the kernel. I am aware that it's taking me to rootfs because I'm not entering the device. I just haven't toyed with it enough, or bothered searching for the appropriate values. /dev/sda and /dev/sdaX do not work. I will update whenever I figure it out.
UPDATE:
I found out what was causing this. The entry in grub (which I have now agonizingly updated to grub2) was set to look for the device /dev/disk/by-uuid/c48c81b7-e772-42a6-95af-f27d768b887b
looking in /dev/disk/by-uuid, that uuid did not exist, nor was it the one for /dev/sda4
I changed it to the corresponding uuid and what it was linked to.
Here is a sample output from my laptop:
Pretty straightforward, no?
grub> kernel=/vmlinuz-linux [ENTER]
[Linux-bzImage, setup=0x4200, size=0x2fc90]
grub> initrd=/initramfs-linux.img [ENTER]
{Linux-initrd @ 0x7fd35000, 0x2ba04e bytes]
grub> boot [ENTER]
It then proceeds to boot the kernel. I am aware that it's taking me to rootfs because I'm not entering the device. I just haven't toyed with it enough, or bothered searching for the appropriate values. /dev/sda and /dev/sdaX do not work. I will update whenever I figure it out.
UPDATE:
I found out what was causing this. The entry in grub (which I have now agonizingly updated to grub2) was set to look for the device /dev/disk/by-uuid/c48c81b7-e772-42a6-95af-f27d768b887b
looking in /dev/disk/by-uuid, that uuid did not exist, nor was it the one for /dev/sda4
I changed it to the corresponding uuid and what it was linked to.
Here is a sample output from my laptop:
# ls -l /dev/disk/by-uuid
lrwxrwxrwx 1 root root 10 Mar 29 14:46 1c7fe2bc-2f14-48e4-84b7-08f1c53a90e2 -> ../../sdb1
lrwxrwxrwx 1 root root 10 Mar 29 14:46 492b94e8-25b4-463b-86a3-6e80d3b40632 -> ../../dm-2
lrwxrwxrwx 1 root root 10 Mar 29 14:46 4c34416c-fc03-4add-b1a0-ba9f5603bc4c -> ../../dm-0
lrwxrwxrwx 1 root root 10 Mar 29 14:46 78b772e4-59b1-4563-b6ab-6d9c24ef9fcd -> ../../sda2
lrwxrwxrwx 1 root root 10 Mar 29 14:46 c3230d94-1048-4c3e-8e35-aea175f6f667 -> ../../dm-1
lrwxrwxrwx 1 root root 10 Mar 29 14:46 f8c7dfa7-907a-4ac5-a2e4-a89e139b7224 -> ../../sdb2
Pretty straightforward, no?
service script on arch linux
Personally I am accustomed to redhat builds of Linux and find myself typing "service".
Instead of typing /etc/rc.d/$service $command where $service is the name of the service I wish to start, or searching for a pre-made solution, I wrote up a little script and saved it as /usr/sbin/service.
After saving it chmod it to 755 so it can be executed. You can now issue the command: service network start
and have the network service start successfully, or whichever service script you find in /etc/rc.d
Instead of typing /etc/rc.d/$service $command where $service is the name of the service I wish to start, or searching for a pre-made solution, I wrote up a little script and saved it as /usr/sbin/service.
#/bin/sh
/etc/rc.d/$1 $2
After saving it chmod it to 755 so it can be executed. You can now issue the command: service network start
and have the network service start successfully, or whichever service script you find in /etc/rc.d
rootfs on arch linux
Find yourself in a bind and logged in to a recovery shell named rootfs?
If you happen to know the partition that your operating system is on, and the boot partition, you can boot into your kernel from this shell.
On my system, I have this layout:
From this rootfs shell, I executed the following commands and booted into the desired kernel on sda4.
This had me boot into my fresh install of arch that I had installed from another partition. Now I can fix grub!
If you happen to know the partition that your operating system is on, and the boot partition, you can boot into your kernel from this shell.
On my system, I have this layout:
/dev/sda1 > /boot
/dev/sda2 > /home
/dev/sda3 > / (ext4)
/dev/sda4 > / (ext4)
From this rootfs shell, I executed the following commands and booted into the desired kernel on sda4.
# mkdir /boot
# mount -t /dev/sda4 /new_root
# cd /new_root
# exec init
This had me boot into my fresh install of arch that I had installed from another partition. Now I can fix grub!
Subscribe to:
Posts (Atom)