Archive for December, 2012
How to get a hard drive serial number from udev.
by jfargen on Dec.26, 2012, under Uncategorized
Some times a hard drive will fail in such a way that tools like smartctl or hdparm is unable to get the hard drive serial number or in certain circumstances will give the wrong hard drive serial.
This may work some of the time, but it won’t always work depending on the type of failure a drive is experiencing. It is definitely a better alternative to try rather than getting someone to go down to the data center and pulling your drive.
*Note that WordPress does something to the hyphens and when rendered on the webpage it is a different character. When entering the command ensure that you enter (hyphen)(hyphen) before each option passed in the command.
$ /sbin/udevadm info –query=property –name=drive| grep -i serial
Just replace drive for which physical drive you are trying to get details. In my case I use the command like so as an example.
$/sbin/udevadm info –query=property –name=sda| grep -i serial
KVM:Reset Linux Guest Password and/or Password Expiration
by jfargen on Dec.21, 2012, under Work and stuff
The post is from the stand point of RHEL hypervisor with a KVM CentOS Linux guest using a raw image file as a backing store and the openssl package, but it could easily be applied to different distros, backing stores, or even booting a Linux livecd as long as you can get the necessary packages. Some steps may vary depending on what kind of backing store you are using for the image and the partitions your OS is installed. This process could also be used to do many other things like increasing the time for password expirations.
First mount the image as a loopback device:
$ sudo losetup /dev/loop0 /var/lib/libvirt/images/virtcort011ccxra.img # note that is a zero at the end of /dev/loop
Next add the partition mappings:
$ sudo kpartx -av /dev/loop0
In my CentOS installation I was using LVM and the next few steps are LVM specific:
Use vgscan to find the LVM volume
$ sudo vgscan
This located the new LVM volume group VolGroup00 # again note that is zero zer at the end of VolGroup. You will use this group in the next step.
Activate LVM Volume Group:
$ sudo vgchange -ay VolGroup00
You can use lvs to find the Volume where your / (root) file system is mounted:
$ sudo lvs
Next mount the volume:
$ sudo mount /dev/VolGroup00/LogVol00 /mnt/linuxrescue
You should be able to see directories in the volume:
$ ls /mnt/linuxrescue
Now generate the new password for the guest:
$ openssl passwd -1 -salt ranNum # for the salt substitute random numbers and letters for ranNum.
Password:
$1$ranNum$N6s5hhYltlYQPnMDdxYy1 # you can see your salt + hash
Now copy this string into /etc/shadow:
$ sudo vi /mnt/linuxrescue/etc/shadow
In editing your shadow file you will see something like below your salt+hash should be substituted as below for the user password you would like to reset.
root:$1$ranNum$N6s5hhYltlYQPnMDdxYy1:15492:1:90:7:::
If you want to change the length of time for password expirations the next step will show you how.
$ sudo vi /etc/login.defs # find the value PASS_MAX_DAYS and edit it to your needs
Now unmount the file system:
$ sudo umount /mnt/linuxrescue
Unactivate the LVM vol group:
$ sudo vgchange -an VolGroup00
Delete the partition mappings:
$ sudo kpartx -dv /dev/loop0
Unmount the loopback device:
$ sudo kpartx -dv /dev/loop0
KVM:Reset Windows Guest Password
by jfargen on Dec.21, 2012, under Work and stuff
The post is from the stand point of RHEL hypervisor with a KVM Windows guest using a raw image file as a backing store using the package chntpw, but it could easily be applied to different distros, backing stores, or even booting a Linux livecd as long as you can install the chntpw package. Some steps may vary depending on what kind of backing store you are using for the image and where your Windows OS was installed.
First get the chntpw package:
$ sudo yum install chntpw
Print the logical loopback device:
$ sudo losetup -f
/dev/loopo
Next mount the image file as a loopback device:
$ sudo losetup /dev/loopo /var/lib/libvirt/images/windows7.raw
Add partition mappings:
$ sudo kpartx -av /dev/loop0 #That is a zero at the end of /dev/loop0
Create a directory that can be used as a mount point:
$ sudo mkdir -p /mnt/winrescue
Mount the appropriate filesystem:
$ sudo mount /dev/mapper/loop0p2 /mnt/winrescue
Change to the directory where the SAM db is located:
$ sudo cd /mnt/winrescue/Windows/System32/config/
Now run the chntpw utility:
$ sudo chntpw -I SAM
Once complete you will want to unmount the filesystem and loopback device.
Get out of the mounted filesystem:
$ cd ~
Umount the filesystem:
$ sudo umount /mnt/windowsrescue/
Delete the partition mappings:
$ sudo kpartx -dv /dev/loop0
Unmount the loopback device:
$ sudo losetup -d /dev/loop0
The process is now complete.