...making Linux just a little more fun!
By Edgar Howell
For a brief period of time this office had been Windows-free, in theory at least. The combo printer requiring '95 had stopped using black ink and '95 had stopped booting, making both obsolete. And '98 on the old notebook doesn't shutdown properly, which turns booting into an adventure. Just hadn't quite got around to dumping all this junk.
Then fate sent a project my way that required some variety of Windows. The one tool I absolutely need I got familiar with many years ago under OS/2. Unfortunately it no longer exists in any such incarnation. So it was time to clench my teeth, say good-bye to dreams of a notebook completely unexposed to Windows and order a Dell with whatever is current from Redmond now-a-days.
We ordered the Dell with twice the hard-drive and 4 times the memory advertised, so we just reduce the partition a bit and put SuSE 10.0 on there and be up and running in nothing flat.
This is something I've done for years. One of my favorite commercial tools had been Partition Magic. Pretty easy to reduce a partition in size and use the free space for some other purpose.
But as Robert Burns put it: The best laid schemes o' Mice an' Men, Gang aft agley.
If in the past I have ever said anything nice about products from Redmond, I really do regret it. If anything, I have certainly been far too polite in just using words like "junk". There are other 4-letter and longer words far more suitable.
Consider: you buy a machine with one pre-installed operating system on an 80GB drive and cfdisk reports:
First Last # Type Sector Sector Offset Length File System Type (ID) Flags -- ------- ----------- ----------- ------ ----------- -------------------- ----- 1 Primary 0 176714 63 176715 Dell Utility (DE) none 2 Primary 176715 146544929 0 146368215 HPFS/NTFS (07) Boot Pri/Log 146544930 146560994 0 16065 free none 3 Primary 146560995 156296384 0 9735390 CP/M / CTOS / . (DB) none
Mount the 3 primary partitions and df shows:
Filesystem 1K-blocks Used Available Use% Mounted on [...] /UNIONFS/dev/sda1 88136 6654 81482 8% /mnt/sda1 /UNIONFS/dev/sda2 73184104 7132524 66051580 10% /mnt/sda2 /UNIONFS/dev/sda3 4858184 3167052 1691132 66% /mnt/sda3
Why is there more than one primary partition? The hardware architecture only supports 4, they're valuable! None is particularly full. And that gap in the middle?! Can we spell "fragmentation"? Define it?
Maybe people living in the wild and wooly world of Windows are used to things like this and don't consider it fraudulent when deprived of about 14GB out of 80. But to have that much real estate taken away without even asking!? Consider the percentage if I hadn't chosen a drive twice the size of normal.
Is there any need to point out the bizarre file system types? And I don't do NTFS!
But it gets better, or worse. Back in '95 days, you got a CD with the operating system, probably also pre-installed on the machine.
With '98 the system was pre-installed and you got a so-called "Recovery CD" along with it. At some point in time you were forced to use the infernal thing and that was when you learned that it wouldn't just restore the operating system but would return the entire partition to the status it had originally had when the machine left the manufacturer.
Like good-bye data if you don't have adequate back-ups and/or another bootable partition (this was long before Knoppix). But if you modified the partition size in order to install something else as well, the "Recovery CD" fails — after it has formatted the partition it can't use! And the last Partition Magic I bought couldn't help because instead of running under DOS it required Windows. A perverse Catch-22. Been there, done that, wore out the T-shirt.
But at least you had a CD with the system software on it.
Dell/Microsoft didn't even provide one! Just how expensive are CD-ROMs today? In bulk?
That's what those other partitions are all about. In other words it is impossible to do something simple like format the drive, allocate partitions, and install software. So now what?!
In spite of having used other fine tools in the past to work through problems, Knoppix has become my toolbox of choice because it gives me an environment I am familiar with, GNU/Linux, and lots and lots of tools.
Of course the first thing I did — after minimal setup, as little as possible — was to change the boot sequence on the notebook to enable using Knoppix. I had to know how to do this (F2, DEL early in the boot process are good candidates): other than one large piece of paper (roughly 2-times legal-size) describing the external features of the hardware, Dell included no significant printed documentation. It's all on the hard-drive.
Above, you have already seen some of the information available from use of the tools on the Knoppix CD/DVD. By the way, here I am using a DVD with Knoppix 4.0.
So far all we have been able to do is to confirm that we have a major problem. Bizarre HD configuration. Unfamiliar file system.
So let's see what tools Klaus Knopper included in his toolbox:
knoppix@3[knoppix]$ apropos NTFS libntfs-gnomevfs (8) - Module for GNOME VFS that allows access to NTFS filesystems. mkntfs (8) - create a NTFS 1.2 (Windows NT/2000/XP) file system ntfscat (8) - concatenate files and print them on the standard output ntfsclone (8) - Efficiently clone, image or restore an NTFS filesystem ntfscluster (8) - identify files in a specified region of an NTFS volume. ntfsfix (8) - tool for fixing NTFS partitions altered by the Linux kernel NTFS driver. ntfsinfo (8) - dump a file's attributes ntfslabel (8) - display/change the label on an ntfs file system ntfsls (8) - list directory contents on an NTFS filesystem ntfsprogs (8) - several tools for doing neat things with NTFS partitions ntfsresize (8) - resize an NTFS filesystem without data loss ntfsundelete (8) - recover a deleted file from an NTFS volume. smbcquotas (1) - Set or get QUOTAs of NTFS 5 shares knoppix@3[knoppix]$
From looking at a couple of the man pages it would seem that this collection of tools has been around for 10 years or so, well beyond release 0.0 by now.
So let's use ntfsclone to push an image of the bootable partition over the LAN onto another machine. Once we have that as back-up we can use ntfsresize to shrink the partition down to something reasonable. After that it should be easy enough to create an extended partition with a couple of logical partitions for Linux.
I'm not at all familiar with these tools but it is always fun to learn something new. And the time is right.
Again, nothing ever quite works the way one expects. Making the image was no exception. Here is one of the unsuccessful attempts:
knoppix@3[knoppix]$ su root@3[knoppix]# ntfsclone --save-image --output - /dev/sda2 | gzip -c | \ ssh -l web lohgopc2 'cat > /DATA/NO_BACKUP/DELL/sda2.img.gz' ntfsclone v1.9.4 The authenticity of host 'lohgopc2 (192.168.0.102)' can't be established. RSA key fingerprint is 65:32:cc:81:8f:eb:73:24:7b:b3:18:a8:66:fa:7c:ae. Are you sure you want to continue connecting (yes/no)? NTFS volume version: 3.1 Cluster size : 4096 bytes Current volume size: 74940522496 bytes (74941 MB) Current device size: 74940526080 bytes (74941 MB) Scanning volume ... 100.00 percent completed Accounting clusters ... Space in use : 7304 MB (9,7%) Saving NTFS to image ... root@3[knoppix]#
After "Saving NTFS to image ..." nothing further happened and I had to cancel with CTRL-C.
Here is what finally worked:
knoppix@1[knoppix]$ su sudo: unable to lookup Knoppix via gethostbyname() root@1[knoppix]# ntfsclone --save-image --output - /dev/sda2 | gzip -c | \ ssh -l web lohgopc2 'cat > /DATA/NO_BACKUP/DELL/sda2.img.gz' ntfsclone v1.9.4 Password: NTFS volume version: 3.1 Cluster size : 4096 bytes Current volume size: 74940522496 bytes (74941 MB) Current device size: 74940526080 bytes (74941 MB) Scanning volume ... 100.00 percent completed Accounting clusters ... Space in use : 7304 MB (9,7%) Saving NTFS to image ... Warning: No xauth data; using fake authentication data for X11 forwarding. 100.00 percent completed Syncing ... root@1[knoppix]#
Other than the obvious difference between success and failure, from a quick glance at the output it isn't clear why one worked and one didn't. But look at the lines ending in "NTFS volume version: 3.1".
On the unsuccessful attempt I had failed to note that ssh wanted confirmation that it was OK to establish a connection with the other machine. It was patiently waiting for me to enter "yes" while I was scratching my head trying to figure out why nothing was happening!
Success the next morning — a good night's sleep can do a world of good — didn't include that question because I had already told ssh that it was OK and it had "permanently" (until next boot with Knoppix) recorded this fact. Refreshed and thinking clearly, I remembered that the password was needed and saw the request from ssh.
Now that our safety-net was in place the first thing to do was to check out the partition:
knoppix@4[knoppix]$ sudo ntfsresize --info /dev/sda2 sudo: unable to lookup Knoppix via gethostbyname() ntfsresize v1.9.4 NTFS volume version: 3.1 Cluster size : 4096 bytes Current volume size: 74940523008 bytes (74941 MB) Current device size: 74940526080 bytes (74941 MB) Checking filesystem consistency ... 100.00 percent completed Accounting clusters ... Space in use : 7304 MB (9,7%) Collecting shrinkage constrains ... Estimating smallest shrunken size supported ... File feature Last used at By inode $MFT : 16790 MB 0 Multi-Record : 8393 MB 9 You might resize at 7303708672 bytes or 7304 MB (freeing 67637 MB). Please make a test run using both the -n and -s options before real resizing! knoppix@4[knoppix]$
Rather than reducing the partition as far as possible, let's follow that advice and see what it looks like if we leave some room for data and the tool that has yet to be installed:
root@0[knoppix]# ntfsresize --no-action --size 10G /dev/sda2 ntfsresize v1.9.4 NTFS volume version: 3.1 Cluster size : 4096 bytes Current volume size: 74940523008 bytes (74941 MB) Current device size: 74940526080 bytes (74941 MB) New volume size : 9999995392 bytes (10000 MB) Checking filesystem consistency ... 100.00 percent completed Accounting clusters ... Space in use : 7304 MB (9,7%) Collecting shrinkage constrains ... Needed relocations : 395906 (1622 MB) Schedule chkdsk for NTFS consistency check at Windows boot time ... Resetting $LogFile ... (this might take a while) Relocating needed data ... 100.00 percent completed Updating $BadClust file ... Updating $Bitmap file ... Updating Boot record ... The read-only test run ended successfully.
OK, go for it.
root@0[knoppix]# ntfsresize --size 10G /dev/sda2 ntfsresize v1.9.4 NTFS volume version: 3.1 Cluster size : 4096 bytes Current volume size: 74940523008 bytes (74941 MB) Current device size: 74940526080 bytes (74941 MB) New volume size : 9999995392 bytes (10000 MB) Checking filesystem consistency ... 100.00 percent completed Accounting clusters ... Space in use : 7304 MB (9,7%) Collecting shrinkage constrains ... Needed relocations : 395906 (1622 MB) WARNING: Every sanity check passed and only the DANGEROUS operations left. Please make sure all your important data had been backed up in case of an unexpected failure! Are you sure you want to proceed (y/[n])? y Schedule chkdsk for NTFS consistency check at Windows boot time ... Resetting $LogFile ... (this might take a while) Relocating needed data ... 100.00 percent completed Updating $BadClust file ... Updating $Bitmap file ... Updating Boot record ... Syncing device ... Successfully resized NTFS on device '/dev/sda2'. You can go on to shrink the device e.g. with 'fdisk'. IMPORTANT: When recreating the partition, make sure you 1) create it with the same starting disk cylinder 2) create it with the same partition type (usually 7, HPFS/NTFS) 3) do not make it smaller than the new NTFS filesystem size 4) set the bootable flag for the partition if it existed before Otherwise you may lose your data or can't boot your computer from the disk! root@0[knoppix]#
Now that we have reduced the size of the area used within the physical partition (comparable to de-frag under Windows, maybe) it is safe to use cfdisk /dev/sda
Festplatte: /dev/sda Größe: 80026361856 Bytes, 80,0 GB Köpfe: 255 Sektoren pro Spur: 63 Zylinder: 9729 Name Flags Part. Typ Dateisystemtyp [Bezeichner] Größe (MB) --------------------------------------------------------------------------------------- sda1 Primäre Dell Utility 90,48 sda2 Boot Primäre NTFS [] 10001,95 sda5 Logische Linux ext2 10010,17 sda6 Logische Linux 10001,95 Logische Freier Bereich 14928,89 sda7 Logische FAT16 10001,95 sda8 Logische Linux swap / Solaris 20003,89 sda3 Primäre CP/M / CTOS / ... 4984,52 [ Bootbar] [Löschen ] [ Hilfe ] [ Maxim. ] [Ausgabe ] [ Ende ] [ Typ ] [Einheit.] [Schreib.]
This was the step where extreme care was called for. A mistake with ntfsresize produces an error message or warning. To me the partition table is comparable to the base register in some assembler languages: something that cannot be verified, a promise, not a guarantee. Mess it up and you may never be able to recover. Pay very close attention to the changes you make and back out if there is anything at all that you don't fully understand!
Once again, in the white hat, Linux wins! The backup was unneeded, although I never would have continued without one.
When booted into Windows, it did whatever it is that it does while it is doing what it does when one doesn't know what it is doing. So that worked. I guess.
Creating the extended partition and a couple of logical partitions inside it is quite straight-forward and doesn't deserve further discussion here. Although I grew up with fdisk, I will repeat the recommendation in the documentation to use cfdisk instead. Interactive and keeping one apprised of current status, it was very easy to get used to.
In retrospect it wasn't necessary to jump back and forth between normal user and root as in the cut-and-paste from screens, above. But there is a time and place for each. On more than one occasion I have failed to notice that I had returned to a virtual terminal with root privileges. Bad! The preferred idiom with Knoppix is "sudo". You won't need a root password but it keeps you aware of where you are and what you are doing.
After having gone through this exercise it occurred to me that a better long-term solution might be to back up the Windows partition as described after major changes, i.e. installation of the tool I need. The other two as well of course, just in case something goes wrong. And then when the time comes that the Windows partition becomes unusable and restoring is necessary, just do it from the network. That should make those other two partitions obsolete and recover a bunch of disk space. Way down the road.
The modem is presumably one of those nefarious "winmodems". I didn't check it out, ISDN currently, not analog. The network card works without problem. And the Kensington Mouse at the USB port was recognized by Knoppix off the starting blocks. It is really neat, the cable winds up into it, to the length needed, from 0 to whatever. I may even take it along when on the road.
The Dell hardware is actually very nice. If you could just get it without having to pay for an operating system you normally don't need...
Edgar is a consultant in the Cologne/Bonn area in Germany.
His day job involves helping a customer with payroll, maintaining
ancient IBM Assembler programs, some occasional COBOL, and
otherwise using QMF, PL/1 and DB/2 under MVS.
(Note: mail that does not contain "linuxgazette" in the subject will be
rejected.)