Preparing your primary mount and swap with fdisk

I have 4 big drives on a new machine, each can hold up to 2Tb of data, at first I thought I’d use the first drive for the OS and the other 3 for a RAID5 (software controlled)

Then after I had installed the operating system, I decided it was a big waste, and that I’d only need about 80gigs for the OS, and that I should use the 1920Gb (-swap,-other blocks) to be part of the RAID.

The first thing I needed to do was to resize the primary partition, but you can’t really do this while you’re using it. So I restarted with the Ubuntu CD in rescue mode, and jumped to the part where you setup the partition sizes. I told it I wanted to make the first partition smaller, I made it 80Gb, I accepted the rest of the options, and after a long while, it was finished creating the file systems, but it seems like it did a mess.

I restarted without the CD, crossed my fingers, and it did boot.

I did a:

sudo fdisk -l
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *          63   156264254    78132096   83  Linux
/dev/sda2       156264255  2930272064  1387003905    5  Extended
/dev/sda5      2882334168  2930272064    23968948+  82  Linux swap / Solaris
/dev/sda6       156264381  2834380079  1339057849+  83  Linux
/dev/sda7      2834380143  2882334104    23976981   82  Linux swap / Solaris

and there were 6 partitions, some overlapping, but the primary looked right. I entered fdisk and deleted the 5 other partitions, and started a new.

Created a new partition (2) for Swap. Since the machine has 8GB of Ram, that’s the amount of Swap I used for it. After the partition was defined, I changed it’s type to type 82 (Linux Swap)

Then I created another partition (3), this one using the remaining space, and set it’s type to 83 (Linux)

I wrote the changes (w) and exited. It told me that the changes were written but the partitions would not be used until I rebooted, so I rebooted.

When I came back and did:

sudo fdisk -l

There they were:

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        9727    78132096   83  Linux
/dev/sda2            9728       10700     7812500+  82  Linux swap / Solaris
/dev/sda3           10700      182402  1379193956   83  Linux

But now there was a problem, when I checked for the memory available there was no swap

$ free
             total       used       free     shared    buffers     cached
Mem:       8183920     198524    7985396          0       6668      70284
-/+ buffers/cache:     121572    8062348
Swap:            0          0          0

So, first thing, I made sure the swap was specified on /etc/fstab for the next boot to include the swap

/dev/sda2 none swap sw 0 0

And then I had to make a file system for the swap

sudo mkswap /dev/sda2

Then, the “free” command did show the swap:

$ free
             total       used       free     shared    buffers     cached
Mem:       8183920     220420    7963500          0       7552      86880
-/+ buffers/cache:     125988    8057932
Swap:      7812492          0    7812492

In this case I didn’t have to make the file system for the primary partition because it was already made, I suppose the term “making the file system” is the equivalent of saying “formatting the drive with a specific filesystem”

However I had to do it for the remainder of the disk:

sudo mkfs.ext3 /dev/sda3

I’ll let you know if I find anything different from the tutorials on how to make RAID5.

New /etc/fstab format in Ubuntu
I while later, I updated the /etc/fstab to include the UUID of the swap partition on the fstab, instead of the device name.
To obtain this UUID I learned about the vol_id command

$ sudo vol_id /dev/sda2
ID_FS_USAGE=other
ID_FS_TYPE=swap
ID_FS_VERSION=2
ID_FS_UUID=b9b825c2-85dc-4def-bfd1-9071042452fa
ID_FS_UUID_ENC=b9b825c2-85dc-4def-bfd1-9071042452fa
ID_FS_LABEL=
ID_FS_LABEL_ENC=
ID_FS_LABEL_SAFE=

Now my /etc/fstab file looks like this:

# /etc/fstab: static file system information.
#
#              

proc            /proc           proc    defaults        0       0
# /dev/sda1
UUID=13676a4b-b669-4a7a-9776-cb10c7b492b9 /               ext3    relatime,errors=remount-ro 0       1
#/dev/sda2
UUID=b9b825c2-85dc-4def-bfd1-9071042452fa none swap sw 0 0
/dev/scd0       /media/cdrom0   udf,iso9660 user,noauto,exec,utf8 0       0
Post on Twitter
Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Google Buzz (aka. Google Reader)

Leave a Reply