Es­sen­tial Linux: cfdisk

Learn how to use cfdisk to par­ti­tion disks, and how to in­stall Linux on those new par­ti­tions

Linux User & Developer - - Contents -

Learn how to use cfdisk to par­ti­tion disks, and how to in­stall Linux

Any file stor­age sys­tem, whether it’s a CD-ROM, a hard drive or a USB stick, is es­sen­tially a de­vice for stor­ing a long chain of 1s and 0s. When we in­ter­act with it, how­ever, we don’t see this; in­stead, we see files, di­rec­to­ries, sym­bolic links and so on. The soft­ware that makes the trans­la­tion for us is called a file sys­tem.

There’s one step in be­tween, though, and it’s of­ten over­looked. A par­tic­u­lar file sys­tem need not take up the whole of the disk it lives on. In­stead, the disk may be split up into in­di­vid­ual sec­tions, called par­ti­tions, each of which can have its own file sys­tem – or none at all.

The disk keeps track of its par­ti­tions through its par­ti­tion ta­ble, which tells it how many par­ti­tions there are, and where each one be­gins and ends.

There are a num­ber of disk par­ti­tion­ing tools, but the one we shall be fo­cus­ing on is one of the eas­i­est to use, fdisk. In fact, we shall mainly be us­ing its fancier cousin, cfdisk, which makes things eas­ier still through its ncurses in­ter­face.

We’ll be demon­strat­ing some of the power of par­ti­tion­ing by in­stalling a com­plete Linux sys­tem to a USB stick, while sav­ing some space ‘on the side’ for file stor­age. The stick needs to be at least 8GB in ca­pac­ity – and ob­vi­ously, first make sure there’s no data on it you want to keep, be­cause we’ll be re­mov­ing ev­ery­thing.

Be­fore par­ti­tion­ing your USB stick, you should find out what your com­puter iden­ti­fies it as. Insert the stick into your com­puter’s port (if it’s al­ready in, eject it and put it in again). Once it’s in, run dmesg in a ter­mi­nal and look for out­put near the end sim­i­lar to the fol­low­ing:

scsi host4: usb-stor­age 2-2:1.0 scsi 4:0:0:0: Di­rect-Ac­cess Generic Flash Disk sd 4:0:0:0: [sdb] 512-byte log­i­cal blocks sd 4:0:0:0: [sdb] Write Pro­tect is off

The thing we’re look­ing for is the name sdb. De­pend­ing on your setup, you might see some­thing dif­fer­ent, such as sdX or hdp – but nor­mally on a Linux sys­tem, it’ll be sd fol­lowed by a sin­gle let­ter.

Let’s sup­pose that your USB stick is avail­able at sdb. You can ver­ify this by run­ning the ls­blk com­mand, which gives an over­view of the stor­age on your sys­tem. You might see some­thing like the out­put in Fig­ure 1. Here, sda is our com­puter’s hard disk, which is al­ready split

into par­ti­tions sda1 and sda2 (there may be more on your sys­tem). Mean­while, our USB stick, sdb, has a sin­gle par­ti­tion, sdb1.

Use par­ti­tion­ing

Once you’ve iden­ti­fied the de­vice name for your USB stick, you can fire up cfdisk:

# cfdisk /dev/sdb

If your USB stick is not at sdb, use the other value here in­stead. You should see a screen like the one in the main im­age (see fac­ing page).

Us­ing the ar­row keys, you can nav­i­gate be­tween the par­ti­tions cur­rently on the stick. Each row of the ta­ble rep­re­sents a con­tigu­ous range of mem­ory ad­dresses that is ei­ther a par­ti­tion or an area of empty space. Most likely, you’ll start off with a sin­gle par­ti­tion and empty space, as in Fig­ure 1. Use the left/right ar­row keys to se­lect the [Delete] op­tion and press En­ter to delete this par­ti­tion. If there are any other par­ti­tions, use up/down to se­lect them and then delete them as well, so that the en­tire USB stick is free space.

Let’s start par­ti­tion­ing the drive. Our first par­ti­tion will be 2GB in size. Use the left/right keys to se­lect the [New] op­tion at the bot­tom and press En­ter. At the prompt, en­ter 2G, and press En­ter again to cre­ate the par­ti­tion.

This should have been fairly easy, so let’s make a new par­ti­tion. Press the down ar­row to move the cur­sor at the top into the Free space row: we will cre­ate the next par­ti­tion in here. Se­lect [New] as be­fore, and this time type in 250M rather than 2G, be­fore press­ing En­ter to cre­ate a new par­ti­tion of size 250MB.

This par­ti­tion is go­ing to play a spe­cial role: it’s go­ing to be the boot par­ti­tion for our USB stick. Any bootable medium, whether it’s a Live CD, your lap­top’s in­ter­nal hard drive or a live USB stick, has to have a spe­cial par­ti­tion called the boot par­ti­tion that con­tains var­i­ous files nec­es­sary for boot­ing up the sys­tem. The boot par­ti­tion may con­tain other files as well – in­deed, var­i­ous older sys­tems are en­tirely con­tained in­side one bootable par­ti­tion – but it is a bit more ro­bust to only use the boot par­ti­tion for boot­ing pur­poses.

For now, all we need to do is to make this par­ti­tion bootable. Keep­ing the cur­sor at the top fo­cused on your new par­ti­tion (which might be named /dev/sdb2), use the left/right ar­rows to se­lect the [Bootable] op­tion, and press En­ter to set the bootable flag. You should see a small star * ap­pear next to /dev/sdb2 at the top, in the Boot col­umn.

Now let’s cre­ate an­other 2GB par­ti­tion af­ter the one we’ve just made. Press the down key to move into the Free space, and then se­lect [New] at the bot­tom again, typ­ing in 2G and press­ing En­ter as be­fore. At the top of the dis­play, we might see some­thing like the fol­low­ing:

Hav­ing the free space at the end means that we can come back and use the [Re­size] op­tion to grow the sdb3 par­ti­tion if we want to later on. Grow­ing the sdb1 and sdb2 par­ti­tions will be much harder once all the par­ti­tions have data writ­ten to them: we will need to recre­ate the par­ti­tion ta­ble in full in cfdisk, and then use an­other tool (such as dd) to shift the data into the new po­si­tions. This is both time-con­sum­ing and po­ten­tially dan­ger­ous to the data if any er­rors oc­cur.

The very last step is to write this par­ti­tion ta­ble to the USB stick. At the mo­ment, noth­ing we have done has ac­tu­ally altered the state of the disk at all, which is a very good thing: if you make any mis­takes, you can cor­rect them (or se­lect [Quit] to start again com­pletely) and be sure that you won’t have messed any­thing up. This is par­tic­u­larly im­por­tant if you are repar­ti­tion­ing a disk that al­ready con­tains data, since writ­ing the par­ti­tion ta­ble in­cor­rectly could de­stroy some of that data.

Us­ing the left/right keys, se­lect [Write] at the bot­tom, and press En­ter. cfdisk will check one last time that this is what we ac­tu­ally want to do:

Are you sure you want to write the par­ti­tion ta­ble to disk?

Type "yes" or "no", or press ESC to leave this di­a­log.

Type yes and then press En­ter to write the par­ti­tion ta­ble. Lastly, nav­i­gate to [Quit] and press En­ter to close cfdisk. We can check what we’ve done by run­ning ls­blk again. Af­ter these changes, the sdb por­tion of the out­put should look some­thing like this:

There are a num­ber of disk par­ti­tion­ing tools, but the one we shall be fo­cus­ing on is cfdisk

Above cfdisk makes it easy to par­ti­tion disks through its user-friendly in­ter­face. Ad­mit­tedly, this might not look all that friendly with so many num­bers float­ing around, but it’s a lot eas­ier than us­ing the com­mand line!

Above We can use the ls­blk com­mand for a use­ful high­level over­view of the par­ti­tions on the de­vices on our sys­tem

Newspapers in English

Newspapers from UK

© PressReader. All rights reserved.