20141014-1 选题

This commit is contained in:
DeadFire 2014-10-14 14:18:06 +08:00
parent c5d545188f
commit 617f59c430
6 changed files with 505 additions and 0 deletions

View File

@ -0,0 +1,79 @@
Linux FAQs with Answers--How to burn an ISO or NRG image to a DVD from the command line on Linux
================================================================================
> **Question**: I need to burn an image file (.iso or .nrg) to a DVD using a DVD writer on my Linux box. Is there a quick and easy way, preferably using a command-line utility, to burn an .iso or .nrg image to a DVD?
The two most popular formats for image files are ISO (.iso file extension) and NRG (.nrg file extension). The ISO format is a global standard created by ISO (International Organization for Standardization), and therefore is supported natively by most operating systems, allowing a high level of portability. On the other hand, the NRG format is a proprietary format developed by Nero AG, a very popular disc imaging and burning software firm.
Here is how to burn an .iso or .nrg image to a DVD from the command line on Linux.
### Convert an NRG Image to ISO Format ###
Due to ISO's widespread adoption, burning an .iso image to CD/DVD is straightforward. However, burning an .nrg image requires converting the image to .iso format first.
To convert an .nrg image file to .iso format, you can use nrg2iso, an open source program that converts images created by Nero Burning Rom to standard .iso (ISO9660) files.
To install **nrg2iso** on Debian and derivatives:
# aptitude install nrg2iso
To install **nrg2iso** on Red Hat-based distros:
# yum install nrg2iso
On CentOS/RHEL, you need to enable [Repoforge repository][1] before running **yum**.
Once the nrg2iso package has been installed, use the following command to convert an .nrg image file to .iso format:
# nrg2iso filename.nrg filename.iso
![](https://farm3.staticflickr.com/2945/15507409981_99eddd2577_z.jpg)
When conversion is complete, an .iso file will appear inside the current working directory:
![](https://farm4.staticflickr.com/3945/15323823510_c933d7710f_z.jpg)
### Burn an .ISO Image File to a DVD ###
In order to burn an .iso image file to a DVD, we will use a tool called **growisofs**:
# growisofs -dvd-compat -speed=4 -Z /dev/dvd1=WindowsXPProfessionalSP3Original.iso
In the above command-line, the "-dvd-compat" option provides maximum media compatibility with DVD-ROM/-Video. In write-once DVD+R or DVD-R context, this results in unappendable recording (closed disk).
The "-Z /dev/dvd1=filename.iso" option indicates that we burn the .iso file to the media found in the selected device (/dev/dvd1).
The "-speed=N" parameter specifies a burning speed of a DVD burner, which is directly related to the capability of the drive itself. "-speed=8" will burn at 8x, "-speed=16" at 16x, and so on. Without this parameter, growisofs by default assumes the lowest speed available, which in this case happens to be 4x. You should choose the burning speed from the available speeds in your drive and the type of disks that you have.
You can find the device name of your DVD burner and its supported writing speed using [this tutorial][2]注此文在另一篇原文中20141014 Linux FAQs with Answers--How to detect DVD writer' s device name and its writing speed from the command line on Linux.md如果也翻译发布了可修改此链接.
![](https://farm3.staticflickr.com/2947/15510172352_5c09c2f495_z.jpg)
When the burning process has been completed, the disk should be automatically ejected from the tray.
### Check the Integrity of a Burned Media ###
At this point, you can check the integrity of the burned media by comparing the md5 checksum of the original .iso file with the same checksum of the burned DVD. If both are identical, you can rest assured that the burning was successful.
However, in case you have converted an .nrg image to .iso using nrg2iso, you need to be aware that nrg2iso creates an .iso file whose size is not a multiple of 2048 (as ordinary .iso files are). Thus, an ordinary comparison between the checksum of this .iso file and the contents of the burned media will differ.
On the other hand, if you have burned an .iso image that does not come from an .nrg file, you can use the following command to check the integrity of the data recorded in a DVD. Replace "/dev/dvd1" with your own device name.
# md5sum filename.iso; dd if=/dev/dvd1 bs=2048 count=$(($(stat -c "%s" filename.iso) / 2048)) | md5sum
The first part of the command (up to the semicolon) calculates the md5 checksum of the .iso file, while the second part reads the contents of the disk present in /dev/dvd1, and pipes them into the md5sum tool. "bs=2048" indicates that dd will use a block sector of 2048 bytes as many times as the size of the original iso file divided by 2048.
![](https://farm3.staticflickr.com/2949/15487396726_bcf47d536f_z.jpg)
If the two md5 checksum values are identical, it means that the burned media is valid.
--------------------------------------------------------------------------------
via: http://ask.xmodulo.com/burn-iso-nrg-image-dvd-command-line.html
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[1]:http://xmodulo.com/how-to-set-up-rpmforge-repoforge-repository-on-centos.html
[2]:http://ask.xmodulo.com/detect-dvd-writer-device-name-writing-speed-command-line-linux.html

View File

@ -0,0 +1,84 @@
Linux FAQs with Answers--How to change date and time from the command line on Linux
================================================================================
> **Question**: In Linux, how can I change date and time from the command line?
Keeping the date and time up-to-date in a Linux system is an important responsibility of every Linux user and system administrator. Many applications rely on accurate timing information to operate properly. Besides, inaccurate date and time render timestamp information in log files meaningless, diminishing their usefulness for system inspection and troubleshooting. For production systems, accurate date and time are even more critical. For example, the production in a retail company must be accounted precisely at all times (and stored in a database server) so that the finance department can calculate the expenses and net income of the day, current week, month, and year.
We must note that there are two kinds of clocks in a Linux machine: the software clock (aka system clock), which is maintained by the kernel, and the (battery-driven) hardware clock, which is used to keep track of time when the machine is powered down. During boot, the kernel sets the system clock to the same time as the hardware clock. Afterwards, both clocks run independent from each other.
### Method One: Date Command ###
In Linux, you can use the date command to change the date and time of your system:
# date --set='NEW_DATE'
where NEW_DATE is a mostly free format human readable date string such as "Sun, 28 Sep 2014 16:21:42" or "2014-09-29 16:21:42".
The date format can also be specified to obtain more accurate results:
# date +FORMAT --set='NEW_DATE'
For example:
# date +%Y%m%d %H%m --set='20140928 1518'
![](https://farm3.staticflickr.com/2944/15220890657_858528a186_o.png)
You can also increment or decrement date or time by a number of days, weeks, months or years, and seconds, minutes or hours, respectively. You may combine date and time parameters in one command as well.
# date --set='+5 minutes'
# date --set='-2 weeks'
# date --set='+3 months'
# date --set='-3 months +2 weeks -5 minutes'
![](https://farm3.staticflickr.com/2943/15220655239_deba528dce_o.png)
Finally, set the hardware clock to the current system time:
# hwclock --systohc
The purpose of running **hwclock --systohc** is to update the hardware clock with the software clock. This is to correct the systematic drift of the hardware clock, where it consistently gains or loses time at a certain rate.
On the other hand, if the hardware clock shows correct date and time, but the system clock does not, the latter can be updated as follows:
# hwclock --hctosys
In either case, hwclock command synchronizes both clocks. Otherwise, the time will be wrong after the next reboot, since the hardware clock keeps the time when power is turned off. However, keep in mind that this is not applicable to virtual machines, as they cannot access the hardware clock of the host machine directly.
If the default timezone is not correct on your Linux system, you can change it by following [this guideline][1].
### Method Two: NTP ###
Another way to keep your system's date and time accurate is using NTP (network time protocol). On Linux, ntpdate command can synchronize system clock against [public NTP servers][2] using NTP.
You can install **ntpdate** as follows:
On Debian and derivatives:
# aptitude install ntpdate
On Red Hat-based distributions:
# yum install ntpdate
To synchronize system clock using NTP:
# ntpdate -u <NTP server name or IP address>
# hwclock --systohc
![](https://farm4.staticflickr.com/3930/15404223021_8da3b44a62_z.jpg)
As opposed to one-time clock sync using ntpdate, you can also set up NTP daemon (ntpd) on your system, so that ntpd always runs in the background, continuously adjusting system clock via NTP. Refer to [this guideline][3] to set up **ntpd**.
--------------------------------------------------------------------------------
via: http://ask.xmodulo.com/change-date-time-command-line-linux.html
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[1]:http://ask.xmodulo.com/change-timezone-linux.html
[2]:http://www.pool.ntp.org/
[3]:http://xmodulo.com/how-to-synchronize-time-with-ntp.html

View File

@ -0,0 +1,90 @@
Linux FAQs with Answers--How to change default location of libvirt VM images
================================================================================
> **Question**: I am using libvirt and virt-manager to create VMs on my Linux system. I noticed that the VM images are stored in /var/lib/libvirt/images directory. Is there a way to change the default location of VM image directory to something else?
**libvirt** and its GUI front-end **virt-manager** can create and manage VMs using different hypervisors such as KVM and Xen. By default, all the VM images created via **libvirt** go to /var/lib/libvirt/images directory. However, this may not be desirable in some cases. For example, the disk partition where /var/lib/libvirt/images lives may have limited free space. Or you may want to store all VM images in a specific repository for management purposes.
In fact, you can easily change the default location of the libvirt image directory, or what they call a "storage pool."
There are two ways to change the default storage pool.
### Method One: Virt-Manager GUI ###
If you are using virt-manager GUI program, changing the default storage pool is very easy.
Go to "Edit" -> "Connection Details" in **virt-manager** menu GUI.
![](https://farm4.staticflickr.com/3935/15433062592_0d89a8d132_o.png)
You will see the default storage pool as shown below. On the left bottom of the window, click on the cross icon, which will stop the default storage pool. Once the pool is stopped, click on the trash bin icon on the right, which will delete the pool. Note that this action will NOT remove the VM images inside the pool.
Now click on the plus icon on the far left to add a new storage pool.
![](https://farm6.staticflickr.com/5600/15246703330_26884c8258_b.jpg)
Type in the name of a new storage pool (e.g., default), and choose the type of the pool. In this case, choose a "filesystem directory" type since we are simply changing a storage pool directory.
![](https://farm4.staticflickr.com/3928/15433416355_1a2f9f85ab_b.jpg)
Type in the path of a new storage pool (e.g., /storage).
![](https://farm6.staticflickr.com/5599/15433062732_195fa6701b_b.jpg)
At this point, the new storage pool should be started, and automatically used when you create a new VM.
![](https://farm4.staticflickr.com/3934/15430217721_b14c3a93fa_b.jpg)
### Method One: Virsh Command-Line ###
Another method to change the default storage pool directory is to use **virsh** command line utility which comes with **libvirt** package.
First, run the following command to dump XML definition of the default storage pool.
$ virsh pool-dumpxml default > pool.xml
Open this XML file with a text editor, and change <path> element from /var/lib/libvirt/images to a new location.
<pool type='dir'>
<name>default</name>
<uuid>0ec0e393-28a2-e975-feec-0c7356f38d08</uuid>
<capacity unit='bytes'>975762788352</capacity>
<allocation unit='bytes'>530052247552</allocation>
<available unit='bytes'>445710540800</available>
<source>
</source>
<target>
<path>/var/lib/libvirt/images</path>
<permissions>
<mode>0711</mode>
<owner>-1</owner>
<group>-1</group>
</permissions>
</target>
</pool>
Remove the current default pool.
$ virsh pool-destroy default
----------
Pool default destroyed
Now create a new storage pool based on the updated XML file.
$ virsh pool-create pool.xml
----------
Pool default created from pool.xml
At this point, a default pool has been changed to a new location, and is ready for use.
--------------------------------------------------------------------------------
via: http://ask.xmodulo.com/change-default-location-libvirt-vm-images.html
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出

View File

@ -0,0 +1,68 @@
Linux FAQs with Answers--How to create and mount an XFS file system on Linux
================================================================================
> **Question**: I heard good things about XFS, and would like to create an XFS file system on my disk partition. What are the Linux commands to format and mount an XFS file system?
[XFS][1] is a high-performance file system which was designed by SGI for their IRIX platform. Since XFS was ported to the Linux kernel in 2001, XFS has remained a preferred choice for many enterprise systems especially with massive amount of data, due to its [high performance][2], architectural scalability and robustness. For example, RHEL/CentOS 7 and Oracle Linux have adopted XFS as their default file system, and SUSE/openSUSE have long been an avid supporter of XFS.
XFS has a number of unique features that make it stand out among the file system crowd, such as scalable/parallel I/O, journaling for metadata operations, online defragmentation, suspend/resume I/O, delayed allocation for performance, etc.
If you want to create and mount an XFS file system on your Linux platform, here is how to do it.
### Install XFS System Utilities ###
First, you need to install XFS system utilities, which allow you to perform various XFS related administration tasks (e.g., format, [expand][3], repair, setting up quota, change parameters, etc).
On Debian, Ubuntu or Linux Mint:
$ sudo apt-get install xfsprogs
On Fedora, CentOS or RHEL:
$ sudo yum install xfsprogs
On Arch Linux:
$ sudo pacman -S xfsprogs
### Create an XFS-Formatted Disk Partition ###
Now let's first prepare a disk partition to create XFS on. Assuming that your disk is located at /dev/sdb, create a partition by:
$ sudo fdisk /dev/sdb
![](https://farm6.staticflickr.com/5604/15474273555_1c0c4be527_b.jpg)
Let's say the created partition is assigned /dev/sdb1 device name.
Next, format the partition as XFS using mkfs.xfs command. The "-f" option is needed if the partition has any other file system created on it, and you want to overwrite it.
$ sudo mkfs.xfs -f /dev/sdb1
![](https://farm4.staticflickr.com/3930/15287704767_fe5ded8ea1_b.jpg)
Now you are ready to mount the formatted partition. Let's assume that /storage is a local mount point for XFS. Go ahead and mount the partition by running:
$ sudo mount -t xfs /dev/sdb1 /storage
Verify that XFS mount is succesful by running:
$ df -Th /storage
![](https://farm4.staticflickr.com/3938/15474273445_aeacdca6eb_o.png)
If you want the XFS partition to be mounted at /storage automatically upon boot, add the following line to /etc/fstab.
/dev/sdb1 /storage xfs defaults 0 0
--------------------------------------------------------------------------------
via: http://ask.xmodulo.com/create-mount-xfs-file-system-linux.html
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[1]:http://xfs.org/
[2]:http://lwn.net/Articles/476263/
[3]:http://ask.xmodulo.com/expand-xfs-file-system.html

View File

@ -0,0 +1,109 @@
Linux FAQs with Answers--How to detect DVD writers device name and its writing speed from the command line on Linux
================================================================================
> **Question**: I want to know the device name assigned to my DVD writer, and also find out how fast I can burn a DVD using the DVD writer. What is a Linux command-line tool to detect the device name of a DVD writer and its writing speed?
Most consumer PCs and laptops nowadays come with a DVD writer. In Linux, optical drives such as CD/DVD drives are assigned device names by the kernel based on udev rules at the time of booting. There are several ways to detect the writer's device name and its writing speed.
### Method One ###
The simplest way to find out the device name associated with a DVD writer is to use dmesg command-line tool, which prints out the message buffer of the kernel. In dmesg output, look for a potential DVD writer:
$ dmesg | egrep -i --color 'dvd|cd/rw|writer'
![](https://farm6.staticflickr.com/5603/15505432622_0bfec51a8f_z.jpg)
The output of the above command will tell you whether a DVD writer is detected on your Linux system, and what the device name assigned to the writer is. In this example, the device name of a DVD writer is "/dev/sr0". This method does not tell you about writing speed, though.
### Method Two ###
The second method to get information about your DVD writer is to use lsscsi command, which simply lists all available SCSI devices.
To install **lsscsi** on Debian-based Linux:
$ sudo apt-get install lsscsi
To install lsscsi on Red Hat-based Linux:
$ sudo yum install lsscsi
The output of lsscsi command will tell you the name of a DVD writer if successfully detected:
$ lsscsi
![](https://farm4.staticflickr.com/3937/15319078780_e650d751d6.jpg)
This again does not tell you more details about the writer, such as writing speed.
### Method Three ###
The third method to obtain information about your DVD writer is to refer to /proc/sys/dev/cdrom/info.
$ cat /proc/sys/dev/cdrom/info
----------
CD-ROM information, Id: cdrom.c 3.20 2003/12/17
drive name: sr0
drive speed: 24
drive # of slots: 1
Can close tray: 1
Can open tray: 1
Can lock tray: 1
Can change speed: 1
Can select disk: 0
Can read multisession: 1
Can read MCN: 1
Reports media changed: 1
Can play audio: 1
Can write CD-R: 1
Can write CD-RW: 1
Can read DVD: 1
Can write DVD-R: 1
Can write DVD-RAM: 1
Can read MRW: 1
Can write MRW: 1
Can write RAM: 1
In this example, the output tells you that the DVD writer (/dev/sr0) is compatible with x24 CD writing speed (i.e., 24x153.6 KBps), which is equivalent to x3 DVD writing speed (i.e., 3x1385 KBps). The writing speed here is maximum possible speed, and actual writing speed of course depends on the type of media being used (e.g., DVD-RW, DVD+RW, DVD-RAM, etc).
### Method Four ###
Another way is to use a command-line utility called wodim. On most Linux distros, this tool, as well as its symbolic link cdrecord, is pre-installed by default.
# wodim -prcap
(or cdrecord -prcap)
![](https://farm6.staticflickr.com/5614/15505433532_4d7e47fc51_o.png)
When invoked without any argument, the wodim command automatically detects a DVD writer, and shows detailed capabilities and maximum read/write speed of the writer. For example, you can find out what media (e.g., CD-R, CD-RW, DVD-RW, DVD-ROM, DVD-R, DVD-RAM, audio CD) are supported by the writer, and what read/write speeds are available. The example output above shows that the DVD writer has maximum x24 writing speed for CDs and maximum x3 writing speed for DVDs.
Note that the writing speed reported by wodim command will automatically change depending on which CD/DVD media you insert to a DVD burner, reflecting the media specification.
### Method Five ###
A yet another way to check DVD burner's writing speed is a tool called dvd+rw-mediainfo, which is part of dvd+rw-tools package (toolchain for DVD+-RW/R media).
To install **dvd+rw-tools** on Debian-based distros:
$ sudo apt-get install dvd+rw-tools
To install dvd+rw-tools on Red Hat-based distros:
$ sudo yum install dvd+rw-tools
Unlike other tools, dvd+rw-mediainfo command will not produce any output unless you insert a DVD media to the burner. So after you insert a DVD media, run the following command. Replace "/dev/sr0" with your own device name.
$ sudo dvd+rw-mediainfo /dev/sr0
![](https://farm6.staticflickr.com/5597/15324137650_91dbf458ef_z.jpg)
The **dvd+rw-mediainfo** tool probes the inserted media ("DVD-R" in this example) to find out actual writing speed against the media.
--------------------------------------------------------------------------------
via: http://ask.xmodulo.com/detect-dvd-writer-device-name-writing-speed-command-line-linux.html
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出

View File

@ -0,0 +1,75 @@
Linux FAQs with Answers--How to detect and patch Shellshock vulnerability in bash
================================================================================
> **Question**: I would like to know how to test whether or not my Linux server is vulnerable to bash Shellshock bug, and how to protect my Linux server against the Shellshock exploit.
On September 24, 2014, a bash vulnerability nicknamed "Shellshock" (aka "Bashdoor" or "Bash bug") was discovered by a security researcher named Stephane Chazelas. This flaw, if exploited, allows a remote attacker to run arbitrary code by exporting function definitions inside specially crafted environment variables before calling the shell. Then the code inside these functions can get executed as soon as bash is invoked.
Note that Shellshock affects bash versions 1.14 through 4.3 (current), and although at the time of this writing no definitive and complete fix for this vulnerability has been found, and major Linux distributors ([Debian][1], [Red Hat][2], [CentOS][3], [Ubuntu][4], and [Novell/Suse][5]) have released patches that address the bugs related to it ([CVE-2014-6271][6] and [CVE-2014-7169][7]), and recommended updating bash as soon as possible, and continuing to check for updates over the next several days:
### Test for Shellshock Bug ###
To check if your Linux system is vulnerable to Shellshock bug, type the following command in a terminal.
$ env x='() { :;}; echo "Your bash version is vulnerable"' bash -c "echo This is a test"
上面代码中echo "Your bash version is vulnerable"一句在发布时刷成红色)
If your Linux system is exposed to Shellshock exploit, the output of the command will be:
Your bash version is vulnerable
This is a test
In the above command, an environment variable called x is made available to the user environment. It does not contain a value as we know it (but a dummy function definition) followed by an arbitrary command (in red)red这个词在发布时刷成红色, which will be executed before bash is called later on.
### Apply Fix for Shellshock Bug ###
You can install the newly released patch for bash as follows.
On Debian and derivatives:
# aptitude update && aptitude safe-upgrade bash
On Red Hat-based distributions:
# yum update bash
#### Before patch: ####
Debian:
![](https://farm4.staticflickr.com/3903/15342893796_0c3c61aa33_z.jpg)
CentOS:
![](https://farm3.staticflickr.com/2949/15362738261_99fa409e8b_z.jpg)
#### After patch: ####
Debian:
![](https://farm3.staticflickr.com/2944/15179388727_bdb8a09d62_z.jpg)
CentOS:
![](https://farm4.staticflickr.com/3884/15179149029_3219ce56ea_z.jpg)
Note that the version has not changed in each chosen distribution before and after installing the patch - but you can verify that it has been installed by observing the behavior of the update commands (most likely you will be asked beforehand in order to confirm the installation).
If for some reason you can't install the patch, or if your distribution has not yet released one, it is recommended to use another shell until a fix comes up.
--------------------------------------------------------------------------------
via: http://ask.xmodulo.com/detect-patch-shellshock-vulnerability-bash.html
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[1]:https://www.debian.org/security/2014/dsa-3032
[2]:https://access.redhat.com/articles/1200223
[3]:http://centosnow.blogspot.com.ar/2014/09/critical-bash-updates-for-centos-5.html
[4]:http://www.ubuntu.com/usn/usn-2362-1/
[5]:http://support.novell.com/security/cve/CVE-2014-6271.html
[6]:http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2014-6271
[7]:http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2014-7169