Expand Partition and Create Swap File on BeagleBone Black Ubuntu SDR Img

IMPORTANT UPDATE: It was pointed out to me that SD cards have a limited number of writes cycles to them. I researched it some and that info is correct. So the swapfile is a bad idea. Don't follow that part of the tutorial, it could result in your SD card becoming unusable. For some reason I thought that had been worked around. Anyway, the rest of the tutorial is still valid.

After posting for the BeagleBone Black Ubuntu SDR img I remembered I had deleted the swapfile and shrunk the partition down to the minimum. I did this to make the download as small as possible. It still comes in at 1.9GB compressed. Anyway, I need to make this post in case some of you may not be familiar with resizing a linux partition and creating and enabling a swap file.

YOU DON'T HAVE TO DO THIS, but I recommend that you do. Ok? Ok. Don't worry about screwing up. If things get that bad you still have the img file you downloaded, right? Just reimage the sd card and start over.

If you'll follow along here these directions will help you expand the img to your microSD's capacity and then add a swap file to help manage RAM.

Connect your BeagleBone Black to the USB cable (and CAT5 Ethernet if you prefer). Open up your favorite terminal program, I use PUTTY, and connect (ssh) to your BeagleBone Black. If you're connecting over the USB then use 192.168.7.1 as the address. Otherwise enter your network IP.

Login is user: ubuntu  password: Temppwd (Capital T)

Need to switch to superuser/root:

# sudo su

Find out what the SD card is mounted as: (will be mounted as mmcblk0p2 if you booted into the image)

# df -m   //Shows usage on currently mounted devices -h GB -m MB -k KB 

If you're booted into my img it should resemble this:

Filesystem     1M-blocks  Used Available Use% Mounted on
/dev/mmcblk0p2      5877  4990       643  89% /
none                   1     0         1   0% /sys/fs/cgroup
udev                 247     1       247   1% /dev
tmpfs                 50     1        50   1% /run
none                   5     0         5   0% /run/lock
none                 249     0       249   0% /run/shm
none                 100     0       100   0% /run/user

We now know that the sd card img is mounted as /dev/mmcblk0p2. We drop the p2 (partition number) and run fdisk. At the command prompt enter p.

# fdisk /dev/mmcblk0 

Command (m for help): p

Disk /dev/mmcblk0: 15.7 GB, 15707668480 bytes
4 heads, 16 sectors/track, 479360 cylinders, total 30679040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1   *        2048      198655       98304    e  W95 FAT16 (LBA)
/dev/mmcblk0p2          198656    30679039    15240192   83  Linux

Command (m for help):

We're going to "delete" partition 2 and resize it. You wouldn't do it this way on a Windows system. I sure wouldn't do it on a live production system anywhere. But for these purposes it will be just fine. All the data stays put, you're just expanding the container a little bit. Don't concentrate on it too much. It works. If somehow this does mess up for you reload the img on your sd card, boot up the BBB, THEN insert the card and follow directions back to this point except your mmcblk will likely be mmcblk1. I've done this both ways, so whatever works best for you.

Now, enter the following in order at the prompts: d, 2

Command (m for help): d
Partition number (1-4): 2

Now we create a new larger partition: n, p, 2, enter, enter

Command (m for help): n  <-
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p  <-
Partition number (1-4, default 2): 2  <-
First sector (198656-30679039, default 198656):  <-hit enter
Using default value 198656
Last sector, +sectors or +size{K,M,G} (198656-30679039, default 30679039): <-hit enter
Using default value 30679039

Your values will vary, Let fdisk choose the start and end on its own unless you know what you are doing. Hit p again to check the partitions.

Command (m for help): p

Disk /dev/mmcblk0: 15.7 GB, 15707668480 bytes
4 heads, 16 sectors/track, 479360 cylinders, total 30679040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1   *        2048      198655       98304    e  W95 FAT16 (LBA)
/dev/mmcblk0p2          198656    30679039    15240192   83  Linux

Now we write the config to disk: w

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy. 
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

Ignore the warning and reboot:

root@arm:/home/ubuntu# reboot now

Broadcast message from ubuntu@arm
        (/dev/pts/0) at 6:15 ...

The system is going down for reboot NOW!
root@arm:/home/ubuntu#

Log back in, and sudo su again. Now to resize the filesystem on that partition.

# sudo su

# df -m

Filesystem     1M-blocks  Used Available Use% Mounted on
/dev/mmcblk0p2      5877  4990       642  89% /
none                   1     0         1   0% /sys/fs/cgroup
udev                 247     1       247   1% /dev
tmpfs                 50     1        50   1% /run
none                   5     0         5   0% /run/lock
none                 249     0       249   0% /run/shm
none                 100     0       100   0% /run/user


We can see that everything is fine. Now for this next command we'll use the complete path for the partition/file system.

#  resize2fs /dev/mmcblk0p2
resize2fs 1.42.9 (4-Feb-2014)
Filesystem at /dev/mmcblk0p2 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/mmcblk0p2 is now 3810048 blocks long.

# df -m
Filesystem     1M-blocks  Used Available Use% Mounted on
/dev/mmcblk0p2     14625  4991      9034  36% /
none                   1     0         1   0% /sys/fs/cgroup
udev                 247     1       247   1% /dev
tmpfs                 50     1        50   1% /run
none                   5     0         5   0% /run/lock
none                 249     0       249   0% /run/shm
none                 100     0       100   0% /run/user

….and you now have use of your full sd card!

 

DO NOT USE THE FOLLOWING PORTION OF THE TUTORIAL IF YOU ARE USING AN SD OR FLASH CARD!

You have been warned.

Now, let's set up your swapfile.

# cd /

# fallocate -l 1G /swapfile

# chmod 600 /swapfile

# mkswap /swapfile

Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=c5519194-f14c-4879-97e8-a486faa398da

# swapon /swapfile

# swapon -s

Filename                                Type            Size    Used    Priority
/swapfile                               file            1048572 0       -1


Ok, now you have a 1GB swapfile and it is enabled. Let's make it permanent.

# nano /etc/fstab

After the bottom line enter the following:

/swapfile   none    swap    sw    0   0

Now hit CTRL w to write, then y, then press Enter.

You now have a permanent 1G swap file. You could lower or raise this to suite the amount of RAM you have on whatever version of BeagleBone Black you are running.

I hope you found this useful and everything worked. If you run into trouble leave a comment or send me an email.

73s

About the Author

kd0cq
Chris - KD0CQ (formerly KB0TLW) has held an amateur (ham) radio license since 1994 and is stubbornly grasping onto his Advanced class operator status. His professional experience includes Network and Systems Administrator, Network Security, and Electronics Engineer. Sometimes even a little bit of web development. mail: chris at kd0cq dot com

8 Comments on "Expand Partition and Create Swap File on BeagleBone Black Ubuntu SDR Img"

  1. Would you please tell me after I installed the software for the BeagleBone, the Login and Passwrod is?

    Is it possible for the software be usable on the small 4.3LCD?

    Thank you very much

     

     

  2. Great work man, saved me alot of time!!!

  3. Thank you for writing such a detailed guide, infact its exactly what I was looking for. Sometimes it takes a guide like this to put all the jigsaw puzzle peices together so to speak.

  4. Thank you very much,your  works are great for geekers.

    Do you mind to develop those for pcduino V3 in your free time after work? I  have two Pcduino V3 Nano boards,and I can give you one for your best works.

    🙂

  5. Works for me, but the beaglebonds ip address on the usb port is 192.168.7.2

     

    Thanks

     

  6. Great!

    thank you man. 

  7. Thomas (tom) Sides | October 13, 2017 at 4:24 pm | Reply

    Great Job. I set it up on a beagle green. I know thats what I had. Is the program set up to run a display? I have HDMI board mounted. I want use this on a SDR radio Setup. I kind of fumbled around with the password, but it worked to script.

Leave a comment

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.