pi.ilpiola.it: The site about Raspberry Pi and Roberto Piola
The idea behind it is that the nde SD will contain the two OS in two separate partitions, and that the shared boot partition will be overwritten, in turn, with the files coming from the boot partition for the first os or with the files from the boot partition of the second OS.
pi@raspbmc$ sudo su - root@raspbmc:/boot# mount /dev/mmcblk0p2 on / type ext4 (rw,noatime) proc on /proc type proc (rw) devpts on /dev/pts type devpts (rw,noexec,nosuid,relatime,gid=5,mode=620) /dev/mmcblk0p1 on /boot type vfat (rw,noatime) /dev/sdb1 on /media/035B-4020 type vfat (rw,nosuid,nodev,uid=1000,gid=1000,shortname=mixed,dmask=0077,utf8=1,showexec,uhelper=udisks) /dev/sdb2 on /media/berryboot type ext4 (rw,nosuid,nodev,uhelper=udisks) root@raspbmc:/boot# umount /dev/sdb1 root@raspbmc:/boot# umount /dev/sdb2/Here, the mount command showed that the sd card reader has been detected as sdb, and that the two partitions of the sd card, namely sdb1 and sdb2, were automounted; I dismounted them with tue umount command.
Maybe your sd card reader will be detected as sda istead of sdb, or you will have just one, or more than two partitions to delete. Adapt the following instructions as follow. (You will not risk damaging your Pi... just your SD cards: if you make something wrong, you'll have to delete all partitions, reformat the cards and reinstall the OS).
So, go ahead and delete all partitions on /dev/sdb with the fdisk command:
root@raspbmc:/boot# fdisk /dev/sdb Command (m for help): p Disk /dev/sdb: 31.9 GB, 31914983424 bytes 64 heads, 32 sectors/track, 30436 cylinders, total 62333952 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/sdb1 2048 131071 64512 e W95 FAT16 (LBA) /dev/sdb2 131072 62333951 31101440 83 Linux Command (m for help): d Partition number (1-4): 2 Command (m for help): d Selected partition 1OK, now the sd card is completely free. We now will create several partitions:
Partition#1 will be 200 M large, and will hold a FAT file system:
Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 1): 1 First sector (2048-62333951, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-62333951, default 62333951): +200M Command (m for help): t Selected partition 1 Hex code (type L to list codes): e Changed system type of partition 1 to e (W95 FAT16 (LBA)) Command (m for help): p Disk /dev/sdb: 31.9 GB, 31914983424 bytes 64 heads, 32 sectors/track, 30436 cylinders, total 62333952 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/sdb1 2048 411647 204800 e W95 FAT16 (LBA)Partitions #2 and #3 will be 4 GB large, and will hold a linux filesystem (default type)
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 (411648-62333951, default 411648): Using default value 411648 Last sector, +sectors or +size{K,M,G} (411648-62333951, default 62333951): +4G Command (m for help): n Partition type: p primary (2 primary, 0 extended, 2 free) e extended Select (default p): p Partition number (1-4, default 3): 3 First sector (8800256-62333951, default 8800256): Using default value 8800256 Last sector, +sectors or +size{K,M,G} (8800256-62333951, default 62333951): +4GThen we'll make a four partition with all the remaining space, and we'll mark it as an "extended" partition for holding more logical partitions:
Command (m for help): n Partition type: p primary (3 primary, 0 extended, 1 free) e extended Select (default e): e Selected partition 4 First sector (17188864-62333951, default 17188864): Using default value 17188864 Last sector, +sectors or +size{K,M,G} (17188864-62333951, default 62333951): Using default value 62333951Now we'll make logical partitions #5 and #6:
Command (m for help): n All primary partitions are in use Adding logical partition 5 First sector (17190912-62333951, default 17190912): Using default value 17190912 Last sector, +sectors or +size{K,M,G} (17190912-62333951, default 62333951): +200M Command (m for help): n All primary partitions are in use Adding logical partition 6 First sector (17602560-62333951, default 17602560): Using default value 17602560 Last sector, +sectors or +size{K,M,G} (17602560-62333951, default 62333951): Using default value 62333951 Command (m for help): p Disk /dev/sdb: 31.9 GB, 31914983424 bytes 64 heads, 32 sectors/track, 30436 cylinders, total 62333952 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/sdb1 2048 411647 204800 e W95 FAT16 (LBA) /dev/sdb2 411648 8800255 4194304 83 Linux /dev/sdb3 8800256 17188863 4194304 83 Linux /dev/sdb4 17188864 62333951 22572544 5 Extended /dev/sdb5 17190912 17600511 204800 83 Linux /dev/sdb6 17602560 62333951 22365696 83 Linuxat last, we'll quit fdisk and start formatting the partitions; before formatting, we'll check again if the automount process remounted some remainings of the first partition of the sdcard, and, if so, we umount them. Another thing worth noticing is that we'll add option -E nodiscard for formatting the linux filesystems: it greatly improves perforance on sdcards.
Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: If you have created or modified any DOS 6.x partitions, please see the fdisk manual page for additional information. Syncing disks. root@raspbmc:/boot# mkfs.vfat /dev/sdb1 mkfs.vfat 3.0.13 (30 Jun 2012) mkfs.vfat: /dev/sdb1 contains a mounted file system. root@raspbmc:/boot# mount /dev/mmcblk0p2 on / type ext4 (rw,noatime) proc on /proc type proc (rw) devpts on /dev/pts type devpts (rw,noexec,nosuid,relatime,gid=5,mode=620) /dev/mmcblk0p1 on /boot type vfat (rw,noatime) /dev/sdb1 on /media/035B-4020 type vfat (rw,nosuid,nodev,uid=1000,gid=1000,shortname=mixed,dmask=0077,utf8=1,showexec,uhelper=udisks) root@raspbmc:/boot# umount /dev/sdb1 root@raspbmc:/boot# mkfs.vfat /dev/sdb1 mkfs.vfat 3.0.13 (30 Jun 2012) root@raspbmc:/boot# root@raspbmc:/boot# mkfs.ext4 -E nodiscard -L /raspbmc /dev/sdb2 mke2fs 1.42.5 (29-Jul-2012) Filesystem label=/raspbmc OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 262144 inodes, 1048576 blocks 52428 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=1073741824 32 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done root@raspbmc:/boot# mkfs.ext4 -E nodiscard -L /raspbian /dev/sdb3 mke2fs 1.42.5 (29-Jul-2012) Filesystem label=/raspbian OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 262144 inodes, 1048576 blocks 52428 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=1073741824 32 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done root@raspbmc:/boot# mkfs.ext4 -E nodiscard -L /rpiutils /dev/sdb5 mke2fs 1.42.5 (29-Jul-2012) Filesystem label=/rpiutils OS type: Linux Block size=1024 (log=0) Fragment size=1024 (log=0) Stride=0 blocks, Stripe width=0 blocks 51200 inodes, 204800 blocks 10240 blocks (5.00%) reserved for the super user First data block=1 Maximum filesystem blocks=67371008 25 block groups 8192 blocks per group, 8192 fragments per group 2048 inodes per group Superblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729 Allocating group tables: done Writing inode tables: done Creating journal (4096 blocks): done Writing superblocks and filesystem accounting information: done root@raspbmc:/boot# mkfs.ext4 -E nodiscard -L /data /dev/sdb6 mke2fs 1.42.5 (29-Jul-2012) Filesystem label=/data OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 1398096 inodes, 5591424 blocks 279571 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=0 171 block groups 32768 blocks per group, 32768 fragments per group 8176 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done root@raspbmc:/boot#Done formatting, let's check the file systems:
root@raspbmc:/boot# mount /dev/mmcblk0p2 on / type ext4 (rw,noatime) proc on /proc type proc (rw) devpts on /dev/pts type devpts (rw,noexec,nosuid,relatime,gid=5,mode=620) /dev/mmcblk0p1 on /boot type vfat (rw,noatime)Good: only raspbmc on the internal sd card is mounted. Let's mount the partitions that will hold raspbmc on the NEW card:
root@raspbmc:/boot# mount /dev/sdb2 /mnt/ root@raspbmc:/boot# mkdir /mnt/boot root@raspbmc:/boot# mount /dev/sdb1 /mnt/boot/And now, let's copy the raspbmc installation:
root@raspbmc:/boot# cd / root@raspbmc:/# tar cf - --one-file-system / /boot | (cd /mnt ; tar xvfp -) ......You will have enough time to brew and drink coffee or tea. When it finishes, we will update the fstab on the raspbmc partition on the new sdcard for forcing a mount of partition#5 on /rpiutils, (and also for forcing a mount of the other partitions under it, so that they will not show up under /media.... we will let the autmount process mount partition#6 under /media/_data like an external device) and we will make a copy of the boot partition; last, we will check fstab. Remember that, after inserting the sd card in the internal slot, the partitions will be renamed from /dev/sdXY to /dev/mmcblk0pY
root@raspbmc:/#cd /mnt root@raspbmc:/mnt# mkdir rpiutils root@raspbmc:/mnt# mount /dev/sdb5 rpiutils/ root@raspbmc:/mnt# mkdir /mnt/rpiutils/raspbmc root@raspbmc:/mnt# mkdir /mnt/rpiutils/raspbian root@raspbmc:/mnt# echo "/dev/mmcblk0p5 /rpiutils ext4 defaults,noatime 0 1" >> /mnt/etc/fstab ######################### CHECK root@raspbmc:/mnt# echo "/dev/mmcblk0p2 /rpiutils/raspbmc ext4 defaults,noatime 0 1" >> /mnt/etc/fstab ######################### CHECK root@raspbmc:/mnt# echo "/dev/mmcblk0p3 /rpiutils/raspbian ext4 defaults,noatime 0 1" >> /mnt/etc/fstab ######################### CHECK root@raspbmc:/mnt# tar cvf rpiutils/boot-raspbmc.tar boot/ root@raspbmc:/mnt# cat /mnt/etc/fstab ################# pasteif everything is OK, shutdown the pi:
root@raspbmc:/mnt# shutdown -h nowRemove the raspbmc SD from the internal slot, and move the multiboot sd from the external reader to the internal slot, then reboot. Raspbmc will come up. Check that everything is OK, shutdown raspbmc, insert the raspbian-only SD in the internal slot, move the multiple boot SD into the esternal reader and reboot.
Raspbian should come up regularly, and automount the external SD under /media/something (boot partition), /media/_raspbian, /media/_raspbmc, /media/_rpiutils, /media/_data). First: let's dismount and remount the interesting partitions (all operations should be done as root):
pi@raspberrypi$ sudo su - root@raspberrypi:/# umount /dev/sdb3 root@raspberrypi:/# mount /dev/sdb3 /mnt/ root@raspberrypi:/# mkdir /mnt/boot root@raspberrypi:/# mount /dev/sdb1 /mnt/boot/Then, copy the raspbian setup into the new directories:
root@rasperrypi:/# cd / root@rasperrypi:/# tar cf - --one-file-system / /boot | (cd /mnt ; tar xvfp -) ......Time for another coffee... now we will be ready to begin the tricky part: edit (with vi or your favorite editor), /mnt/boot/cmdline.cfg e /mnt/etc/fstab, replacing mmcblk0p2 (i.e.: the default root partition) with mmcblk0p3 (that is the NEW root partition)
root@rasperrypi:/# vi /mnt/boot/cmdline.cfg /mnt/etc/fstab root@rasperrypi:/# cat /mnt/boot/cmdline.cfg ######### RIPORTARE root@rasperrypi:/# cat /mnt/etc/fstab ######### RIPORTARENow, like we did with raspbmc, we will make a copy of the boot files, and add rpiutils to the fstab:
root@raspberrypi:/mnt# mkdir data root@raspberrypi:/mnt# mkdir rpiutils root@raspberrypi:/mnt# mount /dev/sdb5 rpiutils root@raspberrypi:/mnt# tar cvf rpiboot/boot-raspbian.tar boot/ root@raspberrypi:/mnt# echo "/dev/mmcblk0p5 /rpiutils ext4 defaults,noatime 0 1" >> /mnt/etc/fstab ######################### CHECK root@raspberrypi:/mnt# echo "/dev/mmcblk0p2 /rpiutils/raspbmc ext4 defaults,noatime 0 1" >> /mnt/etc/fstab ######################### CHECK root@raspberrypi:/mnt# echo "/dev/mmcblk0p3 /rpiutils/raspbian ext4 defaults,noatime 0 1" >> /mnt/etc/fstab ######################### CHECKperform a clean shutdown, remove the raspbian-only SD and boot with the multiboot SD. Now the raspbian OS will be loaded. Open again a terminal and create the scripts to change identity:
pi@raspberrypi$ sudo su - root@raspberrypi:/# cat <<*EOS* >/rpiutils/go-raspbian.sh cd / sudo /bin/rm /boot/* sudo tar xf /rpiutils/boot-raspbian.tar sudo shutdown -r now *EOS* root@raspberrypi:/# chmod a+x /rpiutils/go-raspbian.sh root@raspberrypi:/# cat <<*EOS* >/rpiutils/go-raspbmc.sh cd / sudo /bin/rm /boot/* sudo tar xf /rpiutils/boot-raspbmc.tar sudo shutdown -r now *EOS* root@raspberrypi:/# chmod a+x /rpiutils/go-raspbmc.sh/rpiutils/go-raspbmc.sh will be the magic command that will change your system from raspbian to raspbmc. Make a shortcut for it on your desktop (if you like), and then invoke it (it can be done as user pi)
pi@raspberrypi$ /rpiutils/go-raspbmc.shYour system will be restored to your raspbmc installation: install the "advanced launcher" addon and then add script /rpiutils/go-raspbian.sh as a linux program launcher, then use it to switch from raspbmc back to raspbian with your remote.