This guide will help you create a USB key that is capable of installing ClearOS. While other guides exist for creating a USB key for ClearOS installs, this one aims to be able to create the USB for ClearOS using ONLY an existing ClearOS system. Additionally this method uses GRUB instead of SYSLINUX.
<note warning>This guide is intended for ClearOS 6.5 and earlier and for ClearOS 6.7. ClearOS 6.6.0 and ClearOS 6.6.1 can be made into a USB through a much simpler process. Refer to this guide for 6.6.1</note>
<note warning>This guide requires using commands that can completely wipe your system if they are not executed properly. All commands listed are examples ONLY. On your system, they may reference drives that are currently in production. Please double check all of the commands that you enter to ensure that they are executed against your USB drive and NOT your hard drive. It is highly recommended that you do NOT perform this howto from a production system.</note>
This method requires a working ClearOS server an available USB port and a USB drive that you are willing to completely erase. You will also need to enter to a command prompt. You can do this by pressing Ctrl+Alt+F2 at the console or by using SSH.
Insert your USB device into your server. It should be automatically detected and the default behavior or ClearOS is to NOT mount it. To find your USB drive, type the following from the command prompt:
The 'l' switch in fdisk 'lists' all your hard drives (including your USB drive). Your output may look like this:
Disk /dev/hda: 8012 MB, 8012390400 bytes 240 heads, 61 sectors/track, 1068 cylinders Units = cylinders of 14640 * 512 = 7495680 bytes Device Boot Start End Blocks Id System /dev/hda1 * 1 334 2439453+ 83 Linux Disk /dev/sda: 2000.3 GB, 2000398934016 bytes 255 heads, 63 sectors/track, 243201 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sda1 * 1 15 120456 fd Linux raid autodetect /dev/sda2 16 7664 61440592+ fd Linux raid autodetect /dev/sda3 7665 243201 1891950952+ fd Linux raid autodetect Disk /dev/md2: 62.9 GB, 62915084288 bytes 2 heads, 4 sectors/track, 15360128 cylinders Units = cylinders of 8 * 512 = 4096 bytes Disk /dev/md2 doesn't contain a valid partition table Disk /dev/md3: 1937.3 GB, 1937357668352 bytes 2 heads, 4 sectors/track, 472987712 cylinders Units = cylinders of 8 * 512 = 4096 bytes Disk /dev/md3 doesn't contain a valid partition table Disk /dev/md1: 123 MB, 123273216 bytes 2 heads, 4 sectors/track, 30096 cylinders Units = cylinders of 8 * 512 = 4096 bytes Disk /dev/md1 doesn't contain a valid partition table Disk /dev/sdb: 8004 MB, 8004304896 bytes 240 heads, 61 sectors/track, 1067 cylinders Units = cylinders of 14640 * 512 = 7495680 bytes Device Boot Start End Blocks Id System /dev/sdb1 * 1 334 2439453+ 83 Linux
I know that my USB drive is 8GB in size. I also have a motherboard that has a compact flash. USB devices ALWAYS show up as SCSI disks so I know that my USB drive must be /dev/sdb and not /dev/hda. Here I can also see my main disk /dev/sda. I need to be very careful not to issue any commands against my running hard disk. On your system, you USB drive may NOT be /dev/sdb but some other drive further down in the alphabet.
One way to confirm the drive name is to run the following command immediately after inserting your USB device:
You may see some chatter similar to this:
usb-storage: device scan complete scsi 4:0:0:0: Direct-Access SanDisk Cruzer Fit 1.22 PQ: 0 ANSI: 5 sd 4:0:0:0: Attached scsi generic sg2 type 0 sd 4:0:0:0: [sdc] 15633408 512-byte logical blocks: (8.00 GB/7.45 GiB) sd 4:0:0:0: [sdc] Write Protect is off sd 4:0:0:0: [sdc] Mode Sense: 43 00 00 00 sd 4:0:0:0: [sdc] Assuming drive cache: write through sd 4:0:0:0: [sdc] Assuming drive cache: write through sdc: sdc1 sd 4:0:0:0: [sdc] Assuming drive cache: write through sd 4:0:0:0: [sdc] Attached SCSI removable disk
Such a message would indicate that your device is '/dev/sdc'
The last thing to do is to ensure that no subsystem has automatically detected and mounted your USB device. Using the name you discovered for your USB device run the following (in this example, our device is /dev/sdb):
mount | grep /dev/sdb
If your device is NOT mounted, it will simply return to the next command prompt:
[root@system ~]# mount | grep /dev/sdb [root@system ~]#
Next we will partition and format your drive. You can use any method for this or perhaps you are using a disk that has already been prepared. For the purpose of this section, we will use 'cfdisk' to format a disk.
Run the following to set up your disk using cfdisk (please note, the instructions show /dev/sdb but the images show sdc, please disregard the sdc in the images)
Choose 'New' to create a new partition.
Choose 'Primary' to make this partition the primary partition on this disk. Use the default size or you can make is smaller. It must be about 1100 MB or more in size.
Choose 'Bootable' to make this disk bootable. The screen will not change below but it will now say 'Boot' in the Flags section.
Choose 'Write' to affect these changes to the disk. It will ask you to confirm the change because this will basically destroy any data on this disk so make absolutely sure that this is your USB drive and NOT your main hard drive. Type 'yes' and then hit Enter.
Choose 'Quit' to complete the process and continue.
After you have created a partition with 'cfdisk' or another utility, you will need to format the partition. We will use an ext4 partition but you can use ext3 or even ext2 for this purpose. If your disk is /dev/sdc, you would run the following command:
You will get output similar to this:
mke2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 488640 inodes, 1954168 blocks 97708 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2004877312 60 block groups 32768 blocks per group, 32768 fragments per group 8144 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 38 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
We will want to give the USB drive a name, this will be useful later:
tune2fs -L ClearOS-Install /dev/sdb1 && tune2fs -l /dev/sdb1 |grep "volume name"
You should get output similar to this if it worked:
tune2fs 1.41.12 (17-May-2010) Filesystem volume name: ClearOS-Install
With the USB formatted, we will want to create some directories, mount the device and copy files to it.
mkdir /mnt/usb mount /dev/sdb1 /mnt/usb/ grub-install --no-floppy --root-directory=/mnt/usb /dev/sdb
You should get output that is similar to this which says:
Probing devices to guess BIOS drives. This may take a long time. Installation finished. No error reported. This is the contents of the device map /mnt/usb/boot/grub/device.map. Check if this is correct or not. If any of the lines is incorrect, fix it and re-run the script `grub-install'. (hd0) /dev/sda (hd1) /dev/sdb
Since we will use this as our 'boot' drive eventually on a different box, we need to modify the boot map. Perform the following:
echo "(hd0) /dev/sda" > /mnt/usb/boot/grub/device.map cat /mnt/usb/boot/grub/device.map
It should respond with the following:
Next, we need to populate the USB drive with the installation files. Perform the following:
mkdir /mnt/usb/os cd /mnt/usb/os yum -y install wget wget http://mirror.clearsdn.com/clearos/professional/6.4.0/iso/x86_64/clearos-professional-6.4.0-x86_64-netinstall.iso wget http://images.clearsdn.com/clearos-images/professional/6.4.0/images/iso/x86_64/clearos-professional-6.4.0sp1-x86_64.iso ln -s clearos-professional-6.4.0sp1-x86_64.iso clearos-professional-x86_64.iso
Next, we need to extract some installation files from the ISO image:
mkdir /mnt/iso mount -o loop /mnt/usb/os/clearos-professional-6.4.0-x86_64.iso /mnt/iso mkdir /mnt/usb/os/images/ cp /mnt/iso/images/install.img /mnt/usb/os/images/ cp /mnt/iso/images/product.img /mnt/usb/os/images/ cp /mnt/iso/images/updates.img /mnt/usb/os/images/ cp /mnt/iso/isolinux/vmlinuz /mnt/usb/boot/ cp /mnt/iso/isolinux/initrd.img /mnt/usb/boot/
Lastly, we will make a boot menu for our GRUB from which we will do the install. Using your favorite editor, modify the /mnt/usb/boot/grub/grub.conf file.
Populate this file with the following data:
default 0 timeout 5 # ClearOS Install title ClearOS Install root (hd0,0) kernel /boot/vmlinuz repo=hd:LABEL="ClearOS-Install":/os ks=hd:LABEL="ClearOS-Install":/os initrd /boot/initrd.img
At this point, all things should be in place. Unmount the drives:
cd sync umount /mnt/iso umount /mnt/usb
Lastly, have fun installing ClearOS using USB!
If you run into the error “The file /mnt/usb/boot/grub/stage1 not read correctly.” while installing GRUB (grub-install –no-floppy –root-directory=/mnt/usb /dev/sdb), this could happen if you already have GRUB installed on the device. To blow away this GRUB, be absolutely sure that you are calling the right disk and perform the following:
dd if=/dev/zero of=/dev/sdb bs=512 count=5