nahannidog
Posts: 11
Joined: Wed Feb 05, 2014 10:04 pm

How to remove 2 unwanted OS'es installed with NOOBs

Tue Feb 03, 2015 8:01 pm

Hello,
As a new user, I used NOOBS to install Raspbian, Openelec and Pidora on 16GB SD card. I've since settled upon Raspbian and would like to make more space for it on the SD Card. I have alot of installed programs running under Raspbian, I'd like to keep that intact. Some questions:
1. Are each of those OS'es assigned to their own "partition"?
2. Can I remove Openelec and Pidora without trashing Raspbian and it's programs? If so, how do I then expand Raspbian to fill the SD card?
3. Would it be easier to somehow copy the Raspbian Partition (if it is it's own partition) to a new SD Card? Can I do that in Windows with "WinImage" utility? Will the partition resize itself to fill the new card?

Tnx!

User avatar
procount
Posts: 1831
Joined: Thu Jun 27, 2013 12:32 pm
Location: UK

Re: How to remove 2 unwanted OS'es installed with NOOBs

Wed Feb 04, 2015 12:22 am

1. Yes.
2. Yes. You can use parted to remove unwanted partitions. You can also use it to resize the Raspbian partition. raspi-config can also be used to expand your filesystem to fill the SD card (but I'm not sure it will work in this instance - i've not tried it).
3. At the very least, you should make a backup of your SD card before attempting any of this because it is very easy to trash your SD card when messing about with partitions. Typically WinImage (and others) will copy the WHOLE of your SD card. If you just want to copy your Raspbian partitions, you can do it in Raspbian itself using dd to write the partitions to a USB stick.

As you are a new user, I consider this advanced stuff. You should do some reading up on how to use parted, fdisk, dd, (use parted --help or man parted etc & google of course) before starting this so you know what you are doing. Also read up on how NOOBS will have partitioned your SD card (see github.com/raspberrypi/noobs) and it would also be useful to understand what primary, extended and logical partitions are.

But if you have made sure you have a good backup of your SD card first, then there's nothing like trying it out to learn about how to do it. That's what the PI is all about.

You should look at the installed_os.json file that NOOBS stores on the 3rd partition (SETTINGS) as this will list all the OSs it installed and on which partitions they were installed on. This will tell you which partitions you need to delete and which one you need to expand.

Typically, each OS will have 2 partitions - a small FAT boot partition and a larger ext4 root partition. You only need to expand the Raspbian root ext4 partition.

Hope this points you in the right direction.
PINN - NOOBS with the extras... https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=142574

nahannidog
Posts: 11
Joined: Wed Feb 05, 2014 10:04 pm

Re: How to remove 2 unwanted OS'es installed with NOOBs

Mon Feb 16, 2015 3:12 am

Hello, thanks for your careful reply.
Took some courage to embark on this, but making progress. I have backup of my SD card (wrote it to a different card and it seems to work as a clone), then used Parted (also tried "GParted" live image to give me a graphical view of things). Here's the print output (actually of the clone 64GB SD card, original was 32GB):

Code: Select all

Number  Start   End     Size    Type      File system  Flags
 1      4194kB  1445MB  1441MB  primary   fat32        lba
 2      1447MB  31.9GB  30.4GB  extended
 5      1451MB  1556MB  105MB   logical   fat32        lba
 6      1560MB  11.6GB  9999MB  logical   ext4
 7      11.6GB  11.6GB  83.9MB  logical   fat32        lba
 8      11.7GB  21.1GB  9475MB  logical   ext4
 9      21.1GB  21.2GB  62.9MB  logical   fat32        lba
10      21.2GB  31.9GB  10.7GB  logical   ext4
 3      31.9GB  31.9GB  33.6MB  primary   ext4
I'm not sure which partitions to delete, you wrote the following:
You should look at the installed_os.json file that NOOBS stores on the 3rd partition (SETTINGS) as this will list all the OSs it installed and on which partitions they were installed on. This will tell you which partitions you need to delete and which one you need to expand.
My subsequent questions are:
1. how do I view that 3rd partition...do I need to "mount" it or similar?
2. I'm guessing I need to remove the fat32 (boot) and ext4 partitions as a pair...will the output of installed_os.json make this obvious?

Thanks!
David

beta-tester
Posts: 1244
Joined: Fri Jan 04, 2013 1:57 pm
Location: de_DE

Re: How to remove 2 unwanted OS'es installed with NOOBs

Mon Feb 16, 2015 5:45 am

nahannidog wrote:My subsequent questions are:
1. how do I view that 3rd partition...do I need to "mount" it or similar?
2. I'm guessing I need to remove the fat32 (boot) and ext4 partitions as a pair...will the output of installed_os.json make this obvious?
1. yes, you have to mount the "SETTINGS" partition by hand and edit installed_os.json, remove the deleted partitions and adjust the other entries with their new updated partition values:

Code: Select all

sudo blkid
    /dev/mmcblk0: PTTYPE="dos"
    /dev/mmcblk0p1: LABEL="RECOVERY" TYPE="vfat"
    /dev/mmcblk0p3: LABEL="SETTINGS" UUID="88888888-8888-8888-8888-888888888888" TYPE="ext4"
    /dev/mmcblk0p5: LABEL="boot_OPENEL" UUID="1111-1111" TYPE="vfat"
    /dev/mmcblk0p6: LABEL="root_OpenELEC" UUID="11111111-1111-1111-1111-111111111111" TYPE="ext4"
    /dev/mmcblk0p7: LABEL="boot_PiPLAY" UUID="2222-2222" TYPE="vfat"
    /dev/mmcblk0p8: LABEL="root_PiPLAY" UUID="22222222-2222-2222-2222-222222222222" TYPE="ext4"
    /dev/mmcblk0p9: LABEL="boot_Raspbi" UUID="3333-3333" TYPE="vfat"
    /dev/mmcblk0p10: LABEL="root_Raspbian" UUID="33333333-3333-3333-3333-333333333333" TYPE="ext4"
sudo mount /dev/mmcblk0p3 /mnt
sudo nano /mnt/installed_os.json
sudo umount /mnt
2. yes, one "fat" partition is the boot partition of the OS, and followed by the "ext4" root partition.
to be very sure, take a look to the installed_os.json file, to see ,which partition is member of which OS.
if you remove the root partition, then its boot partition can (or has to) be removed as well.


depending of the installed OS and NOOBS version, it is possible, that you have a copy of the previosusly installed image in the "os" folder in the RECOVERY partition. if unwanted, then it is also waste of disk-space you can delete...
(it is NOT a backup of the actual working partition of the OS, it is a copy of the untouched virgin image as it was at installation time)
for example:

Code: Select all

sudo mount /dev/mmcblk0p1 /mnt
ls /mnt/os/
    OpenELEC    PiPlay    Raspbian
sudo rm -r /mnt/os/OpenELEC
sudo umount /mnt
then you have to shrink the size of the RECOVERY partition as well to get a bit more disk space.
{ I only give negative feedback }
RPi B (rev1, 256MB), B (rev2, 512MB), B+, 2B, 3B, 3B+, ZeroW, ...

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: How to remove 2 unwanted OS'es installed with NOOBs

Mon Feb 16, 2015 11:53 am

You know, …

It's probably easier just to do it the straightforward way. That is, copy all the files from the two needed partitions (the boot one and the rootfs one) to newly created/formatted partitions - and be done with it.

This has many advantages - including learning a lot more about how the thing really works - including one very important one: You won't be messing up your original SD card, so if anything goes wrong (as it inevitably will, this being your first time and all,,,), you can just go back and do it over.

As for the "How do I do this?", there are several ways - which is best depending on your situation - but figuring out which is best for you will be part of the fun. The most straightforward way would be to have a USB card reader attached to your Pi, then boot up the working system and do something like:

cp -av /boot/* /mnt/sda1
umount /boot
cp -av /* /mnt/sda2

with, of course, the appropriate mkfs'ing, mounting and umounting (and so on) along the way.

The point is, at the end, you will end up with a standalone (not NOOBS) boot media set.
(And this is a Good Thing)
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

nahannidog
Posts: 11
Joined: Wed Feb 05, 2014 10:04 pm

Re: How to remove 2 unwanted OS'es installed with NOOBs

Wed Feb 18, 2015 4:44 am

Hello procount and beta-tester.
Well, I made the SD card backup, put the SD card in my PC, used LiveImage GParted and eliminated the Pidora boot and main partitions. Before I went beyond this (ultimately wanting to expand the Raspbian partitions), I checked out status by putting the repartitioned SD card back into the RPi. something strange happened:
1. bootup defaulted to Raspbian, but during the bootup, displayed a error something like: mounting local filesystems... mount /dev/mmcblk0p09 does not exist. Failed". Originally, Pidora was partitions 5&6, Raspbmc was 7&8, Raspbian was partitions 9&10. After removing Pidora all the remaining partitions slipped down two notches, so there were no longer partitions 9&10. First question: what is telling the Raspbian boot process to be looking for partitions 9&10?

2. Second question, what is the bootup process of looking for "devices" in general? For example the above mentioned partitions and also things like keyboard, mouse, display.

For the record, here's what blkid looks like on the repartioned card:

Code: Select all

/dev/mmcblk0p1: LABEL="RECOVERY" UUID="53AA-1F84" TYPE="vfat"
/dev/mmcblk0p3: LABEL="SETTINGS" UUID="acbd1219-278f-4de9-8a33-559389b9944e" TYPE="ext4"
/dev/mmcblk0p5: LABEL="BOOT" UUID="2762-E1C6" TYPE="vfat"
/dev/mmcblk0p6: LABEL="rootfs" UUID="a60e759e-0f33-4165-b931-9ff88ebf956e" TYPE="ext4"
/dev/mmcblk0p7: LABEL="BOOT" UUID="49CA-472F" TYPE="vfat"
/dev/mmcblk0p8: LABEL="root" UUID="2c723494-9077-4955-b08d-8dbfe6a52232" TYPE="ext4"
And parted:

Code: Select all

[email protected] ~ $ sudo parted
GNU Parted 2.3
Using /dev/mmcblk0
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: SD SU32G (sd/mmc)
Disk /dev/mmcblk0: 31.9GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type      File system  Flags
 1      4194kB  1445MB  1441MB  primary   fat32        lba
 2      1447MB  31.9GB  30.4GB  extended
 5      1448MB  1532MB  83.9MB  logical   fat32        lba
 6      1536MB  11.0GB  9475MB  logical   ext4
 7      21.1GB  21.2GB  62.9MB  logical   fat32        lba
 8      21.2GB  31.9GB  10.7GB  logical   ext4
 3      31.9GB  31.9GB  33.6MB  primary   ext4
Thanks!

nahannidog
Posts: 11
Joined: Wed Feb 05, 2014 10:04 pm

Re: How to remove 2 unwanted OS'es installed with NOOBs

Wed Feb 18, 2015 5:51 am

Further update. I burned the backup image of the original SD Card to a fresh SD card. Putting this (let's call it the original SD card) in the RPi, I noticed the bootup screens (i.e. all the text scrolling by after exiting the NOOBs screen) between the Original SD Card and the repartitioned SD Card are vastly different. So maybe question #2 above should be broadened to ask: What defines the bootup process? Is there somekind of bootup configuration file?

Thanks!

User avatar
procount
Posts: 1831
Joined: Thu Jun 27, 2013 12:32 pm
Location: UK

Re: How to remove 2 unwanted OS'es installed with NOOBs

Wed Feb 18, 2015 8:53 am

nahannidog,
Re-inserting the SD card after deleting Pidora is interesting educationally, but the errors are not surprising as you haven't yet completed the process and the partitions do not match what it expected.
Partitions 5-10 are Logical Partitions within the extended partition 2. They are created in a chain, so removing one moves the rest down and they are renumbered consecutively starting at 5, as you discovered. So you have to fix all the places these partition numbers are recorded in noobs and the OS itself.
Each OS type may need a different fixup method. When noobs installs an OS, it executes a script called partition_setup.sh to fix up the appropriate places. Have a look in the recovery partition (/dev/mmcblk0p1) in /os/Raspbian, for example for this file and see what locations it corrects. You will need to duplicate this behaviour to tell it which partitions it is now located on. Typically it will modify the cmdline.txt in the boot partition to tell it where the root file system is, and the fstab in the root file system to automatically mount the boot partition. There could be also references to other partitions here, but I doubt it in your case. You nee d to look at the appropriate partition_setup.sh for each OS that moves partitions.
In Noobs, you need to modify the installed_os.json file as previously mentioned, so that noobs can present a boot selection dialog and boot the correct OS in the correct partition. Noobs also stores the last selected boot partition in noobs.conf, also on the settings partition.
PINN - NOOBS with the extras... https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=142574

beta-tester
Posts: 1244
Joined: Fri Jan 04, 2013 1:57 pm
Location: de_DE

Re: How to remove 2 unwanted OS'es installed with NOOBs

Wed Feb 18, 2015 9:37 pm

some more magic...
when the partition table was changed, you have to adjust the changed /dev/mmcblk0pX in several files.
1. on the SETTINGS partition of NOOBS in the installed_os.json file
2. on each BOOT partition of each OS, the /cmdline.txt there is an entry "root=/dev/mmcblk0pX" (Raspbian) or "boot=/dev/mmcblk0pX disk=/dev/mmcblk0pX" (OpenELEC).
3. on each ROOT partition of each OS, the /etc/fstab, there is an entry for / and an entry for /boot (Raspbian),
OpenELEC does not use /etc/fstab for that purpose.

that you have to adjust the device names according your changes at BOOT's cmdline.txt and ROOT's /etc/fstab i forgot to mention :oops:

basicly, steps 2 & 3 describes, what the partition_setup.sh of each OS is doing, after partitionizing the disk and extracting the OSes filesystems to thier partitions. that partition_setup.sh file is found in each /os...
or here
http://downloads.raspberrypi.org/

Raspbian

OpenELEC
OpenELEC RPi1
OpenELEC RPi2
{ I only give negative feedback }
RPi B (rev1, 256MB), B (rev2, 512MB), B+, 2B, 3B, 3B+, ZeroW, ...

nahannidog
Posts: 11
Joined: Wed Feb 05, 2014 10:04 pm

Re: How to remove 2 unwanted OS'es installed with NOOBs

Fri Feb 20, 2015 6:27 pm

Hi procount & beta-tester,
Hooray, got the Pidora partitions removed, and the Raspbian and Raspbmc os'es functional again. Thanks for your patient help. I used (g)parted, then editted /etc/fstab and /boot/cmdline.txt as you advised. My remaining step is to reuse parted to expand Raspbian into the free-space left by Pidora removal.

A few questions so I understand better what I did:
1. the partition_setup.sh script is only executed when noobs installs a new partition, right? We looked at it to learn what files I had to manually adjust...indeed fstab and cmdline.txt.
2. I didn't understand entirely the partition_setup.sh

Code: Select all

mkdir -p /tmp/1 /tmp/2

mount "$part1" /tmp/1
mount "$part2" /tmp/2
I'm guessing those $partX are temporary variables passed during the Noobs new OS install process, right?
3. The fstab and cmdline.txt editting wouldn't have been necessary if I was lucky enough to want to remove the highest numbered partitions, right? In my case, if I had wanted to remove partitions 9 &10 with parted, there would be no need to renumber the remaining, lower numbered partitions.
4. It seems valuable to have a second os on the SD card in case you damage one OS; you can get back into the healthy OS to do repairs on the damaged one. Either that or have a linux PC to put the SD card into for editing.

Thanks!

User avatar
procount
Posts: 1831
Joined: Thu Jun 27, 2013 12:32 pm
Location: UK

Re: How to remove 2 unwanted OS'es installed with NOOBs

Fri Feb 20, 2015 6:32 pm

Basically, YES to all your points. You've learnt a lot. Well done!
PINN - NOOBS with the extras... https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=142574

nahannidog
Posts: 11
Joined: Wed Feb 05, 2014 10:04 pm

Re: How to remove 2 unwanted OS'es installed with NOOBs

Fri Feb 20, 2015 6:41 pm

Joe Schmoe wrote:You know, …

It's probably easier just to do it the straightforward way. That is, copy all the files from the two needed partitions (the boot one and the rootfs one) to newly created/formatted partitions - and be done with it.

This has many advantages - including learning a lot more about how the thing really works - including one very important one: You won't be messing up your original SD card, so if anything goes wrong (as it inevitably will, this being your first time and all,,,), you can just go back and do it over.

As for the "How do I do this?", there are several ways - which is best depending on your situation - but figuring out which is best for you will be part of the fun. The most straightforward way would be to have a USB card reader attached to your Pi, then boot up the working system and do something like:

cp -av /boot/* /mnt/sda1
umount /boot
cp -av /* /mnt/sda2

with, of course, the appropriate mkfs'ing, mounting and umounting (and so on) along the way.

The point is, at the end, you will end up with a standalone (not NOOBS) boot media set.
(And this is a Good Thing)
Hi Joe Schmoe,
Been wondering about this approach. Are you saying one can successfully duplicate a functioning OS and installed applications and any configuration changes by simply copying the appropriate files to a new SD card? That would be cool; in the Windows world this is impossible (I think) as there are hidden files and registries and histories and other unfathomables. In windows a disk image is the only thing (I think) that can be done.

Could you give me more details, I'm not understanding
1.why /boot needs to be unmounted after the cp -av command
2. "mkfs" is a way to format the new SD card prior to writing to it??
3. How do you sort out the physical storage devices, sda1 in your example? I'm guessing the original SD card is called sda0??

thanks!

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: How to remove 2 unwanted OS'es installed with NOOBs

Fri Feb 20, 2015 10:13 pm

Hi Joe Schmoe,
Been wondering about this approach. Are you saying one can successfully duplicate a functioning OS and installed applications and any configuration changes by simply copying the appropriate files to a new SD card?
Yes. In Linux, this works. Yey for Linux!
That would be cool; in the Windows world this is impossible (I think) as there are hidden files and registries and histories and other unfathomables. In windows a disk image is the only thing (I think) that can be done.
Righto. Linux is very much "What you see is what you get", unlike Windows.
Could you give me more details, I'm not understanding
1.why /boot needs to be unmounted after the cp -av command
That's to avoid copying the contents of /boot into the new rootfs.

Note: This process is actually cleaner if you aren't copying from a live system. That is, if you can boot from a different system, and then copy files between partitions that aren't currently in use. But it *can* be done live and will almost always work (only in rare, pathological cases does it fail). Other posters on the forum will tell you that copying from live systems is a "no-no", but as I said, it usually works out OK. In this model (the one I am suggesting so far), you will be copying from the current root (/) to your SD card mounted on "sda".

What this all means is that the cleanest way to do it is to have another working boot system on the Pi, and then mount the source card (the one you're copying from) on, say "sda" and the other one (the target) on "sdb".
2. "mkfs" is a way to format the new SD card prior to writing to it??
Right. It is analogous to the DOS/Windows "FORMAT" command.
3. How do you sort out the physical storage devices, sda1 in your example? I'm guessing the original SD card is called sda0??
Basically, you just have to know. It is basic Linux stuff.
If you are copying from a live system, then your source SD card will be mounted as /. When you then put another SD card into an SD card reader and plug that into your Pi, it will (usually) come up as "/dev/sda" (you can check this by looking at the output of "dmesg" and also by looking at the (pseudo-) file "/proc/partitions").

Alternatively, if you've booted from another SD card, and put your original SD card into a reader and (yet another) one - the target - into another SD card reader, then the first one (the source) will (usually) be /dev/sda and the second one will (usually) be /dev/sdb. Within each "device", the partitions are numbered like "/dev/sda1", "/dev/sda2", etc. My personal convention is to create directories under /mnt, called "/mnt/sda1", "/mnt/sda2", etc - and mount the corresponding "/dev" files under the matching "/mnt" directories.

Finally, note that all of this is assuming you are using a command line, not a GUI. GUIs screw everything up by trying to be "helpful" and "auto-mounting" your SD cards and USB "sticks" for you, creating stupidly named directories that leave you chasing your tail. This obvious mis-feature can be turned off by editing some config file and it is highly recommended that you do so - but the exact details of how to do this are beyond the scope of this document. But in any case, this stuff is best done from a command line w/o any GUI running.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

beta-tester
Posts: 1244
Joined: Fri Jan 04, 2013 1:57 pm
Location: de_DE

Re: How to remove 2 unwanted OS'es installed with NOOBs

Sat Feb 21, 2015 2:36 pm

Joe Schmoe wrote:You know, …

It's probably easier just to do it the straightforward way. That is, copy all the files from the two needed partitions (the boot one and the rootfs one) to newly created/formatted partitions - and be done with it.

...
cp -av /boot/* /mnt/sda1
umount /boot
cp -av /* /mnt/sda2

with, of course, the appropriate mkfs'ing, mounting and umounting (and so on) along the way.

The point is, at the end, you will end up with a standalone (not NOOBS) boot media set.
(And this is a Good Thing)
but even then, you must have correct the cmdline.txt and /etc/fstab file entries.

in case you use the copy mehtod to /dev/sda to "park" you files on temporaty to an USB stick, be sure, that the filesystem is supporting owner, groups and the modes as the source file system is doing. otherwise again that information goes lost.

your copied system will end up in an unstable or broken state.

but, what works is you could also put all files into a compressed TAR archive for a filebased cloning, to preserve files, structure, access rights, symbolic links and so on... and voila, you are very close to the process to creating a customized NOOBS image...
how-to-create-a-custom-os-version
{ I only give negative feedback }
RPi B (rev1, 256MB), B (rev2, 512MB), B+, 2B, 3B, 3B+, ZeroW, ...

Return to “Beginners”