Pre-requisites
- Host computer running arch and with grub installed
- Internet Connection ( for iso download )
- USB Flash Memory ( at least 10% bigger than the iso you want to use )
First we need to get the latest iso for the greatest Linux distro around, ArchLinux.
If version 8.0 had been released you can download it directly from
http://www.archlinux.org/download/
Today Feb 14 2007 the only way to get your grubby little hands on it is via the beta release
ftp://ftp.archlinux.org/other/0.8/
You may download the current, ftp or my personal favourite base,
It depends on the size of the flash key and any extra uses you might have planed for it.
Prepare
Plug your flash memory into any trusted, working and accessible usb port on your host computer.
Find out what device the flash was assigned.
$ dmesg | tail usb 1-3: new high speed USB device using ehci_hcd and address 4 usb 1-3: configuration #1 chosen from 1 choice scsi5 : SCSI emulation for USB Mass Storage devices usb-storage: device found at 4 scsi 5:0:0:0: Direct-Access Kingston DataTraveler 2.0 PMAP PQ: 0 ANSI: 0 CCS SCSI device sdb: 2015232 512-byte hdwr sectors (1032 MB) sdb: Write Protect is off sdb: Mode Sense: 23 00 00 00 sdb: assuming drive cache: write through sdb: sdb1 sd 5:0:0:0: Attached scsi removable disk sdb sd 5:0:0:0: Attached scsi generic sg2 type 0 usb-storage: device scan complete
In my case the device I will work with will be “sdb” as you can see from the output of the last command, but for safety we will call it “sdx“.
Now it’s time to get partitioning!
Partitioning
You have two choices
-
Double Mint
Two partitions - one for the install and the other for misc storage
- Pros:
- * You can keep things separate
- * VFAT: You can format the second partition in VFAT so you can use the flash memory with winblows machines
- Cons:
- * You will have two mount points bugging you all the time
- * VFAT: Bye bye permission data
-
Big Red
Single partition separated by directories and protected by permissions
- Pros:
- * One mount point
- Cons:
- * You have a slim chance of accidental deletion of an important directory if not first secured using permissions
Double Mint
Let’s get started, we will create the partition structure
# fdisk /dev/sdx
Let’s create a new partition table
Command (m for help): o Building a new DOS disklabel. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable.
Let’s create the first partition ( arch )
Command (m for help): n
Command action
e extended
p primary partition (1-4)
We will make a primary partition
p
This will be partition number 1
Partition number (1-4): 1
This partition will begin from cylinder 1
First cylinder (1-1015, default 1): 1
Here you will have to round up the size of the ISO + 10%
CURRENT ISO 550MB + 55MB = 605MB
BASE ISO 150MB + 15MB = 165MB
FTP ISO 20MB + 2MB = 22MB
Last cylinder or +size or +sizeM or +sizeK (1-1015, default 1015): +165M
Let’s create the second partition ( storage )
Command (m for help): n
Command action
e extended
p primary partition (1-4)
We will make a primary Partition
p
This will be partition number 2
Partition number (1-4): 2
This partition will be default all the way
First cylinder (199-1015, default 199): <return> Using default value 199
Here you will just press return again
Last cylinder or +size or +sizeM or +sizeK (199-1015, default 1015): <return> Using default value 1015
If this partition will be formatted using VFAT then let’s change the system id
Command (m for help): t
Just partition 2
Partition number (1-4): 2
W95 FAT32 is ‘b’
Hex code (type L to list codes): b
Now we must make the first partition active ( boot )
Command (m for help): a
Our boot partition is 1
Partition number (1-4): 1
Where all done here, let’s write the new partition table.
Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: If you have created or modified any DOS 6.x partitions, please see the fdisk manual page for additional information. Syncing disks.
Now we can format our second partition:
If you want to make it ext2/ext3
# mke2fs -j -L storage /dev/sdx2
Or if you are like me you might want to use reiserfs
# mkreiserfs -l storage /dev/sdx2
Maybe your not cool and decide to make it VFAT
# mkdosfs -v -n storage -F 32 /dev/sdx2
Big Red
Let’s get started, we will create the partition structure.
# fdisk /dev/sdx
Let’s create a new partition table
Command (m for help): o Building a new DOS disklabel. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable.
Let’s create the main partition ( arch )
Command (m for help): n
Command action
e extended
p primary partition (1-4)
We will make a primary partition
p
This will be partition number 1
Partition number (1-4): 1
This partition will be default all the way
First cylinder (1-1015, default 1): <return> Using default value 1
Here you will press return again
Last cylinder or +size or +sizeM or +sizeK (1-1015, default 1015): <return> Using default value 1015
Now we must make the first partition active ( boot )
Command (m for help): a
Our boot partition is 1
Partition number (1-4): 1
We’re all done here, let’s write the new partition table.
Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: If you have created or modified any DOS 6.x partitions, please see the fdisk manual page for additional information. Syncing disks.
Format
It’s time to format our new arch partition
If you are a ext2/ext3 fan:
# mke2fs -j -L arch /dev/sdx1
Or If you are a reiserfs fan:
# mkreiserfs -l arch /dev/sdx1
Copy
Let’s make an iso mount point:
# mkdir -p /mnt/iso
Mount downloaded iso
# mount -o loop /path/to/the/arch/cd.iso /mnt/iso
If everything went well you should see the iso’s contents via ‘ls’:
$ ls /mnt/iso arch boot
We also need to make a temporary mount point for our boot partition
# mkdir -p /mnt/tmp
Mount our fresh boot partition
# mount /dev/sdx1 /mnt/tmp
If all went well we can start the copy process
# cp -rav /mnt/iso/* /mnt/tmp/
Make it boot
Systems that can boot-up via flash memory treat the contents just like a fixed drive, that said, we will need to modify the original cd contents.
You will need to modify the arch menu list, the easy way
# cat /mnt/iso/boot/grub/menu.lst | \\
sed -r 's/hd0,0/hd1,0/' | \\
sed -r 's/\(cd\)/\(hd0,0\)/' > /mnt/tmp/boot/grub/menu.lst
Here is why your host arch system needs to have grub installed
We need to copy grub’s stage files
# cp /usr/lib/grub/i386-pc/* /mnt/tmp/boot/grub/
Now let’s make and identifier so we can identify our partition in grub console
# touch /mnt/tmp/boot/grub/.usb
Let’s start up grub
# grub
GNU GRUB version 0.97 (640K lower / 3072K upper memory)
[ Minimal BASH-like line editing is supported. For the first word, TAB
lists possible command completions. Anywhere else TAB lists the possible
completions of a device/filename. ]
Here is where our little identifier comes in handy
grub> find /boot/grub/.usb (hd1,0)
In my case hard drive ‘1′ partition ‘0′, your result may vary
We need to tell grub where it’s files are located
thats result from our last command (hd1,0)
grub> root (hd1,0) Filesystem type is reiserfs, partition type 0x83
Finally we tell it to generate the MBR, you need to tell it what hard drive ( in my case hd1 )
grub> setup (hd1)
Checking if "/boot/grub/stage1" exists... yes
Checking if "/boot/grub/stage2" exists... yes
Checking if "/boot/grub/reiserfs_stage1_5" exists... yes
Running "embed /boot/grub/reiserfs_stage1_5 (hd1)"...
19 sectors are embedded. succeeded
Running "install /boot/grub/stage1 (hd1) (hd1)1+19
p (hd1,0)/boot/grub/stage2 /boot/grub/menu.lst"... succeeded
Done.
That’s it, now we quit
grub> quit
Permissions
Let’s make sure root is owner of all and allow users the joy of knowing
# chown -R root:users /mnt/tmp/
Now this will allow users to create directories and files in the partition while forcing the group ‘users’,
great if you want to share your flash with your friends and family.
# chmod 2775 /mnt/tmp/
OK your done!!
Let’s get rid of the iso mount
# umount /mnt/iso
And now we un-mount the boot partition, It might take a little bit since it needs to flush
# umount /mnt/tmp
We now eject it safely
# eject /dev/sdx
Now go test it out !
END
Comments are welcome,
Guillermo A. Amaral
February 17th, 2007 at 5:11 pm
[...] I use it to update my Arch USB Key Installer made using INSTALL ARCH LINUX 0.8 FROM USB FLASH MEMORY [...]