add a swap partition

When I installed Freebsd I didn't create a swap space. Now I'd like to add it. I'm slightly confused as to naming of the partitions and the procedure for adding it:
I installed FreeBSD on the first partition of my only drive on a laptop. The rest of the space is unpartitioned as far as I know. I'd like to create 2 more partitions: 1 for swap (4GB) and the remaining space for data.

Here's my fdisk and df -h

Code:
bsdtop# fdisk 
******* Working on device /dev/ad4 *******
parameters extracted from in-core disklabel are:
cylinders=484521 heads=16 sectors/track=63 (1008 blks/cyl)

Figures below won't work with BIOS for partitions not in cyl 1
parameters to be used for BIOS calculations are:
cylinders=484521 heads=16 sectors/track=63 (1008 blks/cyl)

Media sector size is 512
Warning: BIOS sector numbering starts with sector 1
Information from DOS bootblock is:
The data for partition 1 is:
sysid 165 (0xa5),(FreeBSD/NetBSD/386BSD)
    start 63, size 88396497 (43162 Meg), flag 80 (active)
	beg: cyl 0/ head 1/ sector 1;
	end: cyl 1023/ head 15/ sector 63
The data for partition 2 is:
<UNUSED>
The data for partition 3 is:
<UNUSED>
The data for partition 4 is:
<UNUSED>
bsdtop# df -h
Filesystem     Size    Used   Avail Capacity  Mounted on
/dev/ad4s1a    496M    258M    198M    57%    /
devfs          1.0K    1.0K      0B   100%    /dev
/dev/ad4s1e    496M     86K    456M     0%    /tmp
/dev/ad4s1f     33G    6.8G     24G    22%    /usr
/dev/ad4s1d    2.9G     56M    2.6G     2%    /var

I'd really appreciate any help with it.
 
martins said:
I'm slightly confused as to naming of the partitions
First things first, get the naming correct. Then it'll all fall into place.

What's called a partition on Windows and/or Linux is called a slice on FreeBSD. Partitions are created inside slices.

ad0 is the first harddisk, ad4 is usually the first SATA drive.

s1,s2 etc are the slices, the 'a','b' etc are the partitions. The 'c' partition is a special case, it's the complete slice.
 
Alt said:
So you must do `ls -l /dev/ad4*` to check which partitions you have
Try
# gpart show

Don't assume there's a device for every slice/partition.
 
  • Thanks
Reactions: Alt
Hi,

Verify with disklabel, that you have a partition "b".

Ex :
Code:
$ disklabel ad0s1
# /dev/ad0s1:
8 partitions:
#        size   offset    fstype   [fsize bsize bps/cpg]
  a:  4194304        0    4.2BSD        0     0     0
[color="Blue"][B]  b:  2097152  8388608      swap[/B][/color]
  c: 41928705        0    unused        0     0         # "raw" part, don't edit
  d:  4194304  4194304    4.2BSD        0     0     0
  e: 10485760 10485760    4.2BSD        0     0     0
  f: 20957185 20971520    4.2BSD        0     0     0

You can create a swap partition with disklabel -e.

A+
 
Sorry for a delay, I had to reinstall FreeBSD, as I didn't know of the existence of -STABLE (as opposed to the RELEASE versions).

Let me get it straight. What in Linux is called a partition is called a slice in BSD and then withing a slice there are further subdivisions into partitions where you mount filesystem(s). Is that right?

Following this I have one slice for my system (within it there are partitions for /var /tmp, etc.). The second slice will be devoted to my data. Do I have to create a partition within a slice to mount it somewhere? I assume the answer will be 'yes'

Now, I've got swap now (actually I did have it then as well - as one of the members pointed out). What I need now is create a slice for my data.

Code:
# gpart show
=>       63  488397105  ad4  MBR  (233G)
         63   88396497    1  freebsd  [active]  (42G)
   88396560     999936    2  !130  (488M)
   89396496  399000672       - free -  (190G)

=>       0  88396497  ad4s1  BSD  (42G)
         0   1048576      1  freebsd-ufs  (512M)
   1048576   8307584      2  freebsd-swap  (4.0G)
   9356160   6250496      4  freebsd-ufs  (3.0G)
  15606656   1048576      5  freebsd-ufs  (512M)
  16655232  71741265      6  freebsd-ufs  (34G)

What is this !130 (488M)? - hmmm, I don't remember creating anything like that.

1. Which utility would I use to create a slice out of this remaining free space (190G)?
2. How would I create a partition on it?
3. What are the recommended entry for /etc/fstab to mount it rw for a normal user.

thank you for your time
 
you could also use a butterfly to edit the sectors via cosmic radiation

martins said:
Code:
# gpart show
=>       63  488397105  ad4  MBR  (233G)
         63   88396497    1  freebsd  [active]  (42G)
   88396560     999936    2  !130  (488M)
   89396496  399000672       - free -  (190G)

=>       0  88396497  ad4s1  BSD  (42G)
         0   1048576      1  freebsd-ufs  (512M)
   1048576   8307584      2  freebsd-swap  (4.0G)
   9356160   6250496      4  freebsd-ufs  (3.0G)
  15606656   1048576      5  freebsd-ufs  (512M)
  16655232  71741265      6  freebsd-ufs  (34G)

What is this !130 (488M)? - hmmm, I don't remember creating anything like that.

1. Which utility would I use to create a slice out of this remaining free space (190G)?
2. How would I create a partition on it?
3. What are the recommended entry for /etc/fstab to mount it rw for a normal user.

thank you for your time

the slice marked 130 is probably linux swap (130 = 0x82), if you're not using linux you can safely remove it. either fdisk(8) or gpart(8) should suffice for partitioning(slicing?) the remaining space, (fdisk is prompted, and since you're already on an MBR scheme, it's probably as good as anything) then bsdlabel(8) the resulting slice and simply newfs(8) the partition under that via something like # bsdlabel -w /dev/ad4s2 && newfs -U -L data0 /dev/ad4s2a && echo "/dev/ufs/data0 /YOUR_MOUNT_POINT_HERE ufs rw 2 3" >> /etc/fstab && mount /YOUR_MOUNT_POINT_HERE

glabel(8)-ing the slice and newfs-ing the /dev/label/ entry is another possibility.

Have fun.
 
Back
Top