Bash scripting is great. Here is a quick trick to funnel a series of numbers (or letters) into a variable, and thus an argument of a script:
#!/bin/bash
for a in {1..18}
do
echo "The number $a"
done
#!/bin/bash
for a in {a..z}
do
echo " The letter $a "
done
Here is another example:
for a in {0..15}; do /usr/sbin/xm vcpu-pin 0 $a 0-1,4-15; done
Such a quick and easy trick!
This is a repository of all of my Linux/Unix writings as well as useful tips and tricks for systems administration, engineering, and programming.
Showing posts with label Xen. Show all posts
Showing posts with label Xen. Show all posts
Wednesday, November 17, 2010
Friday, July 16, 2010
Create huge files fast with dd
Here is a quick way to create very large empty files without writing every byte using dd.
# dd if=/dev/zero of=largeemptyfile.img bs=1M count=1 seek=16999
1+0 records in
1+0 records out
1048576 bytes (1.0 MB) copied, 0.001772 seconds, 592 MB/s
# ls -lh
total 1.1M
-rw-r--r-- 1 root root 17G Jul 16 09:07 largeemptyfile.img
# du -h
1.1M .
Notice that the actual file is only 1.1 MB, but the file shows as 17GB. This is because dd basically wrote the first and last parts of the file, and left the middle alone. You can now use this file for anything, such as a Xen disk image. Once it is in use, it will report as the full 17GB with du.
# dd if=/dev/zero of=largeemptyfile.img bs=1M count=1 seek=16999
1+0 records in
1+0 records out
1048576 bytes (1.0 MB) copied, 0.001772 seconds, 592 MB/s
# ls -lh
total 1.1M
-rw-r--r-- 1 root root 17G Jul 16 09:07 largeemptyfile.img
# du -h
1.1M .
Notice that the actual file is only 1.1 MB, but the file shows as 17GB. This is because dd basically wrote the first and last parts of the file, and left the middle alone. You can now use this file for anything, such as a Xen disk image. Once it is in use, it will report as the full 17GB with du.
Wednesday, December 30, 2009
Sample Linux interview questions
I have compiled some sample interview questions for use in testing a potential systems administrator or systems engineer. I have created most of them but have reused some of them from the recent interviews that I have had. It should be one way to separate candidates as well as prepare others for interviews.
Sample questions:
What is a way to find the current running kernel version level?
Various iterations of the uname command (uname -a or uname -r)
How do you update the system on Red Hat 4? Red Hat 5?
up2date -u (RHEL 4) and yum update (RHEL 5)
What is a way to see what service pack and version the Red Hat system is at? CentOS?
cat /etc/redhat-release (Same for both RHEL and CentOS)
What is a way to change a kernel parameter?
sysctl -w parameter=value (persistent)
or
echo 32768 > /proc/sys/fs/file-max (not reboot persistent)
or
change a kernel parameter in /boot/grub/menu.lst as such:
kernel /boot/vmlinuz-2.6.18-128.1.16.el5 ro root=LABEL=/ elevator=deadline (persistent)
or
change the parameter in /etc/sysctl.conf (persistent)
You have a 32 bit system but want to allow RHEL to be able to use more than 4GB of RAM. What kernel do you use to accomplish this task?
Install and boot into the PAE kernel.
Of these filesystems--XFS, EXT3, EXT4, reiserFS, what is the best for large files?
XFS
Of these filesystems--XFS, EXT3, EXT4, reiserFS, what is the best for small files?
reiserFS
Of these filesystems--XFS, EXT3, EXT4, reiserFS, which ones are supported as of RHEL 5.3?
EXT3 and EXT4 (technology preview)
What has Microsoft contributed to the Linux kernel (trivia)?
A kernel module which enabled better performance with its Hyper-V virtualization technology.
You have tried to install an RPM but it has failed because of broken dependencies. How do you override and force the installation anyway?
rpm -i myprogram.rpm --nodeps
How do you set the maximum interval between fsck checks on /dev/sda1 to be one week?
tune2fs -i 1w /dev/sda1
Define dom0 and domU.
dom0 (domain zero) is the server running the Xen, KVM, or QEMU hypervisor. domU (domain unprivileged) is a virtual machine within a Xen, KVM, or QEMU server.
By default, what is the first disk known as within a VMWare virtual machine?
/dev/sda
By default, what is the first disk known as within a Xen domU?
/dev/xvda
Hope this is helpful.
Sample questions:
What is a way to find the current running kernel version level?
Various iterations of the uname command (uname -a or uname -r)
How do you update the system on Red Hat 4? Red Hat 5?
up2date -u (RHEL 4) and yum update (RHEL 5)
What is a way to see what service pack and version the Red Hat system is at? CentOS?
cat /etc/redhat-release (Same for both RHEL and CentOS)
What is a way to change a kernel parameter?
sysctl -w parameter=value (persistent)
or
echo 32768 > /proc/sys/fs/file-max (not reboot persistent)
or
change a kernel parameter in /boot/grub/menu.lst as such:
kernel /boot/vmlinuz-2.6.18-128.1.16.el5 ro root=LABEL=/ elevator=deadline (persistent)
or
change the parameter in /etc/sysctl.conf (persistent)
You have a 32 bit system but want to allow RHEL to be able to use more than 4GB of RAM. What kernel do you use to accomplish this task?
Install and boot into the PAE kernel.
Of these filesystems--XFS, EXT3, EXT4, reiserFS, what is the best for large files?
XFS
Of these filesystems--XFS, EXT3, EXT4, reiserFS, what is the best for small files?
reiserFS
Of these filesystems--XFS, EXT3, EXT4, reiserFS, which ones are supported as of RHEL 5.3?
EXT3 and EXT4 (technology preview)
What has Microsoft contributed to the Linux kernel (trivia)?
A kernel module which enabled better performance with its Hyper-V virtualization technology.
You have tried to install an RPM but it has failed because of broken dependencies. How do you override and force the installation anyway?
rpm -i myprogram.rpm --nodeps
How do you set the maximum interval between fsck checks on /dev/sda1 to be one week?
tune2fs -i 1w /dev/sda1
Define dom0 and domU.
dom0 (domain zero) is the server running the Xen, KVM, or QEMU hypervisor. domU (domain unprivileged) is a virtual machine within a Xen, KVM, or QEMU server.
By default, what is the first disk known as within a VMWare virtual machine?
/dev/sda
By default, what is the first disk known as within a Xen domU?
/dev/xvda
Hope this is helpful.
Thursday, September 24, 2009
Clone a virtual domU with virt-clone
Here is a simple way to clone a virtual image created with KVM, Xen, QEMU or others.
#virt-clone -o oldDomU -n newDomU -f /var/lib/xen/images/newDomU.img
You can them use xm list to see the new virtual machine:
#xm list
Name ID Mem(MiB) VCPUs State Time(s)
Domain-0 0 1985 8 r----- 10566.8
oldDomU 1 999 1 -b---- 191.0
newDomU 2 999 1 -b---- 138.7
#virt-clone -o oldDomU -n newDomU -f /var/lib/xen/images/newDomU.img
You can them use xm list to see the new virtual machine:
#xm list
Name ID Mem(MiB) VCPUs State Time(s)
Domain-0 0 1985 8 r----- 10566.8
oldDomU 1 999 1 -b---- 191.0
newDomU 2 999 1 -b---- 138.7
Subscribe to:
Posts (Atom)