Pages

Friday, 30 November 2012

MDADM: start raid1 array with one device

When I was home, I copied a lot of pictures to a raid array. As I moved back, I brought only one disk with me. Now, I would like to access the data on that drive, in a read-only fashion.
sudo mdadm --assemble /dev/md0 /dev/sdb1
This printed out the following:
mdadm: /dev/md0 assembled from 1 drive - need all 2 to start it (use --run to insist).
Let's see the status:
cat /proc/mdstat
Gives me:
md0 : inactive sdb1[1](S)
      625129216 blocks
Okay, so this array definitely needs activation. I decided to run this array:
sudo mdadm --run /dev/md0
And now, let's see the status:
cat /proc/mdstat
It seems, that the device is now active.
md0 : active raid1 sdb1[1]
      625129216 blocks [2/1] [_U]
I expected to see a read only mode, and it is a bit annoying, that it seems that it is not r/o. Now, I try to set it to read-only:
sudo mdadm --readonly /dev/md0
And now, it seems better:
cat /proc/mdstat
shows:
md0 : active (read-only) raid1 sdb1[1]
      625129216 blocks [2/1] [_U]
And now, it is time to mount it!
sudo mount --read-only /dev/md0 /mnt/p1
The good stuff, is that I managed to mount it, and hopefully, as I put it back to its original place, it will still be fine.
sudo mdadm --detail /dev/md0
See the "Update Time" (which is exactly the date, when I last accessed the array)
/dev/md0:
        Version : 0.90
  Creation Time : Wed Nov 21 22:52:49 2012
     Raid Level : raid1
     Array Size : 625129216 (596.17 GiB 640.13 GB)
  Used Dev Size : 625129216 (596.17 GiB 640.13 GB)
   Raid Devices : 2
  Total Devices : 1
Preferred Minor : 0
    Persistence : Superblock is persistent

    Update Time : Thu Nov 22 07:10:02 2012
          State : clean, degraded 
 Active Devices : 1
Working Devices : 1
 Failed Devices : 0
  Spare Devices : 0

           UUID : 9d82c2e5:33bd53b5:e4d1075c:94619d7b
         Events : 0.40

    Number   Major   Minor   RaidDevice State
       0       0        0        0      removed
       1       8       17        1      active sync   /dev/sdb1

Monday, 19 November 2012

syrep

I always forgot the name of the tool, that I used to sync directory structures. So here is the name and the URL:

SYREP

Sunday, 11 November 2012

Dreamplug - overwrite the internal SD card

ssh 192.168.0.4 mkfs.ext3 /dev/sda2
ssh 192.168.0.4 mount /dev/sda1 /mnt/sda1
ssh 192.168.0.4 mount /dev/sda2 /mnt/sda2
sudo kpartx -av debian.phase2.img
sudo mount /dev/mapper/loop0p2 p2
cd p2
sudo tar -czf - . | ssh 192.168.0.4 "cd /mnt/sda2 && tar -xzf -"
cd ..
sudo umount p2
sudo mount /dev/mapper/loop0p1 p1
scp p1/uImage 192.168.0.4:/mnt/sda1/uImage2
sudo umount p1
ssh 192.168.0.4 sync
Reboot the plug, and go to uBoot. Remove all USB drives.
setenv x_bootcmd_kernel fatload usb 0 0x6400000 uImage2
setenv x_bootargs_root root=/dev/sda2 rootdelay=10 panic=10
saveenv
Extract the libs:
mkdir libs
cd libs/
sudo tar -xzf ../sda2.tgz
cd lib/modules
sudo tar -czf - . | ssh 192.168.0.4 "cd /lib/modules && tar -xzf -"

Dreamplug - post setup

Some notes on what I did to the installed debian: - /etc/default/locale
LANG="C"
- /etc/hostname - /etc/apt/sources.list
deb http://mirrors.kernel.org/debian squeeze main contrib non-free
deb http://security.debian.org squeeze/updates main contrib non-free
- /etc/network/interfaces
auto lo eth1

iface lo inet loopback
iface eth1 inet dhcp
- start network
dhclient eth1
- update
apt-get update
apt-get upgrade
- install openssh
apt-get --no-install-recommends install openssh-server

Saturday, 10 November 2012

Dreamplug with Debian Squeeze

The goal is to set up a new debian squeeze on the Dreamplug, using the New IT kernel. What is this about? It is about to put some bytes to an USB drive. This is not rocket science. In order to reduce the USB unplugs, I will create the whole image on a virtual disk image (a file), and dd it to the USB drive, as I am ready. With this, I don't have to do expensive file operations on the slow USB drive, only a sequential copy, which is usually fast. So here is a small list of what I have done. Create a root filesystem by using debootstrap:
sudo apt-get install debootstrap
sudo mkdir rootfs
sudo debootstrap --verbose --foreign \
--arch armel squeeze rootfs \
http://mirrors.kernel.org/debian
The root filesystem is not yet ready. As the kernel does not contain the udev system, if this root filesystem were booted, the following message would appear followed by a shutdown:
Warning: unable to open an initial console.
To avoid this, let us create the generic devices:
(
cd rootfs
sudo MAKEDEV generic
)
Now, it is time to create an 1G image:
dd if=/dev/zero of=debian.img bs=1024 count=1000000
Set up this disk as a disk device, and partition it.
sudo apt-get install kpartx
sudo kpartx -av debian.img
(
cat << EOF
,100,6
,,83
EOF
) | sudo sfdisk /dev/loop0 -u M -D
And so I created two primary partitions: 100M FAT16, and the rest as type LINUX. Let's unplug, and replug the device, so partitions are recognised:
sudo kpartx -d debian.img
sudo kpartx -av debian.img
From this point the two partitions are available as /dev/mapper/loop0p1 and /dev/mapper/loop0p2. Now I need to format the filesystems:
sudo mkfs.vfat /dev/mapper/loop0p1
sudo mkfs.ext3 /dev/mapper/loop0p2
sudo e2label /dev/mapper/loop0p2 pluggedroot
Place the kernel image to the first partition:
sudo mkdir p1
sudo mount /dev/mapper/loop0p1 p1
wget -O - \
http://dreamplug.googlecode.com/files/uImage-DreamPlug%20v9 |
 sudo dd of=p1/uImage
sudo umount p1
Please note, that although there is a newer kernel available, I am still using an elder one, because otherwise, the dmesg is full with messages related to gpio. The version that I have is:
Linux xxx 2.6.33.7-dirty #1 PREEMPT Tue Nov 29 06:13:06 EST 2011 armv5tel GNU/Linux
Now, copy the root filesystem to the second one:
sudo mkdir p2
sudo mount /dev/mapper/loop0p2 p2
sudo tar -cf - rootfs | sudo tar -xf - -C p2/ --strip-components=1
sudo umount p2
We can disconnect the virtual disk, and the partition mappings
sudo kpartx -d debian.img
Let us put it on a physical device:
time sudo dd if=debian.img of=/dev/sdb bs=1048576
That took around 40 seconds on my machine, using a Flash Voyager GT
976+1 records in
976+1 records out
1024000000 bytes (1.0 GB) copied, 38.7155 s, 26.4 MB/s

real0m38.734s
user0m0.000s
sys0m1.504s

Part 2 - on the Dreamplug

Let us see if I can use that USB stick at all on the Dreamplug device:
setenv x_bootcmd_kernel fatload usb 2:1 0x6400000 uImage
setenv x_bootargs_root root=/dev/sdc2 rootdelay=10 panic=10 init=/bin/bash
I also tried to specify root="LABEL=pluggedroot" but that failed. After it booted up, I finished the debootstrap:
/debootstrap/debootstrap --second-stage
You should see some lines showing up, and the latest is:
I: Base system installed successfully.
The serial console needs to be set:
echo 'T0:2345:respawn:/sbin/getty -L ttyS0 115200 linux' >> /etc/inittab
As well as the root password (I set it to the standard nosoup4u):
passwd root
Really important to flush the changes made to the filesystem:
sync
And leave the shell simply with:
exit
At this point, I disconnected my USB drive, and made a backup of it. With this action, I will have a snapshot, that could be easily modified according to my needs.
sudo dd if=/dev/sdb of=debian.phase2.img bs=1024 count=1000000
Boot to the new stuff. There is one thing that is interesting:
modprobe: FATAL: Could not load /lib/modules/2.6.33.7-dirty/modules.dep: No such file or directory
That needs to be fixed. The operating system's configuration will be covered in the next post.

References

Dreamplug - Updated Debian - gpio messages

I updated my dreamplug to the latest debian, and I see these messages in dmesg:
the gpio timer is called ! time is 211
This is somewhat really annoying, so I decided to try to install a fresh debian. The instructions I used for the update are: Update guide

Sunday, 4 November 2012

Dreamplug serial console, plus faster boot

Some months ago, I put my hands on a Dreamplug device. I haven't done too much with it, just put arch on it. Now I decided to log in again, and play around with it. First I need to log in with the serial console. In order to do that, I need to be able to use my serial (ttyUSB0) as a simple user. I first added myself to the dialout group:
sudo gpasswd dialout -a matelakat
And as I don't want to log on/off, I activated the group memberships:
newgrp dialout
And off you go, I just had to start minicom:
minicom
Let's make booting a bit faster. See here. I will make a note of my original bootcommand here (The whole stuff needs to be one line!)
bootcmd=setenv ethact egiga0; ${x_bootcmd_ethernet}; setenv ethact egiga1;
 ${x_bootcmd_ethernet}; ${x_bootcmd_usb}; ${x_bootcmd_kernel};
 setenv bootargs ${x_bootargs} ${x_bootargs_root};
 bootm 0x6400000;
And so it is modified to:
${x_bootcmd_usb}; ${x_bootcmd_kernel};
 setenv bootargs ${x_bootargs} ${x_bootargs_root};
 bootm 0x6400000;
With this:
Marvell>> setenv bootcmd '${x_bo...
And save the stuff:
Marvell>> saveenv
And reset
Marvell>> reset
So that the device will boot significantly faster.