Clone Hard Drive to External USB Drive via CLI

Thumb and USB drives

No matter what OS you’re cloning, using “dd” via command line will still work.  I personally tested while cloning a 1TB Ubuntu hard drive to a fancy new 1TB SSD.

Backstory: I purchased a new Dell 7737 laptop with a 1TB hybrid drive, which turned out to be slower than watching paint dry compared to the old SSD I’d been using for a few years.  Otherwise it is a kickass laptop.  So I purchased a 1TB SSD after finding they are roughly 50 cents per GB these days…very affordable.

First I put the new SSD into USB caddy I had laying around for backup purposes.

Next I created a bootable USB stick with an Ubuntu ISO image following the instructions at:

Windows = http://www.ubuntu.com/download/desktop/create-a-usb-stick-on-windows
Ubuntu = http://www.ubuntu.com/download/desktop/create-a-usb-stick-on-ubuntu
MAC = http://www.ubuntu.com/download/desktop/create-a-usb-stick-on-mac-osx

With the USB stick created I booted the system to Ubuntu using the USB LiveCD disk image.  It may require a BIOS change to enable the PC/Laptop to boot from USB device.  Doing this will not make any changes to your current hard drive as long as “Install Ubuntu” is not chosen.

Once booted up I was able to use Gparted, which is a standard app on the LiveCD, to create a new partition table on the new drive in the external USB caddy.

I then used fdisk via command line to find all disks and gain their identifiers needed.

fdisk -l

With the new partition and the identifier of the USB drive I was now ready to initiate the copy.  I used the following command to do that:

dd if=/dev/sdc of=/dev/sdb mb=8M && sync

NOTE: ‘if’ = read from and ‘of’ = write to.

It takes a very long time for this to finish up, especially with larger drives, but the end result was a working drive with my data on it.

After completion I simply switched out the SSD from the caddy with the internal HD in the laptop and all worked well.

Good luck!

Ubuntu can mount ISO files, and IMG files after converting them to ISO

Today I needed to create an OEM Microsoft Office 2007 CD and found that I could download the disks directly from the Microsoft site. However, the files that I downloaded were in IMG format. At first I was puzzled, but quickly (via Google) found out that they were essentially ISO files. However, I did not quickly find anything in Ubuntu that would burn an IMG to disk.
Diligent searching finally revealed that while there were not really ways to burn an IMG to disk, or mount an IMG file directly, there is a tool called ccd2iso that converts the IMG to ISO format.

First I had to install the ccd2iso package via Synaptic package manager, or I could have used ‘sudo apt install ccd2iso’.

After installing this I could simply run the following command from terminal:

ccd2iso myfile.img myfile.iso

The same methods can be used for other image type files:
mdf2iso -> myfile.mdf
nrg2iso -> myfile.nrg

Now I have a regular iso file that can be used to serve our purposes by burning to disk or mounting:

sudo mount -o loop myfile.iso mountname
 
or
 
sudo mount -o loop -t iso9660 myfile.iso mountname

The .nrg files can also be mounted in this manner without converting to ISO by using:

sudo mount -o loop,offset=307200 myfile.nrg mountname

NOTE: if this doesn’t work and you get an error like: “Unrecognized sector mode (0) at sector 0!” it may be due to the limitations of the ccd2iso. In my case the MS Office disk had multiple sessions, and I could not convert it to ISO.

Another post I found on Ubuntuforums said to try the following:

growisofs -dvd-compat -Z /dev/dvdrw=dvd.img

Where /dev/dvdrw is your dvd/cd burner.

FOLLOWUP:
The IMG file I had from Microsoft was a multi-session disk so I was not able to use the steps above. However, when I simply changed the file extension to ‘.iso’ it worked fine. There seems to be very little difference between IMG and ISO.

Hard disk usage from command line on Linux

From the command line I have found many great tools for system management, but really needed to dig into ways of tracking hard disk usage on Linux without the aid of GUI tools. Google to the rescue! I found a few places with great tips and hints on how to do this, but one article on Linux.com came in very handy. Here were my findings:

The df utility displays the disk space usage on all mounted filesystems. The -T option prints the filesystem type as well. By default, df measures the size in 1K blocks, which could be a little difficult for a desktop user to decipher. Use the -h option to get more understandable output:

$ df -h -T
Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/hda6     ext3     20G  9.3G  9.1G  51% /
/dev/hda7 reiserfs     13G  2.1G   11G  17% /mnt/suse
/dev/sda1     vfat    241M  152M   90M  63% /media/usbdisk

You can use the du command to determine which files or directories need to be deleted — or at least trimmed. A simple du will print usage for the present working directory and its subdirectories, along with the size of each directory.

If you want the size of an particular directory, specify it with du directoryname. For instance, du -h /home/bodhi/podcasts will print the size of the podcasts directory in a more readable format than the kilobytes used by default. The -c option prints the grand total size of the directory at the end. The -a option also displays the file names along with directories and can be of use when you want to see a list of files in a particular directory. The -s option will display a summary, without showing all of the subdirectories.

Running du -ch | grep total prints just one line with the total size of the directory. If there’s a particular type of file that you would like to be excluded while calculating a directory’s usage, specify it with the --exclude=type option. Here we’ll check the disk usage of the current directory, and display all file names with their disk usage, and then sort them numerically using the sort utility:

$ du -ah | sort -n
4.2M    ./eweek.10.28.05.mp3
4.5M    ./LQ-Podcast-101105.mp3
4.8M    ./LQ-Podcast-110905.mp3
19M     ./LQRadio-Episode3.mp3
20M     ./LQRadio-Searls.mp3
36M     ./LQRadio-HiserAndAdelstein.mp3
197M    .

Ubuntu Hardy Heron sound broken

Recently I was having a consistent problem with the sound on my Dell Inspiron 1720, which is running on Ubuntu Hardy Heron. It would consistently stop working all together, and I had a terrible time finding the cause of the problem. If I viewed a flash video on the web, the sound would die afterwards. If I listened to streaming Internet radio, the sound would die. If I received an emial or IM the sound would die.

Finally it dawned on me, and I am not sure why or how. But a few weeks prior I had been toying with a Bluetooth stereo headset and had turned on the Audio service in the Bluetooth manager on the services tab.

Problem fixed: I simply turned off the Audio service in the Bluetooth manager, and all is working normally again. However, if I ever need the Audio service I suppose it will break my sound.

Headphone problem with Ubuntu 7.04 (Feisty Fawn)

I was having a sporadic problem with my headphone jack in my new Dell E1505 laptop that came pre-loaded with Ubuntu 7.04 (Feisty Fawn), using ALSA. The problem was that when I plugged in my headphones, sometimes they worked, and other times nothing happened. No sound from my headphones at all.

Here is how I fixed the sound in my Dell laptop…

Continue reading Headphone problem with Ubuntu 7.04 (Feisty Fawn)