Primary menu

Category Archives: Tech

One of the common problems in Linux installations is to lose or damage the the boot loader (Grub), specially if on the same machine coexists other OS from Microsoft family.

On the other side, while you are testing Linux you can loose your Windows Boot.

I used to repair this kind of problems in the old-school way: Booting a Linux liveCD+mount HD partition+chroot+install grub+cross fingers. But this is not a method recommended for novice users…

Recently I’ve discovered an utility that is designed specially for this! The utility is called Boot Repair CD (you have to burn the ISO to a CD or USB) and after booting, an assistant will appear and magically solve your boot problems 🙂

Boot Repair Disk (Easy way)

Even they will help you if the utility can’t repair your boot area:

Launch Boot-Repair, then click the “Recommended repair” button. When repair is finished, note the URL (paste.ubuntu.com/XXXXX) that appears on a paper, then reboot and check if you recovered access to your OSs. If the repair did not succeed, indicate the URL to boot.repair@gmail.com in order to get help.

For advanced users, it also have a bunch of options related to Grub and MBR:

Today I’ve learnt that a Linux partition (which is mounted) can be grown “a la brava” (means “the hard way” in Catalan) directly modifying it through Fdisk and then resizing with resize2fs. That’s it….

With my own conservative way I’d boot the machine into Gparted (A very useful small distro that boots into Gparted directly), resize the partition (unmounted), and then reboot again.

The only condition is that the partition which has to be grown is the last one. If not… things get more complicated (or not, if the last partition is a swap one, which can be erased and recreated without problems). Other condition is that particion can only be grown (not shrink).

The process it’s easy:

First grow the disk physically (can be a VM disk, a new bigger disk just cloned, or simply a partition that does’nt fill the entire disk).

With Fdisk, remove the partition.

Without exiting Fdisk, create a new partition. Carefully note that the first sector match the previous first sector. The last sector can be the end of the disk i.e.

Verify/toggle Boot flag, must be activated.

Save and exit. Cross your fingers and reboot.

Once rebooted, grow the filesystem with resize2fs.

Growing a ext3/4 partition

Shell

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

## 4.3Gb of free space before the process

root@nairobi:~# df -h

Filesystem Size Used Avail Use%Mounted on

/dev/xvda211G5.7G4.3G57%/

udev238M4.0K238M1%/dev

tmpfs49M176K49M1%/run

none5.0M05.0M0%/run/lock

none245M0245M0%/run/shm

## Let's do it

## (Note that HDD is 26.8 Gb. It has been grown previously at XEN dom0 level).

root@nairobi:~# fdisk /dev/xvda

Command(mforhelp):p

Disk/dev/xvda:26.8GB,26843545600bytes

255heads,63sectors/track,3263cylinders,total52428800sectors

Units=sectors of1*512=512bytes

Sector size(logical/physical):512bytes/512bytes

I/Osize(minimum/optimal):512bytes/512bytes

Disk identifier:0x00088b81

Device Boot Start EndBlocks IdSystem

/dev/xvda1204899942349868882Linux swap/Solaris

/dev/xvda2*999424230686711103462483Linux

Command(mforhelp):d

Partition number(1-4):2

# Remove the last partition. DON'T WRITE CHANGES YET!

# And re-create the partition. Note that first sector MUST be the same than before

Today an entire folder disappeared from my Owncloud instance. It is an entire mystery why has disappeared. And I haven’t backups since owncloud data supposedly is synced between all client computers…

But, who wants backups when you have ZFS snapshots? I have all my private Owncloud data into a ZFS volume, and a cron job that do snapshots at midnight. Unlike Solaris, ZFS on Linux doesn’t have snapshotting natively so we have to use this set of pretty scripts: zfs-auto-snapshot

ZFS snapshots can be accessed like if they were a regular filesystem and they show you the files as it were just at the snapshot moment. The good thing is that the space occupied is *very* low (only stores changed data like it were an incremental backup).

So you only have to copy the missing data from the snapshot folder into the original place.

zfs list shows us all the datastores, mountpoints and snapshots:

1

zfs list

zfs list

Shell

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

NAME USED AVAIL REFER MOUNTPOINT

RomaniBulk74,7G154G30Knone

RomaniBulk/ISO30K154G30Knone

RomaniBulk/Media74,7G154G74,7G/mnt/media

RomaniHD25,6G321G30Knone

RomaniHD/Magatzem25,6G321G20,3G/mnt/magatzem/

RomaniHD/Magatzem@copia_daily-2015-04-29-042551,0M-18,3G-

RomaniHD/Magatzem@copia_daily-2015-04-30-0425188K-18,6G-

RomaniHD/Magatzem@copia_daily-2015-05-01-0425195K-18,7G-

RomaniHD/Magatzem@copia_daily-2015-05-02-0425306K-18,7G-

RomaniHD/Magatzem@copia_daily-2015-05-03-0425286K-18,6G-

RomaniHD/Magatzem@copia_daily-2015-05-04-0425212K-18,5G-

RomaniHD/Magatzem@copia_daily-2015-05-05-0425210K-20,3G-

RomaniHD/Magatzem@copia_daily-2015-05-06-0425250K-20,6G-

RomaniHD/Magatzem@copia_daily-2015-05-07-0425283K-20,5G-

RomaniHD/Magatzem@copia_daily-2015-05-08-0425228K-20,5G-

RomaniHD/Magatzem@copia_daily-2015-05-09-0425324K-20,4G-

RomaniHD/Magatzem@copia_daily-2015-05-10-0425237K-20,0G-

RomaniHD/Magatzem@copia_daily-2015-05-11-0425234K-19,4G-

RomaniHD/Magatzem@copia_daily-2015-05-12-0425207K-19,4G-

We want to restore the latest snapshot from May 12th at 04:25am. First we have to ensure that snapshots are visible to us. We’ll set RomaniHD/Magatzem datastore to show snapshots. It will be located hidden on the datastore root (/datastore/.zfs)

1

zfs set snapdir=visible RomaniHD/Magatzem

Voilà, we have a virtual copy of our datastore of the last week:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

root@romani:/mnt/magatzem/.zfs/snapshot# ls -la

total0

dr-xr-xr-x2root root2mai1306:25.

dr-xr-xr-x1root root0abr1520:26..

dr-xr-xr-x1root root0mai1214:36copia_daily-2015-04-29-0425

dr-xr-xr-x1root root0mai1214:36copia_daily-2015-04-30-0425

dr-xr-xr-x1root root0mai1214:36copia_daily-2015-05-01-0425

dr-xr-xr-x1root root0mai1214:36copia_daily-2015-05-02-0425

dr-xr-xr-x1root root0mai1214:36copia_daily-2015-05-03-0425

dr-xr-xr-x1root root0mai1214:36copia_daily-2015-05-04-0425

dr-xr-xr-x1root root0mai1214:36copia_daily-2015-05-05-0425

dr-xr-xr-x1root root0mai1214:36copia_daily-2015-05-06-0425

dr-xr-xr-x1root root0mai1214:36copia_daily-2015-05-07-0425

dr-xr-xr-x1root root0mai1214:36copia_daily-2015-05-08-0425

dr-xr-xr-x1root root0mai1214:36copia_daily-2015-05-09-0425

dr-xr-xr-x1root root0mai1214:36copia_daily-2015-05-10-0425

dr-xr-xr-x1root root0mai1214:36copia_daily-2015-05-11-0425

dr-xr-xr-x1root root0mai1214:36copia_daily-2015-05-12-0425

Now we have to enter the desired folder (day) and copy the contents into the correct place.

In my case, I restored Owncloud data, so after copying the missing data I had to do a content refresh. First become www-data user and tell owncloud to refresh its entire data folder:

It may sound strange, but one radio station (or somebody) may want to stream audio to two different networks. I had this special need in Boca Ràdio (a local Radio Station from Barcelona) because this station broadcasts through a provider and also broadcasts into Guifi.net (A community based, open and neutral network).

So, the box that transcode analog audio coming from the station’s sound mixer, it has to send it to:

Streaming provider in Shoutcast format

Localhost in Icecast format. In the same box there is an Icecast server listening to Guifi network clients. (Note that Icecast server may be running on another location).

I utilize this little transcoder: Darkice that reads configuration from /etc/darkice.cfg and sends analog audio coming from the Soundboard to the specified targets and in the specified format. It is available in Debian repo.

darkice.cfg

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

# this section describes general aspects of the live streaming session

[general]

duration=0# duration of encoding, in seconds. 0 means forever

bufferSecs=1

reconnect=yes# reconnect to the server(s) if disconnected

# this section describes the audio input that will be streamed

[input]

device=/dev/audio# OSS DSP soundcard device for the audio input

sampleRate=44050# sample rate in Hz. try 11025, 22050 or 44100

bitsPerSample=16# bits per sample. try 16

channel=2# channels. 1 = mono, 2 = stereo

# this section describes a streaming connection to an IceCast2 server

# At the moment, Icecast server is running on the same host and acting as a

It’s not uncommon to see on many offices that the Internet connection comes from several WAN connections (for redundancy, or whatever). Even on the more freak homes I’ve seen a multiwan setup (i.e., one wan from the ISP, other from a guifi.net vpn, and other wan being stolen from the neighbors).

I know three methods for managing automatically more than one WAN connection. Best yet, automatically but meeting several rules (i.e.: youtube transit sent to wan1, bittorrent to wan2 and HTTPS transit to wan3).

Method 1: RouterOS PCC

Mikrotik routers can handle natively a multiwan setup through PCC (Per Connection Classifier). Packets must be marked with a routing mark and then the PCC chosses where to send them. Best references:

Method 2: OpenWRT MWAN3

MWAN3 is a package for OpenWRT that do the job and can be configured in a easy and visual way. So you need a powerful router fully compatible with OpenWRT and MWAN3. I have an ex-coworker that uses this stuff and wrote this excellent post:

Method 3: Linux

Method 1 and 2 requires a special router, but this method only requires a Linux Box with two or more ethernet cards. I’ve not tested it but it seems very interesting because it’s not hardware-dependant. In fact, that software is designed for, given more than one WAN connection, discard the first that gets disconnected (hence the title of the project).