2

This is certainly a really easy question for you all I am sure. So I have Ubuntu (13.04) as the only OS mounted on my HDD. What I would like to do is re-partition my HDD so as to begin a LFS build.
Using sudo fdisk /dev/sda, and p for print partition table I get:

/dev/sda1 * ................................. 83 linux
/dev/sda2   ................................. 5 extended
/dev/sda5   ................................. 82 linux swap/solaris

I would like to use the swap space that is /dev/sda5 as the swap space for the build so as to not have superfluous swap space.

Also, I would like to build the system in an extended system so I can make logical partitions for /boot, /, /usr, et al.

My question is, how do I figure out what is in the /dev/sda2 partition? Is it empty? Is it available for me to build my LFS base in? If it is empty, then I won't partition anything. If it is being used by Ubuntu for something then I will have to build another primary partition for the build.

Unfortunately I do not remember making the partition, if I did.

| improve this question | | | | |
1
  1. Check with mount if you have block device mounted
  2. Use blkid tool to find out whether you partition is formatted.
  3. If you have you partition unmounted and formatted, try to mount (blkid helps to determine right filesystem type) and check data on it with mount tool
| improve this answer | | | | |
  • when i used the mount command following your advice, the output gave a description of /dev/sda1, but nothing about /dev/sda2. also when i used the blkid, also after your advice, no output wrt /dev/sda2 was produced. only /sda1 – alienfetuseater Nov 8 '13 at 20:05
1

My question is, how do I figure out what is in the /dev/sda2 partition?

According to your fdisk printout, it appears that /dev/sda2 is an extended partition. Disks partitioned with a MBR (Master boot record) are only capable of 4 real partitions: extended partitions are a way around that limit. They basically look like this:

your disk: ..............................................................
/dev/sda1:  \---------------------/
/dev/sda2:                         \------------------------------------/
/dev/sda5:                          \-----------------------------------/

Note that this is just a possible ASCII art of your disk: you didn't list your partition sizes and locations, so I'm not sure if the order here is correct, or if you have free space somewhere. (Or other partitions lurking about.)

It appears that /dev/sda2 likely contains /dev/sda5, your swap partition.

You could, as others suggest, attempt to mount /dev/sda2, but it will most likely fail.

gparted does a nice job of visualizing extended partitions. If you have it available, I find it much easier to work with than fdisk, and I think its rendering of extended partitions will make more sense.

What I would like to do is re-partition my HDD so as to begin a LFS build

Make sure any important data on the disk is backed up. It takes only one fat-finger on a partition table editor to make getting data off the disk much more exciting. (Also: make sure you're editing the partitions on the disk you intend to be editing, if you have multiple disks.)

| improve this answer | | | | |
  • /dev/sda1 starts at 2048-310503423, and has 155250688 blocks /dev/sda2 starts at 310505470 to 312580095, and has 1037313 blocks /dev/sda5 starts at 310505472 to 312580095, and has 1037313 blocks. from this it seems that /dev/sda2 contains /dev/sda5, as you suggested. i did attempt mount /dev/sda2 but no this did not work. i used gparted for the first time and this is what it told me, /dev/sda1, ext4 filesystem, mount point /, size 148.06 Gib,.. /dev/sda2, extended, has nothing for mount point and contains 1013. mib with 0 used – alienfetuseater Nov 8 '13 at 20:11
  • so this is to suggest that /dev/sda2 contains nothing, and was probably created during the ubuntu install to house the swap partition? ubuntu was originally dual booted on the machine, but windows was subsequently removed. should i be able to increase the size of /dev/sda2 so i can use this as my partition to do my build in? – alienfetuseater Nov 8 '13 at 20:13
  • With PC-style partitions, there can only be one extended partition, and all partitions numbered 5 and above are part of that extended partition. So it is certain that sda2 contains sda5. @alienfetuseater The sda2 partition occupies 512 bytes on its own, plus the space used by the logical partitions that it contains. Since sda2 and sda5 have the same size, there is no free space in sda2. – Gilles 'SO- stop being evil' Nov 8 '13 at 21:33
0

You can check if that partition is already mounted:

mount | grep '/dev/sda2'

This command will show you the mountpoint that partition is mounted under, if any.

Example output:

/dev/sda2 on /home type ext4 (rw,relatime,user_xattr,acl,barrier=1,data=ordered)

In this case, /dev/sda2 is mounted under /home and you can go there directly and figure out "what is in it".

If the command produces no output, you need to mount the partition first in order to read it. Try something like:

sudo mount -t auto /dev/sda2 /mnt

This will mount /dev/sda2 under /mnt so you can go and see what's stored in it.

To find out the space usage for a partition mounted under /mnt, you can do

df -h /mnt

If a partition has enough empty space for your requirements, you can then shrink it and use the newly-created empty space for your LFS build. To shrink partitions easily, you can use a graphical partition editor like gparted

You might also be interested in the following U&L Q&A I answered earlier about something similar:

| improve this answer | | | | |
0

Simply mount the partition and use du -sch mount_point. Also you can check whether there is an activity using lsof

For example, if you have mounted the device in /mnt, you can use lsof +D /mnt to know the activity.

| improve this answer | | | | |
  • i was unable to mount the device, as i didnt know what /mnt was for /dev/sda2. so i could not use any of this – alienfetuseater Nov 8 '13 at 20:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.